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