Improve font matching with FontConfig and FreeType
authortimothy@hatcher.name <timothy@hatcher.name@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jul 2017 19:16:44 +0000 (19:16 +0000)
committertimothy@hatcher.name <timothy@hatcher.name@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jul 2017 19:16:44 +0000 (19:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174374

Reviewed by Michael Catanzaro.

* platform/graphics/freetype/FontCacheFreeType.cpp:
(WebCore::FontCache::createFontPlatformData): Loop through all family name matches from FcFontMatch.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219418 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp

index df88dbc..2998c22 100644 (file)
@@ -1,3 +1,13 @@
+2017-07-12  Timothy Hatcher  <timothy@hatcher.name>
+
+        Improve font matching with FontConfig and FreeType
+        https://bugs.webkit.org/show_bug.cgi?id=174374
+
+        Reviewed by Michael Catanzaro.
+
+        * platform/graphics/freetype/FontCacheFreeType.cpp:
+        (WebCore::FontCache::createFontPlatformData): Loop through all family name matches from FcFontMatch.
+
 2017-07-12  Youenn Fablet  <youenn@apple.com>
 
         Reactivate audio ducking when restarting the shared unit
index 6f57ae4..158acd8 100644 (file)
@@ -364,15 +364,22 @@ std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
     if (!resultPattern) // No match.
         return nullptr;
 
+    // Loop through each font family of the result to see if it fits the one we requested.
+    bool matchedFontFamily = false;
     FcChar8* fontConfigFamilyNameAfterMatching;
-    FcPatternGetString(resultPattern.get(), FC_FAMILY, 0, &fontConfigFamilyNameAfterMatching);
-    String familyNameAfterMatching = String::fromUTF8(reinterpret_cast<char*>(fontConfigFamilyNameAfterMatching));
-
-    // If Fontconfig gave us a different font family than the one we requested, we should ignore it
-    // and allow WebCore to give us the next font on the CSS fallback list. The exceptions are if
-    // this family name is a commonly-used generic family, or if the families are strongly-aliased.
-    // Checking for a strong alias comes last, since it is slow.
-    if (!equalIgnoringASCIICase(familyNameAfterConfiguration, familyNameAfterMatching) && !isCommonlyUsedGenericFamily(familyNameString) && !areStronglyAliased(familyNameAfterConfiguration, familyNameAfterMatching))
+    for (int i = 0; FcPatternGetString(resultPattern.get(), FC_FAMILY, i, &fontConfigFamilyNameAfterMatching) == FcResultMatch; ++i) {
+        // If Fontconfig gave us a different font family than the one we requested, we should ignore it
+        // and allow WebCore to give us the next font on the CSS fallback list. The exceptions are if
+        // this family name is a commonly-used generic family, or if the families are strongly-aliased.
+        // Checking for a strong alias comes last, since it is slow.
+        String familyNameAfterMatching = String::fromUTF8(reinterpret_cast<char*>(fontConfigFamilyNameAfterMatching));
+        if (equalIgnoringASCIICase(familyNameAfterConfiguration, familyNameAfterMatching) || isCommonlyUsedGenericFamily(familyNameString) || areStronglyAliased(familyNameAfterConfiguration, familyNameAfterMatching)) {
+            matchedFontFamily = true;
+            break;
+        }
+    }
+
+    if (!matchedFontFamily)
         return nullptr;
 
     // Verify that this font has an encoding compatible with Fontconfig. Fontconfig currently