diff --git a/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h b/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h index f257e1a884fe..68c4a937b827 100644 --- a/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h +++ b/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h @@ -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 @@ typedef CF_OPTIONS(uint32_t, CTFontDescriptorOptions) { kCTFontDescriptorOptionThisIsNotARealOption = 0xFFFFFFFF }; +typedef CF_ENUM(uint32_t, CTFontTextStylePlatform) +{ + kCTFontTextStylePlatformDefault = (CTFontTextStylePlatform)-1, +}; + #endif WTF_EXTERN_C_BEGIN @@ -141,6 +146,7 @@ CTFontDescriptorRef CTFontDescriptorCreateWithTextStyle(CFStringRef style, CFStr 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(); diff --git a/Source/WebCore/PlatformPlayStation.cmake b/Source/WebCore/PlatformPlayStation.cmake index c27bde8c1cfe..76580f798b7e 100644 --- a/Source/WebCore/PlatformPlayStation.cmake +++ b/Source/WebCore/PlatformPlayStation.cmake @@ -45,6 +45,8 @@ list(APPEND WebCore_SOURCES platform/graphics/libwpe/PlatformDisplayLibWPE.cpp + platform/graphics/playstation/SystemFontDatabasePlayStation.cpp + platform/libwpe/PasteboardLibWPE.cpp platform/libwpe/PlatformKeyboardEventLibWPE.cpp platform/libwpe/PlatformPasteboardLibWPE.cpp diff --git a/Source/WebCore/PlatformWin.cmake b/Source/WebCore/PlatformWin.cmake index 6209fa6e3606..6f16c74acd0f 100644 --- a/Source/WebCore/PlatformWin.cmake +++ b/Source/WebCore/PlatformWin.cmake @@ -56,6 +56,7 @@ list(APPEND WebCore_SOURCES 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 diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt index aaeb1c41884d..d2d4d966db0f 100644 --- a/Source/WebCore/Sources.txt +++ b/Source/WebCore/Sources.txt @@ -2110,6 +2110,7 @@ platform/graphics/SourceBrush.cpp 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 diff --git a/Source/WebCore/SourcesCocoa.txt b/Source/WebCore/SourcesCocoa.txt index 7ff485447e57..6dbaa8a39bd1 100644 --- a/Source/WebCore/SourcesCocoa.txt +++ b/Source/WebCore/SourcesCocoa.txt @@ -407,6 +407,7 @@ platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp 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 diff --git a/Source/WebCore/SourcesGTK.txt b/Source/WebCore/SourcesGTK.txt index 2322e2fd1686..3c998999a8d2 100644 --- a/Source/WebCore/SourcesGTK.txt +++ b/Source/WebCore/SourcesGTK.txt @@ -92,6 +92,7 @@ platform/graphics/gtk/ColorGtk.cpp 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 diff --git a/Source/WebCore/SourcesWPE.txt b/Source/WebCore/SourcesWPE.txt index 3c64bfd9e2a5..6ae23004c411 100644 --- a/Source/WebCore/SourcesWPE.txt +++ b/Source/WebCore/SourcesWPE.txt @@ -67,6 +67,8 @@ platform/graphics/ANGLEWebKitBridge.cpp platform/graphics/GLContext.cpp platform/graphics/PlatformDisplay.cpp +platform/graphics/wpe/SystemFontDatabaseWPE.cpp + platform/graphics/egl/GLContextEGL.cpp platform/graphics/egl/GLContextEGLLibWPE.cpp diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj index 2fe5f39f9a45..a166bcac55d1 100644 --- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj +++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj @@ -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 = ""; }; 1C12AC291EE778AE0079E0A0 /* FontFamilySpecificationCoreText.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontFamilySpecificationCoreText.h; sourceTree = ""; }; 1C12AC2C1EE779950079E0A0 /* FontDescriptionCocoa.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FontDescriptionCocoa.cpp; sourceTree = ""; }; + 1C16B86A284D6B8200318FEC /* SystemFontDatabaseCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemFontDatabaseCocoa.mm; sourceTree = ""; }; 1C16B86C284D73EF00318FEC /* FontCacheCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FontCacheCocoa.mm; sourceTree = ""; }; 1C18DA56181AF6A500C4EF22 /* TextPainter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextPainter.cpp; sourceTree = ""; }; 1C18DA57181AF6A500C4EF22 /* TextPainter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextPainter.h; sourceTree = ""; }; @@ -7239,6 +7241,8 @@ 1C43DE6822AB4B8A001527D9 /* LocalCurrentTraitCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalCurrentTraitCollection.h; sourceTree = ""; }; 1C43DE6A22AB4B8A001527D9 /* LocalCurrentTraitCollection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalCurrentTraitCollection.mm; sourceTree = ""; }; 1C4674FD26F4843600B61273 /* FontPalette.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontPalette.h; sourceTree = ""; }; + 1C4C77DE284DA83900BD0936 /* SystemFontDatabase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SystemFontDatabase.cpp; sourceTree = ""; }; + 1C4C77DF284DA83900BD0936 /* SystemFontDatabase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemFontDatabase.h; sourceTree = ""; }; 1C4D0DD124D9F0DB003D7498 /* GlyphBufferMembers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GlyphBufferMembers.h; sourceTree = ""; }; 1C4DB02427339E5E007B0AD1 /* ShouldLocalizeAxisNames.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShouldLocalizeAxisNames.h; sourceTree = ""; }; 1C50C49522C84F2400A6E4BE /* WHLSLStandardLibraryFunctionMap.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLStandardLibraryFunctionMap.cpp; sourceTree = ""; }; @@ -29451,6 +29455,8 @@ 501BAAA813950E2C00F7ACEB /* WindRule.h */, 379919941200DDF400EA041C /* WOFFFileFormat.cpp */, 379919951200DDF400EA041C /* WOFFFileFormat.h */, + 1C4C77DE284DA83900BD0936 /* SystemFontDatabase.cpp */, + 1C4C77DF284DA83900BD0936 /* SystemFontDatabase.h */, ); path = graphics; sourceTree = ""; @@ -29596,6 +29602,7 @@ 07F5CFF22582A4F800662EF5 /* WebMAudioUtilitiesCocoa.mm */, 7B1619102719880E00C40EAC /* WebProcessGraphicsContextGLCocoa.mm */, 1C16B86C284D73EF00318FEC /* FontCacheCocoa.mm */, + 1C16B86A284D6B8200318FEC /* SystemFontDatabaseCocoa.mm */, ); path = cocoa; sourceTree = ""; @@ -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 */, diff --git a/Source/WebCore/css/CSSValueKeywords.in b/Source/WebCore/css/CSSValueKeywords.in index c169a873756a..05691818a55a 100644 --- a/Source/WebCore/css/CSSValueKeywords.in +++ b/Source/WebCore/css/CSSValueKeywords.in @@ -27,6 +27,7 @@ double // // CSS_PROP_FONT: // +// This needs to be kept in sync with SystemFontDatabase::FontShorthand. caption icon menu diff --git a/Source/WebCore/platform/graphics/SystemFontDatabase.cpp b/Source/WebCore/platform/graphics/SystemFontDatabase.cpp new file mode 100644 index 000000000000..a09293b33440 --- /dev/null +++ b/Source/WebCore/platform/graphics/SystemFontDatabase.cpp @@ -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(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 diff --git a/Source/WebCore/platform/graphics/SystemFontDatabase.h b/Source/WebCore/platform/graphics/SystemFontDatabase.h new file mode 100644 index 000000000000..908241ff4124 --- /dev/null +++ b/Source/WebCore/platform/graphics/SystemFontDatabase.h @@ -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 +#include +#include + +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::type; + static constexpr auto fontShorthandCount = static_cast(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, fontShorthandCount>; + SystemFontShorthandCache m_systemFontShorthandCache; +}; + +} // namespace WebCore diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h index cf72eb91f729..bc44e9b7ee4a 100644 --- a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h +++ b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h @@ -27,6 +27,7 @@ #if HAVE(IOSURFACE) +#include "ImageBuffer.h" #include "ImageBufferCGBackend.h" #include "IOSurface.h" #include "IOSurfacePool.h" diff --git a/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp b/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp index 073142ac5495..c573540441e0 100644 --- a/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp +++ b/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp @@ -368,6 +368,37 @@ static inline float normalizeGXWeight(float value) 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 @@ static inline float denormalizeGXWeight(float value) 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; diff --git a/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h b/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h index e2e345c4cf89..872e24be2d42 100644 --- a/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h +++ b/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h @@ -72,8 +72,10 @@ RetainPtr createFontForInstalledFonts(CTFontDescriptorRef, CGFloat si RetainPtr createFontForInstalledFonts(CTFontRef, AllowUserInstalledFonts); void addAttributesForWebFonts(CFMutableDictionaryRef attributes, AllowUserInstalledFonts); RetainPtr installedFontMandatoryAttributes(AllowUserInstalledFonts); -CFStringRef getUIContentSizeCategoryDidChangeNotificationName(); +float normalizeCTWeight(float); +float denormalizeCTWeight(float); +CFStringRef getUIContentSizeCategoryDidChangeNotificationName(); WEBCORE_EXPORT void setContentSizeCategory(const String&); WEBCORE_EXPORT CFStringRef contentSizeCategory(); diff --git a/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCocoa.mm b/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCocoa.mm new file mode 100644 index 000000000000..5902813f01de --- /dev/null +++ b/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCocoa.mm @@ -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 + +namespace WebCore { + +static auto cocoaFontClass() +{ +#if PLATFORM(IOS_FAMILY) + return PAL::getUIFontClass(); +#else + return NSFont.class; +#endif +}; + +RetainPtr SystemFontDatabaseCoreText::smallCaptionFontDescriptor() +{ + auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() smallSystemFontSize]]; + return static_cast(font.fontDescriptor); +} + +RetainPtr SystemFontDatabaseCoreText::menuFontDescriptor() +{ + return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontMenuItem, [cocoaFontClass() systemFontSize], nullptr)); +} + +RetainPtr SystemFontDatabaseCoreText::statusBarFontDescriptor() +{ + return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, [cocoaFontClass() labelFontSize], nullptr)); +} + +RetainPtr SystemFontDatabaseCoreText::miniControlFontDescriptor() +{ +#if PLATFORM(IOS_FAMILY) + return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontMiniSystem, 0, nullptr)); +#else + auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() systemFontSizeForControlSize:NSControlSizeMini]]; + return static_cast(font.fontDescriptor); +#endif +} + +RetainPtr SystemFontDatabaseCoreText::smallControlFontDescriptor() +{ +#if PLATFORM(IOS_FAMILY) + return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSmallSystem, 0, nullptr)); +#else + auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() systemFontSizeForControlSize:NSControlSizeSmall]]; + return static_cast(font.fontDescriptor); +#endif +} + +RetainPtr SystemFontDatabaseCoreText::controlFontDescriptor() +{ +#if PLATFORM(IOS_FAMILY) + return adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, 0, nullptr)); +#else + auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() systemFontSizeForControlSize:NSControlSizeRegular]]; + return static_cast(font.fontDescriptor); +#endif +} + +} // namespace WebCore diff --git a/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp b/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp index bc3683e8fc95..00d73e9bb427 100644 --- a/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp +++ b/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp @@ -40,6 +40,11 @@ SystemFontDatabaseCoreText& SystemFontDatabaseCoreText::singleton() return database.get(); } +SystemFontDatabase& SystemFontDatabase::singleton() +{ + return SystemFontDatabaseCoreText::singleton(); +} + SystemFontDatabaseCoreText::SystemFontDatabaseCoreText() { } @@ -133,6 +138,7 @@ void SystemFontDatabaseCoreText::clear() m_cursiveFamilies.clear(); m_fantasyFamilies.clear(); m_monospaceFamilies.clear(); + SystemFontDatabase::clear(); } RetainPtr SystemFontDatabaseCoreText::createFontByApplyingWeightWidthItalicsAndFallbackBehavior(CTFontRef font, CGFloat weight, CGFloat width, bool italic, float size, AllowUserInstalledFonts allowUserInstalledFonts, CFStringRef design) @@ -333,4 +339,88 @@ String SystemFontDatabaseCoreText::monospaceFamily(const String& locale) return result; } +static inline FontSelectionValue cssWeightOfSystemFontDescriptor(CTFontDescriptorRef fontDescriptor) +{ + auto resultRef = adoptCF(static_cast(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontCSSWeightAttribute))); + float result = 0; + if (resultRef && CFNumberGetValue(resultRef.get(), kCFNumberFloatType, &result)) + return FontSelectionValue(result); + + auto traitsRef = adoptCF(static_cast(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontTraitsAttribute))); + resultRef = static_cast(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(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); + } +} + } diff --git a/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h b/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h index c3b571db9e25..73cfd0a54ec7 100644 --- a/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h +++ b/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.h @@ -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 #include #include @@ -43,7 +44,7 @@ enum class SystemFontKind : uint8_t { TextStyle }; -class SystemFontDatabaseCoreText { +class SystemFontDatabaseCoreText : public SystemFontDatabase { public: struct CascadeListParameters { CascadeListParameters() @@ -96,9 +97,15 @@ class SystemFontDatabaseCoreText { 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> cascadeList(const CascadeListParameters&, SystemFontKind); @@ -107,6 +114,13 @@ class SystemFontDatabaseCoreText { RetainPtr createSystemDesignFont(SystemFontKind, const CascadeListParameters&); RetainPtr createTextStyleFont(const CascadeListParameters&); + static RetainPtr smallCaptionFontDescriptor(); + static RetainPtr menuFontDescriptor(); + static RetainPtr statusBarFontDescriptor(); + static RetainPtr miniControlFontDescriptor(); + static RetainPtr smallControlFontDescriptor(); + static RetainPtr controlFontDescriptor(); + static RetainPtr createFontByApplyingWeightWidthItalicsAndFallbackBehavior(CTFontRef, CGFloat weight, CGFloat width, bool italic, float size, AllowUserInstalledFonts, CFStringRef design = nullptr); static RetainPtr removeCascadeList(CTFontDescriptorRef); static Vector> computeCascadeList(CTFontRef, CFStringRef locale); diff --git a/Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp b/Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp new file mode 100644 index 000000000000..9f52308de800 --- /dev/null +++ b/Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp @@ -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 + +namespace WebCore { + +SystemFontDatabase& SystemFontDatabase::singleton() +{ + static NeverDestroyed 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 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 diff --git a/Source/WebCore/platform/graphics/playstation/SystemFontDatabasePlayStation.cpp b/Source/WebCore/platform/graphics/playstation/SystemFontDatabasePlayStation.cpp new file mode 100644 index 000000000000..3b815ca95325 --- /dev/null +++ b/Source/WebCore/platform/graphics/playstation/SystemFontDatabasePlayStation.cpp @@ -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 + +namespace WebCore { + +SystemFontDatabase& SystemFontDatabase::singleton() +{ + static NeverDestroyed database = SystemFontDatabase(); + return database.get(); +} + +auto SystemFontDatabase::platformSystemFontShorthandInfo(FontShorthand fontShorthand) -> SystemFontShorthandInfo +{ + notImplemented(); + return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() }; +} + +} // namespace WebCore diff --git a/Source/WebCore/platform/graphics/win/SystemFontDatabaseWin.cpp b/Source/WebCore/platform/graphics/win/SystemFontDatabaseWin.cpp new file mode 100644 index 000000000000..615849648734 --- /dev/null +++ b/Source/WebCore/platform/graphics/win/SystemFontDatabaseWin.cpp @@ -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 + +namespace WebCore { + +SystemFontDatabase& SystemFontDatabase::singleton() +{ + static NeverDestroyed 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 diff --git a/Source/WebCore/platform/graphics/wpe/SystemFontDatabaseWPE.cpp b/Source/WebCore/platform/graphics/wpe/SystemFontDatabaseWPE.cpp new file mode 100644 index 000000000000..3b815ca95325 --- /dev/null +++ b/Source/WebCore/platform/graphics/wpe/SystemFontDatabaseWPE.cpp @@ -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 + +namespace WebCore { + +SystemFontDatabase& SystemFontDatabase::singleton() +{ + static NeverDestroyed database = SystemFontDatabase(); + return database.get(); +} + +auto SystemFontDatabase::platformSystemFontShorthandInfo(FontShorthand fontShorthand) -> SystemFontShorthandInfo +{ + notImplemented(); + return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() }; +} + +} // namespace WebCore diff --git a/Source/WebCore/rendering/RenderEmbeddedObject.cpp b/Source/WebCore/rendering/RenderEmbeddedObject.cpp index 788f37c27277..172fbe9d3c92 100644 --- a/Source/WebCore/rendering/RenderEmbeddedObject.cpp +++ b/Source/WebCore/rendering/RenderEmbeddedObject.cpp @@ -52,6 +52,7 @@ #include "RenderTheme.h" #include "RenderView.h" #include "Settings.h" +#include "SystemFontDatabase.h" #include "Text.h" #include "TextRun.h" #include @@ -304,7 +305,8 @@ void RenderEmbeddedObject::getReplacementTextGeometry(const LayoutPoint& accumul 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);