Added the scanning of command line arguments.
[account.git] / postscript.h
1
2 #include <iostream>
3 #include <exception>
4 #include <libps/pslib.h>
5
6 // Exception class to handle runtime errors
7
8 class psexception : public std::exception
9 {
10 public:
11   virtual const char* what() const throw()
12   {
13     return "PostScript error";
14   }
15
16 };
17
18 // A Postscript document as used in pslib
19
20 extern bool postscript_started;
21
22 class PostScript
23 {
24    PSDoc *psdoc;
25    int   psfont;
26    int   page;
27
28 public:
29
30    PostScript(const char * filename)
31    {
32       if (!postscript_started)
33       {
34          PS_boot();
35          postscript_started = true;
36       }
37       psdoc = PS_new();
38       if (PS_open_file(psdoc, filename) == -1)
39       {
40          throw psexception();
41       }
42       //PS_set_info(psdoc, "BoundingBox", "0 0 842 596");
43       PS_set_parameter(psdoc, "SearchPath", "/usr/local/share/afm");
44       PS_set_parameter(psdoc, "SearchPath", "/usr/lib/openoffice/basis3.1/share/psprint/fontmetric");
45       PS_set_parameter(psdoc, "SearchPath", "/usr/lib/openoffice/basis3.2/share/psprint/fontmetric");
46       psfont = PS_findfont(psdoc, "Courier", NULL, 0);
47       if (psfont == 0)
48       {
49          throw psexception();
50       }
51       page = 0;
52    }
53
54    ~PostScript()
55    {
56       if (page != 0)
57       {
58          PS_end_page(psdoc);
59       }
60       PS_close(psdoc);
61       PS_delete(psdoc);
62    }
63
64    void NewPage(float page_width, float page_height)
65    {
66       if (page != 0)
67       {
68          PS_end_page(psdoc);
69       }
70       if (page_width > page_height)
71       {
72          PS_begin_page(psdoc, page_height, page_width);
73          //  Rotate for landscape.
74
75          PS_translate(psdoc, 600, 0);
76          PS_rotate(psdoc, 90);
77       }
78       else
79       {
80          PS_begin_page(psdoc, page_width, page_height);
81       }
82       page++;
83       PS_setfont(psdoc, psfont, 10.0);
84    }
85
86    void FontSize(float size)
87    {
88       PS_setfont(psdoc, psfont, size);
89    }
90
91    void LineAttributes(float width, float dash_on, float dash_off)
92    {
93       PS_setlinewidth(psdoc, width);
94       PS_setdash(psdoc, dash_on, dash_off);
95    }
96
97    void Line(float x1, float y1, float x2, float y2)
98    {
99       PS_moveto(psdoc, x1, y1);
100       PS_lineto(psdoc, x2, y2);
101       PS_stroke(psdoc);
102    }
103
104    void Rectangle(float x, float y, float width, float height)
105    {
106       PS_setcolor(psdoc, "fill", "rgb", 0.8, 1.0, 0.8, 0.0);
107       PS_rect(psdoc, x, y, width, height);
108       PS_fill(psdoc);
109    }
110
111    void Text(float x, float y, const char * text)
112    {
113       PS_show_xy(psdoc, text, x, y);
114    }
115 };