Skip to content

Instantly share code, notes, and snippets.

@typemytype
Created July 25, 2019 07:07
Show Gist options
  • Select an option

  • Save typemytype/68bbf615649e3a4a3281709d03cee4e9 to your computer and use it in GitHub Desktop.

Select an option

Save typemytype/68bbf615649e3a4a3281709d03cee4e9 to your computer and use it in GitHub Desktop.
import AppKit
import CoreText
def fontWithFeatures(fontName, fontSize=10, features=None):
font = AppKit.NSFont.fontWithName_size_(fontName, fontSize)
if not features:
return font
descriptor = CoreText.CTFontDescriptorCreateCopyWithAttributes(font.fontDescriptor(), {CoreText.kCTFontFeatureSettingsAttribute: features})
return AppKit.NSFont.fontWithDescriptor_size_(descriptor, fontSize)
fontName = font('/Users/frederik/Downloads/DrawBot Error/SourceSerifPro-Bold.otf')
s = FormattedString()
for fea in ["numr", "dnom", "sinf", "sups"]:
aFont = fontWithFeatures(fontName, 100, features=[fea])
attributes = {
AppKit.NSForegroundColorAttributeName: AppKit.NSColor.redColor(),
AppKit.NSFontAttributeName: aFont
}
txt = AppKit.NSAttributedString.alloc().initWithString_attributes_("123", attributes)
s.getNSObject().appendAttributedString_(txt)
text(s, (10, 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment