chiark / gitweb /
merge into history old stuff found on chiark
[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     "%%Trailer\n"
29     "%%EOF\n";
30 }
31
32 void PostScriptOutput::drawcell(const Point* list, int n, Colour colour) {
33   Onscreen p[n];
34   for (int i=0; i<n; i++) p[i]= Onscreen(list[i]);
35   switch (colour) {
36   case grid:
37     docell(p,n,"1 setgray fill");
38     docell(p,n,"0 setgray stroke");
39     break;
40   case solidwhite:
41     docell(p,n,"1 setgray fill");
42     break;
43   case solidblack:
44     docell(p,n,"0 setgray fill");
45     break;
46   default:
47     abort();
48   }
49 }
50
51 void PostScriptOutput::docell(const Onscreen* list, int n, const char *what) {
52   file << "    newpath\n";
53   file << "        " << list->x << " " << list->y << " moveto\n";
54   list++;
55   for (int i=1; i<n; i++, list++) {
56     file << "        " << list->x << " " << list->y << " lineto\n";
57   }
58   file << "      closepath  " << what << "\n";
59 }