An additional rotation was being applied to atsui text output, but not to the same glyphs rendered from their extracted paths. --- commit e3b7a707d4562c308b97a0ec2662ae5a7d3a2272 tree dae0167743da535c9030b3ed73eea73c75d14461 parent 80a69892d7b438b33927aa9ef1a7228ada9accbc author Brian Ewins Sun, 17 Dec 2006 16:21:27 +0000 committer Brian Ewins Sun, 17 Dec 2006 16:21:27 +0000 src/cairo-atsui-font.c | 87 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c index 423141d..d24dd16 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_callback_data cairo_atsui_callback_data_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_callback_data { + cairo_path_fixed_t *path; + cairo_matrix_t *rotation; +}; + static void _cairo_atsui_font_face_destroy (void *abstract_face) { @@ -406,12 +412,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_callback_data_t *data = callback_data; + double x = point->x; + double y = point->y; + + cairo_matrix_transform_point(data->rotation, &x, &y); + _cairo_path_fixed_close_path (data->path); + _cairo_path_fixed_move_to (data->path, + _cairo_fixed_from_double(x), + _cairo_fixed_from_double(y)); return noErr; } @@ -420,11 +429,15 @@ static OSStatus _line_to (const Float32Point *point, void *callback_data) { - cairo_path_fixed_t *path = callback_data; + cairo_atsui_callback_data_t *data = callback_data; + double x = point->x; + double y = point->y; + + cairo_matrix_transform_point(data->rotation, &x, &y); - _cairo_path_fixed_line_to (path, - _cairo_fixed_from_double(point->x), - _cairo_fixed_from_double(point->y)); + _cairo_path_fixed_line_to (data->path, + _cairo_fixed_from_double(x), + _cairo_fixed_from_double(y)); return noErr; } @@ -435,15 +448,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_callback_data_t *data = 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(data->rotation, &x1, &y1); + cairo_matrix_transform_point(data->rotation, &x2, &y2); + cairo_matrix_transform_point(data->rotation, &x3, &y3); + + _cairo_path_fixed_curve_to (data->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; } @@ -452,9 +475,9 @@ static OSStatus _close_path (void *callback_data) { - cairo_path_fixed_t *path = callback_data; + cairo_atsui_callback_data_t *data = callback_data; - _cairo_path_fixed_close_path (path); + _cairo_path_fixed_close_path (data->path); return noErr; } @@ -468,10 +491,20 @@ _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_callback_data_t data; + cairo_matrix_t *scale = &scaled_font->base.scale; + cairo_matrix_t rotation; + double xscale; + double yscale; + + /* extract the rotation component of the scale matrix. */ + cairo_matrix_init(&rotation, scale->xx, scale->yx, scale->xy, scale->yy, 0., 0.); + _cairo_matrix_compute_scale_factors(&rotation, &xscale, &yscale, 1); + cairo_matrix_scale(&rotation, 1.0/xscale, 1.0/yscale); + + data.rotation = &rotation; + data.path = _cairo_path_fixed_create (); + if (!data.path) return CAIRO_STATUS_NO_MEMORY; if (moveProc == NULL) { @@ -486,9 +519,9 @@ _cairo_atsui_scaled_font_init_glyph_path moveProc, lineProc, curveProc, - closePathProc, (void *)path, &err); + closePathProc, (void *)&data, &err); - _cairo_scaled_glyph_set_path (scaled_glyph, &scaled_font->base, path); + _cairo_scaled_glyph_set_path (scaled_glyph, &scaled_font->base, data.path); return CAIRO_STATUS_SUCCESS; }