Title: [295410] trunk/Source/WebCore
Revision
295410
Author
mmaxfi...@apple.com
Date
2022-06-08 22:12:01 -0700 (Wed, 08 Jun 2022)

Log Message

Cache system font shorthand information
https://bugs.webkit.org/show_bug.cgi?id=241404

Reviewed by Cameron McCormack.

This is the fourth piece of https://bugs.webkit.org/show_bug.cgi?id=237817.

System font shorthands are things like "font: caption" or "font: -apple-system-body".

There used to be a cache that was supposed to map each shorthand value to a CTFontDescriptor.
However, the cache didn't work, so I deleted it in
https://github.com/WebKit/WebKit/commit/6ead5274db5f92656360fa1fbae3e0091481fc4f. This patch
reimplements it, but does so in platform/graphics/SystemFontDatabase, which is the natural
place to put it.

One of the repercussions of putting it in platform/ is that it can't use real CSSValuesIDs
as keys into the cache (because it's a layering violation to make things in platform/ see
CSS things). Therefore, this patch creates its own enum, which lives in platform/, which
conveniently exactly matches the relevant values from CSSValueID.

The Cocoa ports already have a SystemFontDatabaseCoreText which does similar things, but this
new cache is not platform-specific, so I'm putting it in SystemFontDatabase instead of
SystemFontDatabaseCoreText. SystemFontDatabaseCoreText will now inherit from SystemFontDatabase,
with 0 virtual methods. I've also taken the existing code that populates the previous cache
and temporarily duplicated it in SystemFontDabase***.cpp to make it populate this cache.

This patch doesn't actually _call_ the new cache, because doing so is somewhat complicated and
deserves its own patch. This patch just implements the cache itself. Also, because callers
aren't migrated to use this new cache yet, this patch doesn't delete the old cache either.
Both of those things will come in a follow-up patch.

* Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h:
* Source/WebCore/PlatformPlayStation.cmake:
* Source/WebCore/PlatformWin.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/SourcesGTK.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/graphics/SystemFontDatabase.cpp: Added.
(WebCore::SystemFontDatabase::systemFontShorthandInfo const):
(WebCore::SystemFontDatabase::systemFontShorthandFamily):
(WebCore::SystemFontDatabase::systemFontShorthandSize):
(WebCore::SystemFontDatabase::systemFontShorthandWeight):
(WebCore::SystemFontDatabase::clear):
* Source/WebCore/platform/graphics/SystemFontDatabase.h: Added.
* Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::normalizeCTWeight):
(WebCore::denormalizeCTWeight):
* Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h:
* Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCocoa.mm: Added.
(WebCore::cocoaFontClass):
(WebCore::SystemFontDatabaseCoreText::smallCaptionFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::menuFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::statusBarFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::miniControlFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::smallControlFontDescriptor):
(WebCore::SystemFontDatabaseCoreText::controlFontDescriptor):
* Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp:
(WebCore::SystemFontDatabase::singleton):
(WebCore::SystemFontDatabaseCoreText::clear):
(WebCore::cssWeightOfSystemFontDescriptor):
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h:
* Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp: Added.
(WebCore::SystemFontDatabase::singleton):
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/platform/graphics/playstation/SystemFontDatabasePlayStation.cpp: Added.
(WebCore::SystemFontDatabase::singleton):
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/platform/graphics/win/SystemFontDatabaseWin.cpp: Added.
(WebCore::SystemFontDatabase::singleton):
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::getReplacementTextGeometry const):

Canonical link: https://commits.webkit.org/251416@main

Modified Paths

Added Paths

Diff

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


--- trunk/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h	2022-06-09 05:12:01 UTC (rev 295410)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2021 Apple Inc.  All rights reserved.
+ * Copyright (C) 2014-2022 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -99,6 +99,11 @@
     kCTFontDescriptorOptionThisIsNotARealOption = 0xFFFFFFFF
 };
 
+typedef CF_ENUM(uint32_t, CTFontTextStylePlatform)
+{
+    kCTFontTextStylePlatformDefault = (CTFontTextStylePlatform)-1,
+};
+
 #endif
 
 WTF_EXTERN_C_BEGIN
@@ -141,6 +146,7 @@
 CTFontDescriptorRef CTFontDescriptorCreateCopyWithSymbolicTraits(CTFontDescriptorRef original, CTFontSymbolicTraits symTraitValue, CTFontSymbolicTraits symTraitMask);
 CTFontDescriptorRef CTFontDescriptorCreateWithTextStyleAndAttributes(CFStringRef style, CFStringRef size, CFDictionaryRef attributes);
 CFBitVectorRef CTFontCopyGlyphCoverageForFeature(CTFontRef, CFDictionaryRef feature);
+CGFloat CTFontDescriptorGetTextStyleSize(CFStringRef style, CFTypeRef sizeCategory, CTFontTextStylePlatform, CGFloat* weight, CGFloat* lineSpacing);
 
 CTFontDescriptorRef CTFontDescriptorCreateWithAttributesAndOptions(CFDictionaryRef attributes, CTFontDescriptorOptions);
 CTFontDescriptorRef CTFontDescriptorCreateLastResort();

