Skip to content

Commit

Permalink
Sketch 3.4+ support
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzwoehr committed Nov 2, 2016
1 parent 6087de6 commit 74464bf
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Deprecated/Golden Line Height.sketchplugin
40 changes: 0 additions & 40 deletions Golden Line Height.sketchplugin

This file was deleted.

17 changes: 17 additions & 0 deletions Golden_Line_Height.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name" : "Golden Line Height",
"identifier" : "com.lorenzwoehr.goldenlineheight",
"version" : "2.0",
"description" : "Optimize your typography based on font size, line-height and width.",
"authorEmail" : "hello@lorenzwoehr.com",
"author" : "Lorenz Woehr",
"commands" : [
{
"script" : "script.js",
"handler" : "onRun",
"shortcut" : "cmd l",
"name" : "Golden Line Height",
"identifier" : "goldenlineheight"
}
]
}
48 changes: 48 additions & 0 deletions Golden_Line_Height.sketchplugin/Contents/Sketch/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Golden Line Height, by Lorenz Woehr — Source code available at [GitHub](https://github.com/lorenzwoehr/Golden-Ratio-Line-Height-Sketch-Plugin)
//
// Sets golden line height (cmd l)

var onRun = function(context) {
var doc = context.document;
var selection = context.selection;

var textLayers = [];

if (selection.count() > 0) {

// Loop through selected layers
for (var i = 0; i < selection.count(); i++) {

var s = selection[i];

// Check if the layer is a text layer
if (s.className() == "MSTextLayer") {
textLayers.push(s);
}
}

if (textLayers.length > 0) {

for (var j = 0; j < textLayers.length; j++) {

var textLayer = textLayers[j];

var fontSize = textLayer.fontSize();
var textWidth = textLayer.frame().width();
var ratio = 1.61803398875;

var lineHeight = fontSize * (ratio - (1 / (2 * ratio)) * (1 - textWidth / ((fontSize * ratio)*(fontSize * ratio))));

int goldenLineHeight = Math.round(lineHeight);

textLayer.setLineHeight(goldenLineHeight);
}

} else {
doc.showMessage("Please select a text layer.");
}
} else {
doc.showMessage("Please select a text layer.")
}

}

0 comments on commit 74464bf

Please sign in to comment.