chiark / gitweb /
found in ijackson@chiark:things/moebius.old-before-cvs
[moebius.git] / postscript.cc
1 /*
2  * PostScript output
3  */
4
5 #include <iostream.h>
6 #include "postscript.hh"
7
8 PostScriptOutput::PostScriptOutput(ofstream& f)
9 : file(f) {
10
11   file <<
12     "%!PS-Adobe-2.0 EPSF-2.0\n"
13     "%%Creator: moebius\n"
14     "%%BoundingBox: -500 -500 500 500\n"
15     "%%Pages: 1\n"
16     "%%DocumentFonts: \n"
17     "%%EndComments\n"
18     "    1 setlinecap 1 setlinejoin 0.002 setlinewidth\n"
19     "    500 500 scale\n"
20     "%%EndProlog\n"
21     "%%Page: 1 0\n"
22     "    save\n";
23 }
24
25 PostScriptOutput::~PostScriptOutput() {
26   file <<
27     "    restore\n"
28     "    showpage\n"
29     "%%Trailer\n"
30     "%%EOF\n";
31 }
32
33 void PostScriptOutput::drawcell(const Point* list, int n) {
34   Onscreen p[n];
35   for (int i=0; i<n; i++) p[i]= Onscreen(list[i]);
36   docell(p,n,"1 setgray fill");
37   docell(p,n,"0 setgray stroke");
38 }
39
40 void PostScriptOutput::docell(const Onscreen* list, int n, const char *what) {
41   file << "    newpath\n";
42   file << "        " << list->x << " " << list->y << " moveto\n";
43   list++;
44   for (int i=1; i<n; i++, list++) {
45     file << "        " << list->x << " " << list->y << " lineto\n";
46   }
47   file << "      closepath  " << what << "\n";
48 }