-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathparse.ps
369 lines (314 loc) · 10.4 KB
/
parse.ps
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
%!PS-Adobe-2.0 EPSF-1.2
%%Pages: 1
%%BoundingBox: 0 0 120 36
%%EndComments
%%BeginDocument:
% compute size of diagram by adding
% #rows x 8.5
% (#rows -1) x 10
% \sum maxheight x 10
/nulllink () def % The symbol of a null link
/wordfontsize 11 def % the size of the word font
/labelfontsize 9 def % the size of the connector label font
/ex 10 def % the horizontal radius of all the links
/ey 10 def % the height of the level 0 links
/ed 10 def % amount to add to this height per level
/radius 10 def % radius for rounded arcs
/row-spacing 10 def % the space between successive rows of the diagram
/gap wordfontsize .5 mul def % the gap between words
/top-of-words wordfontsize .85 mul def
% the delta y above where the text is written where
% the major axis of the ellipse is located
/label-gap labelfontsize .1 mul def
/xwordfontsize 10 def % the size of the word font
/xlabelfontsize 10 def % the size of the connector label font
/xex 10 def % the horizontal radius of all the links
/xey 10 def % the height of the level 0 links
/xed 10 def % amount to add to this height per level
/xradius 10 def % radius for rounded arcs
/xrow-spacing 10 def % the space between successive rows of the diagram
/xgap wordfontsize .5 mul def % the gap between words
/centerpage 1.5 72 mul 2 div def
% this number of points from the left margin is the center of page
/rightpage 1.5 72 mul def
% number of points from the left margin is the right margin
/show-string-centered-dict 5 dict def
/show-string-centered {
show-string-centered-dict begin
/string exch def
/ycenter exch def
/xcenter exch def
xcenter string stringwidth pop 2 div sub
ycenter labelfontsize .3 mul sub
moveto
string show
end
} def
/clear-word-box {
show-string-centered-dict begin
/string exch def
/ycenter exch def
/xcenter exch def
newpath
/urx string stringwidth pop 2 div def
/ury labelfontsize .3 mul def
xcenter urx sub ycenter ury sub moveto
xcenter urx add ycenter ury sub lineto
xcenter urx add ycenter ury add lineto
xcenter urx sub ycenter ury add lineto
closepath
1 setgray fill
0 setgray
end
} def
/diagram-sentence-dict 20 dict def
/diagram-sentence-circle
{diagram-sentence-dict begin
/links exch def
/words exch def
/n words length def
/Times-Roman findfont wordfontsize scalefont setfont
/x 0 def
/y 0 def
/left-ends [x dup words {stringwidth pop add gap add dup}
forall pop pop] def
/right-ends [x words {stringwidth pop add dup gap add} forall pop]
def
/centers [0 1 n 1 sub {/i exch def
left-ends i get
right-ends i get
add 2 div
} for ] def
x y moveto
words {show gap 0 rmoveto} forall
.5 setlinewidth
links {dup 0 get /leftword exch def
dup 1 get /rightword exch def
dup 2 get /level exch def
3 get /string exch def
newpath
string nulllink eq {[2] 1 setdash}{[] 0 setdash} ifelse
% string nulllink eq {.8 setgray}{0 setgray} ifelse
centers leftword get
y top-of-words add
moveto
centers rightword get
centers leftword get
sub 2 div dup
radius
lt {/radiusx exch def}{pop /radiusx radius def} ifelse
centers leftword get
y top-of-words add ey ed level mul add add
centers rightword get
y top-of-words add ey ed level mul add add
radiusx
arcto
4 {pop} repeat
centers rightword get
y top-of-words add ey ed level mul add add
centers rightword get
y top-of-words add
radiusx
arcto
4 {pop} repeat
centers rightword get
y top-of-words add
lineto
stroke
/radius-y ey ed level mul add def
/center-arc-x
centers leftword get centers rightword get add 2 div
def
/center-arc-y
y top-of-words radius-y add add
def
/Courier-Bold findfont labelfontsize scalefont setfont
center-arc-x center-arc-y string clear-word-box
center-arc-x center-arc-y string show-string-centered
} forall
end
} def
/diagramdict 20 dict def
/diagram
{diagramdict begin
/break-words exch def
/links exch def
/words exch def
/n words length def
/n-rows break-words length def
/Times-Roman findfont wordfontsize scalefont setfont
/left-ends [0 dup words {stringwidth pop add gap add dup}
forall pop pop] def
/right-ends [0 words {stringwidth pop add dup gap add} forall pop]
def
/lwindows [ break-words {left-ends exch get gap 2 div sub } forall ]
def
/rwindows [1 1 n-rows 1 sub {/i exch def
lwindows i get } for
right-ends n 1 sub get gap 2 div add
] def
/max 0 def
0 1 links length 1 sub {
/i exch def
/t links i get 2 get def
t max gt {/max t def} if
} for
/max-height ed max mul ey add top-of-words add row-spacing add def
/total-height n-rows max-height mul row-spacing sub def
/max-width 0 def % compute the widest window
0 1 n-rows 1 sub {
/i exch def
/t rwindows i get lwindows i get sub def
t max-width gt {/max-width t def} if
} for
centerpage max-width 2 div sub 0 translate % centers it
% rightpage max-width sub 0 translate % right justified
% Delete both of these to make it left justified
n-rows 1 sub -1 0
{/i exch def
gsave
newpath
%/centering centerpage rwindows i get lwindows i get sub 2 div
%sub def
% this line causes each row to be centered
/centering 0 def
% set centering to 0 to prevent centering of each row
centering -100 moveto % -100 because some letters go below zero
centering max-height n-rows mul lineto
rwindows i get lwindows i get sub centering add
max-height n-rows mul lineto
rwindows i get lwindows i get sub centering add
-100 lineto
closepath
clip
lwindows i get neg n-rows i sub 1 sub max-height mul translate
centerpage centering 0 translate
words links diagram-sentence-circle
grestore
} for
end
} def
/diagramx
{diagramdict begin
/break-words exch def
/links exch def
/words exch def
/n words length def
/n-rows break-words length def
/Times-Roman findfont xwordfontsize scalefont setfont
/left-ends [0 dup words {stringwidth pop add gap add dup}
forall pop pop] def
/right-ends [0 words {stringwidth pop add dup gap add} forall pop]
def
/lwindows [ break-words {left-ends exch get gap 2 div sub } forall ]
def
/rwindows [1 1 n-rows 1 sub {/i exch def
lwindows i get } for
right-ends n 1 sub get xgap 2 div add
] def
/max 0 def
0 1 links length 1 sub {
/i exch def
/t links i get 2 get def
t max gt {/max t def} if
} for
/max-height xed max mul xey add top-of-words add xrow-spacing add
def
/total-height n-rows max-height mul xrow-spacing sub def
/max-width 0 def % compute the widest window
0 1 n-rows 1 sub {
/i exch def
/t rwindows i get lwindows i get sub def
t max-width gt {/max-width t def} if
} for
centerpage max-width 2 div sub 0 translate % centers it
% rightpage max-width sub 0 translate % right justified
% Delete both of these to make it left justified
n-rows 1 sub -1 0
{/i exch def
gsave
newpath
%/centering centerpage rwindows i get lwindows i get sub 2 div
%sub def
% this line causes each row to be centered
/centering 0 def
% set centering to 0 to prevent centering of each row
centering -100 moveto % -100 because some letters go below zero
centering max-height n-rows mul lineto
rwindows i get lwindows i get sub centering add
max-height n-rows mul lineto
rwindows i get lwindows i get sub centering add
-100 lineto
closepath
clip
lwindows i get neg n-rows i sub 1 sub max-height mul translate
centerpage centering 0 translate
words links diagram-sentence-circle
grestore
} for
end
} def
/ldiagram
{diagramdict begin
/break-words exch def
/links exch def
/words exch def
/n words length def
/n-rows break-words length def
/Times-Roman findfont wordfontsize scalefont setfont
/left-ends [0 dup words {stringwidth pop add gap add dup}
forall pop pop] def
/right-ends [0 words {stringwidth pop add dup gap add} forall pop]
def
/lwindows [ break-words {left-ends exch get gap 2 div sub } forall ]
def
/rwindows [1 1 n-rows 1 sub {/i exch def
lwindows i get } for
right-ends n 1 sub get gap 2 div add
] def
/max 0 def
0 1 links length 1 sub {
/i exch def
/t links i get 2 get def
t max gt {/max t def} if
} for
/max-height ed max mul ey add top-of-words add row-spacing add def
/total-height n-rows max-height mul row-spacing sub def
/max-width 0 def % compute the widest window
0 1 n-rows 1 sub {
/i exch def
/t rwindows i get lwindows i get sub def
t max-width gt {/max-width t def} if
} for
% centerpage max-width 2 div sub 0 translate % centers it
% rightpage max-width sub 0 translate % right justified
% Delete both of these to make it left justified
n-rows 1 sub -1 0
{/i exch def
gsave
newpath
%/centering centerpage rwindows i get lwindows i get sub 2 div
%sub def
% this line causes each row to be centered
/centering 0 def
% set centering to 0 to prevent centering of each row
centering -100 moveto % -100 because some letters go below zero
centering max-height n-rows mul lineto
rwindows i get lwindows i get sub centering add
max-height n-rows mul lineto
rwindows i get lwindows i get sub centering add
-100 lineto
closepath
clip
lwindows i get neg n-rows i sub 1 sub max-height mul translate
centerpage centering 0 translate
words links diagram-sentence-circle
grestore
} for
end
} def
[( )(Kevin)(threw)(the)(ball)]
[[1 2 0 (S)][2 4 1 (O)][3 4 0 (D)]]
[0]
diagram
%%EndDocument