bug 475968 - add padding pixels to loose ink bounds on Windows because of ClearType pixel bleed. r=roc
authorJonathan Kew <jfkthame@gmail.com>
Wed, 22 Jun 2011 09:49:53 +0100
changeset 71764 2c2b3ebca177d6de911e4d32169c5a6994f6f7ad
parent 71763 02f8dbc0800524ea8fe9571b5a92f5a932f188a0
child 71765 b5dead3786051808dd3b04005f0f67bf6267a714
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs475968
milestone7.0a1
bug 475968 - add padding pixels to loose ink bounds on Windows because of ClearType pixel bleed. r=roc
gfx/thebes/gfxGDIFont.cpp
gfx/thebes/gfxGDIFont.h
layout/reftests/svg/reftest.list
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -266,16 +266,42 @@ gfxGDIFont::SetupCairoFont(gfxContext *a
         // Don't cairo_set_scaled_font as that would propagate the error to
         // the cairo_t, precluding any further drawing.
         return PR_FALSE;
     }
     cairo_set_scaled_font(aContext->GetCairo(), mScaledFont);
     return PR_TRUE;
 }
 
+gfxFont::RunMetrics
+gfxGDIFont::Measure(gfxTextRun *aTextRun,
+                    PRUint32 aStart, PRUint32 aEnd,
+                    BoundingBoxType aBoundingBoxType,
+                    gfxContext *aRefContext,
+                    Spacing *aSpacing)
+{
+    gfxFont::RunMetrics metrics =
+        gfxFont::Measure(aTextRun, aStart, aEnd,
+                         aBoundingBoxType, aRefContext, aSpacing);
+
+    // if aBoundingBoxType is LOOSE_INK_EXTENTS
+    // and the underlying cairo font may be antialiased,
+    // we can't trust Windows to have considered all the pixels
+    // so we need to add "padding" to the bounds.
+    // (see bugs 475968, 439831, compare also bug 445087)
+    if (aBoundingBoxType == LOOSE_INK_EXTENTS &&
+        mAntialiasOption != kAntialiasNone &&
+        metrics.mBoundingBox.width > 0) {
+        metrics.mBoundingBox.x -= aTextRun->GetAppUnitsPerDevUnit();
+        metrics.mBoundingBox.width += aTextRun->GetAppUnitsPerDevUnit() * 3;
+    }
+
+    return metrics;
+}
+
 void
 gfxGDIFont::Initialize()
 {
     NS_ASSERTION(!mMetrics, "re-creating metrics? this will leak");
 
     LOGFONTW logFont;
 
     if (mAdjustedSize == 0.0) {
--- a/gfx/thebes/gfxGDIFont.h
+++ b/gfx/thebes/gfxGDIFont.h
@@ -68,16 +68,23 @@ public:
 
     /* overrides for the pure virtual methods in gfxFont */
     virtual const gfxFont::Metrics& GetMetrics();
 
     virtual PRUint32 GetSpaceGlyph();
 
     virtual PRBool SetupCairoFont(gfxContext *aContext);
 
+    /* override Measure to add padding for antialiasing */
+    virtual RunMetrics Measure(gfxTextRun *aTextRun,
+                               PRUint32 aStart, PRUint32 aEnd,
+                               BoundingBoxType aBoundingBoxType,
+                               gfxContext *aContextForTightBoundingBox,
+                               Spacing *aSpacing);
+
     /* required for MathML to suppress effects of ClearType "padding" */
     virtual gfxFont* CopyWithAntialiasOption(AntialiasOption anAAOption);
 
     virtual PRBool ProvidesGlyphWidths() { return PR_TRUE; }
 
     // get hinted glyph width in pixels as 16.16 fixed-point value
     virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID);
 
--- a/layout/reftests/svg/reftest.list
+++ b/layout/reftests/svg/reftest.list
@@ -118,20 +118,20 @@ random == dynamic-use-nested-01.svg dyna
 == foreignObject-ancestor-style-change-01.svg foreignObject-ancestor-style-change-01-ref.svg
 == foreignObject-change-transform-01.svg pass.svg
 == foreignObject-display-01.svg pass.svg
 == foreignObject-move-repaint-01.svg pass.svg
 == foreignObject-overflow-01.svg pass.svg
 == foreignObject-start-hidden-01.svg pass.svg # followup from Bug 596765
 == foreignObject-start-hidden-02.svg pass.svg
 == getElementById-a-element-01.svg pass.svg
-fails-if(/^Windows\x20NT\x205\.1/.test(http.oscpu)) == gradient-live-01a.svg gradient-live-01-ref.svg # bug 623403
-fails-if(/^Windows\x20NT\x205\.1/.test(http.oscpu)) == gradient-live-01b.svg gradient-live-01-ref.svg # bug 623403
-fails-if(/^Windows\x20NT\x205\.1/.test(http.oscpu)) == gradient-live-01c.svg gradient-live-01-ref.svg # bug 623403
-fails-if(/^Windows\x20NT\x205\.1/.test(http.oscpu)) == gradient-live-01d.svg gradient-live-01-ref.svg # bug 623403
+== gradient-live-01a.svg gradient-live-01-ref.svg
+== gradient-live-01b.svg gradient-live-01-ref.svg
+== gradient-live-01c.svg gradient-live-01-ref.svg
+== gradient-live-01d.svg gradient-live-01-ref.svg
 fails == inline-in-xul-basic-01.xul pass.svg
 == invalid-text-01.svg pass.svg
 == linearGradient-basic-01.svg pass.svg
 == linearGradient-basic-02.svg pass.svg
 == markers-and-group-opacity-01.svg markers-and-group-opacity-01-ref.svg
 == marker-attribute-01.svg pass.svg
 == marker-viewBox-01.svg marker-viewBox-01-ref.svg
 == mask-basic-01.svg pass.svg