-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_layout_generator.jsx
executable file
·2626 lines (2423 loc) · 123 KB
/
print_layout_generator.jsx
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#target 'Illustrator';
// Print Layout Generator 1.0b
// Github: https://github.com/w4u-public/Print-layout-generator
// Lisence: MIT
(function() {
//================
// Default Settings
// セッティングメニューの初期設定
//================
// Settings
var $outputPath = '~/Desktop'; // 初期保存場所
var $dobu = 3; // 通常のドブの幅 (mm)
var $trimMark = true; // トンボの有無
var $trimMarkJPN = true; //日本式トンボ
var $CompatibleVer = 17; // 互換バージョン (指定しない場合は 0)
var $colorModeCMYK = true; // カラーモード (false は RGB)
var $visualRectColor = 'red'; // 見え寸線の色 (red | green | blue)
var $closeDoc = false; // 生成後に保存じて閉じる
var $multiArtboards = false; // 複数のアートボードにレイアウトをまとめる
// Options
var $layerLock = true; // 非編集レイヤーのロック
var $displaySize = false; // 寸法を図に明記
var $frameView = false; // 見え寸領域の外をフレームで覆う
var $insertTag = true; // タグの挿入
var $numbering = false; // ファイル名の先頭に番号を付ける
// フッタースタンプ
var $dateStamp = false; // フッターに制作日を記述
var $ratioStamp = false; // フッターにレイアウトの比率を記述
var $squareStamp = false; //フッターに平米数を記述
var $freeTextStamp = ''//フッターに任意の文字挿入
// その他の設定
var $HxW = true; //サイズ表記でHが先 (falseで W x H)
var $frameColor = [250, 250, 250]; // フレームの色 (RGB)
var $exclamation = false // CSVで「!」ラインだけを書き出す (SKIP機能の反転)
var $fontFamily = ['Meiryo', 'KozGoPr6N-Regular', 'Osaka']; // 文字のフォント (左優先)
// CSV 取得項目キーワード(任意のキーワードに変更可能
var $keywords1 = [
'名前', // タイトル(名前 ~ 名前5は順に連結されます)
'名前1',
'名前2',
'名前3',
'名前4',
'名前5',
'概要', // 挿入位置: 名前下
'テキスト1', // 概要下 その1
'テキスト2', // 概要下 その2
'テキスト3', // レイアウト下中央
'テキスト4', // アートボード右上
'テキスト5', // アートボード右下
'枚数',
'フォルダ' // 保存サブディレクトリ
];
// CSV 取得サイズ項目キーワード(任意のキーワードに変更可能
var $keywords2 = [
'VW', // Visual Width - 変更例: 見え寸W, 内寸W, 有効表示寸法W, 表示寸法W など
'VH', // Visual Height - 変更例: 見え寸H, 内寸H, 有効表示寸法H, 表示寸法H など
'OW', // Outer Width - 変更例: 外寸W, カット寸W, 板寸W, 仕上がり寸法W など
'OH', // Outer Height - 変更例: 外寸H, カット寸H, 板寸H, 仕上がり寸法H など
'ドブ' // 変更例: 塗り足し, 裁ち落とし, のばし など
]
// 色キーワード定義 (RGB)
var $colorOptions = {
'{R}': [182, 41, 44],
'{G}': [14, 139, 67],
'{B}': [8, 106, 174],
'{P}': [147, 39, 143], // Purple
'{O}': [204, 101, 21], // Orange
'{Y}': [171, 156, 27], // Yellow
'{BLACK}': [0, 0, 0]
};
// 保存オプションの設定 (AI, PDF, EPS)
var $saveOptions = {
ai: {
pdfCompatible: true, //PDF互換ファイルを作成
embedICCProfile: false, //ICCプロファイルを埋め込む
embedLinkedFiles: false, //配置した画像を含む
compressed: true // 圧縮を使用
},
pdf: {
generateThumbnails: true, // サムネイルを生成する
preserveEditability: false, // 編集可能にする
registrationMarks: false, // レジストレーションマークを描画
acrobatLayers: false, // 保存するアートボードの範囲
compatibility: PDFCompatibility.ACROBAT6 // Acrobatの互換バージョン
},
eps: {
embedLinkedFiles: false,
embedAllFonts: true,
includeDocumentThumbnails: false,
preview: EPSPreview.None
}
}
// 規格サイズ (OHに入力で縦型, OWに入力で横型)
var $standardSize = {
// A判
'A0': {w: 841, h: 1189},
'A1': {w: 594, h: 841},
'A2': {w: 420, h: 594},
'A3': {w: 297, h: 420},
'A4': {w: 210, h: 297},
'A5': {w: 148, h: 210},
'A6': {w: 105, h: 148},
'A7': {w: 74, h: 105},
'A8': {w: 52, h: 74},
'A10': {w: 26, h: 37},
// B判
'B0': {w: 1030, h: 1456},
'B1': {w: 728, h: 1030},
'B2': {w: 515, h: 728},
'B3': {w: 364, h: 515},
'B4': {w: 257, h: 364},
'B5': {w: 182, h: 257},
'B6': {w: 128, h: 182},
'B7': {w: 91, h: 128},
'B8': {w: 64, h: 91},
'B9': {w: 32, h: 45}
}
// 設定ここまで==============
//================
// Polyfill
//================
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(callback, thisArg) {
var T, k;
if (this == null) {
throw new TypeError(" this is null or not defined");
}
var O = Object(this);
var len = O.length >>> 0;
if ({}.toString.call(callback) != "[object Function]") {
throw new TypeError(callback + " is not a function");
}
if (thisArg) {
T = thisArg;
}
k = 0;
while(k < len) {
var kValue;
if (k in O) {
kValue = O[ k ];
callback.call(T, kValue, k, O);
}
k++;
}
};
}
//================
// Functions
//================
var isObject = function(data) {
return (Object.prototype.toString.call(data) == '[object Object]') ? true : false;
}
var isArray = function(data) {
return data instanceof Array;
}
var mmToPt = function(mm) {
return mm * 2.83464566929134;
}
var ptToMm = function(pt) {
return pt / 2.83464566929134;
}
var rgb = function(r, g, b) {
var color = new RGBColor();
if(arguments.length == 1 && isArray(arguments[0])) {
color.red = arguments[0][0];
color.green = arguments[0][1];
color.blue = arguments[0][2];
} else {
color.red = r;
color.green = g;
color.blue = b;
}
return color;
}
var getColorCode = function(color) {
if(color == undefined) {
return rgb(0, 0, 0);
} else if(color.typename == 'CMYKColor' || color.typename == 'RGBColor') {
return color;
} else if(isArray(color)) {
return rgb(color);
} else {
throw new Error('invalid color value');
}
}
var zenkakuToHankaku = function(str) {
if(!/[0-9]/.test(str)) return str;
var zen = ["1","2","3","4","5","6","7","8","9","0"];
var han = [1,2,3,4,5,6,7,8,9,0];
while(/[0-9]/.test(str)) {
zen.forEach(function(e, i) {
str = str.replace(zen[i], han[i]);
})
}
return str;
};
var normalizeChara = function(str) {
var meta = ['>', '<', '[?]', ':', ';', '"', '[*]', '[|]', '%', '[.]', '/', ' '];
var zen = ['>', '<', '?', ':', ';', '”', '*', '|', '%', '-', '/', '-'];
meta.forEach(function(e, i) {
var reg = new RegExp(e, 'g');
if(reg.test(str)) {
str = str.replace(reg, zen[i])
}
});
return str;
}
var zeroPadding = function(num, digit) {
var str = num.toString();
var c = digit - str.length;
for(var i = 0; i < c; i++) {
str = '0' + str;
}
return str;
}
var getDate = function(type) {
var o = new Date();
var y = o.getFullYear().toString();
var m = (o.getMonth() + 1).toString();
var d = o.getDate().toString();
if(m.length == 1) m = "0" + m;
if(d.length == 1) d = "0" + d;
switch(type) {
case 'dot':
return y + '.'+ m + '.' + d;
case 'full':
var h = o.getHours().toString();
var min = o.getMinutes().toString();
if(h.length == 1) h = "0" + h;
if(min.length == 1) min = "0" + min;
return y + '-' + m + d + '-' + h + min;
default:
return s = y + m + d;
}
}
var paletteCountDown = function(title) {
var w = new Window('palette', title);
w.text = '';
w.preferredSize.width = 110;
w.preferredSize.height = 0;
w.show();
return {
set: function(count) {
w.text = '残り: ' + count;
},
close: function() {
w.close();
}
};
}
var drawLine = function(group, x1, y1, x2, y2, lineWidth, color) {
var path = group.pathItems.add();
path.pixelAligned = false;
path.filled = false;
path.stroked = true;
path.strokeWidth = (lineWidth !== undefined) ? mmToPt(lineWidth) : mmToPt(0.25);
path.strokeColor = getColorCode(color);
path.setEntirePath([[x1, y1], [x2, y2]]);
return path;
}
// param
// layer, group, color, fillColor, stroke, x, y, w, h, lineWidth, name
var drawRect = function(param) {
var rect;
if(param.layer) {
rect = param.layer.pathItems.rectangle(param.y, param.x, param.w, param.h);
} else if(param.group) {
rect = param.group.pathItems.rectangle(param.y, param.x, param.w, param.h);
}
rect.name = param.name || '';
rect.pixelAligned = false;
rect.strokeColor = getColorCode(param.color);
rect.strokeWidth = (param.lineWidth !== undefined) ? mmToPt(param.lineWidth) : mmToPt(0.25);
if(param.fillColor) {
rect.filled = true;
rect.fillColor = rgb(param.fillColor);
} else {
rect.filled = false;
}
switch(param.stroke) {
case "none":
rect.stroked = false;
break;
case "dashed":
rect.strokeDashes = [param.w / 100, param.w / 100];
break;
default:
rect.stroked = true;
}
return rect;
}
var getBounds = function(item) {
return {
t: item.geometricBounds[1],
r: item.geometricBounds[2],
b: item.geometricBounds[3],
l: item.geometricBounds[0],
w: item.geometricBounds[2] - item.geometricBounds[0],
h: item.geometricBounds[1] - item.geometricBounds[3]
}
}
var getSquare = function(w, h) {
var sq = ((h / 1000) * (w / 1000)) * 100;
return Math.round(sq) / 100;
}
// param
// layer, name, contents, x, y, size, justifi, sep, tracking
var drawText = function(param) {
var textFrames;
var font = getFontFace($fontFamily);
var x = 0;
var y = 0;
if(param.layer) {
textFrames = param.layer.textFrames.add();
} else if(param.group) {
textFrames = param.group.textFrames.add()
}
textFrames.pixelAligned = false;
textFrames = drawContents(textFrames, param.contents);
textFrames.textRange.size = param.size;
textFrames.textRange.textFont = font;
textFrames.top = param.y;
textFrames.left = param.x;
textFrames.name = param.name || "";
if(param.justifi) {
textFrames = setJustification(textFrames, param.justifi, param.x);
};
if(param.tracking) {
textFrames.textRange.tracking = param.tracking;
};
return textFrames;
function setJustification(textFrames, justifi, x) {
var _textFrames = textFrames;
var _justifi = '';
switch(justifi) {
case 'center':
_justifi = Justification.CENTER;
break;
case 'right':
_justifi = Justification.RIGHT;
break;
default:
}
for(var i = 0; i < _textFrames.paragraphs.length; i++) {
var p = _textFrames.paragraphs[i];
p.justification = _justifi;
}
return _textFrames;
}
function getFontFace(fontFamily) {
var font;
for(var i = 0; i < fontFamily.length; i++) {
try {
return app.textFonts[fontFamily[i]]
} catch(e) {
continue;
}
}
return false;
}
function drawContents(textFrames, contents) {
var _textFrames = textFrames;
if(typeof contents == 'string') {
_textFrames.contents = contents;
} else if(isArray(contents)) {
_textFrames = drawArrayText(textFrames, contents);
} else if(isObject(contents) && ('color' in contents)) {
_textFrames = fillText({textFrames: textFrames, set: contents});
} else {
throw new TypeError(contents + " :invalid value");
}
return _textFrames;
function drawArrayText(textFrames, array) {
var _textFrames = textFrames;
var textArray = [];
var colorArray = [];
for(var i = 0; i < array.length; i++) {
var text = array[i];
if(!text || !text.text) continue;
if(isObject(text) && ('color' in text)) {
textArray.push(text.text);
colorArray.push(text.color);
} else {
textArray.push(text);
}
}
if(colorArray.length) {
_textFrames = fillText({
textFrames: textFrames,
sets: {
text: textArray,
color: colorArray
}
});
} else {
_textFrames.contents = textArray.join(' - ');
}
return _textFrames;
}
// Param
// textFrames, set, sets
function fillText(param) {
var _textFrames = param.textFrames;
if(param.sets) {
fillArrayContents(_textFrames, param.sets.text, param.sets.color);
} else if(param.set) {
_textFrames.contents = param.set.text;
if(typeof param.set.text == 'number') {
param.set.text = String(param.set.text);
}
fillCharacter(_textFrames, 0, param.set.text.length, param.set.color);
}
return _textFrames;
function fillArrayContents(textFrames, textArray, colorArray) {
var _textFrames = textFrames;
var start = 0;
var end = 0;
var filltext = '';
var separetor = ' - ';
_textFrames.contents = fillText = textArray.join(separetor);
for(var i = 0; i < textArray.length; i++) {
var text = textArray[i];
var color = colorArray[i];
end = start + text.length;
if(color) {
fillText.indexOf(text, start);
_textFrames = fillCharacter(_textFrames, start, end, color);
}
start += text.length + separetor.length;
}
return _textFrames;
}
function fillCharacter(textFrames, start, end, color) {
if(!color) return;
var _textFrames = textFrames;
for(var i = start; i < end; i++) {
var s = _textFrames.characters[i];
s.fillColor = getColorCode(color);
}
return _textFrames;
}
}
}
}
var docData = (function() {
var inputType = null;
var csvName = null;
var csvPath = null;
var layoutsData = null;
var saveFolder = null;
var converter = {
path: null,
files: null,
}
var doc = null;
var layers = {};
var posAxis = {}
var isOrverArea = false;
return {
set: {
data: function(obj) {
csvName = obj.name;
csvPath = obj.path;
layoutsData = obj.data;
},
saveFolder: function(folderObj) {
saveFolder = folderObj;
},
converter: {
path: function(path) {
converter.path = path;
},
files: function(files) {
converter.files = files;
}
},
createdDoc: function(layer) {
createdDoc.locked = layer;
},
inputType: function(type) {
inputType = type;
},
doc: function(mainDoc) {
doc = mainDoc;
},
layers: function(obj) {
layers = obj;
},
isOrverArea: function(isOrverFlag) {
isOrverArea = isOrverFlag;
}
},
get: {
csvName: function() {
return decodeURI(csvName);
},
csvPath: function() {
return csvPath;
},
layoutsData: function() {
return layoutsData;
},
layoutsCount: function() {
return layoutsData.length;
},
saveFolder: function() {
return saveFolder;
},
converter: {
path: function() {
return converter.path;
},
files: function() {
return converter.files;
}
},
inputType: function() {
return inputType;
},
doc: function() {
return doc;
},
layers: function() {
return layers;
},
layer: function(name) {
return layers[name];
},
isOrverArea: function() {
return isOrverArea;
}
},
layersLock: function() {
for(var key in layers) {
if(key == 'layout' || key == 'mask' || key == 'contents') continue;
layers[key].locked = true;
}
}
}
})();
var generateLayout = function(layoutsData) {
for(var i = 1, l = layoutsData.length; i < l; i++) {
var alert = paletteCountDown();
alert.set(layoutsData.length - i);
var layout = new Layout(layoutsData[i]);
if(!layout.setup()) return;
if(!$multiArtboards) {
if($layerLock) docData.layersLock();
layout.save()
if($closeDoc) activeDocument.close();
}
alert.close();
}
if($multiArtboards) {
if($layerLock) docData.layersLock();
layout.save()
if($closeDoc) activeDocument.close();
}
return true;
}
//================
// Layout Class
//================
var Layout = (function() {
var Layout = function(layoutData) {
this.num = layoutData.num;
this.names = layoutData.names;
this.size = layoutData.size;
this.dobu = layoutData.dobu || mmToPt($dobu);
this.text = layoutData.text;
this.sheet = layoutData.sheet;
this.folder = layoutData.folder;
this.artboard = null;
this.base = {
fontSize: null,
lineWidth: null
}
this.items = {};
this.artboardSize = {};
}
var proto = Layout.prototype;
proto.setup = function() {
if($multiArtboards) {
if(!docData.get.doc()) {
this.createDocument(this.getArtboardSize());
docData.set.layers(this.addLayerSets());
} else {
if(!this.addArtboard(this.getArtboardSize())) return false;
}
} else {
this.createDocument(this.getArtboardSize());
docData.set.layers(this.addLayerSets());
}
this.setArtboardStatus();
this.items = this.addLayoutRects();
if($trimMark) this.items.trimMark = this.addTrimMark();
this.items.title = this.addTitle();
this.items.size = this.addSize();
if($displaySize) this.items.displaySize = this.addDisplaySize();
this.items.text = this.addDetailTexts();
if(this.sheet) this.items.sheet = this.addOrderCount();
if($insertTag) this.items.tag = this.addTag();
this.items.footer = this.addFooterStamp();
return true;
}
proto.getRatio = function(w, h) {
var _w = w || this.size.vw.val || this.size.ow.val;
var _h = h || this.size.vh.val || this.size.ow.val;
var ratio = Math.round((_w / _h) * 100) / 100;
if(String(ratio).length == 1) {
ratio = ratio + ".00";
} else if(ratio.length == 3) {
ratio = ratio + "0";
}
return ratio;
}
proto.getFullName = function(separetor) {
var array = [];
var separetor = separetor ? separetor : ' ';
for(var i = 0; i < this.names.length; i++) {
if(this.names[i] == null || this.names[i].text == undefined) continue;
array.push(this.names[i].text)
}
return array.join(separetor);
}
proto.getSizeText = function(type) {
var vw = this.size.vw.val;
var vh = this.size.vh.val;
var ow = this.size.ow.val;
var oh = this.size.oh.val;
switch(type) {
case 'visual':
if($HxW) {
return 'H' + vh + ' x W' + vw;
} else {
return 'W' + vw + ' x H' + vh;
}
case 'outer':
if($HxW) {
return 'H' + oh + ' x W' + ow;
} else {
return 'W' + ow + ' x H' + oh;
}
break;
default:
if(vw && ow) {
if($HxW) {
return 'H' + vh + ' x W' + vw + ' (H' + oh + ' x W' + ow + ')';
} else {
return 'W' + vw + ' x H' + vh+ ' (W' + ow + ' x H' + oh + ')';
}
} else {
if($HxW) {
return 'H' + oh + ' x W' + ow;
} else {
return 'W' + ow + ' x H' + oh;
}
}
}
return false;
}
proto.addTitle = function() {
var margin = this.artboardSize.w / 10.5;
var textFrames = drawText({
layer: docData.get.layer('text'),
name: 'タイトル',
contents: this.names,
size: this.base.fontSize,
x: this.artboardSize.x + margin,
y: this.artboardSize.t - (this.artboardSize.h / 14)
});
var bounds = getBounds(textFrames);
if(bounds.r > this.artboardSize.r - (margin * 2)) {
textFrames.width = this.artboardSize.r - bounds.l - (margin * 2);
}
return textFrames;
}
proto.addSize = function() {
return drawText({
layer: docData.get.layer('text'),
name: 'サイズ',
contents: this.getSizeText(),
size: this.base.fontSize * 0.7,
x: getBounds(this.items.title).l,
y: getBounds(this.items.title).b - (this.base.fontSize * 0.2),
tracking: 80
});
}
proto.addDetailTexts = function() {
var layer = docData.get.layer('text');
var base = this.base.fontSize;
var array = [];
var x = 0;
var y = 0;
var fontSize = 0;
for(var i = 0, l = this.text.length; i < l; i++) {
var textObj = this.text[i];
if(!textObj || !textObj.text) continue;
switch(i) {
case 0: // タイトル下 概要
array[i] = drawText({
layer: layer,
name: $keywords1[6],
contents: textObj,
size: base * 0.6,
x: getBounds(this.items.size).l,
y: getBounds(this.items.size).b - (base * 0.3),
tracking: 50
});
break;
case 1: // 概要 下 1
if(array[0]) {
x = getBounds(this.items.size).l;
y = getBounds(array[0]).b - (base * 0.6);
} else {
x = getBounds(this.items.size).l;
y = getBounds(this.items.size).b - (base * 0.7);
}
array[i] = drawText({
layer: layer,
name: $keywords1[7],
contents: textObj,
size: base * 0.6,
x: x,
y: y
});
break;
case 2: // 概要 下 2
if(array[0]) {
x = getBounds(this.items.size).l;
y = getBounds(array[0]).b - (base * 0.6);
} else {
x = getBounds(this.items.size).l;
y = getBounds(this.items.size).b - (base * 0.7);
}
if(array[1]) {
x = getBounds(array[1]).r + (getBounds(array[1]).h * 0.4);
}
array[i] = drawText({
layer: layer,
name: $keywords1[8],
contents: textObj,
size: base * 0.6,
x: x,
y: y
});
break;
case 3: // レイアウト下中央
var outerBounds = getBounds(this.items.outer);
var text3posY = getBounds(this.items.mask).b - (base * 2);
if(this.items.displaySize && this.items.displaySize.outer) {
text3posY = getBounds(this.items.displaySize.outer.ow).b - (base * 1.5);
}
array[i] = drawText({
layer: layer,
name: $keywords1[9],
contents: textObj,
size: base * 0.6,
x: outerBounds.l + (outerBounds.w / 2),
y: text3posY,
justifi: 'center'
});
break;
case 4: // アートボード右上
array[i] = drawText({
layer: layer,
contents: textObj,
size: base * 0.4,
x: this.artboardSize.r - (base * 1.5),
y: this.artboardSize.t - (base * 1.5),
justifi: 'right'
});
array[i] = array[i].createOutline();
array[i].name = $keywords1[10];
var bounds = getBounds(array[i]);
drawRect({
layer: layer,
color: textObj.color || [0, 0, 0],
lineWidth: this.base.lineWidth * 2,
name: $keywords1[10] +'_矩形',
x: bounds.l - (base * 0.3),
y: bounds.t + (base * 0.3),
w: bounds.w + (base * 0.6),
h: bounds.h + (base * 0.6)
});
break;
case 5: // アートボード右下
array[i] = drawText({
layer: layer,
name: $keywords1[11],
contents: textObj,
size: base * 0.5,
x: this.artboardSize.r - (base * 1.5),
y: this.artboardSize.b,
justifi: 'right'
});
array[i].top = array[i].top + (base * 1.5);
break;
default:
}
}
return array;
}
proto.getHeaderBounds = function() {
var headerItems = [
this.items.title,
this.items.size,
this.items.text[0],
this.items.text[1],
this.items.text[2]
]
var bounds = {
t: getBounds(this.items.title).t,
r: null,
b: this.artboardSize.h,
l: getBounds(this.items.title).l,
w: null,
h: null
}
for(var i = 0, l = headerItems.length; i < l; i++) {
var item = headerItems[i];
if(!item) continue;
var itemBounds = getBounds(item);
if(itemBounds.r > bounds.r) bounds.r = itemBounds.r;
if(itemBounds.b < bounds.b) bounds.b = itemBounds.b;
bounds.w = bounds.r - bounds.l;
bounds.h = bounds.t - bounds.b;
}
return bounds;
}
proto.addOrderCount = function() {
var group = docData.get.layer('text').groupItems.add();
var margin = this.artboardSize.w / 10.5;
group.name = '枚数';
var l = (this.base.fontSize * 0.5);
var m = l * 4;
var hb = this.getHeaderBounds();
var textPosX = hb.r + m * 2;
if(hb.r > this.artboardSize.r - (margin * 2.5)) {
textPosX = hb.r;
} else {
var path1 = addEntirePath(group.pathItems.add(), [
[hb.r + m, hb.t - (l * 0.5)],
[hb.r + m + l, hb.t - (l * 0.5)],
[hb.r + m + l, hb.b + (l * 0.5)],
[hb.r + m , hb.b + (l * 0.5)]
]);
var path2 = addEntirePath(group.pathItems.add(), [
[hb.r + m + l, hb.t - (hb.h / 2) ],
[hb.r + m + l * 2, hb.t - (hb.h / 2)]
]);
}
drawText({
group: group,
size: this.base.fontSize * 0.8,
contents: {
text: 'x ' + this.sheet,
color: $colorOptions['{R}'],
},
x: textPosX,
y: hb.t - (hb.h / 2) * 0.8
});
return group;
function addEntirePath(item, pathArray) {
item.pixelAligned = false;
item.filled = false;
item.stroked = true;
item.strokeWidth = l / 15;
item.strokeColor = rgb(150, 150, 150);
item.setEntirePath(pathArray);
return item;
}
}
proto.addTag = function() {
var self = this;
var text = this.names.concat();
var size = mmToPt(5);
text.push({color: null, text: this.getSizeText()});
if(this.text[1]) text.push(this.text[1]);
if(this.text[2]) text.push(this.text[2]);
if(this.text[4]) text.push(this.text[4]);
var textFrames = drawText({
layer: docData.get.layer('tag'),
name: 'タグ',
contents: text,
size: size,
x: getBounds(this.items.outer).l + mmToPt(6),
y: getBounds(this.items.outer).t + this.dobu + size + 2,
tracking: -50
});
return resizeTagWidth(textFrames);
function resizeTagWidth(textFrames) {
var _textFrames = textFrames;
var r1 = getBounds(_textFrames).r;
var r2 = getBounds(self.items.outer).r;
if(r1 > r2) {
var offset = r1 - r2;
_textFrames.width = _textFrames.width - offset - 6;
}
return _textFrames;
}
}
proto.addFooterStamp = function() {
var array = [];
/*比率*/ if($ratioStamp) array.push('Ratio: ' + this.getRatio());
/*平米*/ if($squareStamp) array.push('Square: ' + getSquare(this.size.ow.val, this.size.oh.val) + '㎡');
/*日付*/ if($dateStamp) array.push('Created: ' + getDate('dot'));
/*フリーテキスト*/ if($freeTextStamp !== '') array.push($freeTextStamp);
if(array.length == 0) return;
var layer = docData.get.layer('text');
var base = this.base.fontSize;
var textFrames = drawText({
layer: layer,
name: 'フッター',
contents: {text: array.join(' - '), color: [100, 100, 100]},
size: base * 0.4,
x: this.artboardSize.x + this.artboardSize.w / 10.5,
y: this.artboardSize.b + (base * 2),
});
return textFrames;
}
proto.addLayer = function(param) {
var layer = param.parent ? param.parent.layers.add() : activeDocument.layers.add();
layer.name = param.name || '';
layer.color = getColorCode(param.color);
if(param.lock) layer.locked = true;
return layer;
}
proto.addLayerSets = function() {
var layers = {}
layers.layout = this.addLayer({name: 'レイアウト', color: [0, 200, 255]});
app.activeDocument.layers[1].remove();
layers.mask = this.addLayer({parent: layers.layout, name: '内容', color: [0, 105, 205]});
layers.tag = this.addLayer({parent: layers.layout, name: 'タグ', color: [0, 105, 205]});
layers.draftDel = this.addLayer({name: '入稿時削除', color: [255, 0, 200]});