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