From 6946d656014f3a297e8a3cf1ef4f0e3c7f321a32 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 24 Feb 2009 17:53:31 +0100 Subject: [PATCH] Bug 445087; add extra pixel on each side of the glyph's black box returned by GetGlyphOutlineW, to avoid clipping ClearType pixels; r=(roc + vladimir) sr=roc --- gfx/cairo/README | 2 ++ gfx/cairo/cairo/src/cairo-win32-font.c | 13 +++++++++++++ gfx/cairo/win32-cleartype-clipping.patch | 23 +++++++++++++++++++++++ layout/reftests/bugs/reftest.list | 2 +- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 gfx/cairo/win32-cleartype-clipping.patch diff --git a/gfx/cairo/README b/gfx/cairo/README index 5495bd0de18..78ff76547df 100644 --- a/gfx/cairo/README +++ b/gfx/cairo/README @@ -48,6 +48,8 @@ ignore-rank0.patch: bug 474886; Not redrawing the background when changing page win32-canvas-glyph-position.patch: bug 475092; horizontal positioning errors when drawing glyph runs with delta-y offsets to canvas through win32-font +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 diff --git a/gfx/cairo/cairo/src/cairo-win32-font.c b/gfx/cairo/cairo/src/cairo-win32-font.c index 3d06b3053d1..654684046e6 100644 --- a/gfx/cairo/cairo/src/cairo-win32-font.c +++ b/gfx/cairo/cairo/src/cairo-win32-font.c @@ -986,6 +986,19 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f &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 { + 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); if (status) diff --git a/gfx/cairo/win32-cleartype-clipping.patch b/gfx/cairo/win32-cleartype-clipping.patch new file mode 100644 index 00000000000..839e9403917 --- /dev/null +++ b/gfx/cairo/win32-cleartype-clipping.patch @@ -0,0 +1,23 @@ +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,19 @@ _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 { ++ 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); + if (status) diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index 01f6547953f..25cb61e8c76 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -439,7 +439,7 @@ random-if(MOZ_WIDGET_TOOLKIT=="gtk2") == 333970-1.html 333970-1-ref.html # bug 3 == 352980-3f.html 352980-3-ref.html == 355548-1.xml 355548-1-ref.xml == 355548-2.xml 355548-2-ref.xml -== 355548-3.xml 355548-3-ref.xml +fails-if(MOZ_WIDGET_TOOLKIT=="windows") == 355548-3.xml 355548-3-ref.xml # see bug 445087 == 355548-4.xml 355548-4-ref.xml == 355548-5.xml 355548-5-ref.xml fails-if(MOZ_WIDGET_TOOLKIT=="cocoa") == 356774-1.html 356774-1-ref.html # probably bug 379317