Title: [266692] trunk/Source/WebCore
Revision
266692
Author
[email protected]
Date
2020-09-06 23:11:07 -0700 (Sun, 06 Sep 2020)

Log Message

[Cocoa] Prepare for migrating to CTFontHasTable() once it's faster than CTFontCopyAvailableTables()
https://bugs.webkit.org/show_bug.cgi?id=215688

Reviewed by Darin Adler.

Source/WebCore:

We can directly ask Core Text for the information we're looking for.

No new tests because there is no behavior change.

* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontType::FontType):
* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::fontHasVerticalGlyphs):
* platform/graphics/opentype/OpenTypeCG.cpp:
(WebCore::OpenType::fontHasMathTable):

Source/WebCore/PAL:

* pal/spi/cocoa/CoreTextSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (266691 => 266692)


--- trunk/Source/WebCore/ChangeLog	2020-09-07 02:22:02 UTC (rev 266691)
+++ trunk/Source/WebCore/ChangeLog	2020-09-07 06:11:07 UTC (rev 266692)
@@ -1,3 +1,21 @@
+2020-09-06  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Prepare for migrating to CTFontHasTable() once it's faster than CTFontCopyAvailableTables()
+        https://bugs.webkit.org/show_bug.cgi?id=215688
+
+        Reviewed by Darin Adler.
+
+        We can directly ask Core Text for the information we're looking for.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::FontType::FontType):
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::fontHasVerticalGlyphs):
+        * platform/graphics/opentype/OpenTypeCG.cpp:
+        (WebCore::OpenType::fontHasMathTable):
+
 2020-09-06  Wenson Hsieh  <[email protected]>
 
         Make `WebCore::WritingMode` an 8-bit enum class

Modified: trunk/Source/WebCore/PAL/ChangeLog (266691 => 266692)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-09-07 02:22:02 UTC (rev 266691)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-09-07 06:11:07 UTC (rev 266692)
@@ -1,3 +1,12 @@
+2020-09-06  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Prepare for migrating to CTFontHasTable() once it's faster than CTFontCopyAvailableTables()
+        https://bugs.webkit.org/show_bug.cgi?id=215688
+
+        Reviewed by Darin Adler.
+
+        * pal/spi/cocoa/CoreTextSPI.h:
+
 2020-09-05  Myles C. Maxfield  <[email protected]>
 
         [Cocoa] USE(PLATFORM_SYSTEM_FALLBACK_LIST) is true on all Cocoa platforms, so there's no need to consult it in Cocoa-specific files

Modified: trunk/Source/WebCore/platform/graphics/Font.h (266691 => 266692)


--- trunk/Source/WebCore/platform/graphics/Font.h	2020-09-07 02:22:02 UTC (rev 266691)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2020-09-07 06:11:07 UTC (rev 266692)
@@ -64,6 +64,11 @@
 enum Pitch { UnknownPitch, FixedPitch, VariablePitch };
 enum class IsForPlatformFont : uint8_t { No, Yes };
 
+#if PLATFORM(COCOA)
+bool fontHasTable(CTFontRef, unsigned tableTag);
+bool fontHasEitherTable(CTFontRef, unsigned tableTag1, unsigned tableTag2);
+#endif
+
 DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(Font);
 class Font : public RefCounted<Font> {
     WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Font);

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (266691 => 266692)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2020-09-07 02:22:02 UTC (rev 266691)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2020-09-07 06:11:07 UTC (rev 266692)
@@ -479,36 +479,32 @@
 struct FontType {
     FontType(CTFontRef font)
     {
+        bool foundStat = false;
+        bool foundTrak = false;
         auto tables = adoptCF(CTFontCopyAvailableTables(font, kCTFontTableOptionNoOptions));
         if (!tables)
             return;
-        bool foundStat = false;
-        bool foundTrak = false;
         auto size = CFArrayGetCount(tables.get());
         for (CFIndex i = 0; i < size; ++i) {
-            // This is so yucky.
-            // https://developer.apple.com/reference/coretext/1510774-ctfontcopyavailabletables
-            // "The returned set will contain unboxed values, which can be extracted like so:"
-            // "CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tags, index);"
-            CTFontTableTag tableTag = static_cast<CTFontTableTag>(reinterpret_cast<uintptr_t>(CFArrayGetValueAtIndex(tables.get(), i)));
+            auto tableTag = static_cast<CTFontTableTag>(reinterpret_cast<uintptr_t>(CFArrayGetValueAtIndex(tables.get(), i)));
             switch (tableTag) {
-            case 'fvar':
+            case kCTFontTableFvar:
                 if (variationType == VariationType::NotVariable)
                     variationType = VariationType::TrueTypeGX;
                 break;
-            case 'STAT':
+            case kCTFontTableSTAT:
                 foundStat = true;
                 variationType = VariationType::OpenType18;
                 break;
-            case 'morx':
-            case 'mort':
+            case kCTFontTableMorx:
+            case kCTFontTableMort:
                 aatShaping = true;
                 break;
-            case 'GPOS':
-            case 'GSUB':
+            case kCTFontTableGPOS:
+            case kCTFontTableGSUB:
                 openTypeShaping = true;
                 break;
-            case 'trak':
+            case kCTFontTableTrak:
                 foundTrak = true;
                 break;
             }

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm (266691 => 266692)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2020-09-07 02:22:02 UTC (rev 266691)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2020-09-07 06:11:07 UTC (rev 266692)
@@ -62,19 +62,9 @@
     return a && CFStringCompare(a, b, kCFCompareCaseInsensitive) == kCFCompareEqualTo;
 }
 
-static bool fontHasVerticalGlyphs(CTFontRef ctFont)
+static bool fontHasVerticalGlyphs(CTFontRef font)
 {
-    // The check doesn't look neat but this is what AppKit does for vertical writing...
-    RetainPtr<CFArrayRef> tableTags = adoptCF(CTFontCopyAvailableTables(ctFont, kCTFontTableOptionNoOptions));
-    if (!tableTags)
-        return false;
-    CFIndex numTables = CFArrayGetCount(tableTags.get());
-    for (CFIndex index = 0; index < numTables; ++index) {
-        CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tableTags.get(), index);
-        if (tag == kCTFontTableVhea || tag == kCTFontTableVORG)
-            return true;
-    }
-    return false;
+    return fontHasEitherTable(font, kCTFontTableVhea, kCTFontTableVORG);
 }
 
 #if PLATFORM(IOS_FAMILY)
@@ -119,6 +109,34 @@
     return familyName && caseInsensitiveCompare(familyName, CFSTR("Ahem"));
 }
 
