forked from moluapple/ExtendScripts4AI-ID
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathAI_Package Fonts of Document with ID.jsx
63 lines (56 loc) · 1.86 KB
/
AI_Package Fonts of Document with ID.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
function getUsedFonts(doc /*获取文档使用字体信息*/ ) {
var xml = new XML(doc.XMPString),
names = xml.descendants('stFnt:fontName'),
files = xml.descendants('stFnt:fontFileName'),
ln = names.length(),
i = 0,
arr = [];
for (; i < ln; i++) {
arr.push([names[i], files[i]])
};
return arr;
}
function packageFonts(arr, oFolder) {
/*为数组添加 indexOf 方法*/
Array.prototype.indexOf = function (obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) {
return i
}
}
return -1
}
var oFile, oName, fontInfo, fontName, fontFiles, index, n,
psNameArr = String(app.fonts.everyItem().postscriptName).split(','),
arr = arr.split('###'),
ln = arr.length,
i = 0;
for (; i < ln; i++) {
fontInfo = arr[i].split(',');
fontName = fontInfo[0];
fontFiles = fontInfo[1].split('; ');
/*使用 indexOf 通过 postscript 名称找出该字体对象 */
index = psNameArr.indexOf(fontName);
oPath = File(app.fonts[index].location).parent;
for (n = 0; n < fontFiles.length; n++) {
oFile = File(oPath + '/' + fontFiles[n]);
oName = oFolder + '/' + fontFiles[n];
try {
oFile.copy(File(oName), true)
} catch (e) {}
}
}
};
function main() {
var doc = app.activeDocument,
arr = getUsedFonts(doc),
oFolder = new Folder(doc.path + '/Document Fonts'),
bt;
oFolder.create();
bt = new BridgeTalk();
bt.target = "indesign";
bt.body = packageFonts.toSource() + '("' + arr.join('###') + '", "' + oFolder + '")';
bt.send();
oFolder.execute();
}
main();