Modified: trunk/Source/WebCore/PlatformPlayStation.cmake (295409 => 295410)


--- trunk/Source/WebCore/PlatformPlayStation.cmake	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/PlatformPlayStation.cmake	2022-06-09 05:12:01 UTC (rev 295410)
@@ -45,6 +45,8 @@
 
     platform/graphics/libwpe/PlatformDisplayLibWPE.cpp
 
+    platform/graphics/playstation/SystemFontDatabasePlayStation.cpp
+
     platform/libwpe/PasteboardLibWPE.cpp
     platform/libwpe/PlatformKeyboardEventLibWPE.cpp
     platform/libwpe/PlatformPasteboardLibWPE.cpp

Modified: trunk/Source/WebCore/PlatformWin.cmake (295409 => 295410)


--- trunk/Source/WebCore/PlatformWin.cmake	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/PlatformWin.cmake	2022-06-09 05:12:01 UTC (rev 295410)
@@ -56,6 +56,7 @@
     platform/graphics/win/IntSizeWin.cpp
     platform/graphics/win/MediaPlayerPrivateFullscreenWindow.cpp
     platform/graphics/win/SimpleFontDataWin.cpp
+    platform/graphics/win/SystemFontDatabaseWin.cpp
     platform/graphics/win/TransformationMatrixWin.cpp
 
     platform/network/win/DownloadBundleWin.cpp

Modified: trunk/Source/WebCore/Sources.txt (295409 => 295410)


--- trunk/Source/WebCore/Sources.txt	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/Sources.txt	2022-06-09 05:12:01 UTC (rev 295410)
@@ -2110,6 +2110,7 @@
 platform/graphics/SourceBufferPrivate.cpp
 platform/graphics/SourceImage.cpp
 platform/graphics/StringTruncator.cpp
+platform/graphics/SystemFontDatabase.cpp
 platform/graphics/TextRun.cpp
 platform/graphics/TextTrackRepresentation.cpp
 platform/graphics/TrackBuffer.cpp

Modified: trunk/Source/WebCore/SourcesCocoa.txt (295409 => 295410)


--- trunk/Source/WebCore/SourcesCocoa.txt	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2022-06-09 05:12:01 UTC (rev 295410)
@@ -407,6 +407,7 @@
 platform/graphics/cocoa/MediaPlaybackTargetContext.mm
 platform/graphics/cocoa/SourceBufferParser.cpp
 platform/graphics/cocoa/SourceBufferParserWebM.cpp
+platform/graphics/cocoa/SystemFontDatabaseCocoa.mm
 platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp
 platform/graphics/cocoa/TextTrackRepresentationCocoa.mm
 platform/graphics/cocoa/VP9UtilitiesCocoa.mm @no-unify

Modified: trunk/Source/WebCore/SourcesGTK.txt (295409 => 295410)


--- trunk/Source/WebCore/SourcesGTK.txt	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/SourcesGTK.txt	2022-06-09 05:12:01 UTC (rev 295410)
@@ -92,6 +92,7 @@
 platform/graphics/gtk/DisplayRefreshMonitorGtk.cpp
 platform/graphics/gtk/GdkCairoUtilities.cpp
 platform/graphics/gtk/ImageGtk.cpp
+platform/graphics/gtk/SystemFontDatabaseGTK.cpp
 
 platform/graphics/gstreamer/ImageGStreamerCairo.cpp
 

Modified: trunk/Source/WebCore/SourcesWPE.txt (295409 => 295410)


--- trunk/Source/WebCore/SourcesWPE.txt	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/SourcesWPE.txt	2022-06-09 05:12:01 UTC (rev 295410)
@@ -67,6 +67,8 @@
 platform/graphics/GLContext.cpp
 platform/graphics/PlatformDisplay.cpp
 
+platform/graphics/wpe/SystemFontDatabaseWPE.cpp
+
 platform/graphics/egl/GLContextEGL.cpp
 platform/graphics/egl/GLContextEGLLibWPE.cpp
 

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (295409 => 295410)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-06-09 05:12:01 UTC (rev 295410)
@@ -654,6 +654,7 @@
 		1CE8D12E261861C400FC3AEF /* DisplayListIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CE8D12C2618616400FC3AEF /* DisplayListIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1CEAA53226F336FC00868507 /* CSSFontPaletteValuesOverrideColorsValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CEAA53126F331C100868507 /* CSSFontPaletteValuesOverrideColorsValue.h */; };
 		1CFAE3230A6D6A3F0032593D /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CFAE3220A6D6A3F0032593D /* libobjc.dylib */; };
