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