commit 5da77b46ce4e84fe40ef3de74677d472ae3014c5 Author: Brian Ewins Date: Sat Mar 17 01:16:49 2007 +0000 [atsui] fix scaling of glyph metrics Correct remaining user-device unit confusion in _cairo_atsui_font_init_glyph_metrics. diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c index f357e7d..cb2cc74 100644 --- a/src/cairo-atsui-font.c +++ b/src/cairo-atsui-font.c @@ -86,6 +86,7 @@ struct _cairo_atsui_font { Fixed size; CGAffineTransform font_matrix; CGAffineTransform device_to_user_scale; + CGAffineTransform device_to_font_scale; }; struct _cairo_atsui_font_face { @@ -247,6 +248,10 @@ _cairo_atsui_font_create_scaled (cairo_font_face_t *font_face, font->font_matrix = CGAffineTransformMake (1., 0., 0., yscale/xscale, 0., 0.); + font->device_to_font_scale = + CGAffineTransformInvert (CGAffineTransformMake (xscale, 0, + 0, yscale, + 0, 0)); font->size = FloatToFixed (xscale); font->style = CreateSizedCopyOfStyle (style, &font->size, &font->font_matrix); @@ -470,6 +475,7 @@ _cairo_atsui_font_init_glyph_metrics (cairo_atsui_font_t *scaled_font, CGMutablePathRef path; GlyphID theGlyph = _cairo_atsui_scaled_glyph_index (scaled_glyph); double xscale, yscale; + CGPoint device_advance, font_advance; CGRect rect; if (theGlyph == kATSDeletedGlyphcode) { @@ -521,10 +527,19 @@ _cairo_atsui_font_init_glyph_metrics (cairo_atsui_font_t *scaled_font, rect = CGPathGetBoundingBox (path); - extents.x_bearing = rect.origin.x * xscale; - extents.y_bearing = rect.origin.y * yscale; - extents.width = rect.size.width * xscale; - extents.height = rect.size.height * yscale; + /* Scale down to font units.*/ + rect = CGRectApplyAffineTransform (rect, scaled_font->device_to_font_scale); + + device_advance = CGPointMake (metricsH.deviceAdvance.x, metricsH.deviceAdvance.y); + font_advance = CGPointApplyAffineTransform (device_advance, scaled_font->device_to_font_scale); + + extents.x_advance = font_advance.x; + extents.y_advance = 0; + + extents.x_bearing = CGRectGetMinX (rect); + extents.y_bearing = CGRectGetMinY (rect); + extents.width = rect.size.width; + extents.height = rect.size.height; _cairo_scaled_glyph_set_metrics (scaled_glyph, &scaled_font->base,