[cairo-commit] src/cairo-atsui-font.c

Brian Ewins brianewins at kemper.freedesktop.org
Sun Jan 7 17:09:31 PST 2007


 src/cairo-atsui-font.c |   94 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 66 insertions(+), 28 deletions(-)

New commits:
diff-tree 9a005c6221cc279e65d94956c74028a84baf1716 (from 58265f3508959298eabab55ec28dc6d9516eedc3)
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date:   Thu Jan 4 02:09:16 2007 +0000

    [ATSUI] correct the rotation of glyph paths. (#9378)
    
    This fixes a bug visible in the text-rotate test when 
    CAIRO_TEST_GENERATE_REFERENCE_IMAGE is defined. 

diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index 43d4e50..087f4bf 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -63,6 +63,7 @@
 
 typedef struct _cairo_atsui_font_face cairo_atsui_font_face_t;
 typedef struct _cairo_atsui_font cairo_atsui_font_t;
+typedef struct _cairo_atsui_scaled_path cairo_atsui_scaled_path_t;
 
 static cairo_status_t _cairo_atsui_font_create_scaled (cairo_font_face_t *font_face,
 						       ATSUFontID font_id,
@@ -85,6 +86,11 @@ struct _cairo_atsui_font_face {
   ATSUFontID font_id;
 };
 
+struct _cairo_atsui_scaled_path {
+    cairo_path_fixed_t *path;
+    cairo_matrix_t *scale;
+};
+
 static void
 _cairo_atsui_font_face_destroy (void *abstract_face)
 {
@@ -508,12 +514,15 @@ static OSStatus
 _move_to (const Float32Point *point,
 	  void *callback_data)
 {
-    cairo_path_fixed_t *path = callback_data;
-
-    _cairo_path_fixed_close_path (path);
-    _cairo_path_fixed_move_to (path,
-			       _cairo_fixed_from_double(point->x),
-			       _cairo_fixed_from_double(point->y));
+    cairo_atsui_scaled_path_t *scaled_path = callback_data;
+    double x = point->x;
+    double y = point->y;
+    
+    cairo_matrix_transform_point (scaled_path->scale, &x, &y);
+    _cairo_path_fixed_close_path (scaled_path->path);
+    _cairo_path_fixed_move_to (scaled_path->path,
+			       _cairo_fixed_from_double (x),
+			       _cairo_fixed_from_double (y));
 
     return noErr;
 }
@@ -522,11 +531,15 @@ static OSStatus
 _line_to (const Float32Point *point,
 	  void *callback_data)
 {
-    cairo_path_fixed_t *path = callback_data;
-
-    _cairo_path_fixed_line_to (path,
-			       _cairo_fixed_from_double(point->x),
-			       _cairo_fixed_from_double(point->y));
+    cairo_atsui_scaled_path_t *scaled_path = callback_data;
+    double x = point->x;
+    double y = point->y;
+    
+    cairo_matrix_transform_point (scaled_path->scale, &x, &y);
+
+    _cairo_path_fixed_line_to (scaled_path->path,
+			       _cairo_fixed_from_double (x),
+			       _cairo_fixed_from_double (y));
 
     return noErr;
 }
@@ -537,15 +550,25 @@ _curve_to (const Float32Point *point1,
 	   const Float32Point *point3,
 	   void *callback_data)
 {
-    cairo_path_fixed_t *path = callback_data;
-
-    _cairo_path_fixed_curve_to (path,
-				_cairo_fixed_from_double(point1->x),
-				_cairo_fixed_from_double(point1->y),
-				_cairo_fixed_from_double(point2->x),
-				_cairo_fixed_from_double(point2->y),
-				_cairo_fixed_from_double(point3->x),
-				_cairo_fixed_from_double(point3->y));
+    cairo_atsui_scaled_path_t *scaled_path = callback_data;
+    double x1 = point1->x;
+    double y1 = point1->y;
+    double x2 = point2->x;
+    double y2 = point2->y;
+    double x3 = point3->x;
+    double y3 = point3->y;
+    
+    cairo_matrix_transform_point (scaled_path->scale, &x1, &y1);
+    cairo_matrix_transform_point (scaled_path->scale, &x2, &y2);
+    cairo_matrix_transform_point (scaled_path->scale, &x3, &y3);
+
+    _cairo_path_fixed_curve_to (scaled_path->path,
+				_cairo_fixed_from_double (x1),
+				_cairo_fixed_from_double (y1),
+				_cairo_fixed_from_double (x2),
+				_cairo_fixed_from_double (y2),
+				_cairo_fixed_from_double (x3),
+				_cairo_fixed_from_double (y3));
 
     return noErr;
 }
@@ -554,9 +577,9 @@ static OSStatus
 _close_path (void *callback_data)
 
 {
-    cairo_path_fixed_t *path = callback_data;
+    cairo_atsui_scaled_path_t *scaled_path = callback_data;
 
-    _cairo_path_fixed_close_path (path);
+    _cairo_path_fixed_close_path (scaled_path->path);
 
     return noErr;
 }
@@ -570,10 +593,24 @@ _cairo_atsui_scaled_font_init_glyph_path
     static ATSCubicCurveToUPP curveProc = NULL;
     static ATSCubicClosePathUPP closePathProc = NULL;
     OSStatus err;
-    cairo_path_fixed_t *path;
-
-    path = _cairo_path_fixed_create ();
-    if (!path)
+    cairo_atsui_scaled_path_t scaled_path;
+    cairo_matrix_t *font_to_device = &scaled_font->base.scale;
+    cairo_matrix_t unscaled_font_to_device;
+    double xscale;
+    double yscale;
+    
+    /* extract the rotation/shear component of the scale matrix. */
+    _cairo_matrix_compute_scale_factors (font_to_device, &xscale, &yscale, 1);
+    cairo_matrix_init (&unscaled_font_to_device, 
+		      font_to_device->xx, 
+		      font_to_device->yx, 
+		      font_to_device->xy, 
+		      font_to_device->yy, 0., 0.);
+    cairo_matrix_scale (&unscaled_font_to_device, 1.0/xscale, 1.0/yscale);
+
+    scaled_path.scale = &unscaled_font_to_device;
+    scaled_path.path = _cairo_path_fixed_create ();
+    if (!scaled_path.path)
 	return CAIRO_STATUS_NO_MEMORY;
 
     if (moveProc == NULL) {
@@ -588,9 +625,10 @@ _cairo_atsui_scaled_font_init_glyph_path
 				 moveProc,
 				 lineProc,
 				 curveProc,
-				 closePathProc, (void *)path, &err);
+				 closePathProc, (void *)&scaled_path, &err);
 
-    _cairo_scaled_glyph_set_path (scaled_glyph, &scaled_font->base, path);
+    _cairo_scaled_glyph_set_path (scaled_glyph, &scaled_font->base, 
+				  scaled_path.path);
 
     return CAIRO_STATUS_SUCCESS;
 }


More information about the cairo-commit mailing list