blob: cc0937f43c875f55264d9f25f092ef1634716675 (
plain)
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
|
% grestore
% special commands for setting up tree macros
%% version .91 - May 16, 1995
TeXDict begin
% the commands needed to get any of this working. The first section
% may need to be modified if different dvi to postscript programs are
% used.
% redefinition of /@beginspec suggested by Gintas Grigelionis
% (gintas@theophys.kth.se) 5/95. also dropped bop_hook and texpsmatrix
%
% /@beginspec {gsave texpsmatrix setmatrix treedict begin} def
/@beginspec {gsave
Resolution 72 div VResolution -72 div scale
treedict begin} def
/@endspec {end grestore} def
% for landscape Landscape=true, letter Landscape=false
% In dvips 5.5 and later, the matrix in landscape was changed from
% [0.0 -1.0 1.0 0.0 0.0 0.0] to the current setting of [0.0 1.0 -1.0
% 0.0 0.0 0.0]. If you are using an earlier version, switch back.
/treedict 200 dict def treedict begin
% num pt num (converts a number in TeX pts (72.27 pts/in) to
% postscript pts (72pts/in)
/pt {72 mul 72.07 div} def
% end of first section
% definition of a node as a box containing the following information
% The x y location of the lower left hand corner of the box
% the height of the box (h)
% the width of the box (w)
% nodemargin is added to all sides to ensure a boundary around the box
% str w h d node -
% (nodemargin is defined in the TeX file)
/nodemargin 2 def
/nodes 100 dict def
/node { /dpth exch def
/hght exch def
/wdth exch def
4 dict dup begin
/x /y currentpoint
dpth sub nodemargin sub exch 3 1 roll def
nodemargin sub def
/h hght dpth add nodemargin dup add add def
/w wdth nodemargin dup add add def
end nodes 3 1 roll put} def
% commands to find various locations around the nodebox
%
% nodetopleft nodetop nodetopright
% *--------*--------*
% | |
% | |
% nodeleft * (nodebox) * noderight
% | |
% | |
% *--------*--------*
% nodebotleft nodebottom nodebotright
%
% all of these take
% dict nodebottom x1 y1 [dict has x y h w defined]
/nodebottom {begin
x w 2 div add y
end} def
/nodetop {begin
x w 2 div add y h add
end} def
/nodeleft {begin
x y h 2 div add
end} def
/noderight {begin
x w add y h 2 div add
end} def
/nodetopleft {begin
x y h add
end} def
/nodetopright {begin
x w add y h add
end} def
/nodebottomleft {begin
x y
end} def
/nodebottomright {begin
x w add y
end} def
% some more locations of use
/farright {begin
x w add depth add h 2 div y add
end} def
/farleft {begin
x depth sub h 2 div y add
end} def
/farbottom {begin
x w 2 div add y depth sub
end} def
/fartop {begin
x w 2 div add y h add depth add
end} def
/farbottomleft {begin
x depth 45 cos mul sub y depth 45 sin mul sub
end} def
/farbottomright {begin
x w add depth 45 cos mul add y depth 45 sin mul sub
end} def
/fartopright {begin
x w add depth 45 cos mul add y h add depth 45 sin mul add
end} def
/fartopleft {begin
x depth 45 cos mul sub y h add depth 45 sin mul add
end} def
% connects two nodes with a straight line
% add location information (e.g., whether to go from
% nodetop to nodeleft ...
% nodename1 loc1 nodename2 loc2 nodeconnect -
% e.g., a nodetop b nodebottom nodeconnect
% to see if straight lines are indeed straight
% x1 x2 alignpoint x1' x2' finds out if the two numbers are less than
% one pixel apart if so make x1'=x2'
/alignpoint {2 copy sub abs 1 le {add 2 div round dup} if} def
% nodelocation nodename getnodepoint x y
/getnode {nodes exch get} def
% xfrom yfrom xto yto nodeconnect -
/nodeconnect { gsave
transform 4 2 roll
transform
exch 4 1 roll alignpoint
4 2 roll alignpoint
4 1 roll exch
itransform moveto itransform lineto
stroke
grestore
} def
% arrowheads
% xtail ytail xtip ytip headthickness headlength insetlength arrow -
/arrowdict 15 dict def
arrowdict begin
/mtrx matrix def
end
/arrow {arrowdict begin
/insetlength exch def
/headlength exch def
/halfheadthickness exch 2 div def
/tipy exch def /tipx exch def
/taily exch def /tailx exch def
/dx tipx tailx sub def
/dy tipy taily sub def
/angle dy dx atan def
/savematrix mtrx currentmatrix def
tipx tipy translate
angle rotate
% following is for arrow
0 0 moveto
headlength neg halfheadthickness neg lineto
headlength insetlength sub neg 0 lineto
headlength neg halfheadthickness lineto
closepath
fill
savematrix setmatrix
end } def
% does regular filled arrowhead
/arrowfill {gsave
newpath
arrowwidth arrowlength arrowinset arrow
grestore} def
% draws line for arrow but not arrow head(s)
% xtail ytail xtip ytip tailfix tipfix arrowline
/arrowline {arrowdict begin
gsave
newpath
/tipfix exch def
/tailfix exch def
/tipy exch def /tipx exch def
/taily exch def /tailx exch def
/dx tipx tailx sub def
/dy tipy taily sub def
/angle dy dx atan def
/savematrix mtrx currentmatrix def
tipx tipy translate
angle rotate
tipfix neg 0 moveto
savematrix setmatrix
/savematrix mtrx currentmatrix def
tailx taily translate
angle rotate
tailfix 0 lineto
savematrix setmatrix
stroke
grestore
end} def
% xfrom yfrom xto yto testcmd -
% arrownodeconnect
/arrownodeconnect{ gsave
transform 4 2 roll
transform
exch 4 1 roll alignpoint
4 2 roll alignpoint
4 1 roll exch
itransform 4 2 roll itransform
% line
4 copy
0 arrowdict begin arrowlength arrowinset sub end arrowline
% arrow
gsave
newpath
arrowfill
grestore
grestore
} def
/doublearrownodeconnect{ gsave
transform 4 2 roll
transform
exch 4 1 roll alignpoint
4 2 roll alignpoint
4 1 roll exch
itransform 4 2 roll itransform
% line
% 4 copy moveto lineto
% stroke
4 copy
arrowdict begin arrowlength arrowinset sub end dup arrowline
4 copy
% arrow at one end
gsave
newpath
arrowfill
grestore
% arrow at other end
gsave
newpath
4 2 roll arrowfill
grestore
grestore
} def
% connecting with a bar like
% _______________
% | |
% or like
% _______________
% | |
% | node
% node
% depth fromnode fromloc tonode toloc
% depth x1 y1 x2 y2 barnodeconnect -
/barnodeconnect {4 2 roll
2 copy moveto
5 -1 roll add
dup 3 1 roll
lineto
2 index exch
lineto lineto
stroke
} def
/arrowbarnodeconnect {4 2 roll
2 copy moveto
5 -1 roll add
dup 3 1 roll
lineto
2 index exch
4 copy lineto lineto
gsave
newpath
4 2 roll
arrowfill
fill
grestore
stroke
} def
% Takes two nodes and forms a triangle
% node1
% /\
% / \
% ----
% nodess
%
% fromnodename tonodename nodetriangle -
/nodetriangle {
gsave
exch
nodes exch get nodebottom moveto
dup
nodes exch get nodetopleft lineto
nodes exch get nodetopright lineto
closepath
stroke
grestore } def
% not sure what I am using the following for
% x y x y slope num
/slope {/y1 exch def
/x1 exch def
/y0 exch def
/x0 exch def
y1 y0 sub x1 x0 sub div
} def
% x y x y midpoint x y
/midpoint {/y1 exch def
/x1 exch def
/y0 exch def
/x0 exch def
x1 x0 sub abs
x1 x0 ge {x0 add} {x1 add} ifelse
y1 y0 sub abs
y1 y0 ge {y0 add} {y1 add} ifelse
} def
% variant of curveto where x1 y1 = x2 y2
/tancurveto {1 index exch
curveto} def
/nodetancurve {/depth exch def
/to exch def
/from exch def
gsave
nodes from get noderight moveto
nodes to get noderight
tancurveto
stroke
grestore } def
% the node curves draw curves between two points
%
% this swaps a dictionary around an angle, pulls out depth, & dismisses
% the dictionary.
% node locname farloc angle depth
/getloc {3 -1 roll
nodes exch get dup
begin depth end
3 1 roll
exch cvx exec
4 2 roll} def
% nodename rightcur x1 y1 x2 y2
/rightcur {0 /noderight getloc} def
/leftcur {180 /nodeleft getloc } def
/topcur {90 /nodetop getloc} def
/bottomcur {270 /nodebottom getloc} def
/topleftcur {135 /nodetopleft getloc} def
/toprightcur {45 /nodetopright getloc} def
/bottomleftcur {225 /nodebottomleft getloc} def
/bottomrightcur {315 /nodebottomright getloc} def
% (depth predefined) x1 y1 x2 y2 x3 y3 x4 y4 nodecurve -
% where nodename nodeposition produces x1 y1 x2 y2
% where x1 y1 are the endpoint, x2 y2 end-control, etc.
% adjustments for arrowheads, etc.
/arrowfiddledict 10 dict def
% x1 y1 angle depth shift twist arrowfiddle x3 y3 x4 y4
% where x3 y3 are revised endpoint for arrow-headed bezier curves
/arrowfiddle {arrowfiddledict begin
/twist exch def
/shift exch def
/shaft exch def
/angle exch twist add def
/tipy exch def /tipx exch def
tipx angle cos shaft mul add
tipy angle sin shaft mul add
tipx angle cos shift mul add
tipy angle sin shift mul add
end} def
/nodecurve {gsave
0 fromangle arrowfiddle moveto
6 2 roll
0 toangle arrowfiddle curveto
stroke
grestore} def
/arrownodecurve {gsave
0 fromangle arrowfiddle % adjust from angle
moveto
6 2 roll
4 copy 10 4 roll % prepare arrowhead material
arrowlength arrowinset sub %arrowfiddle param.
toangle % ditto
arrowfiddle
curveto
0 toangle arrowfiddle arrowfill
stroke
grestore} def
/arrow2nodecurve {gsave
4 copy
0 fromangle arrowfiddle arrowfill
arrowlength arrowinset sub fromangle arrowfiddle
moveto
6 2 roll
4 copy 10 4 roll % prepare arrowhead material
arrowlength arrowinset sub %arrowfiddle param.
toangle % ditto
arrowfiddle
curveto
0 toangle arrowfiddle arrowfill
stroke
grestore} def
% commands for doing things along line
% blong (predefined) xfrom yfrom xto yto delink -
% need to find halfway point
/delink { gsave
4 copy newslope
6 2 roll newmidpoint
delinkline } def
%% calculated (dx dy xmid ymid) now moveto midpoint
% moveto dup 0 eq
%% duplicate dy and check whether line is horizontal
% {blong 2 div neg 0 rmoveto blong 0 rlineto 2 pop}
%% line not horizontal so check whether vertical
% {exch dup 0 eq
% {0 blong 2 div neg rmoveto 0 blong rlineto 2 pop}
%% If neither than calculate standard case (dy dx)
% {div neg dup dup mul 1 add sqrt
% blong exch div
% 2 copy mul 2 copy 2 div neg exch 2 div neg exch
% rmoveto rlineto 1 pop} ifelse} ifelse
% stroke
% grestore
% } def
% actually draws the line
% dx dy xmid ymid delinkline -
/delinkline { moveto dup 0 eq
% duplicate dy and check whether line is horizontal
{blong 2 div neg 0 rmoveto blong 0 rlineto 2 pop}
% line not horizontal so check whether vertical
{exch dup 0 eq
{0 blong 2 div neg rmoveto 0 blong rlineto 2 pop}
% If neither than calculate standard case (dy dx)
{div neg dup dup mul 1 add sqrt
blong exch div
2 copy mul 2 copy 2 div neg exch 2 div neg exch
rmoveto rlineto 1 pop} ifelse} ifelse
stroke
grestore
} def
%
% delink curve
% blong (predefined) x0 y0 x1 y1 x2 y2 x3 y3 delinkcurve -
/delinkcurve { 8 copy 8 copy
bezslope 10 2 roll % push to back
bezmidpoint
delinkline
} def
% x0 y0 x1 y1 x2 y2 x3 y3 xyarrange x0 x1 x2 x3 y0 y1 y2 y3
% x0 y0 x1 y1 x2 y2 x3 y3
/xyarrange { exch % x0 y0 x1 y1 x2 y2 y3 x3
3 1 roll % x0 y0 x1 y1 x2 x3 y2 y3
5 -1 roll % x0 y0 x1 x2 x3 y2 y3 y1
7 -1 roll % x0 x1 x2 x3 y2 y3 y1 y0
exch % x0 x1 x2 x3 y2 y3 y0 y1
4 2 roll } def % x0 x1 x2 x3 y0 y1 y2 y3
% x0 x1 x2 x3 calcx xn 8(x3+3x2+3x1+x0)=xn
/calcx { exch 3 mul
3 -1 roll 3 mul
add add add 8 mul} def
% x0 x1 x2 x3 calcx xn x3+x2-x1-x0=xn
/calcy { add exch sub exch sub } def
% x0 y0 x1 y1 x2 y2 x3 y3 bezmidpoint xm ym
% using the following equations
% xb=8*(x3+3x2+3x1+x0)
% yb=8*(y3+3y2+3y1+y0)
/bezmidpoint {xyarrange
calcx 5 1 roll calcx exch
} def
% x0 y0 x1 y1 x2 y2 x3 y3 bezslope dx dy
% equations are dx=x3+x2-x1-x0
% dy=y3+y2-y1-y0
/bezslope {xyarrange
calcy 5 1 roll calcy exch
} def
% finds midpoint between two points xfrom yfrom xto yto newmidpoint xmid ymid
/newmidpoint { exch
4 -1 roll
add 2 div
3 1 roll
add 2 div
} def
% finds slope between two points: xfrom yfrom xto yto newslope dx dy
/newslope { 4 -1 roll
exch
4 1 roll
sub 3 1 roll sub exch
} def
%% commands for drawing things around nodes
% nodename nodebox -
/nodebox {nodes exch get begin
gsave
newpath
x y moveto
h w dobox
cleanup
stroke
grestore
end} def
% nodename nodecircle -
% would be nice to have a parameter that adjusts diameter of circle
% depth nodename nodecircle -
/nodecircle {nodes exch get begin
gsave
newpath
w 2 div x add h 2 div y add
w w mul h h mul add sqrt 2 div 4 -1 roll add
360 0 arcn
cleanup
stroke
grestore
end} def
% no cleanup
/nodecircletrans {nodes exch get begin
gsave
newpath
w 2 div x add h 2 div y add
w w mul h h mul add sqrt 2 div 4 -1 roll add
360 0 arcn
stroke
grestore
end} def
% nodename nodeoval -
/nodeoval {nodes exch get begin
gsave
newpath
x 2 sub y 2 sub moveto
h 4 add w 4 add dooval
cleanup
stroke
grestore
end } def
% ratio depth nodename testnodeoval -
% ratio should be between 0 and 1
/testnodeoval {nodes exch get begin
gsave
newpath
h h mul w w mul add sqrt div dup dup dup
w mul neg x add exch
h mul neg y add
moveto
dup
h mul 2 mul h add exch
w mul 2 mul w add
testdooval
stroke
grestore
end } def
/cleanup{gsave
x y moveto
h nodemargin sub .5 add w nodemargin sub .5 add doccbox
1 setgray fill grestore
}def
/boxdict 4 dict def
boxdict /mtrx matrix put
/dobox{boxdict begin
/w exch def
/h exch def
/savematrix mtrx currentmatrix def
0 h rlineto
w 0 rlineto
0 h neg rlineto
closepath
savematrix setmatrix
end} def
% do box in counterclockwise fashion
/doccbox{boxdict begin
/w exch def
/h exch def
/savematrix mtrx currentmatrix def
w 0 rlineto
0 h rlineto
w neg 0 rlineto
closepath
savematrix setmatrix
end} def
/ovaldict 6 dict def
ovaldict /mtrx matrix put
% h w ovaldict -
/dooval{ovaldict begin
/w exch def
/h exch def
/savematrix mtrx currentmatrix def
0 h 2 div rmoveto
0 h 2 div nodemargin sub
nodemargin h 2 div
w 2 div h 2 div
rcurveto
w 2 div nodemargin sub 0
w 2 div nodemargin neg
w 2 div h 2 div neg
rcurveto
0 h 2 div neg nodemargin add
nodemargin neg h 2 div neg
w 2 div neg h 2 div neg
rcurveto
w 2 div neg nodemargin add 0
w 2 div neg nodemargin
w 2 div neg h 2 div
rcurveto
savematrix setmatrix
end} def
% give height and width of a box and the lower left hand point
% produce a curve that will enclose the box.
% initial point already defined
% ratio h w testdooval -
/testdooval{ovaldict begin
/w exch def
/h exch def
/r exch def
h 2 div neg r mul dup
h 2 div dup
r mul 3 1 roll
2 r sub mul
0 h
rcurveto
w 2 div dup
r mul exch
2 r sub mul
w 2 div r mul dup 3 1 roll
w 0
rcurveto
h 2 div r mul dup
h 2 div neg dup
r mul 3 1 roll
2 r sub mul
0 h neg
rcurveto
w 2 div neg dup
r mul exch
2 r sub mul
w 2 div neg r mul dup 3 1 roll
w neg 0
rcurveto
end} def
end % of treedict
end % of TeXdict
% gsave
|