+		1CFD5D7E284DBE7F00089667 /* SystemFontDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C4C77DF284DA83900BD0936 /* SystemFontDatabase.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1D0026A42374D62400CA6CDF /* JSPictureInPictureWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D0026A22374D62300CA6CDF /* JSPictureInPictureWindow.h */; };
 		1D0026AA2374F9EA00CA6CDF /* JSEnterPictureInPictureEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D0026A82374F9D900CA6CDF /* JSEnterPictureInPictureEvent.h */; };
 		1D2C82B7236A3F6A0055D6C5 /* PictureInPictureSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D2C82B6236A3F6A0055D6C5 /* PictureInPictureSupport.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -7167,6 +7168,7 @@
 		1C12AC281EE778AE0079E0A0 /* FontFamilySpecificationCoreText.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FontFamilySpecificationCoreText.cpp; sourceTree = "<group>"; };
 		1C12AC291EE778AE0079E0A0 /* FontFamilySpecificationCoreText.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontFamilySpecificationCoreText.h; sourceTree = "<group>"; };
 		1C12AC2C1EE779950079E0A0 /* FontDescriptionCocoa.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FontDescriptionCocoa.cpp; sourceTree = "<group>"; };
+		1C16B86A284D6B8200318FEC /* SystemFontDatabaseCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemFontDatabaseCocoa.mm; sourceTree = "<group>"; };
 		1C16B86C284D73EF00318FEC /* FontCacheCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FontCacheCocoa.mm; sourceTree = "<group>"; };
 		1C18DA56181AF6A500C4EF22 /* TextPainter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextPainter.cpp; sourceTree = "<group>"; };
 		1C18DA57181AF6A500C4EF22 /* TextPainter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextPainter.h; sourceTree = "<group>"; };
@@ -7239,6 +7241,8 @@
 		1C43DE6822AB4B8A001527D9 /* LocalCurrentTraitCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalCurrentTraitCollection.h; sourceTree = "<group>"; };
 		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>"; };
+		1C4C77DE284DA83900BD0936 /* SystemFontDatabase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SystemFontDatabase.cpp; sourceTree = "<group>"; };
+		1C4C77DF284DA83900BD0936 /* SystemFontDatabase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemFontDatabase.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>"; };
@@ -29451,6 +29455,8 @@
 				501BAAA813950E2C00F7ACEB /* WindRule.h */,
 				379919941200DDF400EA041C /* WOFFFileFormat.cpp */,
 				379919951200DDF400EA041C /* WOFFFileFormat.h */,
+				1C4C77DE284DA83900BD0936 /* SystemFontDatabase.cpp */,
+				1C4C77DF284DA83900BD0936 /* SystemFontDatabase.h */,
 			);
 			path = graphics;
 			sourceTree = "<group>";
@@ -29596,6 +29602,7 @@
 				07F5CFF22582A4F800662EF5 /* WebMAudioUtilitiesCocoa.mm */,
 				7B1619102719880E00C40EAC /* WebProcessGraphicsContextGLCocoa.mm */,
 				1C16B86C284D73EF00318FEC /* FontCacheCocoa.mm */,
+				1C16B86A284D6B8200318FEC /* SystemFontDatabaseCocoa.mm */,
 			);
 			path = cocoa;
 			sourceTree = "<group>";
@@ -37326,6 +37333,7 @@
 				BE20507E18A458C20080647E /* RenderVTTCue.h in Headers */,
 				A871DFE40A15376B00B12A68 /* RenderWidget.h in Headers */,
 				A89CCC530F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.h in Headers */,
+				1CFD5D7E284DBE7F00089667 /* SystemFontDatabase.h in Headers */,
 				2DF512CE1D873E47001D6780 /* ReplaceRangeWithTextCommand.h in Headers */,
 				93309E0A099E64920056E581 /* ReplaceSelectionCommand.h in Headers */,
 				071C00342707D95500D027C7 /* ReplayKitCaptureSource.h in Headers */,

Modified: trunk/Source/WebCore/css/CSSValueKeywords.in (295409 => 295410)


--- trunk/Source/WebCore/css/CSSValueKeywords.in	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/css/CSSValueKeywords.in	2022-06-09 05:12:01 UTC (rev 295410)
@@ -27,6 +27,7 @@
 //
 // CSS_PROP_FONT:
 //
+// This needs to be kept in sync with SystemFontDatabase::FontShorthand.
 caption
 icon
 menu

Added: trunk/Source/WebCore/platform/graphics/SystemFontDatabase.cpp (0 => 295410)


