[cairo] cairo_text_extents() wrong on win32 for transformed context

Tim Rowley tim.rowley at gmail.com
Tue Jun 14 13:58:45 PDT 2005


On 6/13/05, T Rowley <tor at cs.brown.edu> wrote:
> I've been having a problem with cairo_text_extents on win32 (cairo
> 0.5.0).  With a translated context it returns the correct results, but
> with on a context with a rotation or skew matrix set, the resulting box
> has some transformation I haven't been able to discern.  The same code
> works fine on linux and the boxes are as expected.

The problem seems to be that the y_bearing was flipped.  This seems to
give correct boxes in my testing, but might not be a complete
solution:

Index: cairo-win32-font.c
===================================================================
RCS file: /cvsroot/mozilla/gfx/cairo/cairo/src/cairo-win32-font.c,v
retrieving revision 1.1
diff -u -8 -p -r1.1 cairo-win32-font.c
--- cairo-win32-font.c	4 Jun 2005 07:03:27 -0000	1.1
+++ cairo-win32-font.c	14 Jun 2005 20:53:37 -0000
@@ -709,17 +709,17 @@ _cairo_win32_scaled_font_glyph_extents (
 	 * of the font.
 	 */
 	status = _cairo_win32_scaled_font_select_unscaled_font
(&scaled_font->base, hdc);
 	GetGlyphOutlineW (hdc, glyphs[0].index, GGO_METRICS | GGO_GLYPH_INDEX,
 			  &metrics, 0, NULL, &matrix);
 	_cairo_win32_scaled_font_done_unscaled_font (&scaled_font->base);
 
 	extents->x_bearing = (double)metrics.gmptGlyphOrigin.x /
scaled_font->em_square;
-	extents->y_bearing = (double)metrics.gmptGlyphOrigin.y /
scaled_font->em_square;
+	extents->y_bearing = - (double)metrics.gmptGlyphOrigin.y /
scaled_font->em_square;
 	extents->width = (double)metrics.gmBlackBoxX / scaled_font->em_square;
 	extents->height = (double)metrics.gmBlackBoxY / scaled_font->em_square;
 	extents->x_advance = (double)metrics.gmCellIncX / scaled_font->em_square;
 	extents->y_advance = (double)metrics.gmCellIncY / scaled_font->em_square;
     }
 
     return CAIRO_STATUS_SUCCESS;
 }



More information about the cairo mailing list