Title: [266663] trunk/Source/WebCore
Revision
266663
Author
[email protected]
Date
2020-09-05 10:51:09 -0700 (Sat, 05 Sep 2020)

Log Message

[Cocoa] Unify implementation of custom font name aliases between all Cocoa platforms
https://bugs.webkit.org/show_bug.cgi?id=215689

Reviewed by Darin Adler.

The existing code is duplicated almost verbatim. There's no point in having two copies of the same thing.

No new tests because there is no behavior change.

* PlatformMac.cmake:
* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::fontWithFamilySpecialCase):
(WebCore::fontWithFamily):
* platform/graphics/cocoa/FontCacheCoreText.h:
* platform/graphics/cocoa/FontDescriptionCocoa.cpp:
(WebCore::FontCascadeDescription::effectiveFamilyCount const):
(WebCore::FontCascadeDescription::effectiveFamilyAt const):
* platform/graphics/ios/FontCacheIOS.mm:
(WebCore::baseSystemFontDescriptor): Deleted.
(WebCore::systemFontModificationAttributes): Deleted.
(WebCore::systemFontDescriptor): Deleted.
(WebCore::platformFontWithFamilySpecialCase): Deleted.
* platform/graphics/mac/FontCacheMac.mm: Removed.

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (266662 => 266663)


--- trunk/Source/WebCore/ChangeLog	2020-09-05 17:14:23 UTC (rev 266662)
+++ trunk/Source/WebCore/ChangeLog	2020-09-05 17:51:09 UTC (rev 266663)
@@ -1,3 +1,31 @@
+2020-09-05  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Unify implementation of custom font name aliases between all Cocoa platforms
+        https://bugs.webkit.org/show_bug.cgi?id=215689
+
+        Reviewed by Darin Adler.
+
+        The existing code is duplicated almost verbatim. There's no point in having two copies of the same thing.
+
+        No new tests because there is no behavior change.
+
+        * PlatformMac.cmake:
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::fontWithFamilySpecialCase):
+        (WebCore::fontWithFamily):
+        * platform/graphics/cocoa/FontCacheCoreText.h:
+        * platform/graphics/cocoa/FontDescriptionCocoa.cpp:
+        (WebCore::FontCascadeDescription::effectiveFamilyCount const):
+        (WebCore::FontCascadeDescription::effectiveFamilyAt const):
+        * platform/graphics/ios/FontCacheIOS.mm:
+        (WebCore::baseSystemFontDescriptor): Deleted.
+        (WebCore::systemFontModificationAttributes): Deleted.
+        (WebCore::systemFontDescriptor): Deleted.
+        (WebCore::platformFontWithFamilySpecialCase): Deleted.
+        * platform/graphics/mac/FontCacheMac.mm: Removed.
+
 2020-09-05  Sam Weinig  <[email protected]>
 
         [WebIDL] Realign our IDL extended attribute names with those specified in WebIDL

Modified: trunk/Source/WebCore/PlatformMac.cmake (266662 => 266663)


--- trunk/Source/WebCore/PlatformMac.cmake	2020-09-05 17:14:23 UTC (rev 266662)
+++ trunk/Source/WebCore/PlatformMac.cmake	2020-09-05 17:51:09 UTC (rev 266663)
@@ -334,7 +334,6 @@
     platform/graphics/mac/DisplayRefreshMonitorMac.cpp
     platform/graphics/mac/FloatPointMac.mm
     platform/graphics/mac/FloatSizeMac.mm
-    platform/graphics/mac/FontCacheMac.mm
     platform/graphics/mac/FontCustomPlatformData.cpp
     platform/graphics/mac/GlyphPageMac.cpp
     platform/graphics/mac/IconMac.mm

Modified: trunk/Source/WebCore/SourcesCocoa.txt (266662 => 266663)