--- trunk/Source/WebCore/platform/graphics/SystemFontDatabase.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/SystemFontDatabase.cpp	2022-06-09 05:12:01 UTC (rev 295410)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#include "config.h"
+#include "SystemFontDatabase.h"
+
+namespace WebCore {
+
+SystemFontDatabase::SystemFontDatabase() = default;
+
+auto SystemFontDatabase::systemFontShorthandInfo(FontShorthand fontShorthand) -> const SystemFontShorthandInfo& {
+    auto index = static_cast<FontShorthandUnderlyingType>(fontShorthand);
+    if (auto& entry = m_systemFontShorthandCache[index])
+        return *entry;
+
+    m_systemFontShorthandCache[index] = platformSystemFontShorthandInfo(fontShorthand);
+    return *m_systemFontShorthandCache[index];
+}
+
+const AtomString& SystemFontDatabase::systemFontShorthandFamily(FontShorthand fontShorthand)
+{
+    return systemFontShorthandInfo(fontShorthand).family;
+}
+
+float SystemFontDatabase::systemFontShorthandSize(FontShorthand fontShorthand)
+{
+    return systemFontShorthandInfo(fontShorthand).size;
+}
+
+FontSelectionValue SystemFontDatabase::systemFontShorthandWeight(FontShorthand fontShorthand)
+{
+    return systemFontShorthandInfo(fontShorthand).weight;
+}
+
+void SystemFontDatabase::clear()
+{
+    for (auto& item : m_systemFontShorthandCache)
+        item.reset();
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/graphics/SystemFontDatabase.h (0 => 295410)


--- trunk/Source/WebCore/platform/graphics/SystemFontDatabase.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/SystemFontDatabase.h	2022-06-09 05:12:01 UTC (rev 295410)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2022 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 "FontSelectionAlgorithm.h"
+#include <array>
+#include <optional>
+#include <wtf/text/AtomString.h>
+
+namespace WebCore {
+
+class SystemFontDatabase {
+public:
+    WEBCORE_EXPORT static SystemFontDatabase& singleton();
+
+    enum class FontShorthand {
+        // This needs to be kept in sync with CSSValue.
+        Caption,
+        Icon,
+        Menu,
+        MessageBox,
+        SmallCaption,
+        WebkitMiniControl,
+        WebkitSmallControl,
+        WebkitControl,
+#if PLATFORM(COCOA)
+        AppleSystemHeadline,
+        AppleSystemBody,
+        AppleSystemSubheadline,
+        AppleSystemFootnote,
+        AppleSystemCaption1,
+        AppleSystemCaption2,
+        AppleSystemShortHeadline,
+        AppleSystemShortBody,
+        AppleSystemShortSubheadline,
+        AppleSystemShortFootnote,
+        AppleSystemShortCaption1,
+        AppleSystemTallBody,
+        AppleSystemTitle0,
+        AppleSystemTitle1,
+        AppleSystemTitle2,
+        AppleSystemTitle3,
+        AppleSystemTitle4,
+#endif
+        StatusBar,
+    };
+    using FontShorthandUnderlyingType = std::underlying_type<FontShorthand>::type;
+    static constexpr auto fontShorthandCount = static_cast<FontShorthandUnderlyingType>(FontShorthand::StatusBar) + 1;
+
+    const AtomString& systemFontShorthandFamily(FontShorthand);
+    float systemFontShorthandSize(FontShorthand);
+    FontSelectionValue systemFontShorthandWeight(FontShorthand);
+
+    WEBCORE_EXPORT void clear();
+
+protected:
+    SystemFontDatabase();
+
+private:
+    struct SystemFontShorthandInfo {
+        AtomString family;
+        float size;
+        FontSelectionValue weight;
+    };
+    const SystemFontShorthandInfo& systemFontShorthandInfo(FontShorthand);
+    static SystemFontShorthandInfo platformSystemFontShorthandInfo(FontShorthand);
+
+    using SystemFontShorthandCache = std::array<std::optional<SystemFontShorthandInfo>, fontShorthandCount>;
+    SystemFontShorthandCache m_systemFontShorthandCache;
+};
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h (295409 => 295410)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h	2022-06-09 05:12:01 UTC (rev 295410)
@@ -27,6 +27,7 @@
 
 #if HAVE(IOSURFACE)
 
+#include "ImageBuffer.h"
 #include "ImageBufferCGBackend.h"
 #include "IOSurface.h"
 #include "IOSurfacePool.h"

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


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2022-06-09 05:12:01 UTC (rev 295410)
@@ -368,6 +368,37 @@
     return 523.7 * value - 109.3;
 }
 
+// These values were experimentally gathered from the various named weights of San Francisco.
+static struct {
+    float ctWeight;
+    float cssWeight;
+} keyframes[] = {
+    { -0.8, 30 },
+    { -0.4, 274 },
+    { 0, 400 },
+    { 0.23, 510 },
+    { 0.3, 590 },
+    { 0.4, 700 },
+    { 0.56, 860 },
+    { 0.62, 1000 },
+};
+static_assert(WTF_ARRAY_LENGTH(keyframes) > 0);
+
+float normalizeCTWeight(float value)
+{
+    if (value < keyframes[0].ctWeight)
+        return keyframes[0].cssWeight;
+    for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyframes) - 1; ++i) {
+        auto& before = keyframes[i];
+        auto& after = keyframes[i + 1];
+        if (value >= before.ctWeight && value <= after.ctWeight) {
+            float ratio = (value - before.ctWeight) / (after.ctWeight - before.ctWeight);
+            return ratio * (after.cssWeight - before.cssWeight) + before.cssWeight;
+        }
+    }
+    return keyframes[WTF_ARRAY_LENGTH(keyframes) - 1].cssWeight;
+}
+
 static inline float normalizeSlope(float value)
 {
     return value * 300;
@@ -378,6 +409,21 @@
     return (value + 109.3) / 523.7;
 }
 
