Open typemytype opened 6 years ago
Hmm, it doesn't give the correct default settings. For example, dlig
is off by default.
import CoreText
from drawBot.context.tools.openType import *
def getFeatureTagsForDescriptions(featureDescriptions):
featureTags = {}
for featureDescription in featureDescriptions:
featureType = featureDescription[CoreText.NSFontFeatureTypeIdentifierKey]
for selector in featureDescription["CTFeatureTypeSelectors"]:
featureSelector = selector[CoreText.NSFontFeatureSelectorIdentifierKey]
featureTag = reversedFeatureMap.get((featureType, featureSelector))
if featureTag:
featureTags[featureTag.replace("_off", "")] = "_off" not in featureTag
return featureTags
fontName = "HoeflerText-Regular"
descriptor = CoreText.NSFontDescriptor.fontDescriptorWithName_size_(fontName, 12)
featureDescriptions = CoreText.CTFontDescriptorCopyAttribute(descriptor, CoreText.kCTFontFeaturesAttribute)
features = getFeatureTagsForDescriptions(featureDescriptions)
print(features)
size(500, 250)
font(fontName)
fontSize(50)
text("Hoefler Facts #123", (10, 150))
openTypeFeatures(**features)
text("Hoefler Facts #123", (10, 70))
{'liga': True, 'dlig': True, 'tnum': True, 'pnum': True, 'titl': False, 'onum': True, 'lnum': True}
The idea should be that:
features = openTypeFeatures()
openTypeFeatures(**features)
results in no change in behavior at all.
that must be the idea :)
this will do:
import CoreText
from drawBot.context.tools.openType import *
def getFeatureTagsForDescriptions(featureDescriptions):
featureTags = {}
for featureDescription in featureDescriptions:
featureType = featureDescription[CoreText.NSFontFeatureTypeIdentifierKey]
for selector in featureDescription["CTFeatureTypeSelectors"]:
featureSelector = selector[CoreText.NSFontFeatureSelectorIdentifierKey]
featureTag = reversedFeatureMap.get((featureType, featureSelector))
if featureTag:
featureTag = featureTag.replace("_off", "")
featureTags[featureTag] = selector.get(CoreText.kCTFontFeatureSelectorDefaultKey, False)
return featureTags
fontName = "HoeflerText-Regular"
descriptor = CoreText.NSFontDescriptor.fontDescriptorWithName_size_(fontName, 12)
featureDescriptions = CoreText.CTFontDescriptorCopyAttribute(descriptor, CoreText.kCTFontFeaturesAttribute)
features = getFeatureTagsForDescriptions(featureDescriptions)
print(features)
size(830, 330)
font(fontName)
fontSize(50)
text("Hofiefler Facts #123 default", (10, 270))
openTypeFeatures(**features)
text("Hofiefler Facts #123 set from default", (10, 210))
openTypeFeatures(**{k: False for k in features})
text("Hofiefler Facts #123 all False", (10, 150))
openTypeFeatures(**{k: True for k in features})
text("Hofiefler Facts #123 all True", (10, 90))
openTypeFeatures(resetFeatures=True)
text("Hofiefler Facts #123 reset", (10, 30))
Very nice!
Wasn't this issue resolved with #180?
get the default open type feature settings for a given font:
instead of return a list of fea tags, it could also be a dict where the fea tags are the keys and an on off state, see