Bug 1427641 - patch 5 - Also for system-installed fonts, create a separate FcPattern and face for each instance when variations are present. r=lsalzman
authorJonathan Kew <jkew@mozilla.com>
Sat, 06 Jan 2018 10:58:23 +0000
changeset 449887 78fe966a5d43de3b05066a0da697baa960c6fd3f
parent 449886 d6e329f15f6ab2ca85c7daef5ce0370a1327cd00
child 449888 89faa23196eaf6bef55e712663bb0f01f8247f18
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1427641
milestone59.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 1427641 - patch 5 - Also for system-installed fonts, create a separate FcPattern and face for each instance when variations are present. r=lsalzman
gfx/thebes/gfxFcPlatformFontList.cpp
--- a/gfx/thebes/gfxFcPlatformFontList.cpp
+++ b/gfx/thebes/gfxFcPlatformFontList.cpp
@@ -894,33 +894,43 @@ gfxFontconfigFontEntry::CreateFontInstan
     if (!pattern) {
         NS_WARNING("Failed to create Fontconfig pattern for font instance");
         return nullptr;
     }
 
     double size = ChooseFontSize(this, *aFontStyle);
     FcPatternAddDouble(pattern, FC_PIXEL_SIZE, size);
 
-    FT_Face face = mFTFace; // may be null, if it's not a user font
+    FT_Face face = mFTFace;
     FcPattern* fontPattern = mFontPattern;
-    if (mFontData) {
-        MOZ_ASSERT(face, "face should not be null for user font");
-        if (face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) {
-            // For variation fonts, we create a new FT_Face and FcPattern
-            // so that variation coordinates from the style can be applied
-            // without affecting other font instances created from the same
-            // entry (font resource).
+    if (face && face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) {
+        // For variation fonts, we create a new FT_Face and FcPattern
+        // so that variation coordinates from the style can be applied
+        // without affecting other font instances created from the same
+        // entry (font resource).
+        if (mFontData) {
             face = Factory::NewFTFaceFromData(nullptr, mFontData, mLength, 0);
             fontPattern = FcFreeTypeQueryFace(face, ToFcChar8Ptr(""), 0, nullptr);
             if (!fontPattern) {
                 fontPattern = FcPatternCreate();
             }
             FcPatternDel(fontPattern, FC_FILE);
             FcPatternDel(fontPattern, FC_INDEX);
             FcPatternAddFTFace(fontPattern, FC_FT_FACE, face);
+        } else {
+            FcChar8 *filename;
+            if (FcPatternGetString(mFontPattern, FC_FILE, 0, &filename) == FcResultMatch) {
+                int index;
+                if (FcPatternGetInteger(mFontPattern, FC_INDEX, 0, &index) != FcResultMatch) {
+                    index = 0; // default to 0 if not found in pattern
+                }
+                face = Factory::NewFTFace(nullptr, ToCharPtr(filename), index);
+            }
+            fontPattern = FcPatternDuplicate(mFontPattern);
+            FcPatternAddFTFace(fontPattern, FC_FT_FACE, face);
         }
     }
 
     PreparePattern(pattern, aFontStyle->printerFont);
     nsAutoRef<FcPattern> renderPattern
         (FcFontRenderPrepare(nullptr, pattern, fontPattern));
     if (fontPattern != mFontPattern) {
         // Discard temporary pattern used for variation support