+float denormalizeCTWeight(float value)
+{
+    if (value < keyframes[0].cssWeight)
+        return keyframes[0].ctWeight;
+    for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyframes) - 1; ++i) {
+        auto& before = keyframes[i];
+        auto& after = keyframes[i + 1];
+        if (value >= before.cssWeight && value <= after.cssWeight) {
+            float ratio = (value - before.cssWeight) / (after.cssWeight - before.cssWeight);
+            return ratio * (after.ctWeight - before.ctWeight) + before.ctWeight;
+        }
+    }
+    return keyframes[WTF_ARRAY_LENGTH(keyframes) - 1].ctWeight;
+}
+
 static inline float denormalizeSlope(float value)
 {
     return value / 300;

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


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h	2022-06-09 05:12:01 UTC (rev 295410)
@@ -72,8 +72,10 @@
 RetainPtr<CTFontRef> createFontForInstalledFonts(CTFontRef, AllowUserInstalledFonts);
 void addAttributesForWebFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts);
 RetainPtr<CFSetRef> installedFontMandatoryAttributes(AllowUserInstalledFonts);
+float normalizeCTWeight(float);
+float denormalizeCTWeight(float);
+
 CFStringRef getUIContentSizeCategoryDidChangeNotificationName();
-
 WEBCORE_EXPORT void setContentSizeCategory(const String&);
 WEBCORE_EXPORT CFStringRef contentSizeCategory();
 

Added: trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCocoa.mm (0 => 295410)


--- trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCocoa.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCocoa.mm	2022-06-09 05:12:01 UTC (rev 295410)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#import "config.h"
+#import "SystemFontDatabaseCoreText.h"
+
+#import <pal/ios/UIKitSoftLink.h>
+
+namespace WebCore {
+
+static auto cocoaFontClass()
+{
+#if PLATFORM(IOS_FAMILY)
+    return PAL::getUIFontClass();
+#else
+    return NSFont.class;
+#endif
+};
+
+RetainPtr<CTFontDescriptorRef> SystemFontDatabaseCoreText::smallCaptionFontDescriptor()
+{
+    auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() smallSystemFontSize]];
+    return static_cast<CTFontDescriptorRef>(font.fontDescriptor);
+}
+
+RetainPtr<CTFontDescriptorRef> SystemFontDatabaseCoreText::menuFontDescriptor()
+{
+    return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontMenuItem, [cocoaFontClass() systemFontSize], nullptr));
+}
+
+RetainPtr<CTFontDescriptorRef> SystemFontDatabaseCoreText::statusBarFontDescriptor()
+{
+    return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, [cocoaFontClass() labelFontSize], nullptr));
+}
+
+RetainPtr<CTFontDescriptorRef> SystemFontDatabaseCoreText::miniControlFontDescriptor()
+{
+#if PLATFORM(IOS_FAMILY)
+    return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontMiniSystem, 0, nullptr));
+#else
+    auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() systemFontSizeForControlSize:NSControlSizeMini]];
+    return static_cast<CTFontDescriptorRef>(font.fontDescriptor);
+#endif
+}
+
+RetainPtr<CTFontDescriptorRef> SystemFontDatabaseCoreText::smallControlFontDescriptor()
+{
+#if PLATFORM(IOS_FAMILY)
+    return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSmallSystem, 0, nullptr));
+#else
+    auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() systemFontSizeForControlSize:NSControlSizeSmall]];
+    return static_cast<CTFontDescriptorRef>(font.fontDescriptor);
+#endif
+}
+
+RetainPtr<CTFontDescriptorRef> SystemFontDatabaseCoreText::controlFontDescriptor()
+{
+#if PLATFORM(IOS_FAMILY)
+    return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, 0, nullptr));
+#else
+    auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() systemFontSizeForControlSize:NSControlSizeRegular]];
+    return static_cast<CTFontDescriptorRef>(font.fontDescriptor);
+#endif
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp (295409 => 295410)


--- trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp	2022-06-09 05:12:01 UTC (rev 295410)
@@ -40,6 +40,11 @@
     return database.get();
 }
 
+SystemFontDatabase& SystemFontDatabase::singleton()
+{
+    return SystemFontDatabaseCoreText::singleton();
+}
+
 SystemFontDatabaseCoreText::SystemFontDatabaseCoreText()
 {
 }
@@ -133,6 +138,7 @@
     m_cursiveFamilies.clear();
     m_fantasyFamilies.clear();
     m_monospaceFamilies.clear();
