-
Notifications
You must be signed in to change notification settings - Fork 11
/
aprs-sym-export.js
111 lines (86 loc) · 3.26 KB
/
aprs-sym-export.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// export APRS symbols from Illustrator
// Heikki Hannikainen, OH7LZB
var doc = app.activeDocument;
var docWidth = doc.width;
/*var fileName = doc.fullName.toString();
if (fileName.lastIndexOf(".") >= 0) {
fileName = fileName.substr(0, fileName.lastIndexOf("."));
}
*/
var fileName = '/Users/hessu/src/aprs-symbols/out/aprs-symbols';
var resolutions = [ 24, 32, 48, 56, 64, 128, 256 ];
var rows = 8;
var columns = 16;
var arts = doc.artboards;
$.writeln("File " + fileName + " - Artboards: " + arts.length);
// Write out individual artboards
for (var ab = 0; ab < arts.length && ab < 3; ab++) {
arts.setActiveArtboardIndex(ab);
for (var k in resolutions) {
var res = resolutions[k];
$.writeln("ab " + ab + " res " + res);
do_export(doc, fileName, ab, res, "", 1);
do_export(doc, fileName, ab, res, "@2x", 2);
do_export(doc, fileName, ab, res, "@3x", 3);
}
}
//aprsdroid_layer_setup();
//aprsdroid_export(arts);
function aprsdroid_layer_setup()
{
// For Georg, combine all artboards in a single one and export it
$.writeln("artboard 0 rect: " + arts[0].artboardRect);
var ab0r = arts[0].artboardRect;
var ab1r = arts[1].artboardRect;
var w = ab0r[2] - ab0r[0];
var h = ab0r[1] - ab0r[3];
$.writeln("artboard 0 size: w " + w + " h " + h);
var tempLayer = doc.layers.add();
$.writeln("added temporary layer: " + tempLayer);
var gap = 40;
var abTr = [ ab1r[2] + gap, ab1r[1], ab1r[2] + gap + w, ab1r[1] - h*3 ];
var tempAb = arts.add(abTr);
$.writeln("added temporary artboard: " + tempAb + " at " + abTr);
// copy each artboard to the temp one
var sab, k;
for (sab = 0; sab < 3; sab++) {
arts.setActiveArtboardIndex(sab);
doc.selection = null; // deselect everything
doc.selectObjectsOnActiveArtboard(); // select all in artboard
var sel = doc.selection; // get selection
for (k=0; k < sel.length; k++) {
var newItem = sel[k].duplicate(tempLayer, ElementPlacement.PLACEATEND);
var newPosition = [
newItem.position[0] - arts[sab].artboardRect[0] + abTr[0],
newItem.position[1] - arts[sab].artboardRect[1] + abTr[1] - sab*h
];
newItem.position = newPosition;
}
}
}
function aprsdroid_export(arts)
{
// export the temp artboard
$.writeln("exporting for droid: " + arts[3].name);
arts.setActiveArtboardIndex(3);
// var droid_resolutions = [16, 24, 32, 36, 48, 64];
var droid_resolutions = [64];
for (var k in droid_resolutions) {
var res = droid_resolutions[k];
$.writeln("droid res " + res);
do_export(doc, fileName, "droid", res, "", 1);
}
}
function do_export(doc, fname, ab, res, fname_append, res_mult)
{
var fn = fname + "-" + res + "-" + ab + fname_append + ".png";
$.writeln(" " + fn);
var targetWidth = res * columns * res_mult;
$.writeln(" target width " + targetWidth + " doc width " + docWidth);
var exportOptions = new ExportOptionsPNG24();
exportOptions.horizontalScale = exportOptions.verticalScale = 100 * (targetWidth/docWidth);
exportOptions.artBoardClipping = true;
var file = new File('.' + fn);
$.writeln(" file: " + file);
doc.exportFile(file, ExportType.PNG24, exportOptions);
}