]> git.saurik.com Git - wxWidgets.git/blob - src/generic/dcpsg.cpp
Patch #949276: Less agresive strings test.
[wxWidgets.git] / src / generic / dcpsg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcpsg.cpp
3 // Purpose: Generic wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dcpsg.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #ifndef WX_PRECOMP
23 #endif // WX_PRECOMP
24
25 #if wxUSE_PRINTING_ARCHITECTURE
26
27 #if wxUSE_POSTSCRIPT
28
29 #include "wx/setup.h"
30
31 #include "wx/dcmemory.h"
32 #include "wx/utils.h"
33 #include "wx/intl.h"
34 #include "wx/app.h"
35 #include "wx/image.h"
36 #include "wx/log.h"
37 #include "wx/generic/dcpsg.h"
38 #include "wx/prntbase.h"
39 #include "wx/paper.h"
40 #include "wx/filefn.h"
41 #if WXWIN_COMPATIBILITY_2_2
42 #include "wx/window.h"
43 #include "wx/printdlg.h"
44 #endif
45
46 #include <math.h>
47
48 #ifdef __WXMSW__
49
50 #ifdef DrawText
51 #undef DrawText
52 #endif
53
54 #ifdef StartDoc
55 #undef StartDoc
56 #endif
57
58 #ifdef GetCharWidth
59 #undef GetCharWidth
60 #endif
61
62 #ifdef FindWindow
63 #undef FindWindow
64 #endif
65
66 #endif
67
68 //-----------------------------------------------------------------------------
69 // start and end of document/page
70 //-----------------------------------------------------------------------------
71
72 static const char *wxPostScriptHeaderConicTo = "\
73 /conicto {\n\
74 /to_y exch def\n\
75 /to_x exch def\n\
76 /conic_cntrl_y exch def\n\
77 /conic_cntrl_x exch def\n\
78 currentpoint\n\
79 /p0_y exch def\n\
80 /p0_x exch def\n\
81 /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\
82 /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\
83 /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\
84 /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\
85 p1_x p1_y p2_x p2_y to_x to_y curveto\n\
86 } bind def\n\
87 ";
88
89 static const char *wxPostScriptHeaderEllipse = "\
90 /ellipsedict 8 dict def\n\
91 ellipsedict /mtrx matrix put\n\
92 /ellipse {\n\
93 ellipsedict begin\n\
94 /endangle exch def\n\
95 /startangle exch def\n\
96 /yrad exch def\n\
97 /xrad exch def\n\
98 /y exch def\n\
99 /x exch def\n\
100 /savematrix mtrx currentmatrix def\n\
101 x y translate\n\
102 xrad yrad scale\n\
103 0 0 1 startangle endangle arc\n\
104 savematrix setmatrix\n\
105 end\n\
106 } def\n\
107 ";
108
109 static const char *wxPostScriptHeaderEllipticArc= "\
110 /ellipticarcdict 8 dict def\n\
111 ellipticarcdict /mtrx matrix put\n\
112 /ellipticarc\n\
113 { ellipticarcdict begin\n\
114 /do_fill exch def\n\
115 /endangle exch def\n\
116 /startangle exch def\n\
117 /yrad exch def\n\
118 /xrad exch def \n\
119 /y exch def\n\
120 /x exch def\n\
121 /savematrix mtrx currentmatrix def\n\
122 x y translate\n\
123 xrad yrad scale\n\
124 do_fill { 0 0 moveto } if\n\
125 0 0 1 startangle endangle arc\n\
126 savematrix setmatrix\n\
127 do_fill { fill }{ stroke } ifelse\n\
128 end\n\
129 } def\n";
130
131 static const char *wxPostScriptHeaderSpline = "\
132 /DrawSplineSection {\n\
133 /y3 exch def\n\
134 /x3 exch def\n\
135 /y2 exch def\n\
136 /x2 exch def\n\
137 /y1 exch def\n\
138 /x1 exch def\n\
139 /xa x1 x2 x1 sub 0.666667 mul add def\n\
140 /ya y1 y2 y1 sub 0.666667 mul add def\n\
141 /xb x3 x2 x3 sub 0.666667 mul add def\n\
142 /yb y3 y2 y3 sub 0.666667 mul add def\n\
143 x1 y1 lineto\n\
144 xa ya xb yb x3 y3 curveto\n\
145 } def\n\
146 ";
147
148 static const char *wxPostScriptHeaderColourImage = "\
149 % define 'colorimage' if it isn't defined\n\
150 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
151 % via xgrab)\n\
152 /colorimage where % do we know about 'colorimage'?\n\
153 { pop } % yes: pop off the 'dict' returned\n\
154 { % no: define one\n\
155 /colortogray { % define an RGB->I function\n\
156 /rgbdata exch store % call input 'rgbdata'\n\
157 rgbdata length 3 idiv\n\
158 /npixls exch store\n\
159 /rgbindx 0 store\n\
160 0 1 npixls 1 sub {\n\
161 grays exch\n\
162 rgbdata rgbindx get 20 mul % Red\n\
163 rgbdata rgbindx 1 add get 32 mul % Green\n\
164 rgbdata rgbindx 2 add get 12 mul % Blue\n\
165 add add 64 idiv % I = .5G + .31R + .18B\n\
166 put\n\
167 /rgbindx rgbindx 3 add store\n\
168 } for\n\
169 grays 0 npixls getinterval\n\
170 } bind def\n\
171 \n\
172 % Utility procedure for colorimage operator.\n\
173 % This procedure takes two procedures off the\n\
174 % stack and merges them into a single procedure.\n\
175 \n\
176 /mergeprocs { % def\n\
177 dup length\n\
178 3 -1 roll\n\
179 dup\n\
180 length\n\
181 dup\n\
182 5 1 roll\n\
183 3 -1 roll\n\
184 add\n\
185 array cvx\n\
186 dup\n\
187 3 -1 roll\n\
188 0 exch\n\
189 putinterval\n\
190 dup\n\
191 4 2 roll\n\
192 putinterval\n\
193 } bind def\n\
194 \n\
195 /colorimage { % def\n\
196 pop pop % remove 'false 3' operands\n\
197 {colortogray} mergeprocs\n\
198 image\n\
199 } bind def\n\
200 } ifelse % end of 'false' case\n\
201 ";
202
203 #if wxUSE_PANGO
204 #else
205 static char wxPostScriptHeaderReencodeISO1[] =
206 "\n/reencodeISO {\n"
207 "dup dup findfont dup length dict begin\n"
208 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
209 "/Encoding ISOLatin1Encoding def\n"
210 "currentdict end definefont\n"
211 "} def\n"
212 "/ISOLatin1Encoding [\n"
213 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
214 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
215 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
216 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
217 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
218 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
219 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
220 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
221 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
222 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
223 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
224 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
225 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
226 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
227 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
228
229 static char wxPostScriptHeaderReencodeISO2[] =
230 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
231 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
232 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
233 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
234 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
235 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
236 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
237 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
238 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
239 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
240 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
241 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
242 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
243 "/yacute/thorn/ydieresis\n"
244 "] def\n\n";
245 #endif
246
247 //-------------------------------------------------------------------------------
248 // wxPostScriptDC
249 //-------------------------------------------------------------------------------
250
251 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC)
252
253 float wxPostScriptDC::ms_PSScaleFactor = 1.0;
254
255 void wxPostScriptDC::SetResolution(int ppi)
256 {
257 ms_PSScaleFactor = (float)ppi / 72.0;
258 }
259
260 int wxPostScriptDC::GetResolution()
261 {
262 return (int)(ms_PSScaleFactor * 72.0);
263 }
264
265 //-------------------------------------------------------------------------------
266
267 wxPostScriptDC::wxPostScriptDC ()
268 {
269 m_pstream = (FILE*) NULL;
270
271 m_currentRed = 0;
272 m_currentGreen = 0;
273 m_currentBlue = 0;
274
275 m_pageNumber = 0;
276
277 m_clipping = FALSE;
278
279 m_underlinePosition = 0.0;
280 m_underlineThickness = 0.0;
281
282 m_signX = 1; // default x-axis left to right
283 m_signY = -1; // default y-axis bottom up -> top down
284 }
285
286 wxPostScriptDC::wxPostScriptDC (const wxPrintData& printData)
287 {
288 m_pstream = (FILE*) NULL;
289
290 m_currentRed = 0;
291 m_currentGreen = 0;
292 m_currentBlue = 0;
293
294 m_pageNumber = 0;
295
296 m_clipping = FALSE;
297
298 m_underlinePosition = 0.0;
299 m_underlineThickness = 0.0;
300
301 m_signX = 1; // default x-axis left to right
302 m_signY = -1; // default y-axis bottom up -> top down
303
304 m_printData = printData;
305
306 m_ok = TRUE;
307 }
308
309 wxPostScriptDC::~wxPostScriptDC ()
310 {
311 if (m_pstream)
312 {
313 fclose( m_pstream );
314 m_pstream = (FILE*) NULL;
315 }
316 }
317
318 #if WXWIN_COMPATIBILITY_2_2
319 bool wxPostScriptDC::Create( const wxString &output, bool interactive, wxWindow *parent )
320 {
321 wxPrintData data;
322 data.SetFilename( output );
323 data.SetPrintMode( wxPRINT_MODE_FILE );
324
325 if (interactive)
326 {
327 wxPrintDialogData ddata( data );
328 wxPrintDialog dialog( parent, &data );
329 dialog.GetPrintDialogData().SetSetupDialog(TRUE);
330 if (dialog.ShowModal() != wxID_OK)
331 {
332 m_ok = FALSE;
333 return FALSE;
334 }
335 data = dialog.GetPrintDialogData().GetPrintData();
336 }
337
338 return TRUE;
339 }
340 #endif
341
342
343 bool wxPostScriptDC::Ok() const
344 {
345 return m_ok;
346 }
347
348 void wxPostScriptDC::DoSetClippingRegion (wxCoord x, wxCoord y, wxCoord w, wxCoord h)
349 {
350 wxCHECK_RET( m_ok , wxT("invalid postscript dc") );
351
352 if (m_clipping) DestroyClippingRegion();
353
354 wxDC::DoSetClippingRegion(x, y, w, h);
355
356 m_clipping = TRUE;
357
358 PsPrintf( wxT("gsave\n newpath\n")
359 wxT("%d %d moveto\n")
360 wxT("%d %d lineto\n")
361 wxT("%d %d lineto\n")
362 wxT("%d %d lineto\n")
363 wxT("closepath clip newpath\n"),
364 LogicalToDeviceX(x), LogicalToDeviceY(y),
365 LogicalToDeviceX(x+w), LogicalToDeviceY(y),
366 LogicalToDeviceX(x+w), LogicalToDeviceY(y+h),
367 LogicalToDeviceX(x), LogicalToDeviceY(y+h) );
368 }
369
370
371 void wxPostScriptDC::DestroyClippingRegion()
372 {
373 wxCHECK_RET( m_ok , wxT("invalid postscript dc") );
374
375 if (m_clipping)
376 {
377 m_clipping = FALSE;
378 PsPrint( "grestore\n" );
379 }
380
381 wxDC::DestroyClippingRegion();
382 }
383
384 void wxPostScriptDC::Clear()
385 {
386 // This should fail silently to avoid unnecessary
387 // asserts
388 // wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
389 }
390
391 bool wxPostScriptDC::DoFloodFill (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour &WXUNUSED(col), int WXUNUSED(style))
392 {
393 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
394 return FALSE;
395 }
396
397 bool wxPostScriptDC::DoGetPixel (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour * WXUNUSED(col)) const
398 {
399 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
400 return FALSE;
401 }
402
403 void wxPostScriptDC::DoCrossHair (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
404 {
405 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
406 }
407
408 void wxPostScriptDC::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
409 {
410 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
411
412 if (m_pen.GetStyle() == wxTRANSPARENT) return;
413
414 SetPen( m_pen );
415
416 PsPrintf( wxT("newpath\n")
417 wxT("%d %d moveto\n")
418 wxT("%d %d lineto\n")
419 wxT("stroke\n"),
420 LogicalToDeviceX(x1), LogicalToDeviceY(y1),
421 LogicalToDeviceX(x2), LogicalToDeviceY (y2) );
422
423 CalcBoundingBox( x1, y1 );
424 CalcBoundingBox( x2, y2 );
425 }
426
427 #define RAD2DEG 57.29577951308
428
429 void wxPostScriptDC::DoDrawArc (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc)
430 {
431 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
432
433 wxCoord dx = x1 - xc;
434 wxCoord dy = y1 - yc;
435 wxCoord radius = (wxCoord) sqrt( (double)(dx*dx+dy*dy) );
436 double alpha1, alpha2;
437
438 if (x1 == x2 && y1 == y2)
439 {
440 alpha1 = 0.0;
441 alpha2 = 360.0;
442 }
443 else if (radius == 0.0)
444 {
445 alpha1 = alpha2 = 0.0;
446 }
447 else
448 {
449 alpha1 = (x1 - xc == 0) ?
450 (y1 - yc < 0) ? 90.0 : -90.0 :
451 -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG;
452 alpha2 = (x2 - xc == 0) ?
453 (y2 - yc < 0) ? 90.0 : -90.0 :
454 -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG;
455 }
456 while (alpha1 <= 0) alpha1 += 360;
457 while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between
458 while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree
459 while (alpha2 > 360) alpha2 -= 360;
460
461 if (m_brush.GetStyle() != wxTRANSPARENT)
462 {
463 SetBrush( m_brush );
464
465 PsPrintf( wxT("newpath\n")
466 wxT("%d %d %d %d %d %d ellipse\n")
467 wxT("%d %d lineto\n")
468 wxT("closepath\n")
469 wxT("fill\n"),
470 LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2,
471 LogicalToDeviceX(xc), LogicalToDeviceY(yc) );
472
473 CalcBoundingBox( xc-radius, yc-radius );
474 CalcBoundingBox( xc+radius, yc+radius );
475 }
476
477 if (m_pen.GetStyle() != wxTRANSPARENT)
478 {
479 SetPen( m_pen );
480
481 PsPrintf( wxT("newpath\n")
482 wxT("%d %d %d %d %d %d ellipse\n")
483 wxT("%d %d lineto\n")
484 wxT("stroke\n")
485 wxT("fill\n"),
486 LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2,
487 LogicalToDeviceX(xc), LogicalToDeviceY(yc) );
488
489 CalcBoundingBox( xc-radius, yc-radius );
490 CalcBoundingBox( xc+radius, yc+radius );
491 }
492 }
493
494 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
495 {
496 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
497
498 if (sa>=360 || sa<=-360) sa=sa-int(sa/360)*360;
499 if (ea>=360 || ea<=-360) ea=ea-int(ea/360)*360;
500 if (sa<0) sa+=360;
501 if (ea<0) ea+=360;
502
503 if (sa==ea)
504 {
505 DrawEllipse(x,y,w,h);
506 return;
507 }
508
509 if (m_brush.GetStyle () != wxTRANSPARENT)
510 {
511 SetBrush( m_brush );
512
513 PsPrintf( wxT("newpath\n")
514 wxT("%d %d %d %d %d %d true ellipticarc\n"),
515 LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2),
516 LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2),
517 (wxCoord)sa, (wxCoord)ea );
518
519 CalcBoundingBox( x ,y );
520 CalcBoundingBox( x+w, y+h );
521 }
522
523 if (m_pen.GetStyle () != wxTRANSPARENT)
524 {
525 SetPen( m_pen );
526
527 PsPrintf( wxT("newpath\n")
528 wxT("%d %d %d %d %d %d false ellipticarc\n"),
529 LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2),
530 LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2),
531 (wxCoord)sa, (wxCoord)ea );
532
533 CalcBoundingBox( x ,y );
534 CalcBoundingBox( x+w, y+h );
535 }
536 }
537
538 void wxPostScriptDC::DoDrawPoint (wxCoord x, wxCoord y)
539 {
540 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
541
542 if (m_pen.GetStyle() == wxTRANSPARENT) return;
543
544 SetPen (m_pen);
545
546 PsPrintf( wxT("newpath\n")
547 wxT("%d %d moveto\n")
548 wxT("%d %d lineto\n")
549 wxT("stroke\n"),
550 LogicalToDeviceX(x), LogicalToDeviceY(y),
551 LogicalToDeviceX(x+1), LogicalToDeviceY(y) );
552
553 CalcBoundingBox( x, y );
554 }
555
556 void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
557 {
558 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
559
560 if (n <= 0) return;
561
562 if (m_brush.GetStyle () != wxTRANSPARENT)
563 {
564 SetBrush( m_brush );
565
566 PsPrint( "newpath\n" );
567
568 wxCoord xx = LogicalToDeviceX(points[0].x + xoffset);
569 wxCoord yy = LogicalToDeviceY(points[0].y + yoffset);
570
571 PsPrintf( wxT("%d %d moveto\n"), xx, yy );
572
573 CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
574
575 for (int i = 1; i < n; i++)
576 {
577 xx = LogicalToDeviceX(points[i].x + xoffset);
578 yy = LogicalToDeviceY(points[i].y + yoffset);
579
580 PsPrintf( wxT("%d %d lineto\n"), xx, yy );
581
582 CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset);
583 }
584
585 PsPrint( (fillStyle == wxODDEVEN_RULE ? "eofill\n" : "fill\n") );
586 }
587
588 if (m_pen.GetStyle () != wxTRANSPARENT)
589 {
590 SetPen( m_pen );
591
592 PsPrint( "newpath\n" );
593
594 wxCoord xx = LogicalToDeviceX(points[0].x + xoffset);
595 wxCoord yy = LogicalToDeviceY(points[0].y + yoffset);
596
597 PsPrintf( wxT("%d %d moveto\n"), xx, yy );
598
599 CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
600
601 for (int i = 1; i < n; i++)
602 {
603 xx = LogicalToDeviceX(points[i].x + xoffset);
604 yy = LogicalToDeviceY(points[i].y + yoffset);
605
606 PsPrintf( wxT("%d %d lineto\n"), xx, yy );
607
608 CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset);
609 }
610
611 PsPrint( "closepath\n" );
612 PsPrint( "stroke\n" );
613 }
614 }
615
616 void wxPostScriptDC::DoDrawPolyPolygon (int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
617 {
618 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
619
620 if (n <= 0) return;
621
622 if (m_brush.GetStyle () != wxTRANSPARENT)
623 {
624 SetBrush( m_brush );
625
626 PsPrint( "newpath\n" );
627
628 int ofs = 0;
629 for (int i = 0; i < n; ofs += count[i++])
630 {
631 wxCoord xx = LogicalToDeviceX(points[ofs].x + xoffset);
632 wxCoord yy = LogicalToDeviceY(points[ofs].y + yoffset);
633
634 PsPrintf( wxT("%d %d moveto\n"), xx, yy );
635
636 CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset );
637
638 for (int j = 1; j < count[i]; j++)
639 {
640 xx = LogicalToDeviceX(points[ofs+j].x + xoffset);
641 yy = LogicalToDeviceY(points[ofs+j].y + yoffset);
642
643 PsPrintf( wxT("%d %d lineto\n"), xx, yy );
644
645 CalcBoundingBox( points[ofs+j].x + xoffset, points[ofs+j].y + yoffset);
646 }
647 }
648 PsPrint( (fillStyle == wxODDEVEN_RULE ? "eofill\n" : "fill\n") );
649 }
650
651 if (m_pen.GetStyle () != wxTRANSPARENT)
652 {
653 SetPen( m_pen );
654
655 PsPrint( "newpath\n" );
656
657 int ofs = 0;
658 for (int i = 0; i < n; ofs += count[i++])
659 {
660 wxCoord xx = LogicalToDeviceX(points[ofs].x + xoffset);
661 wxCoord yy = LogicalToDeviceY(points[ofs].y + yoffset);
662
663 PsPrintf( wxT("%d %d moveto\n"), xx, yy );
664
665 CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset );
666
667 for (int j = 1; j < count[i]; j++)
668 {
669 xx = LogicalToDeviceX(points[ofs+j].x + xoffset);
670 yy = LogicalToDeviceY(points[ofs+j].y + yoffset);
671
672 PsPrintf( wxT("%d %d lineto\n"), xx, yy );
673
674 CalcBoundingBox( points[ofs+j].x + xoffset, points[ofs+j].y + yoffset);
675 }
676 }
677 PsPrint( "closepath\n" );
678 PsPrint( "stroke\n" );
679 }
680 }
681
682 void wxPostScriptDC::DoDrawLines (int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
683 {
684 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
685
686 if (m_pen.GetStyle() == wxTRANSPARENT) return;
687
688 if (n <= 0) return;
689
690 SetPen (m_pen);
691
692 int i;
693 for ( i =0; i<n ; i++ )
694 {
695 CalcBoundingBox( LogicalToDeviceX(points[i].x+xoffset), LogicalToDeviceY(points[i].y+yoffset));
696 }
697
698 PsPrintf( wxT("newpath\n")
699 wxT("%d %d moveto\n"),
700 LogicalToDeviceX(points[0].x+xoffset),
701 LogicalToDeviceY(points[0].y+yoffset) );
702
703 for (i = 1; i < n; i++)
704 {
705 PsPrintf( wxT("%d %d lineto\n"),
706 LogicalToDeviceX(points[i].x+xoffset),
707 LogicalToDeviceY(points[i].y+yoffset) );
708 }
709
710 PsPrint( "stroke\n" );
711 }
712
713 void wxPostScriptDC::DoDrawRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
714 {
715 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
716
717 if (m_brush.GetStyle () != wxTRANSPARENT)
718 {
719 SetBrush( m_brush );
720
721 PsPrintf( wxT("newpath\n")
722 wxT("%d %d moveto\n")
723 wxT("%d %d lineto\n")
724 wxT("%d %d lineto\n")
725 wxT("%d %d lineto\n")
726 wxT("closepath\n")
727 wxT("fill\n"),
728 LogicalToDeviceX(x), LogicalToDeviceY(y),
729 LogicalToDeviceX(x + width), LogicalToDeviceY(y),
730 LogicalToDeviceX(x + width), LogicalToDeviceY(y + height),
731 LogicalToDeviceX(x), LogicalToDeviceY(y + height) );
732
733 CalcBoundingBox( x, y );
734 CalcBoundingBox( x + width, y + height );
735 }
736
737 if (m_pen.GetStyle () != wxTRANSPARENT)
738 {
739 SetPen (m_pen);
740
741 PsPrintf( wxT("newpath\n")
742 wxT("%d %d moveto\n")
743 wxT("%d %d lineto\n")
744 wxT("%d %d lineto\n")
745 wxT("%d %d lineto\n")
746 wxT("closepath\n")
747 wxT("stroke\n"),
748 LogicalToDeviceX(x), LogicalToDeviceY(y),
749 LogicalToDeviceX(x + width), LogicalToDeviceY(y),
750 LogicalToDeviceX(x + width), LogicalToDeviceY(y + height),
751 LogicalToDeviceX(x), LogicalToDeviceY(y + height) );
752
753 CalcBoundingBox( x, y );
754 CalcBoundingBox( x + width, y + height );
755 }
756 }
757
758 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
759 {
760 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
761
762 if (radius < 0.0)
763 {
764 // Now, a negative radius is interpreted to mean
765 // 'the proportion of the smallest X or Y dimension'
766 double smallest = width < height ? width : height;
767 radius = (-radius * smallest);
768 }
769
770 wxCoord rad = (wxCoord) radius;
771
772 if (m_brush.GetStyle () != wxTRANSPARENT)
773 {
774 SetBrush( m_brush );
775
776 /* Draw rectangle anticlockwise */
777 PsPrintf( wxT("newpath\n")
778 wxT("%d %d %d 90 180 arc\n")
779 wxT("%d %d moveto\n")
780 wxT("%d %d %d 180 270 arc\n")
781 wxT("%d %d lineto\n")
782 wxT("%d %d %d 270 0 arc\n")
783 wxT("%d %d lineto\n")
784 wxT("%d %d %d 0 90 arc\n")
785 wxT("%d %d lineto\n")
786 wxT("closepath\n")
787 wxT("fill\n"),
788 LogicalToDeviceX(x + rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
789 LogicalToDeviceX(x), LogicalToDeviceY(y + rad),
790 LogicalToDeviceX(x + rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
791 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height),
792 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
793 LogicalToDeviceX(x + width), LogicalToDeviceY(y + rad),
794 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
795 LogicalToDeviceX(x + rad), LogicalToDeviceY(y) );
796
797 CalcBoundingBox( x, y );
798 CalcBoundingBox( x + width, y + height );
799 }
800
801 if (m_pen.GetStyle () != wxTRANSPARENT)
802 {
803 SetPen (m_pen);
804
805 /* Draw rectangle anticlockwise */
806 PsPrintf( wxT("newpath\n")
807 wxT("%d %d %d 90 180 arc\n")
808 wxT("%d %d moveto\n")
809 wxT("%d %d %d 180 270 arc\n")
810 wxT("%d %d lineto\n")
811 wxT("%d %d %d 270 0 arc\n")
812 wxT("%d %d lineto\n")
813 wxT("%d %d %d 0 90 arc\n")
814 wxT("%d %d lineto\n")
815 wxT("closepath\n")
816 wxT("stroke\n"),
817 LogicalToDeviceX(x + rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
818 LogicalToDeviceX(x), LogicalToDeviceY(y + rad),
819 LogicalToDeviceX(x + rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
820 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height),
821 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
822 LogicalToDeviceX(x + width), LogicalToDeviceY(y + rad),
823 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
824 LogicalToDeviceX(x + rad), LogicalToDeviceY(y) );
825
826 CalcBoundingBox( x, y );
827 CalcBoundingBox( x + width, y + height );
828 }
829 }
830
831 void wxPostScriptDC::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
832 {
833 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
834
835 if (m_brush.GetStyle () != wxTRANSPARENT)
836 {
837 SetBrush (m_brush);
838
839 PsPrintf( wxT("newpath\n")
840 wxT("%d %d %d %d 0 360 ellipse\n")
841 wxT("fill\n"),
842 LogicalToDeviceX(x + width / 2), LogicalToDeviceY(y + height / 2),
843 LogicalToDeviceXRel(width / 2), LogicalToDeviceYRel(height / 2) );
844
845 CalcBoundingBox( x - width, y - height );
846 CalcBoundingBox( x + width, y + height );
847 }
848
849 if (m_pen.GetStyle () != wxTRANSPARENT)
850 {
851 SetPen (m_pen);
852
853 PsPrintf( wxT("newpath\n")
854 wxT("%d %d %d %d 0 360 ellipse\n")
855 wxT("stroke\n"),
856 LogicalToDeviceX(x + width / 2), LogicalToDeviceY(y + height / 2),
857 LogicalToDeviceXRel(width / 2), LogicalToDeviceYRel(height / 2) );
858
859 CalcBoundingBox( x - width, y - height );
860 CalcBoundingBox( x + width, y + height );
861 }
862 }
863
864 void wxPostScriptDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
865 {
866 DrawBitmap( icon, x, y, TRUE );
867 }
868
869 /* this has to be char, not wxChar */
870 static char hexArray[] = "0123456789ABCDEF";
871
872 void wxPostScriptDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool WXUNUSED(useMask) )
873 {
874 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
875
876 if (!bitmap.Ok()) return;
877
878 wxImage image = bitmap.ConvertToImage();
879
880 if (!image.Ok()) return;
881
882 wxCoord w = image.GetWidth();
883 wxCoord h = image.GetHeight();
884
885 wxCoord ww = LogicalToDeviceXRel(image.GetWidth());
886 wxCoord hh = LogicalToDeviceYRel(image.GetHeight());
887
888 wxCoord xx = LogicalToDeviceX(x);
889 wxCoord yy = LogicalToDeviceY(y + bitmap.GetHeight());
890
891 PsPrintf( wxT("/origstate save def\n")
892 wxT("20 dict begin\n")
893 wxT("/pix %d string def\n")
894 wxT("/grays %d string def\n")
895 wxT("/npixels 0 def\n")
896 wxT("/rgbindx 0 def\n")
897 wxT("%d %d translate\n")
898 wxT("%d %d scale\n")
899 wxT("%d %d 8\n")
900 wxT("[%d 0 0 %d 0 %d]\n")
901 wxT("{currentfile pix readhexstring pop}\n")
902 wxT("false 3 colorimage\n"),
903 w, w, xx, yy, ww, hh, w, h, w, -h, h );
904
905 unsigned char* data = image.GetData();
906
907 /* buffer = line = width*rgb(3)*hexa(2)+'\n'(1)+null(1) */
908 char* buffer = new char[ w*6+2 ];
909 int firstDigit, secondDigit;
910
911 //rows
912 for (int j = 0; j < h; j++)
913 {
914 char* bufferindex = buffer;
915
916 //cols
917 for (int i = 0; i < w*3; i++)
918 {
919 firstDigit = (int)(*data/16.0);
920 secondDigit = (int)(*data - (firstDigit*16.0));
921 *(bufferindex++) = hexArray[firstDigit];
922 *(bufferindex++) = hexArray[secondDigit];
923
924 data++;
925 }
926 *(bufferindex++) = '\n';
927 *bufferindex = 0;
928 PsPrint( buffer );
929 }
930
931 PsPrint( "end\n" );
932 PsPrint( "origstate restore\n" );
933 }
934
935 void wxPostScriptDC::SetFont( const wxFont& font )
936 {
937 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
938
939 if (!font.Ok()) return;
940
941 m_font = font;
942
943 #if wxUSE_PANGO
944 #else
945 int Style = m_font.GetStyle();
946 int Weight = m_font.GetWeight();
947
948 const char *name;
949 switch (m_font.GetFamily())
950 {
951 case wxTELETYPE:
952 case wxMODERN:
953 {
954 if (Style == wxITALIC)
955 {
956 if (Weight == wxBOLD)
957 name = "/Courier-BoldOblique";
958 else
959 name = "/Courier-Oblique";
960 }
961 else
962 {
963 if (Weight == wxBOLD)
964 name = "/Courier-Bold";
965 else
966 name = "/Courier";
967 }
968 break;
969 }
970 case wxROMAN:
971 {
972 if (Style == wxITALIC)
973 {
974 if (Weight == wxBOLD)
975 name = "/Times-BoldItalic";
976 else
977 name = "/Times-Italic";
978 }
979 else
980 {
981 if (Weight == wxBOLD)
982 name = "/Times-Bold";
983 else
984 name = "/Times-Roman";
985 }
986 break;
987 }
988 case wxSCRIPT:
989 {
990 name = "/ZapfChancery-MediumItalic";
991 break;
992 }
993 case wxSWISS:
994 default:
995 {
996 if (Style == wxITALIC)
997 {
998 if (Weight == wxBOLD)
999 name = "/Helvetica-BoldOblique";
1000 else
1001 name = "/Helvetica-Oblique";
1002 }
1003 else
1004 {
1005 if (Weight == wxBOLD)
1006 name = "/Helvetica-Bold";
1007 else
1008 name = "/Helvetica";
1009 }
1010 break;
1011 }
1012 }
1013
1014 // We may legitimately call SetFont before BeginDoc
1015 if (!m_pstream)
1016 return;
1017
1018 PsPrint( name );
1019 PsPrint( " reencodeISO def\n" );
1020 PsPrint( name );
1021 PsPrint( " findfont\n" );
1022
1023 char buffer[100];
1024 sprintf( buffer, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font.GetPointSize() * 1000) / 1000.0F);
1025 // this is a hack - we must scale font size (in pts) according to m_scaleY but
1026 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
1027 // to 1/1000th of pt and then back.
1028 for (int i = 0; i < 100; i++)
1029 if (buffer[i] == ',') buffer[i] = '.';
1030 PsPrint( buffer );
1031 #endif // !wxUSE_PANGO
1032 }
1033
1034 void wxPostScriptDC::SetPen( const wxPen& pen )
1035 {
1036 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
1037
1038 if (!pen.Ok()) return;
1039
1040 int oldStyle = m_pen.GetStyle();
1041
1042 m_pen = pen;
1043
1044 char buffer[100];
1045 sprintf( buffer, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen.GetWidth()) / 1000.0f );
1046 for (int i = 0; i < 100; i++)
1047 if (buffer[i] == ',') buffer[i] = '.';
1048 PsPrint( buffer );
1049
1050 /*
1051 Line style - WRONG: 2nd arg is OFFSET
1052
1053 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1054 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1055 ter is not number of values in the array of the first one, but an offset
1056 into this description of the pattern. I mean a real *offset* not index
1057 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1058 will be first black line *2* units wxCoord, then space 4 units, then the
1059 pattern of *3* units black, 4 units space will be repeated.
1060 */
1061
1062 static const char *dotted = "[2 5] 2";
1063 static const char *short_dashed = "[4 4] 2";
1064 static const char *wxCoord_dashed = "[4 8] 2";
1065 static const char *dotted_dashed = "[6 6 2 6] 4";
1066
1067 const char *psdash;
1068
1069 switch (m_pen.GetStyle())
1070 {
1071 case wxDOT: psdash = dotted; break;
1072 case wxSHORT_DASH: psdash = short_dashed; break;
1073 case wxLONG_DASH: psdash = wxCoord_dashed; break;
1074 case wxDOT_DASH: psdash = dotted_dashed; break;
1075 case wxSOLID:
1076 case wxTRANSPARENT:
1077 default: psdash = "[] 0"; break;
1078 }
1079
1080 if ( (oldStyle != m_pen.GetStyle()) )
1081 {
1082 PsPrint( psdash );
1083 PsPrint( " setdash\n" );
1084 }
1085
1086 // Line colour
1087 unsigned char red = m_pen.GetColour().Red();
1088 unsigned char blue = m_pen.GetColour().Blue();
1089 unsigned char green = m_pen.GetColour().Green();
1090
1091 if (!m_colour)
1092 {
1093 // Anything not white is black
1094 if (! (red == (unsigned char) 255 &&
1095 blue == (unsigned char) 255 &&
1096 green == (unsigned char) 255) )
1097 {
1098 red = (unsigned char) 0;
1099 green = (unsigned char) 0;
1100 blue = (unsigned char) 0;
1101 }
1102 // setgray here ?
1103 }
1104
1105 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1106 {
1107 double redPS = (double)(red) / 255.0;
1108 double bluePS = (double)(blue) / 255.0;
1109 double greenPS = (double)(green) / 255.0;
1110
1111 char buffer[100];
1112 sprintf( buffer,
1113 "%.8f %.8f %.8f setrgbcolor\n",
1114 redPS, greenPS, bluePS );
1115 for (int i = 0; i < 100; i++)
1116 if (buffer[i] == ',') buffer[i] = '.';
1117
1118 PsPrint( buffer );
1119
1120 m_currentRed = red;
1121 m_currentBlue = blue;
1122 m_currentGreen = green;
1123 }
1124 }
1125
1126 void wxPostScriptDC::SetBrush( const wxBrush& brush )
1127 {
1128 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
1129
1130 if (!brush.Ok()) return;
1131
1132 m_brush = brush;
1133
1134 // Brush colour
1135 unsigned char red = m_brush.GetColour().Red();
1136 unsigned char blue = m_brush.GetColour().Blue();
1137 unsigned char green = m_brush.GetColour().Green();
1138
1139 if (!m_colour)
1140 {
1141 // Anything not white is black
1142 if (! (red == (unsigned char) 255 &&
1143 blue == (unsigned char) 255 &&
1144 green == (unsigned char) 255) )
1145 {
1146 red = (unsigned char) 0;
1147 green = (unsigned char) 0;
1148 blue = (unsigned char) 0;
1149 }
1150 // setgray here ?
1151 }
1152
1153 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1154 {
1155 double redPS = (double)(red) / 255.0;
1156 double bluePS = (double)(blue) / 255.0;
1157 double greenPS = (double)(green) / 255.0;
1158
1159 char buffer[100];
1160 sprintf( buffer,
1161 "%.8f %.8f %.8f setrgbcolor\n",
1162 redPS, greenPS, bluePS );
1163 for (int i = 0; i < 100; i++)
1164 if (buffer[i] == ',') buffer[i] = '.';
1165
1166 PsPrint( buffer );
1167
1168 m_currentRed = red;
1169 m_currentBlue = blue;
1170 m_currentGreen = green;
1171 }
1172 }
1173
1174 #if wxUSE_PANGO
1175
1176 #define PANGO_ENABLE_ENGINE
1177
1178 #ifdef __WXGTK20__
1179 #include "wx/gtk/private.h"
1180 #include "gtk/gtk.h"
1181 #else
1182 #include "wx/x11/private.h"
1183 #endif
1184
1185 #include <ft2build.h>
1186 #include FT_FREETYPE_H
1187
1188 #include "wx/fontutil.h"
1189 #include <pango/pangoft2.h>
1190 #include <freetype/ftglyph.h>
1191
1192 #ifndef FT_Outline_Decompose
1193 FT_EXPORT( FT_Error ) FT_Outline_Decompose(
1194 FT_Outline* outline,
1195 const FT_Outline_Funcs* interface,
1196 void* user );
1197 #endif
1198
1199 typedef struct _OutlineInfo OutlineInfo;
1200 struct _OutlineInfo {
1201 wxPostScriptDC* caller;
1202 };
1203
1204 static int paps_move_to( FT_Vector* to, void *user_data)
1205 {
1206 OutlineInfo *outline_info = (OutlineInfo*)user_data;
1207 outline_info->caller->PsPrintf( wxT("%d %d moveto\n"), (int)to->x, (int)to->y );
1208 return 0;
1209 }
1210
1211 static int paps_line_to( FT_Vector* to, void *user_data)
1212 {
1213 OutlineInfo *outline_info = (OutlineInfo*)user_data;
1214 outline_info->caller->PsPrintf( wxT("%d %d lineto\n"), (int)to->x , (int)to->y );
1215 return 0;
1216 }
1217
1218 static int paps_conic_to( FT_Vector* control, FT_Vector* to, void *user_data)
1219 {
1220 OutlineInfo *outline_info = (OutlineInfo*)user_data;
1221 outline_info->caller->PsPrintf( wxT("%d %d %d %d conicto\n"),
1222 (int)control->x ,
1223 (int)control->y ,
1224 (int)to->x ,
1225 (int)to->y );
1226 return 0;
1227 }
1228
1229 static int
1230 paps_cubic_to( FT_Vector* control1, FT_Vector* control2,
1231 FT_Vector* to, void *user_data)
1232 {
1233 OutlineInfo *outline_info = (OutlineInfo*)user_data;
1234 outline_info->caller->PsPrintf(wxT("%d %d %d %d %d %d curveto\n"),
1235 (int)control1->x ,
1236 (int)control1->y ,
1237 (int)control2->x ,
1238 (int)control2->y ,
1239 (int)to->x ,
1240 (int)to->y );
1241 return 0;
1242 }
1243
1244 void draw_bezier_outline(wxPostScriptDC* caller,
1245 FT_Face face,
1246 FT_UInt glyph_index,
1247 int pos_x,
1248 int pos_y,
1249 double scale_x,
1250 double scale_y )
1251 {
1252 FT_Int load_flags = FT_LOAD_NO_BITMAP;
1253 FT_Glyph glyph;
1254
1255 FT_Outline_Funcs outlinefunc =
1256 {
1257 paps_move_to,
1258 paps_line_to,
1259 paps_conic_to,
1260 paps_cubic_to
1261 };
1262
1263 OutlineInfo outline_info;
1264 outline_info.caller = caller;
1265
1266 caller->PsPrint("gsave\n");
1267 caller->PsPrintf( wxT("%d %d translate\n"), pos_x, pos_y );
1268
1269 // We have to replace the "," from the German
1270 // locale with the Englich "." for PostScript
1271 char buf[100];
1272 sprintf(buf, "%.8f %.8f scale\n", scale_x, scale_y );
1273 for (size_t i = 0; i < strlen(buf); i++)
1274 if (buf[i] == ',') buf[i] = '.';
1275 caller->PsPrint(buf);
1276
1277 FT_Load_Glyph(face, glyph_index, load_flags);
1278 FT_Get_Glyph (face->glyph, &glyph);
1279 FT_Outline_Decompose (&(((FT_OutlineGlyph)glyph)->outline),
1280 &outlinefunc, &outline_info);
1281 caller->PsPrint("closepath fill grestore\n");
1282
1283 FT_Done_Glyph (glyph);
1284 }
1285
1286 #endif
1287
1288 void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
1289 {
1290 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
1291
1292 if (m_textForegroundColour.Ok())
1293 {
1294 unsigned char red = m_textForegroundColour.Red();
1295 unsigned char blue = m_textForegroundColour.Blue();
1296 unsigned char green = m_textForegroundColour.Green();
1297
1298 if (!m_colour)
1299 {
1300 // Anything not white is black
1301 if (! (red == (unsigned char) 255 &&
1302 blue == (unsigned char) 255 &&
1303 green == (unsigned char) 255))
1304 {
1305 red = (unsigned char) 0;
1306 green = (unsigned char) 0;
1307 blue = (unsigned char) 0;
1308 }
1309 }
1310
1311 // maybe setgray here ?
1312 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1313 {
1314 double redPS = (double)(red) / 255.0;
1315 double bluePS = (double)(blue) / 255.0;
1316 double greenPS = (double)(green) / 255.0;
1317
1318 char buffer[100];
1319 sprintf( buffer,
1320 "%.8f %.8f %.8f setrgbcolor\n",
1321 redPS, greenPS, bluePS );
1322 for (size_t i = 0; i < strlen(buffer); i++)
1323 if (buffer[i] == ',') buffer[i] = '.';
1324 PsPrint( buffer );
1325
1326 m_currentRed = red;
1327 m_currentBlue = blue;
1328 m_currentGreen = green;
1329 }
1330 }
1331
1332 #if wxUSE_PANGO
1333 int ps_dpi = 72;
1334 int pango_dpi = 600;
1335 PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi );
1336
1337 double scale = (double)pango_dpi / (double)ps_dpi;
1338 scale /= m_userScaleY;
1339
1340 pango_context_set_language (context, pango_language_from_string ("en_US"));
1341 pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
1342
1343 pango_context_set_font_description (context, m_font.GetNativeFontInfo()->description );
1344
1345 PangoLayout *layout = pango_layout_new (context);
1346 #if wxUSE_UNICODE
1347 wxCharBuffer buffer = wxConvUTF8.cWC2MB( text );
1348 #else
1349 wxCharBuffer buffer = wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) );
1350 #endif
1351 pango_layout_set_text( layout, (const char*) buffer, strlen(buffer) );
1352
1353 PsPrintf( wxT("%%%% %s\n"), text.c_str() );
1354
1355 PangoRectangle rect;
1356 pango_layout_get_extents(layout, NULL, &rect);
1357
1358 int xx = LogicalToDeviceX( x );
1359 int yy = LogicalToDeviceY( y );
1360
1361 int xxx = xx * PANGO_SCALE;
1362 int yyy = yy * PANGO_SCALE - (int)(rect.height * 0.66 / scale); // Move down by estimated baseline. HACK.
1363
1364 #define ps_kludge_factor 2.8
1365
1366 // Loop over lines in layout
1367 int num_lines = pango_layout_get_line_count( layout );
1368 for (int i = 0; i < num_lines; i++)
1369 {
1370 PangoLayoutLine *line = pango_layout_get_line( layout, i );
1371
1372 // width of glyphs already printed
1373 int all_width = 0;
1374
1375 // Loop over runs in line
1376 GSList *runs_list = line->runs;
1377 while (runs_list)
1378 {
1379 PangoLayoutRun *run = (PangoLayoutRun*) runs_list->data;
1380 PangoItem *item = run->item;
1381 PangoGlyphString *glyphs = run->glyphs;
1382 PangoAnalysis *analysis = &item->analysis;
1383 PangoFont *font = analysis->font;
1384 FT_Face ft_face = pango_ft2_font_get_face(font);
1385
1386 int num_glyphs = glyphs->num_glyphs;
1387 for (int glyph_idx = 0; glyph_idx < num_glyphs; glyph_idx++)
1388 {
1389 PangoGlyphGeometry geometry = glyphs->glyphs[glyph_idx].geometry;
1390 int pos_x = xxx + (int)((double)(all_width+geometry.x_offset) / scale);
1391 int pos_y = yyy + (int)((double)geometry.y_offset / scale );
1392 all_width += geometry.width;
1393
1394 draw_bezier_outline( this, ft_face,
1395 (FT_UInt)(glyphs->glyphs[glyph_idx].glyph),
1396 pos_x / PANGO_SCALE,
1397 pos_y / PANGO_SCALE,
1398 1.0/(ps_kludge_factor * scale * 26.6),
1399 1.0/(ps_kludge_factor * scale * 26.6) );
1400 }
1401 runs_list = runs_list->next;
1402 }
1403 }
1404
1405 g_object_unref( G_OBJECT( layout ) );
1406 g_object_unref( G_OBJECT( context ) );
1407 #else // !wxUSE_PANGO
1408 wxCoord text_w, text_h, text_descent;
1409
1410 GetTextExtent(text, &text_w, &text_h, &text_descent);
1411
1412 // VZ: this seems to be unnecessary, so taking it out for now, if it
1413 // doesn't create any problems, remove this comment entirely
1414 //SetFont( m_font );
1415
1416
1417 int size = m_font.GetPointSize();
1418
1419 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1420 // commented by V. Slavik and replaced by accurate version
1421 // - note that there is still rounding error in text_descent!
1422 wxCoord by = y + size - text_descent; // baseline
1423
1424 PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x), LogicalToDeviceY(by) );
1425 PsPrint( "(" );
1426
1427 const wxWX2MBbuf textbuf = text.mb_str();
1428 size_t len = strlen(textbuf);
1429 size_t i;
1430 for (i = 0; i < len; i++)
1431 {
1432 int c = (unsigned char) textbuf[i];
1433 if (c == ')' || c == '(' || c == '\\')
1434 {
1435 /* Cope with special characters */
1436 PsPrint( "\\" );
1437 PsPrint(c);
1438 }
1439 else if ( c >= 128 )
1440 {
1441 /* Cope with character codes > 127 */
1442 PsPrintf( wxT("\\%o"), c);
1443 }
1444 else
1445 {
1446 PsPrint(c);
1447 }
1448 }
1449
1450 PsPrint( ") show\n" );
1451
1452 if (m_font.GetUnderlined())
1453 {
1454 wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
1455 char buffer[100];
1456
1457 sprintf( buffer,
1458 "gsave\n"
1459 "%d %d moveto\n"
1460 "%f setlinewidth\n"
1461 "%d %d lineto\n"
1462 "stroke\n"
1463 "grestore\n",
1464 LogicalToDeviceX(x), LogicalToDeviceY(uy),
1465 m_underlineThickness,
1466 LogicalToDeviceX(x + text_w), LogicalToDeviceY(uy) );
1467 for (i = 0; i < 100; i++)
1468 if (buffer[i] == ',') buffer[i] = '.';
1469 PsPrint( buffer );
1470 }
1471
1472 CalcBoundingBox( x, y );
1473 CalcBoundingBox( x + size * text.Length() * 2/3 , y );
1474 #endif // wxUSE_PANGO/!wxUSE_PANGO
1475 }
1476
1477 void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle )
1478 {
1479 if (angle == 0.0)
1480 {
1481 DoDrawText(text, x, y);
1482 return;
1483 }
1484
1485 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
1486
1487 SetFont( m_font );
1488
1489 if (m_textForegroundColour.Ok())
1490 {
1491 unsigned char red = m_textForegroundColour.Red();
1492 unsigned char blue = m_textForegroundColour.Blue();
1493 unsigned char green = m_textForegroundColour.Green();
1494
1495 if (!m_colour)
1496 {
1497 // Anything not white is black
1498 if (! (red == (unsigned char) 255 &&
1499 blue == (unsigned char) 255 &&
1500 green == (unsigned char) 255))
1501 {
1502 red = (unsigned char) 0;
1503 green = (unsigned char) 0;
1504 blue = (unsigned char) 0;
1505 }
1506 }
1507
1508 // maybe setgray here ?
1509 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1510 {
1511 double redPS = (double)(red) / 255.0;
1512 double bluePS = (double)(blue) / 255.0;
1513 double greenPS = (double)(green) / 255.0;
1514
1515 char buffer[100];
1516 sprintf( buffer,
1517 "%.8f %.8f %.8f setrgbcolor\n",
1518 redPS, greenPS, bluePS );
1519 for (int i = 0; i < 100; i++)
1520 if (buffer[i] == ',') buffer[i] = '.';
1521 PsPrint( buffer );
1522
1523 m_currentRed = red;
1524 m_currentBlue = blue;
1525 m_currentGreen = green;
1526 }
1527 }
1528
1529 int size = m_font.GetPointSize();
1530
1531 PsPrintf( wxT("%d %d moveto\n"),
1532 LogicalToDeviceX(x), LogicalToDeviceY(y));
1533
1534 char buffer[100];
1535 sprintf(buffer, "%.8f rotate\n", angle);
1536 size_t i;
1537 for (i = 0; i < 100; i++)
1538 {
1539 if (buffer[i] == ',') buffer[i] = '.';
1540 }
1541 PsPrint( buffer);
1542
1543 PsPrint( "(" );
1544 const wxWX2MBbuf textbuf = text.mb_str();
1545 size_t len = strlen(textbuf);
1546 for (i = 0; i < len; i++)
1547 {
1548 int c = (unsigned char) textbuf[i];
1549 if (c == ')' || c == '(' || c == '\\')
1550 {
1551 /* Cope with special characters */
1552 PsPrint( "\\" );
1553 PsPrint(c);
1554 }
1555 else if ( c >= 128 )
1556 {
1557 /* Cope with character codes > 127 */
1558 PsPrintf( wxT("\\%o"), c);
1559 }
1560 else
1561 {
1562 PsPrint(c);
1563 }
1564 }
1565
1566 PsPrint( ") show\n" );
1567
1568 sprintf( buffer, "%.8f rotate\n", -angle );
1569 for (i = 0; i < 100; i++)
1570 {
1571 if (buffer[i] == ',') buffer[i] = '.';
1572 }
1573 PsPrint( buffer );
1574
1575 if (m_font.GetUnderlined())
1576 {
1577 wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
1578 wxCoord w, h;
1579 char buffer[100];
1580 GetTextExtent(text, &w, &h);
1581
1582 sprintf( buffer,
1583 "gsave\n"
1584 "%d %d moveto\n"
1585 "%f setlinewidth\n"
1586 "%d %d lineto\n"
1587 "stroke\n"
1588 "grestore\n",
1589 LogicalToDeviceX(x), LogicalToDeviceY(uy),
1590 m_underlineThickness,
1591 LogicalToDeviceX(x + w), LogicalToDeviceY(uy) );
1592 for (i = 0; i < 100; i++)
1593 {
1594 if (buffer[i] == ',') buffer[i] = '.';
1595 }
1596 PsPrint( buffer );
1597 }
1598
1599 CalcBoundingBox( x, y );
1600 CalcBoundingBox( x + size * text.Length() * 2/3 , y );
1601 }
1602
1603 void wxPostScriptDC::SetBackground (const wxBrush& brush)
1604 {
1605 m_backgroundBrush = brush;
1606 }
1607
1608 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function))
1609 {
1610 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1611 }
1612
1613 void wxPostScriptDC::DoDrawSpline( wxList *points )
1614 {
1615 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
1616
1617 SetPen( m_pen );
1618
1619 // a and b are not used
1620 //double a, b;
1621 double c, d, x1, y1, x2, y2, x3, y3;
1622 wxPoint *p, *q;
1623
1624 wxList::compatibility_iterator node = points->GetFirst();
1625 p = (wxPoint *)node->GetData();
1626 x1 = p->x;
1627 y1 = p->y;
1628
1629 node = node->GetNext();
1630 p = (wxPoint *)node->GetData();
1631 c = p->x;
1632 d = p->y;
1633 x3 =
1634 #if 0
1635 a =
1636 #endif
1637 (double)(x1 + c) / 2;
1638 y3 =
1639 #if 0
1640 b =
1641 #endif
1642 (double)(y1 + d) / 2;
1643
1644 PsPrintf( wxT("newpath\n")
1645 wxT("%d %d moveto\n")
1646 wxT("%d %d lineto\n"),
1647 LogicalToDeviceX((wxCoord)x1), LogicalToDeviceY((wxCoord)y1),
1648 LogicalToDeviceX((wxCoord)x3), LogicalToDeviceY((wxCoord)y3) );
1649
1650 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1651 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1652
1653 node = node->GetNext();
1654 while (node)
1655 {
1656 q = (wxPoint *)node->GetData();
1657
1658 x1 = x3;
1659 y1 = y3;
1660 x2 = c;
1661 y2 = d;
1662 c = q->x;
1663 d = q->y;
1664 x3 = (double)(x2 + c) / 2;
1665 y3 = (double)(y2 + d) / 2;
1666
1667 PsPrintf( wxT("%d %d %d %d %d %d DrawSplineSection\n"),
1668 LogicalToDeviceX((wxCoord)x1), LogicalToDeviceY((wxCoord)y1),
1669 LogicalToDeviceX((wxCoord)x2), LogicalToDeviceY((wxCoord)y2),
1670 LogicalToDeviceX((wxCoord)x3), LogicalToDeviceY((wxCoord)y3) );
1671
1672 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1673 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1674
1675 node = node->GetNext();
1676 }
1677
1678 /*
1679 At this point, (x2,y2) and (c,d) are the position of the
1680 next-to-last and last point respectively, in the point list
1681 */
1682
1683 PsPrintf( wxT("%d %d lineto\n")
1684 wxT("stroke\n"),
1685 LogicalToDeviceX((wxCoord)c), LogicalToDeviceY((wxCoord)d) );
1686 }
1687
1688 wxCoord wxPostScriptDC::GetCharWidth() const
1689 {
1690 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1691 return (wxCoord) (GetCharHeight() * 72.0 / 120.0);
1692 }
1693
1694
1695 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
1696 {
1697 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
1698
1699 m_signX = (xLeftRight ? 1 : -1);
1700 m_signY = (yBottomUp ? 1 : -1);
1701
1702 // FIXME there is no such function in MSW nor in OS2/PM
1703 #if !defined(__WXMSW__) && !defined(__WXPM__)
1704 ComputeScaleAndOrigin();
1705 #endif
1706 }
1707
1708 void wxPostScriptDC::SetDeviceOrigin( wxCoord x, wxCoord y )
1709 {
1710 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
1711
1712 int h = 0;
1713 int w = 0;
1714 GetSize( &w, &h );
1715
1716 wxDC::SetDeviceOrigin( x, h-y );
1717 }
1718
1719 void wxPostScriptDC::DoGetSize(int* width, int* height) const
1720 {
1721 wxPaperSize id = m_printData.GetPaperId();
1722
1723 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id);
1724
1725 if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
1726
1727 int w = 595;
1728 int h = 842;
1729 if (paper)
1730 {
1731 w = paper->GetSizeDeviceUnits().x;
1732 h = paper->GetSizeDeviceUnits().y;
1733 }
1734
1735 if (m_printData.GetOrientation() == wxLANDSCAPE)
1736 {
1737 int tmp = w;
1738 w = h;
1739 h = tmp;
1740 }
1741
1742 if (width) *width = (int)(w * ms_PSScaleFactor);
1743 if (height) *height = (int)(h * ms_PSScaleFactor);
1744 }
1745
1746 void wxPostScriptDC::DoGetSizeMM(int *width, int *height) const
1747 {
1748 wxPaperSize id = m_printData.GetPaperId();
1749
1750 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id);
1751
1752 if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
1753
1754 int w = 210;
1755 int h = 297;
1756 if (paper)
1757 {
1758 w = paper->GetWidth() / 10;
1759 h = paper->GetHeight() / 10;
1760 }
1761
1762 if (m_printData.GetOrientation() == wxLANDSCAPE)
1763 {
1764 int tmp = w;
1765 w = h;
1766 h = tmp;
1767 }
1768
1769 if (width) *width = w;
1770 if (height) *height = h;
1771 }
1772
1773 // Resolution in pixels per logical inch
1774 wxSize wxPostScriptDC::GetPPI(void) const
1775 {
1776 return wxSize((int)(72 * ms_PSScaleFactor),
1777 (int)(72 * ms_PSScaleFactor));
1778 }
1779
1780
1781 bool wxPostScriptDC::StartDoc( const wxString& message )
1782 {
1783 wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") );
1784
1785 if ( m_printData.GetPrintMode() != wxPRINT_MODE_STREAM )
1786 {
1787 if (m_printData.GetFilename() == wxT(""))
1788 {
1789 wxString filename = wxGetTempFileName( wxT("ps") );
1790 m_printData.SetFilename(filename);
1791 }
1792
1793 // FIXME: use fn_str() here under Unicode?
1794 m_pstream = wxFopen( m_printData.GetFilename().c_str(), wxT("w+") );
1795
1796 if (!m_pstream)
1797 {
1798 wxLogError( _("Cannot open file for PostScript printing!"));
1799 m_ok = FALSE;
1800 return FALSE;
1801 }
1802 }
1803
1804 m_ok = TRUE;
1805 m_title = message;
1806
1807 PsPrint( "%!PS-Adobe-2.0\n" );
1808 PsPrintf( wxT("%%%%Title: %s\n"), m_title.c_str() );
1809 PsPrint( "%%Creator: wxWindows PostScript renderer\n" );
1810 PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() );
1811 if (m_printData.GetOrientation() == wxLANDSCAPE)
1812 PsPrint( "%%Orientation: Landscape\n" );
1813 else
1814 PsPrint( "%%Orientation: Portrait\n" );
1815
1816 // PsPrintf( wxT("%%%%Pages: %d\n"), (wxPageNumber - 1) );
1817
1818 const wxChar *paper;
1819 switch (m_printData.GetPaperId())
1820 {
1821 case wxPAPER_LETTER: paper = wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches
1822 case wxPAPER_LEGAL: paper = wxT("Legal"); break; // Legal, 8 1/2 by 14 inches
1823 case wxPAPER_A4: paper = wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters
1824 case wxPAPER_TABLOID: paper = wxT("Tabloid"); break; // Tabloid, 11 by 17 inches
1825 case wxPAPER_LEDGER: paper = wxT("Ledger"); break; // Ledger, 17 by 11 inches
1826 case wxPAPER_STATEMENT: paper = wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches
1827 case wxPAPER_EXECUTIVE: paper = wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches
1828 case wxPAPER_A3: paper = wxT("A3"); break; // A3 sheet, 297 by 420 millimeters
1829 case wxPAPER_A5: paper = wxT("A5"); break; // A5 sheet, 148 by 210 millimeters
1830 case wxPAPER_B4: paper = wxT("B4"); break; // B4 sheet, 250 by 354 millimeters
1831 case wxPAPER_B5: paper = wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper
1832 case wxPAPER_FOLIO: paper = wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper
1833 case wxPAPER_QUARTO: paper = wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper
1834 case wxPAPER_10X14: paper = wxT("10x14"); break; // 10-by-14-inch sheet
1835 default: paper = wxT("A4");
1836 }
1837 PsPrintf( wxT("%%%%DocumentPaperSizes: %s\n"), paper );
1838 PsPrint( "%%EndComments\n\n" );
1839
1840 PsPrint( "%%BeginProlog\n" );
1841 PsPrint( wxPostScriptHeaderConicTo );
1842 PsPrint( wxPostScriptHeaderEllipse );
1843 PsPrint( wxPostScriptHeaderEllipticArc );
1844 PsPrint( wxPostScriptHeaderColourImage );
1845 #if wxUSE_PANGO
1846 #else
1847 PsPrint( wxPostScriptHeaderReencodeISO1 );
1848 PsPrint( wxPostScriptHeaderReencodeISO2 );
1849 #endif
1850 if (wxPostScriptHeaderSpline)
1851 PsPrint( wxPostScriptHeaderSpline );
1852 PsPrint( "%%EndProlog\n" );
1853
1854 SetBrush( *wxBLACK_BRUSH );
1855 SetPen( *wxBLACK_PEN );
1856 SetBackground( *wxWHITE_BRUSH );
1857 SetTextForeground( *wxBLACK );
1858
1859 // set origin according to paper size
1860 SetDeviceOrigin( 0,0 );
1861
1862 wxPageNumber = 1;
1863 m_pageNumber = 1;
1864 return TRUE;
1865 }
1866
1867 void wxPostScriptDC::EndDoc ()
1868 {
1869 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
1870
1871 if (m_clipping)
1872 {
1873 m_clipping = FALSE;
1874 PsPrint( "grestore\n" );
1875 }
1876
1877 if ( m_pstream ) {
1878 fclose( m_pstream );
1879 m_pstream = (FILE *) NULL;
1880 }
1881
1882 #if 0
1883 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1884 wxCoord wx_printer_translate_x, wx_printer_translate_y;
1885 double wx_printer_scale_x, wx_printer_scale_y;
1886
1887 wx_printer_translate_x = (wxCoord)m_printData.GetPrinterTranslateX();
1888 wx_printer_translate_y = (wxCoord)m_printData.GetPrinterTranslateY();
1889
1890 wx_printer_scale_x = m_printData.GetPrinterScaleX();
1891 wx_printer_scale_y = m_printData.GetPrinterScaleY();
1892
1893 // Compute the bounding box. Note that it is in the default user
1894 // coordinate system, thus we have to convert the values.
1895 wxCoord minX = (wxCoord) LogicalToDeviceX(m_minX);
1896 wxCoord minY = (wxCoord) LogicalToDeviceY(m_minY);
1897 wxCoord maxX = (wxCoord) LogicalToDeviceX(m_maxX);
1898 wxCoord maxY = (wxCoord) LogicalToDeviceY(m_maxY);
1899
1900 // LOG2DEV may have changed the minimum to maximum vice versa
1901 if ( minX > maxX ) { wxCoord tmp = minX; minX = maxX; maxX = tmp; }
1902 if ( minY > maxY ) { wxCoord tmp = minY; minY = maxY; maxY = tmp; }
1903
1904 // account for used scaling (boundingbox is before scaling in ps-file)
1905 double scale_x = m_printData.GetPrinterScaleX() / ms_PSScaleFactor;
1906 double scale_y = m_printData.GetPrinterScaleY() / ms_PSScaleFactor;
1907
1908 wxCoord llx, lly, urx, ury;
1909 llx = (wxCoord) ((minX+wx_printer_translate_x)*scale_x);
1910 lly = (wxCoord) ((minY+wx_printer_translate_y)*scale_y);
1911 urx = (wxCoord) ((maxX+wx_printer_translate_x)*scale_x);
1912 ury = (wxCoord) ((maxY+wx_printer_translate_y)*scale_y);
1913 // (end of bounding box computation)
1914
1915
1916 // If we're landscape, our sense of "x" and "y" is reversed.
1917 if (m_printData.GetOrientation() == wxLANDSCAPE)
1918 {
1919 wxCoord tmp;
1920 tmp = llx; llx = lly; lly = tmp;
1921 tmp = urx; urx = ury; ury = tmp;
1922
1923 // We need either the two lines that follow, or we need to subtract
1924 // min_x from real_translate_y, which is commented out below.
1925 llx = llx - (wxCoord)(m_minX*wx_printer_scale_y);
1926 urx = urx - (wxCoord)(m_minX*wx_printer_scale_y);
1927 }
1928
1929 // The Adobe specifications call for integers; we round as to make
1930 // the bounding larger.
1931 PsPrintf( wxT("%%%%BoundingBox: %d %d %d %d\n"),
1932 (wxCoord)floor((double)llx), (wxCoord)floor((double)lly),
1933 (wxCoord)ceil((double)urx), (wxCoord)ceil((double)ury) );
1934
1935 // To check the correctness of the bounding box, postscript commands
1936 // to draw a box corresponding to the bounding box are generated below.
1937 // But since we typically don't want to print such a box, the postscript
1938 // commands are generated within comments. These lines appear before any
1939 // adjustment of scale, rotation, or translation, and hence are in the
1940 // default user coordinates.
1941 PsPrint( "% newpath\n" );
1942 PsPrintf( wxT("%% %d %d moveto\n"), llx, lly );
1943 PsPrintf( wxT("%% %d %d lineto\n"), urx, lly );
1944 PsPrintf( wxT("%% %d %d lineto\n"), urx, ury );
1945 PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx, ury );
1946 #endif
1947
1948 #if defined(__X__) || defined(__WXGTK__)
1949 if (m_ok && (m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER))
1950 {
1951 wxString command;
1952 command += m_printData.GetPrinterCommand();
1953 command += wxT(" ");
1954 command += m_printData.GetPrinterOptions();
1955 command += wxT(" ");
1956 command += m_printData.GetFilename();
1957
1958 wxExecute( command, TRUE );
1959 wxRemoveFile( m_printData.GetFilename() );
1960 }
1961 #endif
1962 }
1963
1964 void wxPostScriptDC::StartPage()
1965 {
1966 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
1967
1968 PsPrintf( wxT("%%%%Page: %d\n"), wxPageNumber++ );
1969
1970 // What is this one supposed to do? RR.
1971 // *m_pstream << "matrix currentmatrix\n";
1972
1973 // Added by Chris Breeze
1974
1975 // Each page starts with an "initgraphics" which resets the
1976 // transformation and so we need to reset the origin
1977 // (and rotate the page for landscape printing)
1978
1979 // Output scaling
1980 wxCoord translate_x, translate_y;
1981 double scale_x, scale_y;
1982
1983 translate_x = (wxCoord)m_printData.GetPrinterTranslateX();
1984 translate_y = (wxCoord)m_printData.GetPrinterTranslateY();
1985
1986 scale_x = m_printData.GetPrinterScaleX();
1987 scale_y = m_printData.GetPrinterScaleY();
1988
1989 if (m_printData.GetOrientation() == wxLANDSCAPE)
1990 {
1991 int h;
1992 GetSize( (int*) NULL, &h );
1993 translate_y -= h;
1994 PsPrint( "90 rotate\n" );
1995 // I copied this one from a PostScript tutorial, but to no avail. RR.
1996 // PsPrint( "90 rotate llx neg ury nef translate\n" );
1997 }
1998
1999 char buffer[100];
2000 sprintf( buffer, "%.8f %.8f scale\n", scale_x / ms_PSScaleFactor,
2001 scale_y / ms_PSScaleFactor);
2002 for (int i = 0; i < 100; i++)
2003 if (buffer[i] == ',') buffer[i] = '.';
2004 PsPrint( buffer );
2005
2006 PsPrintf( wxT("%d %d translate\n"), translate_x, translate_y );
2007 }
2008
2009 void wxPostScriptDC::EndPage ()
2010 {
2011 wxCHECK_RET( m_ok , wxT("invalid postscript dc") );
2012
2013 PsPrint( "showpage\n" );
2014 }
2015
2016 bool wxPostScriptDC::DoBlit( wxCoord xdest, wxCoord ydest,
2017 wxCoord fwidth, wxCoord fheight,
2018 wxDC *source,
2019 wxCoord xsrc, wxCoord ysrc,
2020 int rop, bool WXUNUSED(useMask), wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask) )
2021 {
2022 wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") );
2023
2024 wxCHECK_MSG( source, FALSE, wxT("invalid source dc") );
2025
2026 /* blit into a bitmap */
2027 wxBitmap bitmap( (int)fwidth, (int)fheight );
2028 wxMemoryDC memDC;
2029 memDC.SelectObject(bitmap);
2030 memDC.Blit(0, 0, fwidth, fheight, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */
2031 memDC.SelectObject(wxNullBitmap);
2032
2033 /* draw bitmap. scaling and positioning is done there */
2034 DrawBitmap( bitmap, xdest, ydest );
2035
2036 return TRUE;
2037 }
2038
2039 wxCoord wxPostScriptDC::GetCharHeight() const
2040 {
2041 if (m_font.Ok())
2042 return m_font.GetPointSize();
2043 else
2044 return 12;
2045 }
2046
2047 void wxPostScriptDC::DoGetTextExtent(const wxString& string,
2048 wxCoord *x, wxCoord *y,
2049 wxCoord *descent, wxCoord *externalLeading,
2050 wxFont *theFont ) const
2051 {
2052 wxFont *fontToUse = theFont;
2053
2054 if (!fontToUse) fontToUse = (wxFont*) &m_font;
2055
2056 wxCHECK_RET( fontToUse, wxT("GetTextExtent: no font defined") );
2057
2058 if (string.IsEmpty())
2059 {
2060 if (x) (*x) = 0;
2061 if (y) (*y) = 0;
2062 if (descent) (*descent) = 0;
2063 if (externalLeading) (*externalLeading) = 0;
2064 return;
2065 }
2066
2067 #if wxUSE_PANGO
2068 int wx_dpi = GetResolution();
2069 int pango_dpi = 600;
2070 PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi );
2071
2072 double scale = pango_dpi / wx_dpi;
2073 scale /= m_userScaleY;
2074
2075 pango_context_set_language (context, pango_language_from_string ("en_US"));
2076 pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
2077
2078 PangoLayout *layout = pango_layout_new (context);
2079
2080 PangoFontDescription *desc = fontToUse->GetNativeFontInfo()->description;
2081 pango_layout_set_font_description(layout, desc);
2082 #if wxUSE_UNICODE
2083 const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
2084 #else
2085 const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
2086 const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
2087 #endif
2088 pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
2089 PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
2090
2091 PangoRectangle rect;
2092 pango_layout_line_get_extents(line, NULL, &rect);
2093
2094 if (x) (*x) = (wxCoord) ( rect.width / PANGO_SCALE / scale );
2095 if (y) (*y) = (wxCoord) ( rect.height / PANGO_SCALE / scale );
2096 if (descent)
2097 {
2098 // Do something about metrics here
2099 (*descent) = 0;
2100 }
2101 if (externalLeading) (*externalLeading) = 0; // ??
2102
2103 g_object_unref( G_OBJECT( layout ) );
2104 #else
2105 // GTK 2.0
2106
2107 const wxWX2MBbuf strbuf = string.mb_str();
2108
2109 #if !wxUSE_AFM_FOR_POSTSCRIPT
2110 /* Provide a VERY rough estimate (avoid using it).
2111 * Produces accurate results for mono-spaced font
2112 * such as Courier (aka wxMODERN) */
2113
2114 int height = 12;
2115 if (fontToUse)
2116 {
2117 height = fontToUse->GetPointSize();
2118 }
2119 if ( x )
2120 *x = strlen (strbuf) * height * 72 / 120;
2121 if ( y )
2122 *y = (wxCoord) (height * 1.32); /* allow for descender */
2123 if (descent) *descent = 0;
2124 if (externalLeading) *externalLeading = 0;
2125 #else
2126
2127 /* method for calculating string widths in postscript:
2128 / read in the AFM (adobe font metrics) file for the
2129 / actual font, parse it and extract the character widths
2130 / and also the descender. this may be improved, but for now
2131 / it works well. the AFM file is only read in if the
2132 / font is changed. this may be chached in the future.
2133 / calls to GetTextExtent with the font unchanged are rather
2134 / efficient!!!
2135 /
2136 / for each font and style used there is an AFM file necessary.
2137 / currently i have only files for the roman font family.
2138 / I try to get files for the other ones!
2139 /
2140 / CAVE: the size of the string is currently always calculated
2141 / in 'points' (1/72 of an inch). this should later on be
2142 / changed to depend on the mapping mode.
2143 / CAVE: the path to the AFM files must be set before calling this
2144 / function. this is usually done by a call like the following:
2145 / wxSetAFMPath("d:\\wxw161\\afm\\");
2146 /
2147 / example:
2148 /
2149 / wxPostScriptDC dc(NULL, TRUE);
2150 / if (dc.Ok()){
2151 / wxSetAFMPath("d:\\wxw161\\afm\\");
2152 / dc.StartDoc("Test");
2153 / dc.StartPage();
2154 / wxCoord w,h;
2155 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
2156 / dc.GetTextExtent("Hallo",&w,&h);
2157 / dc.EndPage();
2158 / dc.EndDoc();
2159 / }
2160 /
2161 / by steve (stefan.hammes@urz.uni-heidelberg.de)
2162 / created: 10.09.94
2163 / updated: 14.05.95 */
2164
2165 /* these static vars are for storing the state between calls */
2166 static int lastFamily= INT_MIN;
2167 static int lastSize= INT_MIN;
2168 static int lastStyle= INT_MIN;
2169 static int lastWeight= INT_MIN;
2170 static int lastDescender = INT_MIN;
2171 static int lastWidths[256]; /* widths of the characters */
2172
2173 double UnderlinePosition = 0.0;
2174 double UnderlineThickness = 0.0;
2175
2176 // Get actual parameters
2177 int Family = fontToUse->GetFamily();
2178 int Size = fontToUse->GetPointSize();
2179 int Style = fontToUse->GetStyle();
2180 int Weight = fontToUse->GetWeight();
2181
2182 // If we have another font, read the font-metrics
2183 if (Family!=lastFamily || Size!=lastSize || Style!=lastStyle || Weight!=lastWeight)
2184 {
2185 // Store actual values
2186 lastFamily = Family;
2187 lastSize = Size;
2188 lastStyle = Style;
2189 lastWeight = Weight;
2190
2191 const wxChar *name;
2192
2193 switch (Family)
2194 {
2195 case wxMODERN:
2196 case wxTELETYPE:
2197 {
2198 if ((Style == wxITALIC) && (Weight == wxBOLD)) name = wxT("CourBoO.afm");
2199 else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = wxT("CourBo.afm");
2200 else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = wxT("CourO.afm");
2201 else name = wxT("Cour.afm");
2202 break;
2203 }
2204 case wxROMAN:
2205 {
2206 if ((Style == wxITALIC) && (Weight == wxBOLD)) name = wxT("TimesBoO.afm");
2207 else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = wxT("TimesBo.afm");
2208 else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = wxT("TimesO.afm");
2209 else name = wxT("TimesRo.afm");
2210 break;
2211 }
2212 case wxSCRIPT:
2213 {
2214 name = wxT("Zapf.afm");
2215 break;
2216 }
2217 case wxSWISS:
2218 default:
2219 {
2220 if ((Style == wxITALIC) && (Weight == wxBOLD)) name = wxT("HelvBoO.afm");
2221 else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = wxT("HelvBo.afm");
2222 else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = wxT("HelvO.afm");
2223 else name = wxT("Helv.afm");
2224 break;
2225 }
2226 }
2227
2228 FILE *afmFile = NULL;
2229
2230 // Get the directory of the AFM files
2231 wxString afmName;
2232 if (!m_printData.GetFontMetricPath().IsEmpty())
2233 {
2234 afmName = m_printData.GetFontMetricPath();
2235 afmName << wxFILE_SEP_PATH << name;
2236 afmFile = wxFopen(afmName,wxT("r"));
2237 }
2238
2239 #if defined(__UNIX__) && !defined(__VMS__)
2240 if (afmFile==NULL)
2241 {
2242 afmName = wxGetDataDir();
2243 afmName << wxFILE_SEP_PATH
2244 #if defined(__LINUX__) || defined(__FREEBSD__)
2245 << wxT("gs_afm") << wxFILE_SEP_PATH
2246 #else
2247 << wxT("afm") << wxFILE_SEP_PATH
2248 #endif
2249 << name;
2250 afmFile = wxFopen(afmName,wxT("r"));
2251 }
2252 #endif
2253
2254 /* 2. open and process the file
2255 / a short explanation of the AFM format:
2256 / we have for each character a line, which gives its size
2257 / e.g.:
2258 /
2259 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2260 /
2261 / that means, we have a character with ascii code 63, and width
2262 / (444/1000 * fontSize) points.
2263 / the other data is ignored for now!
2264 /
2265 / when the font has changed, we read in the right AFM file and store the
2266 / character widths in an array, which is processed below (see point 3.). */
2267 if (afmFile==NULL)
2268 {
2269 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName.c_str() );
2270 wxLogDebug( wxT(" using approximate values"));
2271 for (int i=0; i<256; i++) lastWidths[i] = 500; /* an approximate value */
2272 lastDescender = -150; /* dito. */
2273 }
2274 else
2275 {
2276 /* init the widths array */
2277 for(int i=0; i<256; i++) lastWidths[i] = INT_MIN;
2278 /* some variables for holding parts of a line */
2279 char cString[10],semiString[10],WXString[10],descString[20];
2280 char upString[30], utString[30], encString[50];
2281 char line[256];
2282 int ascii,cWidth;
2283 /* read in the file and parse it */
2284 while(fgets(line,sizeof(line),afmFile)!=NULL)
2285 {
2286 /* A.) check for descender definition */
2287 if (strncmp(line,"Descender",9)==0)
2288 {
2289 if ((sscanf(line,"%s%d",descString,&lastDescender)!=2) ||
2290 (strcmp(descString,"Descender")!=0))
2291 {
2292 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName.c_str(),line );
2293 }
2294 }
2295 /* JC 1.) check for UnderlinePosition */
2296 else if(strncmp(line,"UnderlinePosition",17)==0)
2297 {
2298 if ((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) ||
2299 (strcmp(upString,"UnderlinePosition")!=0))
2300 {
2301 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName.c_str(), line );
2302 }
2303 }
2304 /* JC 2.) check for UnderlineThickness */
2305 else if(strncmp(line,"UnderlineThickness",18)==0)
2306 {
2307 if ((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) ||
2308 (strcmp(utString,"UnderlineThickness")!=0))
2309 {
2310 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName.c_str(), line );
2311 }
2312 }
2313 /* JC 3.) check for EncodingScheme */
2314 else if(strncmp(line,"EncodingScheme",14)==0)
2315 {
2316 if ((sscanf(line,"%s%s",utString,encString)!=2) ||
2317 (strcmp(utString,"EncodingScheme")!=0))
2318 {
2319 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName.c_str(), line );
2320 }
2321 else if (strncmp(encString, "AdobeStandardEncoding", 21))
2322 {
2323 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2324 afmName.c_str(),line, encString);
2325 }
2326 }
2327 /* B.) check for char-width */
2328 else if(strncmp(line,"C ",2)==0)
2329 {
2330 if (sscanf(line,"%s%d%s%s%d",cString,&ascii,semiString,WXString,&cWidth)!=5)
2331 {
2332 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName.c_str(),line);
2333 }
2334 if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 || strcmp(WXString,"WX")!=0)
2335 {
2336 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName.c_str(),line);
2337 }
2338 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2339 if (ascii>=0 && ascii<256)
2340 {
2341 lastWidths[ascii] = cWidth; /* store width */
2342 }
2343 else
2344 {
2345 /* MATTHEW: this happens a lot; don't print an error */
2346 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2347 }
2348 }
2349 /* C.) ignore other entries. */
2350 }
2351 fclose(afmFile);
2352 }
2353 /* hack to compute correct values for german 'Umlaute'
2354 / the correct way would be to map the character names
2355 / like 'adieresis' to corresp. positions of ISOEnc and read
2356 / these values from AFM files, too. Maybe later ... */
2357
2358 // NB: casts to int are needed to suppress gcc 3.3 warnings
2359 lastWidths[196] = lastWidths[(int)'A']; // Ä
2360 lastWidths[228] = lastWidths[(int)'a']; // ä
2361 lastWidths[214] = lastWidths[(int)'O']; // Ö
2362 lastWidths[246] = lastWidths[(int)'o']; // ö
2363 lastWidths[220] = lastWidths[(int)'U']; // Ü
2364 lastWidths[252] = lastWidths[(int)'u']; // ü
2365 lastWidths[223] = lastWidths[(int)251]; // ß
2366
2367 /* JC: calculate UnderlineThickness/UnderlinePosition */
2368
2369 // VS: dirty, but is there any better solution?
2370 double *pt;
2371 pt = (double*) &m_underlinePosition;
2372 *pt = LogicalToDeviceYRel((wxCoord)(UnderlinePosition * fontToUse->GetPointSize())) / 1000.0f;
2373 pt = (double*) &m_underlineThickness;
2374 *pt = LogicalToDeviceYRel((wxCoord)(UnderlineThickness * fontToUse->GetPointSize())) / 1000.0f;
2375
2376 }
2377
2378
2379 /* 3. now the font metrics are read in, calc size this
2380 / is done by adding the widths of the characters in the
2381 / string. they are given in 1/1000 of the size! */
2382
2383 long sum=0;
2384 wxCoord height=Size; /* by default */
2385 unsigned char *p;
2386 for(p=(unsigned char *)wxMBSTRINGCAST strbuf; *p; p++)
2387 {
2388 if(lastWidths[*p]== INT_MIN)
2389 {
2390 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p,*p);
2391 sum += lastWidths[(unsigned char)' ']; /* assume space */
2392 }
2393 else
2394 {
2395 sum += lastWidths[*p];
2396 }
2397 }
2398
2399 double widthSum = sum;
2400 widthSum *= Size;
2401 widthSum /= 1000.0F;
2402
2403 /* add descender to height (it is usually a negative value) */
2404 //if (lastDescender != INT_MIN)
2405 //{
2406 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2407 //}
2408 // - commented by V. Slavik - height already contains descender in it
2409 // (judging from few experiments)
2410
2411 /* return size values */
2412 if ( x )
2413 *x = (wxCoord)widthSum;
2414 if ( y )
2415 *y = height;
2416
2417 /* return other parameters */
2418 if (descent)
2419 {
2420 if(lastDescender!=INT_MIN)
2421 {
2422 *descent = (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2423 }
2424 else
2425 {
2426 *descent = 0;
2427 }
2428 }
2429
2430 /* currently no idea how to calculate this! */
2431 if (externalLeading) *externalLeading = 0;
2432 #endif
2433 // Use AFM
2434
2435 #endif
2436 // GTK 2.0
2437 }
2438
2439 // print postscript datas via required method (file, stream)
2440 void wxPostScriptDC::PsPrintf( const wxChar* fmt, ... )
2441 {
2442 va_list argptr;
2443 va_start(argptr, fmt);
2444
2445 PsPrint( wxString::FormatV( fmt, argptr ).c_str() );
2446 }
2447
2448 void wxPostScriptDC::PsPrint( const char* psdata )
2449 {
2450 switch( m_printData.GetPrintMode() )
2451 {
2452 #if wxUSE_STREAMS
2453 // append to output stream
2454 case wxPRINT_MODE_STREAM:
2455 {
2456 wxOutputStream* outputstream = m_printData.GetOutputStream();
2457 wxCHECK_RET( outputstream, wxT("invalid outputstream") );
2458 outputstream->Write( psdata, strlen( psdata ) );
2459 }
2460 break;
2461 #endif // wxUSE_STREAMS
2462
2463 // save data into file
2464 default:
2465 wxCHECK_RET( m_pstream, wxT("invalid postscript dc") );
2466 fwrite( psdata, 1, strlen( psdata ), m_pstream );
2467 }
2468 }
2469
2470 void wxPostScriptDC::PsPrint( int ch )
2471 {
2472 switch( m_printData.GetPrintMode() )
2473 {
2474 #if wxUSE_STREAMS
2475 // append to output stream
2476 case wxPRINT_MODE_STREAM:
2477 {
2478 wxOutputStream* outputstream = m_printData.GetOutputStream();
2479 wxCHECK_RET( outputstream, wxT("invalid outputstream") );
2480 outputstream->PutC( ch );
2481 }
2482 break;
2483 #endif // wxUSE_STREAMS
2484
2485 // save data into file
2486 default:
2487 wxCHECK_RET( m_pstream, wxT("invalid postscript dc") );
2488 fputc( ch, m_pstream );
2489 }
2490 }
2491
2492 #if WXWIN_COMPATIBILITY_2_2
2493 WXDLLEXPORT wxPrintSetupData *wxThePrintSetupData = 0;
2494
2495 void wxInitializePrintSetupData(bool init)
2496 {
2497 if (init)
2498 {
2499 // gets initialized in the constructor
2500 wxThePrintSetupData = new wxPrintSetupData;
2501 }
2502 else
2503 {
2504 delete wxThePrintSetupData;
2505
2506 wxThePrintSetupData = (wxPrintSetupData *) NULL;
2507 }
2508 }
2509
2510 // A module to allow initialization/cleanup of PostScript-related
2511 // things without calling these functions from app.cpp.
2512
2513 class WXDLLEXPORT wxPostScriptModule: public wxModule
2514 {
2515 DECLARE_DYNAMIC_CLASS(wxPostScriptModule)
2516 public:
2517 wxPostScriptModule() {}
2518 bool OnInit();
2519 void OnExit();
2520 };
2521
2522 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule, wxModule)
2523
2524 bool wxPostScriptModule::OnInit()
2525 {
2526 wxInitializePrintSetupData();
2527
2528 return TRUE;
2529 }
2530
2531 void wxPostScriptModule::OnExit()
2532 {
2533 wxInitializePrintSetupData(FALSE);
2534 }
2535 #endif
2536 // WXWIN_COMPATIBILITY_2_2
2537
2538 #endif
2539 // wxUSE_POSTSCRIPT
2540
2541 #endif
2542 // wxUSE_PRINTING_ARCHITECTURE
2543
2544
2545 // vi:sts=4:sw=4:et