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