--- trunk/Source/WebCore/SourcesCocoa.txt	2020-09-05 17:14:23 UTC (rev 266662)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2020-09-05 17:51:09 UTC (rev 266663)
@@ -402,7 +402,6 @@
 platform/graphics/mac/DisplayRefreshMonitorMac.cpp
 platform/graphics/mac/FloatPointMac.mm
 platform/graphics/mac/FloatSizeMac.mm
-platform/graphics/mac/FontCacheMac.mm
 platform/graphics/mac/FontCustomPlatformData.cpp
 platform/graphics/mac/GlyphPageMac.cpp
 platform/graphics/mac/IconMac.mm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (266662 => 266663)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-09-05 17:14:23 UTC (rev 266662)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-09-05 17:51:09 UTC (rev 266663)
@@ -13117,7 +13117,6 @@
 		B2A1F2A70CEF0ABF00442F6A /* SVGMissingGlyphElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGMissingGlyphElement.cpp; sourceTree = "<group>"; };
 		B2A1F2A80CEF0ABF00442F6A /* SVGMissingGlyphElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGMissingGlyphElement.h; sourceTree = "<group>"; };
 		B2A1F2A90CEF0ABF00442F6A /* SVGMissingGlyphElement.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = SVGMissingGlyphElement.idl; sourceTree = "<group>"; };
-		B2AFFC740D00A5C10030074D /* FontCacheMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = FontCacheMac.mm; sourceTree = "<group>"; };
 		B2AFFC750D00A5C10030074D /* FontCustomPlatformData.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FontCustomPlatformData.cpp; sourceTree = "<group>"; };
 		B2AFFC760D00A5C10030074D /* FontCustomPlatformData.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FontCustomPlatformData.h; sourceTree = "<group>"; };
 		B2AFFC780D00A5C10030074D /* FontCascadeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = FontCascadeCocoa.mm; sourceTree = "<group>"; };
@@ -25788,7 +25787,6 @@
 				2DE70022192FE82A00B0975C /* DisplayRefreshMonitorMac.h */,
 				B275354B0B053814002CE64F /* FloatPointMac.mm */,
 				B275354D0B053814002CE64F /* FloatSizeMac.mm */,
-				B2AFFC740D00A5C10030074D /* FontCacheMac.mm */,
 				B2AFFC750D00A5C10030074D /* FontCustomPlatformData.cpp */,
 				B2AFFC760D00A5C10030074D /* FontCustomPlatformData.h */,
 				B2AFFC7B0D00A5C10030074D /* GlyphPageMac.cpp */,

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


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2020-09-05 17:14:23 UTC (rev 266662)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2020-09-05 17:51:09 UTC (rev 266663)
@@ -1257,6 +1257,7 @@
 
 static RetainPtr<CTFontRef> fontWithFamilySpecialCase(const AtomString& family, const FontDescription& fontDescription, float size, AllowUserInstalledFonts allowUserInstalledFonts)
 {
+    // FIXME: See comment in FontCascadeDescription::effectiveFamilyAt() in FontDescriptionCocoa.cpp
     Optional<SystemFontKind> systemDesign;
 
 #if HAVE(DESIGN_SYSTEM_UI_FONTS)
@@ -1268,7 +1269,7 @@
         systemDesign = SystemFontKind::UIRounded;
 #endif
 
-    if (equalLettersIgnoringASCIICase(family, "ui-sans-serif")) {
+    if (equalLettersIgnoringASCIICase(family, "-webkit-system-font") || equalLettersIgnoringASCIICase(family, "-apple-system") || equalLettersIgnoringASCIICase(family, "-apple-system-font") || equalLettersIgnoringASCIICase(family, "system-ui") || equalLettersIgnoringASCIICase(family, "ui-sans-serif")) {
         ASSERT(!systemDesign);
         systemDesign = SystemFontKind::SystemUI;
     }
@@ -1299,6 +1300,21 @@
         return createFontForInstalledFonts(result.get(), allowUserInstalledFonts);
     }
 
+    if (equalLettersIgnoringASCIICase(family, "lastresort")) {
+        static const CTFontDescriptorRef lastResort = CTFontDescriptorCreateLastResort();
+        return adoptCF(CTFontCreateWithFontDescriptor(lastResort, size, nullptr));
+    }
+
+    if (equalLettersIgnoringASCIICase(family, "-apple-system-monospaced-numbers")) {
+        int numberSpacingType = kNumberSpacingType;
+        int monospacedNumbersSelector = kMonospacedNumbersSelector;
+        auto numberSpacingNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &numberSpacingType));
+        auto monospacedNumbersNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &monospacedNumbersSelector));
+        auto systemFontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, size, nullptr));
+        auto monospaceFontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithFeature(systemFontDescriptor.get(), numberSpacingNumber.get(), monospacedNumbersNumber.get()));
+        return createFontForInstalledFonts(monospaceFontDescriptor.get(), size, allowUserInstalledFonts);
+    }
+
     return nullptr;
 }
 
