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