summaryrefslogtreecommitdiff
path: root/sys/src/cmd/postscript/postmd/postmd.ps
blob: 6a5661e2c9a0dfa31180c9a95e1425b8ffe0ec35 (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
%
% Version 3.3.2 prologue for matrix display files.
%

/#copies 1 store
/aspectratio 1 def
/font /Helvetica def
/formsperpage 1 def
/landscape false def
/magnification 1 def
/margin 10 def
/orientation 0 def
/rotation 1 def
/size 9 def
/statspace 1.6 def
/ticklength .06 def
/tickspacing 10 def
/xoffset 0 def
/yoffset 0 def

/useclippath true def
/pagebbox [0 0 612 792] def

/inch {72 mul} bind def
/min {2 copy gt {exch} if pop} bind def

/show {show} bind def		% so later references don't bind
/stringwidth {stringwidth} bind def

/setup {
	counttomark 2 idiv {def} repeat pop

	landscape {/orientation 90 orientation add def} if

	pagedimensions
	height width lt {
		/statspace statspace height width div mul def
		/size size height width div mul def
		/ticklength ticklength height width div mul def
	} if
	/height height margin sub statspace inch sub ticklength inch sub size 6 mul sub def
	/width width margin sub ticklength inch sub def
	xcenter ycenter translate
	orientation rotation mul rotate
	xoffset inch yoffset inch translate
	0 height 2 div height width min 2 div sub translate
	0 statspace inch 2 div translate
	magnification dup aspectratio mul scale

	0 setlinewidth
} def

/pagedimensions {
	useclippath {
		/pagebbox [clippath pathbbox newpath] def
	} if
	pagebbox aload pop
	4 -1 roll exch 4 1 roll 4 copy
	landscape {4 2 roll} if
	sub /width exch def
	sub /height exch def
	add 2 div /xcenter exch def
	add 2 div /ycenter exch def
	userdict /gotpagebbox true put
} def

/pagesetup {/page exch def} bind def

/bitmap {
	/scanlines exch def
	/scanlength exch def

	/picstr scanlength string def

	gsave
	height scanlines div width scanlength div min
	/scaling exch def
	scaling scaling scale

	scanlength neg 2 div scanlines neg 2 div translate
	scanlength scanlines scale
	getbitmap
	grestore
} bind def

/getbitmap {
	scanlength scanlines 8 [scanlength 0 0 scanlines neg 0 scanlines] {
		0 {
			currentfile token pop dup
			0 eq {pop pop exit} if
			/charcount exch def
			picstr 1 index charcount getinterval
			/repl exch def
			currentfile repl readhexstring pop pop
			charcount add
			currentfile token pop {
				picstr 1 index repl putinterval
				charcount add
			} repeat
		} loop
		picstr
	} image
} bind def

/labelmatrix {
	/matrixlimits exch def
	/matrixname exch def

	gsave
	scaling scaling scale
	font findfont size scaling div scalefont setfont
	scanlength neg 2 div scanlines 2 div translate

	0 scanlines size 1.5 mul scaling div add neg moveto
	matrixname show

	scanlength scanlines size 1.5 mul scaling div add neg moveto
	matrixlimits stringwidth pop neg 0 rmoveto
	matrixlimits show

	newpath
	0 0 moveto
	scanlength 0 rlineto
	0 scanlines neg rlineto
	scanlength neg 0 rlineto
	closepath stroke

	scanlength tickspacing idiv 1 add tickspacing 0 ticks
	scanlines tickspacing idiv 1 add 0 tickspacing neg ticks
	grestore
} bind def

/ticks {
	/dy exch def
	/dx exch def

	/tl ticklength inch scaling div def
	newpath
	0 0 moveto
	{
		gsave dx 0 eq {tl neg 0} {0 tl} ifelse rlineto stroke grestore
		dx dy rmoveto
	} repeat
} bind def

/legend {
	/regions exch def
	/total exch def

	gsave
	width height min 2 div neg dup size 2 mul sub translate
	0 statspace inch neg translate

	gsave
	regions {
		gsave
		total div statspace inch size 2 mul sub mul size 2 mul add
		width height min regions div exch scale
		1 1 8 [1 0 0 1 0 0] 5 -1 roll image
		grestore
		width height min regions div 0 translate
	} repeat
	grestore

	width height min size 1.5 mul neg translate
	font findfont size scalefont setfont
	dup dup add 1 add width height min exch div /interval exch def
	{
    		interval neg 0 translate
		interval 2 div neg 0 translate
    		dup stringwidth pop 2 div neg 0 moveto show
		interval 2 div neg 0 translate
	} repeat
	grestore
} bind def

/done {/lastpage where {pop lastpage} if} def