1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/lemon/eps.cc Mon Feb 20 06:41:12 2006 +0000
1.3 @@ -0,0 +1,301 @@
1.4 +#include <eps.h>
1.5 +
1.6 +namespace lemon {
1.7 +
1.8 + void EpsDrawer::defMacros()
1.9 + {
1.10 + out << "/clmode true def\n" <<
1.11 + "/cshowmode false def\n" <<
1.12 + "/defont (Helvetica) findfont def\n" <<
1.13 + "/fosi 12 def\n" <<
1.14 + "\n" <<
1.15 + "/st { clmode { currentpoint stroke newpath moveto } if } bind def\n" <<
1.16 + "/str { currentpoint stroke newpath moveto /clmode true def } bind def\n"
1.17 + <<
1.18 + "/fl { currentpoint fill newpath moveto /clmode true def } bind def\n" <<
1.19 + "/eofl { currentpoint eofill newpath moveto /clmode true def } bind def\n"
1.20 + <<
1.21 + "/cl { currentpoint clip newpath moveto /clmode true def } bind def\n"
1.22 + <<
1.23 + "/eocl { currentpoint eoclip newpath moveto /clmode true def } bind def\n"
1.24 + <<
1.25 + "\n" <<
1.26 + "/l { moveto lineto st } bind def\n" <<
1.27 + "/lt { lineto st } bind def\n" <<
1.28 + "/mt { moveto } bind def\n" <<
1.29 + "/c { dup 3 index add 2 index moveto 0 360 arc st } bind def\n" <<
1.30 + "/collect { /clmode false def currentpoint newpath moveto } bind def\n" <<
1.31 + "\n" <<
1.32 + "/fontset { defont fosi scalefont setfont } bind def\n" <<
1.33 + "/stfs { /fosi exch def fontset } bind def\n" <<
1.34 + "/cshow { dup stringwidth pop\n" <<
1.35 + " neg 2 div 0 rmoveto show } bind def\n" <<
1.36 + "/xshow { cshowmode { cshow } { show } ifelse } def\n" <<
1.37 + "\n" <<
1.38 + "fontset\n" <<
1.39 + "newpath\n" <<
1.40 + "0 0 moveto\n" <<
1.41 + "1 setlinecap\n";
1.42 + }
1.43 +
1.44 + void EpsDrawer::init(int x1,int y1,int x2,int y2)
1.45 + {
1.46 + out << "%!PS-Adobe-2.0 EPSF-2.0\n" <<
1.47 + "%%BoundingBox: " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
1.48 + "\n%%EndComments\n";
1.49 + defMacros();
1.50 + }
1.51 +
1.52 + void EpsDrawer::init(double x1,double y1,double x2,double y2)
1.53 + {
1.54 + out << "%!PS-Adobe-2.0\n" <<
1.55 + "%%HiResBoundingBox: " <<
1.56 + x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
1.57 + "\n%%EndComments\n";
1.58 + defMacros();
1.59 + }
1.60 +
1.61 +
1.62 + EpsDrawer::EpsDrawer(std::ostream &os,int x,int y) : local_stream(false),
1.63 + out(os)
1.64 + {
1.65 + init(0,0,x,y);
1.66 + }
1.67 +
1.68 + EpsDrawer::EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2) :
1.69 + local_stream(false),
1.70 + out(os)
1.71 + {
1.72 + init(x1,y1,x2,y2);
1.73 + }
1.74 +
1.75 + EpsDrawer::EpsDrawer(std::ostream &os,xy<double> s) : local_stream(false),
1.76 + out(os)
1.77 + {
1.78 + init(0.0,0.0,s.x,s.y);
1.79 + }
1.80 +
1.81 + EpsDrawer::EpsDrawer(std::ostream &os,xy<double> a, xy<double> b) :
1.82 + local_stream(false),
1.83 + out(os)
1.84 + {
1.85 + init(a.x,a.y,b.x,b.y);
1.86 + }
1.87 +
1.88 +
1.89 + EpsDrawer::EpsDrawer(const std::string &name,int x,int y) :
1.90 + local_stream(true),
1.91 + out(*new std::ofstream(name.c_str()))
1.92 + {
1.93 + init(0,0,x,y);
1.94 + }
1.95 +
1.96 + EpsDrawer::EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2) :
1.97 + local_stream(true),
1.98 + out(*new std::ofstream(name.c_str()))
1.99 + {
1.100 + init(x1,y1,x2,y2);
1.101 + }
1.102 +
1.103 + EpsDrawer::EpsDrawer(const std::string &name,xy<double> s) :
1.104 + local_stream(true),
1.105 + out(*new std::ofstream(name.c_str()))
1.106 + {
1.107 + init(0.0,0.0,s.x,s.y);
1.108 + }
1.109 +
1.110 + EpsDrawer::EpsDrawer(const std::string &name,xy<double> a, xy<double> b) :
1.111 + local_stream(true),
1.112 + out(*new std::ofstream(name.c_str()))
1.113 + {
1.114 + init(a.x,a.y,b.x,b.y);
1.115 + }
1.116 +
1.117 +
1.118 + EpsDrawer::~EpsDrawer()
1.119 + {
1.120 + out << "showpage\n";
1.121 + if(local_stream) delete &out;
1.122 + }
1.123 +
1.124 + EpsDrawer &EpsDrawer::save()
1.125 + {
1.126 + out << "gsave\n";
1.127 + return *this;
1.128 + }
1.129 +
1.130 + EpsDrawer &EpsDrawer::restore()
1.131 + {
1.132 + out << "grestore\n";
1.133 + return *this;
1.134 + }
1.135 +
1.136 + EpsDrawer &EpsDrawer::line(double x1,double y1,double x2,double y2)
1.137 + {
1.138 + out << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << " l\n";
1.139 + return *this;
1.140 +
1.141 + }
1.142 +
1.143 + EpsDrawer &EpsDrawer::lineTo(double x1,double y1)
1.144 + {
1.145 + out << x1 << ' ' << y1 << " lt\n";
1.146 + return *this;
1.147 +
1.148 + }
1.149 +
1.150 + EpsDrawer &EpsDrawer::moveTo(double x1,double y1)
1.151 + {
1.152 + out << x1 << ' ' << y1 << " mt\n";
1.153 + return *this;
1.154 + }
1.155 +
1.156 + EpsDrawer &EpsDrawer::circle(double x,double y, double r)
1.157 + {
1.158 + out << x << ' ' << y << ' ' << r << " c\n";
1.159 + return *this;
1.160 + }
1.161 +
1.162 + EpsDrawer &EpsDrawer::operator<<(const std::string &s)
1.163 + {
1.164 + out << "(" << s <<") xshow\n";
1.165 + return *this;
1.166 + }
1.167 +
1.168 + EpsDrawer &EpsDrawer::operator<<(const char *s)
1.169 + {
1.170 + out << "(" << s <<") xshow\n";
1.171 + return *this;
1.172 + }
1.173 +
1.174 + EpsDrawer &EpsDrawer::operator<<(int i)
1.175 + {
1.176 + out << "(" << i <<") xshow\n";
1.177 + return *this;
1.178 + }
1.179 +
1.180 + EpsDrawer &EpsDrawer::operator<<(double d)
1.181 + {
1.182 + out << "(" << d <<") xshow\n";
1.183 + return *this;
1.184 + }
1.185 +
1.186 + EpsDrawer &EpsDrawer::fontSize(double si)
1.187 + {
1.188 + out << si << " stfs\n";
1.189 + return *this;
1.190 + }
1.191 + EpsDrawer &EpsDrawer::font(std::string s)
1.192 + {
1.193 + out << "/defont ("<<s<<") findfont def fontset\n";
1.194 + return *this;
1.195 + }
1.196 +
1.197 +
1.198 + EpsDrawer &EpsDrawer::collect()
1.199 + {
1.200 + out << "collect\n";
1.201 + return *this;
1.202 + }
1.203 +
1.204 + EpsDrawer &EpsDrawer::closePath()
1.205 + {
1.206 + out << "closepath\n";
1.207 + return *this;
1.208 + }
1.209 +
1.210 + EpsDrawer &EpsDrawer::stroke()
1.211 + {
1.212 + out << "str\n";
1.213 + return *this;
1.214 + }
1.215 + EpsDrawer &EpsDrawer::fill()
1.216 + {
1.217 + out << "fl\n";
1.218 + return *this;
1.219 + }
1.220 + EpsDrawer &EpsDrawer::eoFill()
1.221 + {
1.222 + out << "eofl\n";
1.223 + return *this;
1.224 + }
1.225 + EpsDrawer &EpsDrawer::clip()
1.226 + {
1.227 + out << "cl\n";
1.228 + return *this;
1.229 + }
1.230 + EpsDrawer &EpsDrawer::eoClip()
1.231 + {
1.232 + out << "eocl\n";
1.233 + return *this;
1.234 + }
1.235 +
1.236 + EpsDrawer &EpsDrawer::lineWidth(double w)
1.237 + {
1.238 + out << w << " setlinewidth\n";
1.239 + return *this;
1.240 + }
1.241 +
1.242 + EpsDrawer &EpsDrawer::lineCap(int i)
1.243 + {
1.244 + out << i << " setlinecap\n";
1.245 + return *this;
1.246 + }
1.247 +
1.248 + EpsDrawer &EpsDrawer::lineJoin(int i)
1.249 + {
1.250 + out << i << " setlinejoin\n";
1.251 + return *this;
1.252 + }
1.253 +
1.254 + EpsDrawer &EpsDrawer::miterLimit(double w)
1.255 + {
1.256 + out << w << " setmiterlimit\n";
1.257 + return *this;
1.258 + }
1.259 +
1.260 + EpsDrawer &EpsDrawer::color(double r, double g, double b)
1.261 + {
1.262 + out << r << ' ' << g << ' ' << b << " setrgbcolor\n";
1.263 + return *this;
1.264 + }
1.265 +
1.266 + EpsDrawer &EpsDrawer::translate(double x,double y)
1.267 + {
1.268 + out << x << ' ' << y << " translate\n";
1.269 + return *this;
1.270 + }
1.271 +
1.272 + EpsDrawer &EpsDrawer::rotate(double r)
1.273 + {
1.274 + out << r << " rotate\n";
1.275 + return *this;
1.276 + }
1.277 + EpsDrawer &EpsDrawer::scale(double sx, double sy)
1.278 + {
1.279 + out << sx << ' ' << sy << " scale\n";
1.280 + return *this;
1.281 + }
1.282 +
1.283 + EpsDrawer &EpsDrawer::clear()
1.284 + {
1.285 + out << "erasepage\n";
1.286 + return *this;
1.287 + }
1.288 +
1.289 + EpsDrawer &EpsDrawer::centerMode(bool m)
1.290 + {
1.291 + if(m) out << "/cshowmode true def\n";
1.292 + else out << "/cshowmode false def\n";
1.293 +
1.294 + return *this;
1.295 + }
1.296 +
1.297 + EpsDrawer &EpsDrawer::flush()
1.298 + {
1.299 + out << "flush\n";
1.300 + // fflush(fp);
1.301 + return *this;
1.302 + }
1.303 +
1.304 +}