Bug 1309917 - Stop defaulting to system wide default fonts if no IDWriteFont exists. r=jfkthame
authorMason Chang <mchang@mozilla.com>
Wed, 12 Oct 2016 15:53:04 -0700
changeset 317911 5b7c66cd059c6541d8f5de09bb8adb7297b51591
parent 317910 829c16e72fb7099733a01b01d1cdcaa66f717248
child 317912 b044f5da367000d075c25acc950193366c11262e
push id33170
push usercbook@mozilla.com
push dateFri, 14 Oct 2016 10:37:07 +0000
treeherderautoland@0d101ebfd95c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1309917
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1309917 - Stop defaulting to system wide default fonts if no IDWriteFont exists. r=jfkthame
gfx/2d/2D.h
gfx/2d/Factory.cpp
gfx/2d/ScaledFontDWrite.cpp
gfx/2d/ScaledFontDWrite.h
gfx/skia/skia/include/ports/SkTypeface_win.h
gfx/skia/skia/src/ports/SkFontHost_win.cpp
gfx/skia/skia/src/ports/SkTypeface_win_dw.h
gfx/thebes/gfxDWriteFontList.cpp
gfx/thebes/gfxDWriteFontList.h
gfx/thebes/gfxDWriteFonts.cpp
gfx/thebes/gfxDWriteFonts.h
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -40,21 +40,20 @@ typedef _cairo_scaled_font cairo_scaled_
 
 struct _FcPattern;
 typedef _FcPattern FcPattern;
 
 struct ID3D11Texture2D;
 struct ID3D11Device;
 struct ID2D1Device;
 struct IDWriteRenderingParams;
-struct IDWriteFont;
-struct IDWriteFontFamily;
 struct IDWriteFontFace;
 
 class GrContext;
+struct gfxFontStyle;
 
 struct CGContext;
 typedef struct CGContext *CGContextRef;
 
 namespace mozilla {
 
 namespace gfx {
 
@@ -1491,19 +1490,18 @@ public:
   static already_AddRefed<GlyphRenderingOptions>
     CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams);
 
   static uint64_t GetD2DVRAMUsageDrawTarget();
   static uint64_t GetD2DVRAMUsageSourceSurface();
   static void D2DCleanup();
 
   static already_AddRefed<ScaledFont>
-    CreateScaledFontForDWriteFont(IDWriteFont* aFont,
-                                  IDWriteFontFamily* aFontFamily,
-                                  IDWriteFontFace* aFontFace,
+    CreateScaledFontForDWriteFont(IDWriteFontFace* aFontFace,
+                                  const gfxFontStyle* aStyle,
                                   Float aSize,
                                   bool aUseEmbeddedBitmap,
                                   bool aForceGDIMode);
 
 private:
   static ID2D1Device *mD2D1Device;
   static ID3D11Device *mD3D11Device;
 #endif
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -700,25 +700,25 @@ Factory::D2DCleanup()
   if (mD2D1Device) {
     mD2D1Device->Release();
     mD2D1Device = nullptr;
   }
   DrawTargetD2D1::CleanupD2D();
 }
 
 already_AddRefed<ScaledFont>
-Factory::CreateScaledFontForDWriteFont(IDWriteFont* aFont,
-                                       IDWriteFontFamily* aFontFamily,
-                                       IDWriteFontFace* aFontFace,
+Factory::CreateScaledFontForDWriteFont(IDWriteFontFace* aFontFace,
+                                       const gfxFontStyle* aStyle,
                                        float aSize,
                                        bool aUseEmbeddedBitmap,
                                        bool aForceGDIMode)
 {
-  return MakeAndAddRef<ScaledFontDWrite>(aFont, aFontFamily, aFontFace,
-                                         aSize, aUseEmbeddedBitmap, aForceGDIMode);
+  return MakeAndAddRef<ScaledFontDWrite>(aFontFace, aSize,
+                                         aUseEmbeddedBitmap, aForceGDIMode,
+                                         aStyle);
 }
 
 #endif // XP_WIN
 
 #ifdef USE_SKIA_GPU
 already_AddRefed<DrawTarget>
 Factory::CreateDrawTargetSkiaWithGrContext(GrContext* aGrContext,
                                            const IntSize &aSize,
--- a/gfx/2d/ScaledFontDWrite.cpp
+++ b/gfx/2d/ScaledFontDWrite.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DrawTargetD2D1.h"
 #include "ScaledFontDWrite.h"
 #include "PathD2D.h"
+#include "gfxFont.h"
 
 using namespace std;
 
 #ifdef USE_SKIA
 #include "PathSkia.h"
 #include "skia/include/core/SkPaint.h"
 #include "skia/include/core/SkPath.h"
 #include "skia/include/ports/SkTypeface_win.h"
@@ -69,16 +70,57 @@ DoGrayscale(IDWriteFontFace *aDWFace, Fl
         break;
       }
     }
     aDWFace->ReleaseFontTable(tableContext);
   }
   return true;
 }
 
