5 void EpsDrawer::defMacros()
7 out << "/clmode true def\n" <<
8 "/cshowmode false def\n" <<
9 "/defont (Helvetica) findfont def\n" <<
12 "/st { clmode { currentpoint stroke newpath moveto } if } bind def\n" <<
13 "/str { currentpoint stroke newpath moveto /clmode true def } bind def\n"
15 "/fl { currentpoint fill newpath moveto /clmode true def } bind def\n" <<
16 "/eofl { currentpoint eofill newpath moveto /clmode true def } bind def\n"
18 "/cl { currentpoint clip newpath moveto /clmode true def } bind def\n"
20 "/eocl { currentpoint eoclip newpath moveto /clmode true def } bind def\n"
23 "/l { moveto lineto st } bind def\n" <<
24 "/lt { lineto st } bind def\n" <<
25 "/mt { moveto } bind def\n" <<
26 "/c { dup 3 index add 2 index moveto 0 360 arc st } bind def\n" <<
27 "/collect { /clmode false def currentpoint newpath moveto } bind def\n" <<
29 "/fontset { defont fosi scalefont setfont } bind def\n" <<
30 "/stfs { /fosi exch def fontset } bind def\n" <<
31 "/cshow { dup stringwidth pop\n" <<
32 " neg 2 div 0 rmoveto show } bind def\n" <<
33 "/xshow { cshowmode { cshow } { show } ifelse } def\n" <<
41 void EpsDrawer::init(int x1,int y1,int x2,int y2)
43 out << "%!PS-Adobe-2.0 EPSF-2.0\n" <<
44 "%%BoundingBox: " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
49 void EpsDrawer::init(double x1,double y1,double x2,double y2)
51 out << "%!PS-Adobe-2.0\n" <<
52 "%%HiResBoundingBox: " <<
53 x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
59 EpsDrawer::EpsDrawer(std::ostream &os,int x,int y) : local_stream(false),
65 EpsDrawer::EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2) :
72 EpsDrawer::EpsDrawer(std::ostream &os,xy<double> s) : local_stream(false),
75 init(0.0,0.0,s.x,s.y);
78 EpsDrawer::EpsDrawer(std::ostream &os,xy<double> a, xy<double> b) :
82 init(a.x,a.y,b.x,b.y);
86 EpsDrawer::EpsDrawer(const std::string &name,int x,int y) :
88 out(*new std::ofstream(name.c_str()))
93 EpsDrawer::EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2) :
95 out(*new std::ofstream(name.c_str()))
100 EpsDrawer::EpsDrawer(const std::string &name,xy<double> s) :
102 out(*new std::ofstream(name.c_str()))
104 init(0.0,0.0,s.x,s.y);
107 EpsDrawer::EpsDrawer(const std::string &name,xy<double> a, xy<double> b) :
109 out(*new std::ofstream(name.c_str()))
111 init(a.x,a.y,b.x,b.y);
115 EpsDrawer::~EpsDrawer()
118 if(local_stream) delete &out;
121 EpsDrawer &EpsDrawer::save()
127 EpsDrawer &EpsDrawer::restore()
133 EpsDrawer &EpsDrawer::line(double x1,double y1,double x2,double y2)
135 out << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << " l\n";
140 EpsDrawer &EpsDrawer::lineTo(double x1,double y1)
142 out << x1 << ' ' << y1 << " lt\n";
147 EpsDrawer &EpsDrawer::moveTo(double x1,double y1)
149 out << x1 << ' ' << y1 << " mt\n";
153 EpsDrawer &EpsDrawer::circle(double x,double y, double r)
155 out << x << ' ' << y << ' ' << r << " c\n";
159 EpsDrawer &EpsDrawer::operator<<(const std::string &s)
161 out << "(" << s <<") xshow\n";
165 EpsDrawer &EpsDrawer::operator<<(const char *s)
167 out << "(" << s <<") xshow\n";
171 EpsDrawer &EpsDrawer::operator<<(int i)
173 out << "(" << i <<") xshow\n";
177 EpsDrawer &EpsDrawer::operator<<(double d)
179 out << "(" << d <<") xshow\n";
183 EpsDrawer &EpsDrawer::fontSize(double si)
185 out << si << " stfs\n";
188 EpsDrawer &EpsDrawer::font(std::string s)
190 out << "/defont ("<<s<<") findfont def fontset\n";
195 EpsDrawer &EpsDrawer::collect()
201 EpsDrawer &EpsDrawer::closePath()
203 out << "closepath\n";
207 EpsDrawer &EpsDrawer::stroke()
212 EpsDrawer &EpsDrawer::fill()
217 EpsDrawer &EpsDrawer::eoFill()
222 EpsDrawer &EpsDrawer::clip()
227 EpsDrawer &EpsDrawer::eoClip()
233 EpsDrawer &EpsDrawer::lineWidth(double w)
235 out << w << " setlinewidth\n";
239 EpsDrawer &EpsDrawer::lineCap(int i)
241 out << i << " setlinecap\n";
245 EpsDrawer &EpsDrawer::lineJoin(int i)
247 out << i << " setlinejoin\n";
251 EpsDrawer &EpsDrawer::miterLimit(double w)
253 out << w << " setmiterlimit\n";
257 EpsDrawer &EpsDrawer::color(double r, double g, double b)
259 out << r << ' ' << g << ' ' << b << " setrgbcolor\n";
263 EpsDrawer &EpsDrawer::translate(double x,double y)
265 out << x << ' ' << y << " translate\n";
269 EpsDrawer &EpsDrawer::rotate(double r)
271 out << r << " rotate\n";
274 EpsDrawer &EpsDrawer::scale(double sx, double sy)
276 out << sx << ' ' << sy << " scale\n";
280 EpsDrawer &EpsDrawer::clear()
282 out << "erasepage\n";
286 EpsDrawer &EpsDrawer::centerMode(bool m)
288 if(m) out << "/cshowmode true def\n";
289 else out << "/cshowmode false def\n";
294 EpsDrawer &EpsDrawer::flush()
301 EpsDrawer &EpsDrawer::node(NodeShapes t, double x, double y, double r,
302 Color col, Color brd)
305 << brd.red() << ' ' << brd.green() << ' ' << brd.blue()
309 out << "newpath " << x << ' ' << y << ' ' << r
310 << " dup 3 index add 2 index moveto 0 360 arc fill\n";
314 << x-r << ' ' << y-r << " moveto\n"
315 << x-r << ' ' << y+r << " lineto\n"
316 << x+r << ' ' << y+r << " lineto\n"
317 << x+r << ' ' << y-r << " lineto closepath fill\n";
321 << x-r << ' ' << y << " moveto\n"
322 << x << ' ' << y+r << " lineto\n"
323 << x+r << ' ' << y << " lineto\n"
324 << x << ' ' << y-r << " lineto closepath fill\n";
332 out << col.red() << ' ' << col.green() << ' ' << col.blue()
336 out << "newpath " << x << ' ' << y << ' ' << r
337 << " dup 3 index add 2 index moveto 0 360 arc fill\n";
341 << x-r << ' ' << y-r << " moveto\n"
342 << x-r << ' ' << y+r << " lineto\n"
343 << x+r << ' ' << y+r << " lineto\n"
344 << x+r << ' ' << y-r << " lineto closepath fill\n";
348 << x-r << ' ' << y << " moveto\n"
349 << x << ' ' << y+r << " lineto\n"
350 << x+r << ' ' << y << " lineto\n"
351 << x << ' ' << y-r << " lineto closepath fill\n";