@@ -1308,12 +1324,9 @@
         return nullptr;
 
     FontLookup fontLookup;
-    fontLookup.result = platformFontWithFamilySpecialCase(family, fontDescription, size, fontDescription.shouldAllowUserInstalledFonts());
-    if (!fontLookup.result) {
-        fontLookup.result = fontWithFamilySpecialCase(family, fontDescription, size, fontDescription.shouldAllowUserInstalledFonts());
-        if (!fontLookup.result)
-            fontLookup = platformFontLookupWithFamily(family, fontDescription.fontSelectionRequest(), size, fontDescription.shouldAllowUserInstalledFonts());
-    }
+    fontLookup.result = fontWithFamilySpecialCase(family, fontDescription, size, fontDescription.shouldAllowUserInstalledFonts());
+    if (!fontLookup.result)
+        fontLookup = platformFontLookupWithFamily(family, fontDescription.fontSelectionRequest(), size, fontDescription.shouldAllowUserInstalledFonts());
     return preparePlatformFont(fontLookup.result.get(), fontDescription, fontFaceFeatures, fontFaceCapabilities, !fontLookup.createdFromPostScriptName);
 }
 

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


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h	2020-09-05 17:14:23 UTC (rev 266662)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h	2020-09-05 17:51:09 UTC (rev 266663)
@@ -52,7 +52,6 @@
 
 RetainPtr<CTFontRef> preparePlatformFont(CTFontRef, const FontDescription&, const FontFeatureSettings* fontFaceFeatures, FontSelectionSpecifiedCapabilities fontFaceCapabilities, bool applyWeightWidthSlopeVariations = true);
 SynthesisPair computeNecessarySynthesis(CTFontRef, const FontDescription&, bool isPlatformFont = false);
