[iOS] Narrow non-breaking space does not fall back to a correct font
[WebKit-https.git] / Source / WebCore / platform / graphics / ios / FontCacheIOS.mm
index 059a0c8d6153ca7f4f5a542e71c56a896bf57ee9..b6306b12fd7b028b4a76107fd70d878808142016 100644 (file)
@@ -50,7 +50,7 @@ static inline bool isFontWeightBold(NSInteger fontWeight)
 
 static inline bool requiresCustomFallbackFont(const UInt32 character)
 {
-    return character == AppleLogo || character == blackCircle;
+    return character == AppleLogo || character == blackCircle || character == narrowNonBreakingSpace;
 }
 
 static CFCharacterSetRef copyFontCharacterSet(CFStringRef fontName)
@@ -487,15 +487,30 @@ PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescri
 FontPlatformData* FontCache::getCustomFallbackFont(const UInt32 c, const FontDescription& description)
 {
     ASSERT(requiresCustomFallbackFont(c));
-    if (c == AppleLogo) {
-        static NeverDestroyed<AtomicString> helveticaFamily("Helvetica Neue", AtomicString::ConstructFromLiteral);
-        return getCachedFontPlatformData(description, helveticaFamily);
-    }
-    if (c == blackCircle) {
-        static NeverDestroyed<AtomicString> lockClockFamily("LockClock-Light", AtomicString::ConstructFromLiteral);
-        return getCachedFontPlatformData(description, lockClockFamily);
+
+    static NeverDestroyed<AtomicString> helveticaFamily("Helvetica Neue", AtomicString::ConstructFromLiteral);
+    static NeverDestroyed<AtomicString> lockClockFamily("LockClock-Light", AtomicString::ConstructFromLiteral);
+    static NeverDestroyed<AtomicString> timesNewRomanPSMTFamily("TimesNewRomanPSMT", AtomicString::ConstructFromLiteral);
+
+    AtomicString* family = nullptr;
+    switch (c) {
+    case AppleLogo:
+        family = &helveticaFamily.get();
+        break;
+    case blackCircle:
+        family = &lockClockFamily.get();
+        break;
+    case narrowNonBreakingSpace:
+        family = &timesNewRomanPSMTFamily.get();
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+        return nullptr;
     }
-    return nullptr;
+    ASSERT(family);
+    if (!family)
+        return nullptr;
+    return getCachedFontPlatformData(description, *family);
 }
 
 static inline FontTraitsMask toTraitsMask(CTFontSymbolicTraits ctFontTraits)