Kite/PScript/Defs.pm

filter: Statementstmt 89.1% 33 / 37 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 2 totaltotal 82.9% 39 / 47 CC 2 SCAR 4.5
CC
2
Cov
90%
AUTOLOAD
2.0
load
2.0
new
2.0
CRAP 1.6
« Kite.pm ↑ Summary Kite/XML/Parser.pm »
1 #========================================================================
2 # Kite::PScript::Defs
3 #
4 # DESCRIPTION
5 # Perl module defining a number of PostScript definitions useful
6 # for generating PostScript documents for kite part layout, etc.
7 #
8 # AUTHOR
9 # Simon Stapleton <simon@tufty.co.uk> wrote the original xml2ps.pl
10 # utility which contained most of the PostScript contained herein.
11 #
12 # Most of that, he freely admits, was gleaned from the Blue Book
13 # (PostScript Language Tutorial and Cookbook, Adobe).
14 #
15 # Andy Wardley <abw@kfs.org> re-packaged it into a module for
16 # integration into the Kite bundle.
17 #
18 # COPYRIGHT
19 # This module is free software; you can redistribute it and/or
20 # modify it under the same terms as Perl itself.
21 #
22 # VERSION
23 # $Id: Defs.pm,v 1.3 2000/10/18 08:37:49 abw Exp $
24 #
25 #========================================================================
26  
27 package Kite::PScript::Defs;
28  
29 2 require 5.004;
30 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 2 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use vars qw( $AUTOLOAD @EXPORT_OK %EXPORT_TAGS
Subroutine BEGIN: called CC=1 SCAR=0.0
34 $mm $lines $cross $dot $circle $crop $clip $reg $noreg
35 2 $outline $tiles $tilemap $dotiles $pathtext $box );
36  
37 2 @EXPORT_OK = qw( mm lines cross dot circle crop clip reg noreg
38 outline tiles tilemap dotiles pathtext );
39 2 %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] );
40  
41 8 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=6.9
42 8 my $item = $AUTOLOAD;
43 8 $item =~ s/.*:://;
44 8 ▶ return if $item eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $item eq "DESTROY" 1 7 8
45 7 return ${ __PACKAGE__ . "\::$item" };
46 }
47  
48 0 ▶sub load {
Subroutine load: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my $class = shift;
50 0 return $class;
51 }
52  
53 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
54 0 my $class = shift;
55 0 bless { }, $class;
56 }
57  
58  
59 #------------------------------------------------------------------------
60 2 $mm =<<EOF;
61 /mm { 72 mul 25.4 div } bind def
62 EOF
63  
64 #------------------------------------------------------------------------
65 2 $lines =<<EOF;
66 /linelight { 0.25 setlinewidth [] 0 setdash } bind def
67 /linenormal { 0.5 setlinewidth [] 0 setdash } bind def
68 /lineheavy { 0.75 setlinewidth [] 0 setdash } bind def
69 /linedotted { 0.5 setlinewidth [3 5 1 5] 0 setdash } def
70 /linedashed { 0.5 setlinewidth [5 3 2 3] 0 setdash } def
71 EOF
72  
73 #------------------------------------------------------------------------
74 2 $cross =<<EOF;
75 /cross {
76 linenormal
77 newpath moveto
78 -5 mm 0 rmoveto
79 10 mm 0 mm rlineto
80 -5 mm -5 mm rmoveto
81 0 mm 10 mm rlineto
82 stroke
83 } def
84 EOF
85  
86 #------------------------------------------------------------------------
87 2 $dot =<<EOF;
88 /dot {
89 linenormal
90 newpath 0.75 mm 0 360 arc
91 fill
92 stroke
93 } def
94 EOF
95  
96 #------------------------------------------------------------------------
97 2 $circle =<<EOF;
98 /circle {
99 linenormal
100 newpath 2 mm 0 360 arc
101 stroke
102 } def
103 EOF
104  
105 #------------------------------------------------------------------------
106 2 $crop =<<EOF;
107 /crop {
108 /y exch def
109 /x exch def
110 x y circle
111 x y cross
112 } def
113 EOF
114  
115 #------------------------------------------------------------------------
116 2 $clip =<<EOF;
117 % clipping rectangle set to current imageable size minus border
118 clippath pathbbox
119 /cliptry exch border sub def
120 /cliptrx exch border sub def
121 /clipbly exch border add def
122 /clipblx exch border add def
123 /clipysize cliptry clipbly sub def
124 /clipxsize cliptrx clipblx sub def
125 /clipbox {
126 clipblx clipbly clipxsize clipysize
127 } def
128  
129 EOF
130  
131 #------------------------------------------------------------------------
132 2 $reg =<<EOF;
133 % registration marks relative to clipping rectangle,
134 % of course...
135 /regmarks {
136 % draw clipping edge if border > 0
137 border 0 gt {
138 linedashed
139 % .5 setgray
140 clipbox rectstroke
141 } if
142  
143 % draw registration marks at corners
144 linenormal
145 % 0 setgray
146 clipblx clipbly crop
147 clipblx cliptry crop
148 cliptrx cliptry crop
149 cliptrx clipbly crop
150 } def
151 EOF
152  
153 #------------------------------------------------------------------------
154 2 $noreg =<<EOF;
155 % Define a dummy regmarks procedure
156 /regmarks { } def
157 EOF
158  
159 #------------------------------------------------------------------------
160 2 $outline =<<EOF;
161 % define procedure to draw an outline at a fixed distance from path
162 /outline {
163 gsave
164 linedashed
165 dup /outwide exch def
166 setlinewidth
167 gsave stroke grestore
168 outwide 2 sub setlinewidth 1 setgray [] 0 setdash
169 stroke
170 grestore
171 } def
172 EOF
173
174 #------------------------------------------------------------------------
175 2 $tiles =<<EOF;
176 % tiles determines number of page tiles required for path on stack
177 /tiles {
178 gsave
179 pathbbox
180 /try exch def
181 /trx exch def
182 /bly exch def
183 /blx exch def
184 /ysize try bly sub abs def
185 /xsize trx blx sub abs def
186 grestore
187  
188 % calculate number of tiles required in X and Y
189 /tilesnx { xsize clipxsize div ceiling } def
190 /tilesny { ysize clipysize div ceiling } def
191  
192 % determine X/Y offset required to centre path in tiles
193 /tilesxorg tilesnx clipxsize mul xsize sub 2 div border add def
194 /tilesyorg tilesny clipysize mul ysize sub 2 div border add def
195  
196 % add border to tilesorgx/y?
197 } def
198 EOF
199  
200  
201 #------------------------------------------------------------------------
202 2 $tilemap =<<EOF;
203 % prints map of page tiles with current page shaded
204 /tilemap {
205 gsave
206 % 0.5 setlinewidth
207 /mapx clipxsize 15 div def
208 /mapy clipysize 15 div def
209 /gapx mapx 5 div def
210 /gapy gapx def
211 /mapxsize mapx gapx add def
212 /mapysize mapy gapy add def
213 /mapxorg clipblx gapx add def
214 /mapyorg cliptry mapysize tilesny mul sub def
215 0 1 tilesnx 1 sub {
216 /maptx exch def
217 0 1 tilesny 1 sub {
218 /mapty exch def
219 % fill tile if current page
220 maptx tilex eq mapty tiley eq and {
221 mapxorg maptx mapxsize mul add
222 mapyorg mapty mapysize mul add
223 mapx mapy .9 setgray rectfill
224 0.2 setgray
225 0.5 setlinewidth
226 } {
227 0.5 setgray
228 0.5 setlinewidth
229 } ifelse
230 % outline tile
231 mapxorg maptx mapxsize mul add
232 mapyorg mapty mapysize mul add
233 mapx mapy rectstroke
234 } for
235 } for
236 grestore
237 } def
238 EOF
239  
240 #------------------------------------------------------------------------
241 # dotiles
242 2 $dotiles =<<EOF;
243 % we process pages from top left to bottom right, so must negate the order
244 % of the y pages
245 tilesny 1 sub -1 0
246 {
247 /tiley exch def
248 0 1 tilesnx 1 sub
249 {
250 /tilex exch def
251 tilepage
252 gsave
253 clipbox rectclip
254 % translate origin to the new image rectangle
255 tilesxorg tilesyorg translate
256 tilex clipxsize mul neg tiley clipysize mul neg translate
257 tileimage
258 showpage
259 grestore
260 } for
261 } for
262 EOF
263  
264  
265 #------------------------------------------------------------------------
266 2 $pathtext =<<EOF;
267 %------------------------------------------------------------------------
268 % Define /pathtext function to draw text along an arbitrary path (ripped
269 % off from the Blue Book, of course)
270 %
271 /pathtextdict 26 dict def
272 /pathtext {
273 pathtextdict begin
274 /offset exch def
275 /str exch def
276 /pathdist 0 def
277 /setdist offset def
278 /charcount 0 def
279 gsave
280 flattenpath
281 {movetoproc} {linetoproc} {curvetoproc} {closepathproc}
282 pathforall
283 grestore
284 newpath
285 end
286 } def
287  
288 pathtextdict begin
289 /movetoproc {
290 /newy exch def /newx exch def
291 /firstx newx def /firsty newy def
292 /ovr 0 def
293 newx newy transform
294 /cpy exch def /cpx exch def
295 } def
296  
297 /linetoproc {
298 /oldx newx def /oldy newy def
299 /newy exch def /newx exch def
300 /dx newx oldx sub def
301 /dy newy oldy sub def
302 /dist dx dup mul dy dup mul add sqrt def
303 dist 0 ne
304 { /dsx dx dist div ovr mul def
305 /dsy dy dist div ovr mul def
306 oldx dsx add oldy dsy add transform
307 /cpy exch def /cpx exch def
308 /pathdist pathdist dist add def
309 { setdist pathdist le
310 { charcount str length lt
311 {setchar} {exit} ifelse }
312 { /ovr setdist pathdist sub def
313 exit }
314 ifelse
315 } loop
316 } if
317 } def
318  
319 /curvetoproc {
320 (ERROR: No curveto's after flattenpath!) print
321 } def
322  
323 /closepathproc {
324 firstx firsty linetoproc
325 firstx firsty movetoproc
326 } def
327  
328 /setchar {
329 /char str charcount 1 getinterval def
330 /charcount charcount 1 add def
331 /charwidth char stringwidth pop def
332 gsave
333 cpx cpy itransform translate
334 dy dx atan rotate
335 0 0 moveto char show
336 currentpoint transform
337 /cpy exch def /cpx exch def
338 grestore
339 /setdist setdist charwidth add def
340 } def
341 end
342 %------------------------------------------------------------------------
343  
344 EOF
345  
346  
347 #------------------------------------------------------------------------
348 2 $box =<<EOF;
349 % blx bly trx try Box
350 % create a new Box array
351 /Box {
352 4 array astore
353 } def
354  
355 % Box Box_select
356 % unpacks Box to define various Box_* variables
357 /Box_select {
358 aload pop
359 /Box_try exch def
360 /Box_trx exch def
361 /Box_bly exch def
362 /Box_blx exch def
363 /Box_width Box_trx Box_blx sub abs def
364 /Box_height Box_try Box_bly sub abs def
365 } def
366  
367 % Box Box_rect
368 % output Box as a rect suitable for rectstoke etc.
369 /Box_rect {
370 Box_select
371 Box_blx Box_bly Box_width Box_height
372 } def
373  
374 % Box Box_path
375 % output Box as a path suitable for stroke, clip, etc.
376 /Box_path {
377 Box_select
378 newpath
379 Box_blx Box_bly moveto
380 Box_blx Box_try lineto
381 Box_trx Box_try lineto
382 Box_trx Box_bly lineto
383 closepath
384 } def
385  
386 % Box border Box_border
387 % create a new Box bordered within a Box
388 /Box_border {
389 /border exch def
390 Box_select
391 Box_blx border add
392 Box_bly border add
393 Box_trx border sub
394 Box_try border sub
395 Box
396 } def
397  
398 % Box tiles space pad Box_vsplit
399 % split Box vertically into 'tiles' new Boxes, spaced apart by 'space'
400 % and padded within the original Box by 'pad'
401 /Box_vsplit {
402 /Box_pad exch def
403 /Box_space exch def
404 /Box_tiles exch def
405 Box_select
406 /Box_height
407 Box_try Box_bly sub
408 Box_pad 2 mul sub
409 Box_space Box_tiles 1 sub mul sub
410 Box_tiles div
411 def
412 /Box_width
413 Box_trx Box_blx sub
414 Box_pad 2 mul sub
415 def
416 /Box_blx Box_blx Box_pad add def
417 /Box_bly Box_bly Box_pad add def
418 1 1 Box_tiles {
419 pop
420 Box_blx Box_bly Box_blx Box_width add Box_bly Box_height add Box
421 /Box_bly Box_bly Box_height add Box_space add def
422 } for
423 } def
424  
425 % Box tiles space pad Box_hsplit
426 % as per Box_vsplit, splitting Box horizontally
427 /Box_hsplit {
428 /Box_pad exch def
429 /Box_space exch def
430 /Box_tiles exch def
431 Box_select
432 /Box_height Box_height
433 Box_pad 2 mul sub
434 def
435 /Box_width Box_width
436 Box_pad 2 mul sub
437 Box_space Box_tiles 1 sub mul sub
438 Box_tiles div
439 def
440 /Box_blx Box_blx Box_pad add def
441 /Box_bly Box_bly Box_pad add def
442 1 1 Box_tiles {
443 pop
444 Box_blx Box_bly Box_blx Box_width add Box_bly Box_height add Box
445 /Box_blx Box_blx Box_width add Box_space add def
446 } for
447 } def
448  
449  
450 /Box_focus {
451 /Box_box exch def
452 gsave
453 Box_box Box_select
454 Box_box Box_path clip
455 Box_blx Box_bly translate
456 } def
457  
458 /Box_defocus {
459 grestore
460 } def
461 EOF
462  
463  
464 2 1;
465  
466 __END__
« Kite.pm ↑ Summary Kite/XML/Parser.pm »