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

Behdad Esfahbod behdad at kemper.freedesktop.org
Sat Jul 15 15:28:52 PDT 2006


 src/cairo-scaled-font.c |    6 +++---
 src/cairo-surface.c     |   12 +++++++-----
 test/cairo-test.c       |    2 ++
 3 files changed, 12 insertions(+), 8 deletions(-)

New commits:
diff-tree 84840e6bba6e72aa88fad7a0ee929e8955ba9051 (from 47d3c5a2c63478288345235f26533f2d6059e815)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 14 21:42:41 2006 -0400

    Use font matrix offset to reposition glyph origin instead of adjusting advance
    
    As the font matrix includes translation, which is otherwise unused for glyph
    transformation, the interpretation of translation is fairly arbitrary. For
    1.2.0, we choose to have this translation affect the glyph advance with the
    thought that it could be used to do letter spacing/kerning. That is fairly
    useless in practice, and a far more useful interpretation is to relocate
    the origin of each glyph.
    
    This patch uses the translation in the font matrix as an offset for the
    glyph origin in user space. It turns out glyph extents were already correctly
    shifted.
    
    The end result with this patch is to have cairo match the 1.0 behaviour for
    font matrix translations, but now we know why :-)
    
    Explanation above courtesy of Keith Packard.

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index e57b25f..a4fe953 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -1152,9 +1152,9 @@ _cairo_scaled_glyph_set_metrics (cairo_s
 
     scaled_glyph->metrics.x_advance = fs_metrics->x_advance;
     scaled_glyph->metrics.y_advance = fs_metrics->y_advance;
-    cairo_matrix_transform_point (&scaled_font->font_matrix,
-				  &scaled_glyph->metrics.x_advance,
-				  &scaled_glyph->metrics.y_advance);
+    cairo_matrix_transform_distance (&scaled_font->font_matrix,
+				     &scaled_glyph->metrics.x_advance,
+				     &scaled_glyph->metrics.y_advance);
 
     scaled_glyph->bbox.p1.x = _cairo_fixed_from_double (min_device_x);
     scaled_glyph->bbox.p1.y = _cairo_fixed_from_double (min_device_y);
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index e01c2c9..3ff1ae7 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -1705,6 +1705,7 @@ _cairo_surface_show_glyphs (cairo_surfac
     cairo_glyph_t *dev_glyphs = (cairo_glyph_t*) glyphs;
     cairo_scaled_font_t *dev_scaled_font = scaled_font;
     cairo_pattern_union_t dev_source;
+    cairo_matrix_t font_matrix;
 
     assert (! surface->is_snapshot);
 
@@ -1718,7 +1719,9 @@ _cairo_surface_show_glyphs (cairo_surfac
 						 surface,
 						 &dev_source.base);
 
-    if (_cairo_surface_has_device_transform (surface))
+    cairo_scaled_font_get_font_matrix (scaled_font, &font_matrix);
+
+    if (_cairo_surface_has_device_transform (surface) || font_matrix.x0 != 0.0 || font_matrix.y0 != 0.0)
     {
         int i;
 
@@ -1728,8 +1731,8 @@ _cairo_surface_show_glyphs (cairo_surfac
 
         for (i = 0; i < num_glyphs; i++) {
             dev_glyphs[i].index = glyphs[i].index;
-            dev_glyphs[i].x = glyphs[i].x;
-	    dev_glyphs[i].y = glyphs[i].y;
+            dev_glyphs[i].x = glyphs[i].x + font_matrix.x0;
+	    dev_glyphs[i].y = glyphs[i].y + font_matrix.y0;
 	    cairo_matrix_transform_point (&surface->device_transform,
 					  &dev_glyphs[i].x,
 					  &dev_glyphs[i].y);
@@ -1737,11 +1740,10 @@ _cairo_surface_show_glyphs (cairo_surfac
 
 	if (! _cairo_matrix_is_integer_translation (&surface->device_transform, NULL, NULL)) {
 	    cairo_font_options_t *font_options;
-	    cairo_matrix_t font_matrix, dev_ctm;
+	    cairo_matrix_t dev_ctm;
 
 	    font_options = cairo_font_options_create ();
 
-	    cairo_scaled_font_get_font_matrix (scaled_font, &font_matrix);
 	    cairo_scaled_font_get_ctm (scaled_font, &dev_ctm);
 	    cairo_matrix_multiply (&dev_ctm, &dev_ctm, &surface->device_transform);
 	    cairo_scaled_font_get_font_options (scaled_font, font_options);
diff-tree 47d3c5a2c63478288345235f26533f2d6059e815 (from c70edff0842bc6f7238e17a5fe92dddceec283d3)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 14 20:06:34 2006 -0400

    Flush stdout after writing \r, to remove artifacts.

diff --git a/test/cairo-test.c b/test/cairo-test.c
index 19adf3e..ea580be 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -1886,6 +1886,7 @@ cairo_test_expecting (cairo_test_t *test
 		} else {
 		    /* eat the test name */
 		    printf ("\r");
+		    fflush (stdout);
 		}
 		cairo_test_log ("CRASHED\n");
 		fprintf (stderr, "%s-%s-%s [%d]:\t%s!!!CRASHED!!!%s\n",
@@ -1905,6 +1906,7 @@ cairo_test_expecting (cairo_test_t *test
 		    } else {
 			/* eat the test name */
 			printf ("\r");
+			fflush (stdout);
 		    }
 		    fprintf (stderr, "%s-%s-%s [%d]:\t%sFAIL%s\n",
 			     test->name, target->name,


More information about the cairo-commit mailing list