-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6087de6
commit 74464bf
Showing
4 changed files
with
67 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
Deprecated/Golden Line Height.sketchplugin |
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
Golden_Line_Height.sketchplugin/Contents/Sketch/manifest.json
This file contains 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
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" | ||
} | ||
] | ||
} |
This file contains 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
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.") | ||
} | ||
|
||
} |