/* * postscript interface */ #include "config.h" #include #include "interface.h" #include "ps_int.h" static const char ps_prolog[] = "%!PS-Adobe-2.0\n" "%%Creator: " PACKAGE " version " VERSION "\n" "%%BeginProlog\n" "\n" "/rm { rmoveto } bind def\n" "/rl { rlineto } bind def\n" "/m { moveto } bind def\n" "/l { lineto } bind def\n" "/s { stroke } bind def\n" "/w { setlinewidth } bind def\n" "\n" "/beginpage\n" " {\n" " clippath\n" " pathbbox /py2 exch def /px2 exch def /py1 exch def /px1 exch def\n" " /pw px2 px1 sub def /ph py2 py1 sub def\n" " } bind def\n" "\n" "/endpage\n" " {\n" " showpage\n" " } bind def\n" "\n" "/beginfig\n" " {\n" " /fy2 exch def /fx2 exch def /fy1 exch def /fx1 exch def\n" " /fw fx2 fx1 sub def /fh fy2 fy1 sub def\n" " px1 fx1 pw fw div mul sub py1 fy1 ph fh div mul sub translate\n" " pw fw div ph fh div scale\n" "% pw fw sub 0.5 mul ph fh sub 0.5 mul translate\n" " newpath 0 0 moveto\n" " } bind def\n" "\n" "/endfig\n" " {\n" " s\n" " } bind def\n" "\n" "/bp\n" " {\n" " gsave newpath\n" " } bind def\n" "\n" "/ep\n" " {\n" " closepath\n" " fill\n" " grestore\n" " } bind def\n" "\n" "%%EndProlog\n" ; static const char ps_epilog[] = "%%Pages: 1\n" "%%EOF\n" ; ps_int::ps_int (ostream &out) t_no : o(out) { o << ps_prolog; } ps_int::~ps_int () t_no { o << ps_epilog; } void ps_int::begin_fig () t_no { x1 = 1e10; x2 = -x1; y1 = 1e10; y2 = -y1; last_pos = vec(0,0,0); o << "%%Page:\n" << "beginpage\n"; fig = new ostringstream; } void ps_int::end_fig () t_no { o << x1-10 << " " << y1-10 << " " << x2+10 << " " << y2+10 << " beginfig\n"; o << fig->str (); delete fig; o << "endfig\n" << "endpage\n" << "%%EndPage:\n"; } void ps_int::clip (const vec &v) t_no { if (x1 > v[0]) x1 = v[0]; if (y1 > v[1]) y1 = v[1]; if (x2 < v[0]) x2 = v[0]; if (y2 < v[1]) y2 = v[1]; } void ps_int::check_attrs (const attribute_set &attr) t_err { *fig << "s 0 0 m\n"; last_pos = vec(0,0,0); *fig << attr("width", 1) << " w\n"; } void ps_int::segment (const point &a, const point &b) t_err { check_attrs (a.attr); if (last_pos[0] != a.v[0] || last_pos[1] != a.v[1]) { clip (a.v); *fig << a.v[0]-last_pos[0] << " " << a.v[1]-last_pos[1] << " rm\n"; } clip (b.v); *fig << b.v[0]-a.v[0] << " " << b.v[1]-a.v[1] << " rl\n"; last_pos = b.v; } void ps_int::object (const points &v) t_err { char moveline = 'm'; check_attrs (v.front().attr); *fig << "bp "; for(points::const_iterator i = v.begin (); i != v.end(); ++i) { clip (i->v); *fig << i->v[0] << " " << i->v[1] << " " << moveline << " "; moveline = 'l'; } *fig << "ep\n"; }