-
-
Save matt-curtis/e2847ec5ebde98ac18a4d1253fff8970 to your computer and use it in GitHub Desktop.
Testing to see if I can build an Opentype Panel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
framework("CoreText"); | |
const document = require("sketch").getSelectedDocument(); | |
const textLayer = document.selectedLayers.layers[0]; | |
// WORKS (System font has native support for small caps): | |
const font = NSFont.systemFontOfSize_weight(28, NSFontWeightBold); | |
// DOESN'T WORK: (Depending on if the existing font has small caps support: | |
// const font = textLayer.font; | |
// Two notes: | |
// 1. Had to look it up, [] in ES6 brackets can be used to use variables as object literal keys - | |
// before you were actually using "NSFontFeatureSettingsAttribute" instead of what that variable is set to, which is "CT"-something | |
// 2. kLowerCaseType & kLowerCaseSmallCapsSelector are defined in the CoreText framework | |
const descriptor = font.fontDescriptor().fontDescriptorByAddingAttributes({ | |
[NSFontFeatureSettingsAttribute]: [{ | |
[NSFontFeatureTypeIdentifierKey]: kLowerCaseType, | |
[NSFontFeatureSelectorIdentifierKey]: kLowerCaseSmallCapsSelector | |
}] | |
}); | |
const newFont = NSFont.fontWithDescriptor_size(descriptor, 20); | |
// - Using _object here worked, but it's the private version of the public sketchObject property. | |
// Using _object or sketchObject gave you the MSTextLayer (internal Sketch Objective-C class) | |
// that the Sketch JS library Text object (textLayer) wraps. | |
// - The Text object has the font property so we _should_ be able to use that, but for whatever reason it's not working, so... | |
textLayer.sketchObject.setFont(newFont); | |
document.sketchObject.inspectorController().reload(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment