[cairo-commit] rcairo/src rb_cairo_context.c, 1.26, 1.27 rb_cairo_private.c, 1.7, 1.8 rb_cairo_private.h, 1.10, 1.11 rb_cairo_scaled_font.c, 1.6, 1.7

Kouhei Sutou commit at pdx.freedesktop.org
Sat Aug 16 01:34:21 PDT 2008


Committed by: kou

Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv1768/src

Modified Files:
	rb_cairo_context.c rb_cairo_private.c rb_cairo_private.h 
	rb_cairo_scaled_font.c 
Log Message:
        * src/rb_cairo_private.[ch] (rb_cairo__text_clusters_from_ruby_object)
        (rb_cairo__glyphs_from_ruby_object): add.

        * test/test_context.rb (ContextTest#test_text_to_glyphs): add a
        test for Cairo::Context#show_text_glyphs.

        * src/rb_cairo_context.c: support Cairo::Context#show_text_glyphs.


Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_context.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- rb_cairo_context.c	16 Aug 2008 07:23:15 -0000	1.26
+++ rb_cairo_context.c	16 Aug 2008 08:34:18 -0000	1.27
@@ -1177,6 +1177,36 @@
 {
   return CBOOL2RVAL (cairo_has_show_text_glyphs (_SELF));
 }
+
+static VALUE
+cr_show_text_glyphs (VALUE self, VALUE rb_utf8, VALUE rb_glyphs,
+                     VALUE rb_clusters, VALUE rb_backward)
+{
+  cairo_t *cr;
+  const char *utf8;
+  int utf8_len;
+  cairo_glyph_t *glyphs;
+  int num_glyphs;
+  cairo_text_cluster_t *clusters;
+  int num_clusters;
+  cairo_bool_t backward;
+
+  cr = _SELF;
+  utf8 = RSTRING_PTR (rb_utf8);
+  utf8_len = RSTRING_LEN (rb_utf8);
+  rb_cairo__glyphs_from_ruby_object (rb_glyphs, &glyphs, &num_glyphs);
+  rb_cairo__text_clusters_from_ruby_object (rb_clusters,
+                                            &clusters, &num_clusters);
+  backward = RVAL2CBOOL (rb_backward);
+  cairo_show_text_glyphs (cr, utf8, utf8_len,
+                          glyphs, num_glyphs,
+                          clusters, num_clusters,
+                          backward);
+  cairo_glyph_free (glyphs);
+  cairo_text_cluster_free (clusters);
+
+  return self;
+}
 #endif
 
 static VALUE
@@ -1593,6 +1623,8 @@
                     cr_has_show_text_glyphs, 0);
   rb_define_alias (rb_cCairo_Context,
                    "has_show_text_glyphs?", "have_show_text_glyphs?");
+  rb_define_method (rb_cCairo_Context, "show_text_glyphs",
+                    cr_show_text_glyphs, 4);
 #endif
   rb_define_method (rb_cCairo_Context, "text_path", cr_text_path, 1);
   rb_define_method (rb_cCairo_Context, "glyph_path", cr_glyph_path, 1);

Index: rb_cairo_private.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_private.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- rb_cairo_private.c	16 Aug 2008 08:16:39 -0000	1.7
+++ rb_cairo_private.c	16 Aug 2008 08:34:18 -0000	1.8
@@ -130,13 +130,13 @@
 }
 
 VALUE
-rb_cairo__glyphs_to_ruby_object (cairo_glyph_t *glyphs, int n_glyphs)
+rb_cairo__glyphs_to_ruby_object (cairo_glyph_t *glyphs, int num_glyphs)
 {
   int i;
   VALUE rb_glyphs;
 
-  rb_glyphs = rb_ary_new2 (n_glyphs);
-  for (i = 0; i < n_glyphs; i++)
+  rb_glyphs = rb_ary_new2 (num_glyphs);
+  for (i = 0; i < num_glyphs; i++)
     {
       RARRAY_PTR (rb_glyphs)[i] = CRGLYPH2RVAL (glyphs + i);
     }
@@ -144,15 +144,32 @@
   return rb_glyphs;
 }
 
