diff --git a/gfx/thebes/gfxDWriteFonts.cpp b/gfx/thebes/gfxDWriteFonts.cpp index 38c16bdd664..f188da3ca35 100644 --- a/gfx/thebes/gfxDWriteFonts.cpp +++ b/gfx/thebes/gfxDWriteFonts.cpp @@ -7,9 +7,7 @@ #include "mozilla/MemoryReporting.h" -#include "gfxHarfBuzzShaper.h" #include -#include "gfxGraphiteShaper.h" #include "gfxDWriteFontList.h" #include "gfxContext.h" #include @@ -106,14 +104,6 @@ gfxDWriteFont::gfxDWriteFont(gfxFontEntry *aFontEntry, } ComputeMetrics(anAAOption); - - if (FontCanSupportGraphite()) { - mGraphiteShaper = new gfxGraphiteShaper(this); - } - - if (FontCanSupportHarfBuzz()) { - mHarfBuzzShaper = new gfxHarfBuzzShaper(this); - } } gfxDWriteFont::~gfxDWriteFont() @@ -134,32 +124,6 @@ gfxDWriteFont::CopyWithAntialiasOption(AntialiasOption anAAOption) &mStyle, mNeedsBold, anAAOption); } -bool -gfxDWriteFont::ShapeText(gfxContext *aContext, - const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping) -{ - bool ok = false; - - if (mGraphiteShaper && gfxPlatform::GetPlatform()->UseGraphiteShaping()) { - ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength, - aScript, aShapedText); - } - - if (!ok && mHarfBuzzShaper) { - ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength, - aScript, aShapedText); - } - - PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText); - - return ok; -} - const gfxFont::Metrics& gfxDWriteFont::GetMetrics() { diff --git a/gfx/thebes/gfxDWriteFonts.h b/gfx/thebes/gfxDWriteFonts.h index 8ee972b553d..a2adea8ebf2 100644 --- a/gfx/thebes/gfxDWriteFonts.h +++ b/gfx/thebes/gfxDWriteFonts.h @@ -71,14 +71,6 @@ public: virtual cairo_scaled_font_t *GetCairoScaledFont(); protected: - virtual bool ShapeText(gfxContext *aContext, - const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping = false); - bool GetFakeMetricsForArialBlack(DWRITE_FONT_METRICS *aFontMetrics); void ComputeMetrics(AntialiasOption anAAOption); diff --git a/gfx/thebes/gfxFT2Fonts.cpp b/gfx/thebes/gfxFT2Fonts.cpp index cb5088bcacd..fdc0e0e40cc 100644 --- a/gfx/thebes/gfxFT2Fonts.cpp +++ b/gfx/thebes/gfxFT2Fonts.cpp @@ -24,8 +24,6 @@ #include "gfxFT2Utils.h" #include "gfxFT2FontList.h" #include -#include "gfxHarfBuzzShaper.h" -#include "gfxGraphiteShaper.h" #include "nsGkAtoms.h" #include "nsTArray.h" #include "nsUnicodeRange.h" @@ -44,42 +42,20 @@ */ bool -gfxFT2Font::ShapeText(gfxContext *aContext, +gfxFT2Font::ShapeText(gfxContext *aContext, const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping) + uint32_t aOffset, + uint32_t aLength, + int32_t aScript, + gfxShapedText *aShapedText) { - bool ok = false; - - if (FontCanSupportGraphite()) { - if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) { - if (!mGraphiteShaper) { - mGraphiteShaper = new gfxGraphiteShaper(this); - } - ok = mGraphiteShaper->ShapeText(aContext, aText, - aOffset, aLength, - aScript, aShapedText); - } - } - - if (!ok) { - if (!mHarfBuzzShaper) { - mHarfBuzzShaper = new gfxHarfBuzzShaper(this); - } - ok = mHarfBuzzShaper->ShapeText(aContext, aText, - aOffset, aLength, - aScript, aShapedText); - } - - if (!ok) { + if (!gfxFont::ShapeText(aContext, aText, aOffset, aLength, aScript, + aShapedText)) { + // harfbuzz must have failed(?!), just render raw glyphs AddRange(aText, aOffset, aLength, aShapedText); + PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText); } - PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText); - return true; } diff --git a/gfx/thebes/gfxFT2Fonts.h b/gfx/thebes/gfxFT2Fonts.h index 871b9397f9a..f0e390c5a60 100644 --- a/gfx/thebes/gfxFT2Fonts.h +++ b/gfx/thebes/gfxFT2Fonts.h @@ -77,8 +77,7 @@ protected: uint32_t aOffset, uint32_t aLength, int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping); + gfxShapedText *aShapedText); void FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd); diff --git a/gfx/thebes/gfxFont.cpp b/gfx/thebes/gfxFont.cpp index 7a2da014154..3d4c1b68a83 100644 --- a/gfx/thebes/gfxFont.cpp +++ b/gfx/thebes/gfxFont.cpp @@ -23,6 +23,7 @@ #include "gfxTypes.h" #include "gfxContext.h" #include "gfxFontMissingGlyphs.h" +#include "gfxGraphiteShaper.h" #include "gfxHarfBuzzShaper.h" #include "gfxUserFontSet.h" #include "gfxPlatformFontList.h" @@ -3944,8 +3945,7 @@ gfxFont::ShapeText(gfxContext *aContext, uint32_t aOffset, uint32_t aLength, int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping) + gfxShapedText *aShapedText) { nsDependentCSubstring ascii((const char*)aText, aLength); nsAutoString utf16; @@ -3954,7 +3954,7 @@ gfxFont::ShapeText(gfxContext *aContext, return false; } return ShapeText(aContext, utf16.BeginReading(), aOffset, aLength, - aScript, aShapedText, aPreferPlatformShaping); + aScript, aShapedText); } bool @@ -3963,30 +3963,29 @@ gfxFont::ShapeText(gfxContext *aContext, uint32_t aOffset, uint32_t aLength, int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping) + gfxShapedText *aShapedText) { bool ok = false; - if (mGraphiteShaper && gfxPlatform::GetPlatform()->UseGraphiteShaping()) { - ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength, - aScript, aShapedText); + if (FontCanSupportGraphite()) { + if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) { + if (!mGraphiteShaper) { + mGraphiteShaper = new gfxGraphiteShaper(this); + } + ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength, + aScript, aShapedText); + } } - if (!ok && mHarfBuzzShaper && !aPreferPlatformShaping) { + if (!ok) { + if (!mHarfBuzzShaper) { + mHarfBuzzShaper = new gfxHarfBuzzShaper(this); + } ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength, aScript, aShapedText); } - if (!ok) { - if (!mPlatformShaper) { - CreatePlatformShaper(); - } - if (mPlatformShaper) { - ok = mPlatformShaper->ShapeText(aContext, aText, aOffset, aLength, - aScript, aShapedText); - } - } + NS_WARN_IF_FALSE(ok, "shaper failed, expect scrambled or missing text"); PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText); diff --git a/gfx/thebes/gfxFont.h b/gfx/thebes/gfxFont.h index cc9bde759ce..41f65b31be3 100644 --- a/gfx/thebes/gfxFont.h +++ b/gfx/thebes/gfxFont.h @@ -1470,12 +1470,12 @@ public: // Shape a piece of text and store the resulting glyph data into // aShapedText. Parameters aOffset/aLength indicate the range of // aShapedText to be updated; aLength is also the length of aText. - virtual bool ShapeText(gfxContext *aContext, + virtual bool ShapeText(gfxContext *aContext, const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText) = 0; + uint32_t aOffset, + uint32_t aLength, + int32_t aScript, + gfxShapedText *aShapedText) = 0; gfxFont *GetFont() const { return mFont; } @@ -1976,8 +1976,7 @@ protected: uint32_t aOffset, // dest offset in gfxShapedText uint32_t aLength, int32_t aScript, - gfxShapedText *aShapedText, // where to store the result - bool aPreferPlatformShaping = false); + gfxShapedText *aShapedText); // where to store the result // Call the appropriate shaper to generate glyphs for aText and store // them into aShapedText. @@ -1986,8 +1985,7 @@ protected: uint32_t aOffset, uint32_t aLength, int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping = false); + gfxShapedText *aShapedText); // Helper to adjust for synthetic bold and set character-type flags // in the shaped text; implementations of ShapeText should call this @@ -2146,19 +2144,14 @@ protected: // measurement by mathml code nsAutoPtr mNonAAFont; - // we may switch between these shapers on the fly, based on the script - // of the text run being shaped - nsAutoPtr mPlatformShaper; + // we create either or both of these shapers when needed, depending + // whether the font has graphite tables, and whether graphite shaping + // is actually enabled nsAutoPtr mHarfBuzzShaper; nsAutoPtr mGraphiteShaper; mozilla::RefPtr mAzureScaledFont; - // Create a default platform text shaper for this font. - // (TODO: This should become pure virtual once all font backends have - // been updated.) - virtual void CreatePlatformShaper() { } - // Helper for subclasses that want to initialize standard metrics from the // tables of sfnt (TrueType/OpenType) fonts. // This will use mFUnitsConvFactor if it is already set, else compute it diff --git a/gfx/thebes/gfxGDIFont.cpp b/gfx/thebes/gfxGDIFont.cpp index a410ff974bd..926fbb536d6 100644 --- a/gfx/thebes/gfxGDIFont.cpp +++ b/gfx/thebes/gfxGDIFont.cpp @@ -8,9 +8,7 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/WindowsVersion.h" -#include "gfxHarfBuzzShaper.h" #include -#include "gfxGraphiteShaper.h" #include "gfxWindowsPlatform.h" #include "gfxContext.h" #include "mozilla/Preferences.h" @@ -51,10 +49,6 @@ gfxGDIFont::gfxGDIFont(GDIFontEntry *aFontEntry, mSpaceGlyph(0), mNeedsBold(aNeedsBold) { - if (FontCanSupportGraphite()) { - mGraphiteShaper = new gfxGraphiteShaper(this); - } - mHarfBuzzShaper = new gfxHarfBuzzShaper(this); } gfxGDIFont::~gfxGDIFont() @@ -79,13 +73,12 @@ gfxGDIFont::CopyWithAntialiasOption(AntialiasOption anAAOption) } bool -gfxGDIFont::ShapeText(gfxContext *aContext, +gfxGDIFont::ShapeText(gfxContext *aContext, const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping) + uint32_t aOffset, + uint32_t aLength, + int32_t aScript, + gfxShapedText *aShapedText) { if (!mMetrics) { Initialize(); @@ -104,7 +97,7 @@ gfxGDIFont::ShapeText(gfxContext *aContext, } return gfxFont::ShapeText(aContext, aText, aOffset, aLength, aScript, - aShapedText, aPreferPlatformShaping); + aShapedText); } const gfxFont::Metrics& diff --git a/gfx/thebes/gfxGDIFont.h b/gfx/thebes/gfxGDIFont.h index 3b979c41387..13839599b1c 100644 --- a/gfx/thebes/gfxGDIFont.h +++ b/gfx/thebes/gfxGDIFont.h @@ -71,13 +71,12 @@ public: protected: /* override to ensure the cairo font is set up properly */ - virtual bool ShapeText(gfxContext *aContext, + virtual bool ShapeText(gfxContext *aContext, const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping); + uint32_t aOffset, + uint32_t aLength, + int32_t aScript, + gfxShapedText *aShapedText); void Initialize(); // creates metrics and Cairo fonts diff --git a/gfx/thebes/gfxMacFont.cpp b/gfx/thebes/gfxMacFont.cpp index 3b7f752c5db..23e8301534e 100644 --- a/gfx/thebes/gfxMacFont.cpp +++ b/gfx/thebes/gfxMacFont.cpp @@ -8,9 +8,7 @@ #include "mozilla/MemoryReporting.h" #include "gfxCoreTextShaper.h" -#include "gfxHarfBuzzShaper.h" #include -#include "gfxGraphiteShaper.h" #include "gfxPlatformMac.h" #include "gfxContext.h" #include "gfxFontUtils.h" @@ -106,13 +104,6 @@ gfxMacFont::gfxMacFont(MacOSFontEntry *aFontEntry, const gfxFontStyle *aFontStyl NS_WARNING(warnBuf); #endif } - - if (FontCanSupportGraphite()) { - mGraphiteShaper = new gfxGraphiteShaper(this); - } - if (FontCanSupportHarfBuzz()) { - mHarfBuzzShaper = new gfxHarfBuzzShaper(this); - } } gfxMacFont::~gfxMacFont() @@ -126,29 +117,31 @@ gfxMacFont::~gfxMacFont() } bool -gfxMacFont::ShapeText(gfxContext *aContext, +gfxMacFont::ShapeText(gfxContext *aContext, const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping) + uint32_t aOffset, + uint32_t aLength, + int32_t aScript, + gfxShapedText *aShapedText) { if (!mIsValid) { NS_WARNING("invalid font! expect incorrect text rendering"); return false; } - bool requiresAAT = - static_cast(GetFontEntry())->RequiresAATLayout(); - return gfxFont::ShapeText(aContext, aText, aOffset, aLength, - aScript, aShapedText, requiresAAT); -} + if (static_cast(GetFontEntry())->RequiresAATLayout()) { + if (!mCoreTextShaper) { + mCoreTextShaper = new gfxCoreTextShaper(this); + } + if (mCoreTextShaper->ShapeText(aContext, aText, aOffset, aLength, + aScript, aShapedText)) { + PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText); + return true; + } + } -void -gfxMacFont::CreatePlatformShaper() -{ - mPlatformShaper = new gfxCoreTextShaper(this); + return gfxFont::ShapeText(aContext, aText, aOffset, aLength, aScript, + aShapedText); } bool diff --git a/gfx/thebes/gfxMacFont.h b/gfx/thebes/gfxMacFont.h index 0e88c5d0f06..3942213c039 100644 --- a/gfx/thebes/gfxMacFont.h +++ b/gfx/thebes/gfxMacFont.h @@ -51,16 +51,13 @@ public: virtual FontType GetType() const { return FONT_TYPE_MAC; } protected: - virtual void CreatePlatformShaper(); - // override to prefer CoreText shaping with fonts that depend on AAT - virtual bool ShapeText(gfxContext *aContext, + virtual bool ShapeText(gfxContext *aContext, const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping = false); + uint32_t aOffset, + uint32_t aLength, + int32_t aScript, + gfxShapedText *aShapedText); void InitMetrics(); void InitMetricsFromPlatform(); @@ -76,6 +73,8 @@ protected: cairo_font_face_t *mFontFace; + nsAutoPtr mCoreTextShaper; + Metrics mMetrics; uint32_t mSpaceGlyph; }; diff --git a/gfx/thebes/gfxPangoFonts.cpp b/gfx/thebes/gfxPangoFonts.cpp index abfc5e7c71e..2dbd0c233d8 100644 --- a/gfx/thebes/gfxPangoFonts.cpp +++ b/gfx/thebes/gfxPangoFonts.cpp @@ -20,8 +20,6 @@ #include "gfxFT2Utils.h" #include "harfbuzz/hb.h" #include "harfbuzz/hb-ot.h" -#include "gfxHarfBuzzShaper.h" -#include "gfxGraphiteShaper.h" #include "nsUnicodeProperties.h" #include "nsUnicodeScriptCodes.h" #include "gfxFontconfigUtils.h" @@ -663,14 +661,6 @@ public: protected: virtual already_AddRefed GetSmallCapsFont(); - virtual bool ShapeText(gfxContext *aContext, - const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping); - private: gfxFcFont(cairo_scaled_font_t *aCairoFont, gfxFcFontEntry *aFontEntry, const gfxFontStyle *aFontStyle); @@ -1632,42 +1622,6 @@ gfxFcFont::GetSmallCapsFont() return font.forget(); } -bool -gfxFcFont::ShapeText(gfxContext *aContext, - const char16_t *aText, - uint32_t aOffset, - uint32_t aLength, - int32_t aScript, - gfxShapedText *aShapedText, - bool aPreferPlatformShaping) -{ - bool ok = false; - - if (FontCanSupportGraphite()) { - if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) { - if (!mGraphiteShaper) { - mGraphiteShaper = new gfxGraphiteShaper(this); - } - ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength, - aScript, aShapedText); - } - } - - if (!ok) { - if (!mHarfBuzzShaper) { - mHarfBuzzShaper = new gfxHarfBuzzShaper(this); - } - ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength, - aScript, aShapedText); - } - - NS_WARN_IF_FALSE(ok, "shaper failed, expect scrambled or missing text"); - - PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText); - - return ok; -} - /* static */ void gfxPangoFontGroup::Shutdown() {