From c89157b9ea0a9203b350f95501192e9c92d07e70 Mon Sep 17 00:00:00 2001 From: Mason Chang Date: Tue, 8 Mar 2016 07:37:16 -0800 Subject: [PATCH] Bug 1249600. Lookup font and font family from font face when requesting SkTypeface. r=bas --- gfx/2d/ScaledFontDWrite.cpp | 32 +++++++++++++++++++++++++++++++- gfx/2d/ScaledFontDWrite.h | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gfx/2d/ScaledFontDWrite.cpp b/gfx/2d/ScaledFontDWrite.cpp index a9c9e8f80512..06cfb6da2d73 100644 --- a/gfx/2d/ScaledFontDWrite.cpp +++ b/gfx/2d/ScaledFontDWrite.cpp @@ -115,12 +115,42 @@ ScaledFontDWrite::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget #ifdef USE_SKIA +// This can happen if we have mixed backends which create DWrite +// fonts in a mixed environment. e.g. a cairo content backend +// but Skia canvas backend. +void +ScaledFontDWrite::GetFontDataFromSystemFonts(IDWriteFactory* aFactory) +{ + MOZ_ASSERT(mFontFace); + RefPtr systemFonts; + HRESULT hr = aFactory->GetSystemFontCollection(getter_AddRefs(systemFonts)); + if (FAILED(hr)) { + gfxWarning() << "Failed to get system font collection from file data. Code: " << hexa(hr); + return; + } + + hr = systemFonts->GetFontFromFontFace(mFontFace, getter_AddRefs(mFont)); + if (FAILED(hr)) { + gfxWarning() << "Failed to get system font from font face. Code: " << hexa(hr); + return; + } + + hr = mFont->GetFontFamily(getter_AddRefs(mFontFamily)); + if (FAILED(hr)) { + gfxWarning() << "Failed to get font family from font face. Code: " << hexa(hr); + return; + } +} + SkTypeface* ScaledFontDWrite::GetSkTypeface() { - MOZ_ASSERT(mFont); if (!mTypeface) { IDWriteFactory *factory = DrawTargetD2D1::GetDWriteFactory(); + if (!mFont || !mFontFamily) { + GetFontDataFromSystemFonts(factory); + } + mTypeface = SkCreateTypefaceFromDWriteFont(factory, mFontFace, mFont, mFontFamily); } return mTypeface; diff --git a/gfx/2d/ScaledFontDWrite.h b/gfx/2d/ScaledFontDWrite.h index 65f25d89ff70..9a4d16264e13 100644 --- a/gfx/2d/ScaledFontDWrite.h +++ b/gfx/2d/ScaledFontDWrite.h @@ -46,8 +46,10 @@ public: #ifdef USE_SKIA virtual SkTypeface* GetSkTypeface(); + void GetFontDataFromSystemFonts(IDWriteFactory* aFactory); #endif + // The font and font family are only used with Skia RefPtr mFont; RefPtr mFontFamily; RefPtr mFontFace;