1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 #include "wx/wxprec.h"
30 #include "wx/dcmemory.h"
33 #include "wx/filedlg.h"
35 #include "wx/msgdlg.h"
38 #include "wx/generic/dcpsg.h"
39 #include "wx/generic/prntdlgg.h"
40 #include "wx/button.h"
41 #include "wx/stattext.h"
42 #include "wx/radiobox.h"
43 #include "wx/textctrl.h"
44 #include "wx/prntbase.h"
69 //-----------------------------------------------------------------------------
70 // start and end of document/page
71 //-----------------------------------------------------------------------------
73 static const char *wxPostScriptHeaderEllipse
= "\
74 /ellipsedict 8 dict def\n\
75 ellipsedict /mtrx matrix put\n\
79 /startangle exch def\n\
84 /savematrix mtrx currentmatrix def\n\
87 0 0 1 startangle endangle arc\n\
88 savematrix setmatrix\n\
93 static const char *wxPostScriptHeaderEllipticArc
= "\
94 /ellipticarcdict 8 dict def\n\
95 ellipticarcdict /mtrx matrix put\n\
97 { ellipticarcdict begin\n\
100 /startangle exch def\n\
105 /savematrix mtrx currentmatrix def\n\
108 do_fill { 0 0 moveto } if\n\
109 0 0 1 startangle endangle arc\n\
110 savematrix setmatrix\n\
111 do_fill { fill }{ stroke } ifelse\n\
115 static const char *wxPostScriptHeaderSpline
= "\
116 /DrawSplineSection {\n\
123 /xa x1 x2 x1 sub 0.666667 mul add def\n\
124 /ya y1 y2 y1 sub 0.666667 mul add def\n\
125 /xb x3 x2 x3 sub 0.666667 mul add def\n\
126 /yb y3 y2 y3 sub 0.666667 mul add def\n\
128 xa ya xb yb x3 y3 curveto\n\
132 static const char *wxPostScriptHeaderColourImage
= "\
133 % define 'colorimage' if it isn't defined\n\
134 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
136 /colorimage where % do we know about 'colorimage'?\n\
137 { pop } % yes: pop off the 'dict' returned\n\
138 { % no: define one\n\
139 /colortogray { % define an RGB->I function\n\
140 /rgbdata exch store % call input 'rgbdata'\n\
141 rgbdata length 3 idiv\n\
142 /npixls exch store\n\
144 0 1 npixls 1 sub {\n\
146 rgbdata rgbindx get 20 mul % Red\n\
147 rgbdata rgbindx 1 add get 32 mul % Green\n\
148 rgbdata rgbindx 2 add get 12 mul % Blue\n\
149 add add 64 idiv % I = .5G + .31R + .18B\n\
151 /rgbindx rgbindx 3 add store\n\
153 grays 0 npixls getinterval\n\
156 % Utility procedure for colorimage operator.\n\
157 % This procedure takes two procedures off the\n\
158 % stack and merges them into a single procedure.\n\
160 /mergeprocs { % def\n\
179 /colorimage { % def\n\
180 pop pop % remove 'false 3' operands\n\
181 {colortogray} mergeprocs\n\
184 } ifelse % end of 'false' case\n\
187 static char wxPostScriptHeaderReencodeISO1
[] =
189 "dup dup findfont dup length dict begin\n"
190 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
191 "/Encoding ISOLatin1Encoding def\n"
192 "currentdict end definefont\n"
194 "/ISOLatin1Encoding [\n"
195 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
196 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
197 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
198 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
199 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
200 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
201 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
202 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
203 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
204 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
205 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
206 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
207 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
208 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
209 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
211 static char wxPostScriptHeaderReencodeISO2
[] =
212 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
213 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
214 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
215 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
216 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
217 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
218 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
219 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
220 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
221 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
222 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
223 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
224 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
225 "/yacute/thorn/ydieresis\n"
228 //-------------------------------------------------------------------------------
230 //-------------------------------------------------------------------------------
232 wxPostScriptDC::wxPostScriptDC ()
234 m_pstream
= (ofstream
*) NULL
;
244 m_underlinePosition
= 0.0;
245 m_underlineThickness
= 0.0;
247 m_signX
= 1; // default x-axis left to right
248 m_signY
= -1; // default y-axis bottom up -> top down
250 // Compatibility only
251 m_printData
= * wxThePrintSetupData
;
254 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
256 m_pstream
= (ofstream
*) NULL
;
266 m_underlinePosition
= 0.0;
267 m_underlineThickness
= 0.0;
269 m_signX
= 1; // default x-axis left to right
270 m_signY
= -1; // default y-axis bottom up -> top down
272 Create(file
, interactive
, parent
);
275 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
277 m_isInteractive
= interactive
;
280 m_printData
.SetFilename(file
);
283 // Can only send to file in Windows
284 m_printData
.SetPrintMode(wxPRINT_MODE_FILE
);
289 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
299 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
301 m_pstream
= (ofstream
*) NULL
;
311 m_underlinePosition
= 0.0;
312 m_underlineThickness
= 0.0;
314 m_signX
= 1; // default x-axis left to right
315 m_signY
= -1; // default y-axis bottom up -> top down
317 m_printData
= printData
;
320 wxPostScriptDC::~wxPostScriptDC ()
322 if (m_pstream
) delete m_pstream
;
325 bool wxPostScriptDC::Ok() const
330 // This dialog is deprecated now: use wxGenericPrintDialog or the printing framework
331 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
333 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
334 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
335 m_ok
= (dialog
.ShowModal () == wxID_OK
);
337 if (!m_ok
) return FALSE
;
339 if ((m_printData
.GetFilename() == "") &&
340 (m_printData
.GetPrintMode() == wxPRINT_MODE_PREVIEW
||
341 m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
345 m_printData
.SetFilename("preview");
347 // For PS_PRINTER action this depends on a Unix-style print spooler
348 // since the wx_printer_file can be destroyed during a session
349 // @@@ TODO: a Windows-style answer for non-Unix
351 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
353 wxStrcpy (tmp
, _T("/tmp/preview_"));
354 wxStrcat (tmp
, userId
);
355 m_printData
.SetFilename(tmp
);
358 wxStrcpy(tmp2
, m_printData
.GetFilename());
359 wxStrcat (tmp2
, _T(".ps"));
360 m_printData
.SetFilename(tmp2
);
362 else if ((m_printData
.GetFilename() == _T("")) && (m_printData
.GetPrintMode() == wxPRINT_MODE_FILE
))
364 wxString file
= wxSaveFileSelector (_("PostScript"), _T("ps"));
365 if ( file
.IsEmpty() )
371 m_printData
.SetFilename(file
);
378 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
380 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
382 if (m_clipping
) return;
384 wxDC::SetClippingRegion( x
, y
, w
, h
);
387 *m_pstream
<< "gsave\n"
389 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
390 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
391 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
392 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
393 << "closepath clip newpath\n";
396 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
400 void wxPostScriptDC::DestroyClippingRegion()
402 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
404 wxDC::DestroyClippingRegion();
409 *m_pstream
<< "grestore\n";
413 void wxPostScriptDC::Clear()
415 wxFAIL_MSG( _T("wxPostScriptDC::Clear not implemented.") );
418 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
420 wxFAIL_MSG( _T("wxPostScriptDC::FloodFill not implemented.") );
423 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
425 wxFAIL_MSG( _T("wxPostScriptDC::GetPixel not implemented.") );
429 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
431 wxFAIL_MSG( _T("wxPostScriptDC::CrossHair not implemented.") );
434 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
436 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
438 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
442 *m_pstream
<< "newpath\n"
443 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
444 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
447 CalcBoundingBox( x1
, y1
);
448 CalcBoundingBox( x2
, y2
);
451 #define RAD2DEG 57.29577951308
453 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
455 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
459 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
460 double alpha1
, alpha2
;
462 if (x1
== x2
&& y1
== y2
)
466 } else if (radius
== 0.0)
468 alpha1
= alpha2
= 0.0;
471 alpha1
= (x1
- xc
== 0) ?
472 (y1
- yc
< 0) ? 90.0 : -90.0 :
473 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
474 alpha2
= (x2
- xc
== 0) ?
475 (y2
- yc
< 0) ? 90.0 : -90.0 :
476 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
478 while (alpha1
<= 0) alpha1
+= 360;
479 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
480 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
481 while (alpha2
> 360) alpha2
-= 360;
483 if (m_brush
.GetStyle() != wxTRANSPARENT
)
486 *m_pstream
<< "newpath\n"
487 << XLOG2DEV(xc
) << " "
488 << YLOG2DEV(yc
) << " "
489 << XLOG2DEVREL(radius
) << " "
490 << YLOG2DEVREL(radius
) << " "
492 << alpha2
<< " ellipse\n"
493 << XLOG2DEV(xc
) << " "
494 << YLOG2DEV(yc
) << " lineto\n"
499 if (m_pen
.GetStyle() != wxTRANSPARENT
)
502 *m_pstream
<< "newpath\n"
503 << XLOG2DEV(xc
) << " "
504 << YLOG2DEV(yc
) << " "
505 << XLOG2DEVREL(radius
) << " "
506 << YLOG2DEVREL(radius
) << " "
508 << alpha2
<< " ellipse\n"
512 CalcBoundingBox( xc
-radius
, yc
-radius
);
513 CalcBoundingBox( xc
+radius
, yc
+radius
);
516 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
518 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
520 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
521 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
527 DrawEllipse(x
,y
,w
,h
);
531 if (m_brush
.GetStyle () != wxTRANSPARENT
)
535 *m_pstream
<< "newpath\n"
536 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
537 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
538 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
540 CalcBoundingBox( x
,y
);
541 CalcBoundingBox( x
+w
, y
+h
);
544 if (m_pen
.GetStyle () != wxTRANSPARENT
)
548 *m_pstream
<< "newpath\n"
549 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
550 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
551 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
553 CalcBoundingBox( x
, y
);
554 CalcBoundingBox( x
+w
, y
+h
);
558 void wxPostScriptDC::DrawPoint (long x
, long y
)
560 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
562 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
566 *m_pstream
<< "newpath\n"
567 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
568 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
571 CalcBoundingBox( x
, y
);
574 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
576 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
580 if (m_brush
.GetStyle () != wxTRANSPARENT
)
584 *m_pstream
<< "newpath\n";
586 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
587 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
588 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
589 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
591 for (int i
= 1; i
< n
; i
++)
593 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
594 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
595 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
596 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
598 *m_pstream
<< "fill\n";
601 if (m_pen
.GetStyle () != wxTRANSPARENT
)
605 *m_pstream
<< "newpath\n";
607 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
608 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
609 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
610 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
612 for (int i
= 1; i
< n
; i
++)
614 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
615 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
616 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
617 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
620 *m_pstream
<< "stroke\n";
624 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
626 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
628 if (m_pen
.GetStyle() == wxTRANSPARENT
)
636 for ( i
=0; i
<n
; i
++ )
638 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
641 *m_pstream
<< "newpath\n"
642 << XLOG2DEV(points
[0].x
+xoffset
) << " "
643 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
645 for (i
= 1; i
< n
; i
++)
647 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
648 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
651 *m_pstream
<< "stroke\n";
654 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
656 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
658 if (m_brush
.GetStyle () != wxTRANSPARENT
)
662 *m_pstream
<< "newpath\n"
663 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
664 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
665 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
666 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
670 CalcBoundingBox( x
, y
);
671 CalcBoundingBox( x
+ width
, y
+ height
);
674 if (m_pen
.GetStyle () != wxTRANSPARENT
)
678 *m_pstream
<< "newpath\n"
679 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
680 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
681 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
682 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
686 CalcBoundingBox( x
, y
);
687 CalcBoundingBox( x
+ width
, y
+ height
);
691 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
693 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
697 // Now, a negative radius is interpreted to mean
698 // 'the proportion of the smallest X or Y dimension'
699 double smallest
= 0.0;
704 radius
= (-radius
* smallest
);
707 long rad
= (long) radius
;
709 if (m_brush
.GetStyle () != wxTRANSPARENT
)
713 // Draw rectangle anticlockwise
714 *m_pstream
<< "newpath\n"
715 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
716 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
717 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
718 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
719 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
720 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
721 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
722 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
726 CalcBoundingBox( x
, y
);
727 CalcBoundingBox( x
+ width
, y
+ height
);
730 if (m_pen
.GetStyle () != wxTRANSPARENT
)
734 // Draw rectangle anticlockwise
735 *m_pstream
<< "newpath\n"
736 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
737 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
738 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
739 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
740 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
741 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
742 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
743 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
747 CalcBoundingBox( x
, y
);
748 CalcBoundingBox( x
+ width
, y
+ height
);
752 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
754 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
756 if (m_brush
.GetStyle () != wxTRANSPARENT
)
760 *m_pstream
<< "newpath\n"
761 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
762 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
765 CalcBoundingBox( x
- width
, y
- height
);
766 CalcBoundingBox( x
+ width
, y
+ height
);
769 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
773 *m_pstream
<< "newpath\n"
774 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
775 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
778 CalcBoundingBox( x
- width
, y
- height
);
779 CalcBoundingBox( x
+ width
, y
+ height
);
783 void wxPostScriptDC::DrawIcon( const wxIcon
& icon
, long x
, long y
)
785 DrawBitmap( icon
, x
, y
, TRUE
);
788 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool WXUNUSED(useMask
) )
790 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
792 if (!bitmap
.Ok()) return;
794 wxImage
image( bitmap
);
796 if (!image
.Ok()) return;
798 int ww
= XLOG2DEVREL(image
.GetWidth());
799 int hh
= YLOG2DEVREL(image
.GetHeight());
801 image
= image
.Scale( ww
, hh
);
803 if (!image
.Ok()) return;
805 int xx
= XLOG2DEV(x
);
806 int yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
808 *m_pstream
<< "/origstate save def\n"
810 << "/pix " << ww
<< " string def\n"
811 << "/grays " << ww
<< " string def\n"
812 << "/npixels 0 def\n"
813 << "/rgbindx 0 def\n"
814 << xx
<< " " << yy
<< " translate\n"
815 << ww
<< " " << hh
<< " scale\n"
816 << ww
<< " " << hh
<< " 8\n"
817 << "[" << ww
<< " 0 0 " << (-hh
) << " 0 " << hh
<< "]\n"
818 << "{currentfile pix readhexstring pop}\n"
819 << "false 3 colorimage\n";
821 for (int j
= 0; j
< hh
; j
++)
823 for (int i
= 0; i
< ww
; i
++)
827 wxDecToHex( image
.GetRed(i
,j
), buffer
);
828 *m_pstream
<< buffer
;
829 wxDecToHex( image
.GetGreen(i
,j
), buffer
);
830 *m_pstream
<< buffer
;
831 wxDecToHex( image
.GetBlue(i
,j
), buffer
);
832 *m_pstream
<< buffer
;
837 *m_pstream
<< "end\n";
838 *m_pstream
<< "origstate restore\n";
842 void wxPostScriptDC::SetFont( const wxFont
& font
)
844 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
846 if (!font
.Ok()) return;
851 const char *style
= "";
852 int Style
= m_font
.GetStyle();
853 int Weight
= m_font
.GetWeight();
855 switch (m_font
.GetFamily ())
865 // name = "/Times-Roman";
866 name
= "/Times"; // Altered by EDZ
869 name
= "/Zapf-Chancery-MediumItalic";
874 case wxDEFAULT
: // Sans Serif Font
875 name
= "/LucidaSans";
878 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
880 if (m_font
.GetFamily () == wxROMAN
)
885 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
889 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
891 if (m_font
.GetFamily () == wxROMAN
)
896 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
898 if (m_font
.GetFamily () == wxROMAN
)
899 style
= "-BoldItalic";
901 style
= "-BoldOblique";
903 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
905 if (m_font
.GetFamily () == wxROMAN
)
910 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
912 if (m_font
.GetFamily () == wxROMAN
)
913 style
= "-BoldItalic";
915 style
= "-BoldOblique";
926 *m_pstream
<< buf
<< " reencodeISO def\n";
927 *m_pstream
<< buf
<< " findfont\n";
928 *m_pstream
<< YLOG2DEVREL(m_font
.GetPointSize()) << " scalefont setfont\n";
931 void wxPostScriptDC::SetPen( const wxPen
& pen
)
933 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
935 if (!pen
.Ok()) return;
937 int oldStyle
= m_pen
.GetStyle();
941 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
944 Line style - WRONG: 2nd arg is OFFSET
946 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
947 operator correctly. You should look-up this in the Red Book: the 2nd parame-
948 ter is not number of values in the array of the first one, but an offset
949 into this description of the pattern. I mean a real *offset* not index
950 into array. I.e. If the command is [3 4] 1 setdash is used, then there
951 will be first black line *2* units long, then space 4 units, then the
952 pattern of *3* units black, 4 units space will be repeated.
955 static const char *dotted
= "[2 5] 2";
956 static const char *short_dashed
= "[4 4] 2";
957 static const char *long_dashed
= "[4 8] 2";
958 static const char *dotted_dashed
= "[6 6 2 6] 4";
960 const char *psdash
= (char *) NULL
;
961 switch (m_pen
.GetStyle ())
963 case wxDOT
: psdash
= dotted
; break;
964 case wxSHORT_DASH
: psdash
= short_dashed
; break;
965 case wxLONG_DASH
: psdash
= long_dashed
; break;
966 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
969 default: psdash
= "[] 0"; break;
972 if (oldStyle
!= m_pen
.GetStyle())
974 *m_pstream
<< psdash
<< " setdash\n";
978 unsigned char red
= m_pen
.GetColour().Red();
979 unsigned char blue
= m_pen
.GetColour().Blue();
980 unsigned char green
= m_pen
.GetColour().Green();
984 // Anything not white is black
985 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
986 && green
== (unsigned char) 255))
988 red
= (unsigned char) 0;
989 green
= (unsigned char) 0;
990 blue
= (unsigned char) 0;
996 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
998 float redPS
= (float)(red
) / 255.0;
999 float bluePS
= (float)(blue
) / 255.0;
1000 float greenPS
= (float)(green
) / 255.0;
1001 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1004 m_currentBlue
= blue
;
1005 m_currentGreen
= green
;
1009 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1011 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1013 if (!brush
.Ok()) return;
1018 unsigned char red
= m_brush
.GetColour().Red();
1019 unsigned char blue
= m_brush
.GetColour().Blue();
1020 unsigned char green
= m_brush
.GetColour().Green();
1024 // Anything not black is white
1025 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
1026 && green
== (unsigned char) 0))
1028 red
= (unsigned char) 255;
1029 green
= (unsigned char) 255;
1030 blue
= (unsigned char) 255;
1036 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1038 float redPS
= (float)(red
) / 255.0;
1039 float bluePS
= (float)(blue
) / 255.0;
1040 float greenPS
= (float)(green
) / 255.0;
1041 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1043 m_currentBlue
= blue
;
1044 m_currentGreen
= green
;
1048 void wxPostScriptDC::DrawText( const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
) )
1050 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1054 if (m_textForegroundColour
.Ok ())
1056 unsigned char red
= m_textForegroundColour
.Red ();
1057 unsigned char blue
= m_textForegroundColour
.Blue ();
1058 unsigned char green
= m_textForegroundColour
.Green ();
1062 // Anything not white is black
1063 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
1064 && green
== (unsigned char) 255))
1066 red
= (unsigned char) 0;
1067 green
= (unsigned char) 0;
1068 blue
= (unsigned char) 0;
1072 // maybe setgray here ?
1074 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1076 float redPS
= (float)(red
) / 255.0;
1077 float bluePS
= (float)(blue
) / 255.0;
1078 float greenPS
= (float)(green
) / 255.0;
1079 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1082 m_currentBlue
= blue
;
1083 m_currentGreen
= green
;
1087 int size
= m_font
.GetPointSize();
1089 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
1090 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
1093 const wxWX2MBbuf textbuf
= text
.mb_str();
1094 int len
= strlen (textbuf
);
1096 for (i
= 0; i
< len
; i
++)
1098 int c
= (unsigned char) textbuf
[i
];
1099 if ( c
== ')' || c
== '(' || c
== '\\')
1101 *m_pstream
<< "\\" << (char) c
;
1103 else if ( c
>= 128 )
1105 // Cope with character codes > 127
1107 sprintf(tmp
, "\\%o", c
);
1111 *m_pstream
<< (char) c
;
1114 *m_pstream
<< ")" << " show\n";
1116 if (m_font
.GetUnderlined())
1118 long uy
= (long)(y
+ size
- m_underlinePosition
);
1120 GetTextExtent(text
, &w
, &h
);
1122 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
1124 << (long)m_underlineThickness
<< " setlinewidth "
1125 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
1126 << " lineto stroke grestore\n";
1129 CalcBoundingBox( x
, y
);
1130 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1134 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1136 m_backgroundBrush
= brush
;
1139 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1141 wxFAIL_MSG( _T("wxPostScriptDC::SetLogicalFunction not implemented.") );
1144 void wxPostScriptDC::DrawSpline( wxList
*points
)
1146 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1150 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1153 wxNode
*node
= points
->First();
1154 p
= (wxPoint
*)node
->Data();
1158 node
= node
->Next();
1159 p
= (wxPoint
*)node
->Data();
1162 x3
= a
= (double)(x1
+ c
) / 2;
1163 y3
= b
= (double)(y1
+ d
) / 2;
1165 *m_pstream
<< "newpath "
1166 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
1167 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
1169 CalcBoundingBox( (long)x1
, (long)y1
);
1170 CalcBoundingBox( (long)x3
, (long)y3
);
1172 while ((node
= node
->Next()) != NULL
)
1174 q
= (wxPoint
*)node
->Data();
1182 x3
= (double)(x2
+ c
) / 2;
1183 y3
= (double)(y2
+ d
) / 2;
1184 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
1185 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
1186 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
1188 CalcBoundingBox( (long)x1
, (long)y1
);
1189 CalcBoundingBox( (long)x3
, (long)y3
);
1193 At this point, (x2,y2) and (c,d) are the position of the
1194 next-to-last and last point respectively, in the point list
1197 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1200 long wxPostScriptDC::GetCharWidth ()
1202 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1203 return (long) (GetCharHeight() * 72.0 / 120.0);
1207 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1209 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1211 m_signX
= (xLeftRight
? 1 : -1);
1212 m_signY
= (yBottomUp
? 1 : -1);
1214 // FIXME there is no such function in MSW
1216 ComputeScaleAndOrigin();
1220 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1222 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1228 wxDC::SetDeviceOrigin( x
, h
-y
);
1231 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1233 wxPaperSize id
= m_printData
.GetPaperId();
1235 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1237 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1241 if (width
) *width
= paper
->GetSizeDeviceUnits().x
;
1242 if (height
) *height
= paper
->GetSizeDeviceUnits().y
;
1246 if (width
) *width
= 595;
1247 if (height
) *height
= 842;
1251 void wxPostScriptDC::GetSizeMM(int *width
, int *height
) const
1253 wxPaperSize id
= m_printData
.GetPaperId();
1255 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1257 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1261 if (width
) *width
= paper
->GetWidth() / 10;
1262 if (height
) *height
= paper
->GetHeight() / 10;
1266 if (width
) *width
= 210;
1267 if (height
) *height
= 297;
1271 // Resolution in pixels per logical inch
1272 wxSize
wxPostScriptDC::GetPPI(void) const
1274 return wxSize(72, 72);
1278 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1280 wxCHECK_MSG( m_ok
, FALSE
, _T("invalid postscript dc") );
1282 if (m_printData
.GetFilename() == "")
1284 wxString filename
= wxGetTempFileName("ps");
1285 m_printData
.SetFilename(filename
);
1290 m_pstream
= new ofstream (m_printData
.GetFilename().fn_str());
1292 if (!m_pstream
|| !m_pstream
->good())
1294 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1301 SetBrush( *wxBLACK_BRUSH
);
1302 SetPen( *wxBLACK_PEN
);
1303 SetBackground( *wxWHITE_BRUSH
);
1304 SetTextForeground( *wxBLACK
);
1306 // set origin according to paper size
1307 SetDeviceOrigin( 0,0 );
1315 void wxPostScriptDC::EndDoc ()
1317 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1322 *m_pstream
<< "grestore\n";
1328 m_pstream
= (ofstream
*) NULL
;
1331 wxChar
*header_file
= wxGetTempFileName("ps");
1333 m_pstream
= new ofstream( wxConv_file
.cWX2MB(header_file
) );
1335 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1336 *m_pstream
<< "%%Title: " << m_title
.mb_str() << "\n";
1337 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1338 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1341 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1343 *m_pstream
<< "%%For: " << MBSTRINGCAST wxConv_libc
.cWX2MB(userID
);
1344 wxChar userName
[245];
1345 if (wxGetUserName(userName
, sizeof(userName
)))
1346 *m_pstream
<< " (" << MBSTRINGCAST wxConv_libc
.cWX2MB(userName
) << ")";
1349 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1351 *m_pstream
<< "%%For: " << MBSTRINGCAST wxConv_libc
.cWX2MB(userID
) << "\n";
1354 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1356 long wx_printer_translate_x
, wx_printer_translate_y
;
1357 double wx_printer_scale_x
, wx_printer_scale_y
;
1359 wx_printer_translate_x
= m_printData
.GetPrinterTranslateX();
1360 wx_printer_translate_y
= m_printData
.GetPrinterTranslateY();
1362 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1363 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1365 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1367 *m_pstream
<< "%%Orientation: Landscape\n";
1371 *m_pstream
<< "%%Orientation: Portrait\n";
1374 // Compute the bounding box. Note that it is in the default user
1375 // coordinate system, thus we have to convert the values.
1376 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1377 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1378 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1379 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1381 // If we're landscape, our sense of "x" and "y" is reversed.
1382 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1385 tmp
= llx
; llx
= lly
; lly
= tmp
;
1386 tmp
= urx
; urx
= ury
; ury
= tmp
;
1388 // We need either the two lines that follow, or we need to subtract
1389 // min_x from real_translate_y, which is commented out below.
1390 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1391 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1394 // The Adobe specifications call for integers; we round as to make
1395 // the bounding larger.
1396 *m_pstream
<< "%%BoundingBox: "
1397 << floor((double)llx
) << " " << floor((double)lly
) << " "
1398 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1399 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1400 *m_pstream
<< "%%EndComments\n\n";
1402 // To check the correctness of the bounding box, postscript commands
1403 // to draw a box corresponding to the bounding box are generated below.
1404 // But since we typically don't want to print such a box, the postscript
1405 // commands are generated within comments. These lines appear before any
1406 // adjustment of scale, rotation, or translation, and hence are in the
1407 // default user coordinates.
1408 *m_pstream
<< "% newpath\n";
1409 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1410 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1411 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1412 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1414 *m_pstream
<< "%%BeginProlog\n";
1415 *m_pstream
<< wxPostScriptHeaderEllipse
;
1416 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1417 *m_pstream
<< wxPostScriptHeaderColourImage
;
1418 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1419 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1421 if (wxPostScriptHeaderSpline
)
1422 *m_pstream
<< wxPostScriptHeaderSpline
;
1423 *m_pstream
<< "%%EndProlog\n";
1426 m_pstream
= (ofstream
*) NULL
;
1428 wxChar
*tmp_file
= wxGetTempFileName("ps");
1430 // Paste header Before wx_printer_file
1431 wxConcatFiles (header_file
, m_printData
.GetFilename(), tmp_file
);
1432 wxRemoveFile (header_file
);
1433 wxRemoveFile (m_printData
.GetFilename());
1434 wxRenameFile(tmp_file
, m_printData
.GetFilename());
1436 #if defined(__X__) || defined(__WXGTK__)
1439 wxString
previewCommand(m_printData
.GetPreviewCommand());
1440 wxString
printerCommand(m_printData
.GetPrinterCommand());
1441 wxString
printerOptions(m_printData
.GetPrinterOptions());
1442 wxString
filename(m_printData
.GetFilename());
1444 switch (m_printData
.GetPrintMode()) {
1446 case wxPRINT_MODE_PREVIEW
:
1449 argv
[0] = WXSTRINGCAST previewCommand
;
1450 argv
[1] = WXSTRINGCAST filename
;
1451 argv
[2] = (wxChar
*) NULL
;
1452 wxExecute (argv
, TRUE
);
1453 wxRemoveFile(m_printData
.GetFilename());
1457 case wxPRINT_MODE_PRINTER
:
1461 argv
[argc
++] = WXSTRINGCAST printerCommand
;
1463 // !SM! If we simply assign to argv[1] here, if printer options
1464 // are blank, we get an annoying and confusing message from lpr.
1465 wxChar
* opts
= WXSTRINGCAST printerOptions
;
1467 argv
[argc
++] = opts
;
1469 argv
[argc
++] = WXSTRINGCAST filename
;
1470 argv
[argc
++] = (wxChar
*) NULL
;
1471 wxExecute (argv
, TRUE
);
1472 wxRemoveFile(filename
);
1476 case wxPRINT_MODE_FILE
:
1477 case wxPRINT_MODE_NONE
:
1484 void wxPostScriptDC::StartPage ()
1486 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1488 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1490 // *m_pstream << "matrix currentmatrix\n";
1492 // Added by Chris Breeze
1494 // Each page starts with an "initgraphics" which resets the
1495 // transformation and so we need to reset the origin
1496 // (and rotate the page for landscape printing)
1499 m_scaleFactor = 1.0;
1500 m_logicalOriginX = 0;
1501 m_logicalOriginY = 0;
1504 long translate_x
, translate_y
;
1505 double scale_x
, scale_y
;
1507 translate_x
= m_printData
.GetPrinterTranslateX();
1508 translate_y
= m_printData
.GetPrinterTranslateY();
1510 scale_x
= m_printData
.GetPrinterScaleX();
1511 scale_y
= m_printData
.GetPrinterScaleY();
1513 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1515 translate_y
-= m_maxY
;
1516 *m_pstream
<< "90 rotate\n";
1519 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1520 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1523 void wxPostScriptDC::EndPage ()
1525 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1527 *m_pstream
<< "showpage\n";
1530 bool wxPostScriptDC::Blit( long xdest
, long ydest
,
1531 long fwidth
, long fheight
,
1533 long xsrc
, long ysrc
,
1534 int rop
, bool WXUNUSED(useMask
) )
1536 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, _T("invalid postscript dc") );
1538 wxCHECK_MSG( source
, FALSE
, _T("invalid source dc") );
1540 /* blit into a bitmap */
1542 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1544 memDC
.SelectObject(bitmap
);
1545 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1546 memDC
.SelectObject(wxNullBitmap
);
1548 /* draw bitmap. scaling and positioning is done there */
1550 DrawBitmap( bitmap
, xdest
, ydest
);
1555 long wxPostScriptDC::GetCharHeight()
1558 return m_font
.GetPointSize();
1563 void wxPostScriptDC::GetTextExtent( const wxString
& string
, long *x
, long *y
,
1564 long *descent
, long *externalLeading
, wxFont
*theFont
,
1565 bool WXUNUSED(use16
) )
1567 wxFont
*fontToUse
= theFont
;
1569 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1571 wxCHECK_RET( fontToUse
, _T("GetTextExtent: no font defined") );
1572 wxCHECK_RET( x
, _T("GetTextExtent: x == NULL") );
1573 wxCHECK_RET( y
, _T("GetTextExtent: y == NULL") );
1575 const wxWX2MBbuf strbuf
= string
.mb_str();
1577 #if !USE_AFM_FOR_POSTSCRIPT
1578 /* Provide a VERY rough estimate (avoid using it).
1579 * Produces accurate results for mono-spaced font
1580 * such as Courier (aka wxMODERN) */
1585 height
= fontToUse
->GetPointSize();
1587 *x
= strlen (strbuf
) * height
* 72 / 120;
1588 *y
= (long) (height
* 1.32); /* allow for descender */
1589 if (descent
) *descent
= 0;
1590 if (externalLeading
) *externalLeading
= 0;
1593 /* method for calculating string widths in postscript:
1594 / read in the AFM (adobe font metrics) file for the
1595 / actual font, parse it and extract the character widths
1596 / and also the descender. this may be improved, but for now
1597 / it works well. the AFM file is only read in if the
1598 / font is changed. this may be chached in the future.
1599 / calls to GetTextExtent with the font unchanged are rather
1602 / for each font and style used there is an AFM file necessary.
1603 / currently i have only files for the roman font family.
1604 / I try to get files for the other ones!
1606 / CAVE: the size of the string is currently always calculated
1607 / in 'points' (1/72 of an inch). this should later on be
1608 / changed to depend on the mapping mode.
1609 / CAVE: the path to the AFM files must be set before calling this
1610 / function. this is usually done by a call like the following:
1611 / wxSetAFMPath("d:\\wxw161\\afm\\");
1615 / wxPostScriptDC dc(NULL, TRUE);
1617 / wxSetAFMPath("d:\\wxw161\\afm\\");
1618 / dc.StartDoc("Test");
1621 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1622 / dc.GetTextExtent("Hallo",&w,&h);
1627 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1629 / updated: 14.05.95 */
1631 /* these static vars are for storing the state between calls */
1632 static int lastFamily
= INT_MIN
;
1633 static int lastSize
= INT_MIN
;
1634 static int lastStyle
= INT_MIN
;
1635 static int lastWeight
= INT_MIN
;
1636 static int lastDescender
= INT_MIN
;
1637 static int lastWidths
[256]; /* widths of the characters */
1639 /* get actual parameters */
1640 const int Family
= fontToUse
->GetFamily();
1641 const int Size
= fontToUse
->GetPointSize();
1642 const int Style
= fontToUse
->GetStyle();
1643 const int Weight
= fontToUse
->GetWeight();
1645 /* if we have another font, read the font-metrics */
1646 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1648 /* store actual values */
1649 lastFamily
= Family
;
1652 lastWeight
= Weight
;
1654 char *name
= (char*) NULL
;
1660 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO";
1661 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo";
1662 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Cour0";
1668 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO";
1669 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo";
1670 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO";
1671 else if name
= "TimesRo"; /* no typo */
1676 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO";
1677 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo";
1678 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Helv0";
1684 /* get the directory of the AFM files */
1687 wxString
fmPath(m_printData
.GetFontMetricPath());
1688 if (fmPath
!= "") strcpy( afmName
, (const char*) fmPath
);
1690 /* 2. open and process the file
1691 / a short explanation of the AFM format:
1692 / we have for each character a line, which gives its size
1695 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1697 / that means, we have a character with ascii code 63, and width
1698 / (444/1000 * fontSize) points.
1699 / the other data is ignored for now!
1701 / when the font has changed, we read in the right AFM file and store the
1702 / character widths in an array, which is processed below (see point 3.). */
1704 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
1706 strcat(afmName
,name
);
1707 strcat(afmName
,".afm");
1708 FILE *afmFile
= fopen(afmName
,"r");
1709 if ( afmFile
==NULL
)
1711 wxLogDebug( "GetTextExtent: can't open AFM file '%s'\n", afmName
);
1712 wxLogDebug( " using approximate values\n");
1713 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
1714 lastDescender
= -150; /* dito. */
1718 /* init the widths array */
1719 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
1720 /* some variables for holding parts of a line */
1721 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1722 char upString
[30], utString
[30], encString
[50];
1725 /* read in the file and parse it */
1726 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
1728 /* A.) check for descender definition */
1729 if (strncmp(line
,"Descender",9)==0)
1731 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
1732 (strcmp(descString
,"Descender")!=0))
1734 wxLogDebug( "AFM-file '%s': line '%s' has error (bad descender)\n", afmName
,line
);
1737 /* JC 1.) check for UnderlinePosition */
1738 else if(strncmp(line
,"UnderlinePosition",17)==0)
1740 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
1741 (strcmp(upString
,"UnderlinePosition")!=0))
1743 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", afmName
, line
);
1746 /* JC 2.) check for UnderlineThickness */
1747 else if(strncmp(line
,"UnderlineThickness",18)==0)
1749 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
1750 (strcmp(utString
,"UnderlineThickness")!=0))
1752 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", afmName
, line
);
1755 /* JC 3.) check for EncodingScheme */
1756 else if(strncmp(line
,"EncodingScheme",14)==0)
1758 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
1759 (strcmp(utString
,"EncodingScheme")!=0))
1761 wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", afmName
, line
);
1763 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1765 wxLogDebug( "AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1766 afmName
,line
, encString
);
1769 /* B.) check for char-width */
1770 else if(strncmp(line
,"C ",2)==0)
1772 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
1774 wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1776 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
1778 wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1780 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
1781 if (ascii
>=0 && ascii
<256)
1783 lastWidths
[ascii
] = cWidth
; /* store width */
1787 /* MATTHEW: this happens a lot; don't print an error */
1788 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); */
1791 /* C.) ignore other entries. */
1795 /* hack to compute correct values for german 'Umlaute'
1796 / the correct way would be to map the character names
1797 / like 'adieresis' to corresp. positions of ISOEnc and read
1798 / these values from AFM files, too. Maybe later ... */
1799 lastWidths
[196] = lastWidths
['A']; // Ä
1800 lastWidths
[228] = lastWidths
['a']; // ä
1801 lastWidths
[214] = lastWidths
['O']; // Ö
1802 lastWidths
[246] = lastWidths
['o']; // ö
1803 lastWidths
[220] = lastWidths
['U']; // Ü
1804 lastWidths
[252] = lastWidths
['u']; // ü
1805 lastWidths
[223] = lastWidths
[251]; // ß
1808 /* JC: calculate UnderlineThickness/UnderlinePosition */
1809 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1810 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1812 /* 3. now the font metrics are read in, calc size this
1813 / is done by adding the widths of the characters in the
1814 / string. they are given in 1/1000 of the size! */
1817 long height
=Size
; /* by default */
1819 for(p
=(unsigned char *)strbuf
; *p
; p
++)
1821 if(lastWidths
[*p
]== INT_MIN
)
1823 wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n", *p
,*p
);
1824 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); /* assume space */
1828 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1832 /* add descender to height (it is usually a negative value) */
1833 if (lastDescender
!=INT_MIN
)
1835 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1838 /* return size values */
1842 /* return other parameters */
1845 if(lastDescender
!=INT_MIN
)
1847 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1855 /* currently no idea how to calculate this! */
1856 if (externalLeading
) *externalLeading
= 0;
1861 // Determine the Default Postscript Previewer
1862 // available on the platform
1863 #if defined(__SUN__) && defined(__XVIEW__)
1864 // OpenWindow/NeWS's Postscript Previewer
1865 # define PS_VIEWER_PROG "pageview"
1866 #elif defined(__VMS__)
1867 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
1868 #elif defined(__SGI__)
1869 // SGI's Display Postscript Previewer
1870 //# define PS_VIEWER_PROG "dps"
1871 # define PS_VIEWER_PROG "xpsview"
1872 #elif defined(__X__) || defined(__WXGTK__)
1873 // Front-end to ghostscript
1874 # define PS_VIEWER_PROG "ghostview"
1876 // Windows ghostscript/ghostview
1877 # define PS_VIEWER_PROG NULL
1880 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
1882 #if !USE_SHARED_LIBRARY
1883 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
1884 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
1887 // Redundant now I think
1889 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
1891 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
1892 const wxPoint
& pos
, const wxSize
& size
, long style
):
1893 wxDialog(parent
, -1, title
, pos
, size
, style
)
1895 wxBeginBusyCursor();
1900 *orientation
= new wxString
[2],
1901 *print_modes
= new wxString
[3];
1903 long wx_printer_translate_x
, wx_printer_translate_y
;
1904 double wx_printer_scale_x
, wx_printer_scale_y
;
1906 orientation
[0] = _("Portrait");
1907 orientation
[1] = _("Landscape");
1909 print_modes
[0] = _("Send to Printer");
1910 print_modes
[1] = _("Print to File");
1911 print_modes
[2] = _("Preview Only");
1915 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
1916 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
1917 okBut
->SetDefault();
1920 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1921 (void) new wxStaticText( this, -1, _("Printer Command: "),
1923 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
1924 wxPoint(100, yPos
), wxSize(100, -1) );
1926 (void) new wxStaticText( this, -1, _("Printer Options: "),
1927 wxPoint(210, yPos
) );
1928 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
1929 wxPoint(305, yPos
), wxSize(150, -1) );
1935 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
1936 2,orientation
,2,wxRA_SPECIFY_ROWS
);
1937 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
1939 // @@@ Configuration hook
1940 if ( !wxThePrintSetupData
->GetPrintPreviewCommand() )
1941 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
1943 // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand);
1945 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
1946 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
1948 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
1950 wxSize(-1,-1), features
,
1951 print_modes
, features
, wxRA_SPECIFY_ROWS
);
1954 radio1
->Enable(0, FALSE
);
1955 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
1956 radio1
->Enable(2, FALSE
);
1959 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
1960 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1961 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1963 sprintf (buf
, "%.2f", wx_printer_scale_x
);
1966 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
1967 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1969 sprintf (buf
, "%.2f", wx_printer_scale_y
);
1970 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
1971 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1975 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
1976 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
1977 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1979 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
1980 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
1981 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1985 delete[] orientation
;
1986 delete[] print_modes
;
1991 int wxPostScriptPrintDialog::ShowModal ()
1993 if ( wxDialog::ShowModal() == wxID_OK
)
1995 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
1996 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
1997 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
1998 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
1999 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2000 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2001 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2002 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2004 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->m_printerScaleX
);
2005 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->m_printerScaleY
);
2006 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->m_printerTranslateX
);
2007 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->m_printerTranslateY
);
2010 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2011 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2014 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? wxLANDSCAPE
: wxPORTRAIT
));
2017 switch ( radio1
->GetSelection() ) {
2018 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2019 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2020 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2029 // PostScript printer settings
2030 // RETAINED FOR BACKWARD COMPATIBILITY
2031 void wxSetPrinterCommand(const wxString
& cmd
)
2033 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2036 void wxSetPrintPreviewCommand(const wxString
& cmd
)
2038 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2041 void wxSetPrinterOptions(const wxString
& flags
)
2043 wxThePrintSetupData
->SetPrinterOptions(flags
);
2046 void wxSetPrinterFile(const wxString
& f
)
2048 wxThePrintSetupData
->SetPrinterFile(f
);
2051 void wxSetPrinterOrientation(int orient
)
2053 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2056 void wxSetPrinterScaling(double x
, double y
)
2058 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2061 void wxSetPrinterTranslation(long x
, long y
)
2063 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2066 // 1 = Preview, 2 = print to file, 3 = send to printer
2067 void wxSetPrinterMode(int mode
)
2069 wxThePrintSetupData
->SetPrinterMode(mode
);
2072 void wxSetAFMPath(const wxString
& f
)
2074 wxThePrintSetupData
->SetAFMPath(f
);
2077 // Get current values
2078 wxString
wxGetPrinterCommand()
2080 return wxThePrintSetupData
->GetPrinterCommand();
2083 wxString
wxGetPrintPreviewCommand()
2085 return wxThePrintSetupData
->GetPrintPreviewCommand();
2088 wxString
wxGetPrinterOptions()
2090 return wxThePrintSetupData
->GetPrinterOptions();
2093 wxString
wxGetPrinterFile()
2095 return wxThePrintSetupData
->GetPrinterFile();
2098 int wxGetPrinterOrientation()
2100 return wxThePrintSetupData
->GetPrinterOrientation();
2103 void wxGetPrinterScaling(double* x
, double* y
)
2105 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2108 void wxGetPrinterTranslation(long *x
, long *y
)
2110 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2113 int wxGetPrinterMode()
2115 return wxThePrintSetupData
->GetPrinterMode();
2118 wxString
wxGetAFMPath()
2120 return wxThePrintSetupData
->GetAFMPath();
2127 wxPrintSetupData::wxPrintSetupData()
2129 m_printerOrient
= wxPORTRAIT
;
2130 m_printerScaleX
= (double)1.0;
2131 m_printerScaleY
= (double)1.0;
2132 m_printerTranslateX
= 0;
2133 m_printerTranslateY
= 0;
2134 m_printerMode
= wxPRINT_MODE_FILE
;
2135 m_printColour
= TRUE
;
2138 wxPrintSetupData::~wxPrintSetupData()
2142 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2144 SetPrinterCommand(data
.GetPrinterCommand());
2145 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2146 SetPrinterOptions(data
.GetPrinterOptions());
2148 data
.GetPrinterTranslation(&x
, &y
);
2149 SetPrinterTranslation(x
, y
);
2152 data
.GetPrinterScaling(&x1
, &y1
);
2153 SetPrinterScaling(x1
, y1
);
2155 SetPrinterOrientation(data
.GetPrinterOrientation());
2156 SetPrinterMode(data
.GetPrinterMode());
2157 SetAFMPath(data
.GetAFMPath());
2158 SetPaperName(data
.GetPaperName());
2159 SetColour(data
.GetColour());
2162 // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData).
2163 void wxPrintSetupData::operator=(const wxPrintData
& data
)
2165 SetPrinterCommand(data
.GetPrinterCommand());
2166 SetPrintPreviewCommand(data
.GetPreviewCommand());
2167 SetPrinterOptions(data
.GetPrinterOptions());
2168 SetPrinterTranslation(data
.GetPrinterTranslateX(), data
.GetPrinterTranslateY());
2169 SetPrinterScaling(data
.GetPrinterScaleX(), data
.GetPrinterScaleY());
2170 SetPrinterOrientation(data
.GetOrientation());
2171 SetPrinterMode((int) data
.GetPrintMode());
2172 SetAFMPath(data
.GetFontMetricPath());
2173 SetPaperName(wxThePrintPaperDatabase
->ConvertIdToName(data
.GetPaperId()));
2174 SetColour(data
.GetColour());
2175 SetPrinterFile(data
.GetFilename());
2178 void wxInitializePrintSetupData(bool init
)
2182 wxThePrintSetupData
= new wxPrintSetupData
;
2184 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2185 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
2186 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_PREVIEW
);
2187 wxThePrintSetupData
->SetPaperName(_("A4 sheet, 210 x 297 mm"));
2189 // Could have a .ini file to read in some defaults
2190 // - and/or use environment variables, e.g. WXWIN
2192 wxThePrintSetupData
->SetPrinterCommand("print");
2193 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2194 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2197 wxThePrintSetupData
->SetPrinterCommand("print");
2198 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2199 wxThePrintSetupData
->SetPrinterOptions("");
2201 #if !defined(__VMS__) && !defined(__WXMSW__)
2202 wxThePrintSetupData
->SetPrinterCommand("lpr");
2203 wxThePrintSetupData
->SetPrinterOptions("");
2204 wxThePrintSetupData
->SetAFMPath("");
2209 if (wxThePrintSetupData
)
2210 delete wxThePrintSetupData
;
2211 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2215 // A module to allow initialization/cleanup of PostScript-related
2216 // things without calling these functions from app.cpp.
2218 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2220 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2222 wxPostScriptModule() {}
2227 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2230 * Initialization/cleanup module
2233 bool wxPostScriptModule::OnInit()
2235 wxInitializePrintSetupData();
2240 void wxPostScriptModule::OnExit()
2242 wxInitializePrintSetupData(FALSE
);