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

Jeff Muizelaar jrmuizel at kemper.freedesktop.org
Tue May 11 12:12:43 PDT 2010


 src/cairo-win32-font.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)

New commits:
commit 35307fc66f649cc042ec07b7b79277d7ee5987f3
Author: Jonathan Kew <jfkthame at gmail.com>
Date:   Tue May 11 15:12:01 2010 -0400

    win32: Grow glyph extents to account for ClearType
    
    Add extra pixel on each side of the glyph's black box returned by
    GetGlyphOutlineW, to avoid clipping ClearType pixels.
    
    From https://bugzilla.mozilla.org/show_bug.cgi?id=445087

diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index 596ca25..cb253dd 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -979,6 +979,19 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f
 			      GGO_METRICS | GGO_GLYPH_INDEX,
 			      &metrics, 0, NULL, &matrix) == GDI_ERROR) {
 	    memset (&metrics, 0, sizeof (GLYPHMETRICS));
+	} else {
+	    if (metrics.gmBlackBoxX > 0 && scaled_font->base.options.antialias != CAIRO_ANTIALIAS_NONE) {
+		/* The bounding box reported by Windows supposedly contains the glyph's "black" area;
+		 * however, antialiasing (especially with ClearType) means that the actual image that
+		 * needs to be rendered may "bleed" into the adjacent pixels, mainly on the right side.
+		 * To avoid clipping the glyphs when drawn by _cairo_surface_fallback_show_glyphs,
+		 * for example, or other code that uses glyph extents to determine the area to update,
+		 * we add a pixel of "slop" to left side of the nominal "black" area returned by GDI,
+		 * and two pixels to the right (as tests show some glyphs bleed into this column).
+		 */
+		metrics.gmptGlyphOrigin.x -= 1;
+		metrics.gmBlackBoxX += 3;
+	    }
 	}
 	cairo_win32_scaled_font_done_font (&scaled_font->base);
 


More information about the cairo-commit mailing list