Skip to content

Instantly share code, notes, and snippets.

Forked from KevinGutowski/FontSpike.js
Last active December 18, 2018 16:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Testing to see if I can build an Opentype Panel
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...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment