summaryrefslogtreecommitdiff
path: root/dviware/dvipsconfig/config.mmgrid
blob: 7e655325a1aa4d3968f9437a448925d0119cd186 (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
%!
% config.mmgrid
% Configuration and header file for dvips. Load with: dvips -P mmgrid
%
% Draw a line grid in millimetres.
%
% This code is based on code from the book
%
%	@Book{Merz:PostscriptAcrobatBibel,
%	  author =       "Thomas Merz",
%	  title =        "Die PostScript- und Acrobat-Bibel. Was Sie schon
%	  		 immer {\"u}ber PostScript und Acrobat/{PDF} wissen
%			 wollten",
%	  publisher =    "Thomas Merz Verlag",
%	  year =         "1996",
%	  address =      "M{\"u}nchen",
%	  edition =      "1",
%	  ISBN =         "3-9804943-0-6",
%	}
%	@Book{Merz:PostscriptAcrobatBible,
%	  author =       "Thomas Merz",
%	  title =        "PostScript & acrobat/{PDF}: applications,
%                	 troubleshooting, and cross-platform publishing",
%	  publisher =    "Springer",
%	  year =         "1997",
%	  address =      "Berlin",
%	  ISBN =         "3-540-60854-0",
%	}
%
% The original code can be found in file ps/eps/gitter.ps on the CD which
% accompanies the German edition.
% The original code is copyright (C) Thomas Merz 1994-96.
% Incorporation of the original code into this file is with permission of
% Thomas Merz.
% For further information about the book see http://www.pdflib.com/
%
% This file is built so it can be used both as the header file for
% PostScript and as the configuration file for dvips.
% (Note that dvips ignores any lines beginning with a space or a "%".)
%
% Copyright (C) 1995-2006 by Volker Kuhlmann.
% Released under the terms of the GNU General Public License (GPL) Version 2.
% See http://www.gnu.org/ for details.
%
% Volker Kuhlmann <VolkerKuhlmann@gmx.de>
%   25, 26 Oct 1997; 25 Jan 1998; 9 Mar 2000; 11 May 2006
%
 /dr@wgrid {
 
 save
 25 dict begin
 
 % Dirty way of getting a mm grid:
 %1 72 mul 25.4 div   dup scale
 
 % usable units:
 /mm {25.4 div 72 mul} bind def
 
 /gridunit  1 mm def		% the grid unit, in PostScript points
 /step      5 def		% grid line increment, in grid units
 /medstep  10 def		% solid grid lines every this many grid units
 /numstep  20 def		% numbered grid lines every this many grid units
 
 /FontSize 10 def		% font size of numbers
 
 /numstepunit numstep gridunit mul def
 
 %initgraphics % don't use - can stuff things up and is not necessary
 newpath 0 setlinecap 0 setlinejoin 10 setmiterlimit
 
 clippath pathbbox newpath
 cvi /ury exch def
 cvi /urx exch def
 % This seems to be designed to ensure llx,lly are a little too big.
 % Unfortunately, a lly of -0.19 becomes -10, doing bad things to the grid
 % position (i.e. it's totally wrong), with grid units other than 1.
 % -> Use the nearest integer, as for urx, ury.
 %10 div floor 10 mul cvi /lly exch def
 %10 div floor 10 mul cvi /llx exch def
 cvi /lly exch def
 cvi /llx exch def
 urx llx sub /lenx exch def
 ury lly sub /leny exch def
 
 /snaptopixel {
     transform
 	.25 sub round .25 add exch
 	.25 sub round .25 add exch
     itransform
 } bind def
 
 0.01 setlinewidth
 [1 2] 0 setdash		% dashed line
 0 setgray
 /set-line-style {
     dup gridunit div round cvi medstep mod 0 eq { [ ] 0 setdash } if
     dup gridunit div round cvi numstep mod 0 eq { 0.4 setlinewidth } if
     dup gridunit div round cvi 0 eq { 0.6 setlinewidth } if
 } bind def
 
 llx  step gridunit mul  urx { %  draw vertical lines
     gsave
     set-line-style
     lly snaptopixel moveto 0 leny snaptopixel rlineto stroke
     grestore
 } for
 
 lly  step gridunit mul  ury { % draw horizontal lines
     gsave
     set-line-style
     llx exch snaptopixel moveto lenx 0 snaptopixel rlineto stroke
     grestore
 } for
 
 % circle at (0,0)
 [ ] 0 setdash 1 setlinewidth newpath 15 0 moveto 0 0 15 0 360 arc stroke
 
 /kreis { % clip light circle from existing lines
     gsave 1 setgray
     %/d (500) stringwidth pop def
     dup stringwidth pop /d exch def % adjust circle size to string width
     currentpoint FontSize 3 div add exch d 2 div add exch
     d 0.6 mul 0 360 arc
     fill grestore
 } def
 
 % axes labelling font
 /Helvetica-Bold findfont FontSize scalefont setfont
 0.5 setgray
 
 % print axis labelling, X
 llx numstepunit div floor numstepunit mul cvi
 numstepunit
 urx
 { % for
     dup 0 eq
     {
       pop
     }{
       dup 20 moveto
       gridunit div round cvi
       (      ) cvs dup stringwidth pop 2 div neg 0 rmoveto
       kreis show
     } ifelse
 } bind for
 
 % print axis labelling, Y
 lly numstepunit div floor numstepunit mul cvi
 numstepunit
 ury 
 { % for
     dup 0 eq
     {
       pop
     }{
       40 1 index moveto
       gridunit div round cvi
       (      ) cvs dup stringwidth pop 
       neg 3 sub FontSize 3 div neg rmoveto
       kreis show
     } ifelse
 } bind for
 
 end restore
 
 } bind def  % dr@wgrid
 
 % %% Hook into dvips-generated PS
 % at start of page:
 %/bop-hook where
 %	{
 %	  pop
 %	  /@ldbophookgrid /bop-hook load def
 %	  /bop-hook { @ldbophookgrid dr@wgrid } def
 %	}{
 %	  /bop-hook { dr@wgrid } def
 %	} ifelse
 % at end of page:
 /eop-hook where
 	{
 	  pop
 	  /@ldeophookgrid /eop-hook load def
 	  /eop-hook { @ldeophookgrid dr@wgrid } def
 	}{
 	  /eop-hook { dr@wgrid } def
 	} ifelse
%
 { % start a procedure so PostScript `ignores' the dvips configuration part.
h config.mmgrid
 } pop % PostScript cleanup
%
% EOF config.mmgrid