Skip to content

Commit

Permalink
[Cocoa] kCTFontCSSWidthAttribute is available on all Cocoa platforms
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=250364
rdar://104064199

Reviewed by Tim Horton.

Simply unify the codepaths.

* Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::capabilitiesForFontDescriptor):
(WebCore::normalizeWidth): Deleted.
(WebCore::stretchFromCoreTextTraits): Deleted.

Canonical link: https://commits.webkit.org/258709@main
  • Loading branch information
litherum committed Jan 10, 2023
1 parent bb2cc18 commit 47c5a9d
Showing 1 changed file with 1 addition and 41 deletions.
42 changes: 1 addition & 41 deletions Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
#include <wtf/cf/TypeCastsCF.h>
#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>

// FIXME: This seems like it should be in PlatformHave.h.
// FIXME: Likely we can remove this special case for watchOS and tvOS.
#define HAS_CORE_TEXT_WIDTH_ATTRIBUTE (PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV))

namespace WebCore {

static inline void appendTrueTypeFeature(CFMutableArrayRef features, int type, int selector)
Expand Down Expand Up @@ -231,13 +227,6 @@ static inline float normalizeVariationWidth(float value)
return value * 400 - 400;
}

#if !HAS_CORE_TEXT_WIDTH_ATTRIBUTE
static inline float normalizeWidth(float value)
{
return normalizeVariationWidth(value + 1);
}
#endif

struct FontType {
FontType(CTFontRef font)
{
Expand Down Expand Up @@ -593,20 +582,6 @@ RefPtr<Font> FontCache::similarFont(const FontDescription& description, const St
return nullptr;
}

#if !HAS_CORE_TEXT_WIDTH_ATTRIBUTE
static float stretchFromCoreTextTraits(CFDictionaryRef traits)
{
auto widthNumber = static_cast<CFNumberRef>(CFDictionaryGetValue(traits, kCTFontWidthTrait));
if (!widthNumber)
return normalStretchValue();

float ctWidth;
auto success = CFNumberGetValue(widthNumber, kCFNumberFloatType, &ctWidth);
ASSERT_UNUSED(success, success);
return normalizeWidth(ctWidth);
}
#endif

static void fontCacheRegisteredFontsChangedNotificationCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void *, CFDictionaryRef)
{
ASSERT_UNUSED(observer, isMainThread() && observer == &FontCache::forCurrentThread());
Expand Down Expand Up @@ -838,22 +813,9 @@ FontSelectionCapabilities capabilitiesForFontDescriptor(CTFontDescriptorRef font

VariationCapabilities variationCapabilities = variationCapabilitiesForFontDescriptor(fontDescriptor);

#if !HAS_CORE_TEXT_WIDTH_ATTRIBUTE
bool weightOrWidthComeFromTraits = !variationCapabilities.weight || !variationCapabilities.width;
#else
bool weightOrWidthComeFromTraits = false;
#endif

if (!variationCapabilities.slope || weightOrWidthComeFromTraits) {
if (!variationCapabilities.slope) {
auto traits = adoptCF(static_cast<CFDictionaryRef>(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontTraitsAttribute)));
if (traits) {
#if !HAS_CORE_TEXT_WIDTH_ATTRIBUTE
if (!variationCapabilities.width) {
auto widthValue = stretchFromCoreTextTraits(traits.get());
variationCapabilities.width = {{ widthValue, widthValue }};
}
#endif

if (!variationCapabilities.slope) {
auto symbolicTraitsNumber = static_cast<CFNumberRef>(CFDictionaryGetValue(traits.get(), kCTFontSymbolicTrait));
if (symbolicTraitsNumber) {
Expand All @@ -873,12 +835,10 @@ FontSelectionCapabilities capabilitiesForFontDescriptor(CTFontDescriptorRef font
variationCapabilities.weight = {{ value, value }};
}

#if HAS_CORE_TEXT_WIDTH_ATTRIBUTE
if (!variationCapabilities.width) {
auto value = getCSSAttribute(fontDescriptor, kCTFontCSSWidthAttribute, static_cast<float>(normalStretchValue()));
variationCapabilities.width = {{ value, value }};
}
#endif

FontSelectionCapabilities result = {{ FontSelectionValue(variationCapabilities.weight.value().minimum), FontSelectionValue(variationCapabilities.weight.value().maximum) },
{ FontSelectionValue(variationCapabilities.width.value().minimum), FontSelectionValue(variationCapabilities.width.value().maximum) },
Expand Down

0 comments on commit 47c5a9d

Please sign in to comment.