Title: [285318] trunk/Source/WebCore
Revision
285318
Author
[email protected]
Date
2021-11-04 16:18:23 -0700 (Thu, 04 Nov 2021)

Log Message

[Cocoa] Migrate from CTFontCopyVariationAxes() to CTFontCopyVariationAxesInternal() if possible
https://bugs.webkit.org/show_bug.cgi?id=232690

Reviewed by Simon Fraser and Cameron McCormack.

Source/WebCore:

CTFontCopyVariationAxesInternal() is faster than CTFontCopyVariationAxes(), but the strings
it provides are not localized. Luckily, we don't actually use the strings in the common case,
so we can migrate to CTFontCopyVariationAxesInternal() safely.

No new tests because there is no behavior change.

* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::variationAxes):
(WebCore::defaultVariationValues):
(WebCore::preparePlatformFont):
* platform/graphics/cocoa/FontCacheCoreText.h:
* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
(WebCore::FontPlatformData::variationAxes const):

Source/WebCore/PAL:

* pal/spi/cf/CoreTextSPI.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (285317 => 285318)


--- trunk/Source/WebCore/ChangeLog	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/ChangeLog	2021-11-04 23:18:23 UTC (rev 285318)
@@ -1,3 +1,24 @@
+2021-11-04  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Migrate from CTFontCopyVariationAxes() to CTFontCopyVariationAxesInternal() if possible
+        https://bugs.webkit.org/show_bug.cgi?id=232690
+
+        Reviewed by Simon Fraser and Cameron McCormack.
+
+        CTFontCopyVariationAxesInternal() is faster than CTFontCopyVariationAxes(), but the strings
+        it provides are not localized. Luckily, we don't actually use the strings in the common case,
+        so we can migrate to CTFontCopyVariationAxesInternal() safely.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::variationAxes):
+        (WebCore::defaultVariationValues):
+        (WebCore::preparePlatformFont):
+        * platform/graphics/cocoa/FontCacheCoreText.h:
+        * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
+        (WebCore::FontPlatformData::variationAxes const):
+
 2021-11-04  Nikolaos Mouchtaris  <[email protected]>
 
         Make scrollbar orientation an enum class

Modified: trunk/Source/WebCore/Headers.cmake (285317 => 285318)


--- trunk/Source/WebCore/Headers.cmake	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/Headers.cmake	2021-11-04 23:18:23 UTC (rev 285318)
@@ -1373,6 +1373,7 @@
     platform/graphics/RenderingResourceIdentifier.h
     platform/graphics/RenderingMode.h
     platform/graphics/RoundedRect.h
+    platform/graphics/ShouldLocalizeAxisNames.h
     platform/graphics/SourceBufferPrivate.h
     platform/graphics/SourceBufferPrivateClient.h
     platform/graphics/StringTruncator.h

Modified: trunk/Source/WebCore/PAL/ChangeLog (285317 => 285318)


--- trunk/Source/WebCore/PAL/ChangeLog	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/PAL/ChangeLog	2021-11-04 23:18:23 UTC (rev 285318)
@@ -1,3 +1,12 @@
+2021-11-04  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Migrate from CTFontCopyVariationAxes() to CTFontCopyVariationAxesInternal() if possible
+        https://bugs.webkit.org/show_bug.cgi?id=232690
+
+        Reviewed by Simon Fraser and Cameron McCormack.
+
+        * pal/spi/cf/CoreTextSPI.h:
+
 2021-11-04  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r285228.

Modified: trunk/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h (285317 => 285318)


--- trunk/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h	2021-11-04 23:18:23 UTC (rev 285318)
@@ -169,6 +169,7 @@
 CTFontRef CTFontCreateForCharactersWithLanguageAndOption(CTFontRef currentFont, const UTF16Char *characters, CFIndex length, CFStringRef language, CTFontFallbackOption, CFIndex *coveredLength);
 CTFontRef CTFontCopyPhysicalFont(CTFontRef);
 CTFontSymbolicTraits CTFontGetPhysicalSymbolicTraits(CTFontRef);
