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