+    SystemFontDatabase::clear();
 }
 
 RetainPtr<CTFontRef> SystemFontDatabaseCoreText::createFontByApplyingWeightWidthItalicsAndFallbackBehavior(CTFontRef font, CGFloat weight, CGFloat width, bool italic, float size, AllowUserInstalledFonts allowUserInstalledFonts, CFStringRef design)
@@ -333,4 +339,88 @@
     return result;
 }
 
+static inline FontSelectionValue cssWeightOfSystemFontDescriptor(CTFontDescriptorRef fontDescriptor)
+{
+    auto resultRef = adoptCF(static_cast<CFNumberRef>(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontCSSWeightAttribute)));
+    float result = 0;
+    if (resultRef && CFNumberGetValue(resultRef.get(), kCFNumberFloatType, &result))
+        return FontSelectionValue(result);
+
+    auto traitsRef = adoptCF(static_cast<CFDictionaryRef>(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontTraitsAttribute)));
+    resultRef = static_cast<CFNumberRef>(CFDictionaryGetValue(traitsRef.get(), kCTFontWeightTrait));
+    CFNumberGetValue(resultRef.get(), kCFNumberFloatType, &result);
+    return FontSelectionValue(normalizeCTWeight(result));
 }
+
+auto SystemFontDatabase::platformSystemFontShorthandInfo(FontShorthand fontShorthand) -> SystemFontShorthandInfo
+{
+    auto interrogateFontDescriptorShorthandItem = [] (CTFontDescriptorRef fontDescriptor, const String& family) {
+        auto sizeNumber = adoptCF(static_cast<CFNumberRef>(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontSizeAttribute)));
+        float size = 0;
+        CFNumberGetValue(sizeNumber.get(), kCFNumberFloatType, &size);
+        auto weight = cssWeightOfSystemFontDescriptor(fontDescriptor);
+        return SystemFontShorthandInfo { AtomString(family), size, FontSelectionValue(weight) };
+    };
+
+    auto interrogateTextStyleShorthandItem = [] (CFStringRef textStyle) {
+        CGFloat weight = 0;
+        float size = CTFontDescriptorGetTextStyleSize(textStyle, contentSizeCategory(), kCTFontTextStylePlatformDefault, &weight, nullptr);
+        auto cssWeight = normalizeCTWeight(weight);
+        return SystemFontShorthandInfo { textStyle, size, FontSelectionValue(cssWeight) };
+    };
+
+    switch (fontShorthand) {
+    case FontShorthand::Caption:
+    case FontShorthand::Icon:
+    case FontShorthand::MessageBox:
+        return interrogateFontDescriptorShorthandItem(adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, 0, nullptr)).get(), "system-ui"_s);
+    case FontShorthand::Menu:
+        return interrogateFontDescriptorShorthandItem(SystemFontDatabaseCoreText::menuFontDescriptor().get(), "-apple-menu"_s);
+    case FontShorthand::SmallCaption:
+        return interrogateFontDescriptorShorthandItem(SystemFontDatabaseCoreText::smallCaptionFontDescriptor().get(), "system-ui"_s);
+    case FontShorthand::WebkitMiniControl:
+        return interrogateFontDescriptorShorthandItem(SystemFontDatabaseCoreText::miniControlFontDescriptor().get(), "system-ui"_s);
+    case FontShorthand::WebkitSmallControl:
+        return interrogateFontDescriptorShorthandItem(SystemFontDatabaseCoreText::smallControlFontDescriptor().get(), "system-ui"_s);
+    case FontShorthand::WebkitControl:
+        return interrogateFontDescriptorShorthandItem(SystemFontDatabaseCoreText::controlFontDescriptor().get(), "system-ui"_s);
+    case FontShorthand::AppleSystemHeadline:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleHeadline);
+    case FontShorthand::AppleSystemBody:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleBody);
+    case FontShorthand::AppleSystemSubheadline:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleSubhead);
+    case FontShorthand::AppleSystemFootnote:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleFootnote);
+    case FontShorthand::AppleSystemCaption1:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleCaption1);
+    case FontShorthand::AppleSystemCaption2:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleCaption2);
+    case FontShorthand::AppleSystemShortHeadline:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleShortHeadline);
+    case FontShorthand::AppleSystemShortBody:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleShortBody);
+    case FontShorthand::AppleSystemShortSubheadline:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleShortSubhead);
+    case FontShorthand::AppleSystemShortFootnote:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleShortFootnote);
+    case FontShorthand::AppleSystemShortCaption1:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleShortCaption1);
+    case FontShorthand::AppleSystemTallBody:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleTallBody);
+    case FontShorthand::AppleSystemTitle0:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleTitle0);
+    case FontShorthand::AppleSystemTitle1:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleTitle1);
+    case FontShorthand::AppleSystemTitle2:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleTitle2);
+    case FontShorthand::AppleSystemTitle3:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleTitle3);
+    case FontShorthand::AppleSystemTitle4:
+        return interrogateTextStyleShorthandItem(kCTUIFontTextStyleTitle4);
+    case FontShorthand::StatusBar:
+        return interrogateFontDescriptorShorthandItem(SystemFontDatabaseCoreText::statusBarFontDescriptor().get(), "-apple-status-bar"_s);
+    }
+}
+
+}

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h (295409 => 295410)


--- trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h	2022-06-09 05:12:01 UTC (rev 295410)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2018-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "FontDescription.h"
+#include "SystemFontDatabase.h"
 #include <pal/spi/cf/CoreTextSPI.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashTraits.h>
@@ -43,7 +44,7 @@
     TextStyle
 };
 
-class SystemFontDatabaseCoreText {
+class SystemFontDatabaseCoreText : public SystemFontDatabase {
 public:
     struct CascadeListParameters {
         CascadeListParameters()
@@ -96,9 +97,15 @@
     String fantasyFamily(const String& locale);
     String monospaceFamily(const String& locale);
 
+    const AtomString& systemFontShorthandFamily(FontShorthand);
+    float systemFontShorthandSize(FontShorthand);
+    FontSelectionValue systemFontShorthandWeight(FontShorthand);
+
     void clear();
 
 private:
+    friend class SystemFontDatabase;
+
     SystemFontDatabaseCoreText();
 
     Vector<RetainPtr<CTFontDescriptorRef>> cascadeList(const CascadeListParameters&, SystemFontKind);
@@ -107,6 +114,13 @@
     RetainPtr<CTFontRef> createSystemDesignFont(SystemFontKind, const CascadeListParameters&);
     RetainPtr<CTFontRef> createTextStyleFont(const CascadeListParameters&);
 
+    static RetainPtr<CTFontDescriptorRef> smallCaptionFontDescriptor();
+    static RetainPtr<CTFontDescriptorRef> menuFontDescriptor();
+    static RetainPtr<CTFontDescriptorRef> statusBarFontDescriptor();
+    static RetainPtr<CTFontDescriptorRef> miniControlFontDescriptor();
+    static RetainPtr<CTFontDescriptorRef> smallControlFontDescriptor();
+    static RetainPtr<CTFontDescriptorRef> controlFontDescriptor();
+
     static RetainPtr<CTFontRef> createFontByApplyingWeightWidthItalicsAndFallbackBehavior(CTFontRef, CGFloat weight, CGFloat width, bool italic, float size, AllowUserInstalledFonts, CFStringRef design = nullptr);
     static RetainPtr<CTFontDescriptorRef> removeCascadeList(CTFontDescriptorRef);
     static Vector<RetainPtr<CTFontDescriptorRef>> computeCascadeList(CTFontRef, CFStringRef locale);

Added: trunk/Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp (0 => 295410)


--- trunk/Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp	2022-06-09 05:12:01 UTC (rev 295410)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2020 Igalia S.L.
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "SystemFontDatabase.h"
+
+#include "WebKitFontFamilyNames.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+SystemFontDatabase& SystemFontDatabase::singleton()
+{
+    static NeverDestroyed<SystemFontDatabase> database = SystemFontDatabase();
+    return database.get();
+}
+
+auto SystemFontDatabase::platformSystemFontShorthandInfo(FontShorthand fontShorthand) -> SystemFontShorthandInfo
+{
+    GtkSettings* settings = gtk_settings_get_default();
+    if (!settings)
+        return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() };
+
+    // This will be a font selection string like "Sans 10" so we cannot use it as the family name.
+    GUniqueOutPtr<gchar> fontName;
+    g_object_get(settings, "gtk-font-name", &fontName.outPtr(), nullptr);
+    if (!fontName || !fontName.get()[0])
+        return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() };
+
+    PangoFontDescription* pangoDescription = pango_font_description_from_string(fontName.get());
+    if (!pangoDescription)
+        return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() };
+
+    int size = pango_font_description_get_size(pangoDescription) / PANGO_SCALE;
+    // If the size of the font is in points, we need to convert it to pixels.
+    if (!pango_font_description_get_size_is_absolute(pangoDescription))
+        size = size * (screenDPI() / 72.0);
+
+    SystemFontShorthandInfo result { AtomString::fromLatin1(pango_font_description_get_family(pangoDescription)), size, normalWeightValue() };
+    pango_font_description_free(pangoDescription);
+    return result;
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/graphics/playstation/SystemFontDatabasePlayStation.cpp (0 => 295410)


--- trunk/Source/WebCore/platform/graphics/playstation/SystemFontDatabasePlayStation.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/playstation/SystemFontDatabasePlayStation.cpp	2022-06-09 05:12:01 UTC (rev 295410)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2022 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.
+ */
+
+#include "config.h"
+#include "SystemFontDatabase.h"
+
+#include "NotImplemented.h"
+#include "WebKitFontFamilyNames.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+SystemFontDatabase& SystemFontDatabase::singleton()
+{
+    static NeverDestroyed<SystemFontDatabase> database = SystemFontDatabase();
+    return database.get();
+}
+
+auto SystemFontDatabase::platformSystemFontShorthandInfo(FontShorthand fontShorthand) -> SystemFontShorthandInfo
+{
+    notImplemented();
+    return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() };
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/graphics/win/SystemFontDatabaseWin.cpp (0 => 295410)


--- trunk/Source/WebCore/platform/graphics/win/SystemFontDatabaseWin.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/SystemFontDatabaseWin.cpp	2022-06-09 05:12:01 UTC (rev 295410)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2006-2022 Apple Inc. All rights reserved.
+ * Copyright (C) 2009 Kenneth Rohde Christiansen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+#include "SystemFontDatabase.h"
+
+#include "WebKitFontFamilyNames.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+SystemFontDatabase& SystemFontDatabase::singleton()
+{
+    static NeverDestroyed<SystemFontDatabase> database = SystemFontDatabase();
+    return database.get();
+}
+
+static const float defaultControlFontPixelSize = 13;
+
+auto SystemFontDatabase::platformSystemFontShorthandInfo(FontShorthand fontShorthand) -> SystemFontShorthandInfo
+{
+    static bool initialized;
+    static NONCLIENTMETRICS ncm;
+
+    if (!initialized) {
+        initialized = true;
+        ncm.cbSize = sizeof(NONCLIENTMETRICS);
+        ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
+    }
+
+    LOGFONT logFont;
+    bool shouldUseDefaultControlFontPixelSize = false;
+    switch (fontShorthand) {
+    case FontShorthand::Icon:
+        ::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(logFont), &logFont, 0);
+        break;
+    case FontShorthand::Menu:
+        logFont = ncm.lfMenuFont;
+        break;
+    case FontShorthand::MessageBox:
+        logFont = ncm.lfMessageFont;
+        break;
+    case FontShorthand::StatusBar:
+        logFont = ncm.lfStatusFont;
+        break;
+    case FontShorthand::Caption:
+        logFont = ncm.lfCaptionFont;
+        break;
+    case FontShorthand::SmallCaption:
+        logFont = ncm.lfSmCaptionFont;
+        break;
+    case FontShorthand::WebkitSmallControl:
+    case FontShorthand::WebkitMiniControl: // Just map to small.
+    case FontShorthand::WebkitControl: // Just map to small.
+        shouldUseDefaultControlFontPixelSize = true;
+        FALLTHROUGH;
+    default: { // Everything else uses the stock GUI font.
+        HGDIOBJ hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
+        if (!hGDI)
+            return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() };
+        if (::GetObject(hGDI, sizeof(logFont), &logFont) <= 0)
+            return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() };
+    }
+    }
+    float size = shouldUseDefaultControlFontPixelSize ? defaultControlFontPixelSize : abs(logFont.lfHeight);
+    auto weight = logFont.lfWeight >= 700 ? boldWeightValue() : normalWeightValue();
+    return { logFont.lfFaceName, size, weight };
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/graphics/wpe/SystemFontDatabaseWPE.cpp (0 => 295410)