+static inline DWRITE_FONT_STRETCH
+DWriteFontStretchFromStretch(int16_t aStretch)
+{
+    switch (aStretch) {
+        case NS_FONT_STRETCH_ULTRA_CONDENSED:
+            return DWRITE_FONT_STRETCH_ULTRA_CONDENSED;
+        case NS_FONT_STRETCH_EXTRA_CONDENSED:
+            return DWRITE_FONT_STRETCH_EXTRA_CONDENSED;
+        case NS_FONT_STRETCH_CONDENSED:
+            return DWRITE_FONT_STRETCH_CONDENSED;
+        case NS_FONT_STRETCH_SEMI_CONDENSED:
+            return DWRITE_FONT_STRETCH_SEMI_CONDENSED;
+        case NS_FONT_STRETCH_NORMAL:
+            return DWRITE_FONT_STRETCH_NORMAL;
+        case NS_FONT_STRETCH_SEMI_EXPANDED:
+            return DWRITE_FONT_STRETCH_SEMI_EXPANDED;
+        case NS_FONT_STRETCH_EXPANDED:
+            return DWRITE_FONT_STRETCH_EXPANDED;
+        case NS_FONT_STRETCH_EXTRA_EXPANDED:
+            return DWRITE_FONT_STRETCH_EXTRA_EXPANDED;
+        case NS_FONT_STRETCH_ULTRA_EXPANDED:
+            return DWRITE_FONT_STRETCH_ULTRA_EXPANDED;
+        default:
+            return DWRITE_FONT_STRETCH_UNDEFINED;
+    }
+}
+
+ScaledFontDWrite::ScaledFontDWrite(IDWriteFontFace *aFontFace, Float aSize,
+                                   bool aUseEmbeddedBitmap, bool aForceGDIMode,
+                                   const gfxFontStyle* aStyle)
+    : ScaledFontBase(aSize)
+    , mFontFace(aFontFace)
+    , mUseEmbeddedBitmap(aUseEmbeddedBitmap)
+    , mForceGDIMode(aForceGDIMode)
+{
+  mStyle = SkFontStyle(aStyle->weight,
+                       DWriteFontStretchFromStretch(aStyle->stretch),
+                       aStyle->style == NS_FONT_STYLE_NORMAL ?
+                       SkFontStyle::kUpright_Slant : SkFontStyle::kItalic_Slant);
+}
+
 already_AddRefed<Path>
 ScaledFontDWrite::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
 {
   if (aTarget->GetBackendType() != BackendType::DIRECT2D && aTarget->GetBackendType() != BackendType::DIRECT2D1_1) {
     return ScaledFontBase::GetPathForGlyphs(aBuffer, aTarget);
   }
 
   RefPtr<PathBuilder> pathBuilder = aTarget->CreatePathBuilder();
@@ -88,93 +130,26 @@ ScaledFontDWrite::GetPathForGlyphs(const
 
   CopyGlyphsToSink(aBuffer, pathBuilderD2D->GetSink());
 
   return pathBuilder->Finish();
 }
 
 
 #ifdef USE_SKIA
-bool
-ScaledFontDWrite::DefaultToArialFont(IDWriteFontCollection* aSystemFonts)
-{
-  // If we can't find the same font face as we're given, fallback to arial
-  static const WCHAR fontFamilyName[] = L"Arial";
-
-  UINT32 fontIndex;
-  BOOL exists;
-  HRESULT hr = aSystemFonts->FindFamilyName(fontFamilyName, &fontIndex, &exists);
-  if (FAILED(hr)) {
-    gfxCriticalNote << "Failed to get backup arial font font from system fonts. Code: " << hexa(hr);
-    return false;
-  }
-
-  hr = aSystemFonts->GetFontFamily(fontIndex, getter_AddRefs(mFontFamily));
-  if (FAILED(hr)) {
-    gfxCriticalNote << "Failed to get font family for arial. Code: " << hexa(hr);
-    return false;
-  }
-
-  hr = mFontFamily->GetFirstMatchingFont(DWRITE_FONT_WEIGHT_NORMAL,
-                                         DWRITE_FONT_STRETCH_NORMAL,
-                                         DWRITE_FONT_STYLE_NORMAL,
-                                         getter_AddRefs(mFont));
-  if (FAILED(hr)) {
-    gfxCriticalNote << "Failed to get a matching font for arial. Code: " << hexa(hr);
-    return false;
-  }
-
-  return true;
-}
-
-// 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.
-bool
-ScaledFontDWrite::GetFontDataFromSystemFonts(IDWriteFactory* aFactory)
-{
-  MOZ_ASSERT(mFontFace);
-  RefPtr<IDWriteFontCollection> systemFonts;
-  HRESULT hr = aFactory->GetSystemFontCollection(getter_AddRefs(systemFonts));
-  if (FAILED(hr)) {
-    gfxCriticalNote << "Failed to get system font collection from file data. Code: " << hexa(hr);
-    return false;
-  }
-
-  hr = systemFonts->GetFontFromFontFace(mFontFace, getter_AddRefs(mFont));
-  if (FAILED(hr)) {
-    gfxCriticalNote << "Failed to get system font from font face. Code: " << hexa(hr);
-    return DefaultToArialFont(systemFonts);
-  }
-
-  hr = mFont->GetFontFamily(getter_AddRefs(mFontFamily));
-  if (FAILED(hr)) {
-    gfxCriticalNote << "Failed to get font family from font face. Code: " << hexa(hr);
-    return DefaultToArialFont(systemFonts);
-  }
-
-  return true;
-}
-
 SkTypeface*
 ScaledFontDWrite::GetSkTypeface()
 {
   if (!mTypeface) {
     IDWriteFactory *factory = DrawTargetD2D1::GetDWriteFactory();
     if (!factory) {
       return nullptr;
     }
 
-    if (!mFont || !mFontFamily) {
-      if (!GetFontDataFromSystemFonts(factory)) {
-        return nullptr;
-      }
-    }
-
-    mTypeface = SkCreateTypefaceFromDWriteFont(factory, mFontFace, mFont, mFontFamily);
+    mTypeface = SkCreateTypefaceFromDWriteFont(factory, mFontFace, mStyle);
   }
   return mTypeface;
 }
 #endif
 
 void
 ScaledFontDWrite::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, BackendType aBackendType, const Matrix *aTransformHint)
 {
--- a/gfx/2d/ScaledFontDWrite.h
+++ b/gfx/2d/ScaledFontDWrite.h
@@ -5,43 +5,34 @@
 
 #ifndef MOZILLA_GFX_SCALEDFONTDWRITE_H_
 #define MOZILLA_GFX_SCALEDFONTDWRITE_H_
 
 #include <dwrite.h>
 #include "ScaledFontBase.h"
 
 struct ID2D1GeometrySink;
+struct gfxFontStyle;
 
 namespace mozilla {
 namespace gfx {
 
 class ScaledFontDWrite final : public ScaledFontBase
 {
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontDwrite)
   ScaledFontDWrite(IDWriteFontFace *aFont, Float aSize)
     : ScaledFontBase(aSize)
-    , mFont(nullptr)
-    , mFontFamily(nullptr)
     , mFontFace(aFont)
     , mUseEmbeddedBitmap(false)
     , mForceGDIMode(false)
   {}
 
-  ScaledFontDWrite(IDWriteFont* aFont, IDWriteFontFamily* aFontFamily,
-                   IDWriteFontFace *aFontFace, Float aSize, bool aUseEmbeddedBitmap,
-                   bool aForceGDIMode)
-    : ScaledFontBase(aSize)
-    , mFont(aFont)
-    , mFontFamily(aFontFamily)
-    , mFontFace(aFontFace)
-    , mUseEmbeddedBitmap(aUseEmbeddedBitmap)
-    , mForceGDIMode(aForceGDIMode)
-  {}
+  ScaledFontDWrite(IDWriteFontFace *aFontFace, Float aSize, bool aUseEmbeddedBitmap,
+                   bool aForceGDIMode, const gfxFontStyle* aStyle);
 
   virtual FontType GetType() const { return FontType::DWRITE; }
 
   virtual already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
   virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, BackendType aBackendType, const Matrix *aTransformHint);
 
   void CopyGlyphsToSink(const GlyphBuffer &aBuffer, ID2D1GeometrySink *aSink);
 
@@ -51,23 +42,19 @@ public:
 
   virtual AntialiasMode GetDefaultAAMode() override;
 
   bool UseEmbeddedBitmaps() { return mUseEmbeddedBitmap; }
   bool ForceGDIMode() { return mForceGDIMode; }
 
 #ifdef USE_SKIA
   virtual SkTypeface* GetSkTypeface();
-  bool GetFontDataFromSystemFonts(IDWriteFactory* aFactory);
-  bool DefaultToArialFont(IDWriteFontCollection* aSystemFonts);
+  SkFontStyle mStyle;
 #endif
 
-  // The font and font family are only used with Skia
-  RefPtr<IDWriteFont> mFont;
-  RefPtr<IDWriteFontFamily> mFontFamily;
   RefPtr<IDWriteFontFace> mFontFace;
   bool mUseEmbeddedBitmap;
   bool mForceGDIMode;
 
 protected:
 #ifdef USE_CAIRO_SCALED_FONT
   cairo_font_face_t* GetCairoFontFace() override;
 #endif
--- a/gfx/skia/skia/include/ports/SkTypeface_win.h
+++ b/gfx/skia/skia/include/ports/SkTypeface_win.h
@@ -45,18 +45,17 @@ struct IDWriteFontCollection;
 
 /**
  *  Like the other Typeface create methods, this returns a new reference to the
  *  corresponding typeface for the specified dwrite font. The caller is responsible
  *  for calling unref() when it is finished.
  */
 SK_API SkTypeface* SkCreateTypefaceFromDWriteFont(IDWriteFactory* aFactory,
                                                   IDWriteFontFace* aFontFace,
-                                                  IDWriteFont* aFont,
-                                                  IDWriteFontFamily* aFontFamily);
+                                                  SkFontStyle aStyle);
 
 SK_API SkFontMgr* SkFontMgr_New_GDI();
 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL,
                                             IDWriteFontCollection* collection = NULL);
 
 /**
  *  Creates an SkFontMgr which renders using DirectWrite and obtains its data
  *  from the SkRemotableFontMgr.
--- a/gfx/skia/skia/src/ports/SkFontHost_win.cpp
+++ b/gfx/skia/skia/src/ports/SkFontHost_win.cpp
@@ -333,20 +333,19 @@ SkTypeface* SkCreateTypefaceFromLOGFONT(
 }
 
 /***
  * This guy is public.
  */
 
 SkTypeface* SkCreateTypefaceFromDWriteFont(IDWriteFactory* aFactory,
                                            IDWriteFontFace* aFontFace,
-                                           IDWriteFont* aFont,
-                                           IDWriteFontFamily* aFontFamily)
+                                           SkFontStyle aStyle)
 {
-  return DWriteFontTypeface::Create(aFactory, aFontFace, aFont, aFontFamily);
+  return DWriteFontTypeface::Create(aFactory, aFontFace, aStyle);
 }
 
 /**
  *  The created SkTypeface takes ownership of fontMemResource.
  */
 SkTypeface* SkCreateFontMemResourceTypefaceFromLOGFONT(const LOGFONT& origLF, HANDLE fontMemResource) {
     LOGFONT lf = origLF;
     make_canonical(&lf);
--- a/gfx/skia/skia/src/ports/SkTypeface_win_dw.h
+++ b/gfx/skia/skia/src/ports/SkTypeface_win_dw.h
@@ -34,26 +34,26 @@ static SkFontStyle get_style(IDWriteFont
                                                    : SkFontStyle::kUpright_Slant);
 }
 
 class DWriteFontTypeface : public SkTypeface {
 private:
     DWriteFontTypeface(const SkFontStyle& style, SkFontID fontID,
                        IDWriteFactory* factory,
                        IDWriteFontFace* fontFace,
-                       IDWriteFont* font,
-                       IDWriteFontFamily* fontFamily,
+                       IDWriteFont* font = nullptr,
+                       IDWriteFontFamily* fontFamily = nullptr,
                        IDWriteFontFileLoader* fontFileLoader = nullptr,
                        IDWriteFontCollectionLoader* fontCollectionLoader = nullptr)
         : SkTypeface(style, fontID, false)
         , fFactory(SkRefComPtr(factory))
         , fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader))
         , fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader))
