Skip to content

Commit c1d47f2

Browse files
author
David Frank
committed
initial release
1 parent 47d176a commit c1d47f2

File tree

4 files changed

+89
-8
lines changed

4 files changed

+89
-8
lines changed

Align Text Layers.sketchplugin

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// (cmd option l)
2+
#import 'helpers.js'
3+
4+
format();

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
Changelog
3+
=========
4+
5+
6+
# 1.x release
7+
8+
## v1.0.0 (master)
9+
10+
- Major: initial release
11+

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,39 @@ sketch-text-align
44

55
Properly align text layers regardless of their rectangle box in Sketch
66

7+
![demo][demo-image]
8+
79

810
# Motivation
911

10-
Because Sketch v3.x still has less than ideal support for font-size and line-height, especially when you are dealing with CJK language (Some say it's a limit of OS X). This plugin allow you to align text as imagined, ignoring those incorrectly calculated text rectangles.
12+
Because Sketch v3.x still has less than ideal support for font-size and line-height, especially when you are dealing with CJK language (Some say it's a limit of OSX). This plugin allow you to align text as imagined, ignoring those incorrectly calculated text rectangles.
13+
14+
This plugin is tested with Sketch version 3.2.2 (9983).
1115

1216

1317
# Install
1418

15-
1. Download ZIP of this repo
16-
2. Extract
17-
3. Put the folder in your Sketch plugin folder (Use `Plugins>Reveal Plugins Folder` to find it)
19+
1. Download ZIP of this repo.
20+
2. Extract and rename folder to suit your taste.
21+
3. Put the folder in your Sketch plugin folder (Use `Plugins>Reveal Plugins Folder` to find it).
1822

19-
Folder name and plugin filename will show up in Sketch `Plugins` menu.
23+
Folder name and plugin filename will show up as items in Sketch `Plugins` menu.
2024

2125

2226
# Usage
2327

24-
1. Select multiple text layers
25-
2. Alt + Cmd + L or `Plugins` menu
26-
3. Follow the dialog prompt
28+
1. Select multiple text layers.
29+
2. `Alt + Cmd + L` or use `Plugins` menu.
30+
3. Follow the dialog prompt.
31+
32+
33+
# Note
34+
35+
This plugin does not fix multiline text layer line height and padding issues, it makes aligning multiple text layer easier instead.
2736

2837

2938
# License
3039

3140
MIT
41+
42+
[demo-image]: http://i.imgur.com/Bx1hpLA.png

helpers.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
/**
3+
* helpers.js
4+
*
5+
* A helper for aligning text layers
6+
*/
7+
8+
function format() {
9+
var app = NSApplication.sharedApplication();
10+
11+
if (selection.count() < 2) {
12+
app.displayDialog('Please select at least 2 text layers');
13+
return;
14+
}
15+
16+
var scale = parseFloat(doc.askForUserInput_initialValue('Input your expected line-height (unit em)', '1.5'));
17+
if (!scale) {
18+
return;
19+
}
20+
21+
var prevLayer, prevFrame;
22+
23+
for (var i = selection.count() - 1; i >= 0; i--) {
24+
var layer = selection[i];
25+
26+
if (layer.className() != 'MSTextLayer') {
27+
continue;
28+
}
29+
30+
if (!prevLayer) {
31+
prevLayer = layer;
32+
continue;
33+
}
34+
35+
var pos = position(prevLayer, scale);
36+
align(layer, pos);
37+
38+
prevLayer = layer;
39+
};
40+
};
41+
42+
function position(layer, scale) {
43+
var frame = layer.frame();
44+
var pos = {};
45+
pos.x = frame.x();
46+
pos.y = frame.y() + layer.fontSize() * scale;
47+
48+
return pos;
49+
};
50+
51+
function align(layer, pos) {
52+
var frame = layer.frame();
53+
frame.setX(pos.x);
54+
frame.setY(pos.y);
55+
};

0 commit comments

Comments
 (0)