// Project 2 for CMSC 838P // Charles B. Cranston xxx-yy-zzzz // May 19, 1997 // Facility to print PostScript which is larger than a single page. // Drawing commands are stored up in a PostScript procedure which is // then played back multiple times, once for each physical page. // Note: code from example on pages 182-185 of Adobe "Blue Book" with // slight mods for arbitrary print rectangle and to eliminate variables. class PSOutFile { public: PSOutFile(ostream &stream, int pagewide, int leftmarg, int ritemarg, int pagehite, int toppmarg, int bottmarg): os(stream) { writeheader(leftmarg,bottmarg, pagewide-leftmarg-ritemarg, pagehite-toppmarg-bottmarg); } PSOutFile(ostream &stream, int imleft, int imbott, int imwide, int imhite): os(stream) { writeheader(imleft,imbott,imwide,imhite); } inline void beginjob() { // Start saving os << "{\n"; drawleft = drawbott = 0; drawwide = drawhite = -1; } inline void drawname(int hp, int vp, string *s) { os << hp << ' ' << vp << " moveto(" << *s << ")show\n"; drawarea(hp,vp-5,96,15); } inline void drawline(int h1, int v1, int h2, int v2) { os< drawwide) { drawleft = newleft; drawbott = newbott; drawwide = newwide; drawhite = newhite; } else { int drawrite = drawleft + drawwide; int drawtopp = drawbott + drawhite; int newrite = newleft + newwide; int newtopp = newbott + newhite; if (drawleft > newleft) drawleft = newleft; if (drawbott > newbott) drawbott = newbott; if (drawrite < newrite) drawrite = newrite; if (drawtopp < newtopp) drawtopp = newtopp; drawwide = drawrite - drawleft; drawhite = drawtopp - drawbott; } } void endjob() { if (0 >= drawwide) drawwide = 1; if (0 >= drawhite) drawhite = 1; endjob(drawleft,drawbott,drawwide,drawhite); } void endjob(int prleft, int prbott, int prwide, int prhite) { os << "} bind\n" << prleft << ' ' << prbott << ' ' << prwide << ' ' << prhite << '\n' << "5 index exec\n"; } protected: void writeheader(int imleft, int imbott, int imwide, int imhite) { os << "%!PS-Adobe\n" << imleft << ' ' << imbott << ' ' << imwide << ' ' << imhite << '\n' << "{\n" << "gsave\n" << "9 index 4 index sub\n" << "9 index 8 index add 4 index 3 index add sub translate\n" << "dup 1 sub 7 index idiv\n" << "0 1 4 index 1 sub 11 index idiv\n" << "{\n" << "pop\n" << "gsave\n" << "0 1 2 index\n" << "{\n" << "pop\n" << "5 index gsave exec grestore\n" << "gsave showpage grestore\n" << "0 8 index translate\n" << "} for\n" << "grestore\n" << "8 index neg 0 translate\n" << "} for\n" << "6{pop}repeat\n" << "grestore\n" << "} bind\n" << "/Helvetica findfont 10 scalefont setfont\n"; } ostream &os; // has-a output stream int drawleft; // Left side of computed draw rectangle int drawbott; // Bottom of computed draw rectangle int drawwide; // Width of computed draw rectangle int drawhite; // Height of computed draw rectangle }; // End of PSOutFile.h