[cairo-commit] 2 commits - src/cairo.c test/bitmap-font.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon Mar 5 13:19:49 PST 2007


 src/cairo.c        |   38 +++++++++++++++++++++++++++++++++-----
 test/bitmap-font.c |    6 ++++--
 2 files changed, 37 insertions(+), 7 deletions(-)

New commits:
diff-tree cc12c5acc41f452edff3f4ad8fafe1aebf1810aa (from b63f5ae58f6617b9a2c9f3434bc1c9f3c72612ac)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Mar 5 16:19:28 2007 -0500

    Make cairo_text_path() set current point correctly
    
    This fixes the bitmap-text test that I just made reveal a bug.

diff --git a/src/cairo.c b/src/cairo.c
index fba24e7..66434d0 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -2793,9 +2793,9 @@ cairo_glyph_extents (cairo_t            
  *
  * NOTE: The cairo_show_text() function call is part of what the cairo
  * designers call the "toy" text API. It is convenient for short demos
- * and simple programs, but it is not expected to be adequate for the
- * most serious of text-using applications. See cairo_show_glyphs()
- * for the "real" text display API in cairo.
+ * and simple programs, but it is not expected to be adequate for
+ * serious text-using applications. See cairo_show_glyphs() for the
+ * "real" text display API in cairo.
  **/
 void
 cairo_show_text (cairo_t *cr, const char *utf8)
@@ -2879,11 +2879,25 @@ cairo_show_glyphs (cairo_t *cr, const ca
  * cairo_show_text().
  *
  * Text conversion and positioning is done similar to cairo_show_text().
+ *
+ * Like cairo_show_text(), After this call the current point is
+ * moved to the origin of where the next glyph would be placed in
+ * this same progression.  That is, the current point will be at
+ * the origin of the final glyph offset by its advance values.
+ * This allows for chaining multiple calls to to cairo_text_path()
+ * without having to set current point in between.
+ *
+ * NOTE: The cairo_text_path() function call is part of what the cairo
+ * designers call the "toy" text API. It is convenient for short demos
+ * and simple programs, but it is not expected to be adequate for
+ * serious text-using applications. See cairo_glyph_path() for the
+ * "real" text path API in cairo.
  **/
 void
 cairo_text_path  (cairo_t *cr, const char *utf8)
 {
-    cairo_glyph_t *glyphs = NULL;
+    cairo_text_extents_t extents;
+    cairo_glyph_t *glyphs = NULL, *last_glyph;
     int num_glyphs;
     double x, y;
 
@@ -2907,8 +2921,22 @@ cairo_text_path  (cairo_t *cr, const cha
 					   glyphs, num_glyphs,
 					   &cr->path);
 
-    /* XXX: set current point like in cairo_show_text() */
+    if (cr->status)
+	goto BAIL;
+
+    last_glyph = &glyphs[num_glyphs - 1];
+    cr->status = _cairo_gstate_glyph_extents (cr->gstate,
+					      last_glyph, 1,
+					      &extents);
+
+    if (cr->status)
+	goto BAIL;
+
+    x = last_glyph->x + extents.x_advance;
+    y = last_glyph->y + extents.y_advance;
+    cairo_move_to (cr, x, y);
 
+ BAIL:
     if (glyphs)
 	free (glyphs);
 
diff-tree b63f5ae58f6617b9a2c9f3434bc1c9f3c72612ac (from a487d094212d6bc4a06d5bfc774ba6d575165aa5)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Mar 5 16:15:09 2007 -0500

    [test] In the bitmap-font test, break cairo_text_path() call into two
    such that it checks current-point handling after that call.  It fails now,
    because cairo_text_path does not set current-point explicitly.

diff --git a/test/bitmap-font.c b/test/bitmap-font.c
index d38243a..2a9754e 100644
--- a/test/bitmap-font.c
+++ b/test/bitmap-font.c
@@ -110,9 +110,11 @@ draw (cairo_t *cr, int width, int height
      * fonts at all should fix this. */
     cairo_move_to (cr, width -1, 2 * (TEXT_SIZE - 5));
     cairo_rotate (cr, M_PI);
-    cairo_show_text (cr, "the quick brown fox");
+    cairo_show_text (cr, "the quick");
+    cairo_show_text (cr, " brown fox");
 
-    cairo_text_path (cr, " jumps over a lazy dog");
+    cairo_text_path (cr, " jumps over");
+    cairo_text_path (cr, " a lazy dog");
     cairo_fill (cr);
 
     return CAIRO_TEST_SUCCESS;


More information about the cairo-commit mailing list