[cairo-commit] 7 commits - src/cairo-arc.c src/cairo-ft-font.c src/cairo-scaled-font.c src/cairo-user-font.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Wed May 28 17:36:29 PDT 2008


 src/cairo-arc.c         |    1 
 src/cairo-ft-font.c     |    2 
 src/cairo-scaled-font.c |    4 -
 src/cairo-user-font.c   |  111 ++++++++++++++++++++++++++++++++----------------
 4 files changed, 79 insertions(+), 39 deletions(-)

New commits:
commit a9b2461c41dba6bb097ee316f093d5b9d3fb6d56
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 28 20:29:11 2008 -0400

    [user-font] Handle metrics-hinting font option

diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index 297ab67..4c59398 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -149,7 +149,10 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 	    extents.height    = (y2 - y1) * y_scale;
 	}
 
-	/* XXX round advance to device-space-ints if metrics-hinting enabled? */
+	if (scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF) {
+	    extents.x_advance = _cairo_lround (extents.x_advance / scaled_font->snap_x_scale) * scaled_font->snap_x_scale;
+	    extents.y_advance = _cairo_lround (extents.y_advance / scaled_font->snap_y_scale) * scaled_font->snap_y_scale;
+	}
 
 	_cairo_scaled_glyph_set_metrics (scaled_glyph,
 					 &scaled_font->base,
commit b0796bf200de86cb37e84c8241f8f72d8d5657d2
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 28 20:20:46 2008 -0400

    [user-font] Cache extent-space scale in the scaled font

diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index 96e533f..297ab67 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -59,6 +59,16 @@ typedef struct _cairo_user_scaled_font {
     cairo_scaled_font_t  base;
 
     cairo_text_extents_t default_glyph_extents;
+
+    /* space to compute extents in, and factors to convert back to user space */
+    cairo_matrix_t extent_scale;
+    double extent_x_scale;
+    double extent_y_scale;
+
+    /* multiplier for metrics hinting */
+    double snap_x_scale;
+    double snap_y_scale;
+
 } cairo_user_scaled_font_t;
 
 /* #cairo_user_scaled_font_t */
@@ -117,41 +127,22 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 	if (extents.width == 0.) {
 	    /* Compute extents.x/y/width/height from meta_surface, in font space */
 
-	    cairo_matrix_t matrix;
-	    double fixed_scale, x_scale, y_scale;
-
 	    cairo_box_t bbox;
 	    double x1, y1, x2, y2;
+	    double x_scale, y_scale;
 	    cairo_surface_t *null_surface = _cairo_null_surface_create (cairo_surface_get_content (meta_surface));
 	    cairo_surface_t *analysis_surface = _cairo_analysis_surface_create (null_surface, -1, -1);
 	    cairo_surface_destroy (null_surface);
 
-	    /* compute a normalized version of font scale matrix to compute
-	     * extents in.  This is to minimize error caused by the cairo_fixed_t
-	     * representation. */
-
-	    matrix = scaled_font->base.scale_inverse;
-	    status = _cairo_matrix_compute_scale_factors (&matrix, &x_scale, &y_scale, 1);
-	    if (status)
-		return status;
-
-	    /* since glyphs are pretty much 1.0x1.0, we can reduce error by
-	     * scaling to a larger square.  say, 1024.x1024. */
-	    fixed_scale = 1024.;
-	    x_scale /= fixed_scale;
-	    y_scale /= fixed_scale;
-	    if (x_scale == 0) x_scale = 1. / fixed_scale;
-	    if (y_scale == 0) y_scale = 1. / fixed_scale;
-
-	    cairo_matrix_scale (&matrix, 1. / x_scale, 1. / y_scale);
-
-	    _cairo_analysis_surface_set_ctm (analysis_surface, &matrix);
+	    _cairo_analysis_surface_set_ctm (analysis_surface, &scaled_font->extent_scale);
 	    status = _cairo_meta_surface_replay (meta_surface, analysis_surface);
 	    _cairo_analysis_surface_get_bounding_box (analysis_surface, &bbox);
 	    cairo_surface_destroy (analysis_surface);
 
 	    _cairo_box_to_doubles (&bbox, &x1, &y1, &x2, &y2);
 
+	    x_scale = scaled_font->extent_x_scale;
+	    y_scale = scaled_font->extent_y_scale;
 	    extents.x_bearing = x1 * x_scale;
 	    extents.y_bearing = y1 * y_scale;
 	    extents.width     = (x2 - x1) * x_scale;
@@ -342,7 +333,38 @@ _cairo_user_font_face_scaled_font_create (void                        *abstract_
 	return status;
     }
 
-    if (font_face->scaled_font_methods.init != NULL) {
+    /* compute a normalized version of font scale matrix to compute
+     * extents in.  This is to minimize error caused by the cairo_fixed_t
+     * representation. */
+    {
+	double fixed_scale, x_scale, y_scale;
+
+	user_scaled_font->extent_scale = user_scaled_font->base.scale_inverse;
+	status = _cairo_matrix_compute_scale_factors (&user_scaled_font->extent_scale,
+						      &x_scale, &y_scale,
+						      1);
+	if (status == CAIRO_STATUS_SUCCESS) {
+
+	    if (x_scale == 0) x_scale = 1.;
+	    if (y_scale == 0) y_scale = 1.;
+
+	    user_scaled_font->snap_x_scale = x_scale;
+	    user_scaled_font->snap_y_scale = y_scale;
+
+	    /* since glyphs are pretty much 1.0x1.0, we can reduce error by
+	     * scaling to a larger square.  say, 1024.x1024. */
+	    fixed_scale = 1024.;
+	    x_scale /= fixed_scale;
+	    y_scale /= fixed_scale;
+
+	    cairo_matrix_scale (&user_scaled_font->extent_scale, 1. / x_scale, 1. / y_scale);
+
+	    user_scaled_font->extent_x_scale = x_scale;
+	    user_scaled_font->extent_y_scale = y_scale;
+	}
+    }
+
+    if (status == CAIRO_STATUS_SUCCESS && font_face->scaled_font_methods.init != NULL) {
 
 	/* Lock the scaled_font mutex such that user doesn't accidentally try
          * to use it just yet. */
commit abdf04c671235a120f23a1444a53893afdd949b0
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 28 19:52:56 2008 -0400

    [user-font] Handle the case of a null render_glyph callback

diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index b1b5b03..96e533f 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -90,9 +90,12 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 	cairo_set_font_size (cr, 1.0);
 	cairo_set_font_options (cr, &scaled_font->base.options);
 
-	status = face->scaled_font_methods.render_glyph ((cairo_scaled_font_t *)scaled_font,
-							 _cairo_scaled_glyph_index(scaled_glyph),
-							 cr, &extents);
+	if (face->scaled_font_methods.render_glyph)
+	    status = face->scaled_font_methods.render_glyph ((cairo_scaled_font_t *)scaled_font,
+							     _cairo_scaled_glyph_index(scaled_glyph),
+							     cr, &extents);
+	else
+	    status = CAIRO_STATUS_USER_FONT_ERROR;
 
 	if (status == CAIRO_STATUS_SUCCESS)
 	    status = cairo_status (cr);
commit 50e6957e8089f9f0db36b1e44249f41041cf405d
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 28 19:31:51 2008 -0400

    [user-font] Remove completed TODO item
    
    The user-font-proxy test case already does this.

diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index 07a98b1..b1b5b03 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -61,8 +61,6 @@ typedef struct _cairo_user_scaled_font {
     cairo_text_extents_t default_glyph_extents;
 } cairo_user_scaled_font_t;
 
-/* TODO test user fonts using other fonts in the render_glyph */
-
 /* #cairo_user_scaled_font_t */
 
 static const cairo_scaled_font_backend_t cairo_user_scaled_font_backend;
commit f2b385558b185a723ae0043ad1381621c17318d8
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 28 19:30:39 2008 -0400

    [cairo-user-font] Add comment about possibly doing metrics-hinting

diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index ac5d2ab..07a98b1 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -157,6 +157,8 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 	    extents.height    = (y2 - y1) * y_scale;
 	}
 
+	/* XXX round advance to device-space-ints if metrics-hinting enabled? */
+
 	_cairo_scaled_glyph_set_metrics (scaled_glyph,
 					 &scaled_font->base,
 					 &extents);
commit 9b1cbcde3272dac176bd9184ceb21c953c30517d
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 28 19:27:58 2008 -0400

    [user-font] Handle antialiasing font option

diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index 5fac368..ac5d2ab 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -80,9 +80,12 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 	cairo_user_font_face_t *face =
 	    (cairo_user_font_face_t *) scaled_font->base.font_face;
 	cairo_text_extents_t extents = scaled_font->default_glyph_extents;
+	cairo_content_t content = scaled_font->base.options.antialias == CAIRO_ANTIALIAS_SUBPIXEL ?
+									 CAIRO_CONTENT_COLOR_ALPHA :
+									 CAIRO_CONTENT_ALPHA;
 	cairo_t *cr;
 
-	meta_surface = _cairo_meta_surface_create (CAIRO_CONTENT_COLOR_ALPHA, -1, -1);
+	meta_surface = _cairo_meta_surface_create (content, -1, -1);
 	cr = cairo_create (meta_surface);
 
 	cairo_set_matrix (cr, &scaled_font->base.scale);
@@ -162,18 +165,28 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
     if (info & CAIRO_SCALED_GLYPH_INFO_SURFACE) {
 	cairo_surface_t	*surface;
 	cairo_status_t status = CAIRO_STATUS_SUCCESS;
+	cairo_format_t format;
 	int width, height;
 
-	/* TODO: extend the glyph cache to support argb glyphs */
+	/* TODO
+	 * extend the glyph cache to support argb glyphs.
+	 * need to figure out the semantics and interaction with subpixel
+	 * rendering first.
+	 */
 
 	width = _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.x) -
 	  _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.x);
 	height = _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.y) -
 	  _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.y);
 