+bool fontHasTable(CTFontRef ctFont, unsigned tableTag)
+{
+    auto tableTags = adoptCF(CTFontCopyAvailableTables(ctFont, kCTFontTableOptionNoOptions));
+    if (!tableTags)
+        return false;
+    CFIndex numTables = CFArrayGetCount(tableTags.get());
+    for (CFIndex index = 0; index < numTables; ++index) {
+        auto tag = static_cast<CTFontTableTag>(reinterpret_cast<uintptr_t>(CFArrayGetValueAtIndex(tableTags.get(), index)));
+        if (tag == tableTag)
+            return true;
+    }
+    return false;
+}
+
+bool fontHasEitherTable(CTFontRef ctFont, unsigned tableTag1, unsigned tableTag2)
+{
+    auto tableTags = adoptCF(CTFontCopyAvailableTables(ctFont, kCTFontTableOptionNoOptions));
+    if (!tableTags)
+        return false;
+    CFIndex numTables = CFArrayGetCount(tableTags.get());
+    for (CFIndex index = 0; index < numTables; ++index) {
+        auto tag = static_cast<CTFontTableTag>(reinterpret_cast<uintptr_t>(CFArrayGetValueAtIndex(tableTags.get(), index)));
+        if (tag == tableTag1 || tag == tableTag2)
+            return true;
+    }
+    return false;
+}
+
 void Font::platformInit()
 {
 #if PLATFORM(IOS_FAMILY)
@@ -137,7 +155,7 @@
     // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows:
     // "If set, it is strongly recommended to use OS/2.sTypoAscender - OS/2.sTypoDescender+ OS/2.sTypoLineGap as a value for default line spacing for this font."
     // On OS X, we only apply this rule in the important case of fonts with a MATH table.
-    if (OpenType::fontHasMathTable(m_platformData.ctFont())) {
+    if (fontHasTable(m_platformData.ctFont(), kCTFontTableMATH)) {
         short typoAscent, typoDescent, typoLineGap;
         if (OpenType::tryGetTypoMetrics(m_platformData.font(), typoAscent, typoDescent, typoLineGap)) {
             ascent = scaleEmToUnits(typoAscent, unitsPerEm) * pointSize;

Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp (266691 => 266692)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp	2020-09-07 02:22:02 UTC (rev 266691)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp	2020-09-07 06:11:07 UTC (rev 266692)
@@ -35,20 +35,6 @@
 static const unsigned long kCTFontTableOS2 = 'OS/2';
 #endif
 
-bool fontHasMathTable(CTFontRef ctFont)
-{
-    RetainPtr<CFArrayRef> tableTags = adoptCF(CTFontCopyAvailableTables(ctFont, kCTFontTableOptionNoOptions));
-    if (!tableTags)
-        return false;
-    CFIndex numTables = CFArrayGetCount(tableTags.get());
-    for (CFIndex index = 0; index < numTables; ++index) {
-        CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tableTags.get(), index);
-        if (tag == 'MATH')
-            return true;
-    }
-    return false;
-}
-
 static inline short readShortFromTable(const UInt8* os2Data, CFIndex offset)
 {
     return *(reinterpret_cast<const OpenType::Int16*>(os2Data + offset));

Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h (266691 => 266692)


--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h	2020-09-07 02:22:02 UTC (rev 266691)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h	2020-09-07 06:11:07 UTC (rev 266692)
@@ -36,7 +36,6 @@
 namespace WebCore {
 namespace OpenType {
 
-bool fontHasMathTable(CTFontRef);
 bool tryGetTypoMetrics(CTFontRef, short& ascent, short& descent, short& lineGap);
 
 } // namespace OpenType
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to