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 #include "swindow/SPrinter.h"
21 #include "swindow/SPostscript.h"
22
23 /**
24 * @author: Gaspar Sinai <gaspar@yudit.org>
25 * @version: 2000-04-23
26 * This is a postscript renderer for yudit.
27 */
28
SPrinter(const SWriter & w,SType t,SMedia m,SOrientation o)29 SPrinter::SPrinter (const SWriter& w, SType t, SMedia m, SOrientation o)
30 {
31 delegate = 0;
32 type = t;
33 switch (type)
34 {
35 case POSTSCRIPT:
36 delegate = new SPostscript (w, (SPostscript::SMedia) m,
37 (SPostscript::SOrientation) o);
38 case PCL:
39 case WIN32:
40 break;
41 }
42 }
43
SPrinter(const SPrinter & printer)44 SPrinter::SPrinter (const SPrinter& printer)
45 {
46 delegate = 0;
47 type = printer.type;
48 switch (type)
49 {
50 case POSTSCRIPT:
51 delegate = new SPostscript (*((SPostscript*) (printer.delegate)));
52 break;
53 case PCL:
54 case WIN32:
55 break;
56 }
57 }
58
~SPrinter()59 SPrinter::~SPrinter()
60 {
61 if (delegate) delete delegate;
62 }
63
64 unsigned int
getWidth() const65 SPrinter::getWidth() const
66 {
67 switch (type)
68 {
69 case POSTSCRIPT:
70 return ((SPostscript*) delegate)->getWidth();
71 case PCL:
72 case WIN32:
73 break;
74 }
75 return 0;
76 }
77
78 unsigned int
getHeight() const79 SPrinter::getHeight() const
80 {
81 switch (type)
82 {
83 case POSTSCRIPT:
84 return ((SPostscript*) delegate)->getHeight();
85 case PCL:
86 case WIN32:
87 break;
88 }
89 return 0;
90 }
91
92 /**
93 * return the margin stripped X corner.
94 */
95 int
getX() const96 SPrinter::getX() const
97 {
98 switch (type)
99 {
100 case POSTSCRIPT:
101 return ((SPostscript*) delegate)->getX();
102 case PCL:
103 case WIN32:
104 break;
105 }
106 return 0;
107 }
108
109 /**
110 * return the margin stripped Y corner.
111 */
112 int
getY() const113 SPrinter::getY() const
114 {
115 switch (type)
116 {
117 case POSTSCRIPT:
118 return ((SPostscript*) delegate)->getY();
119 case PCL:
120 case WIN32:
121 break;
122 }
123 return 0;
124 }
125
126 /**
127 * Print out the postscript prolog
128 * This will by default turn on cacheing.
129 */
130 bool
open(bool background)131 SPrinter::open (bool background)
132 {
133 if (delegate) switch (type)
134 {
135 case POSTSCRIPT:
136 return ((SPostscript*) delegate)->open(background);
137 case PCL:
138 case WIN32:
139 break;
140 }
141 return false;
142 }
143
144 void
newPage()145 SPrinter::newPage()
146 {
147 if (delegate) switch (type)
148 {
149 case POSTSCRIPT:
150 ((SPostscript*) delegate)->newPage();
151 break;
152 case PCL:
153 case WIN32:
154 break;
155 }
156 return;
157 }
158
159 bool
cacheOn(bool on)160 SPrinter::cacheOn (bool on)
161 {
162 if (delegate) switch (type)
163 {
164 case POSTSCRIPT:
165 return ((SPostscript*) delegate)->cacheOn (on);
166 case PCL:
167 case WIN32:
168 break;
169 }
170 return false;
171 }
172
173 /**
174 * Print out the ending lines.
175 */
176 bool
close()177 SPrinter::close ()
178 {
179 if (delegate) switch (type)
180 {
181 case POSTSCRIPT:
182 return ((SPostscript*) delegate)->close();
183 break;
184 case PCL:
185 case WIN32:
186 break;
187 }
188 return false;
189 }
190
191 /*
192 * The Printing instructions follow:
193 */
194 bool
beginImage(double x,double y,const SString & id,const SColor & background)195 SPrinter::beginImage (double x, double y, const SString& id, const SColor& background)
196 {
197 if (delegate) return delegate->beginImage (x, y, id, background);
198 return false;
199 }
200 void
endImage()201 SPrinter::endImage ()
202 {
203 if (delegate) delegate->endImage ();
204 }
205
206 void
newpath()207 SPrinter::newpath ()
208 {
209 if (delegate) delegate->newpath ();
210 }
211
212 void
stroke(const SPen & pen)213 SPrinter::stroke (const SPen& pen)
214 {
215 if (delegate) delegate->stroke (pen);
216 }
217
218 void
fill(const SPen & pen)219 SPrinter::fill (const SPen& pen)
220 {
221 if (delegate) delegate->fill (pen);
222 }
223
224 void
moveto(double _x,double _y)225 SPrinter::moveto (double _x, double _y)
226 {
227 if (delegate) delegate->moveto (_x, _y);
228 }
229
230 void
lineto(double _x,double _y)231 SPrinter::lineto (double _x, double _y)
232 {
233 if (delegate) delegate->lineto (_x, _y);
234 }
235
236 void
curveto(double _x0,double _y0,double _x1,double _y1,double _x2,double _y2)237 SPrinter::curveto (double _x0, double _y0, double _x1, double _y1, double _x2, double _y2)
238 {
239 if (delegate) delegate->curveto (_x0, _y0, _x1, _y1, _x2, _y2);
240 }
241
242 void
closepath()243 SPrinter::closepath()
244 {
245 if (delegate) delegate->closepath ();
246 }
247
248
249 void
pushmatrix()250 SPrinter::pushmatrix()
251 {
252 if (delegate) delegate->pushmatrix ();
253 }
254
255 void
popmatrix()256 SPrinter::popmatrix()
257 {
258 if (delegate) delegate->popmatrix ();
259 }
260
261 void
scale(double x,double y)262 SPrinter::scale (double x, double y)
263 {
264 if (delegate) switch (type)
265 {
266 case POSTSCRIPT:
267 ((SPostscript*)delegate)->scale (x, y);
268 break;
269 case PCL:
270 case WIN32:
271 break;
272 }
273 }
274
275 void
translate(double x,double y)276 SPrinter::translate (double x, double y)
277 {
278 if (delegate) delegate->translate (x, y);
279 }
280
281 void
rotate(double angle)282 SPrinter::rotate (double angle)
283 {
284 if (delegate) delegate->rotate (angle);
285 }
286
287 void
bitfont(const SPen & pen,double x,double y,void * native,char * data,unsigned int len)288 SPrinter::bitfont (const SPen& pen, double x, double y,
289 void* native, char* data, unsigned int len)
290 {
291 if (delegate) delegate->bitfont (pen, x, y, native, data, len);
292 }
293
294 /**
295 * Fill a solid rectangle
296 * @param x is the upper left corner
297 * @param y is the upper top corner
298 * @param width is the width of the region to fill
299 * @param height is the height of the region to fill
300 */
301 void
bitfill(const SColor & bg,int x,int y,unsigned int width,unsigned int height)302 SPrinter::bitfill (const SColor& bg, int x, int y,
303 unsigned int width, unsigned int height)
304 {
305 }
306
307 /**
308 * Draw a solid line.
309 * @param x is the starting x point
310 * @param y is the starting y point
311 * @param x is the ending non-exclusive x point
312 * @param y is the ending non-exclusive y point
313 */
314 void
bitline(const SColor & fg,int x,int y,int tox,int toy)315 SPrinter::bitline (const SColor& fg, int x, int y, int tox, int toy)
316 {
317 }
318
319 /**
320 * Draw a solid line.
321 * @param x is the x point
322 * @param y is the y point
323 */
324 void
bitpoint(const SColor & fg,int x,int y)325 SPrinter::bitpoint (const SColor& fg, int x, int y)
326 {
327 if (delegate) delegate->bitpoint (SColor("black"), x, y);
328 }
329
330 void
bitpoints(const SColor & fg,const int * x,const int * y,unsigned int _size)331 SPrinter::bitpoints (const SColor& fg, const int* x, const int* y,
332 unsigned int _size)
333 {
334 if (delegate) delegate->bitpoints (SColor("black"), x, y, _size);
335 }
336
337 void
fill()338 SPrinter::fill ()
339 {
340 if (delegate) delegate->fill (SPen(SColor("black")));
341 }
342
343 void
stroke()344 SPrinter::stroke ()
345 {
346 if (delegate) delegate->stroke (SPen(SColor("black")));
347 }
348
349 SString
getCreationDate() const350 SPrinter::getCreationDate () const
351 {
352 if (delegate) switch (type)
353 {
354 case POSTSCRIPT:
355 return ((SPostscript*)delegate)->getCreationDate ();
356 case PCL:
357 case WIN32:
358 break;
359 }
360 return SString();
361 }
362
363 /**
364 * return true if printed output used native fonts.
365 */
366 bool
hasNative() const367 SPrinter::hasNative() const
368 {
369 if (delegate) switch (type)
370 {
371 case POSTSCRIPT:
372 return ((SPostscript*)delegate)->hasNative ();
373 case PCL:
374 case WIN32:
375 break;
376 }
377 return false;
378 }
379