diff --git a/gfx/thebes/gfxDWriteFonts.cpp b/gfx/thebes/gfxDWriteFonts.cpp index 2d1a39e3a6f..e31bfd4c97b 100644 --- a/gfx/thebes/gfxDWriteFonts.cpp +++ b/gfx/thebes/gfxDWriteFonts.cpp @@ -481,27 +481,37 @@ gfxDWriteFont::GetFontTable(PRUint32 aTag) } PRInt32 -gfxDWriteFont::GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID) +gfxDWriteFont::GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID) { if (!mGlyphWidths.IsInitialized()) { mGlyphWidths.Init(200); } - PRInt32 width; + PRInt32 width = -1; if (mGlyphWidths.Get(aGID, &width)) { return width; } DWRITE_GLYPH_METRICS glyphMetrics; - HRESULT hr = mFontFace->GetGdiCompatibleGlyphMetrics( + HRESULT hr; + if (mUsingClearType) { + hr = mFontFace->GetDesignGlyphMetrics( + &aGID, 1, &glyphMetrics, FALSE); + if (SUCCEEDED(hr)) { + width = + NS_lround(glyphMetrics.advanceWidth * mFUnitsConvFactor * + 65536.0); + } + } else { + hr = mFontFace->GetGdiCompatibleGlyphMetrics( GetAdjustedSize(), 1.0f, nsnull, FALSE, &aGID, 1, &glyphMetrics, FALSE); - - if (NS_SUCCEEDED(hr)) { - width = NS_lround(glyphMetrics.advanceWidth * mFUnitsConvFactor) << 16; - mGlyphWidths.Put(aGID, width); - return width; + if (SUCCEEDED(hr)) { + width = + NS_lround(glyphMetrics.advanceWidth * mFUnitsConvFactor) << 16; + } } - return -1; + mGlyphWidths.Put(aGID, width); + return width; } diff --git a/gfx/thebes/gfxDWriteFonts.h b/gfx/thebes/gfxDWriteFonts.h index 9334caeac98..d382c1143b9 100644 --- a/gfx/thebes/gfxDWriteFonts.h +++ b/gfx/thebes/gfxDWriteFonts.h @@ -79,13 +79,16 @@ public: // use DWrite API to get direct access to system font data virtual hb_blob_t *GetFontTable(PRUint32 aTag); - virtual PRBool ProvidesHintedWidths() const { - return !mUsingClearType; + virtual PRBool ProvidesGlyphWidths() const { + return !mUsingClearType || + (mFontFace->GetSimulations() & DWRITE_FONT_SIMULATIONS_BOLD); } - virtual PRInt32 GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID); + virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID); protected: + friend class gfxDWriteShaper; + virtual void CreatePlatformShaper(); void ComputeMetrics(); diff --git a/gfx/thebes/gfxDWriteShaper.cpp b/gfx/thebes/gfxDWriteShaper.cpp index 85654fa0a82..46ee2d75da9 100644 --- a/gfx/thebes/gfxDWriteShaper.cpp +++ b/gfx/thebes/gfxDWriteShaper.cpp @@ -175,7 +175,7 @@ trymoreglyphs: continue; } - if (mFont->ProvidesHintedWidths()) { + if (!static_cast(mFont)->mUsingClearType) { hr = analyzer->GetGdiCompatibleGlyphPlacements( aString + range.start, clusters.Elements(), diff --git a/gfx/thebes/gfxFT2FontBase.cpp b/gfx/thebes/gfxFT2FontBase.cpp index 53ada1cc686..269356c4f03 100644 --- a/gfx/thebes/gfxFT2FontBase.cpp +++ b/gfx/thebes/gfxFT2FontBase.cpp @@ -216,7 +216,7 @@ gfxFT2FontBase::GetGlyph(PRUint32 unicode, PRUint32 variation_selector) } PRInt32 -gfxFT2FontBase::GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID) +gfxFT2FontBase::GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID) { cairo_text_extents_t extents; GetGlyphExtents(aGID, &extents); diff --git a/gfx/thebes/gfxFT2FontBase.h b/gfx/thebes/gfxFT2FontBase.h index 916efa389b8..3207a8d3121 100644 --- a/gfx/thebes/gfxFT2FontBase.h +++ b/gfx/thebes/gfxFT2FontBase.h @@ -63,8 +63,8 @@ public: virtual hb_blob_t *GetFontTable(PRUint32 aTag); virtual PRBool ProvidesGetGlyph() const { return PR_TRUE; } virtual PRUint32 GetGlyph(PRUint32 unicode, PRUint32 variation_selector); - virtual PRBool ProvidesHintedWidths() const { return PR_TRUE; } - virtual PRInt32 GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID); + virtual PRBool ProvidesGlyphWidths() const { return PR_TRUE; } + virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID); cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; }; virtual PRBool SetupCairoFont(gfxContext *aContext); diff --git a/gfx/thebes/gfxFont.h b/gfx/thebes/gfxFont.h index eae828a8e9b..38477a7a99c 100644 --- a/gfx/thebes/gfxFont.h +++ b/gfx/thebes/gfxFont.h @@ -1009,16 +1009,16 @@ public: return 0; } - // subclasses may provide hinted glyph widths (in font units); + // subclasses may provide (possibly hinted) glyph widths (in font units); // if they do not override this, harfbuzz will use unhinted widths // derived from the font tables - virtual PRBool ProvidesHintedWidths() const { + virtual PRBool ProvidesGlyphWidths() const { return PR_FALSE; } // The return value is interpreted as a horizontal advance in 16.16 fixed // point format. - virtual PRInt32 GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID) { + virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID) { return -1; } diff --git a/gfx/thebes/gfxGDIFont.cpp b/gfx/thebes/gfxGDIFont.cpp index ff7e84c4e7b..9012a9398c1 100644 --- a/gfx/thebes/gfxGDIFont.cpp +++ b/gfx/thebes/gfxGDIFont.cpp @@ -476,7 +476,7 @@ gfxGDIFont::FillLogFont(LOGFONTW& aLogFont, gfxFloat aSize) } PRInt32 -gfxGDIFont::GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID) +gfxGDIFont::GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID) { if (!mGlyphWidths.IsInitialized()) { mGlyphWidths.Init(200); diff --git a/gfx/thebes/gfxGDIFont.h b/gfx/thebes/gfxGDIFont.h index 902785d5c87..aa0b706fadb 100644 --- a/gfx/thebes/gfxGDIFont.h +++ b/gfx/thebes/gfxGDIFont.h @@ -76,10 +76,10 @@ public: /* required for MathML to suppress effects of ClearType "padding" */ virtual gfxFont* CopyWithAntialiasOption(AntialiasOption anAAOption); - virtual PRBool ProvidesHintedWidths() const { return PR_TRUE; } + virtual PRBool ProvidesGlyphWidths() const { return PR_TRUE; } // get hinted glyph width in pixels as 16.16 fixed-point value - virtual PRInt32 GetHintedGlyphWidth(gfxContext *aCtx, PRUint16 aGID); + virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID); protected: virtual void CreatePlatformShaper(); diff --git a/gfx/thebes/gfxHarfBuzzShaper.cpp b/gfx/thebes/gfxHarfBuzzShaper.cpp index a9eef1540cd..84fc12c2c7d 100644 --- a/gfx/thebes/gfxHarfBuzzShaper.cpp +++ b/gfx/thebes/gfxHarfBuzzShaper.cpp @@ -83,7 +83,7 @@ gfxHarfBuzzShaper::gfxHarfBuzzShaper(gfxFont *aFont) mSubtableOffset(0), mUVSTableOffset(0), mUseFontGetGlyph(aFont->ProvidesGetGlyph()), - mUseHintedWidths(aFont->ProvidesHintedWidths()) + mUseFontGlyphWidths(aFont->ProvidesGlyphWidths()) { } @@ -215,8 +215,8 @@ gfxHarfBuzzShaper::GetGlyphAdvance(gfxContext *aContext, hb_position_t *x_advance, hb_position_t *y_advance) const { - if (mUseHintedWidths) { - *x_advance = mFont->GetHintedGlyphWidth(aContext, glyph); + if (mUseFontGlyphWidths) { + *x_advance = mFont->GetGlyphWidth(aContext, glyph); return; } @@ -752,8 +752,8 @@ gfxHarfBuzzShaper::InitTextRun(gfxContext *aContext, hb_blob_unlock(mCmapTable); } - if (!mUseHintedWidths) { - // if font doesn't implement hinted widths, we will be reading + if (!mUseFontGlyphWidths) { + // if font doesn't implement GetGlyphWidth, we will be reading // the hmtx table directly; // read mNumLongMetrics from hhea table without caching its blob, // and preload/cache the hmtx table @@ -788,7 +788,7 @@ gfxHarfBuzzShaper::InitTextRun(gfxContext *aContext, } if ((!mUseFontGetGlyph && mCmapFormat <= 0) || - (!mUseHintedWidths && !mHmtxTable)) { + (!mUseFontGlyphWidths && !mHmtxTable)) { // unable to shape with this font return PR_FALSE; } diff --git a/gfx/thebes/gfxHarfBuzzShaper.h b/gfx/thebes/gfxHarfBuzzShaper.h index 665bdef0c3b..aaa4e2363bc 100644 --- a/gfx/thebes/gfxHarfBuzzShaper.h +++ b/gfx/thebes/gfxHarfBuzzShaper.h @@ -118,9 +118,9 @@ protected: // Whether the font implements GetGlyph, or we should read tables // directly PRPackedBool mUseFontGetGlyph; - // Whether the font implements hinted widths, or we should read tables + // Whether the font implements GetGlyphWidth, or we should read tables // directly to get ideal widths - PRPackedBool mUseHintedWidths; + PRPackedBool mUseFontGlyphWidths; }; #endif /* GFX_HARFBUZZSHAPER_H */ diff --git a/layout/reftests/text/reftest.list b/layout/reftests/text/reftest.list index d920bcc5fbe..5098efcc401 100644 --- a/layout/reftests/text/reftest.list +++ b/layout/reftests/text/reftest.list @@ -41,9 +41,7 @@ skip-if(!(d2d||cocoaWidget)) != subpixel-glyphs-x-2a.html subpixel-glyphs-x-2b.h == subpixel-glyphs-y-1a.html subpixel-glyphs-y-1b.html == subpixel-lineheight-1a.html subpixel-lineheight-1b.html == swash-1.html swash-1-ref.html -# Test for bug 593564, synthetic bold should cause glyph metrics to increase -# Random on Windows - fails on tinderbox Opt reftest, passes elsewhere - see bug 597300 -random-if(winWidget) HTTP(..) != synthetic-bold-metrics-01.html synthetic-bold-metrics-01-notref.html +HTTP(..) != synthetic-bold-metrics-01.html synthetic-bold-metrics-01-notref.html == variation-selector-unsupported-1.html variation-selector-unsupported-1-ref.html == white-space-1a.html white-space-1-ref.html == white-space-1b.html white-space-1-ref.html