--- trunk/Source/WebCore/platform/graphics/wpe/SystemFontDatabaseWPE.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/wpe/SystemFontDatabaseWPE.cpp	2022-06-09 05:12:01 UTC (rev 295410)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2022 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.
+ */
+
+#include "config.h"
+#include "SystemFontDatabase.h"
+
+#include "NotImplemented.h"
+#include "WebKitFontFamilyNames.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+SystemFontDatabase& SystemFontDatabase::singleton()
+{
+    static NeverDestroyed<SystemFontDatabase> database = SystemFontDatabase();
+    return database.get();
+}
+
+auto SystemFontDatabase::platformSystemFontShorthandInfo(FontShorthand fontShorthand) -> SystemFontShorthandInfo
+{
+    notImplemented();
+    return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() };
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp (295409 => 295410)


--- trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp	2022-06-09 04:55:57 UTC (rev 295409)
+++ trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp	2022-06-09 05:12:01 UTC (rev 295410)
@@ -52,6 +52,7 @@
 #include "RenderTheme.h"
 #include "RenderView.h"
 #include "Settings.h"
+#include "SystemFontDatabase.h"
 #include "Text.h"
 #include "TextRun.h"
 #include <wtf/IsoMallocInlines.h>
@@ -304,7 +305,8 @@
     contentRect = contentBoxRect();
     contentRect.moveBy(roundedIntPoint(accumulatedOffset));
 
-    auto fontDescription = RenderTheme::singleton().systemFont(CSSValueWebkitSmallControl);
+    FontCascadeDescription fontDescription;
+    fontDescription.setOneFamily(SystemFontDatabase::singleton().systemFontShorthandFamily(SystemFontDatabase::FontShorthand::WebkitSmallControl));
     fontDescription.setWeight(boldWeightValue());
     fontDescription.setRenderingMode(settings().fontRenderingMode());
     fontDescription.setComputedSize(12);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to