-	/* XXX handle / figure out antialias/subpixel font options to choose
-	 * the right format here? */
-	surface = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
+	switch (scaled_font->base.options.antialias) {
+	default:
+	case CAIRO_ANTIALIAS_DEFAULT:
+	case CAIRO_ANTIALIAS_GRAY:	format = CAIRO_FORMAT_A8;	break;
+	case CAIRO_ANTIALIAS_NONE:	format = CAIRO_FORMAT_A1;	break;
+	case CAIRO_ANTIALIAS_SUBPIXEL:	format = CAIRO_FORMAT_ARGB32;	break;
+	}
+	surface = cairo_image_surface_create (format, width, height);
 
 	cairo_surface_set_device_offset (surface,
 	                                 - _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.x),
commit e8e23862333f4be69e2afd9ee41c9a27817f9659
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 28 19:10:09 2008 -0400

    Remove some bogus XXX marks
    
    These are all perfectly correct code.  Most are simply there because when
    we support vertical text writing mode we need to update there, but that's
    pretty trivial.  No special markers needed.
    
    /me is trying to make user-font clean of XXX and TODO marks

diff --git a/src/cairo-arc.c b/src/cairo-arc.c
index eed75e7..2b36809 100644
--- a/src/cairo-arc.c
+++ b/src/cairo-arc.c
@@ -190,7 +190,6 @@ _cairo_arc_in_direction (cairo_t	  *cr,
     /* Recurse if drawing arc larger than pi */
     if (angle_max - angle_min > M_PI) {
 	double angle_mid = angle_min + (angle_max - angle_min) / 2.0;
-	/* XXX: Something tells me this block could be condensed. */
 	if (dir == CAIRO_DIRECTION_FORWARD) {
 	    _cairo_arc_in_direction (cr, xc, yc, radius,
 				     angle_min, angle_mid,
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 649aad0..3e3f2a2 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -601,7 +601,7 @@ _compute_transform (cairo_ft_font_transform_t *sf,
 
     status = _cairo_matrix_compute_scale_factors (scale,
 						  &x_scale, &y_scale,
-						  /* XXX */ 1);
+						  1);
     if (status)
 	return status;
 
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index e401f8f..33ee9af 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -675,7 +675,7 @@ _cairo_scaled_font_set_metrics (cairo_scaled_font_t	    *scaled_font,
 
     status = _cairo_matrix_compute_scale_factors (&scaled_font->font_matrix,
 						  &font_scale_x, &font_scale_y,
-						  /* XXX */ 1);
+						  1);
     if (status)
 	return status;
 
@@ -1957,7 +1957,7 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
 	}
 
 	_cairo_scaled_glyph_set_index(scaled_glyph, index);
-	scaled_glyph->cache_entry.size = 1;	/* XXX */
+	scaled_glyph->cache_entry.size = 1;	/* We currently don't differentiate on glyph size at all */
 	scaled_glyph->scaled_font = scaled_font;
 	scaled_glyph->surface = NULL;
 	scaled_glyph->path = NULL;
diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index 887e37a..5fac368 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -127,7 +127,7 @@ _cairo_user_scaled_glyph_init (void			 *abstract_font,
 	     * representation. */
 
 	    matrix = scaled_font->base.scale_inverse;
-	    status = _cairo_matrix_compute_scale_factors (&matrix, &x_scale, &y_scale, /* XXX */ 1);
+	    status = _cairo_matrix_compute_scale_factors (&matrix, &x_scale, &y_scale, 1);
 	    if (status)
 		return status;
 
@@ -356,7 +356,7 @@ _cairo_user_font_face_scaled_font_create (void                        *abstract_
         user_scaled_font->default_glyph_extents.width = 0.;
         user_scaled_font->default_glyph_extents.height = font_extents.ascent + font_extents.descent;
         user_scaled_font->default_glyph_extents.x_advance = font_extents.max_x_advance;
-        user_scaled_font->default_glyph_extents.y_advance = 0.; /* XXX */
+        user_scaled_font->default_glyph_extents.y_advance = 0.;
 
 	*scaled_font = &user_scaled_font->base;
     }


More information about the cairo-commit mailing list