Ticket #168: ticket168_point_in_grid.ps

File ticket168_point_in_grid.ps, 11.4 KB (added by duncan, 17 years ago)
Line 
1%!PS-Adobe-3.0 EPSF-3.0
2%%Creator: Tk Canvas Widget
3%%Title: Window .17405352.17438520.17475344.17475504.17475464
4%%CreationDate: Wed May 30 17:13:42 2007
5%%BoundingBox: -210 102 823 690
6%%Pages: 1
7%%DocumentData: Clean7Bit
8%%Orientation: Portrait
9%%EndComments
10
11%%BeginProlog
12/CurrentEncoding [
13/space/space/space/space/space/space/space/space
14/space/space/space/space/space/space/space/space
15/space/space/space/space/space/space/space/space
16/space/space/space/space/space/space/space/space
17/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quotesingle
18/parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
19/zero/one/two/three/four/five/six/seven
20/eight/nine/colon/semicolon/less/equal/greater/question
21/at/A/B/C/D/E/F/G
22/H/I/J/K/L/M/N/O
23/P/Q/R/S/T/U/V/W
24/X/Y/Z/bracketleft/backslash/bracketright/asciicircum/underscore
25/grave/a/b/c/d/e/f/g
26/h/i/j/k/l/m/n/o
27/p/q/r/s/t/u/v/w
28/x/y/z/braceleft/bar/braceright/asciitilde/space
29/Euro/space/quotesinglbase/florin/quotedblbase/ellipsis/dagger/daggerdbl
30/circumflex/perthousand/Scaron/guilsinglleft/OE/space/Zcaron/space
31/space/quoteleft/quoteright/quotedblleft/quotedblright/bullet/endash/emdash
32/tilde/trademark/scaron/guilsinglright/oe/space/zcaron/Ydieresis
33/space/exclamdown/cent/sterling/currency/yen/brokenbar/section
34/dieresis/copyright/ordfeminine/guillemotleft/logicalnot/hyphen/registered/macron
35/degree/plusminus/twosuperior/threesuperior/acute/mu/paragraph/periodcentered
36/cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown
37/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
38/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis
39/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/multiply
40/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
41/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
42/egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
43/eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide
44/oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis
45] def
46
4750 dict begin
48% This is a standard prolog for Postscript generated by Tk's canvas
49% widget.
50% RCS: @(#) $Id: mkpsenc.tcl,v 1.3 2002/07/19 14:37:21 drh Exp $
51
52% The definitions below just define all of the variables used in
53% any of the procedures here.  This is needed for obscure reasons
54% explained on p. 716 of the Postscript manual (Section H.2.7,
55% "Initializing Variables," in the section on Encapsulated Postscript).
56
57/baseline 0 def
58/stipimage 0 def
59/height 0 def
60/justify 0 def
61/lineLength 0 def
62/spacing 0 def
63/stipple 0 def
64/strings 0 def
65/xoffset 0 def
66/yoffset 0 def
67/tmpstip null def
68
69
70/cstringshow {
71    {
72        dup type /stringtype eq
73        { show } { glyphshow }
74        ifelse
75    }
76    forall
77} bind def
78
79
80
81/cstringwidth {
82    0 exch 0 exch
83    {
84        dup type /stringtype eq
85        { stringwidth } { 
86            currentfont /Encoding get exch 1 exch put (\001) stringwidth 
87        }
88        ifelse 
89        exch 3 1 roll add 3 1 roll add exch
90    }
91    forall
92} bind def
93
94% font ISOEncode font
95% This procedure changes the encoding of a font from the default
96% Postscript encoding to current system encoding.  It's typically invoked just
97% before invoking "setfont".  The body of this procedure comes from
98% Section 5.6.1 of the Postscript book.
99
100/ISOEncode {
101    dup length dict begin
102        {1 index /FID ne {def} {pop pop} ifelse} forall
103        /Encoding CurrentEncoding def
104        currentdict
105    end
106
107    % I'm not sure why it's necessary to use "definefont" on this new
108    % font, but it seems to be important; just use the name "Temporary"
109    % for the font.
110
111    /Temporary exch definefont
112} bind def
113
114% StrokeClip
115%
116% This procedure converts the current path into a clip area under
117% the assumption of stroking.  It's a bit tricky because some Postscript
118% interpreters get errors during strokepath for dashed lines.  If
119% this happens then turn off dashes and try again.
120
121/StrokeClip {
122    {strokepath} stopped {
123        (This Postscript printer gets limitcheck overflows when) =
124        (stippling dashed lines;  lines will be printed solid instead.) =
125        [] 0 setdash strokepath} if
126    clip
127} bind def
128
129% desiredSize EvenPixels closestSize
130%
131% The procedure below is used for stippling.  Given the optimal size
132% of a dot in a stipple pattern in the current user coordinate system,
133% compute the closest size that is an exact multiple of the device's
134% pixel size.  This allows stipple patterns to be displayed without
135% aliasing effects.
136
137/EvenPixels {
138    % Compute exact number of device pixels per stipple dot.
139    dup 0 matrix currentmatrix dtransform
140    dup mul exch dup mul add sqrt
141
142    % Round to an integer, make sure the number is at least 1, and compute
143    % user coord distance corresponding to this.
144    dup round dup 1 lt {pop 1} if
145    exch div mul
146} bind def
147
148% width height string StippleFill --
149%
150% Given a path already set up and a clipping region generated from
151% it, this procedure will fill the clipping region with a stipple
152% pattern.  "String" contains a proper image description of the
153% stipple pattern and "width" and "height" give its dimensions.  Each
154% stipple dot is assumed to be about one unit across in the current
155% user coordinate system.  This procedure trashes the graphics state.
156
157/StippleFill {
158    % The following code is needed to work around a NeWSprint bug.
159
160    /tmpstip 1 index def
161
162    % Change the scaling so that one user unit in user coordinates
163    % corresponds to the size of one stipple dot.
164    1 EvenPixels dup scale
165
166    % Compute the bounding box occupied by the path (which is now
167    % the clipping region), and round the lower coordinates down
168    % to the nearest starting point for the stipple pattern.  Be
169    % careful about negative numbers, since the rounding works
170    % differently on them.
171
172    pathbbox
173    4 2 roll
174    5 index div dup 0 lt {1 sub} if cvi 5 index mul 4 1 roll
175    6 index div dup 0 lt {1 sub} if cvi 6 index mul 3 2 roll
176
177    % Stack now: width height string y1 y2 x1 x2
178    % Below is a doubly-nested for loop to iterate across this area
179    % in units of the stipple pattern size, going up columns then
180    % across rows, blasting out a stipple-pattern-sized rectangle at
181    % each position
182
183    6 index exch {
184        2 index 5 index 3 index {
185            % Stack now: width height string y1 y2 x y
186
187            gsave
188            1 index exch translate
189            5 index 5 index true matrix tmpstip imagemask
190            grestore
191        } for
192        pop
193    } for
194    pop pop pop pop pop
195} bind def
196
197% -- AdjustColor --
198% Given a color value already set for output by the caller, adjusts
199% that value to a grayscale or mono value if requested by the CL
200% variable.
201
202/AdjustColor {
203    CL 2 lt {
204        currentgray
205        CL 0 eq {
206            .5 lt {0} {1} ifelse
207        } if
208        setgray
209    } if
210} bind def
211
212% x y strings spacing xoffset yoffset justify stipple DrawText --
213% This procedure does all of the real work of drawing text.  The
214% color and font must already have been set by the caller, and the
215% following arguments must be on the stack:
216%
217% x, y -        Coordinates at which to draw text.
218% strings -     An array of strings, one for each line of the text item,
219%               in order from top to bottom.
220% spacing -     Spacing between lines.
221% xoffset -     Horizontal offset for text bbox relative to x and y: 0 for
222%               nw/w/sw anchor, -0.5 for n/center/s, and -1.0 for ne/e/se.
223% yoffset -     Vertical offset for text bbox relative to x and y: 0 for
224%               nw/n/ne anchor, +0.5 for w/center/e, and +1.0 for sw/s/se.
225% justify -     0 for left justification, 0.5 for center, 1 for right justify.
226% stipple -     Boolean value indicating whether or not text is to be
227%               drawn in stippled fashion.  If text is stippled,
228%               procedure StippleText must have been defined to call
229%               StippleFill in the right way.
230%
231% Also, when this procedure is invoked, the color and font must already
232% have been set for the text.
233
234/DrawText {
235    /stipple exch def
236    /justify exch def
237    /yoffset exch def
238    /xoffset exch def
239    /spacing exch def
240    /strings exch def
241
242    % First scan through all of the text to find the widest line.
243
244    /lineLength 0 def
245    strings {
246        cstringwidth pop
247        dup lineLength gt {/lineLength exch def} {pop} ifelse
248        newpath
249    } forall
250
251    % Compute the baseline offset and the actual font height.
252
253    0 0 moveto (TXygqPZ) false charpath
254    pathbbox dup /baseline exch def
255    exch pop exch sub /height exch def pop
256    newpath
257
258    % Translate coordinates first so that the origin is at the upper-left
259    % corner of the text's bounding box. Remember that x and y for
260    % positioning are still on the stack.
261
262    translate
263    lineLength xoffset mul
264    strings length 1 sub spacing mul height add yoffset mul translate
265
266    % Now use the baseline and justification information to translate so
267    % that the origin is at the baseline and positioning point for the
268    % first line of text.
269
270    justify lineLength mul baseline neg translate
271
272    % Iterate over each of the lines to output it.  For each line,
273    % compute its width again so it can be properly justified, then
274    % display it.
275
276    strings {
277        dup cstringwidth pop
278        justify neg mul 0 moveto
279        stipple {
280           
281 
282            % The text is stippled, so turn it into a path and print
283            % by calling StippledText, which in turn calls StippleFill.
284            % Unfortunately, many Postscript interpreters will get
285            % overflow errors if we try to do the whole string at
286            % once, so do it a character at a time.
287
288            gsave
289            /char (X) def
290            {
291                dup type /stringtype eq {
292                    % This segment is a string.
293                    {
294                        char 0 3 -1 roll put
295                        currentpoint
296                        gsave
297                        char true charpath clip StippleText
298                        grestore
299                        char stringwidth translate
300                        moveto
301                    } forall
302                } {
303                    % This segment is glyph name
304                    % Temporary override
305                    currentfont /Encoding get exch 1 exch put
306                    currentpoint
307                    gsave (\001) true charpath clip StippleText
308                    grestore
309                    (\001) stringwidth translate
310                    moveto
311                } ifelse
312            } forall
313            grestore 
314        } {cstringshow} ifelse
315        0 spacing neg translate
316    } forall
317} bind def
318
319%%EndProlog
320%%BeginSetup
321/CL 2 def
322%%EndSetup
323
324%%Page: 1 1
325save
326306.0 396.0 translate
3270.75 0.75 scale
328-2537715 -391 translate
3292537027 782 moveto 2538404 782 lineto 2538404 0 lineto 2537027 0 lineto closepath clip newpath
330gsave
3312535641.1828 -1007.55440000072 moveto
3322589590.9952 34958.9872000003 lineto
3332572363.47134961 2354.86766358558 lineto
3342535641.1828 -1007.55440000072 lineto
3351 setlinejoin 1 setlinecap
3361 setlinewidth
337[] 0 setdash
3380.000 1.000 0.000 setrgbcolor AdjustColor
339stroke
340grestore
341gsave
3422572363.47134961 2354.86766358558 moveto
3432571782.61170278 -35586.2370702559 lineto
3442535641.1828 -1007.55440000072 lineto
3452572363.47134961 2354.86766358558 lineto
3461 setlinejoin 1 setlinecap
3471 setlinewidth
348[] 0 setdash
3490.000 1.000 0.000 setrgbcolor AdjustColor
350stroke
351grestore
352gsave
3532537796.175296 434.10726399906 moveto 6.00000000046566 0 rlineto 0 -5.99999999906868 rlineto -6.00000000046566 0 rlineto closepath
3541.000 1.000 1.000 setrgbcolor AdjustColor
355fill
3562537796.175296 434.10726399906 moveto 6.00000000046566 0 rlineto 0 -5.99999999906868 rlineto -6.00000000046566 0 rlineto closepath
3570 setlinejoin 2 setlinecap
3581 setlinewidth
359[] 0 setdash
3600.000 0.000 0.000 setrgbcolor AdjustColor
361stroke
362grestore
363restore showpage
364
365%%Trailer
366end
367%%EOF