Modified: trunk/Source/WebCore/ChangeLog (281643 => 281644)
--- trunk/Source/WebCore/ChangeLog 2021-08-26 19:22:37 UTC (rev 281643)
+++ trunk/Source/WebCore/ChangeLog 2021-08-26 19:30:32 UTC (rev 281644)
@@ -1,3 +1,18 @@
+2021-08-26 Michael Catanzaro <[email protected]>
+
+ [FreeType] Avoid yucky strong alias computations in font fallback code
+ https://bugs.webkit.org/show_bug.cgi?id=228927
+
+ Reviewed by Myles C. Maxfield.
+
+ If built against the upcoming Fontconfig 2.13.95, we can avoid compiling a bunch of arcane
+ font matching code. It will be a while before we can require Fontconfig 2.13.95, so use
+ preprocessor guards for now.
+
+ * platform/graphics/freetype/FontCacheFreeType.cpp:
+ (WebCore::areStronglyAliased):
+ (WebCore::FontCache::createFontPlatformData):
+
2021-08-26 Commit Queue <[email protected]>
Unreviewed, reverting r281616.
Modified: trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp (281643 => 281644)
--- trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp 2021-08-26 19:22:37 UTC (rev 281643)
+++ trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp 2021-08-26 19:30:32 UTC (rev 281644)
@@ -355,9 +355,9 @@
return "";
}
-// This is based on Chromium BSD code from Skia (src/ports/SkFontMgr_fontconfig.cpp). It is a
-// hack for lack of API in Fontconfig: https://bugs.freedesktop.org/show_bug.cgi?id=19375
-// FIXME: This is horrible. It should be deleted once Fontconfig can do this itself.
+#if FC_VERSION < 21395
+// This is based on BSD-licensed code from Skia (src/ports/SkFontMgr_fontconfig.cpp).
+// It is obsoleted by newer Fontconfig, see https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/294.
enum class AliasStrength {
Weak,
Strong,
@@ -482,6 +482,7 @@
}
return false;
}
+#endif // FC_VERSION < 21395
static inline bool isCommonlyUsedGenericFamily(const String& familyNameString)
{
@@ -515,8 +516,6 @@
if (!configurePatternForFontDescription(pattern.get(), fontDescription))
return nullptr;
- // The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp):
- //
// We do not normally allow fontconfig to substitute one font family for another, since this
// would break CSS font family fallback: the website should be in control of fallback. During
// normal font matching, the only font family substitution permitted is for generic families
@@ -540,20 +539,33 @@
if (!resultPattern) // No match.
return nullptr;
- // Loop through each font family of the result to see if it fits the one we requested.
+#if FC_VERSION < 21395
bool matchedFontFamily = false;
FcChar8* fontConfigFamilyNameAfterMatching;
for (int i = 0; FcPatternGetString(resultPattern.get(), FC_FAMILY, i, &fontConfigFamilyNameAfterMatching) == FcResultMatch; ++i) {
+ String familyNameAfterMatching = String::fromUTF8(reinterpret_cast<char*>(fontConfigFamilyNameAfterMatching));
+ if (equalIgnoringASCIICase(familyNameAfterConfiguration, familyNameAfterMatching) || isCommonlyUsedGenericFamily(familyNameString) || areStronglyAliased(familyNameAfterConfiguration, familyNameAfterMatching)) {
+ matchedFontFamily = true;
+ break;
+ }
+ }
+#else
+ // Loop through each font family of the result to see if it fits the one we requested.
+ bool matchedFontFamily = false;
+ FcValue value;
+ FcValueBinding binding;
+ for (int i = 0; FcPatternGetWithBinding(resultPattern.get(), FC_FAMILY, i, &value, &binding) == FcResultMatch; ++i) {
+ ASSERT(value.type == FcTypeString);
+ String familyNameAfterMatching = String::fromUTF8(reinterpret_cast<const char*>(value.u.s));
// 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)) {
+ if (binding == FcValueBindingStrong || equalIgnoringASCIICase(familyNameAfterConfiguration, familyNameAfterMatching) || isCommonlyUsedGenericFamily(familyNameString)) {
matchedFontFamily = true;
break;
}
}
+#endif
if (!matchedFontFamily)
return nullptr;