+CFArrayRef CTFontCopyVariationAxesInternal(CTFontRef);
 
 extern const CFStringRef kCTUIFontTextStyleShortHeadline;
 extern const CFStringRef kCTUIFontTextStyleShortBody;

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (285317 => 285318)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-11-04 23:18:23 UTC (rev 285318)
@@ -629,6 +629,7 @@
 		1C26671B26FA932F00117073 /* FontCreationContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C26671926FA7F2E00117073 /* FontCreationContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1C43DE6B22AB4B8A001527D9 /* LocalCurrentTraitCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C43DE6822AB4B8A001527D9 /* LocalCurrentTraitCollection.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1C4D0DD324D9F10D003D7498 /* GlyphBufferMembers.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C4D0DD124D9F0DB003D7498 /* GlyphBufferMembers.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		1C4DB02627339FE0007B0AD1 /* ShouldLocalizeAxisNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C4DB02427339E5E007B0AD1 /* ShouldLocalizeAxisNames.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1C5E1DA826F94B9000E07AF1 /* FontPaletteValues.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C5E1DA626F949B900E07AF1 /* FontPaletteValues.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1C6626111C6E7CA600AB527C /* FontFace.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C66260F1C6E7CA600AB527C /* FontFace.h */; };
 		1C73A7132185757E004CCEA5 /* TextUnderlineOffset.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CB6B4FB217B83940093B9CD /* TextUnderlineOffset.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -7037,6 +7038,7 @@
 		1C43DE6A22AB4B8A001527D9 /* LocalCurrentTraitCollection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalCurrentTraitCollection.mm; sourceTree = "<group>"; };
 		1C4674FD26F4843600B61273 /* FontPalette.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontPalette.h; sourceTree = "<group>"; };
 		1C4D0DD124D9F0DB003D7498 /* GlyphBufferMembers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GlyphBufferMembers.h; sourceTree = "<group>"; };
+		1C4DB02427339E5E007B0AD1 /* ShouldLocalizeAxisNames.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShouldLocalizeAxisNames.h; sourceTree = "<group>"; };
 		1C50C49522C84F2400A6E4BE /* WHLSLStandardLibraryFunctionMap.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLStandardLibraryFunctionMap.cpp; sourceTree = "<group>"; };
 		1C5E1DA626F949B900E07AF1 /* FontPaletteValues.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontPaletteValues.h; sourceTree = "<group>"; };
 		1C66260E1C6E7CA600AB527C /* FontFace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontFace.cpp; sourceTree = "<group>"; };
@@ -18609,11 +18611,11 @@
 		1A569CC40D7E2B60007C3983 /* bridge */ = {
 			isa = PBXGroup;
 			children = (
-				59B5977111086556007159E8 /* jsc */,
-				1A569CE20D7E2B82007C3983 /* objc */,
 				599E758F11055A1F00D904FA /* Bridge.h */,
 				1A71D5790F33819000F9CE4E /* IdentifierRep.cpp */,
 				1A71D57A0F33819000F9CE4E /* IdentifierRep.h */,
+				59B5977111086556007159E8 /* jsc */,
+				1A569CE20D7E2B82007C3983 /* objc */,
 				1A569CEF0D7E2B82007C3983 /* runtime_array.cpp */,
 				1A569CF00D7E2B82007C3983 /* runtime_array.h */,
 				1A569CF10D7E2B82007C3983 /* runtime_method.cpp */,
@@ -27368,6 +27370,7 @@
 				A73F95FD12C97BFE0031AAF9 /* RoundedRect.h */,
 				0F3DD44D12F5EA1B000D9190 /* ShadowBlur.cpp */,
 				0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */,
+				1C4DB02427339E5E007B0AD1 /* ShouldLocalizeAxisNames.h */,
 				1DD127AC256E3A8700B227D7 /* SourceBufferPrivate.cpp */,
 				CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */,
 				CDC8B5AC1804AE5D0016E685 /* SourceBufferPrivateClient.h */,
@@ -35393,6 +35396,7 @@
 				CD36C16B260A65CC00C8C529 /* SharedRoutingArbitrator.h in Headers */,
 				834DFAD01F7DAE5D00C2725B /* SharedStringHash.h in Headers */,
 				93309EA3099EB78C0056E581 /* SharedTimer.h in Headers */,
+				1C4DB02627339FE0007B0AD1 /* ShouldLocalizeAxisNames.h in Headers */,
 				DF19E2AC24772BC1007BDACB /* ShouldRelaxThirdPartyCookieBlocking.h in Headers */,
 				8362E8C120CEF9CB00245886 /* ShouldTreatAsContinuingLoad.h in Headers */,
 				9316DDFB240C64B4009340AA /* SimpleRange.h in Headers */,

Modified: trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp (285317 => 285318)


--- trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp	2021-11-04 23:18:23 UTC (rev 285318)
@@ -575,7 +575,7 @@
 static Ref<Protocol::CSS::Font> buildObjectForFont(const Font& font)
 {
     auto resultVariationAxes = JSON::ArrayOf<Protocol::CSS::FontVariationAxis>::create();
-    for (auto& variationAxis : font.platformData().variationAxes()) {
+    for (auto& variationAxis : font.platformData().variationAxes(ShouldLocalizeAxisNames::Yes)) {
         auto axis = Protocol::CSS::FontVariationAxis::create()
             .setTag(variationAxis.tag())
             .setMinimumValue(variationAxis.minimumValue())

Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp (285317 => 285318)


--- trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp	2021-11-04 23:18:23 UTC (rev 285318)
@@ -82,7 +82,7 @@
 #endif
 
 #if !PLATFORM(COCOA)
-Vector<FontPlatformData::FontVariationAxis> FontPlatformData::variationAxes() const
+Vector<FontPlatformData::FontVariationAxis> FontPlatformData::variationAxes(ShouldLocalizeAxisNames) const
 {
     // FIXME: <webkit.org/b/219614> Not implemented yet.
     return { };

Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (285317 => 285318)


--- trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2021-11-04 23:18:23 UTC (rev 285318)
@@ -25,6 +25,7 @@
 #pragma once
 
 #include "SharedBuffer.h"
+#include "ShouldLocalizeAxisNames.h"
 #include "TextFlags.h"
 #include <wtf/Forward.h>
 #include <wtf/RetainPtr.h>
@@ -179,7 +180,7 @@
     bool isForTextCombine() const { return widthVariant() != FontWidthVariant::RegularWidth; } // Keep in sync with callers of FontDescription::setWidthVariant().
 
     String familyName() const;
-    Vector<FontVariationAxis> variationAxes() const;
+    Vector<FontVariationAxis> variationAxes(ShouldLocalizeAxisNames) const;
 
 #if USE(CAIRO)
     cairo_scaled_font_t* scaledFont() const { return m_scaledFont.get(); }

Added: trunk/Source/WebCore/platform/graphics/ShouldLocalizeAxisNames.h (0 => 285318)


--- trunk/Source/WebCore/platform/graphics/ShouldLocalizeAxisNames.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ShouldLocalizeAxisNames.h	2021-11-04 23:18:23 UTC (rev 285318)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <cstdint>
+
+namespace WebCore {
+
+enum class ShouldLocalizeAxisNames : uint8_t {
+    No,
+    Yes
+};
+
+}
Property changes on: trunk/Source/WebCore/platform/graphics/ShouldLocalizeAxisNames.h
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Author Date Id Rev URL \ No newline at end of property

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


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2021-11-04 23:18:23 UTC (rev 285318)
@@ -300,10 +300,22 @@
     return CFStringGetLength(fontName) > 0 && CFStringGetCharacterAtIndex(fontName, 0) == '.';
 }
 
-VariationDefaultsMap defaultVariationValues(CTFontRef font)
+static RetainPtr<CFArrayRef> variationAxes(CTFontRef font, ShouldLocalizeAxisNames shouldLocalizeAxisNames)
 {
+#if defined(HAVE_CTFontCopyVariationAxesInternal) // This macro is defined inside CoreText, not WebKit.
+    if (shouldLocalizeAxisNames == ShouldLocalizeAxisNames::Yes)
+        return adoptCF(CTFontCopyVariationAxes(font));
+    return adoptCF(CTFontCopyVariationAxesInternal(font));
+#else
+    UNUSED_PARAM(shouldLocalizeAxisNames);
+    return adoptCF(CTFontCopyVariationAxes(font));
+#endif
+}
+
+VariationDefaultsMap defaultVariationValues(CTFontRef font, ShouldLocalizeAxisNames shouldLocalizeAxisNames)
+{
     VariationDefaultsMap result;
-    auto axes = adoptCF(CTFontCopyVariationAxes(font));
+    auto axes = variationAxes(font, shouldLocalizeAxisNames);
     if (!axes)
         return result;
     auto size = CFArrayGetCount(axes.get());
@@ -518,7 +530,7 @@
 
     auto fontOpticalSizing = fontDescription.opticalSizing();
 
-    auto defaultValues = defaultVariationValues(originalFont);
+    auto defaultValues = defaultVariationValues(originalFont, ShouldLocalizeAxisNames::No);
 
     auto fontSelectionRequest = fontDescription.fontSelectionRequest();
     auto fontStyleAxis = fontDescription.fontStyleAxis();
@@ -1021,7 +1033,7 @@
         return result;
 
     auto font = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor, 0, nullptr));
-    auto variations = adoptCF(CTFontCopyVariationAxes(font.get()));
+    auto variations = variationAxes(font.get(), ShouldLocalizeAxisNames::No);
     if (!variations)
         return result;
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h (285317 => 285318)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h	2021-11-04 23:18:23 UTC (rev 285318)
@@ -29,6 +29,7 @@
 #pragma once
 
 #include "FontDescription.h"
+#include "ShouldLocalizeAxisNames.h"
 
 #include <CoreText/CTFont.h>
 
@@ -72,5 +73,5 @@
 void addAttributesForWebFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts);
 RetainPtr<CFSetRef> installedFontMandatoryAttributes(AllowUserInstalledFonts);
 
-VariationDefaultsMap defaultVariationValues(CTFontRef);
+VariationDefaultsMap defaultVariationValues(CTFontRef, ShouldLocalizeAxisNames);
 }

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm (285317 => 285318)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2021-11-04 22:55:12 UTC (rev 285317)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2021-11-04 23:18:23 UTC (rev 285318)
@@ -62,7 +62,7 @@
     return nullptr;
 }
 
-Vector<FontPlatformData::FontVariationAxis> FontPlatformData::variationAxes() const
+Vector<FontPlatformData::FontVariationAxis> FontPlatformData::variationAxes(ShouldLocalizeAxisNames shouldLocalizeAxisNames) const
 {
     auto platformFont = ctFont();
     if (!platformFont)
@@ -69,7 +69,7 @@
         return { };
     
     Vector<FontVariationAxis> results;
-    for (auto& [tag, values] : defaultVariationValues(platformFont))
+    for (auto& [tag, values] : defaultVariationValues(platformFont, shouldLocalizeAxisNames))
         results.append(FontPlatformData::FontVariationAxis(values.axisName, String(tag.data(), tag.size()), values.defaultValue, values.minimumValue, values.maximumValue));
     
     return results;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to