-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathList Fonts.jsx
76 lines (61 loc) · 2.1 KB
/
List Fonts.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
var refPSD = new ActionReference();
function arrayUnique(a){
var temp = []
i = a.length;
// ExtendScript has no indexOf function
while(i--) {
var found = false,
n = temp.length;
while (n--) {
if(a[i] === temp[n]) {
found = true;
}
}
if(!found) {
temp.push(a[i]);
}
}
return temp;
}
function findFonts() {
refPSD.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
// Get layers from PSD
var countLayers = executeActionGet(refPSD).getInteger(charIDToTypeID('NmbL'))+1,
fonts = [];
// Loop through each layer
while(countLayers--) {
var refLayer = new ActionReference(),
descLayer,
layerStyles,
countStyles;
refLayer.putIndex( charIDToTypeID( 'Lyr ' ), countLayers );
// Catch error when no backgroundLayer is present
try {
descLayer = executeActionGet(refLayer);
} catch (e) {
continue;
}
// Only proceed if text layer
if(!descLayer.hasKey(stringIDToTypeID( 'textKey' ))) continue;
// Get list of styles (in case of multiple fonts in a text layer)
layerStyles = descLayer.getObjectValue(stringIDToTypeID('textKey')).getList(stringIDToTypeID('textStyleRange'));
countStyles = layerStyles.count;
// Loop through each style and get the font name
while(countStyles--) {
try {
var fontName = layerStyles.getObjectValue(countStyles).getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontPostScriptName'));
fonts.push(fontName);
} catch (e) {
continue;
}
}
}
// Return a unique and sorted array of font names
return arrayUnique(fonts).sort();
}
if (documents.length) {
var fontsFound = findFonts();
alert(fontsFound.length +' fonts found \n'+fontsFound.join('\n'));
} else {
alert('No fonts found \nOpen a PSD before running this script',);
}