Bug 445087. Add extra pixel on each side of the glyph's black box returned by GetGlyphOutlineW, to avoid clipping ClearType pixels. r=vlad
☠☠ backed out by c1dabe868c32 ☠ ☠
authorJonathan Kew <jfkthame@gmail.com>
Thu, 05 Feb 2009 21:06:14 +1300
changeset 24658 d679ac3a8de0c6de7339056d80c7d0470b7c0a95
parent 24657 ba595db2b681d7f5554f6235c2dc0f2cadb4e87a
child 24659 d7119b967560999f59a02dc7028510037e8e1397
child 24677 c1dabe868c329e83fc95183ba931d0da48e7d865
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad
bugs445087
milestone1.9.2a1pre
Bug 445087. Add extra pixel on each side of the glyph's black box returned by GetGlyphOutlineW, to avoid clipping ClearType pixels. r=vlad
gfx/cairo/README
gfx/cairo/cairo/src/cairo-win32-font.c
gfx/cairo/win32-cleartype-clipping.patch
--- a/gfx/cairo/README
+++ b/gfx/cairo/README
@@ -39,15 +39,17 @@ wince-fixes.patch: stubs out win32 funct
 ft-done-face.patch: bug 467874; only destroy FT_Faces created by cairo
 
 wince-fontconfig.patch: bug 462908; fixes required to compile for windows ce.  Also allows for building without fontconfig
 
 glyph-safety-margin.patch: Change the glyph dropping safety margin from 2em to 10em for bug 460023.  Upstream commit: 28a72648ba7abe02ebd4df7234424e333b85dc9c.
 
 win32-vertically-offset-glyph.patch: bug 454098; vertical positioning errors when drawing glyph runs including delta-y offsets on screen via GDI
 
+win32-cleartype-clipping.patch: bug 445087; some glyphs are clipped, mainly on right-hand edge, when ClearType is enabled and drawing to RGBA canvas
+
 ==== pixman patches ====
 
 endian.patch: include cairo-platform.h for endian macros
 
 ==== disable printing patch ====
 
 disable-printing.patch:  allows us to use NS_PRINTING to disable printing.
--- a/gfx/cairo/cairo/src/cairo-win32-font.c
+++ b/gfx/cairo/cairo/src/cairo-win32-font.c
@@ -981,16 +981,26 @@ static cairo_status_t
 	if (status)
 	    return status;
 
 	if (GetGlyphOutlineW (hdc, _cairo_scaled_glyph_index (scaled_glyph),
 			      GGO_METRICS | GGO_GLYPH_INDEX,
 			      &metrics, 0, NULL, &matrix) == GDI_ERROR) {
 	  status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_init_glyph_metrics:GetGlyphOutlineW");
 	  memset (&metrics, 0, sizeof (GLYPHMETRICS));
+	} else {
+	    /* 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,
+	     * therefore, we add a pixel of "slop" to left side of the nominal "black" area,
+	     * 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);
 	if (status)
 	    return status;
 
 	if (scaled_font->swap_axes) {
 	    extents.x_bearing = - metrics.gmptGlyphOrigin.y / scaled_font->y_scale;
 	    extents.y_bearing = metrics.gmptGlyphOrigin.x / scaled_font->x_scale;
new file mode 100644
--- /dev/null
+++ b/gfx/cairo/win32-cleartype-clipping.patch
@@ -0,0 +1,20 @@
+diff --git a/gfx/cairo/cairo/src/cairo-win32-font.c b/gfx/cairo/cairo/src/cairo-win32-font.c
+--- a/gfx/cairo/cairo/src/cairo-win32-font.c
++++ b/gfx/cairo/cairo/src/cairo-win32-font.c
+@@ -986,6 +986,16 @@ _cairo_win32_scaled_font_init_glyph_metr
+ 			      &metrics, 0, NULL, &matrix) == GDI_ERROR) {
+ 	  status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_init_glyph_metrics:GetGlyphOutlineW");
+ 	  memset (&metrics, 0, sizeof (GLYPHMETRICS));
++	} else {
++	    /* 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,
++	     * therefore, we add a pixel of "slop" to left side of the nominal "black" area,
++	     * 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);
+ 	if (status)