Bug 1249600. Lookup font and font family from font face when requesting SkTypeface. r=bas

This commit is contained in:
Mason Chang 2016-03-08 07:37:16 -08:00
parent 4272902ae3
commit c89157b9ea
2 changed files with 33 additions and 1 deletions

View File

@ -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<IDWriteFontCollection> 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;

View File

@ -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<IDWriteFont> mFont;
RefPtr<IDWriteFontFamily> mFontFamily;
RefPtr<IDWriteFontFace> mFontFace;