Skip to content

Instantly share code, notes, and snippets.

@KevinGutowski
Last active May 28, 2019 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KevinGutowski/9d6f5a0980393c12aca5243aae8947e0 to your computer and use it in GitHub Desktop.
Save KevinGutowski/9d6f5a0980393c12aca5243aae8947e0 to your computer and use it in GitHub Desktop.
var sketch = require('sketch')
var document = sketch.getSelectedDocument()
var text = document.selectedLayers.layers[0].sketchObject
let textView = text.editingDelegate().textView()
let selectedRange = textView.selectedRange()
let textStorage = textView.textStorage()
let settingsAttribute = getSettingsAttributeForKey_Value(kLowerCaseType, kLowerCaseSmallCapsSelector)
function getSettingsAttributeForKey_Value(key, value) {
let settingsAttribute = {
[NSFontFeatureSettingsAttribute]: [{
[NSFontFeatureTypeIdentifierKey]: key,
[NSFontFeatureSelectorIdentifierKey]: value
}]
}
return settingsAttribute
}
let font = text.font()
let fontSize = font.pointSize()
let descriptor = font.fontDescriptor().fontDescriptorByAddingAttributes(settingsAttribute)
let newFont = NSFont.fontWithDescriptor_size(descriptor,fontSize)
let attrsDict = NSDictionary.dictionaryWithObject_forKey(newFont,NSFontAttributeName)
textStorage.addAttributes_range(attrsDict,selectedRange)
textView.didChangeText()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment