Title: [289870] trunk/Source/WebCore
Revision
289870
Author
[email protected]
Date
2022-02-15 17:47:37 -0800 (Tue, 15 Feb 2022)

Log Message

Add a new rule to decide if a font is used only for icons
https://bugs.webkit.org/show_bug.cgi?id=236660
rdar://84829499

Reviewed by Wenson Hsieh.

Add check for more characters to avoid incorrectly tagging certain fonts as symbol-only.

* platform/graphics/coretext/FontCoreText.cpp:
(WebCore::hasGlyphsForCharacterRange):
(WebCore::Font::isProbablyOnlyUsedToRenderIcons const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289869 => 289870)


--- trunk/Source/WebCore/ChangeLog	2022-02-16 01:40:26 UTC (rev 289869)
+++ trunk/Source/WebCore/ChangeLog	2022-02-16 01:47:37 UTC (rev 289870)
@@ -1,3 +1,17 @@
+2022-02-15  Sihui Liu  <[email protected]>
+
+        Add a new rule to decide if a font is used only for icons
+        https://bugs.webkit.org/show_bug.cgi?id=236660
+        rdar://84829499
+
+        Reviewed by Wenson Hsieh.
+
+        Add check for more characters to avoid incorrectly tagging certain fonts as symbol-only.
+
+        * platform/graphics/coretext/FontCoreText.cpp:
+        (WebCore::hasGlyphsForCharacterRange):
+        (WebCore::Font::isProbablyOnlyUsedToRenderIcons const):
+
 2022-02-15  Brady Eidson  <[email protected]>
 
         Implement ServiceWorkerRegistration.getNotifications().

Modified: trunk/Source/WebCore/platform/graphics/coretext/FontCoreText.cpp (289869 => 289870)


--- trunk/Source/WebCore/platform/graphics/coretext/FontCoreText.cpp	2022-02-16 01:40:26 UTC (rev 289869)
+++ trunk/Source/WebCore/platform/graphics/coretext/FontCoreText.cpp	2022-02-16 01:47:37 UTC (rev 289870)
@@ -812,6 +812,33 @@
     return CTFontGetGlyphsForCharacters(platformData().ctFont(), codeUnits, glyphs, count);
 }
 
+static bool hasGlyphsForCharacterRange(CTFontRef font, UniChar firstCharacter, UniChar lastCharacter, bool expectValidGlyphsForAllCharacters)
+{
+    const unsigned numberOfCharacters = lastCharacter - firstCharacter + 1;
+    Vector<CGGlyph> glyphs;
+    glyphs.fill(0, numberOfCharacters);
+    CTFontGetGlyphsForCharacterRange(font, glyphs.begin(), CFRangeMake(firstCharacter, numberOfCharacters));
+    glyphs.removeAll(0);
+
+    if (glyphs.isEmpty())
+        return false;
+
+    Vector<CGRect> boundingRects;
+    boundingRects.fill(CGRectZero, glyphs.size());
+    CTFontGetBoundingRectsForGlyphs(font, kCTFontOrientationDefault, glyphs.begin(), boundingRects.begin(), glyphs.size());
+
+    unsigned validGlyphsCount = 0;
+    for (auto& rect : boundingRects) {
+        if (!CGRectIsEmpty(rect))
+            ++validGlyphsCount;
+    }
+
+    if (expectValidGlyphsForAllCharacters)
+        return validGlyphsCount == glyphs.size();
+
+    return validGlyphsCount;
+}
+
 bool Font::isProbablyOnlyUsedToRenderIcons() const
 {
     auto platformFont = platformData().ctFont();
@@ -831,25 +858,7 @@
     if (CFCharacterSetHasMemberInPlane(supportedCharacters.get(), 1) || CFCharacterSetHasMemberInPlane(supportedCharacters.get(), 2))
         return false;
 
-    // This encompasses all basic Latin non-control characters.
-    constexpr UniChar firstCharacterToTest = ' ';
-    constexpr UniChar lastCharacterToTest = '~';
-    constexpr auto numberOfCharactersToTest = lastCharacterToTest - firstCharacterToTest + 1;
-
-    Vector<CGGlyph> glyphs;
-    glyphs.fill(0, numberOfCharactersToTest);
-    CTFontGetGlyphsForCharacterRange(platformFont, glyphs.begin(), CFRangeMake(firstCharacterToTest, numberOfCharactersToTest));
-    glyphs.removeAll(0);
-
-    if (glyphs.isEmpty())
-        return false;
-
-    Vector<CGRect> boundingRects;
-    boundingRects.fill(CGRectZero, glyphs.size());
-    CTFontGetBoundingRectsForGlyphs(platformFont, kCTFontOrientationDefault, glyphs.begin(), boundingRects.begin(), glyphs.size());
-    return notFound == boundingRects.findIf([](auto& rect) {
-        return !CGRectIsEmpty(rect);
-    });
+    return !hasGlyphsForCharacterRange(platformFont, ' ', '~', false) && !hasGlyphsForCharacterRange(platformFont, 0x0600, 0x06FF, true);
 }
 
 #if PLATFORM(COCOA)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to