From b4407fab225dff3fbb2bc0134ea8afcd4549bb25 Mon Sep 17 00:00:00 2001 From: Mason Chang Date: Thu, 8 Sep 2016 09:34:10 -0700 Subject: [PATCH] Bug 1300025. Use embedded bitmaps in CJK fonts with skia on Windows. r=lsalzman --- gfx/2d/2D.h | 3 ++- gfx/2d/DrawTargetSkia.cpp | 10 ++++++++++ gfx/2d/Factory.cpp | 5 +++-- gfx/2d/ScaledFontDWrite.h | 7 ++++++- gfx/thebes/gfxDWriteFonts.cpp | 7 ++++++- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h index 518134962a10..89ffd1a89405 100644 --- a/gfx/2d/2D.h +++ b/gfx/2d/2D.h @@ -1481,7 +1481,8 @@ public: CreateScaledFontForDWriteFont(IDWriteFont* aFont, IDWriteFontFamily* aFontFamily, IDWriteFontFace* aFontFace, - Float aSize); + Float aSize, + bool aUseEmbeddedBitmap); private: static ID2D1Device *mD2D1Device; diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp index 124fced56e53..cd82047a353b 100644 --- a/gfx/2d/DrawTargetSkia.cpp +++ b/gfx/2d/DrawTargetSkia.cpp @@ -41,6 +41,10 @@ #include "CGTextDrawing.h" #endif +#ifdef XP_WIN +#include "ScaledFontDWrite.h" +#endif + namespace mozilla { namespace gfx { @@ -1291,6 +1295,12 @@ DrawTargetSkia::FillGlyphs(ScaledFont *aFont, } break; } + case FontType::DWRITE: + { + ScaledFontDWrite* dwriteFont = static_cast(aFont); + paint.mPaint.setEmbeddedBitmapText(dwriteFont->UseEmbeddedBitmaps()); + break; + } default: break; } diff --git a/gfx/2d/Factory.cpp b/gfx/2d/Factory.cpp index e791c953d16b..8151040caa04 100644 --- a/gfx/2d/Factory.cpp +++ b/gfx/2d/Factory.cpp @@ -705,9 +705,10 @@ already_AddRefed Factory::CreateScaledFontForDWriteFont(IDWriteFont* aFont, IDWriteFontFamily* aFontFamily, IDWriteFontFace* aFontFace, - float aSize) + float aSize, + bool aUseEmbeddedBitmap) { - return MakeAndAddRef(aFont, aFontFamily, aFontFace, aSize); + return MakeAndAddRef(aFont, aFontFamily, aFontFace, aSize, aUseEmbeddedBitmap); } #endif // XP_WIN diff --git a/gfx/2d/ScaledFontDWrite.h b/gfx/2d/ScaledFontDWrite.h index 8e9c6c8e152e..05fb05c6c13c 100644 --- a/gfx/2d/ScaledFontDWrite.h +++ b/gfx/2d/ScaledFontDWrite.h @@ -23,14 +23,16 @@ public: , mFont(nullptr) , mFontFamily(nullptr) , mFontFace(aFont) + , mUseEmbeddedBitmap(false) {} ScaledFontDWrite(IDWriteFont* aFont, IDWriteFontFamily* aFontFamily, - IDWriteFontFace *aFontFace, Float aSize) + IDWriteFontFace *aFontFace, Float aSize, bool aUseEmbeddedBitmap) : ScaledFontBase(aSize) , mFont(aFont) , mFontFamily(aFontFamily) , mFontFace(aFontFace) + , mUseEmbeddedBitmap(aUseEmbeddedBitmap) {} virtual FontType GetType() const { return FontType::DWRITE; } @@ -46,6 +48,8 @@ public: virtual AntialiasMode GetDefaultAAMode() override; + bool UseEmbeddedBitmaps() { return mUseEmbeddedBitmap; } + #ifdef USE_SKIA virtual SkTypeface* GetSkTypeface(); bool GetFontDataFromSystemFonts(IDWriteFactory* aFactory); @@ -56,6 +60,7 @@ public: RefPtr mFont; RefPtr mFontFamily; RefPtr mFontFace; + bool mUseEmbeddedBitmap; protected: #ifdef USE_CAIRO_SCALED_FONT diff --git a/gfx/thebes/gfxDWriteFonts.cpp b/gfx/thebes/gfxDWriteFonts.cpp index f33b9fa68c5d..8d39c201dd9b 100644 --- a/gfx/thebes/gfxDWriteFonts.cpp +++ b/gfx/thebes/gfxDWriteFonts.cpp @@ -702,9 +702,14 @@ gfxDWriteFont::GetScaledFont(mozilla::gfx::DrawTarget *aTarget) GetAdjustedSize(), GetCairoScaledFont()); } else if (aTarget->GetBackendType() == BackendType::SKIA) { + gfxDWriteFontEntry *fe = + static_cast(mFontEntry.get()); + bool useEmbeddedBitmap = (fe->IsCJKFont() && HasBitmapStrikeForSize(NS_lround(mAdjustedSize))); + mAzureScaledFont = Factory::CreateScaledFontForDWriteFont(mFont, mFontFamily, - mFontFace, GetAdjustedSize()); + mFontFace, GetAdjustedSize(), + useEmbeddedBitmap); } else { mAzureScaledFont = Factory::CreateScaledFontForNativeFont(nativeFont, GetAdjustedSize());