-RetainPtr<CTFontRef> platformFontWithFamilySpecialCase(const AtomString& family, const FontDescription&, float size, AllowUserInstalledFonts);
 RetainPtr<CTFontRef> platformFontWithFamily(const AtomString& family, FontSelectionRequest, TextRenderingMode, float size);
 bool requiresCustomFallbackFont(UChar32 character);
 FontSelectionCapabilities capabilitiesForFontDescriptor(CTFontDescriptorRef);

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontDescriptionCocoa.cpp (266662 => 266663)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontDescriptionCocoa.cpp	2020-09-05 17:14:23 UTC (rev 266662)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontDescriptionCocoa.cpp	2020-09-05 17:51:09 UTC (rev 266663)
@@ -95,7 +95,7 @@
 
 unsigned FontCascadeDescription::effectiveFamilyCount() const
 {
-    // FIXME: Move all the other system font keywords from platformFontWithFamilySpecialCase() to here.
+    // FIXME: Move all the other system font keywords from fontWithFamilySpecialCase() to here.
     unsigned result = 0;
     for (unsigned i = 0; i < familyCount(); ++i) {
         const auto& cssFamily = familyAt(i);
@@ -109,7 +109,7 @@
 
 FontFamilySpecification FontCascadeDescription::effectiveFamilyAt(unsigned index) const
 {
-    // The special cases in this function need to match the behavior in FontCacheIOS.mm and FontCacheMac.mm. On systems
+    // The special cases in this function need to match the behavior in FontCacheCoreText.cpp. On systems
     // where USE(PLATFORM_SYSTEM_FALLBACK_LIST) is set to true, this code is used for regular (element style) lookups,
     // and the code in FontDescriptionCocoa.cpp is used when src:local(special-cased-name) is specified inside an
     // @font-face block.

Modified: trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm (266662 => 266663)


--- trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm	2020-09-05 17:14:23 UTC (rev 266662)
+++ trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm	2020-09-05 17:51:09 UTC (rev 266663)
@@ -74,93 +74,6 @@
     return getCachedFontPlatformData(description, *family);
 }
 
-static RetainPtr<CTFontDescriptorRef> baseSystemFontDescriptor(FontSelectionValue weight, bool bold, float size)
-{
-    CTFontUIFontType fontType = kCTFontUIFontSystem;
-    if (weight >= FontSelectionValue(350)) {
-        if (bold)
-            fontType = kCTFontUIFontEmphasizedSystem;
-    } else if (weight >= FontSelectionValue(250))
-        fontType = static_cast<CTFontUIFontType>(kCTFontUIFontSystemLight);
-    else if (weight >= FontSelectionValue(150))
-        fontType = static_cast<CTFontUIFontType>(kCTFontUIFontSystemThin);
-    else
-        fontType = static_cast<CTFontUIFontType>(kCTFontUIFontSystemUltraLight);
-    return adoptCF(CTFontDescriptorCreateForUIType(fontType, size, nullptr));
-}
-
-static RetainPtr<NSDictionary> systemFontModificationAttributes(FontSelectionValue weight, bool italic)
-{
-    RetainPtr<NSMutableDictionary> traitsDictionary = adoptNS([[NSMutableDictionary alloc] init]);
-
-    float ctWeight = kCTFontWeightRegular;
-    if (weight < FontSelectionValue(150))
-        ctWeight = kCTFontWeightUltraLight;
-    else if (weight < FontSelectionValue(250))
-        ctWeight = kCTFontWeightThin;
-    else if (weight < FontSelectionValue(350))
-        ctWeight = kCTFontWeightLight;
-    else if (weight < FontSelectionValue(450))
-        ctWeight = kCTFontWeightRegular;
-    else if (weight < FontSelectionValue(550))
-        ctWeight = kCTFontWeightMedium;
-    else if (weight < FontSelectionValue(650))
-        ctWeight = kCTFontWeightSemibold;
-    else if (weight < FontSelectionValue(750))
-        ctWeight = kCTFontWeightBold;
-    else if (weight < FontSelectionValue(850))
-        ctWeight = kCTFontWeightHeavy;
-    else
-        ctWeight = kCTFontWeightBlack;
-    [traitsDictionary setObject:[NSNumber numberWithFloat:ctWeight] forKey:static_cast<NSString *>(kCTFontWeightTrait)];
-
-    [traitsDictionary setObject:@YES forKey:static_cast<NSString *>(kCTFontUIFontDesignTrait)];
-
-    if (italic)
-        [traitsDictionary setObject:@(kCTFontItalicTrait) forKey:static_cast<NSString *>(kCTFontSymbolicTrait)];
-
-    return @{ static_cast<NSString *>(kCTFontTraitsAttribute) : traitsDictionary.get() };
-}
-
-static RetainPtr<CTFontDescriptorRef> systemFontDescriptor(FontSelectionValue weight, bool bold, bool italic, float size)
-{
-    RetainPtr<CTFontDescriptorRef> fontDescriptor = baseSystemFontDescriptor(weight, bold, size);
-    RetainPtr<NSDictionary> attributes = systemFontModificationAttributes(weight, italic);
-    return adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor.get(), static_cast<CFDictionaryRef>(attributes.get())));
-}
-
-RetainPtr<CTFontRef> platformFontWithFamilySpecialCase(const AtomString& family, const FontDescription& fontDescription, float size, AllowUserInstalledFonts allowUserInstalledFonts)
-{
-    // FIXME: See comment in FontCascadeDescription::effectiveFamilyAt() in FontDescriptionCocoa.cpp
-    const auto& request = fontDescription.fontSelectionRequest();
-
-    // FIXME: Migrate this to use SystemFontDatabaseCoreText like the design system-ui block below.
-    if (equalLettersIgnoringASCIICase(family, "-webkit-system-font") || equalLettersIgnoringASCIICase(family, "-apple-system") || equalLettersIgnoringASCIICase(family, "-apple-system-font") || equalLettersIgnoringASCIICase(family, "system-ui")) {
-        auto fontDescriptor = systemFontDescriptor(request.weight, isFontWeightBold(request.weight), isItalic(request.slope), size);
-        return createFontForInstalledFonts(fontDescriptor.get(), size, allowUserInstalledFonts);
-    }
-
-    if (equalLettersIgnoringASCIICase(family, "-apple-system-monospaced-numbers")) {
-        RetainPtr<CTFontDescriptorRef> systemFontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, size, nullptr));
-        RetainPtr<CTFontDescriptorRef> monospaceFontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithFeature(systemFontDescriptor.get(), (CFNumberRef)@(kNumberSpacingType), (CFNumberRef)@(kMonospacedNumbersSelector)));
-        return createFontForInstalledFonts(monospaceFontDescriptor.get(), size, allowUserInstalledFonts);
-    }
-
-    if (equalLettersIgnoringASCIICase(family, "lastresort")) {
-// FIXME: Likely we can remove this special case for watchOS and tvOS.
-#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
-        static const CTFontDescriptorRef lastResort = CTFontDescriptorCreateLastResort();
-        return adoptCF(CTFontCreateWithFontDescriptor(lastResort, size, nullptr));
-#else
-        // LastResort is special, so it's important to look this exact string up, and not some case-folded version.
-        // We handle this here so any caching and case folding we do in our general text codepath is bypassed.
-        return adoptCF(CTFontCreateWithName(CFSTR("LastResort"), size, nullptr));
-#endif
-    }
-
-    return nullptr;
-}
-
 } // namespace WebCore
 
 #endif // PLATFORM(IOS_FAMILY)

