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