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