[cairo] [PATCH]reworked _transform_glyph_bitmap

sunmoon1997 sunmoon1997 at gmail.com
Tue Oct 25 06:58:24 PDT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi,
   I reworked _transform_glyph_bitmap today.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDXjn/uOtwLijeKbwRAm9qAKCaoCRXsd4unqHO+QLfQN0U3S9g8QCfYzCU
mlM/DusWkOYc4Sl9865sb9I=
=dOdP
-----END PGP SIGNATURE-----

-------------- next part --------------
Index: src/cairo-ft-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ft-font.c,v
retrieving revision 1.113
diff -u -p -r1.113 cairo-ft-font.c
--- src/cairo-ft-font.c	2 Sep 2005 03:38:07 -0000	1.113
+++ src/cairo-ft-font.c	25 Oct 2005 13:52:30 -0000
@@ -96,7 +96,8 @@ struct _cairo_ft_unscaled_font {
     double x_scale;		/* Extracted X scale factor */
     double y_scale;             /* Extracted Y scale factor */
     cairo_bool_t have_shape;	/* true if the current scale has a non-scale component*/
-    
+    cairo_matrix_t current_shape;
+
     int lock;		/* count of how many times this font has been locked */
 
     cairo_ft_font_face_t *faces;	/* Linked list of faces for this font */
@@ -618,6 +619,11 @@ _cairo_ft_unscaled_font_set_scale (cairo
 
     unscaled->x_scale = sf.x_scale;
     unscaled->y_scale = sf.y_scale;
+
+    cairo_matrix_init (&unscaled->current_shape,
+		       sf.shape[0][0], sf.shape[0][1],
+		       sf.shape[1][0], sf.shape[1][1],
+		       0.0, 0.0);
 	
     mat.xx = DOUBLE_TO_16_16(sf.shape[0][0]);
     mat.yx = - DOUBLE_TO_16_16(sf.shape[0][1]);
@@ -1087,18 +1093,17 @@ _render_glyph_bitmap (FT_Face		      fac
     return status;
 }
 
-#if 0
-/* XXX */
 static cairo_status_t
-_transform_glyph_bitmap (cairo_image_glyph_cache_entry_t *val)
+_transform_glyph_bitmap (cairo_matrix_t         * shape,
+			 cairo_image_surface_t ** surface)
 {
-    cairo_ft_font_transform_t sf;
     cairo_matrix_t original_to_transformed;
     cairo_matrix_t transformed_to_original;
     cairo_image_surface_t *old_image;
     cairo_surface_t *image;
     double x[4], y[4];
     double origin_x, origin_y;
+    int origin_width, origin_height;
     int i;
     int x_min, y_min, x_max, y_max;
     int width, height;
@@ -1106,26 +1111,26 @@ _transform_glyph_bitmap (cairo_image_gly
     cairo_surface_pattern_t pattern;
     
     /* We want to compute a transform that takes the origin
-     * (val->size.x, val->size.y) to 0,0, then applies the "shape"
-     * portion of the font transform
+     * (x, y) to 0.0, then applies the "shape" portion of
+     * the font transform
      */
-    _compute_transform (&sf, &val->key.scale);
-
-    cairo_matrix_init (&original_to_transformed,
-		       sf.shape[0][0], sf.shape[0][1],
-		       sf.shape[1][0], sf.shape[1][1],
-		       0, 0);
+    original_to_transformed = *shape;
+    
+    origin_x = (*surface)->base.device_x_offset;
+    origin_y = (*surface)->base.device_y_offset;
+    origin_width = cairo_image_surface_get_width (&(*surface)->base);
+    origin_height = cairo_image_surface_get_height (&(*surface)->base);
 
     cairo_matrix_translate (&original_to_transformed,
-			    val->size.x, val->size.y);
+			    origin_x, origin_y);
 
     /* Find the bounding box of the original bitmap under that
      * transform
      */
-    x[0] = 0;               y[0] = 0;
-    x[1] = val->size.width; y[1] = 0;
-    x[2] = val->size.width; y[2] = val->size.height;
-    x[3] = 0;               y[3] = val->size.height;
+    x[0] = 0;            y[0] = 0;
+    x[1] = origin_width; y[1] = 0;
+    x[2] = origin_width; y[2] = origin_height;
+    x[3] = 0;            y[3] = origin_height;
 
     for (i = 0; i < 4; i++)
       cairo_matrix_transform_point (&original_to_transformed,
@@ -1188,11 +1193,11 @@ _transform_glyph_bitmap (cairo_image_gly
 
     _cairo_pattern_fini (&pattern.base);
 
-    /* Now update the cache entry for the new bitmap, recomputing
+    /* Now update the glyph for the new bitmap, recomputing
      * the origin based on the final transform.
      */
-    origin_x = - val->size.x;
-    origin_y = - val->size.y;
+    origin_x = - origin_x;
+    origin_y = - origin_y;
     cairo_matrix_transform_point (&original_to_transformed,
 				  &origin_x, &origin_y);
 
@@ -1200,14 +1205,11 @@ _transform_glyph_bitmap (cairo_image_gly
     (*surface) = (cairo_image_surface_t *)image;
     cairo_surface_destroy (&old_image->base);
 
-    val->size.width = width;
-    val->size.height = height;
-    val->size.x = - floor (origin_x + 0.5);
-    val->size.y = - floor (origin_y + 0.5);
-    
+    (*surface)->base.device_x_offset = - floor (origin_x + 0.5);
+    (*surface)->base.device_y_offset = - floor (origin_y + 0.5);
+
     return status;
 }
-#endif
 
 static const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend = {
     _cairo_ft_unscaled_font_destroy,
@@ -1821,9 +1823,14 @@ _cairo_ft_scaled_glyph_init (void			*abs
 	if (glyph->format == FT_GLYPH_FORMAT_OUTLINE)
 	    status = _render_glyph_outline (face, &scaled_font->base.options,
 					    &surface);
-	else
+	else {
 	    status = _render_glyph_bitmap (face, &scaled_font->base.options,
 					   &surface);
+	    if (!status && unscaled->have_shape)
+		status = _transform_glyph_bitmap (&unscaled->current_shape,
+						  &surface);
+	}
+
 	if (status) {
 	    cairo_ft_scaled_font_unlock_face (abstract_font);
 	    return status;


More information about the cairo mailing list