From 68c1798a6703f9476b29c53abe95dd59ae280613 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Wed, 18 Dec 2019 15:57:14 +0200 Subject: [PATCH] [coretext] Use kCTFontOpenTypeFeatureTag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of trying to map OpenType features to AAT feature selectors which only works for a small subset of OpenType features, use the simpler kCTFontOpenTypeFeatureTag with OpenType feature tags directly. With this change, features like cvXX can be enabled in coretext shaper, while they were previously ignored due to missing mapping. This seems to work even with AAT fonts that don’t have OpenType layout tables, which suggests that CoreText is doing the mapping itself in this case. kCTFontOpenTypeFeatureTag seems to have been introduced in macOS 10.10 and iOS 8.0, though, so its use is conditional on version check for now. Not sure how to check iOS version, so I left this out. --- src/hb-coretext.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 8885cfe73..7a900e255 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -475,13 +475,19 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, hb_vector_t feature_events; for (unsigned int i = 0; i < num_features; i++) { + active_feature_t feature; + +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1010 const hb_aat_feature_mapping_t * mapping = hb_aat_layout_find_feature_mapping (features[i].tag); if (!mapping) continue; - active_feature_t feature; feature.rec.feature = mapping->aatFeatureType; feature.rec.setting = features[i].value ? mapping->selectorToEnable : mapping->selectorToDisable; +#else + feature.rec.feature = features[i].tag; + feature.rec.setting = features[i].value; +#endif feature.order = i; feature_event_t *event; @@ -530,6 +536,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, /* active_features.qsort (); */ for (unsigned int j = 0; j < active_features.length; j++) { +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1010 CFStringRef keys[] = { kCTFontFeatureTypeIdentifierKey, kCTFontFeatureSelectorIdentifierKey @@ -538,6 +545,17 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &active_features[j].rec.feature), CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &active_features[j].rec.setting) }; +#else + char tag[5] = {HB_UNTAG (active_features[j].rec.feature)}; + CFTypeRef keys[] = { + kCTFontOpenTypeFeatureTag, + kCTFontOpenTypeFeatureValue + }; + CFTypeRef values[] = { + CFStringCreateWithCString (kCFAllocatorDefault, tag, kCFStringEncodingASCII), + CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &active_features[j].rec.setting) + }; +#endif static_assert ((ARRAY_LENGTH_CONST (keys) == ARRAY_LENGTH_CONST (values)), ""); CFDictionaryRef dict = CFDictionaryCreate (kCFAllocatorDefault, (const void **) keys,