alpar@2391
|
1 |
/* -*- C++ -*-
|
alpar@2391
|
2 |
*
|
alpar@2391
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@2391
|
4 |
*
|
alpar@2391
|
5 |
* Copyright (C) 2003-2007
|
alpar@2391
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@2391
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@2391
|
8 |
*
|
alpar@2391
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@2391
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@2391
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@2391
|
12 |
*
|
alpar@2391
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@2391
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@2391
|
15 |
* purpose.
|
alpar@2391
|
16 |
*
|
alpar@2391
|
17 |
*/
|
alpar@2391
|
18 |
|
ladanyi@2013
|
19 |
#include <lemon/eps.h>
|
alpar@1971
|
20 |
|
alpar@1971
|
21 |
namespace lemon {
|
alpar@1971
|
22 |
|
alpar@1971
|
23 |
void EpsDrawer::defMacros()
|
alpar@1971
|
24 |
{
|
alpar@1971
|
25 |
out << "/clmode true def\n" <<
|
alpar@1971
|
26 |
"/cshowmode false def\n" <<
|
alpar@1971
|
27 |
"/defont (Helvetica) findfont def\n" <<
|
alpar@1971
|
28 |
"/fosi 12 def\n" <<
|
alpar@1971
|
29 |
"\n" <<
|
alpar@1971
|
30 |
"/st { clmode { currentpoint stroke newpath moveto } if } bind def\n" <<
|
alpar@1971
|
31 |
"/str { currentpoint stroke newpath moveto /clmode true def } bind def\n"
|
alpar@1971
|
32 |
<<
|
alpar@1971
|
33 |
"/fl { currentpoint fill newpath moveto /clmode true def } bind def\n" <<
|
alpar@1971
|
34 |
"/eofl { currentpoint eofill newpath moveto /clmode true def } bind def\n"
|
alpar@1971
|
35 |
<<
|
alpar@1971
|
36 |
"/cl { currentpoint clip newpath moveto /clmode true def } bind def\n"
|
alpar@1971
|
37 |
<<
|
alpar@1971
|
38 |
"/eocl { currentpoint eoclip newpath moveto /clmode true def } bind def\n"
|
alpar@1971
|
39 |
<<
|
alpar@1971
|
40 |
"\n" <<
|
alpar@1971
|
41 |
"/l { moveto lineto st } bind def\n" <<
|
alpar@1971
|
42 |
"/lt { lineto st } bind def\n" <<
|
alpar@1971
|
43 |
"/mt { moveto } bind def\n" <<
|
alpar@1971
|
44 |
"/c { dup 3 index add 2 index moveto 0 360 arc st } bind def\n" <<
|
alpar@1971
|
45 |
"/collect { /clmode false def currentpoint newpath moveto } bind def\n" <<
|
alpar@1971
|
46 |
"\n" <<
|
alpar@1971
|
47 |
"/fontset { defont fosi scalefont setfont } bind def\n" <<
|
alpar@1971
|
48 |
"/stfs { /fosi exch def fontset } bind def\n" <<
|
alpar@1971
|
49 |
"/cshow { dup stringwidth pop\n" <<
|
alpar@1971
|
50 |
" neg 2 div 0 rmoveto show } bind def\n" <<
|
alpar@1971
|
51 |
"/xshow { cshowmode { cshow } { show } ifelse } def\n" <<
|
alpar@1971
|
52 |
"\n" <<
|
alpar@1971
|
53 |
"fontset\n" <<
|
alpar@1971
|
54 |
"newpath\n" <<
|
alpar@1971
|
55 |
"0 0 moveto\n" <<
|
alpar@1971
|
56 |
"1 setlinecap\n";
|
alpar@1971
|
57 |
}
|
alpar@1971
|
58 |
|
alpar@1971
|
59 |
void EpsDrawer::init(int x1,int y1,int x2,int y2)
|
alpar@1971
|
60 |
{
|
alpar@1971
|
61 |
out << "%!PS-Adobe-2.0 EPSF-2.0\n" <<
|
alpar@1971
|
62 |
"%%BoundingBox: " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
|
alpar@1971
|
63 |
"\n%%EndComments\n";
|
alpar@1971
|
64 |
defMacros();
|
alpar@1971
|
65 |
}
|
alpar@1971
|
66 |
|
alpar@1971
|
67 |
void EpsDrawer::init(double x1,double y1,double x2,double y2)
|
alpar@1971
|
68 |
{
|
alpar@1971
|
69 |
out << "%!PS-Adobe-2.0\n" <<
|
alpar@1971
|
70 |
"%%HiResBoundingBox: " <<
|
alpar@1971
|
71 |
x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
|
alpar@1971
|
72 |
"\n%%EndComments\n";
|
alpar@1971
|
73 |
defMacros();
|
alpar@1971
|
74 |
}
|
alpar@1971
|
75 |
|
alpar@1971
|
76 |
|
alpar@1971
|
77 |
EpsDrawer::EpsDrawer(std::ostream &os,int x,int y) : local_stream(false),
|
alpar@1971
|
78 |
out(os)
|
alpar@1971
|
79 |
{
|
alpar@1971
|
80 |
init(0,0,x,y);
|
alpar@1971
|
81 |
}
|
alpar@1971
|
82 |
|
alpar@1971
|
83 |
EpsDrawer::EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2) :
|
alpar@1971
|
84 |
local_stream(false),
|
alpar@1971
|
85 |
out(os)
|
alpar@1971
|
86 |
{
|
alpar@1971
|
87 |
init(x1,y1,x2,y2);
|
alpar@1971
|
88 |
}
|
alpar@1971
|
89 |
|
alpar@2207
|
90 |
EpsDrawer::EpsDrawer(std::ostream &os,dim2::Point<double> s) : local_stream(false),
|
alpar@1971
|
91 |
out(os)
|
alpar@1971
|
92 |
{
|
alpar@1971
|
93 |
init(0.0,0.0,s.x,s.y);
|
alpar@1971
|
94 |
}
|
alpar@1971
|
95 |
|
alpar@2207
|
96 |
EpsDrawer::EpsDrawer(std::ostream &os,dim2::Point<double> a, dim2::Point<double> b) :
|
alpar@1971
|
97 |
local_stream(false),
|
alpar@1971
|
98 |
out(os)
|
alpar@1971
|
99 |
{
|
alpar@1971
|
100 |
init(a.x,a.y,b.x,b.y);
|
alpar@1971
|
101 |
}
|
alpar@1971
|
102 |
|
alpar@1971
|
103 |
|
alpar@1971
|
104 |
EpsDrawer::EpsDrawer(const std::string &name,int x,int y) :
|
alpar@1971
|
105 |
local_stream(true),
|
alpar@1971
|
106 |
out(*new std::ofstream(name.c_str()))
|
alpar@1971
|
107 |
{
|
alpar@1971
|
108 |
init(0,0,x,y);
|
alpar@1971
|
109 |
}
|
alpar@1971
|
110 |
|
alpar@1971
|
111 |
EpsDrawer::EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2) :
|
alpar@1971
|
112 |
local_stream(true),
|
alpar@1971
|
113 |
out(*new std::ofstream(name.c_str()))
|
alpar@1971
|
114 |
{
|
alpar@1971
|
115 |
init(x1,y1,x2,y2);
|
alpar@1971
|
116 |
}
|
alpar@1971
|
117 |
|
alpar@2207
|
118 |
EpsDrawer::EpsDrawer(const std::string &name,dim2::Point<double> s) :
|
alpar@1971
|
119 |
local_stream(true),
|
alpar@1971
|
120 |
out(*new std::ofstream(name.c_str()))
|
alpar@1971
|
121 |
{
|
alpar@1971
|
122 |
init(0.0,0.0,s.x,s.y);
|
alpar@1971
|
123 |
}
|
alpar@1971
|
124 |
|
alpar@2207
|
125 |
EpsDrawer::EpsDrawer(const std::string &name,dim2::Point<double> a, dim2::Point<double> b) :
|
alpar@1971
|
126 |
local_stream(true),
|
alpar@1971
|
127 |
out(*new std::ofstream(name.c_str()))
|
alpar@1971
|
128 |
{
|
alpar@1971
|
129 |
init(a.x,a.y,b.x,b.y);
|
alpar@1971
|
130 |
}
|
alpar@1971
|
131 |
|
alpar@1971
|
132 |
|
alpar@1971
|
133 |
EpsDrawer::~EpsDrawer()
|
alpar@1971
|
134 |
{
|
alpar@1971
|
135 |
out << "showpage\n";
|
alpar@1971
|
136 |
if(local_stream) delete &out;
|
alpar@1971
|
137 |
}
|
alpar@1971
|
138 |
|
alpar@1971
|
139 |
EpsDrawer &EpsDrawer::save()
|
alpar@1971
|
140 |
{
|
alpar@1971
|
141 |
out << "gsave\n";
|
alpar@1971
|
142 |
return *this;
|
alpar@1971
|
143 |
}
|
alpar@1971
|
144 |
|
alpar@1971
|
145 |
EpsDrawer &EpsDrawer::restore()
|
alpar@1971
|
146 |
{
|
alpar@1971
|
147 |
out << "grestore\n";
|
alpar@1971
|
148 |
return *this;
|
alpar@1971
|
149 |
}
|
alpar@1971
|
150 |
|
alpar@1971
|
151 |
EpsDrawer &EpsDrawer::line(double x1,double y1,double x2,double y2)
|
alpar@1971
|
152 |
{
|
alpar@1971
|
153 |
out << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << " l\n";
|
alpar@1971
|
154 |
return *this;
|
alpar@1971
|
155 |
|
alpar@1971
|
156 |
}
|
alpar@1971
|
157 |
|
alpar@1971
|
158 |
EpsDrawer &EpsDrawer::lineTo(double x1,double y1)
|
alpar@1971
|
159 |
{
|
alpar@1971
|
160 |
out << x1 << ' ' << y1 << " lt\n";
|
alpar@1971
|
161 |
return *this;
|
alpar@1971
|
162 |
|
alpar@1971
|
163 |
}
|
alpar@1971
|
164 |
|
alpar@1971
|
165 |
EpsDrawer &EpsDrawer::moveTo(double x1,double y1)
|
alpar@1971
|
166 |
{
|
alpar@1971
|
167 |
out << x1 << ' ' << y1 << " mt\n";
|
alpar@1971
|
168 |
return *this;
|
alpar@1971
|
169 |
}
|
alpar@1971
|
170 |
|
alpar@1971
|
171 |
EpsDrawer &EpsDrawer::circle(double x,double y, double r)
|
alpar@1971
|
172 |
{
|
alpar@1971
|
173 |
out << x << ' ' << y << ' ' << r << " c\n";
|
alpar@1971
|
174 |
return *this;
|
alpar@1971
|
175 |
}
|
alpar@1971
|
176 |
|
alpar@1971
|
177 |
EpsDrawer &EpsDrawer::operator<<(const std::string &s)
|
alpar@1971
|
178 |
{
|
alpar@1971
|
179 |
out << "(" << s <<") xshow\n";
|
alpar@1971
|
180 |
return *this;
|
alpar@1971
|
181 |
}
|
alpar@1971
|
182 |
|
alpar@1971
|
183 |
EpsDrawer &EpsDrawer::operator<<(const char *s)
|
alpar@1971
|
184 |
{
|
alpar@1971
|
185 |
out << "(" << s <<") xshow\n";
|
alpar@1971
|
186 |
return *this;
|
alpar@1971
|
187 |
}
|
alpar@1971
|
188 |
|
alpar@1971
|
189 |
EpsDrawer &EpsDrawer::operator<<(int i)
|
alpar@1971
|
190 |
{
|
alpar@1971
|
191 |
out << "(" << i <<") xshow\n";
|
alpar@1971
|
192 |
return *this;
|
alpar@1971
|
193 |
}
|
alpar@1971
|
194 |
|
alpar@1971
|
195 |
EpsDrawer &EpsDrawer::operator<<(double d)
|
alpar@1971
|
196 |
{
|
alpar@1971
|
197 |
out << "(" << d <<") xshow\n";
|
alpar@1971
|
198 |
return *this;
|
alpar@1971
|
199 |
}
|
alpar@1971
|
200 |
|
alpar@1971
|
201 |
EpsDrawer &EpsDrawer::fontSize(double si)
|
alpar@1971
|
202 |
{
|
alpar@1971
|
203 |
out << si << " stfs\n";
|
alpar@1971
|
204 |
return *this;
|
alpar@1971
|
205 |
}
|
alpar@1971
|
206 |
EpsDrawer &EpsDrawer::font(std::string s)
|
alpar@1971
|
207 |
{
|
alpar@1971
|
208 |
out << "/defont ("<<s<<") findfont def fontset\n";
|
alpar@1971
|
209 |
return *this;
|
alpar@1971
|
210 |
}
|
alpar@1971
|
211 |
|
alpar@1971
|
212 |
|
alpar@1971
|
213 |
EpsDrawer &EpsDrawer::collect()
|
alpar@1971
|
214 |
{
|
alpar@1971
|
215 |
out << "collect\n";
|
alpar@1971
|
216 |
return *this;
|
alpar@1971
|
217 |
}
|
alpar@1971
|
218 |
|
alpar@1971
|
219 |
EpsDrawer &EpsDrawer::closePath()
|
alpar@1971
|
220 |
{
|
alpar@1971
|
221 |
out << "closepath\n";
|
alpar@1971
|
222 |
return *this;
|
alpar@1971
|
223 |
}
|
alpar@1971
|
224 |
|
alpar@1971
|
225 |
EpsDrawer &EpsDrawer::stroke()
|
alpar@1971
|
226 |
{
|
alpar@1971
|
227 |
out << "str\n";
|
alpar@1971
|
228 |
return *this;
|
alpar@1971
|
229 |
}
|
alpar@1971
|
230 |
EpsDrawer &EpsDrawer::fill()
|
alpar@1971
|
231 |
{
|
alpar@1971
|
232 |
out << "fl\n";
|
alpar@1971
|
233 |
return *this;
|
alpar@1971
|
234 |
}
|
alpar@1971
|
235 |
EpsDrawer &EpsDrawer::eoFill()
|
alpar@1971
|
236 |
{
|
alpar@1971
|
237 |
out << "eofl\n";
|
alpar@1971
|
238 |
return *this;
|
alpar@1971
|
239 |
}
|
alpar@1971
|
240 |
EpsDrawer &EpsDrawer::clip()
|
alpar@1971
|
241 |
{
|
alpar@1971
|
242 |
out << "cl\n";
|
alpar@1971
|
243 |
return *this;
|
alpar@1971
|
244 |
}
|
alpar@1971
|
245 |
EpsDrawer &EpsDrawer::eoClip()
|
alpar@1971
|
246 |
{
|
alpar@1971
|
247 |
out << "eocl\n";
|
alpar@1971
|
248 |
return *this;
|
alpar@1971
|
249 |
}
|
alpar@1971
|
250 |
|
alpar@1971
|
251 |
EpsDrawer &EpsDrawer::lineWidth(double w)
|
alpar@1971
|
252 |
{
|
alpar@1971
|
253 |
out << w << " setlinewidth\n";
|
alpar@1971
|
254 |
return *this;
|
alpar@1971
|
255 |
}
|
alpar@1971
|
256 |
|
alpar@1971
|
257 |
EpsDrawer &EpsDrawer::lineCap(int i)
|
alpar@1971
|
258 |
{
|
alpar@1971
|
259 |
out << i << " setlinecap\n";
|
alpar@1971
|
260 |
return *this;
|
alpar@1971
|
261 |
}
|
alpar@1971
|
262 |
|
alpar@1971
|
263 |
EpsDrawer &EpsDrawer::lineJoin(int i)
|
alpar@1971
|
264 |
{
|
alpar@1971
|
265 |
out << i << " setlinejoin\n";
|
alpar@1971
|
266 |
return *this;
|
alpar@1971
|
267 |
}
|
alpar@1971
|
268 |
|
alpar@1971
|
269 |
EpsDrawer &EpsDrawer::miterLimit(double w)
|
alpar@1971
|
270 |
{
|
alpar@1971
|
271 |
out << w << " setmiterlimit\n";
|
alpar@1971
|
272 |
return *this;
|
alpar@1971
|
273 |
}
|
alpar@1971
|
274 |
|
alpar@1971
|
275 |
EpsDrawer &EpsDrawer::color(double r, double g, double b)
|
alpar@1971
|
276 |
{
|
alpar@1971
|
277 |
out << r << ' ' << g << ' ' << b << " setrgbcolor\n";
|
alpar@1971
|
278 |
return *this;
|
alpar@1971
|
279 |
}
|
alpar@1971
|
280 |
|
alpar@1971
|
281 |
EpsDrawer &EpsDrawer::translate(double x,double y)
|
alpar@1971
|
282 |
{
|
alpar@1971
|
283 |
out << x << ' ' << y << " translate\n";
|
alpar@1971
|
284 |
return *this;
|
alpar@1971
|
285 |
}
|
alpar@1971
|
286 |
|
alpar@1971
|
287 |
EpsDrawer &EpsDrawer::rotate(double r)
|
alpar@1971
|
288 |
{
|
alpar@1971
|
289 |
out << r << " rotate\n";
|
alpar@1971
|
290 |
return *this;
|
alpar@1971
|
291 |
}
|
alpar@1971
|
292 |
EpsDrawer &EpsDrawer::scale(double sx, double sy)
|
alpar@1971
|
293 |
{
|
alpar@1971
|
294 |
out << sx << ' ' << sy << " scale\n";
|
alpar@1971
|
295 |
return *this;
|
alpar@1971
|
296 |
}
|
alpar@1971
|
297 |
|
alpar@1971
|
298 |
EpsDrawer &EpsDrawer::clear()
|
alpar@1971
|
299 |
{
|
alpar@1971
|
300 |
out << "erasepage\n";
|
alpar@1971
|
301 |
return *this;
|
alpar@1971
|
302 |
}
|
alpar@1971
|
303 |
|
alpar@1971
|
304 |
EpsDrawer &EpsDrawer::centerMode(bool m)
|
alpar@1971
|
305 |
{
|
alpar@1971
|
306 |
if(m) out << "/cshowmode true def\n";
|
alpar@1971
|
307 |
else out << "/cshowmode false def\n";
|
alpar@1971
|
308 |
|
alpar@1971
|
309 |
return *this;
|
alpar@1971
|
310 |
}
|
alpar@1971
|
311 |
|
alpar@1971
|
312 |
EpsDrawer &EpsDrawer::flush()
|
alpar@1971
|
313 |
{
|
alpar@1971
|
314 |
out << "flush\n";
|
alpar@1971
|
315 |
// fflush(fp);
|
alpar@1971
|
316 |
return *this;
|
alpar@1971
|
317 |
}
|
alpar@1971
|
318 |
|
alpar@2008
|
319 |
EpsDrawer &EpsDrawer::node(NodeShapes t, double x, double y, double r,
|
alpar@2008
|
320 |
Color col, Color brd)
|
alpar@2008
|
321 |
{
|
alpar@2008
|
322 |
out << "gsave\n"
|
alpar@2008
|
323 |
<< brd.red() << ' ' << brd.green() << ' ' << brd.blue()
|
alpar@2008
|
324 |
<< " setrgbcolor\n";
|
alpar@2008
|
325 |
switch(t) {
|
alpar@2008
|
326 |
case CIRCLE:
|
alpar@2008
|
327 |
out << "newpath " << x << ' ' << y << ' ' << r
|
alpar@2008
|
328 |
<< " dup 3 index add 2 index moveto 0 360 arc fill\n";
|
alpar@2008
|
329 |
break;
|
alpar@2008
|
330 |
case SQUARE:
|
alpar@2008
|
331 |
out << "newpath\n"
|
alpar@2008
|
332 |
<< x-r << ' ' << y-r << " moveto\n"
|
alpar@2008
|
333 |
<< x-r << ' ' << y+r << " lineto\n"
|
alpar@2008
|
334 |
<< x+r << ' ' << y+r << " lineto\n"
|
alpar@2008
|
335 |
<< x+r << ' ' << y-r << " lineto closepath fill\n";
|
alpar@2008
|
336 |
break;
|
alpar@2008
|
337 |
case DIAMOND:
|
alpar@2008
|
338 |
out << "newpath\n"
|
alpar@2008
|
339 |
<< x-r << ' ' << y << " moveto\n"
|
alpar@2008
|
340 |
<< x << ' ' << y+r << " lineto\n"
|
alpar@2008
|
341 |
<< x+r << ' ' << y << " lineto\n"
|
alpar@2008
|
342 |
<< x << ' ' << y-r << " lineto closepath fill\n";
|
alpar@2008
|
343 |
break;
|
alpar@2008
|
344 |
case MALE:
|
alpar@2008
|
345 |
break;
|
alpar@2008
|
346 |
case FEMALE:
|
alpar@2008
|
347 |
break;
|
alpar@2008
|
348 |
}
|
alpar@2008
|
349 |
r/=1.1;
|
alpar@2008
|
350 |
out << col.red() << ' ' << col.green() << ' ' << col.blue()
|
alpar@2008
|
351 |
<< " setrgbcolor\n";
|
alpar@2008
|
352 |
switch(t) {
|
alpar@2008
|
353 |
case CIRCLE:
|
alpar@2008
|
354 |
out << "newpath " << x << ' ' << y << ' ' << r
|
alpar@2008
|
355 |
<< " dup 3 index add 2 index moveto 0 360 arc fill\n";
|
alpar@2008
|
356 |
break;
|
alpar@2008
|
357 |
case SQUARE:
|
alpar@2008
|
358 |
out << "newpath\n"
|
alpar@2008
|
359 |
<< x-r << ' ' << y-r << " moveto\n"
|
alpar@2008
|
360 |
<< x-r << ' ' << y+r << " lineto\n"
|
alpar@2008
|
361 |
<< x+r << ' ' << y+r << " lineto\n"
|
alpar@2008
|
362 |
<< x+r << ' ' << y-r << " lineto closepath fill\n";
|
alpar@2008
|
363 |
break;
|
alpar@2008
|
364 |
case DIAMOND:
|
alpar@2008
|
365 |
out << "newpath\n"
|
alpar@2008
|
366 |
<< x-r << ' ' << y << " moveto\n"
|
alpar@2008
|
367 |
<< x << ' ' << y+r << " lineto\n"
|
alpar@2008
|
368 |
<< x+r << ' ' << y << " lineto\n"
|
alpar@2008
|
369 |
<< x << ' ' << y-r << " lineto closepath fill\n";
|
alpar@2008
|
370 |
break;
|
alpar@2008
|
371 |
case MALE:
|
alpar@2008
|
372 |
break;
|
alpar@2008
|
373 |
case FEMALE:
|
alpar@2008
|
374 |
break;
|
alpar@2008
|
375 |
}
|
alpar@2008
|
376 |
|
alpar@2008
|
377 |
out << "grestore\n";
|
alpar@2008
|
378 |
return *this;
|
alpar@2008
|
379 |
}
|
alpar@2008
|
380 |
|
alpar@1971
|
381 |
}
|