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
|
-- ps.lua
-- lua interface to postscript
-- Luiz Henrique de Figueiredo (lhf@csg.uwaterloo.ca)
-- 14 May 96
PS={}
function P(x)
write(x.."\n")
end
-------------------------------------------------------------------- control --
function PS.open(title)
if title==nil then title="(no title)" end
P("%!PS-Adobe-2.0 EPSF-1.2")
P("%%Title: "..title)
P("%%Creator: ps.lua from Lua 2.4")
P("%%CreationDate: "..date())
P("%%Pages: (atend)")
P("%%BoundingBox: (atend)")
P("%%EndComments")
P("%%BeginProcSet: ps.lua")
P("/s { stroke } bind def")
P("/f { fill } bind def")
P("/m { moveto } bind def")
P("/l { lineto } bind def")
P("/L { moveto lineto stroke } bind def")
P("/t { show } bind def")
P("/o { 0 360 arc stroke } bind def")
P("/O { 0 360 arc fill } bind def")
P("/p { 3 0 360 arc fil } bind def")
P("/F { findfont exch scalefont setfont } bind def")
P("/LS { 0 setdash } bind def")
P("/LW { setlinewidth } bind def")
P("%%EndProcSet: ps.lua")
P("%%EndProlog")
P("%%BeginSetup")
P("0 setlinewidth")
P("1 setlinejoin")
P("1 setlinecap")
P("10 /Times-Roman F")
P("%%EndSetup\n")
P("%%Page: 1 1")
-- cxmin=dv.xmin; cxmax=dv.xmax; cymin=dv.ymin; cymax=dv.ymax
xmin=1000; xmax=-1000; ymin=1000; ymax=-1000
page=1
end
function PS.close()
P("stroke")
P("showpage")
P("%%Trailer")
P("%%Pages: "..page)
P("%%BoundingBox: "..xmin.." "..ymin.." "..xmax.." "..ymax)
P("%%EOF")
end
function PS.clear()
if (empty) then return end
page=page+1
P("showpage")
P("%%Page: "..page.." "..page)
empty=1
end
function PS.comment(s)
P("% "..s)
end
--------------------------------------------------------------- direct color --
function PS.rgbcolor(r,g,b)
P(r.." "..g.." "..b.." setrgbcolor")
end
function PS.gray(g)
P(g.." setgray")
end
---------------------------------------------------------------- named color --
function PS.color(c)
P("C"..c)
end
function PS.defrgbcolor(c,r,g,b)
P("/C"..c.." { "..r.." "..g.." "..b.." setrgbcolor } def")
end
function PS.defgraycolor(c,g)
P("/C"..c.." { "..g.." setgray } def")
end
----------------------------------------------------------------------- line --
function PS.line(x1,y1,x2,y2)
P(x2.." "..y2.." "..x1.." "..y1.." L")
PS.update(x1,y1)
PS.update(x2,y2)
end
function PS.moveto(x,y)
P(x.." "..y.." m")
PS.update(x,y)
end
function PS.lineto(x,y)
P(x.." "..y.." l")
PS.update(x,y)
end
function PS.linewidth(w)
P(w.." LW")
end
function PS.linestyle(s)
P("["..s.."] LS")
end
----------------------------------------------------------------------- text --
function PS.font(name,size)
if (size==nil) then size=10 end
P(size.." /"..name.." F")
end
function PS.text(x,y,s)
P(x.." "..y.."m ("..s..") t")
PS.update(x,y)
end
--------------------------------------------------------------------- circle --
function PS.circle(x,y,r)
P(x.." "..y.." "..r.." o")
PS.update(x-r,y-r)
PS.update(x+r,y+r)
end
function PS.disk(x,y,r)
P(x.." "..y.." "..r.." O")
PS.update(x-r,y-r)
PS.update(x+r,y+r)
end
function PS.dot(x,y)
P(x.." "..y.." p")
PS.update(x-r,y-r)
PS.update(x+r,y+r)
end
------------------------------------------------------------------------ box --
function PS.rectangle(xmin,xmax,ymin,ymax)
P(xmin.." "..ymin.." m "..
xmax.." "..ymin.." l "..
xmax.." "..ymax.." l "..
xmin.." "..ymax.." l s")
PS.update(xmin,ymin)
PS.update(xmax,ymax)
end
function PS.box(xmin,xmax,ymin,ymax)
P(xmin.." "..ymin.." m "..
xmax.." "..ymin.." l "..
xmax.." "..ymax.." l "..
xmin.." "..ymax.." l f")
PS.update(xmin,ymin)
PS.update(xmax,ymax)
end
-------------------------------------------------------- update bounding box --
function PS.update(x,y)
-- if (x>=cxmin and x<=cxmax and y>=cxmin and y<=cxmax) then
if (x<xmin) then xmin=x elseif (x>xmax) then xmax=x end
if (y<ymin) then ymin=y elseif (y>ymax) then ymax=y end
empty=0
-- end
end
|