]> git.saurik.com Git - wxWidgets.git/blob - src/generic/dcpsg.cpp
Doc/distribution script mods
[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 wxCoord xx0 = xx;
654 wxCoord yy0 = yy;
655
656 fprintf( m_pstream, "%d %d moveto\n", xx, yy );
657
658 CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
659
660 for (int i = 1; i < n; i++)
661 {
662 xx = XLOG2DEV(points[i].x + xoffset);
663 yy = YLOG2DEV(points[i].y + yoffset);
664
665 fprintf( m_pstream, "%d %d lineto\n", xx, yy );
666
667 CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset);
668 }
669
670 fprintf( m_pstream, "%d %d lineto\n", xx0, yy0 );
671 fprintf( m_pstream, "stroke\n" );
672 }
673 }
674
675 void wxPostScriptDC::DoDrawLines (int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
676 {
677 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
678
679 if (m_pen.GetStyle() == wxTRANSPARENT) return;
680
681 if (n <= 0) return;
682
683 SetPen (m_pen);
684
685 int i;
686 for ( i =0; i<n ; i++ )
687 {
688 CalcBoundingBox( XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset));
689 }
690
691 fprintf( m_pstream,
692 "newpath\n"
693 "%d %d moveto\n",
694 XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) );
695
696 for (i = 1; i < n; i++)
697 {
698 fprintf( m_pstream,
699 "%d %d lineto\n",
700 XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) );
701 }
702
703 fprintf( m_pstream, "stroke\n" );
704 }
705
706 void wxPostScriptDC::DoDrawRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
707 {
708 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
709
710 if (m_brush.GetStyle () != wxTRANSPARENT)
711 {
712 SetBrush( m_brush );
713
714 fprintf( m_pstream,
715 "newpath\n"
716 "%d %d moveto\n"
717 "%d %d lineto\n"
718 "%d %d lineto\n"
719 "%d %d lineto\n"
720 "closepath\n"
721 "fill\n",
722 XLOG2DEV(x), YLOG2DEV(y),
723 XLOG2DEV(x + width), YLOG2DEV(y),
724 XLOG2DEV(x + width), YLOG2DEV(y + height),
725 XLOG2DEV(x), YLOG2DEV(y + height) );
726
727 CalcBoundingBox( x, y );
728 CalcBoundingBox( x + width, y + height );
729 }
730
731 if (m_pen.GetStyle () != wxTRANSPARENT)
732 {
733 SetPen (m_pen);
734
735 fprintf( m_pstream,
736 "newpath\n"
737 "%d %d moveto\n"
738 "%d %d lineto\n"
739 "%d %d lineto\n"
740 "%d %d lineto\n"
741 "closepath\n"
742 "stroke\n",
743 XLOG2DEV(x), YLOG2DEV(y),
744 XLOG2DEV(x + width), YLOG2DEV(y),
745 XLOG2DEV(x + width), YLOG2DEV(y + height),
746 XLOG2DEV(x), YLOG2DEV(y + height) );
747
748 CalcBoundingBox( x, y );
749 CalcBoundingBox( x + width, y + height );
750 }
751 }
752
753 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
754 {
755 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
756
757 if (radius < 0.0)
758 {
759 // Now, a negative radius is interpreted to mean
760 // 'the proportion of the smallest X or Y dimension'
761 double smallest = 0.0;
762 if (width < height)
763 smallest = width;
764 else
765 smallest = height;
766 radius = (-radius * smallest);
767 }
768
769 wxCoord rad = (wxCoord) radius;
770
771 if (m_brush.GetStyle () != wxTRANSPARENT)
772 {
773 SetBrush( m_brush );
774
775 /* Draw rectangle anticlockwise */
776 fprintf( m_pstream,
777 "newpath\n"
778 "%d %d %d 90 180 arc\n"
779 "%d %d moveto\n"
780 "%d %d %d 180 270 arc\n"
781 "%d %d lineto\n"
782 "%d %d %d 270 0 arc\n"
783 "%d %d lineto\n"
784 "%d %d %d 0 90 arc\n"
785 "%d %d lineto\n"
786 "closepath\n"
787 "fill\n",
788 XLOG2DEV(x + rad), YLOG2DEV(y + rad), XLOG2DEVREL(rad),
789 XLOG2DEV(x), YLOG2DEV(y + rad),
790 XLOG2DEV(x + rad), YLOG2DEV(y + height - rad), XLOG2DEVREL(rad),
791 XLOG2DEV(x + width - rad), YLOG2DEV(y + height),
792 XLOG2DEV(x + width - rad), YLOG2DEV(y + height - rad), XLOG2DEVREL(rad),
793 XLOG2DEV(x + width), YLOG2DEV(y + rad),
794 XLOG2DEV(x + width - rad), YLOG2DEV(y + rad), XLOG2DEVREL(rad),
795 XLOG2DEV(x + rad), YLOG2DEV(y) );
796
797 CalcBoundingBox( x, y );
798 CalcBoundingBox( x + width, y + height );
799 }
800
801 if (m_pen.GetStyle () != wxTRANSPARENT)
802 {
803 SetPen (m_pen);
804
805 /* Draw rectangle anticlockwise */
806 fprintf( m_pstream,
807 "newpath\n"
808 "%d %d %d 90 180 arc\n"
809 "%d %d moveto\n"
810 "%d %d %d 180 270 arc\n"
811 "%d %d lineto\n"
812 "%d %d %d 270 0 arc\n"
813 "%d %d lineto\n"
814 "%d %d %d 0 90 arc\n"
815 "%d %d lineto\n"
816 "closepath\n"
817 "stroke\n",
818 XLOG2DEV(x + rad), YLOG2DEV(y + rad), XLOG2DEVREL(rad),
819 XLOG2DEV(x), YLOG2DEV(y + rad),
820 XLOG2DEV(x + rad), YLOG2DEV(y + height - rad), XLOG2DEVREL(rad),
821 XLOG2DEV(x + width - rad), YLOG2DEV(y + height),
822 XLOG2DEV(x + width - rad), YLOG2DEV(y + height - rad), XLOG2DEVREL(rad),
823 XLOG2DEV(x + width), YLOG2DEV(y + rad),
824 XLOG2DEV(x + width - rad), YLOG2DEV(y + rad), XLOG2DEVREL(rad),
825 XLOG2DEV(x + rad), YLOG2DEV(y) );
826
827 CalcBoundingBox( x, y );
828 CalcBoundingBox( x + width, y + height );
829 }
830 }
831
832 void wxPostScriptDC::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
833 {
834 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
835
836 if (m_brush.GetStyle () != wxTRANSPARENT)
837 {
838 SetBrush (m_brush);
839
840 fprintf( m_pstream,
841 "newpath\n"
842 "%d %d %d %d 0 360 ellipse\n"
843 "fill\n",
844 XLOG2DEV(x + width / 2), YLOG2DEV(y + height / 2),
845 XLOG2DEVREL(width / 2), YLOG2DEVREL(height / 2) );
846
847 CalcBoundingBox( x - width, y - height );
848 CalcBoundingBox( x + width, y + height );
849 }
850
851 if (m_pen.GetStyle () != wxTRANSPARENT)
852 {
853 SetPen (m_pen);
854
855 fprintf( m_pstream,
856 "newpath\n"
857 "%d %d %d %d 0 360 ellipse\n"
858 "stroke\n",
859 XLOG2DEV(x + width / 2), YLOG2DEV(y + height / 2),
860 XLOG2DEVREL(width / 2), YLOG2DEVREL(height / 2) );
861
862 CalcBoundingBox( x - width, y - height );
863 CalcBoundingBox( x + width, y + height );
864 }
865 }
866
867 void wxPostScriptDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
868 {
869 DrawBitmap( icon, x, y, TRUE );
870 }
871
872 /* this has to be char, not wxChar */
873 static char hexArray[] = "0123456789ABCDEF";
874 static void LocalDecToHex( int dec, char *buf )
875 {
876 int firstDigit = (int)(dec/16.0);
877 int secondDigit = (int)(dec - (firstDigit*16.0));
878 buf[0] = hexArray[firstDigit];
879 buf[1] = hexArray[secondDigit];
880 buf[2] = 0;
881 }
882
883 void wxPostScriptDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool WXUNUSED(useMask) )
884 {
885 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
886
887 if (!bitmap.Ok()) return;
888
889 wxImage image( bitmap );
890
891 if (!image.Ok()) return;
892
893 wxCoord w = image.GetWidth();
894 wxCoord h = image.GetHeight();
895
896 wxCoord ww = XLOG2DEVREL(image.GetWidth());
897 wxCoord hh = YLOG2DEVREL(image.GetHeight());
898
899 wxCoord xx = XLOG2DEV(x);
900 wxCoord yy = YLOG2DEV(y + bitmap.GetHeight());
901
902 fprintf( m_pstream,
903 "/origstate save def\n"
904 "20 dict begin\n"
905 "/pix %d string def\n"
906 "/grays %d string def\n"
907 "/npixels 0 def\n"
908 "/rgbindx 0 def\n"
909 "%d %d translate\n"
910 "%d %d scale\n"
911 "%d %d 8\n"
912 "[%d 0 0 %d 0 %d]\n"
913 "{currentfile pix readhexstring pop}\n"
914 "false 3 colorimage\n",
915 w, w, xx, yy, ww, hh, w, h, w, -h, h );
916
917
918 for (int j = 0; j < h; j++)
919 {
920 for (int i = 0; i < w; i++)
921 {
922 char buffer[5];
923 LocalDecToHex( image.GetRed(i,j), buffer );
924 fprintf( m_pstream, buffer );
925 LocalDecToHex( image.GetGreen(i,j), buffer );
926 fprintf( m_pstream, buffer );
927 LocalDecToHex( image.GetBlue(i,j), buffer );
928 fprintf( m_pstream, buffer );
929 }
930 fprintf( m_pstream, "\n" );
931 }
932
933 fprintf( m_pstream, "end\n" );
934 fprintf( m_pstream, "origstate restore\n" );
935 }
936
937 void wxPostScriptDC::SetFont( const wxFont& font )
938 {
939 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
940
941 if (!font.Ok()) return;
942
943 m_font = font;
944
945 const char *name;
946 const char *style = "";
947 int Style = m_font.GetStyle();
948 int Weight = m_font.GetWeight();
949
950 switch (m_font.GetFamily())
951 {
952 case wxTELETYPE:
953 case wxMODERN:
954 name = "/Courier";
955 break;
956 case wxSWISS:
957 name = "/Helvetica";
958 break;
959 case wxROMAN:
960 // name = "/Times-Roman";
961 name = "/Times"; // Altered by EDZ
962 break;
963 case wxSCRIPT:
964 name = "/Zapf-Chancery-MediumItalic";
965 Style = wxNORMAL;
966 Weight = wxNORMAL;
967 break;
968 default:
969 case wxDEFAULT: // Sans Serif Font
970 name = "/LucidaSans";
971 }
972
973 if (Style == wxNORMAL && (Weight == wxNORMAL || Weight == wxLIGHT))
974 {
975 if (m_font.GetFamily () == wxROMAN)
976 style = "-Roman";
977 else
978 style = "";
979 }
980 else if (Style == wxNORMAL && Weight == wxBOLD)
981 {
982 style = "-Bold";
983 }
984 else if (Style == wxITALIC && (Weight == wxNORMAL || Weight == wxLIGHT))
985 {
986 if (m_font.GetFamily () == wxROMAN)
987 style = "-Italic";
988 else
989 style = "-Oblique";
990 }
991 else if (Style == wxITALIC && Weight == wxBOLD)
992 {
993 if (m_font.GetFamily () == wxROMAN)
994 style = "-BoldItalic";
995 else
996 style = "-BoldOblique";
997 }
998 else if (Style == wxSLANT && (Weight == wxNORMAL || Weight == wxLIGHT))
999 {
1000 if (m_font.GetFamily () == wxROMAN)
1001 style = "-Italic";
1002 else
1003 style = "-Oblique";
1004 }
1005 else if (Style == wxSLANT && Weight == wxBOLD)
1006 {
1007 if (m_font.GetFamily () == wxROMAN)
1008 style = "-BoldItalic";
1009 else
1010 style = "-BoldOblique";
1011 }
1012 else
1013 {
1014 style = "";
1015 }
1016
1017 char buffer[100];
1018 strcpy( buffer, name );
1019 strcat( buffer, style );
1020
1021 fprintf( m_pstream, buffer );
1022 fprintf( m_pstream, " reencodeISO def\n" );
1023 fprintf( m_pstream, buffer );
1024 fprintf( m_pstream, " findfont\n" );
1025
1026 sprintf( buffer, "%f scalefont setfont\n", YLOG2DEVREL(m_font.GetPointSize() * 1000) / 1000.0F);
1027 // this is a hack - we must scale font size (in pts) according to m_scaleY but
1028 // YLOG2DEVREL works with wxCoord type (int or longint). Se we first convert font size
1029 // to 1/1000th of pt and then back.
1030 for (int i = 0; i < 100; i++)
1031 if (buffer[i] == ',') buffer[i] = '.';
1032 fprintf( m_pstream, buffer );
1033 }
1034
1035 void wxPostScriptDC::SetPen( const wxPen& pen )
1036 {
1037 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1038
1039 if (!pen.Ok()) return;
1040
1041 int oldStyle = m_pen.GetStyle();
1042
1043 m_pen = pen;
1044
1045 {
1046 char buffer[100];
1047 #ifdef __WXMSW__
1048 sprintf( buffer, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen.GetWidth()) / 1000.0f );
1049 #else
1050 sprintf( buffer, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen.GetWidth()) / 1000.0f );
1051 #endif
1052 for (int i = 0; i < 100; i++)
1053 if (buffer[i] == ',') buffer[i] = '.';
1054 fprintf( m_pstream, buffer );
1055 }
1056
1057 /*
1058 Line style - WRONG: 2nd arg is OFFSET
1059
1060 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1061 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1062 ter is not number of values in the array of the first one, but an offset
1063 into this description of the pattern. I mean a real *offset* not index
1064 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1065 will be first black line *2* units wxCoord, then space 4 units, then the
1066 pattern of *3* units black, 4 units space will be repeated.
1067 */
1068
1069 static const char *dotted = "[2 5] 2";
1070 static const char *short_dashed = "[4 4] 2";
1071 static const char *wxCoord_dashed = "[4 8] 2";
1072 static const char *dotted_dashed = "[6 6 2 6] 4";
1073
1074 const char *psdash = (char *) NULL;
1075 switch (m_pen.GetStyle())
1076 {
1077 case wxDOT: psdash = dotted; break;
1078 case wxSHORT_DASH: psdash = short_dashed; break;
1079 case wxLONG_DASH: psdash = wxCoord_dashed; break;
1080 case wxDOT_DASH: psdash = dotted_dashed; break;
1081 case wxSOLID:
1082 case wxTRANSPARENT:
1083 default: psdash = "[] 0"; break;
1084 }
1085
1086 if (oldStyle != m_pen.GetStyle())
1087 {
1088 fprintf( m_pstream, psdash );
1089 fprintf( m_pstream," setdash\n" );
1090 }
1091
1092 // Line colour
1093 unsigned char red = m_pen.GetColour().Red();
1094 unsigned char blue = m_pen.GetColour().Blue();
1095 unsigned char green = m_pen.GetColour().Green();
1096
1097 if (!m_colour)
1098 {
1099 // Anything not white is black
1100 if (! (red == (unsigned char) 255 &&
1101 blue == (unsigned char) 255 &&
1102 green == (unsigned char) 255) )
1103 {
1104 red = (unsigned char) 0;
1105 green = (unsigned char) 0;
1106 blue = (unsigned char) 0;
1107 }
1108 // setgray here ?
1109 }
1110
1111 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1112 {
1113 double redPS = (double)(red) / 255.0;
1114 double bluePS = (double)(blue) / 255.0;
1115 double greenPS = (double)(green) / 255.0;
1116
1117 char buffer[100];
1118 sprintf( buffer,
1119 "%.8f %.8f %.8f setrgbcolor\n",
1120 redPS, greenPS, bluePS );
1121 for (int i = 0; i < 100; i++)
1122 if (buffer[i] == ',') buffer[i] = '.';
1123 fprintf( m_pstream, buffer );
1124
1125 m_currentRed = red;
1126 m_currentBlue = blue;
1127 m_currentGreen = green;
1128 }
1129 }
1130
1131 void wxPostScriptDC::SetBrush( const wxBrush& brush )
1132 {
1133 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1134
1135 if (!brush.Ok()) return;
1136
1137 m_brush = brush;
1138
1139 // Brush colour
1140 unsigned char red = m_brush.GetColour().Red();
1141 unsigned char blue = m_brush.GetColour().Blue();
1142 unsigned char green = m_brush.GetColour().Green();
1143
1144 if (!m_colour)
1145 {
1146 // Anything not white is black
1147 if (! (red == (unsigned char) 255 &&
1148 blue == (unsigned char) 255 &&
1149 green == (unsigned char) 255) )
1150 {
1151 red = (unsigned char) 0;
1152 green = (unsigned char) 0;
1153 blue = (unsigned char) 0;
1154 }
1155 // setgray here ?
1156 }
1157
1158 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1159 {
1160 double redPS = (double)(red) / 255.0;
1161 double bluePS = (double)(blue) / 255.0;
1162 double greenPS = (double)(green) / 255.0;
1163
1164 char buffer[100];
1165 sprintf( buffer,
1166 "%.8f %.8f %.8f setrgbcolor\n",
1167 redPS, greenPS, bluePS );
1168 for (int i = 0; i < 100; i++)
1169 if (buffer[i] == ',') buffer[i] = '.';
1170 fprintf( m_pstream, buffer );
1171
1172 m_currentRed = red;
1173 m_currentBlue = blue;
1174 m_currentGreen = green;
1175 }
1176 }
1177
1178 void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
1179 {
1180 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1181
1182 wxCoord text_w, text_h, text_descent;
1183
1184 GetTextExtent(text, &text_w, &text_h, &text_descent);
1185
1186 SetFont( m_font );
1187
1188 if (m_textForegroundColour.Ok())
1189 {
1190 unsigned char red = m_textForegroundColour.Red();
1191 unsigned char blue = m_textForegroundColour.Blue();
1192 unsigned char green = m_textForegroundColour.Green();
1193
1194 if (!m_colour)
1195 {
1196 // Anything not white is black
1197 if (! (red == (unsigned char) 255 &&
1198 blue == (unsigned char) 255 &&
1199 green == (unsigned char) 255))
1200 {
1201 red = (unsigned char) 0;
1202 green = (unsigned char) 0;
1203 blue = (unsigned char) 0;
1204 }
1205 }
1206
1207 // maybe setgray here ?
1208 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1209 {
1210 double redPS = (double)(red) / 255.0;
1211 double bluePS = (double)(blue) / 255.0;
1212 double greenPS = (double)(green) / 255.0;
1213
1214 char buffer[100];
1215 sprintf( buffer,
1216 "%.8f %.8f %.8f setrgbcolor\n",
1217 redPS, greenPS, bluePS );
1218 for (int i = 0; i < 100; i++)
1219 if (buffer[i] == ',') buffer[i] = '.';
1220 fprintf( m_pstream, buffer );
1221
1222 m_currentRed = red;
1223 m_currentBlue = blue;
1224 m_currentGreen = green;
1225 }
1226 }
1227
1228 int size = m_font.GetPointSize();
1229
1230 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1231 // commented by V. Slavik and replaced by accurate version
1232 // - note that there is still rounding error in text_descent!
1233 wxCoord by = y + size - text_descent; // baseline
1234 fprintf( m_pstream, "%d %d moveto\n", XLOG2DEV(x), YLOG2DEV(by) );
1235
1236 /* I don't know how to write char to a stream, so I use a mini string */
1237 char tmpbuf[2];
1238 tmpbuf[1] = 0;
1239
1240 fprintf( m_pstream, "(" );
1241 const wxWX2MBbuf textbuf = text.mb_str();
1242 int len = strlen(textbuf);
1243 int i;
1244 for (i = 0; i < len; i++)
1245 {
1246 int c = (unsigned char) textbuf[i];
1247 if (c == ')' || c == '(' || c == '\\')
1248 {
1249 /* Cope with special characters */
1250 fprintf( m_pstream, "\\" );
1251 tmpbuf[0] = (char) c;
1252 fprintf( m_pstream, tmpbuf );
1253 }
1254 else if ( c >= 128 )
1255 {
1256 /* Cope with character codes > 127 */
1257 fprintf(m_pstream, "\\%o", c);
1258 }
1259 else
1260 {
1261 tmpbuf[0] = (char) c;
1262 fprintf( m_pstream, tmpbuf );
1263 }
1264 }
1265
1266 fprintf( m_pstream, ") show\n" );
1267
1268 if (m_font.GetUnderlined())
1269 {
1270 wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
1271 char buffer[100];
1272
1273 sprintf( buffer,
1274 "gsave\n"
1275 "%d %d moveto\n"
1276 "%f setlinewidth\n"
1277 "%d %d lineto\n"
1278 "stroke\n"
1279 "grestore\n",
1280 XLOG2DEV(x), YLOG2DEV(uy),
1281 m_underlineThickness,
1282 XLOG2DEV(x + text_w), YLOG2DEV(uy) );
1283 for (i = 0; i < 100; i++)
1284 if (buffer[i] == ',') buffer[i] = '.';
1285 fprintf( m_pstream, buffer );
1286 }
1287
1288 CalcBoundingBox( x, y );
1289 CalcBoundingBox( x + size * text.Length() * 2/3 , y );
1290 }
1291
1292 void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle )
1293 {
1294 if (angle == 0.0)
1295 {
1296 DoDrawText(text, x, y);
1297 return;
1298 }
1299
1300 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1301
1302 SetFont( m_font );
1303
1304 if (m_textForegroundColour.Ok())
1305 {
1306 unsigned char red = m_textForegroundColour.Red();
1307 unsigned char blue = m_textForegroundColour.Blue();
1308 unsigned char green = m_textForegroundColour.Green();
1309
1310 if (!m_colour)
1311 {
1312 // Anything not white is black
1313 if (! (red == (unsigned char) 255 &&
1314 blue == (unsigned char) 255 &&
1315 green == (unsigned char) 255))
1316 {
1317 red = (unsigned char) 0;
1318 green = (unsigned char) 0;
1319 blue = (unsigned char) 0;
1320 }
1321 }
1322
1323 // maybe setgray here ?
1324 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1325 {
1326 double redPS = (double)(red) / 255.0;
1327 double bluePS = (double)(blue) / 255.0;
1328 double greenPS = (double)(green) / 255.0;
1329
1330 char buffer[100];
1331 sprintf( buffer,
1332 "%.8f %.8f %.8f setrgbcolor\n",
1333 redPS, greenPS, bluePS );
1334 for (int i = 0; i < 100; i++)
1335 if (buffer[i] == ',') buffer[i] = '.';
1336 fprintf( m_pstream, buffer );
1337
1338 m_currentRed = red;
1339 m_currentBlue = blue;
1340 m_currentGreen = green;
1341 }
1342 }
1343
1344 int size = m_font.GetPointSize();
1345
1346 long by = y + (long)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1347
1348 // FIXME only correct for 90 degrees
1349 fprintf(m_pstream, "%d %d moveto\n",
1350 XLOG2DEV((wxCoord)(x + size)), YLOG2DEV((wxCoord)by) );
1351
1352 char buffer[100];
1353 sprintf(buffer, "%.8f rotate\n", angle);
1354 int i;
1355 for (i = 0; i < 100; i++)
1356 if (buffer[i] == ',') buffer[i] = '.';
1357 fprintf(m_pstream, buffer);
1358
1359 /* I don't know how to write char to a stream, so I use a mini string */
1360 char tmpbuf[2];
1361 tmpbuf[1] = 0;
1362
1363 fprintf( m_pstream, "(" );
1364 const wxWX2MBbuf textbuf = text.mb_str();
1365 int len = strlen(textbuf);
1366 for (i = 0; i < len; i++)
1367 {
1368 int c = (unsigned char) textbuf[i];
1369 if (c == ')' || c == '(' || c == '\\')
1370 {
1371 /* Cope with special characters */
1372 fprintf( m_pstream, "\\" );
1373 tmpbuf[0] = (char) c;
1374 fprintf( m_pstream, tmpbuf );
1375 }
1376 else if ( c >= 128 )
1377 {
1378 /* Cope with character codes > 127 */
1379 fprintf(m_pstream, "\\%o", c);
1380 }
1381 else
1382 {
1383 tmpbuf[0] = (char) c;
1384 fprintf( m_pstream, tmpbuf );
1385 }
1386 }
1387
1388 fprintf( m_pstream, ") show\n" );
1389
1390 sprintf( buffer, "%.8f rotate\n", -angle );
1391 for (i = 0; i < 100; i++)
1392 if (buffer[i] == ',') buffer[i] = '.';
1393 fprintf( m_pstream, buffer );
1394
1395 if (m_font.GetUnderlined())
1396 {
1397 wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
1398 wxCoord w, h;
1399 char buffer[100];
1400 GetTextExtent(text, &w, &h);
1401
1402 sprintf( buffer,
1403 "gsave\n"
1404 "%d %d moveto\n"
1405 "%f setlinewidth\n"
1406 "%d %d lineto\n"
1407 "stroke\n"
1408 "grestore\n",
1409 XLOG2DEV(x), YLOG2DEV(uy),
1410 m_underlineThickness,
1411 XLOG2DEV(x + w), YLOG2DEV(uy) );
1412 for (i = 0; i < 100; i++)
1413 if (buffer[i] == ',') buffer[i] = '.';
1414 fprintf( m_pstream, buffer );
1415 }
1416
1417 CalcBoundingBox( x, y );
1418 CalcBoundingBox( x + size * text.Length() * 2/3 , y );
1419 }
1420
1421 void wxPostScriptDC::SetBackground (const wxBrush& brush)
1422 {
1423 m_backgroundBrush = brush;
1424 }
1425
1426 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function))
1427 {
1428 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1429 }
1430
1431 void wxPostScriptDC::DoDrawSpline( wxList *points )
1432 {
1433 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1434
1435 SetPen( m_pen );
1436
1437 double a, b, c, d, x1, y1, x2, y2, x3, y3;
1438 wxPoint *p, *q;
1439
1440 wxNode *node = points->First();
1441 p = (wxPoint *)node->Data();
1442 x1 = p->x;
1443 y1 = p->y;
1444
1445 node = node->Next();
1446 p = (wxPoint *)node->Data();
1447 c = p->x;
1448 d = p->y;
1449 x3 = a = (double)(x1 + c) / 2;
1450 y3 = b = (double)(y1 + d) / 2;
1451
1452 fprintf( m_pstream,
1453 "newpath\n"
1454 "%d %d moveto\n"
1455 "%d %d lineto\n",
1456 XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1),
1457 XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
1458
1459 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1460 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1461
1462 while ((node = node->Next()) != NULL)
1463 {
1464 q = (wxPoint *)node->Data();
1465
1466 x1 = x3;
1467 y1 = y3;
1468 x2 = c;
1469 y2 = d;
1470 c = q->x;
1471 d = q->y;
1472 x3 = (double)(x2 + c) / 2;
1473 y3 = (double)(y2 + d) / 2;
1474
1475 fprintf( m_pstream,
1476 "%d %d %d %d %d %d DrawSplineSection\n",
1477 XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1),
1478 XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2),
1479 XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
1480
1481 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1482 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
1483 }
1484
1485 /*
1486 At this point, (x2,y2) and (c,d) are the position of the
1487 next-to-last and last point respectively, in the point list
1488 */
1489
1490 fprintf( m_pstream,
1491 "%d %d lineto\n"
1492 "stroke\n",
1493 XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) );
1494 }
1495
1496 wxCoord wxPostScriptDC::GetCharWidth() const
1497 {
1498 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1499 return (wxCoord) (GetCharHeight() * 72.0 / 120.0);
1500 }
1501
1502
1503 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
1504 {
1505 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1506
1507 m_signX = (xLeftRight ? 1 : -1);
1508 m_signY = (yBottomUp ? 1 : -1);
1509
1510 // FIXME there is no such function in MSW nor in OS2/PM
1511 #if !defined(__WXMSW__) && !defined(__WXPM__)
1512 ComputeScaleAndOrigin();
1513 #endif
1514 }
1515
1516 void wxPostScriptDC::SetDeviceOrigin( wxCoord x, wxCoord y )
1517 {
1518 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1519
1520 int h = 0;
1521 int w = 0;
1522 GetSize( &w, &h );
1523
1524 wxDC::SetDeviceOrigin( x, h-y );
1525 }
1526
1527 void wxPostScriptDC::DoGetSize(int* width, int* height) const
1528 {
1529 wxPaperSize id = m_printData.GetPaperId();
1530
1531 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id);
1532
1533 if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
1534
1535 int w = 595;
1536 int h = 842;
1537 if (paper)
1538 {
1539 w = paper->GetSizeDeviceUnits().x;
1540 h = paper->GetSizeDeviceUnits().y;
1541 }
1542
1543 if (m_printData.GetOrientation() == wxLANDSCAPE)
1544 {
1545 int tmp = w;
1546 w = h;
1547 h = tmp;
1548 }
1549
1550 if (width) *width = (int)(w * ms_PSScaleFactor);
1551 if (height) *height = (int)(h * ms_PSScaleFactor);
1552 }
1553
1554 void wxPostScriptDC::DoGetSizeMM(int *width, int *height) const
1555 {
1556 wxPaperSize id = m_printData.GetPaperId();
1557
1558 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id);
1559
1560 if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
1561
1562 int w = 210;
1563 int h = 297;
1564 if (paper)
1565 {
1566 w = paper->GetWidth() / 10;
1567 h = paper->GetHeight() / 10;
1568 }
1569
1570 if (m_printData.GetOrientation() == wxLANDSCAPE)
1571 {
1572 int tmp = w;
1573 w = h;
1574 h = tmp;
1575 }
1576
1577 if (width) *width = w;
1578 if (height) *height = h;
1579 }
1580
1581 // Resolution in pixels per logical inch
1582 wxSize wxPostScriptDC::GetPPI(void) const
1583 {
1584 return wxSize((int)(72 * ms_PSScaleFactor),
1585 (int)(72 * ms_PSScaleFactor));
1586 }
1587
1588
1589 bool wxPostScriptDC::StartDoc( const wxString& message )
1590 {
1591 wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") );
1592
1593 if (m_printData.GetFilename() == "")
1594 {
1595 wxString filename = wxGetTempFileName("ps");
1596 m_printData.SetFilename(filename);
1597 }
1598
1599 m_pstream = fopen( m_printData.GetFilename().fn_str(), "w+" );
1600
1601 if (!m_pstream)
1602 {
1603 wxLogError( _("Cannot open file for PostScript printing!"));
1604 m_ok = FALSE;
1605 return FALSE;
1606 }
1607
1608 m_ok = TRUE;
1609
1610 fprintf( m_pstream, "%%%%BeginProlog\n" );
1611 fprintf( m_pstream, wxPostScriptHeaderEllipse );
1612 fprintf( m_pstream, wxPostScriptHeaderEllipticArc );
1613 fprintf( m_pstream, wxPostScriptHeaderColourImage );
1614 fprintf( m_pstream, wxPostScriptHeaderReencodeISO1 );
1615 fprintf( m_pstream, wxPostScriptHeaderReencodeISO2 );
1616 if (wxPostScriptHeaderSpline)
1617 fprintf( m_pstream, wxPostScriptHeaderSpline );
1618 fprintf( m_pstream, "%%%%EndProlog\n" );
1619
1620 SetBrush( *wxBLACK_BRUSH );
1621 SetPen( *wxBLACK_PEN );
1622 SetBackground( *wxWHITE_BRUSH );
1623 SetTextForeground( *wxBLACK );
1624
1625 // set origin according to paper size
1626 SetDeviceOrigin( 0,0 );
1627
1628 wxPageNumber = 1;
1629 m_pageNumber = 1;
1630 m_title = message;
1631 return TRUE;
1632 }
1633
1634 void wxPostScriptDC::EndDoc ()
1635 {
1636 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1637
1638 if (m_clipping)
1639 {
1640 m_clipping = FALSE;
1641 fprintf( m_pstream, "grestore\n" );
1642 }
1643
1644 fclose( m_pstream );
1645 m_pstream = (FILE *) NULL;
1646
1647 wxChar *header_file = wxGetTempFileName("ps");
1648
1649 m_pstream = fopen( wxConvFile.cWX2MB(header_file) , "w+" );
1650
1651 fprintf( m_pstream, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings
1652 fprintf( m_pstream, "%%%%Title: %s\n", (const char *)m_title.mb_str() );
1653 fprintf( m_pstream, "%%%%Creator: %s\n", (const char*)wxConvCurrent->cWX2MB(wxTheApp->argv[0]) );
1654 fprintf( m_pstream, "%%%%CreationDate: %s\n", (const char *)wxNow().mb_str() );
1655
1656 wxChar userID[256];
1657 if ( wxGetEmailAddress(userID, sizeof(userID)) )
1658 {
1659 fprintf( m_pstream, "%%%%For: %s ", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userID) );
1660 wxChar userName[245];
1661 if (wxGetUserName(userName, sizeof(userName)))
1662 fprintf( m_pstream, " (%s)", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userName) );
1663 fprintf( m_pstream, "\n" );
1664 }
1665 else if ( wxGetUserName(userID, sizeof(userID)) )
1666 {
1667 fprintf( m_pstream, "%%%%For: %s\n", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userID) );;
1668 }
1669
1670 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1671
1672 wxCoord wx_printer_translate_x, wx_printer_translate_y;
1673 double wx_printer_scale_x, wx_printer_scale_y;
1674
1675 wx_printer_translate_x = (wxCoord)m_printData.GetPrinterTranslateX();
1676 wx_printer_translate_y = (wxCoord)m_printData.GetPrinterTranslateY();
1677
1678 wx_printer_scale_x = m_printData.GetPrinterScaleX();
1679 wx_printer_scale_y = m_printData.GetPrinterScaleY();
1680
1681 if (m_printData.GetOrientation() == wxLANDSCAPE)
1682 fprintf( m_pstream, "%%%%Orientation: Landscape\n" );
1683 else
1684 fprintf( m_pstream, "%%%%Orientation: Portrait\n" );
1685
1686 // Compute the bounding box. Note that it is in the default user
1687 // coordinate system, thus we have to convert the values.
1688 wxCoord llx = (wxCoord) ((XLOG2DEV(m_minX)+wx_printer_translate_x)*wx_printer_scale_x);
1689 wxCoord lly = (wxCoord) ((YLOG2DEV(m_minY)+wx_printer_translate_y)*wx_printer_scale_y);
1690 wxCoord urx = (wxCoord) ((XLOG2DEV(m_maxX)+wx_printer_translate_x)*wx_printer_scale_x);
1691 wxCoord ury = (wxCoord) ((YLOG2DEV(m_maxY)+wx_printer_translate_y)*wx_printer_scale_y);
1692
1693 // If we're landscape, our sense of "x" and "y" is reversed.
1694 if (m_printData.GetOrientation() == wxLANDSCAPE)
1695 {
1696 wxCoord tmp;
1697 tmp = llx; llx = lly; lly = tmp;
1698 tmp = urx; urx = ury; ury = tmp;
1699
1700 // We need either the two lines that follow, or we need to subtract
1701 // min_x from real_translate_y, which is commented out below.
1702 llx = llx - (wxCoord)(m_minX*wx_printer_scale_y);
1703 urx = urx - (wxCoord)(m_minX*wx_printer_scale_y);
1704 }
1705
1706 // The Adobe specifications call for integers; we round as to make
1707 // the bounding larger.
1708 fprintf( m_pstream,
1709 "%%%%BoundingBox: %d %d %d %d\n",
1710 (wxCoord)floor((double)llx), (wxCoord)floor((double)lly),
1711 (wxCoord)ceil((double)urx), (wxCoord)ceil((double)ury) );
1712 fprintf( m_pstream, "%%%%Pages: %d\n", (wxPageNumber - 1) );
1713 fprintf( m_pstream, "%%%%EndComments\n\n" );
1714
1715 // To check the correctness of the bounding box, postscript commands
1716 // to draw a box corresponding to the bounding box are generated below.
1717 // But since we typically don't want to print such a box, the postscript
1718 // commands are generated within comments. These lines appear before any
1719 // adjustment of scale, rotation, or translation, and hence are in the
1720 // default user coordinates.
1721 fprintf( m_pstream, "%% newpath\n" );
1722 fprintf( m_pstream, "%% %d %d moveto\n", llx, lly );
1723 fprintf( m_pstream, "%% %d %d lineto\n", urx, lly );
1724 fprintf( m_pstream, "%% %d %d lineto\n", urx, ury );
1725 fprintf( m_pstream, "%% %d %d lineto closepath stroke\n", llx, ury );
1726
1727 fclose( m_pstream );
1728 m_pstream = (FILE*) NULL;
1729
1730 wxChar *tmp_file = wxGetTempFileName("ps");
1731
1732 // Paste header Before wx_printer_file
1733 wxConcatFiles (header_file, m_printData.GetFilename(), tmp_file );
1734 wxRemoveFile( header_file );
1735 wxRemoveFile( m_printData.GetFilename() );
1736 wxRenameFile( tmp_file, m_printData.GetFilename() );
1737
1738 #if defined(__X__) || defined(__WXGTK__)
1739 if (m_ok)
1740 {
1741 wxString previewCommand(m_printData.GetPreviewCommand());
1742 wxString printerCommand(m_printData.GetPrinterCommand());
1743 wxString printerOptions(m_printData.GetPrinterOptions());
1744 wxString filename(m_printData.GetFilename());
1745
1746 switch (m_printData.GetPrintMode())
1747 {
1748 case wxPRINT_MODE_PREVIEW:
1749 {
1750 wxChar *argv[3];
1751 argv[0] = WXSTRINGCAST previewCommand;
1752 argv[1] = WXSTRINGCAST filename;
1753 argv[2] = (wxChar*) NULL;
1754 wxExecute( argv, TRUE );
1755 wxRemoveFile( m_printData.GetFilename() );
1756 }
1757 break;
1758 case wxPRINT_MODE_PRINTER:
1759 {
1760 wxChar *argv[4];
1761 int argc = 0;
1762 argv[argc++] = WXSTRINGCAST printerCommand;
1763
1764 // !SM! If we simply assign to argv[1] here, if printer options
1765 // are blank, we get an annoying and confusing message from lpr.
1766 wxChar *opts = WXSTRINGCAST printerOptions;
1767 if (opts && *opts)
1768 argv[argc++] = opts;
1769
1770 argv[argc++] = WXSTRINGCAST filename;
1771 argv[argc++] = (wxChar *) NULL;
1772 wxExecute( argv, TRUE );
1773 wxRemoveFile( filename );
1774 }
1775 break;
1776 case wxPRINT_MODE_FILE:
1777 case wxPRINT_MODE_NONE:
1778 break;
1779 }
1780 }
1781 #endif
1782 }
1783
1784 void wxPostScriptDC::StartPage()
1785 {
1786 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1787
1788 fprintf( m_pstream, "%%%%Page: %d\n", wxPageNumber++ );
1789
1790 // What is this one supposed to do? RR.
1791 // *m_pstream << "matrix currentmatrix\n";
1792
1793 // Added by Chris Breeze
1794
1795 // Each page starts with an "initgraphics" which resets the
1796 // transformation and so we need to reset the origin
1797 // (and rotate the page for landscape printing)
1798
1799 // Output scaling
1800 wxCoord translate_x, translate_y;
1801 double scale_x, scale_y;
1802
1803 translate_x = (wxCoord)m_printData.GetPrinterTranslateX();
1804 translate_y = (wxCoord)m_printData.GetPrinterTranslateY();
1805
1806 scale_x = m_printData.GetPrinterScaleX();
1807 scale_y = m_printData.GetPrinterScaleY();
1808
1809 if (m_printData.GetOrientation() == wxLANDSCAPE)
1810 {
1811 int h;
1812 GetSize( (int*) NULL, &h );
1813 translate_y -= h;
1814 fprintf( m_pstream, "90 rotate\n" );
1815
1816 // I copied this one from a PostScript tutorial, but to no avail. RR.
1817 // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" );
1818 }
1819
1820 char buffer[100];
1821 sprintf( buffer, "%.8f %.8f scale\n", scale_x / ms_PSScaleFactor,
1822 scale_y / ms_PSScaleFactor);
1823 for (int i = 0; i < 100; i++)
1824 if (buffer[i] == ',') buffer[i] = '.';
1825 fprintf( m_pstream, buffer );
1826
1827 fprintf( m_pstream, "%d %d translate\n", translate_x, translate_y );
1828 }
1829
1830 void wxPostScriptDC::EndPage ()
1831 {
1832 wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
1833
1834 fprintf( m_pstream, "showpage\n" );
1835 }
1836
1837 bool wxPostScriptDC::DoBlit( wxCoord xdest, wxCoord ydest,
1838 wxCoord fwidth, wxCoord fheight,
1839 wxDC *source,
1840 wxCoord xsrc, wxCoord ysrc,
1841 int rop, bool WXUNUSED(useMask) )
1842 {
1843 wxCHECK_MSG( m_ok && m_pstream, FALSE, wxT("invalid postscript dc") );
1844
1845 wxCHECK_MSG( source, FALSE, wxT("invalid source dc") );
1846
1847 /* blit into a bitmap */
1848 wxBitmap bitmap( (int)fwidth, (int)fheight );
1849 wxMemoryDC memDC;
1850 memDC.SelectObject(bitmap);
1851 memDC.Blit(0, 0, fwidth, fheight, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */
1852 memDC.SelectObject(wxNullBitmap);
1853
1854 /* draw bitmap. scaling and positioning is done there */
1855 DrawBitmap( bitmap, xdest, ydest );
1856
1857 return TRUE;
1858 }
1859
1860 wxCoord wxPostScriptDC::GetCharHeight() const
1861 {
1862 if (m_font.Ok())
1863 return m_font.GetPointSize();
1864 else
1865 return 12;
1866 }
1867
1868 void wxPostScriptDC::DoGetTextExtent(const wxString& string,
1869 wxCoord *x, wxCoord *y,
1870 wxCoord *descent, wxCoord *externalLeading,
1871 wxFont *theFont ) const
1872 {
1873 wxFont *fontToUse = theFont;
1874
1875 if (!fontToUse) fontToUse = (wxFont*) &m_font;
1876
1877 wxCHECK_RET( fontToUse, wxT("GetTextExtent: no font defined") );
1878
1879 const wxWX2MBbuf strbuf = string.mb_str();
1880
1881 #if !wxUSE_AFM_FOR_POSTSCRIPT
1882 /* Provide a VERY rough estimate (avoid using it).
1883 * Produces accurate results for mono-spaced font
1884 * such as Courier (aka wxMODERN) */
1885
1886 int height = 12;
1887 if (fontToUse)
1888 {
1889 height = fontToUse->GetPointSize();
1890 }
1891 if ( x )
1892 *x = strlen (strbuf) * height * 72 / 120;
1893 if ( y )
1894 *y = (wxCoord) (height * 1.32); /* allow for descender */
1895 if (descent) *descent = 0;
1896 if (externalLeading) *externalLeading = 0;
1897 #else
1898
1899 /* method for calculating string widths in postscript:
1900 / read in the AFM (adobe font metrics) file for the
1901 / actual font, parse it and extract the character widths
1902 / and also the descender. this may be improved, but for now
1903 / it works well. the AFM file is only read in if the
1904 / font is changed. this may be chached in the future.
1905 / calls to GetTextExtent with the font unchanged are rather
1906 / efficient!!!
1907 /
1908 / for each font and style used there is an AFM file necessary.
1909 / currently i have only files for the roman font family.
1910 / I try to get files for the other ones!
1911 /
1912 / CAVE: the size of the string is currently always calculated
1913 / in 'points' (1/72 of an inch). this should later on be
1914 / changed to depend on the mapping mode.
1915 / CAVE: the path to the AFM files must be set before calling this
1916 / function. this is usually done by a call like the following:
1917 / wxSetAFMPath("d:\\wxw161\\afm\\");
1918 /
1919 / example:
1920 /
1921 / wxPostScriptDC dc(NULL, TRUE);
1922 / if (dc.Ok()){
1923 / wxSetAFMPath("d:\\wxw161\\afm\\");
1924 / dc.StartDoc("Test");
1925 / dc.StartPage();
1926 / wxCoord w,h;
1927 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1928 / dc.GetTextExtent("Hallo",&w,&h);
1929 / dc.EndPage();
1930 / dc.EndDoc();
1931 / }
1932 /
1933 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1934 / created: 10.09.94
1935 / updated: 14.05.95 */
1936
1937 /* these static vars are for storing the state between calls */
1938 static int lastFamily= INT_MIN;
1939 static int lastSize= INT_MIN;
1940 static int lastStyle= INT_MIN;
1941 static int lastWeight= INT_MIN;
1942 static int lastDescender = INT_MIN;
1943 static int lastWidths[256]; /* widths of the characters */
1944
1945 double UnderlinePosition = 0.0;
1946 double UnderlineThickness = 0.0;
1947
1948 /* get actual parameters */
1949 const int Family = fontToUse->GetFamily();
1950 const int Size = fontToUse->GetPointSize();
1951 const int Style = fontToUse->GetStyle();
1952 const int Weight = fontToUse->GetWeight();
1953
1954 /* if we have another font, read the font-metrics */
1955 if (Family!=lastFamily || Size!=lastSize || Style!=lastStyle || Weight!=lastWeight)
1956 {
1957 /* store actual values */
1958 lastFamily = Family;
1959 lastSize = Size;
1960 lastStyle = Style;
1961 lastWeight = Weight;
1962
1963 char *name = (char*) NULL;
1964
1965 switch (Family)
1966 {
1967 case wxMODERN:
1968 {
1969 if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "CourBoO";
1970 else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "CourBo";
1971 else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "CourO";
1972 else name = "Cour";
1973 }
1974 break;
1975 case wxROMAN:
1976 {
1977 if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "TimesBoO";
1978 else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "TimesBo";
1979 else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "TimesO";
1980 else name = "TimesRo";
1981 }
1982 break;
1983 default:
1984 {
1985 if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "HelvBoO";
1986 else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "HelvBo";
1987 else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "HelvO";
1988 else name = "Helv";
1989 }
1990 break;
1991 }
1992
1993 /* get the directory of the AFM files */
1994 wxString afmName = wxEmptyString;
1995 if (!m_printData.GetFontMetricPath().IsEmpty())
1996 {
1997 afmName = m_printData.GetFontMetricPath();
1998 }
1999
2000 /* 2. open and process the file
2001 / a short explanation of the AFM format:
2002 / we have for each character a line, which gives its size
2003 / e.g.:
2004 /
2005 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2006 /
2007 / that means, we have a character with ascii code 63, and width
2008 / (444/1000 * fontSize) points.
2009 / the other data is ignored for now!
2010 /
2011 / when the font has changed, we read in the right AFM file and store the
2012 / character widths in an array, which is processed below (see point 3.). */
2013
2014 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
2015
2016 afmName << name << wxT(".afm");
2017 FILE *afmFile = wxFopen(afmName,wxT("r"));
2018 if (afmFile==NULL)
2019 {
2020 afmName = wxThePrintSetupData->GetAFMPath();
2021 afmName << wxFILE_SEP_PATH << name << wxT(".afm");
2022 afmFile = wxFopen(afmName,wxT("r"));
2023 }
2024
2025 #ifdef __UNIX__
2026 #ifndef __VMS__
2027 if (afmFile==NULL)
2028 /* please do NOT change the line above to "else if (afmFile==NULL)" -
2029 - afmFile = fopen() may fail and in that case the next if branch
2030 MUST be executed - and it would not if there was "else" */
2031 {
2032 afmName = wxINSTALL_PREFIX;
2033 afmName << wxFILE_SEP_PATH
2034 << wxT("share") << wxFILE_SEP_PATH
2035 << wxT("wx") << wxFILE_SEP_PATH
2036 << wxT("afm") << wxFILE_SEP_PATH
2037 << name << wxT(".afm");
2038 afmFile = wxFopen(afmName,wxT("r"));
2039 }
2040 #endif
2041 #endif
2042
2043 if (afmFile==NULL)
2044 {
2045 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%hs'\n"), afmName.c_str() );
2046 wxLogDebug( wxT(" using approximate values\n"));
2047 for (int i=0; i<256; i++) lastWidths[i] = 500; /* an approximate value */
2048 lastDescender = -150; /* dito. */
2049 }
2050 else
2051 {
2052 /* init the widths array */
2053 for(int i=0; i<256; i++) lastWidths[i] = INT_MIN;
2054 /* some variables for holding parts of a line */
2055 char cString[10],semiString[10],WXString[10],descString[20];
2056 char upString[30], utString[30], encString[50];
2057 char line[256];
2058 int ascii,cWidth;
2059 /* read in the file and parse it */
2060 while(fgets(line,sizeof(line),afmFile)!=NULL)
2061 {
2062 /* A.) check for descender definition */
2063 if (strncmp(line,"Descender",9)==0)
2064 {
2065 if ((sscanf(line,"%s%d",descString,&lastDescender)!=2) ||
2066 (strcmp(descString,"Descender")!=0))
2067 {
2068 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad descender)\n"), afmName.c_str(),line );
2069 }
2070 }
2071 /* JC 1.) check for UnderlinePosition */
2072 else if(strncmp(line,"UnderlinePosition",17)==0)
2073 {
2074 if ((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) ||
2075 (strcmp(upString,"UnderlinePosition")!=0))
2076 {
2077 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlinePosition)\n"), afmName.c_str(), line );
2078 }
2079 }
2080 /* JC 2.) check for UnderlineThickness */
2081 else if(strncmp(line,"UnderlineThickness",18)==0)
2082 {
2083 if ((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) ||
2084 (strcmp(utString,"UnderlineThickness")!=0))
2085 {
2086 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlineThickness)\n"), afmName.c_str(), line );
2087 }
2088 }
2089 /* JC 3.) check for EncodingScheme */
2090 else if(strncmp(line,"EncodingScheme",14)==0)
2091 {
2092 if ((sscanf(line,"%s%s",utString,encString)!=2) ||
2093 (strcmp(utString,"EncodingScheme")!=0))
2094 {
2095 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad EncodingScheme)\n"), afmName.c_str(), line );
2096 }
2097 else if (strncmp(encString, "AdobeStandardEncoding", 21))
2098 {
2099 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (unsupported EncodingScheme %hs)\n"),
2100 afmName.c_str(),line, encString);
2101 }
2102 }
2103 /* B.) check for char-width */
2104 else if(strncmp(line,"C ",2)==0)
2105 {
2106 if (sscanf(line,"%s%d%s%s%d",cString,&ascii,semiString,WXString,&cWidth)!=5)
2107 {
2108 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has an error (bad character width)\n"),afmName.c_str(),line);
2109 }
2110 if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 || strcmp(WXString,"WX")!=0)
2111 {
2112 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has a format error\n"),afmName.c_str(),line);
2113 }
2114 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2115 if (ascii>=0 && ascii<256)
2116 {
2117 lastWidths[ascii] = cWidth; /* store width */
2118 }
2119 else
2120 {
2121 /* MATTHEW: this happens a lot; don't print an error */
2122 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName.c_str(),ascii); */
2123 }
2124 }
2125 /* C.) ignore other entries. */
2126 }
2127 fclose(afmFile);
2128 }
2129 /* hack to compute correct values for german 'Umlaute'
2130 / the correct way would be to map the character names
2131 / like 'adieresis' to corresp. positions of ISOEnc and read
2132 / these values from AFM files, too. Maybe later ... */
2133 lastWidths[196] = lastWidths['A']; // Ä
2134 lastWidths[228] = lastWidths['a']; // ä
2135 lastWidths[214] = lastWidths['O']; // Ö
2136 lastWidths[246] = lastWidths['o']; // ö
2137 lastWidths[220] = lastWidths['U']; // Ü
2138 lastWidths[252] = lastWidths['u']; // ü
2139 lastWidths[223] = lastWidths[251]; // ß
2140
2141 /* JC: calculate UnderlineThickness/UnderlinePosition */
2142
2143 // VS: dirty, but is there any better solution?
2144 double *pt;
2145 pt = (double*) &m_underlinePosition;
2146 *pt = YLOG2DEVREL((wxCoord)(UnderlinePosition * fontToUse->GetPointSize())) / 1000.0f;
2147 pt = (double*) &m_underlineThickness;
2148 *pt = YLOG2DEVREL((wxCoord)(UnderlineThickness * fontToUse->GetPointSize())) / 1000.0f;
2149
2150 }
2151
2152
2153 /* 3. now the font metrics are read in, calc size this
2154 / is done by adding the widths of the characters in the
2155 / string. they are given in 1/1000 of the size! */
2156
2157 double widthSum=0;
2158 wxCoord height=Size; /* by default */
2159 unsigned char *p;
2160 for(p=(unsigned char *)wxMBSTRINGCAST strbuf; *p; p++)
2161 {
2162 if(lastWidths[*p]== INT_MIN)
2163 {
2164 wxLogDebug(wxT("GetTextExtent: undefined width for character '%hc' (%d)\n"), *p,*p);
2165 widthSum += (lastWidths[' ']/1000.0F * Size); /* assume space */
2166 }
2167 else
2168 {
2169 widthSum += ((lastWidths[*p]/1000.0F)*Size);
2170 }
2171 }
2172
2173 /* add descender to height (it is usually a negative value) */
2174 //if (lastDescender != INT_MIN)
2175 //{
2176 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2177 //}
2178 // - commented by V. Slavik - height already contains descender in it
2179 // (judging from few experiments)
2180
2181 /* return size values */
2182 if ( x )
2183 *x = (wxCoord)widthSum;
2184 if ( y )
2185 *y = height;
2186
2187 /* return other parameters */
2188 if (descent)
2189 {
2190 if(lastDescender!=INT_MIN)
2191 {
2192 *descent = (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2193 }
2194 else
2195 {
2196 *descent = 0;
2197 }
2198 }
2199
2200 /* currently no idea how to calculate this! */
2201 if (externalLeading) *externalLeading = 0;
2202
2203 #endif
2204 }
2205
2206 // Determine the Default Postscript Previewer
2207 // available on the platform
2208 #if defined(__SUN__) && defined(__XVIEW__)
2209 // OpenWindow/NeWS's Postscript Previewer
2210 # define PS_VIEWER_PROG "pageview"
2211 #elif defined(__VMS__)
2212 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
2213 #elif defined(__SGI__)
2214 // SGI's Display Postscript Previewer
2215 //# define PS_VIEWER_PROG "dps"
2216 # define PS_VIEWER_PROG "xpsview"
2217 #elif defined(__X__) || defined(__WXGTK__)
2218 // Front-end to ghostscript
2219 # define PS_VIEWER_PROG "ghostview"
2220 #else
2221 // Windows ghostscript/ghostview
2222 # define PS_VIEWER_PROG "gsview"
2223 #endif
2224
2225 wxPrintSetupData *wxThePrintSetupData = (wxPrintSetupData *) NULL;
2226
2227 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC)
2228 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData, wxObject)
2229
2230 // Redundant now I think
2231 #if 1
2232 IMPLEMENT_CLASS(wxPostScriptPrintDialog, wxDialog)
2233
2234 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow *parent, const wxString& title,
2235 const wxPoint& pos, const wxSize& size, wxCoord style):
2236 wxDialog(parent, -1, title, pos, size, style)
2237 {
2238 wxBeginBusyCursor();
2239
2240 char buf[100];
2241 int yPos = 40;
2242 wxString
2243 *orientation = new wxString[2],
2244 *print_modes = new wxString[3];
2245 int features;
2246 wxCoord wx_printer_translate_x, wx_printer_translate_y;
2247 double wx_printer_scale_x, wx_printer_scale_y;
2248
2249 orientation[0] = _("Portrait");
2250 orientation[1] = _("Landscape");
2251
2252 print_modes[0] = _("Send to Printer");
2253 print_modes[1] = _("Print to File");
2254 print_modes[2] = _("Preview Only");
2255
2256
2257
2258 wxButton *okBut = new wxButton (this, wxID_OK, _("OK"), wxPoint(5, 5));
2259 (void) new wxButton (this, wxID_CANCEL, _("Cancel"), wxPoint(40, 5));
2260 okBut->SetDefault();
2261
2262
2263 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2264 (void) new wxStaticText( this, -1, _("Printer Command: "),
2265 wxPoint(5, yPos) );
2266 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND, wxThePrintSetupData->GetPrinterCommand(),
2267 wxPoint(100, yPos), wxSize(100, -1) );
2268
2269 (void) new wxStaticText( this, -1, _("Printer Options: "),
2270 wxPoint(210, yPos) );
2271 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS, wxThePrintSetupData->GetPrinterOptions(),
2272 wxPoint(305, yPos), wxSize(150, -1) );
2273
2274 yPos += 40;
2275 #endif
2276
2277
2278 wxRadioBox *radio0 = new wxRadioBox(this, wxID_PRINTER_ORIENTATION, "Orientation: ", wxPoint(5, yPos), wxSize(-1,-1),
2279 2,orientation,2,wxRA_SPECIFY_ROWS);
2280 radio0->SetSelection((int)wxThePrintSetupData->GetPrinterOrientation() - 1);
2281
2282 // @@@ Configuration hook
2283 if ( !wxThePrintSetupData->GetPrintPreviewCommand() )
2284 wxThePrintSetupData->SetPrintPreviewCommand(PS_VIEWER_PROG);
2285
2286 // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand);
2287
2288 features = (wxThePrintSetupData->GetPrintPreviewCommand() &&
2289 *wxThePrintSetupData->GetPrintPreviewCommand()) ? 3 : 2;
2290
2291 wxRadioBox *radio1 = new wxRadioBox(this, wxID_PRINTER_MODES, _("PostScript:"),
2292 wxPoint(150, yPos),
2293 wxSize(-1,-1), features,
2294 print_modes, features, wxRA_SPECIFY_ROWS);
2295
2296 #ifdef __WXMSW__
2297 radio1->Enable(0, FALSE);
2298 if (wxThePrintSetupData->GetPrintPreviewCommand() && *wxThePrintSetupData->GetPrintPreviewCommand())
2299 radio1->Enable(2, FALSE);
2300 #endif
2301
2302 radio1->SetSelection((int)wxThePrintSetupData->GetPrinterMode());
2303 wxThePrintSetupData->GetPrinterTranslation(&wx_printer_translate_x, &wx_printer_translate_y);
2304 wxThePrintSetupData->GetPrinterScaling(&wx_printer_scale_x, &wx_printer_scale_y);
2305
2306 sprintf (buf, "%.2f", wx_printer_scale_x);
2307
2308 yPos += 90;
2309 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos));
2310 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE, buf, wxPoint(100, yPos), wxSize(100, -1));
2311
2312 sprintf (buf, "%.2f", wx_printer_scale_y);
2313 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos));
2314 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE, buf, wxPoint(320, yPos), wxSize(100, -1));
2315
2316 yPos += 25;
2317
2318 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos));
2319 sprintf (buf, "%.2d", wx_printer_translate_x);
2320 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS, buf, wxPoint(100, yPos), wxSize(100, -1));
2321
2322 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos));
2323 sprintf (buf, "%.2d", wx_printer_translate_y);
2324 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS, buf, wxPoint(320, yPos), wxSize(100, -1));
2325
2326 Fit ();
2327
2328 delete[] orientation;
2329 delete[] print_modes;
2330
2331 wxEndBusyCursor();
2332 }
2333
2334 int wxPostScriptPrintDialog::ShowModal ()
2335 {
2336 if ( wxDialog::ShowModal() == wxID_OK )
2337 {
2338 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2339 wxTextCtrl *text1 = (wxTextCtrl *)FindWindow(wxID_PRINTER_X_SCALE);
2340 wxTextCtrl *text2 = (wxTextCtrl *)FindWindow(wxID_PRINTER_Y_SCALE);
2341 wxTextCtrl *text3 = (wxTextCtrl *)FindWindow(wxID_PRINTER_X_TRANS);
2342 wxTextCtrl *text4 = (wxTextCtrl *)FindWindow(wxID_PRINTER_Y_TRANS);
2343 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2344 wxRadioBox *radio0 = (wxRadioBox *)FindWindow(wxID_PRINTER_ORIENTATION);
2345 wxRadioBox *radio1 = (wxRadioBox *)FindWindow(wxID_PRINTER_MODES);
2346
2347 StringToDouble (WXSTRINGCAST text1->GetValue (), &wxThePrintSetupData->m_printerScaleX);
2348 StringToDouble (WXSTRINGCAST text2->GetValue (), &wxThePrintSetupData->m_printerScaleY);
2349
2350 long dummy;
2351 StringToLong (WXSTRINGCAST text3->GetValue (), &dummy);
2352 wxThePrintSetupData->m_printerTranslateX = (wxCoord)dummy;
2353 StringToLong (WXSTRINGCAST text4->GetValue (), &dummy);
2354 wxThePrintSetupData->m_printerTranslateY = (wxCoord)dummy;
2355
2356 #ifdef __X__
2357 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2358 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2359 #endif
2360
2361 wxThePrintSetupData->SetPrinterOrientation((radio0->GetSelection() == 1 ? wxLANDSCAPE : wxPORTRAIT));
2362
2363 // C++ wants this
2364 switch ( radio1->GetSelection() ) {
2365 case 0: wxThePrintSetupData->SetPrinterMode(PS_PRINTER); break;
2366 case 1: wxThePrintSetupData->SetPrinterMode(PS_FILE); break;
2367 case 2: wxThePrintSetupData->SetPrinterMode(PS_PREVIEW); break;
2368 }
2369 return wxID_OK;
2370 }
2371 return wxID_CANCEL;
2372 }
2373 #endif
2374 // 0 (redundant)
2375
2376 // PostScript printer settings
2377 // RETAINED FOR BACKWARD COMPATIBILITY
2378 void wxSetPrinterCommand(const wxString& cmd)
2379 {
2380 wxThePrintSetupData->SetPrinterCommand(cmd);
2381 }
2382
2383 void wxSetPrintPreviewCommand(const wxString& cmd)
2384 {
2385 wxThePrintSetupData->SetPrintPreviewCommand(cmd);
2386 }
2387
2388 void wxSetPrinterOptions(const wxString& flags)
2389 {
2390 wxThePrintSetupData->SetPrinterOptions(flags);
2391 }
2392
2393 void wxSetPrinterFile(const wxString& f)
2394 {
2395 wxThePrintSetupData->SetPrinterFile(f);
2396 }
2397
2398 void wxSetPrinterOrientation(int orient)
2399 {
2400 wxThePrintSetupData->SetPrinterOrientation(orient);
2401 }
2402
2403 void wxSetPrinterScaling(double x, double y)
2404 {
2405 wxThePrintSetupData->SetPrinterScaling(x, y);
2406 }
2407
2408 void wxSetPrinterTranslation(wxCoord x, wxCoord y)
2409 {
2410 wxThePrintSetupData->SetPrinterTranslation(x, y);
2411 }
2412
2413 // 1 = Preview, 2 = print to file, 3 = send to printer
2414 void wxSetPrinterMode(int mode)
2415 {
2416 wxThePrintSetupData->SetPrinterMode(mode);
2417 }
2418
2419 void wxSetAFMPath(const wxString& f)
2420 {
2421 wxThePrintSetupData->SetAFMPath(f);
2422 }
2423
2424 // Get current values
2425 wxString wxGetPrinterCommand()
2426 {
2427 return wxThePrintSetupData->GetPrinterCommand();
2428 }
2429
2430 wxString wxGetPrintPreviewCommand()
2431 {
2432 return wxThePrintSetupData->GetPrintPreviewCommand();
2433 }
2434
2435 wxString wxGetPrinterOptions()
2436 {
2437 return wxThePrintSetupData->GetPrinterOptions();
2438 }
2439
2440 wxString wxGetPrinterFile()
2441 {
2442 return wxThePrintSetupData->GetPrinterFile();
2443 }
2444
2445 int wxGetPrinterOrientation()
2446 {
2447 return wxThePrintSetupData->GetPrinterOrientation();
2448 }
2449
2450 void wxGetPrinterScaling(double* x, double* y)
2451 {
2452 wxThePrintSetupData->GetPrinterScaling(x, y);
2453 }
2454
2455 void wxGetPrinterTranslation(wxCoord *x, wxCoord *y)
2456 {
2457 wxThePrintSetupData->GetPrinterTranslation(x, y);
2458 }
2459
2460 int wxGetPrinterMode()
2461 {
2462 return wxThePrintSetupData->GetPrinterMode();
2463 }
2464
2465 wxString wxGetAFMPath()
2466 {
2467 return wxThePrintSetupData->GetAFMPath();
2468 }
2469
2470 /*
2471 * Print setup data
2472 */
2473
2474 wxPrintSetupData::wxPrintSetupData()
2475 {
2476 m_printerOrient = wxPORTRAIT;
2477 m_printerScaleX = (double)1.0;
2478 m_printerScaleY = (double)1.0;
2479 m_printerTranslateX = 0;
2480 m_printerTranslateY = 0;
2481 m_printerMode = wxPRINT_MODE_FILE;
2482 m_printColour = TRUE;
2483 }
2484
2485 wxPrintSetupData::~wxPrintSetupData()
2486 {
2487 }
2488
2489 void wxPrintSetupData::operator=(wxPrintSetupData& data)
2490 {
2491 SetPrinterCommand(data.GetPrinterCommand());
2492 SetPrintPreviewCommand(data.GetPrintPreviewCommand());
2493 SetPrinterOptions(data.GetPrinterOptions());
2494 wxCoord x, y;
2495 data.GetPrinterTranslation(&x, &y);
2496 SetPrinterTranslation(x, y);
2497
2498 double x1, y1;
2499 data.GetPrinterScaling(&x1, &y1);
2500 SetPrinterScaling(x1, y1);
2501
2502 SetPrinterOrientation(data.GetPrinterOrientation());
2503 SetPrinterMode(data.GetPrinterMode());
2504 SetAFMPath(data.GetAFMPath());
2505 SetPaperName(data.GetPaperName());
2506 SetColour(data.GetColour());
2507 }
2508
2509 // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData).
2510 void wxPrintSetupData::operator=(const wxPrintData& data)
2511 {
2512 SetPrinterCommand(data.GetPrinterCommand());
2513 SetPrintPreviewCommand(data.GetPreviewCommand());
2514 SetPrinterOptions(data.GetPrinterOptions());
2515 SetPrinterTranslation((wxCoord)data.GetPrinterTranslateX(),
2516 (wxCoord)data.GetPrinterTranslateY());
2517 SetPrinterScaling(data.GetPrinterScaleX(), data.GetPrinterScaleY());
2518 SetPrinterOrientation(data.GetOrientation());
2519 SetPrinterMode((int) data.GetPrintMode());
2520 SetAFMPath(data.GetFontMetricPath());
2521 SetPaperName(wxThePrintPaperDatabase->ConvertIdToName(data.GetPaperId()));
2522 SetColour(data.GetColour());
2523 SetPrinterFile(data.GetFilename());
2524 }
2525
2526 void wxInitializePrintSetupData(bool init)
2527 {
2528 if (init)
2529 {
2530 wxThePrintSetupData = new wxPrintSetupData;
2531
2532 wxThePrintSetupData->SetPrintPreviewCommand(PS_VIEWER_PROG);
2533 wxThePrintSetupData->SetPrinterOrientation(wxPORTRAIT);
2534 wxThePrintSetupData->SetPrinterMode(wxPRINT_MODE_PREVIEW);
2535 wxThePrintSetupData->SetPaperName(_("A4 sheet, 210 x 297 mm"));
2536
2537 // Could have a .ini file to read in some defaults
2538 // - and/or use environment variables, e.g. WXWIN
2539 #ifdef __VMS__
2540 wxThePrintSetupData->SetPrinterCommand("print");
2541 wxThePrintSetupData->SetPrinterOptions("/nonotify/queue=psqueue");
2542 wxThePrintSetupData->SetAFMPath("sys$ps_font_metrics:");
2543 #endif
2544 #ifdef __WXMSW__
2545 wxThePrintSetupData->SetPrinterCommand("print");
2546 wxThePrintSetupData->SetAFMPath("c:\\windows\\system\\");
2547 wxThePrintSetupData->SetPrinterOptions("");
2548 #endif
2549 #if !defined(__VMS__) && !defined(__WXMSW__)
2550 wxThePrintSetupData->SetPrinterCommand("lpr");
2551 wxThePrintSetupData->SetPrinterOptions("");
2552 wxThePrintSetupData->SetAFMPath("");
2553 #endif
2554 }
2555 else
2556 {
2557 if (wxThePrintSetupData)
2558 delete wxThePrintSetupData;
2559 wxThePrintSetupData = (wxPrintSetupData *) NULL;
2560 }
2561 }
2562
2563 // A module to allow initialization/cleanup of PostScript-related
2564 // things without calling these functions from app.cpp.
2565
2566 class WXDLLEXPORT wxPostScriptModule: public wxModule
2567 {
2568 DECLARE_DYNAMIC_CLASS(wxPostScriptModule)
2569 public:
2570 wxPostScriptModule() {}
2571 bool OnInit();
2572 void OnExit();
2573 };
2574
2575 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule, wxModule)
2576
2577 /*
2578 * Initialization/cleanup module
2579 */
2580
2581 bool wxPostScriptModule::OnInit()
2582 {
2583 wxInitializePrintSetupData();
2584
2585 return TRUE;
2586 }
2587
2588 void wxPostScriptModule::OnExit()
2589 {
2590 wxInitializePrintSetupData(FALSE);
2591 }
2592
2593 #endif
2594 // wxUSE_POSTSCRIPT
2595
2596 #endif
2597 // wxUSE_PRINTING_ARCHITECTURE