|
|
1.1 root 1: -> PS_head
2:
3: %ps_include: begin
4: save
5: /ed {exch def} def
6:
7: # redefine dangerous operators
8: {} /showpage ed
9: {} /copypage ed
10: {} /erasepage ed
11: {} /letter ed
12:
13: # restore findfont from systemdict if it looks like it's be redefined
14: currentdict /findfont known systemdict /findfont known and {
15: /findfont systemdict /findfont get def
16: } if
17:
18: # computations are done in the context of a new dictionary
19: 36 dict dup /PS-include-dict-dw ed begin
20:
21: # context holds the save object created earlier
22: /context ed
23:
24: # save and clear the operand stack
25: count array astore /o-stack ed
26:
27: # the following variables are now expected:
28: # llx,lly,urx,ury bounding box of picture to be included
29: # w nonzero if space should be painted white to start
30: # o nonzero if space should be outlined
31: # s nonzero if both dimensions should be scaled
32: # cx,cy center of page space in current coordinates
33: # sx,sy size of page space in current coordinates
34: # ax,ay left-right, up-down adjustment of picture in page space
35: # rot rotation of picture in page space
36: %ps_include: variables begin
37:
38:
39:
40: -> PS_setup
41:
42: %ps_include: variables end
43:
44: # some routines:
45: # - BBOX llx lly urx ury put bounding box on stack
46: # llx lly urx ury BOXPATH - make a path with given box corners
47: # dx dy LEN length compute length of positionless vector
48: # a b MIN min compute minimum of two numbers
49: # a b MAX max compute maximum of two numbers
50: # x y NICE x y move to pixel boundaries in default coords
51: {llx lly urx ury} /bbox ed
52: {newpath 2 index exch 2 index exch dup 6 index exch
53: moveto 3 {lineto} repeat closepath} /boxpath ed
54: {dup mul exch dup mul add sqrt} /len ed
55: {2 copy gt {exch} if pop} /min ed
56: {2 copy lt {exch} if pop} /max ed
57: {transform round exch round exch A itransform} /nice ed
58:
59: # A is the transformation from default to current coordinates
60: {6 array} /n ed
61: n defaultmatrix n currentmatrix n invertmatrix n concatmatrix /A ed
62:
63: # Sx,Sy and Cx,Cy are dimensions and size of bounding box in current coordinates
64: urx llx sub 0 A dtransform len /Sx ed
65: 0 ury lly sub A dtransform len /Sy ed
66: llx urx add 2 div lly ury add 2 div A transform /Cy ed /Cx ed
67:
68: # H and W are height and width of rotated box in current coordinates
69: rot dup sin abs /S ed cos abs /C ed
70: Sx S mul Sy C mul add /H ed
71: Sx C mul Sy S mul add /W ed
72:
73: # Scalex and Scaley are the required horizontal and vertical scaling factors
74: sy H div /Scaley ed
75: sx W div /Scalex ed
76:
77: # Preserve aspect ratio if we're not scaling both dimensions (ie. s is 0)
78: s 0 eq {Scalex Scaley min dup /Scalex ed /Scaley ed} if
79:
80: # add to cx,cy the shift needed within the page space
81: sx Scalex W mul sub 0 max ax 0.5 sub mul cx add /cx ed
82: sy Scaley H mul sub 0 max ay 0.5 sub mul cy add /cy ed
83:
84: # the actual rotation needed is rot less the current rotation
85: urx llx sub 0 A dtransform exch atan rot exch sub /rot ed
86:
87: # set up the coordinate system
88: n currentmatrix initgraphics setmatrix
89: cx cy translate
90: Scalex Scaley scale
91: rot rotate
92: Cx neg Cy neg translate
93: A concat
94:
95: # set the clipping region, and conditionally whiteout and outline
96: bbox boxpath clip newpath
97: w 0 ne {gsave bbox boxpath 1 setgray fill grestore} if
98:
99: # pop local dictionary from the dict stack
100: end
101:
102: # now begins the actual material extracted from the file
103: gsave
104: %ps_include: inclusion begin
105:
106:
107:
108: -> PS_tail
109:
110: %ps_include: inclusion end
111: grestore
112:
113: # within the context of the local dictionary ...
114: PS-include-dict-dw begin
115:
116: o 0 ne {gsave A defaultmatrix /A ed llx lly nice urx ury nice
117: initgraphics 0.1 setlinewidth boxpath stroke grestore} if
118:
119: # ... restore the operand stack and the save context
120: clear o-stack aload pop
121: context end restore
122: %ps_include: end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.