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