├── .gitignore
├── Golden_Line_Height.sketchplugin
└── Contents
│ └── Sketch
│ ├── manifest.json
│ └── script.js
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | Deprecated/Golden Line Height.sketchplugin
3 |
--------------------------------------------------------------------------------
/Golden_Line_Height.sketchplugin/Contents/Sketch/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name" : "Golden Line Height",
3 | "identifier" : "com.lorenzwoehr.goldenlineheight",
4 | "version" : "2.0",
5 | "description" : "Optimize your typography based on font size, line-height and width.",
6 | "authorEmail" : "hello@lorenzwoehr.com",
7 | "author" : "Lorenz Woehr",
8 | "commands" : [
9 | {
10 | "script" : "script.js",
11 | "handler" : "onRun",
12 | "shortcut" : "cmd l",
13 | "name" : "Golden Line Height",
14 | "identifier" : "goldenlineheight"
15 | }
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/Golden_Line_Height.sketchplugin/Contents/Sketch/script.js:
--------------------------------------------------------------------------------
1 | // Golden Line Height, by Lorenz Woehr — Source code available at [GitHub](https://github.com/lorenzwoehr/Golden-Ratio-Line-Height-Sketch-Plugin)
2 | //
3 | // Sets golden line height (cmd l)
4 |
5 | var onRun = function(context) {
6 | var doc = context.document;
7 | var selection = context.selection;
8 |
9 | var textLayers = [];
10 |
11 | if (selection.count() > 0) {
12 |
13 | // Loop through selected layers
14 | for (var i = 0; i < selection.count(); i++) {
15 |
16 | var s = selection[i];
17 |
18 | // Check if the layer is a text layer
19 | if (s.className() == "MSTextLayer") {
20 | textLayers.push(s);
21 | }
22 | }
23 |
24 | if (textLayers.length > 0) {
25 |
26 | for (var j = 0; j < textLayers.length; j++) {
27 |
28 | var textLayer = textLayers[j];
29 |
30 | var fontSize = textLayer.fontSize();
31 | var textWidth = textLayer.frame().width();
32 | var ratio = 1.61803398875;
33 |
34 | var lineHeight = fontSize * (ratio - (1 / (2 * ratio)) * (1 - textWidth / ((fontSize * ratio)*(fontSize * ratio))));
35 |
36 | int goldenLineHeight = Math.round(lineHeight);
37 |
38 | textLayer.setLineHeight(goldenLineHeight);
39 | }
40 |
41 | } else {
42 | doc.showMessage("Please select a text layer.");
43 | }
44 | } else {
45 | doc.showMessage("Please select a text layer.")
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Lorenz Wöhr
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | *****
2 | **Sketch Plugin by Lorenz Wöhr**
3 | *****
4 |
5 | # Golden Ratio Line Height
6 | Optimize your typography with ease.
7 |
8 |
9 | ## Install
10 | 1. Download and extract ZIP of this repo.
11 | 2. Copy the plugin ``Golden Line Height.sketchplugin`` in your Sketch plugin folder (use ``Plugins > Reveal Plugins Folder``).
12 | Plugin filename will show up as item in Sketch Plugins menu.
13 |
14 | ## Usage
15 | 1. Select one or more text layers in Sketch.
16 | 2. Run ``Plugins > Golden Line Height`` or use ``cmd + L``
17 |
18 |
19 | Thanks to Pearsonified's Golden Ratio Typography Calculator for providing all the math magic stuff!
20 |
--------------------------------------------------------------------------------