-        , fDWriteFontFamily(SkRefComPtr(fontFamily))
-        , fDWriteFont(SkRefComPtr(font))
+        , fDWriteFontFamily(SkSafeRefComPtr(fontFamily))
+        , fDWriteFont(SkSafeRefComPtr(font))
         , fDWriteFontFace(SkRefComPtr(fontFace))
     {
 #if SK_HAS_DWRITE_1_H
         if (!SUCCEEDED(fDWriteFontFace->QueryInterface(&fDWriteFontFace1))) {
             // IUnknown::QueryInterface states that if it fails, punk will be set to nullptr.
             // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx
             SkASSERT_RELEASE(nullptr == fDWriteFontFace1.get());
         }
@@ -68,16 +68,25 @@ public:
     SkTScopedComPtr<IDWriteFont> fDWriteFont;
     SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace;
 #if SK_HAS_DWRITE_1_H
     SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1;
 #endif
 
     static DWriteFontTypeface* Create(IDWriteFactory* factory,
                                       IDWriteFontFace* fontFace,
+                                      SkFontStyle aStyle) {
+        SkFontID fontID = SkTypefaceCache::NewFontID();
+        return new DWriteFontTypeface(aStyle, fontID, factory, fontFace,
+                                      nullptr, nullptr,
+                                      nullptr, nullptr);
+    }
+
+    static DWriteFontTypeface* Create(IDWriteFactory* factory,
+                                      IDWriteFontFace* fontFace,
                                       IDWriteFont* font,
                                       IDWriteFontFamily* fontFamily,
                                       IDWriteFontFileLoader* fontFileLoader = nullptr,
                                       IDWriteFontCollectionLoader* fontCollectionLoader = nullptr) {
         SkFontID fontID = SkTypefaceCache::NewFontID();
         return new DWriteFontTypeface(get_style(font), fontID, factory, fontFace, font, fontFamily,
                                       fontFileLoader, fontCollectionLoader);
     }
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -344,34 +344,16 @@ gfxDWriteFontFamily::AddSizeOfExcludingT
 void
 gfxDWriteFontFamily::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
                                             FontListSizes* aSizes) const
 {
     aSizes->mFontListSize += aMallocSizeOf(this);
     AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
 }
 