Deleted: trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm (266662 => 266663)


--- trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm	2020-09-05 17:14:23 UTC (rev 266662)
+++ trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm	2020-09-05 17:51:09 UTC (rev 266663)
@@ -1,123 +0,0 @@
-/*
- * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
- * Copyright (C) 2007 Nicholas Shanks <[email protected]>
- *
- * 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. 
- * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission. 
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "FontCache.h"
-
-#import "Font.h"
-#import "FontCascade.h"
-#import "FontPlatformData.h"
-#import "SystemFontDatabaseCoreText.h"
-#import <pal/spi/cg/CoreGraphicsSPI.h>
-#import <pal/spi/cocoa/CoreTextSPI.h>
-
-#if PLATFORM(MAC)
-#import <AppKit/AppKit.h>
-#import <pal/spi/mac/NSFontSPI.h>
-#import <wtf/MainThread.h>
-#import <wtf/NeverDestroyed.h>
-#import <wtf/StdLibExtras.h>
-#import <wtf/Threading.h>
-#import <wtf/text/AtomStringHash.h>
-#endif
-
-#import <wtf/SoftLinking.h>
-
-namespace WebCore {
-
-#if PLATFORM(MAC)
-
-static CGFloat toNSFontWeight(FontSelectionValue fontWeight)
-{
-    if (fontWeight < FontSelectionValue(150))
-        return NSFontWeightUltraLight;
-    if (fontWeight < FontSelectionValue(250))
-        return NSFontWeightThin;
-    if (fontWeight < FontSelectionValue(350))
-        return NSFontWeightLight;
-    if (fontWeight < FontSelectionValue(450))
-        return NSFontWeightRegular;
-    if (fontWeight < FontSelectionValue(550))
-        return NSFontWeightMedium;
-    if (fontWeight < FontSelectionValue(650))
-        return NSFontWeightSemibold;
-    if (fontWeight < FontSelectionValue(750))
-        return NSFontWeightBold;
-    if (fontWeight < FontSelectionValue(850))
-        return NSFontWeightHeavy;
-    return NSFontWeightBlack;
-}
-
-RetainPtr<CTFontRef> platformFontWithFamilySpecialCase(const AtomString& family, const FontDescription& fontDescription, float size, AllowUserInstalledFonts allowUserInstalledFonts)
-{
-    // FIXME: See comment in FontCascadeDescription::effectiveFamilyAt() in FontDescriptionCocoa.cpp
-    const auto& request = fontDescription.fontSelectionRequest();
-
-    // FIXME: Migrate this to use SystemFontDatabaseCoreText like the design system-ui block below.
-    if (equalLettersIgnoringASCIICase(family, "-webkit-system-font") || equalLettersIgnoringASCIICase(family, "-apple-system") || equalLettersIgnoringASCIICase(family, "-apple-system-font") || equalLettersIgnoringASCIICase(family, "system-ui")) {
-        RetainPtr<CTFontRef> result = toCTFont([NSFont systemFontOfSize:size weight:toNSFontWeight(request.weight)]);
-        if (isItalic(request.slope)) {
-            CTFontSymbolicTraits desiredTraits = kCTFontItalicTrait;
-            if (isFontWeightBold(request.weight))
-                desiredTraits |= kCTFontBoldTrait;
-            if (auto italicizedFont = adoptCF(CTFontCreateCopyWithSymbolicTraits(result.get(), size, nullptr, desiredTraits, desiredTraits)))
-                result = italicizedFont;
-        }
-        return createFontForInstalledFonts(result.get(), allowUserInstalledFonts);
-    }
-
-    if (equalLettersIgnoringASCIICase(family, "-apple-system-monospaced-numbers")) {
-        int numberSpacingType = kNumberSpacingType;
-        int monospacedNumbersSelector = kMonospacedNumbersSelector;
-        RetainPtr<CFNumberRef> numberSpacingNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &numberSpacingType));
-        RetainPtr<CFNumberRef> monospacedNumbersNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &monospacedNumbersSelector));
-        CFTypeRef featureKeys[] = { kCTFontFeatureTypeIdentifierKey, kCTFontFeatureSelectorIdentifierKey };
-        CFTypeRef featureValues[] = { numberSpacingNumber.get(), monospacedNumbersNumber.get() };
-        RetainPtr<CFDictionaryRef> featureIdentifier = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, featureKeys, featureValues, WTF_ARRAY_LENGTH(featureKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-        CFTypeRef featureIdentifiers[] = { featureIdentifier.get() };
-        RetainPtr<CFArrayRef> featureArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, featureIdentifiers, 1, &kCFTypeArrayCallBacks));
-        auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-        CFDictionaryAddValue(attributes.get(), kCTFontFeatureSettingsAttribute, featureArray.get());
-        addAttributesForInstalledFonts(attributes.get(), allowUserInstalledFonts);
-        RetainPtr<CTFontRef> result = toCTFont([NSFont systemFontOfSize:size]);
-        auto modification = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
-        return adoptCF(CTFontCreateCopyWithAttributes(result.get(), size, nullptr, modification.get()));
-    }
-
-    if (equalLettersIgnoringASCIICase(family, "lastresort")) {
-        static const CTFontDescriptorRef lastResort = CTFontDescriptorCreateLastResort();
-        return adoptCF(CTFontCreateWithFontDescriptor(lastResort, size, nullptr));
-    }
-
-    return nullptr;
-}
-
-#endif // PLATFORM(MAC)
-
-} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to