forked from graysitory/Novelty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
preptext.jsx
executable file
·157 lines (143 loc) · 4.31 KB
/
preptext.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
//DESCRIPTION: Jongware's PrepText
if (app.activeDocument.selection[0].constructor.name != "InsertionPoint")
{
alert ("Cursor in "+app.activeDocument.selection[0].constructor.name+"\nPlease put the cursor into a text frame");
exit(0);
}
var myMaximumValue = 63;
var myProgressBarWidth = 384;
var myIncrement = myMaximumValue/myProgressBarWidth;
myCreateProgressPanel(myMaximumValue, myProgressBarWidth);
myProgressPanel.myProgressBar.value = 0;
myCreateProgressPanel(100, 400);
myProgressPanel.show();
for (b=0; b<2; b++)
{
for (i=0; i<2; i++)
{
for (s=0; s<2; s++)
{
for (u=0; u<2; u++)
{
// Don't process strikeout
for (k=0; k<1; k++)
{
for (c=0; c<3; c++)
{
if (b+i+s+u+k+c)
{
myProgressPanel.myProgressBar.value = 32*b+16*i+8*s+4*u+2*k+c;
findAttr (b, i, s, false, u, /*k*/false, c, "");
if (s)
findAttr (b, i, false, s, u, /*k*/false, c, "");
}
}
}
}
}
}
}
myProgressPanel.hide();
exit(0);
function myCreateProgressPanel(myMaximumValue, myProgressBarWidth)
{
myProgressPanel = new Window('window', 'Prepping text');
with(myProgressPanel)
{
myProgressPanel.myProgressBar = add('progressbar', [12, 12, myProgressBarWidth, 24], 0, myMaximumValue);
}
}
function findAttr (bold, italic, superscript, subscript, underline, strikeout, small_all_caps, StyleName)
{
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedCharacterStyle = app.activeDocument.characterStyles[0]; // "[None]"
app.findTextPreferences.fontStyle = "Regular";
app.findTextPreferences.position = Position.NORMAL;
app.findTextPreferences.capitalization = Capitalization.NORMAL;
app.findTextPreferences.underline = false;
app.findTextPreferences.strikeThru = false;
if (bold)
{
if (italic)
app.findTextPreferences.fontStyle = "Bold Italic";
else
app.findTextPreferences.fontStyle = "Bold";
} else
{
if (italic)
app.findTextPreferences.fontStyle = "Italic";
}
if (superscript)
app.findTextPreferences.position = Position.SUPERSCRIPT;
if (subscript)
app.findTextPreferences.position = Position.SUBSCRIPT;
if (underline)
app.findTextPreferences.underline = true;
if (strikeout)
app.findTextPreferences.strikeThru = true;
if (small_all_caps == 1)
app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;
if (small_all_caps == 2)
app.findTextPreferences.capitalization = Capitalization.ALL_CAPS;
foundItems = app.activeDocument.selection[0].parent.findText();
if (foundItems.length > 0)
{
if (StyleName == "")
{
// Make up a name
if (bold)
StyleName = "Bold";
if (italic)
{
if (bold)
StyleName = "Bold Italic";
else
StyleName = "Italic";
}
if (superscript)
{
if (StyleName) StyleName += " + ";
StyleName += "Super";
}
if (subscript)
{
if (StyleName) StyleName += " + ";
StyleName += "Sub";
}
if (underline)
{
if (StyleName) StyleName += " + ";
StyleName += "Underline";
}
if (strikeout)
{
if (StyleName) StyleName += " + ";
StyleName += "Stkout";
}
if (small_all_caps == 1)
{
if (StyleName) StyleName += " + ";
StyleName += "Scaps";
}
if (small_all_caps == 2)
{
if (StyleName) StyleName += " + ";
StyleName += "Caps";
}
try
{
cstyle = app.activeDocument.characterStyles.add({name:StyleName}); // , fontStyle:app.findTextPreferences.fontStyle, underline:app.findTextPreferences.underline, strikeThru:app.findTextPreferences.strikeThru, position:app.findTextPreferences.position, capitalization:app.findTextPreferences.capitalization});
if (bold || italic) cstyle.fontStyle = app.findTextPreferences.fontStyle;
if (superscript || subscript) cstyle.position = app.findTextPreferences.position;
if (underline) cstyle.underline = app.findTextPreferences.underline;
if (strikeout) cstyle.strikeThru = app.findTextPreferences.strikeThru;
if (small_all_caps) cstyle.capitalization = app.findTextPreferences.capitalization;
} catch (e)
{
}
}
app.changeTextPreferences.appliedCharacterStyle = StyleName;
app.activeDocument.selection[0].parent.changeText (false);
}
}