-already_AddRefed<IDWriteFont>
-gfxDWriteFontFamily::GetDefaultFont()
-{
-  RefPtr<IDWriteFont> font;
-  for (UINT32 i = 0; i < mDWFamily->GetFontCount(); i++) {
-    HRESULT hr = mDWFamily->GetFont(i, getter_AddRefs(font));
-    if (FAILED(hr)) {
-      NS_WARNING("Failed to get default font from existing family");
-      continue;
-    }
-
-    return font.forget();
-  }
-
-  NS_WARNING("No available DWrite fonts. Returning null");
-  return nullptr;
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 // gfxDWriteFontEntry
 
 gfxDWriteFontEntry::~gfxDWriteFontEntry()
 {
 }
 
 bool
--- a/gfx/thebes/gfxDWriteFontList.h
+++ b/gfx/thebes/gfxDWriteFontList.h
@@ -53,17 +53,16 @@ public:
 
     void SetForceGDIClassic(bool aForce) { mForceGDIClassic = aForce; }
 
     void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                                 FontListSizes* aSizes) const final;
     void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                                 FontListSizes* aSizes) const final;
 
-    already_AddRefed<IDWriteFont> GetDefaultFont();
 protected:
     /** This font family's directwrite fontfamily object */
     RefPtr<IDWriteFontFamily> mDWFamily;
     bool mForceGDIClassic;
 };
 
 /**
  * \brief Class representing DirectWrite FontEntry (a unique font style/family)
@@ -162,20 +161,16 @@ public:
     void SetForceGDIClassic(bool aForce) { mForceGDIClassic = aForce; }
     bool GetForceGDIClassic() { return mForceGDIClassic; }
 
     virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                                         FontListSizes* aSizes) const;
     virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                                         FontListSizes* aSizes) const;
 
-    IDWriteFont* GetFont() {
-      return mFont;
-    }
-
 protected:
     friend class gfxDWriteFont;
     friend class gfxDWriteFontList;
 
     virtual nsresult CopyFontTable(uint32_t aTableTag,
                                    nsTArray<uint8_t>& aBuffer) override;
 
     virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle,
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -98,31 +98,16 @@ gfxDWriteFont::gfxDWriteFont(gfxFontEntr
 
     rv = fe->CreateFontFace(getter_AddRefs(mFontFace), sims);
 
     if (NS_FAILED(rv)) {
         mIsValid = false;
         return;
     }
 
-    mFont = fe->GetFont();
-    if (!mFont) {
-        gfxPlatformFontList* fontList = gfxPlatformFontList::PlatformFontList();
-        gfxDWriteFontFamily* defaultFontFamily =
-            static_cast<gfxDWriteFontFamily*>(fontList->GetDefaultFont(aFontStyle));
-
-        mFont = defaultFontFamily->GetDefaultFont();
-        MOZ_ASSERT(mFont);
-    }
-
-    HRESULT hr = mFont->GetFontFamily(getter_AddRefs(mFontFamily));
-    if (FAILED(hr)) {
-        MOZ_ASSERT(false);
-    }
-
     ComputeMetrics(anAAOption);
 }
 
 gfxDWriteFont::~gfxDWriteFont()
 {
     if (mCairoFontFace) {
         cairo_font_face_destroy(mCairoFontFace);
     }
@@ -701,19 +686,20 @@ gfxDWriteFont::GetScaledFont(mozilla::gf
     mAzureScaledFont = Factory::CreateScaledFontWithCairo(nativeFont,
                                                         GetAdjustedSize(),
                                                         GetCairoScaledFont());
   } else if (aTarget->GetBackendType() == BackendType::SKIA) {
     gfxDWriteFontEntry *fe =
         static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
     bool useEmbeddedBitmap = (fe->IsCJKFont() && HasBitmapStrikeForSize(NS_lround(mAdjustedSize)));
 
+    const gfxFontStyle* fontStyle = GetStyle();
     mAzureScaledFont =
-            Factory::CreateScaledFontForDWriteFont(mFont, mFontFamily,
-                                                   mFontFace, GetAdjustedSize(),
+            Factory::CreateScaledFontForDWriteFont(mFontFace, fontStyle,
+                                                   GetAdjustedSize(),
                                                    useEmbeddedBitmap,
                                                    GetForceGDIClassic());
   } else {
     mAzureScaledFont = Factory::CreateScaledFontForNativeFont(nativeFont,
                                                             GetAdjustedSize());
   }
 
   mAzureScaledFontIsCairo = wantCairo;
--- a/gfx/thebes/gfxDWriteFonts.h
+++ b/gfx/thebes/gfxDWriteFonts.h
@@ -83,18 +83,16 @@ protected:
     cairo_font_face_t *CairoFontFace();
 
     gfxFloat MeasureGlyphWidth(uint16_t aGlyph);
 
     DWRITE_MEASURING_MODE GetMeasuringMode();
     bool GetForceGDIClassic();
 
     RefPtr<IDWriteFontFace> mFontFace;
-    RefPtr<IDWriteFont> mFont;
-    RefPtr<IDWriteFontFamily> mFontFamily;
     cairo_font_face_t *mCairoFontFace;
 
     Metrics *mMetrics;
 
     // cache of glyph widths in 16.16 fixed-point pixels
     mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey,int32_t>> mGlyphWidths;
 
     uint32_t mSpaceGlyph;