+void
+rb_cairo__glyphs_from_ruby_object (VALUE rb_glyphs,
+                                   cairo_glyph_t **glyphs, int *num_glyphs)
+{
+  int i;
+
+  *num_glyphs = RARRAY_LEN (rb_glyphs);
+  *glyphs = cairo_glyph_allocate (*num_glyphs);
+  for (i = 0; i < *num_glyphs; i++)
+    {
+      cairo_glyph_t *glyph;
+
+      glyph = *glyphs + i;
+      *glyph = *(RVAL2CRGLYPH (RARRAY_PTR (rb_glyphs)[i]));
+    }
+}
+
 VALUE
 rb_cairo__text_clusters_to_ruby_object (cairo_text_cluster_t *clusters,
-                                        int n_clusters)
+                                        int num_clusters)
 {
   int i;
   VALUE rb_clusters;
 
-  rb_clusters = rb_ary_new2 (n_clusters);
-  for (i = 0; i < n_clusters; i++)
+  rb_clusters = rb_ary_new2 (num_clusters);
+  for (i = 0; i < num_clusters; i++)
     {
       RARRAY_PTR (rb_clusters)[i] = CRTEXTCLUSTER2RVAL (clusters + i);
     }
@@ -161,6 +178,24 @@
 }
 
 void
+rb_cairo__text_clusters_from_ruby_object (VALUE rb_clusters,
+                                          cairo_text_cluster_t **clusters,
+                                          int *num_clusters)
+{
+  int i;
+
+  *num_clusters = RARRAY_LEN (rb_clusters);
+  *clusters = cairo_text_cluster_allocate (*num_clusters);
+  for (i = 0; i < *num_clusters; i++)
+    {
+      cairo_text_cluster_t *cluster;
+
+      cluster = *clusters + i;
+      *cluster = *(RVAL2CRTEXTCLUSTER (RARRAY_PTR (rb_clusters)[i]));
+    }
+}
+
+void
 Init_cairo_private (void)
 {
   cr_id_normalize_const_name = rb_intern ("normalize_const_name");

Index: rb_cairo_private.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_private.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- rb_cairo_private.h	16 Aug 2008 08:16:39 -0000	1.10
+++ rb_cairo_private.h	16 Aug 2008 08:34:18 -0000	1.11
@@ -93,8 +93,13 @@
 
 const char *rb_cairo__inspect (VALUE object);
 
-VALUE rb_cairo__glyphs_to_ruby_object (cairo_glyph_t *glyphs, int n_glyphs);
+VALUE rb_cairo__glyphs_to_ruby_object (cairo_glyph_t *glyphs, int num_glyphs);
+void rb_cairo__glyphs_from_ruby_object (VALUE rb_glyphs,
+                                        cairo_glyph_t **glyphs, int *num_glyphs);
 VALUE rb_cairo__text_clusters_to_ruby_object (cairo_text_cluster_t *clusters,
-                                              int n_clusters);
+                                              int num_clusters);
+void rb_cairo__text_clusters_from_ruby_object (VALUE rb_clusters,
+                                               cairo_text_cluster_t **clusters,
+                                               int *num_clusters);
 
 #endif

Index: rb_cairo_scaled_font.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_scaled_font.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- rb_cairo_scaled_font.c	16 Aug 2008 08:16:39 -0000	1.6
+++ rb_cairo_scaled_font.c	16 Aug 2008 08:34:19 -0000	1.7
@@ -122,9 +122,9 @@
   const char *utf8;
   int utf8_len;
   cairo_glyph_t *glyphs = NULL;
-  int n_glyphs;
+  int num_glyphs;
   cairo_text_cluster_t *clusters = NULL;
-  int n_clusters;
+  int num_clusters;
   cairo_bool_t backward;
   cairo_status_t status;
   VALUE rb_glyphs, rb_clusters;
@@ -136,14 +136,14 @@
 
   status = cairo_scaled_font_text_to_glyphs (_SELF (self),
                                              x, y, utf8, utf8_len,
-                                             &glyphs, &n_glyphs,
-                                             &clusters, &n_clusters,
+                                             &glyphs, &num_glyphs,
+                                             &clusters, &num_clusters,
                                              &backward);
   rb_cairo_check_status (status);
 
-  rb_glyphs = rb_cairo__glyphs_to_ruby_object (glyphs, n_glyphs);
+  rb_glyphs = rb_cairo__glyphs_to_ruby_object (glyphs, num_glyphs);
   cairo_glyph_free (glyphs);
-  rb_clusters = rb_cairo__text_clusters_to_ruby_object (clusters, n_clusters);
+  rb_clusters = rb_cairo__text_clusters_to_ruby_object (clusters, num_clusters);
   cairo_text_cluster_free (clusters);
 
   return rb_ary_new3 (3, rb_glyphs, rb_clusters, CBOOL2RVAL (backward));



More information about the cairo-commit mailing list