Skip to content

Commit

Permalink
[Cocoa] CTFontCreateForCharactersWithLanguageAndOption() is available…
Browse files Browse the repository at this point in the history
… on all Cocoa platforms

https://bugs.webkit.org/show_bug.cgi?id=250363
rdar://104063789

Reviewed by Tim Horton.

Simply unify the codepaths.

* Source/WTF/wtf/PlatformHave.h:
* Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::preparePlatformFont):
(WebCore::createFontForCharacters):
(WebCore::FontCache::prewarm):
* Source/WebCore/platform/graphics/cocoa/FontDatabase.cpp:
(WebCore::FontDatabase::InstalledFont::InstalledFont):
(WebCore::FontDatabase::collectionForFamily):
(WebCore::FontDatabase::fontForPostScriptName):
* Source/WebCore/platform/graphics/cocoa/FontDatabase.h:

Canonical link: https://commits.webkit.org/258710@main
  • Loading branch information
litherum committed Jan 10, 2023
1 parent 47c5a9d commit b81575a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 35 deletions.
4 changes: 0 additions & 4 deletions Source/WTF/wtf/PlatformHave.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,6 @@
#define HAVE_MDNS_FAST_REGISTRATION 1
#endif

#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
#define HAVE_CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION 1
#endif

#if PLATFORM(IOS)
#define HAVE_ARKIT_QUICK_LOOK_PREVIEW_ITEM 1
#endif
Expand Down
19 changes: 1 addition & 18 deletions Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,8 @@ RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, const FontDescr
bool variantSettingsIsNormal = variantSettings.isAllNormal();
bool dontNeedToApplyOpticalSizing = fontOpticalSizing == FontOpticalSizing::Enabled && !forceOpticalSizingOn;
bool fontFaceDoesntSpecifyFeatures = !fontCreationContext.fontFaceFeatures() || fontCreationContext.fontFaceFeatures()->isEmpty();
if (noFontFeatureSettings && noFontVariationSettings && textRenderingModeIsAuto && variantSettingsIsNormal && dontNeedToApplyOpticalSizing && fontFaceDoesntSpecifyFeatures && !shouldDisableLigaturesForSpacing && dontNeedToApplyFontPalettes) {
#if HAVE(CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION)
if (noFontFeatureSettings && noFontVariationSettings && textRenderingModeIsAuto && variantSettingsIsNormal && dontNeedToApplyOpticalSizing && fontFaceDoesntSpecifyFeatures && !shouldDisableLigaturesForSpacing && dontNeedToApplyFontPalettes)
return originalFont;
#else
return createFontForInstalledFonts(originalFont, fontDescription.shouldAllowUserInstalledFonts());
#endif
}

// This algorithm is described at https://drafts.csswg.org/css-fonts-4/#feature-variation-precedence
FeaturesMap featuresToBeApplied;
Expand Down Expand Up @@ -1120,20 +1115,12 @@ static bool isUserInstalledFont(CTFontRef font)
}
#endif

#if HAVE(CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION)
static RetainPtr<CTFontRef> createFontForCharacters(CTFontRef font, CFStringRef localeString, AllowUserInstalledFonts allowUserInstalledFonts, const UChar* characters, unsigned length)
{
CFIndex coveredLength = 0;
auto fallbackOption = allowUserInstalledFonts == AllowUserInstalledFonts::No ? kCTFontFallbackOptionSystem : kCTFontFallbackOptionDefault;
return adoptCF(CTFontCreateForCharactersWithLanguageAndOption(font, reinterpret_cast<const UniChar*>(characters), length, localeString, fallbackOption, &coveredLength));
}
#else
static RetainPtr<CTFontRef> createFontForCharacters(CTFontRef font, CFStringRef localeString, AllowUserInstalledFonts, const UChar* characters, unsigned length)
{
CFIndex coveredLength = 0;
return adoptCF(CTFontCreateForCharactersWithLanguage(font, reinterpret_cast<const UniChar*>(characters), length, localeString, &coveredLength));
}
#endif

static RetainPtr<CTFontRef> lookupFallbackFont(CTFontRef font, FontSelectionValue fontWeight, const AtomString& locale, AllowUserInstalledFonts allowUserInstalledFonts, const UChar* characters, unsigned length)
{
Expand Down Expand Up @@ -1356,11 +1343,7 @@ void FontCache::prewarm(PrewarmInformation&& prewarmInformation)
CFIndex coveredLength = 0;
UniChar character = ' ';

#if HAVE(CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION)
auto fallbackWarmingFont = adoptCF(CTFontCreateForCharactersWithLanguageAndOption(warmingFont.get(), &character, 1, nullptr, kCTFontFallbackOptionSystem, &coveredLength));
#else
auto fallbackWarmingFont = adoptCF(CTFontCreateForCharactersWithLanguage(warmingFont.get(), &character, 1, nullptr, &coveredLength));
#endif
}
}
});
Expand Down
15 changes: 3 additions & 12 deletions Source/WebCore/platform/graphics/cocoa/FontDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,10 @@

namespace WebCore {

FontDatabase::InstalledFont::InstalledFont(CTFontDescriptorRef fontDescriptor, AllowUserInstalledFonts allowUserInstalledFonts)
FontDatabase::InstalledFont::InstalledFont(CTFontDescriptorRef fontDescriptor)
: fontDescriptor(fontDescriptor)
, capabilities(capabilitiesForFontDescriptor(fontDescriptor))
{
#if HAVE(CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION)
UNUSED_PARAM(allowUserInstalledFonts);
#else
if (allowUserInstalledFonts != AllowUserInstalledFonts::No)
return;
auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
addAttributesForInstalledFonts(attributes.get(), allowUserInstalledFonts);
this->fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor, attributes.get()));
#endif
}

FontDatabase::InstalledFontFamily::InstalledFontFamily(Vector<InstalledFont>&& installedFonts)
Expand Down Expand Up @@ -81,7 +72,7 @@ const FontDatabase::InstalledFontFamily& FontDatabase::collectionForFamily(const
Vector<InstalledFont> result;
result.reserveInitialCapacity(count);
for (CFIndex i = 0; i < count; ++i) {
InstalledFont installedFont(static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(matches.get(), i)), m_allowUserInstalledFonts);
InstalledFont installedFont(static_cast<CTFontDescriptorRef>(CFArrayGetValueAtIndex(matches.get(), i)));
result.uncheckedAppend(WTFMove(installedFont));
}
return makeUnique<InstalledFontFamily>(WTFMove(result));
Expand All @@ -106,7 +97,7 @@ const FontDatabase::InstalledFont& FontDatabase::fontForPostScriptName(const Ato
auto fontDescriptorToMatch = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
auto mandatoryAttributes = installedFontMandatoryAttributes(m_allowUserInstalledFonts);
auto match = adoptCF(CTFontDescriptorCreateMatchingFontDescriptor(fontDescriptorToMatch.get(), mandatoryAttributes.get()));
return InstalledFont(match.get(), m_allowUserInstalledFonts);
return InstalledFont(match.get());
}).iterator->value;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/cocoa/FontDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FontDatabase {

struct InstalledFont {
InstalledFont() = default;
InstalledFont(CTFontDescriptorRef, AllowUserInstalledFonts);
InstalledFont(CTFontDescriptorRef);

RetainPtr<CTFontDescriptorRef> fontDescriptor;
FontSelectionCapabilities capabilities;
Expand Down

0 comments on commit b81575a

Please sign in to comment.