diff -r bd88ea06ab69 -r 9a59a6cacfd9 lemon/eps.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/eps.cc Mon Feb 20 06:41:12 2006 +0000 @@ -0,0 +1,301 @@ +#include + +namespace lemon { + + void EpsDrawer::defMacros() + { + out << "/clmode true def\n" << + "/cshowmode false def\n" << + "/defont (Helvetica) findfont def\n" << + "/fosi 12 def\n" << + "\n" << + "/st { clmode { currentpoint stroke newpath moveto } if } bind def\n" << + "/str { currentpoint stroke newpath moveto /clmode true def } bind def\n" + << + "/fl { currentpoint fill newpath moveto /clmode true def } bind def\n" << + "/eofl { currentpoint eofill newpath moveto /clmode true def } bind def\n" + << + "/cl { currentpoint clip newpath moveto /clmode true def } bind def\n" + << + "/eocl { currentpoint eoclip newpath moveto /clmode true def } bind def\n" + << + "\n" << + "/l { moveto lineto st } bind def\n" << + "/lt { lineto st } bind def\n" << + "/mt { moveto } bind def\n" << + "/c { dup 3 index add 2 index moveto 0 360 arc st } bind def\n" << + "/collect { /clmode false def currentpoint newpath moveto } bind def\n" << + "\n" << + "/fontset { defont fosi scalefont setfont } bind def\n" << + "/stfs { /fosi exch def fontset } bind def\n" << + "/cshow { dup stringwidth pop\n" << + " neg 2 div 0 rmoveto show } bind def\n" << + "/xshow { cshowmode { cshow } { show } ifelse } def\n" << + "\n" << + "fontset\n" << + "newpath\n" << + "0 0 moveto\n" << + "1 setlinecap\n"; + } + + void EpsDrawer::init(int x1,int y1,int x2,int y2) + { + out << "%!PS-Adobe-2.0 EPSF-2.0\n" << + "%%BoundingBox: " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << + "\n%%EndComments\n"; + defMacros(); + } + + void EpsDrawer::init(double x1,double y1,double x2,double y2) + { + out << "%!PS-Adobe-2.0\n" << + "%%HiResBoundingBox: " << + x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << + "\n%%EndComments\n"; + defMacros(); + } + + + EpsDrawer::EpsDrawer(std::ostream &os,int x,int y) : local_stream(false), + out(os) + { + init(0,0,x,y); + } + + EpsDrawer::EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2) : + local_stream(false), + out(os) + { + init(x1,y1,x2,y2); + } + + EpsDrawer::EpsDrawer(std::ostream &os,xy s) : local_stream(false), + out(os) + { + init(0.0,0.0,s.x,s.y); + } + + EpsDrawer::EpsDrawer(std::ostream &os,xy a, xy b) : + local_stream(false), + out(os) + { + init(a.x,a.y,b.x,b.y); + } + + + EpsDrawer::EpsDrawer(const std::string &name,int x,int y) : + local_stream(true), + out(*new std::ofstream(name.c_str())) + { + init(0,0,x,y); + } + + EpsDrawer::EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2) : + local_stream(true), + out(*new std::ofstream(name.c_str())) + { + init(x1,y1,x2,y2); + } + + EpsDrawer::EpsDrawer(const std::string &name,xy s) : + local_stream(true), + out(*new std::ofstream(name.c_str())) + { + init(0.0,0.0,s.x,s.y); + } + + EpsDrawer::EpsDrawer(const std::string &name,xy a, xy b) : + local_stream(true), + out(*new std::ofstream(name.c_str())) + { + init(a.x,a.y,b.x,b.y); + } + + + EpsDrawer::~EpsDrawer() + { + out << "showpage\n"; + if(local_stream) delete &out; + } + + EpsDrawer &EpsDrawer::save() + { + out << "gsave\n"; + return *this; + } + + EpsDrawer &EpsDrawer::restore() + { + out << "grestore\n"; + return *this; + } + + EpsDrawer &EpsDrawer::line(double x1,double y1,double x2,double y2) + { + out << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << " l\n"; + return *this; + + } + + EpsDrawer &EpsDrawer::lineTo(double x1,double y1) + { + out << x1 << ' ' << y1 << " lt\n"; + return *this; + + } + + EpsDrawer &EpsDrawer::moveTo(double x1,double y1) + { + out << x1 << ' ' << y1 << " mt\n"; + return *this; + } + + EpsDrawer &EpsDrawer::circle(double x,double y, double r) + { + out << x << ' ' << y << ' ' << r << " c\n"; + return *this; + } + + EpsDrawer &EpsDrawer::operator<<(const std::string &s) + { + out << "(" << s <<") xshow\n"; + return *this; + } + + EpsDrawer &EpsDrawer::operator<<(const char *s) + { + out << "(" << s <<") xshow\n"; + return *this; + } + + EpsDrawer &EpsDrawer::operator<<(int i) + { + out << "(" << i <<") xshow\n"; + return *this; + } + + EpsDrawer &EpsDrawer::operator<<(double d) + { + out << "(" << d <<") xshow\n"; + return *this; + } + + EpsDrawer &EpsDrawer::fontSize(double si) + { + out << si << " stfs\n"; + return *this; + } + EpsDrawer &EpsDrawer::font(std::string s) + { + out << "/defont ("<