Added alignmargins
[grml-scripts.git] / usr_share / align.ps
1 %!PS-Adobe-3.0
2 %%Pages: 1
3 %%Title: Alignment testpage for Ghostscript
4 %%Creator: Dieter Stueken (<EMAIL: PROTECTED>)
5 %%BeginProlog
6 % Source: http://www.geocrawler.com/archives/3/378/1997/1/50/2064509/
7
8 /rectdraw               % <x0> <y0> <x1> <y1> rectdraw -
9  { exch 4 -1 roll exch 2 array astore {0 moveto 0 PH rlineto stroke} forall
10    2 array astore {0 exch moveto PW 0 rlineto stroke} forall
11  } bind def
12
13 /arrow          % <ang> <x0> <y0> arrow 
14   { gsave translate rotate
15     0 0 moveto 20 60 lineto -20 60 lineto closepath stroke
16     0 0 moveto 0 80 lineto stroke
17     grestore
18   } bind def
19
20 /triangle {     % len ang x y
21         gsave translate dup rotate exch
22         0 setlinewidth
23         0 0 moveto
24         dup 0 lineto
25         dup 0.98 mul dup 10 div lineto
26         closepath
27         gsave 0.65 setgray fill grestore stroke
28         100 10 moveto
29         100 100 2 index {
30                 gsave 0 -12 rmoveto 0 24 rlineto stroke grestore
31                 gsave 0 24 rmoveto 10 div 2 index neg rotate
32                 cvi =string cvs -6 -4 rmoveto show grestore
33                 100 10 rmoveto
34         } for
35         0 0 moveto
36         0 10 2 index {
37                 pop
38                 gsave 0 -6 rmoveto 0 12 rlineto stroke grestore
39                 10 1 rmoveto
40         } for
41         pop pop
42         grestore
43 } bind def
44
45 /round {dup 3 1 roll mul cvi exch div} def
46
47 /Show {  % print value or unfold array
48         dup type /realtype eq {100 round} if
49         dup type /nulltype eq
50          { pop (-NULL-) show}
51          {dup type /arraytype eq
52           { ([ ) show {Show} forall ( ]) show}
53           {=string cvs show ( ) show}
54          ifelse }
55         ifelse
56 } bind def
57
58 /Pval {         % key val, move down 1 line
59         gsave exch
60         gsave Show (:) show grestore
61         150 0 rmoveto Show
62         grestore
63         0 -12 rmoveto
64 } bind def
65
66 /showtext {
67  /S 80 string def
68  { currentfile S readline pop dup (%END) eq { pop exit } if
69    gsave show grestore 0 -12 rmoveto
70  } loop
71 } bind def
72
73 /.knownget { 2 copy known { get true } { pop pop false } ifelse } bind def
74
75 %%EndProlog
76 %%BeginSetup
77
78 % you may try different settings here, but start with default settings first
79 %<<
80 %  /.HWMargins [8.5 38.0 10.5 12.5]
81 %  /Margins [-35 -51]
82 %>> setpagedevice
83 %
84
85 %%EndSetup
86 %%Page: 1
87
88 % printout all values
89
90 /Helvetica findfont
91 12 scalefont setfont
92 120 756 moveto
93
94 showtext
95 Current settings:
96
97 %END
98
99 [/OutputDevice
100  /Margins
101  /.HWMargins
102  /.MarginsHWResolution
103  /HWResolution
104  /PageOffset
105  /PageSize
106 ] { currentpagedevice 1 index
107     .knownget not {(-undefined-)} if Pval
108 } forall
109
110 showtext
111
112 Graphics alignment:
113
114 Let the distance in inches from the left edge of the page to the
115 vertical line be H, and from the bottom edge to the horizontal line
116 be V. You may define the alignment of your page to the paper by
117
118         << /Margins [x y] >> setpagedevice
119 with
120 %END
121
122 gsave
123 /res currentpagedevice /.MarginsHWResolution .knownget not {600} if def
124 (        x = (1 - H) * ) show res 0 get =string cvs show
125 (, y = (V - 1) * ) show res 1 get =string cvs show
126 grestore 0 -12 rmoveto
127
128 showtext
129
130 If set correctly the drawn arrows should extend into the
131 papers corners (not the clipping corners). After archieving
132 that, you may continue with the clipping edges.
133
134 The clipping edges may be set by
135
136         << /.HWMargins [ml mb mr mt] >> setpagedevice
137
138 where [ml mb mr mt] are the distances of the clipped edges of
139 your graphics relative to the papers edges (left bottom right top)
140 measured in 1/72 inches. The wedge shaped rules may be used to
141 define these values very accurately as its intersections are in
142 1/72 inches. Take the value at the cutoff point from the scale to
143 the next clockwise edge. 
144
145 Start setting the margin values to all zero to see the natural hardware
146 clipping of your printer. You should then define the margins just as big
147 enough to keep the defined margins within your printers real hardware
148 clipping. This is archieved if you can see the thin line drawn all around
149 your defined margin. In addition the thin drawn arrows are just touching
150 the margin and should be totally visible.
151
152 When you put this settings into your inititializing file "gs_init.ps"
153 you may want to apply this setting to a specific printer device only.
154 Here is an example of a printer specific setup:
155
156 <<
157   /ljet4 <<                   % make entries for some device
158     /.HWMargins [16.0 13.2 13.0 11.1]
159     /Margins [-132 -92]
160   >>
161   /ljet2p <<                  % and for an other devices, too
162     /.HWMargins [14.4  6.8 14.5 17.5]
163     /Margins [-60 -23]
164   >>
165 >> currentpagedevice /OutputDevice get
166 .knownget {setpagedevice} if
167 %END
168
169 % get page size
170 currentpagedevice /PageSize get aload pop
171 /PH exch def
172 /PW exch def
173
174 1 setlinewidth
175 PW   0  0  0 triangle
176 PH  90 PW  0 triangle
177 PW 180 PW PH triangle
178 PH 270  0 PH triangle
179
180 % get clipping values
181 clippath pathbbox newpath
182
183 % show clipping box
184 gsave
185 1 setlinewidth % 0.65 setgray
186 4 copy rectdraw
187 grestore
188
189 /CT exch def
190 /CR exch def
191 /CB exch def
192 /CL exch def
193
194 % draw the alignment lines
195 0 setlinewidth
196 72 0 moveto 0 CT rlineto stroke
197 0 72 moveto CR 0 rlineto stroke
198
199 2 setlinewidth
200 1 setlinejoin
201 1 setlinecap
202
203 0 200 moveto 71 0 rlineto -24 -12 rlineto 0 24 rlineto 24 -12 rlineto stroke
204 34 206 moveto (H) show
205
206 144 0 moveto 0 71 rlineto -12 -24 rlineto 24 0 rlineto -12 24 rlineto stroke
207 150 34 moveto (V) show
208
209
210 % draw arrows into to the papers corners
211 1 setlinewidth
212 45
213 90 sub dup  0  0 arrow
214 90 sub dup  0 PH arrow
215 90 sub dup PW PH arrow
216 90 sub dup PW  0 arrow
217 pop %45
218
219 % draw arrows touching the clipping edges
220 0 setlinewidth
221   0 PW 2 div CB arrow
222 180 PW 2 div CT arrow
223 -90 CL PH 2 div arrow
224  90 CR PH 2 div arrow
225
226 showpage
227 %%EOF