1 /**
2  *  Yudit Unicode Editor Source File
3  *
4  *  GNU Copyright (C) 1997-2006  Gaspar Sinai <gaspar@yudit.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License, version 2,
8  *  dated June 1991. See file COPYYING for details.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef SPostscript_h
21 #define SPostscript_h
22 
23 #include "swindow/SCanvas.h"
24 
25 #include "stoolkit/SExcept.h"
26 #include "stoolkit/SString.h"
27 #include "stoolkit/SProperties.h"
28 #include "stoolkit/SIOStream.h"
29 #include "stoolkit/SMatrix.h"
30 #include "stoolkit/SEvent.h"
31 
32 /**
33  * @author: Gaspar Sinai <gaspar@yudit.org>
34  * @version: 2000-04-23
35  * This is a postscript renderer for yudit.
36  */
37 class SPostscript : public SCanvas, public SEventTarget
38 {
39 public:
40   enum SMedia { A3, A4, A5, B4, B5, Executive, Folio, Ledger,
41                 Legal, Letter, Quarto, Statement, Tabloid  };
42   enum SOrientation { PORTRAIT, LANDSCAPE };
43   SPostscript (const SWriter& w, SMedia m, SOrientation o);
44   virtual ~SPostscript();
45 
46   /* maybe we should move these to canvas */
47   unsigned int getWidth() const;
48   unsigned int getHeight() const;
49   int getX() const;
50   int getY() const;
51 
52   bool open (bool background);
53   void newPage();
54   bool cacheOn (bool on=true);
55   bool close ();
56   bool hasNative () const;
57 
58   /* From SCanvas */
59   virtual bool beginImage (double x, double y, const SString& id, const SColor& background);
60   virtual void newpath ();
61   virtual void endImage ();
62   virtual void fill (const SPen& pen);
63   virtual void stroke (const SPen& pen);
64 
65   virtual void moveto (double x, double y);
66   virtual void lineto (double x, double y);
67   virtual void curveto (double x0, double y0, double x1,
68           double y1, double x3, double y3);
69   virtual void closepath();
70   virtual void pushmatrix();
71   virtual void popmatrix();
72   virtual void scale (double x, double y);
73   virtual void translate (double x, double y);
74   virtual void rotate (double angle);
75   virtual void bitfont (const SPen& pen, double x, double y,
76        void* native, char* data, unsigned int len);
77   virtual void bitfill (const SColor& bg, int x, int y, unsigned int width, unsigned int height);
78   virtual void bitline (const SColor& fg, int x, int y, int tox, int toy);
79   virtual void bitpoint (const SColor& fg, int x, int y);
80   virtual void bitpoints (const SColor& fg, const int* x, const int* y,
81          unsigned int size);
82   SString getCreationDate() const;
83 
84   /* for background */
85   bool timeout (const SEventSource* s);
86 
87 private:
88   void            fill ();
89   unsigned int    ticks;
90   STimer*         timer;
91   virtual bool _beginImage (double x, double y, const SString& id);
92   bool   writeString (const SString& str);
93   bool   isUgly;
94 
95   unsigned int    pages;
96   unsigned int    currentPage;
97   SS_MatrixStack  matrix;
98   SMedia          media;
99   SOrientation    orientation;
100   bool            status;
101 
102   unsigned int  width;
103   unsigned int  height;
104   unsigned int  widthMargin;
105   unsigned int  heightMargin;
106 
107   SWriter       out;
108 
109   SProperties   cache;
110   SProperties   cacheIDMap;
111   unsigned int  cacheIDMapCount;
112   SString       cacheID;
113   SString       cacheCurrent;
114   double        cacheOriginX;
115   double        cacheOriginY;
116   SString       creationDate;
117 };
118 
119 #endif /* SPostscript_h */
120