blob: 332eae0036460d72f06530282cb3a0bb7a3cf154 (
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
|
%!
% bb.ps -- $Header: bb.ps,v 1.6 88/01/19 17:02:37 van Exp $
%
% Prints a file, but keeps track of bounding box info, and prints the box at
% the end (around the figure.)
%
/$BoundingBox 50 dict def
$BoundingBox begin
/bb$_llx 99999 def
/bb$_lly 99999 def
/bb$_urx -99999 def
/bb$_ury -99999 def
/bb$_mtx matrix defaultmatrix def
end
/bb$_xdef {
exch def
} def
/bb$_put {
exch $BoundingBox 3 1 roll put
} def
/bb$_pt+ {
exch
4 -1 roll add
3 1 roll add
} def
%
% Stubs of old functions.
%
/-stroke /stroke load def
/-fill /fill load def
/-eofill /eofill load def
/-image /image load def
/-show /show load def
/-awidthshow /awidthshow load def
/-showpage /showpage load def
/-restore /restore load def
%
% New Functions.
%
% make sure we remember bb around save-restores
/restore {
$BoundingBox begin bb$_ury bb$_urx bb$_lly bb$_llx end
5 -1 roll
-restore
$BoundingBox begin
/bb$_llx bb$_put
/bb$_lly bb$_put
/bb$_urx bb$_put
/bb$_ury bb$_put
end
} def
/stroke {
gsave
{
flattenpath
strokepath % Make sure to take line width into account.
} stopped { % strokepath often hits a limitcheck.
grestore % Restore the original path
gsave
} if
bb$_path % Accumulate it into our box.
grestore
-stroke
} def
/fill {
gsave
bb$_path
grestore
-fill
} def
/eofill {
gsave
bb$_path
grestore
-eofill
} def
%
% Text is implemented by reducing everything to an `awidthshow'.
%
/show {
0 0 0 0 0 % Extra parameters for awidthshow
6 -1 roll % Bring the string back up
awidthshow
} def
/widthshow {
0 0 % Extra parameters for awidthshow
3 -1 roll % Bring the string back up.
awidthshow
} def
/ashow {
0 0 0
6 3 roll
awidthshow
} def
/awidthshow {
5 dict begin
gsave
currentpoint
2 copy /@starty bb$_xdef /@startx bb$_xdef
2 index stringwidth % Get the natural length of the string
bb$_pt+ % Add to the start to get the end.
2 index length % How many characters?
dup % Add the offsets to each character
6 index mul
exch 5 index mul
bb$_pt+
5 index 3 index
bb$_chcount % How many padding characters?
dup % Add the offsets for each pad.
9 index mul
exch 8 index mul
bb$_pt+
/@endy bb$_xdef /@endx bb$_xdef
bb$_fontheight % Get the height and depth of the current font.
4 copy
@startx @starty bb$_pt+ bb$_point
@startx @starty bb$_pt+ bb$_point
@endx @endy bb$_pt+ bb$_point
@endx @endy bb$_pt+ bb$_point
grestore
end
-awidthshow
} def
%
% `image':
%
% Assume here that the image lands in the unit square.
%
/image {
0 0 bb$_point
1 1 bb$_point
-image
} def
%
% `showpage':
%
% Just draw the box around the figure and print the page, and then initialize
% the bounding box variables again.
%
/bb$_string 10 string def
/showpage {
$BoundingBox begin
initgraphics bb$_mtx setmatrix
% Convert to default coords.
bb$_llx bb$_lly itransform
bb$_urx bb$_ury itransform
/bb$_lly bb$_put /bb$_urx bb$_put
/bb$_ury bb$_put /bb$_llx bb$_put
bb$_llx bb$_lly moveto % Make the box
bb$_llx bb$_ury lineto
bb$_urx bb$_ury lineto
bb$_urx bb$_lly lineto
closepath
bb$_bwstroke % Draw the box.
0 setgray
/Courier findfont 10 scalefont setfont
bb$_llx bb$_lly 12 sub moveto
bb$_llx bb$_string cvs -show ( ) -show
bb$_lly bb$_string cvs -show ( ) -show
bb$_urx bb$_string cvs -show ( ) -show
bb$_ury bb$_string cvs -show
(%%BoundingBox: ) print
bb$_llx bb$_string cvs print ( ) print
bb$_lly bb$_string cvs print ( ) print
bb$_urx bb$_string cvs print ( ) print
bb$_ury bb$_string cvs print (\n) print
end
99999 /bb$_llx bb$_put
99999 /bb$_lly bb$_put
-99999 /bb$_urx bb$_put
-99999 /bb$_ury bb$_put
-showpage
} def
%/copypage {showpage} def
%
% BoundingBox functions:
%
% We accumulate the information about the bounding box into four variables.
% The data is stored in device coordinates.
%
%
% x y `bb$_point' -
%
% Takes a point in user coordinates and adds it into the bounding box info.
%
/bb$_point {
$BoundingBox begin
transform % Convert to device coords.
dup bb$_lly lt {dup /bb$_lly bb$_put}if
dup bb$_ury gt {dup /bb$_ury bb$_put}if
pop
dup bb$_llx lt {dup /bb$_llx bb$_put}if
dup bb$_urx gt {dup /bb$_urx bb$_put}if
pop
end
} def
%
% - `bb$_path' -
%
% Incorporates the bounding box of the path into the bounding box info.
%
/bb$_path {
gsave
{
0 setlinejoin
flattenpath
pathbbox
bb$_point
bb$_point
} stopped {
grestore
gsave
} if
grestore
} def
%
% Stuff for text.
%
%
% char-code string `bb$_chcount' occurs
%
% Counts the number of times a character appears in a string.
%
/bb$_chcount {
0 exch
{
2 index eq {
1 add
} if
} forall
exch pop
} def
%
% - `bb$_fontheight' heightx heighty depthx depthy
%
% Returns the offsets to the lowest point and highest point in the current
% font.
%
/bb$_fontheight {
currentfont begin
FontBBox
exch pop 0 exch
FontMatrix transform
4 2 roll
exch pop 0 exch
FontMatrix transform
end
} def
/bb$_bwstroke {
0 setlinewidth
1 setgray
[5] 0 setdash
gsave -stroke grestore
0 setgray
[5] 5 setdash
-stroke
} def
% end of bb.ps
|