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