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"
28 #if wxUSE_PRINTING_ARCHITECTURE
32 #include "wx/dcmemory.h"
35 #include "wx/filedlg.h"
37 #include "wx/msgdlg.h"
40 #include "wx/generic/dcpsg.h"
41 #include "wx/generic/prntdlgg.h"
42 #include "wx/button.h"
43 #include "wx/stattext.h"
44 #include "wx/radiobox.h"
45 #include "wx/textctrl.h"
46 #include "wx/prntbase.h"
71 //-----------------------------------------------------------------------------
72 // start and end of document/page
73 //-----------------------------------------------------------------------------
75 static const char *wxPostScriptHeaderEllipse
= "\
76 /ellipsedict 8 dict def\n\
77 ellipsedict /mtrx matrix put\n\
81 /startangle exch def\n\
86 /savematrix mtrx currentmatrix def\n\
89 0 0 1 startangle endangle arc\n\
90 savematrix setmatrix\n\
95 static const char *wxPostScriptHeaderEllipticArc
= "\
96 /ellipticarcdict 8 dict def\n\
97 ellipticarcdict /mtrx matrix put\n\
99 { ellipticarcdict begin\n\
101 /endangle exch def\n\
102 /startangle exch def\n\
107 /savematrix mtrx currentmatrix def\n\
110 do_fill { 0 0 moveto } if\n\
111 0 0 1 startangle endangle arc\n\
112 savematrix setmatrix\n\
113 do_fill { fill }{ stroke } ifelse\n\
117 static const char *wxPostScriptHeaderSpline
= "\
118 /DrawSplineSection {\n\
125 /xa x1 x2 x1 sub 0.666667 mul add def\n\
126 /ya y1 y2 y1 sub 0.666667 mul add def\n\
127 /xb x3 x2 x3 sub 0.666667 mul add def\n\
128 /yb y3 y2 y3 sub 0.666667 mul add def\n\
130 xa ya xb yb x3 y3 curveto\n\
134 static const char *wxPostScriptHeaderColourImage
= "\
135 %% define 'colorimage' if it isn't defined\n\
136 %% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
138 /colorimage where %% do we know about 'colorimage'?\n\
139 { pop } %% yes: pop off the 'dict' returned\n\
140 { %% no: define one\n\
141 /colortogray { %% define an RGB->I function\n\
142 /rgbdata exch store %% call input 'rgbdata'\n\
143 rgbdata length 3 idiv\n\
144 /npixls exch store\n\
146 0 1 npixls 1 sub {\n\
148 rgbdata rgbindx get 20 mul %% Red\n\
149 rgbdata rgbindx 1 add get 32 mul %% Green\n\
150 rgbdata rgbindx 2 add get 12 mul %% Blue\n\
151 add add 64 idiv %% I = .5G + .31R + .18B\n\
153 /rgbindx rgbindx 3 add store\n\
155 grays 0 npixls getinterval\n\
158 %% Utility procedure for colorimage operator.\n\
159 %% This procedure takes two procedures off the\n\
160 %% stack and merges them into a single procedure.\n\
162 /mergeprocs { %% def\n\
181 /colorimage { %% def\n\
182 pop pop %% remove 'false 3' operands\n\
183 {colortogray} mergeprocs\n\
186 } ifelse %% end of 'false' case\n\
189 static char wxPostScriptHeaderReencodeISO1
[] =
191 "dup dup findfont dup length dict begin\n"
192 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
193 "/Encoding ISOLatin1Encoding def\n"
194 "currentdict end definefont\n"
196 "/ISOLatin1Encoding [\n"
197 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
198 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
199 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
200 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
201 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
202 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
203 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
204 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
205 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
206 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
207 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
208 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
209 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
210 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
211 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
213 static char wxPostScriptHeaderReencodeISO2
[] =
214 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
215 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
216 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
217 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
218 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
219 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
220 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
221 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
222 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
223 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
224 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
225 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
226 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
227 "/yacute/thorn/ydieresis\n"
230 //-------------------------------------------------------------------------------
232 //-------------------------------------------------------------------------------
234 wxPostScriptDC::wxPostScriptDC ()
236 m_pstream
= (FILE*) NULL
;
246 m_underlinePosition
= 0.0;
247 m_underlineThickness
= 0.0;
249 m_signX
= 1; // default x-axis left to right
250 m_signY
= -1; // default y-axis bottom up -> top down
252 // Compatibility only
253 m_printData
= * wxThePrintSetupData
;
256 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
258 m_pstream
= (FILE*) NULL
;
268 m_underlinePosition
= 0.0;
269 m_underlineThickness
= 0.0;
271 m_signX
= 1; // default x-axis left to right
272 m_signY
= -1; // default y-axis bottom up -> top down
274 Create(file
, interactive
, parent
);
277 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
279 m_isInteractive
= interactive
;
282 m_printData
.SetFilename(file
);
285 // Can only send to file in Windows
286 m_printData
.SetPrintMode(wxPRINT_MODE_FILE
);
291 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
301 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
303 m_pstream
= (FILE*) NULL
;
313 m_underlinePosition
= 0.0;
314 m_underlineThickness
= 0.0;
316 m_signX
= 1; // default x-axis left to right
317 m_signY
= -1; // default y-axis bottom up -> top down
319 m_printData
= printData
;
324 wxPostScriptDC::~wxPostScriptDC ()
329 m_pstream
= (FILE*) NULL
;
333 bool wxPostScriptDC::Ok() const
338 // This dialog is deprecated now: use wxGenericPrintDialog or the printing framework
339 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
341 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
342 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
343 m_ok
= (dialog
.ShowModal () == wxID_OK
);
345 if (!m_ok
) return FALSE
;
347 if ((m_printData
.GetFilename() == "") &&
348 (m_printData
.GetPrintMode() == wxPRINT_MODE_PREVIEW
||
349 m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
353 m_printData
.SetFilename("preview");
355 // For PS_PRINTER action this depends on a Unix-style print spooler
356 // since the wx_printer_file can be destroyed during a session
357 // @@@ TODO: a Windows-style answer for non-Unix
359 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
361 wxStrcpy (tmp
, _T("/tmp/preview_"));
362 wxStrcat (tmp
, userId
);
363 m_printData
.SetFilename(tmp
);
366 wxStrcpy(tmp2
, m_printData
.GetFilename());
367 wxStrcat (tmp2
, _T(".ps"));
368 m_printData
.SetFilename(tmp2
);
370 else if ((m_printData
.GetFilename() == _T("")) && (m_printData
.GetPrintMode() == wxPRINT_MODE_FILE
))
372 wxString file
= wxSaveFileSelector (_("PostScript"), _T("ps"));
373 if ( file
.IsEmpty() )
379 m_printData
.SetFilename(file
);
386 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
388 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
390 if (m_clipping
) return;
392 wxDC::SetClippingRegion( x
, y
, w
, h
);
401 "closepath clip newpath\n",
402 XLOG2DEV(x
), YLOG2DEV(y
),
403 XLOG2DEV(x
+w
), YLOG2DEV(y
),
404 XLOG2DEV(x
+w
), YLOG2DEV(y
+h
),
405 XLOG2DEV(x
), YLOG2DEV(y
+h
) );
408 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
410 wxFAIL_MSG( _T("wxPostScriptDC::SetClippingRegion not implemented.") );
413 void wxPostScriptDC::DestroyClippingRegion()
415 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
417 wxDC::DestroyClippingRegion();
422 fprintf( m_pstream
, "grestore\n" );
426 void wxPostScriptDC::Clear()
428 wxFAIL_MSG( _T("wxPostScriptDC::Clear not implemented.") );
431 void wxPostScriptDC::DoFloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
433 wxFAIL_MSG( _T("wxPostScriptDC::FloodFill not implemented.") );
436 bool wxPostScriptDC::DoGetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
438 wxFAIL_MSG( _T("wxPostScriptDC::GetPixel not implemented.") );
442 void wxPostScriptDC::DoCrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
444 wxFAIL_MSG( _T("wxPostScriptDC::CrossHair not implemented.") );
447 void wxPostScriptDC::DoDrawLine (long x1
, long y1
, long x2
, long y2
)
449 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
451 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
460 XLOG2DEV(x1
), YLOG2DEV(y1
),
461 XLOG2DEV(x2
), YLOG2DEV (y2
) );
463 CalcBoundingBox( x1
, y1
);
464 CalcBoundingBox( x2
, y2
);
467 #define RAD2DEG 57.29577951308
469 void wxPostScriptDC::DoDrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
471 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
475 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
476 double alpha1
, alpha2
;
478 if (x1
== x2
&& y1
== y2
)
483 else if (radius
== 0.0)
485 alpha1
= alpha2
= 0.0;
489 alpha1
= (x1
- xc
== 0) ?
490 (y1
- yc
< 0) ? 90.0 : -90.0 :
491 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
492 alpha2
= (x2
- xc
== 0) ?
493 (y2
- yc
< 0) ? 90.0 : -90.0 :
494 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
496 while (alpha1
<= 0) alpha1
+= 360;
497 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
498 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
499 while (alpha2
> 360) alpha2
-= 360;
501 if (m_brush
.GetStyle() != wxTRANSPARENT
)
507 "%ld %ld %ld %ld %ld %ld ellipse\n"
511 XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL(radius
), YLOG2DEVREL(radius
), (long)alpha1
, (long) alpha2
,
512 XLOG2DEV(xc
), YLOG2DEV(yc
) );
514 CalcBoundingBox( xc
-radius
, yc
-radius
);
515 CalcBoundingBox( xc
+radius
, yc
+radius
);
518 if (m_pen
.GetStyle() != wxTRANSPARENT
)
524 "%ld %ld %ld %ld %ld %ld ellipse\n"
528 XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL(radius
), YLOG2DEVREL(radius
), (long)alpha1
, (long) alpha2
,
529 XLOG2DEV(xc
), YLOG2DEV(yc
) );
531 CalcBoundingBox( xc
-radius
, yc
-radius
);
532 CalcBoundingBox( xc
+radius
, yc
+radius
);
536 void wxPostScriptDC::DoDrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
538 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
540 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
541 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
547 DrawEllipse(x
,y
,w
,h
);
551 if (m_brush
.GetStyle () != wxTRANSPARENT
)
557 "%ld %ld %ld %ld %ld %ld true ellipticarc\n",
558 XLOG2DEV(x
+w
/2), YLOG2DEV(y
+h
/2), XLOG2DEVREL(w
/2), YLOG2DEVREL(h
/2), (long)sa
, (long)ea
);
560 CalcBoundingBox( x
,y
);
561 CalcBoundingBox( x
+w
, y
+h
);
564 if (m_pen
.GetStyle () != wxTRANSPARENT
)
570 "%ld %ld %ld %ld %ld %ld false ellipticarc\n",
571 XLOG2DEV(x
+w
/2), YLOG2DEV(y
+h
/2), XLOG2DEVREL(w
/2), YLOG2DEVREL(h
/2), (long)sa
, (long)ea
);
573 CalcBoundingBox( x
,y
);
574 CalcBoundingBox( x
+w
, y
+h
);
578 void wxPostScriptDC::DoDrawPoint (long x
, long y
)
580 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
582 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
591 XLOG2DEV(x
), YLOG2DEV(y
),
592 XLOG2DEV(x
+1), YLOG2DEV(y
) );
594 CalcBoundingBox( x
, y
);
597 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
599 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
603 if (m_brush
.GetStyle () != wxTRANSPARENT
)
607 fprintf( m_pstream
, "newpath\n" );
609 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
610 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
612 fprintf( m_pstream
, "%ld %ld moveto\n", xx
, yy
);
614 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
616 for (int i
= 1; i
< n
; i
++)
618 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
619 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
621 fprintf( m_pstream
, "%ld %ld lineto\n", xx
, yy
);
623 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
626 fprintf( m_pstream
, "fill\n" );
629 if (m_pen
.GetStyle () != wxTRANSPARENT
)
633 fprintf( m_pstream
, "newpath\n" );
635 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
636 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
638 fprintf( m_pstream
, "%ld %ld moveto\n", xx
, yy
);
640 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
642 for (int i
= 1; i
< n
; i
++)
644 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
645 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
647 fprintf( m_pstream
, "%ld %ld lineto\n", xx
, yy
);
649 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
652 fprintf( m_pstream
, "fill\n" );
656 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
658 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
660 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
667 for ( i
=0; i
<n
; i
++ )
669 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
675 XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
677 for (i
= 1; i
< n
; i
++)
681 XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
684 fprintf( m_pstream
, "stroke\n" );
687 void wxPostScriptDC::DoDrawRectangle (long x
, long y
, long width
, long height
)
689 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
691 if (m_brush
.GetStyle () != wxTRANSPARENT
)
703 XLOG2DEV(x
), YLOG2DEV(y
),
704 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
705 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
706 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
708 CalcBoundingBox( x
, y
);
709 CalcBoundingBox( x
+ width
, y
+ height
);
712 if (m_pen
.GetStyle () != wxTRANSPARENT
)
724 XLOG2DEV(x
), YLOG2DEV(y
),
725 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
726 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
727 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
729 CalcBoundingBox( x
, y
);
730 CalcBoundingBox( x
+ width
, y
+ height
);
734 void wxPostScriptDC::DoDrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
736 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
740 // Now, a negative radius is interpreted to mean
741 // 'the proportion of the smallest X or Y dimension'
742 double smallest
= 0.0;
747 radius
= (-radius
* smallest
);
750 long rad
= (long) radius
;
752 if (m_brush
.GetStyle () != wxTRANSPARENT
)
756 /* Draw rectangle anticlockwise */
759 "%ld %ld %ld 90 180 arc\n"
761 "%ld %ld %ld 180 270 arc\n"
763 "%ld %ld %ld 270 0 arc\n"
765 "%ld %ld %ld 0 90 arc\n"
769 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
770 XLOG2DEV(x
), YLOG2DEV(y
+ rad
),
771 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
772 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
773 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
774 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
775 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
776 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
778 CalcBoundingBox( x
, y
);
779 CalcBoundingBox( x
+ width
, y
+ height
);
782 if (m_pen
.GetStyle () != wxTRANSPARENT
)
786 /* Draw rectangle anticlockwise */
789 "%ld %ld %ld 90 180 arc\n"
791 "%ld %ld %ld 180 270 arc\n"
793 "%ld %ld %ld 270 0 arc\n"
795 "%ld %ld %ld 0 90 arc\n"
799 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
800 XLOG2DEV(x
), YLOG2DEV(y
+ rad
),
801 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
802 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
803 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
804 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
805 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
806 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
808 CalcBoundingBox( x
, y
);
809 CalcBoundingBox( x
+ width
, y
+ height
);
813 void wxPostScriptDC::DoDrawEllipse (long x
, long y
, long width
, long height
)
815 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
817 if (m_brush
.GetStyle () != wxTRANSPARENT
)
823 "%ld %ld %ld %ld 0 360 ellipse\n"
825 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
826 XLOG2DEV(width
/ 2), YLOG2DEVREL(height
/ 2) );
828 CalcBoundingBox( x
- width
, y
- height
);
829 CalcBoundingBox( x
+ width
, y
+ height
);
832 if (m_pen
.GetStyle () != wxTRANSPARENT
)
838 "%ld %ld %ld %ld 0 360 ellipse\n"
840 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
841 XLOG2DEV(width
/ 2), YLOG2DEVREL(height
/ 2) );
843 CalcBoundingBox( x
- width
, y
- height
);
844 CalcBoundingBox( x
+ width
, y
+ height
);
848 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, long x
, long y
)
850 DrawBitmap( icon
, x
, y
, TRUE
);
853 /* this has to be char, not wxChar */
854 static char hexArray
[] = "0123456789ABCDEF";
855 static void LocalDecToHex( int dec
, char *buf
)
857 int firstDigit
= (int)(dec
/16.0);
858 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
859 buf
[0] = hexArray
[firstDigit
];
860 buf
[1] = hexArray
[secondDigit
];
864 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool WXUNUSED(useMask
) )
866 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
868 if (!bitmap
.Ok()) return;
870 wxImage
image( bitmap
);
872 if (!image
.Ok()) return;
874 long ww
= XLOG2DEVREL(image
.GetWidth());
875 long hh
= YLOG2DEVREL(image
.GetHeight());
877 image
= image
.Scale( ww
, hh
);
879 if (!image
.Ok()) return;
881 long xx
= XLOG2DEV(x
);
882 long yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
885 "/origstate save def\n"
887 "/pix %ld string def\n"
888 "/grays %ld string def\n"
891 "%ld %ld translate\n"
894 "[%ld 0 0 %ld 0 %ld]\n"
895 "{currentfile pix readhexstring pop}\n"
896 "false 3 colorimage\n",
897 ww
, ww
, xx
, yy
, ww
, hh
, ww
, hh
, ww
, -hh
, hh
);
899 for (int j
= 0; j
< hh
; j
++)
901 for (int i
= 0; i
< ww
; i
++)
904 LocalDecToHex( image
.GetRed(i
,j
), buffer
);
905 fprintf( m_pstream
, buffer
);
906 LocalDecToHex( image
.GetGreen(i
,j
), buffer
);
907 fprintf( m_pstream
, buffer
);
908 LocalDecToHex( image
.GetBlue(i
,j
), buffer
);
909 fprintf( m_pstream
, buffer
);
911 fprintf( m_pstream
, "\n" );
914 fprintf( m_pstream
, "end\n" );
915 fprintf( m_pstream
, "origstate restore\n" );
918 void wxPostScriptDC::SetFont( const wxFont
& font
)
920 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
922 if (!font
.Ok()) return;
927 const char *style
= "";
928 int Style
= m_font
.GetStyle();
929 int Weight
= m_font
.GetWeight();
931 switch (m_font
.GetFamily())
941 // name = "/Times-Roman";
942 name
= "/Times"; // Altered by EDZ
945 name
= "/Zapf-Chancery-MediumItalic";
950 case wxDEFAULT
: // Sans Serif Font
951 name
= "/LucidaSans";
954 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
956 if (m_font
.GetFamily () == wxROMAN
)
961 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
965 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
967 if (m_font
.GetFamily () == wxROMAN
)
972 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
974 if (m_font
.GetFamily () == wxROMAN
)
975 style
= "-BoldItalic";
977 style
= "-BoldOblique";
979 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
981 if (m_font
.GetFamily () == wxROMAN
)
986 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
988 if (m_font
.GetFamily () == wxROMAN
)
989 style
= "-BoldItalic";
991 style
= "-BoldOblique";
999 strcpy( buffer
, name
);
1000 strcat( buffer
, style
);
1002 fprintf( m_pstream
, buffer
);
1003 fprintf( m_pstream
, " reencodeISO def\n" );
1004 fprintf( m_pstream
, buffer
);
1005 fprintf( m_pstream
, " findfont\n" );
1006 fprintf( m_pstream
, "%ld scalefont setfont\n", YLOG2DEVREL(m_font
.GetPointSize()) );
1009 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1011 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1013 if (!pen
.Ok()) return;
1015 int oldStyle
= m_pen
.GetStyle();
1019 fprintf( m_pstream
, "%ld setlinewidth\n", XLOG2DEVREL(m_pen
.GetWidth()) );
1022 Line style - WRONG: 2nd arg is OFFSET
1024 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1025 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1026 ter is not number of values in the array of the first one, but an offset
1027 into this description of the pattern. I mean a real *offset* not index
1028 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1029 will be first black line *2* units long, then space 4 units, then the
1030 pattern of *3* units black, 4 units space will be repeated.
1033 static const char *dotted
= "[2 5] 2";
1034 static const char *short_dashed
= "[4 4] 2";
1035 static const char *long_dashed
= "[4 8] 2";
1036 static const char *dotted_dashed
= "[6 6 2 6] 4";
1038 const char *psdash
= (char *) NULL
;
1039 switch (m_pen
.GetStyle())
1041 case wxDOT
: psdash
= dotted
; break;
1042 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1043 case wxLONG_DASH
: psdash
= long_dashed
; break;
1044 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1047 default: psdash
= "[] 0"; break;
1050 if (oldStyle
!= m_pen
.GetStyle())
1052 fprintf( m_pstream
, psdash
);
1053 fprintf( m_pstream
," setdash\n" );
1057 unsigned char red
= m_pen
.GetColour().Red();
1058 unsigned char blue
= m_pen
.GetColour().Blue();
1059 unsigned char green
= m_pen
.GetColour().Green();
1063 // Anything not white is black
1064 if (! (red
== (unsigned char) 255 &&
1065 blue
== (unsigned char) 255 &&
1066 green
== (unsigned char) 255) )
1068 red
= (unsigned char) 0;
1069 green
= (unsigned char) 0;
1070 blue
= (unsigned char) 0;
1075 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1077 double redPS
= (double)(red
) / 255.0;
1078 double bluePS
= (double)(blue
) / 255.0;
1079 double greenPS
= (double)(green
) / 255.0;
1082 "%.8f %.8f %.8f setrgbcolor\n",
1083 redPS
, greenPS
, bluePS
);
1086 m_currentBlue
= blue
;
1087 m_currentGreen
= green
;
1091 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1093 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1095 if (!brush
.Ok()) return;
1100 unsigned char red
= m_brush
.GetColour().Red();
1101 unsigned char blue
= m_brush
.GetColour().Blue();
1102 unsigned char green
= m_brush
.GetColour().Green();
1106 // Anything not white is black
1107 if (! (red
== (unsigned char) 255 &&
1108 blue
== (unsigned char) 255 &&
1109 green
== (unsigned char) 255) )
1111 red
= (unsigned char) 0;
1112 green
= (unsigned char) 0;
1113 blue
= (unsigned char) 0;
1118 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1120 double redPS
= (double)(red
) / 255.0;
1121 double bluePS
= (double)(blue
) / 255.0;
1122 double greenPS
= (double)(green
) / 255.0;
1125 "%.8f %.8f %.8f setrgbcolor\n",
1126 redPS
, greenPS
, bluePS
);
1129 m_currentBlue
= blue
;
1130 m_currentGreen
= green
;
1134 void wxPostScriptDC::DoDrawText( const wxString
& text
, long x
, long y
)
1136 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1140 if (m_textForegroundColour
.Ok())
1142 unsigned char red
= m_textForegroundColour
.Red();
1143 unsigned char blue
= m_textForegroundColour
.Blue();
1144 unsigned char green
= m_textForegroundColour
.Green();
1148 // Anything not white is black
1149 if (! (red
== (unsigned char) 255 &&
1150 blue
== (unsigned char) 255 &&
1151 green
== (unsigned char) 255))
1153 red
= (unsigned char) 0;
1154 green
= (unsigned char) 0;
1155 blue
= (unsigned char) 0;
1159 // maybe setgray here ?
1160 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1162 double redPS
= (double)(red
) / 255.0;
1163 double bluePS
= (double)(blue
) / 255.0;
1164 double greenPS
= (double)(green
) / 255.0;
1167 "%.8f %.8f %.8f setrgbcolor\n",
1168 redPS
, greenPS
, bluePS
);
1171 m_currentBlue
= blue
;
1172 m_currentGreen
= green
;
1176 int size
= m_font
.GetPointSize();
1178 long by
= y
+ (long)floor( double(size
) * 2.0 / 3.0 ); // approximate baseline
1179 fprintf( m_pstream
, "%ld %ld moveto\n", XLOG2DEV(x
), YLOG2DEV(by
) );
1181 /* I don't know how to write char to a stream, so I use a mini string */
1185 fprintf( m_pstream
, "(" );
1186 const wxWX2MBbuf textbuf
= text
.mb_str();
1187 int len
= strlen(textbuf
);
1189 for (i
= 0; i
< len
; i
++)
1191 int c
= (unsigned char) textbuf
[i
];
1192 if (c
== ')' || c
== '(' || c
== '\\')
1194 /* Cope with special characters */
1195 fprintf( m_pstream
, "\\" );
1196 tmpbuf
[0] = (char) c
;
1197 fprintf( m_pstream
, tmpbuf
);
1199 else if ( c
>= 128 )
1201 /* Cope with character codes > 127 */
1202 fprintf(m_pstream
, "\\%o", c
);
1206 tmpbuf
[0] = (char) c
;
1207 fprintf( m_pstream
, tmpbuf
);
1211 fprintf( m_pstream
, ") show\n" );
1213 if (m_font
.GetUnderlined())
1215 long uy
= (long)(y
+ size
- m_underlinePosition
);
1217 GetTextExtent(text
, &w
, &h
);
1222 "%ld setlinewidth\n"
1226 XLOG2DEV(x
), YLOG2DEV(uy
),
1227 (long)m_underlineThickness
,
1228 XLOG2DEV(x
+ w
), YLOG2DEV(uy
) );
1231 CalcBoundingBox( x
, y
);
1232 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1236 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1238 m_backgroundBrush
= brush
;
1241 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1243 wxFAIL_MSG( _T("wxPostScriptDC::SetLogicalFunction not implemented.") );
1246 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1248 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1252 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1255 wxNode
*node
= points
->First();
1256 p
= (wxPoint
*)node
->Data();
1260 node
= node
->Next();
1261 p
= (wxPoint
*)node
->Data();
1264 x3
= a
= (double)(x1
+ c
) / 2;
1265 y3
= b
= (double)(y1
+ d
) / 2;
1271 XLOG2DEV((long)x1
), YLOG2DEV((long)y1
),
1272 XLOG2DEV((long)x3
), YLOG2DEV((long)y3
) );
1274 CalcBoundingBox( (long)x1
, (long)y1
);
1275 CalcBoundingBox( (long)x3
, (long)y3
);
1277 while ((node
= node
->Next()) != NULL
)
1279 q
= (wxPoint
*)node
->Data();
1287 x3
= (double)(x2
+ c
) / 2;
1288 y3
= (double)(y2
+ d
) / 2;
1291 "%ld %ld %ld %ld %ld %ld DrawSplineSection\n",
1292 XLOG2DEV((long)x1
), YLOG2DEV((long)y1
),
1293 XLOG2DEV((long)x2
), YLOG2DEV((long)y2
),
1294 XLOG2DEV((long)x3
), YLOG2DEV((long)y3
) );
1296 CalcBoundingBox( (long)x1
, (long)y1
);
1297 CalcBoundingBox( (long)x3
, (long)y3
);
1301 At this point, (x2,y2) and (c,d) are the position of the
1302 next-to-last and last point respectively, in the point list
1308 XLOG2DEV((long)c
), YLOG2DEV((long)d
) );
1311 long wxPostScriptDC::GetCharWidth() const
1313 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1314 return (long) (GetCharHeight() * 72.0 / 120.0);
1318 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1320 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1322 m_signX
= (xLeftRight
? 1 : -1);
1323 m_signY
= (yBottomUp
? 1 : -1);
1325 // FIXME there is no such function in MSW
1327 ComputeScaleAndOrigin();
1331 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1333 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1339 wxDC::SetDeviceOrigin( x
, h
-y
);
1342 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1344 wxPaperSize id
= m_printData
.GetPaperId();
1346 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1348 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1352 if (width
) *width
= paper
->GetSizeDeviceUnits().x
;
1353 if (height
) *height
= paper
->GetSizeDeviceUnits().y
;
1357 if (width
) *width
= 595;
1358 if (height
) *height
= 842;
1362 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1364 wxPaperSize id
= m_printData
.GetPaperId();
1366 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1368 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1372 if (width
) *width
= paper
->GetWidth() / 10;
1373 if (height
) *height
= paper
->GetHeight() / 10;
1377 if (width
) *width
= 210;
1378 if (height
) *height
= 297;
1382 // Resolution in pixels per logical inch
1383 wxSize
wxPostScriptDC::GetPPI(void) const
1385 return wxSize(72, 72);
1389 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1391 wxCHECK_MSG( m_ok
, FALSE
, _T("invalid postscript dc") );
1393 if (m_printData
.GetFilename() == "")
1395 wxString filename
= wxGetTempFileName("ps");
1396 m_printData
.SetFilename(filename
);
1399 m_pstream
= fopen( m_printData
.GetFilename().fn_str(), "w+" );
1403 wxMessageBox( _("Cannot open file for PostScript printing!"), _("Error"), wxOK
);
1410 fprintf( m_pstream
, "%%%%BeginProlog\n" );
1411 fprintf( m_pstream
, wxPostScriptHeaderEllipse
);
1412 fprintf( m_pstream
, wxPostScriptHeaderEllipticArc
);
1413 fprintf( m_pstream
, wxPostScriptHeaderColourImage
);
1414 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO1
);
1415 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO2
);
1416 if (wxPostScriptHeaderSpline
)
1417 fprintf( m_pstream
, wxPostScriptHeaderSpline
);
1418 fprintf( m_pstream
, "%%%%EndProlog\n" );
1420 SetBrush( *wxBLACK_BRUSH
);
1421 SetPen( *wxBLACK_PEN
);
1422 SetBackground( *wxWHITE_BRUSH
);
1423 SetTextForeground( *wxBLACK
);
1425 // set origin according to paper size
1426 SetDeviceOrigin( 0,0 );
1434 void wxPostScriptDC::EndDoc ()
1436 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1441 fprintf( m_pstream
, "grestore\n" );
1444 fclose( m_pstream
);
1445 m_pstream
= (FILE *) NULL
;
1447 wxChar
*header_file
= wxGetTempFileName("ps");
1449 m_pstream
= fopen( wxConvFile
.cWX2MB(header_file
) , "w+" );
1451 fprintf( m_pstream
, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings
1452 fprintf( m_pstream
, "%%%%Title: %s\n", m_title
.mb_str() );
1453 fprintf( m_pstream
, "%%%%Creator: %s\n", wxTheApp
->argv
[0] );
1454 fprintf( m_pstream
, "%%%%CreationDate: %s\n", wxNow().mb_str() );
1457 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1459 fprintf( m_pstream
, "%%%%For: %s ", MBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );
1460 wxChar userName
[245];
1461 if (wxGetUserName(userName
, sizeof(userName
)))
1462 fprintf( m_pstream
, " (%s)", MBSTRINGCAST wxConvCurrent
->cWX2MB(userName
) );
1463 fprintf( m_pstream
, "\n" );
1465 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1467 fprintf( m_pstream
, "%%%%For: %s\n", MBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );;
1470 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1472 long wx_printer_translate_x
, wx_printer_translate_y
;
1473 double wx_printer_scale_x
, wx_printer_scale_y
;
1475 wx_printer_translate_x
= m_printData
.GetPrinterTranslateX();
1476 wx_printer_translate_y
= m_printData
.GetPrinterTranslateY();
1478 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1479 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1481 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1482 fprintf( m_pstream
, "%%%%Orientation: Landscape\n" );
1484 fprintf( m_pstream
, "%%%%Orientation: Portrait\n" );
1486 // Compute the bounding box. Note that it is in the default user
1487 // coordinate system, thus we have to convert the values.
1488 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1489 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1490 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1491 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1493 // If we're landscape, our sense of "x" and "y" is reversed.
1494 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1497 tmp
= llx
; llx
= lly
; lly
= tmp
;
1498 tmp
= urx
; urx
= ury
; ury
= tmp
;
1500 // We need either the two lines that follow, or we need to subtract
1501 // min_x from real_translate_y, which is commented out below.
1502 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1503 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1506 // The Adobe specifications call for integers; we round as to make
1507 // the bounding larger.
1509 "%%%%BoundingBox: %ld %ld %ld %ld\n",
1510 (long)floor((double)llx
), (long)floor((double)lly
),
1511 (long)ceil((double)urx
), (long)ceil((double)ury
) );
1512 fprintf( m_pstream
, "%%%%Pages: %d\n", (wxPageNumber
- 1) );
1513 fprintf( m_pstream
, "%%%%EndComments\n\n" );
1515 // To check the correctness of the bounding box, postscript commands
1516 // to draw a box corresponding to the bounding box are generated below.
1517 // But since we typically don't want to print such a box, the postscript
1518 // commands are generated within comments. These lines appear before any
1519 // adjustment of scale, rotation, or translation, and hence are in the
1520 // default user coordinates.
1521 fprintf( m_pstream
, "%% newpath\n" );
1522 fprintf( m_pstream
, "%% %ld %ld moveto\n", llx
, lly
);
1523 fprintf( m_pstream
, "%% %ld %ld lineto\n", urx
, lly
);
1524 fprintf( m_pstream
, "%% %ld %ld lineto\n", urx
, ury
);
1525 fprintf( m_pstream
, "%% %ld %ld lineto closepath stroke\n", llx
, ury
);
1527 fclose( m_pstream
);
1528 m_pstream
= (FILE*) NULL
;
1530 wxChar
*tmp_file
= wxGetTempFileName("ps");
1532 // Paste header Before wx_printer_file
1533 wxConcatFiles (header_file
, m_printData
.GetFilename(), tmp_file
);
1534 wxRemoveFile( header_file
);
1535 wxRemoveFile( m_printData
.GetFilename() );
1536 wxRenameFile( tmp_file
, m_printData
.GetFilename() );
1538 #if defined(__X__) || defined(__WXGTK__)
1541 wxString
previewCommand(m_printData
.GetPreviewCommand());
1542 wxString
printerCommand(m_printData
.GetPrinterCommand());
1543 wxString
printerOptions(m_printData
.GetPrinterOptions());
1544 wxString
filename(m_printData
.GetFilename());
1546 switch (m_printData
.GetPrintMode())
1548 case wxPRINT_MODE_PREVIEW
:
1551 argv
[0] = WXSTRINGCAST previewCommand
;
1552 argv
[1] = WXSTRINGCAST filename
;
1553 argv
[2] = (wxChar
*) NULL
;
1554 wxExecute( argv
, TRUE
);
1555 wxRemoveFile( m_printData
.GetFilename() );
1558 case wxPRINT_MODE_PRINTER
:
1562 argv
[argc
++] = WXSTRINGCAST printerCommand
;
1564 // !SM! If we simply assign to argv[1] here, if printer options
1565 // are blank, we get an annoying and confusing message from lpr.
1566 wxChar
*opts
= WXSTRINGCAST printerOptions
;
1568 argv
[argc
++] = opts
;
1570 argv
[argc
++] = WXSTRINGCAST filename
;
1571 argv
[argc
++] = (wxChar
*) NULL
;
1572 wxExecute( argv
, TRUE
);
1573 wxRemoveFile( filename
);
1576 case wxPRINT_MODE_FILE
:
1577 case wxPRINT_MODE_NONE
:
1584 void wxPostScriptDC::StartPage()
1586 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1588 fprintf( m_pstream
, "%%%%Page: %d\n", wxPageNumber
++ );
1590 // *m_pstream << "matrix currentmatrix\n";
1592 // Added by Chris Breeze
1594 // Each page starts with an "initgraphics" which resets the
1595 // transformation and so we need to reset the origin
1596 // (and rotate the page for landscape printing)
1599 m_scaleFactor = 1.0;
1600 m_logicalOriginX = 0;
1601 m_logicalOriginY = 0;
1604 long translate_x
, translate_y
;
1605 double scale_x
, scale_y
;
1607 translate_x
= m_printData
.GetPrinterTranslateX();
1608 translate_y
= m_printData
.GetPrinterTranslateY();
1610 scale_x
= m_printData
.GetPrinterScaleX();
1611 scale_y
= m_printData
.GetPrinterScaleY();
1613 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1615 // translate_y -= m_maxY;
1616 // fprintf( m_pstream, "90 rotate\n" );
1620 fprintf( m_pstream
, "90 rotate llx neg ury nef translate\n" );
1623 // fprintf( m_pstream, "%.8f %.8f scale\n", scale_x, scale_y );
1624 // fprintf( m_pstream, "%ld %ld translate\n", translate_x, translate_y );
1627 void wxPostScriptDC::EndPage ()
1629 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1631 fprintf( m_pstream
, "showpage\n" );
1634 bool wxPostScriptDC::DoBlit( long xdest
, long ydest
,
1635 long fwidth
, long fheight
,
1637 long xsrc
, long ysrc
,
1638 int rop
, bool WXUNUSED(useMask
) )
1640 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, _T("invalid postscript dc") );
1642 wxCHECK_MSG( source
, FALSE
, _T("invalid source dc") );
1644 /* blit into a bitmap */
1645 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1647 memDC
.SelectObject(bitmap
);
1648 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1649 memDC
.SelectObject(wxNullBitmap
);
1651 /* draw bitmap. scaling and positioning is done there */
1652 DrawBitmap( bitmap
, xdest
, ydest
);
1657 long wxPostScriptDC::GetCharHeight() const
1660 return m_font
.GetPointSize();
1665 void wxPostScriptDC::GetTextExtent( const wxString
& string
, long *x
, long *y
,
1666 long *descent
, long *externalLeading
, wxFont
*theFont
) const
1668 wxFont
*fontToUse
= theFont
;
1670 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1672 wxCHECK_RET( fontToUse
, _T("GetTextExtent: no font defined") );
1673 wxCHECK_RET( x
, _T("GetTextExtent: x == NULL") );
1674 wxCHECK_RET( y
, _T("GetTextExtent: y == NULL") );
1676 const wxWX2MBbuf strbuf
= string
.mb_str();
1678 #if !USE_AFM_FOR_POSTSCRIPT
1679 /* Provide a VERY rough estimate (avoid using it).
1680 * Produces accurate results for mono-spaced font
1681 * such as Courier (aka wxMODERN) */
1686 height
= fontToUse
->GetPointSize();
1688 *x
= strlen (strbuf
) * height
* 72 / 120;
1689 *y
= (long) (height
* 1.32); /* allow for descender */
1690 if (descent
) *descent
= 0;
1691 if (externalLeading
) *externalLeading
= 0;
1694 /* method for calculating string widths in postscript:
1695 / read in the AFM (adobe font metrics) file for the
1696 / actual font, parse it and extract the character widths
1697 / and also the descender. this may be improved, but for now
1698 / it works well. the AFM file is only read in if the
1699 / font is changed. this may be chached in the future.
1700 / calls to GetTextExtent with the font unchanged are rather
1703 / for each font and style used there is an AFM file necessary.
1704 / currently i have only files for the roman font family.
1705 / I try to get files for the other ones!
1707 / CAVE: the size of the string is currently always calculated
1708 / in 'points' (1/72 of an inch). this should later on be
1709 / changed to depend on the mapping mode.
1710 / CAVE: the path to the AFM files must be set before calling this
1711 / function. this is usually done by a call like the following:
1712 / wxSetAFMPath("d:\\wxw161\\afm\\");
1716 / wxPostScriptDC dc(NULL, TRUE);
1718 / wxSetAFMPath("d:\\wxw161\\afm\\");
1719 / dc.StartDoc("Test");
1722 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1723 / dc.GetTextExtent("Hallo",&w,&h);
1728 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1730 / updated: 14.05.95 */
1732 /* these static vars are for storing the state between calls */
1733 static int lastFamily
= INT_MIN
;
1734 static int lastSize
= INT_MIN
;
1735 static int lastStyle
= INT_MIN
;
1736 static int lastWeight
= INT_MIN
;
1737 static int lastDescender
= INT_MIN
;
1738 static int lastWidths
[256]; /* widths of the characters */
1740 /* get actual parameters */
1741 const int Family
= fontToUse
->GetFamily();
1742 const int Size
= fontToUse
->GetPointSize();
1743 const int Style
= fontToUse
->GetStyle();
1744 const int Weight
= fontToUse
->GetWeight();
1746 /* if we have another font, read the font-metrics */
1747 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1749 /* store actual values */
1750 lastFamily
= Family
;
1753 lastWeight
= Weight
;
1755 char *name
= (char*) NULL
;
1761 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO";
1762 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo";
1763 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Cour0";
1769 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO";
1770 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo";
1771 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO";
1772 else if name
= "TimesRo"; /* no typo */
1777 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO";
1778 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo";
1779 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Helv0";
1785 /* get the directory of the AFM files */
1789 if (!m_printData
.GetFontMetricPath().IsEmpty())
1791 strcpy( afmName
, m_printData
.GetFontMetricPath().fn_str() )
1794 /* 2. open and process the file
1795 / a short explanation of the AFM format:
1796 / we have for each character a line, which gives its size
1799 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1801 / that means, we have a character with ascii code 63, and width
1802 / (444/1000 * fontSize) points.
1803 / the other data is ignored for now!
1805 / when the font has changed, we read in the right AFM file and store the
1806 / character widths in an array, which is processed below (see point 3.). */
1808 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
1810 strcat(afmName
,name
);
1811 strcat(afmName
,".afm");
1812 FILE *afmFile
= fopen(afmName
,"r");
1817 strcpy( afmName
, "/usr/local/share/wx/gs_afm/" );
1818 strcat(afmName
,name
);
1819 strcat(afmName
,".afm");
1820 FILE *afmFile
= fopen(afmName
,"r");
1825 strcpy( afmName
, "/usr/share/wx/gs_afm/" );
1826 strcat(afmName
,name
);
1827 strcat(afmName
,".afm");
1828 FILE *afmFile
= fopen(afmName
,"r");
1834 wxLogDebug( "GetTextExtent: can't open AFM file '%s'\n", afmName
);
1835 wxLogDebug( " using approximate values\n");
1836 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
1837 lastDescender
= -150; /* dito. */
1841 /* init the widths array */
1842 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
1843 /* some variables for holding parts of a line */
1844 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1845 char upString
[30], utString
[30], encString
[50];
1848 /* read in the file and parse it */
1849 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
1851 /* A.) check for descender definition */
1852 if (strncmp(line
,"Descender",9)==0)
1854 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
1855 (strcmp(descString
,"Descender")!=0))
1857 wxLogDebug( "AFM-file '%s': line '%s' has error (bad descender)\n", afmName
,line
);
1860 /* JC 1.) check for UnderlinePosition */
1861 else if(strncmp(line
,"UnderlinePosition",17)==0)
1863 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
1864 (strcmp(upString
,"UnderlinePosition")!=0))
1866 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", afmName
, line
);
1869 /* JC 2.) check for UnderlineThickness */
1870 else if(strncmp(line
,"UnderlineThickness",18)==0)
1872 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
1873 (strcmp(utString
,"UnderlineThickness")!=0))
1875 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", afmName
, line
);
1878 /* JC 3.) check for EncodingScheme */
1879 else if(strncmp(line
,"EncodingScheme",14)==0)
1881 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
1882 (strcmp(utString
,"EncodingScheme")!=0))
1884 wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", afmName
, line
);
1886 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1888 wxLogDebug( "AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1889 afmName
,line
, encString
);
1892 /* B.) check for char-width */
1893 else if(strncmp(line
,"C ",2)==0)
1895 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
1897 wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1899 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
1901 wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1903 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
1904 if (ascii
>=0 && ascii
<256)
1906 lastWidths
[ascii
] = cWidth
; /* store width */
1910 /* MATTHEW: this happens a lot; don't print an error */
1911 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); */
1914 /* C.) ignore other entries. */
1918 /* hack to compute correct values for german 'Umlaute'
1919 / the correct way would be to map the character names
1920 / like 'adieresis' to corresp. positions of ISOEnc and read
1921 / these values from AFM files, too. Maybe later ... */
1922 lastWidths
[196] = lastWidths
['A']; // Ä
1923 lastWidths
[228] = lastWidths
['a']; // ä
1924 lastWidths
[214] = lastWidths
['O']; // Ö
1925 lastWidths
[246] = lastWidths
['o']; // ö
1926 lastWidths
[220] = lastWidths
['U']; // Ü
1927 lastWidths
[252] = lastWidths
['u']; // ü
1928 lastWidths
[223] = lastWidths
[251]; // ß
1931 /* JC: calculate UnderlineThickness/UnderlinePosition */
1932 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1933 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1935 /* 3. now the font metrics are read in, calc size this
1936 / is done by adding the widths of the characters in the
1937 / string. they are given in 1/1000 of the size! */
1940 long height
=Size
; /* by default */
1942 for(p
=(unsigned char *)strbuf
; *p
; p
++)
1944 if(lastWidths
[*p
]== INT_MIN
)
1946 wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n", *p
,*p
);
1947 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); /* assume space */
1951 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1955 /* add descender to height (it is usually a negative value) */
1956 if (lastDescender
!=INT_MIN
)
1958 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1961 /* return size values */
1965 /* return other parameters */
1968 if(lastDescender
!=INT_MIN
)
1970 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1978 /* currently no idea how to calculate this! */
1979 if (externalLeading
) *externalLeading
= 0;
1984 // Determine the Default Postscript Previewer
1985 // available on the platform
1986 #if defined(__SUN__) && defined(__XVIEW__)
1987 // OpenWindow/NeWS's Postscript Previewer
1988 # define PS_VIEWER_PROG "pageview"
1989 #elif defined(__VMS__)
1990 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
1991 #elif defined(__SGI__)
1992 // SGI's Display Postscript Previewer
1993 //# define PS_VIEWER_PROG "dps"
1994 # define PS_VIEWER_PROG "xpsview"
1995 #elif defined(__X__) || defined(__WXGTK__)
1996 // Front-end to ghostscript
1997 # define PS_VIEWER_PROG "ghostview"
1999 // Windows ghostscript/ghostview
2000 # define PS_VIEWER_PROG NULL
2003 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2005 #if !USE_SHARED_LIBRARY
2006 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
2007 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
2010 // Redundant now I think
2012 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2014 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2015 const wxPoint
& pos
, const wxSize
& size
, long style
):
2016 wxDialog(parent
, -1, title
, pos
, size
, style
)
2018 wxBeginBusyCursor();
2023 *orientation
= new wxString
[2],
2024 *print_modes
= new wxString
[3];
2026 long wx_printer_translate_x
, wx_printer_translate_y
;
2027 double wx_printer_scale_x
, wx_printer_scale_y
;
2029 orientation
[0] = _("Portrait");
2030 orientation
[1] = _("Landscape");
2032 print_modes
[0] = _("Send to Printer");
2033 print_modes
[1] = _("Print to File");
2034 print_modes
[2] = _("Preview Only");
2038 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2039 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2040 okBut
->SetDefault();
2043 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2044 (void) new wxStaticText( this, -1, _("Printer Command: "),
2046 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2047 wxPoint(100, yPos
), wxSize(100, -1) );
2049 (void) new wxStaticText( this, -1, _("Printer Options: "),
2050 wxPoint(210, yPos
) );
2051 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2052 wxPoint(305, yPos
), wxSize(150, -1) );
2058 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2059 2,orientation
,2,wxRA_SPECIFY_ROWS
);
2060 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2062 // @@@ Configuration hook
2063 if ( !wxThePrintSetupData
->GetPrintPreviewCommand() )
2064 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2066 // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand);
2068 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
2069 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2071 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2073 wxSize(-1,-1), features
,
2074 print_modes
, features
, wxRA_SPECIFY_ROWS
);
2077 radio1
->Enable(0, FALSE
);
2078 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2079 radio1
->Enable(2, FALSE
);
2082 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2083 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2084 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2086 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2089 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2090 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2092 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2093 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2094 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2098 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2099 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
2100 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2102 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2103 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
2104 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2108 delete[] orientation
;
2109 delete[] print_modes
;
2114 int wxPostScriptPrintDialog::ShowModal ()
2116 if ( wxDialog::ShowModal() == wxID_OK
)
2118 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2119 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2120 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2121 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2122 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2123 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2124 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2125 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2127 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->m_printerScaleX
);
2128 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->m_printerScaleY
);
2129 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->m_printerTranslateX
);
2130 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->m_printerTranslateY
);
2133 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2134 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2137 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? wxLANDSCAPE
: wxPORTRAIT
));
2140 switch ( radio1
->GetSelection() ) {
2141 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2142 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2143 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2152 // PostScript printer settings
2153 // RETAINED FOR BACKWARD COMPATIBILITY
2154 void wxSetPrinterCommand(const wxString
& cmd
)
2156 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2159 void wxSetPrintPreviewCommand(const wxString
& cmd
)
2161 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2164 void wxSetPrinterOptions(const wxString
& flags
)
2166 wxThePrintSetupData
->SetPrinterOptions(flags
);
2169 void wxSetPrinterFile(const wxString
& f
)
2171 wxThePrintSetupData
->SetPrinterFile(f
);
2174 void wxSetPrinterOrientation(int orient
)
2176 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2179 void wxSetPrinterScaling(double x
, double y
)
2181 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2184 void wxSetPrinterTranslation(long x
, long y
)
2186 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2189 // 1 = Preview, 2 = print to file, 3 = send to printer
2190 void wxSetPrinterMode(int mode
)
2192 wxThePrintSetupData
->SetPrinterMode(mode
);
2195 void wxSetAFMPath(const wxString
& f
)
2197 wxThePrintSetupData
->SetAFMPath(f
);
2200 // Get current values
2201 wxString
wxGetPrinterCommand()
2203 return wxThePrintSetupData
->GetPrinterCommand();
2206 wxString
wxGetPrintPreviewCommand()
2208 return wxThePrintSetupData
->GetPrintPreviewCommand();
2211 wxString
wxGetPrinterOptions()
2213 return wxThePrintSetupData
->GetPrinterOptions();
2216 wxString
wxGetPrinterFile()
2218 return wxThePrintSetupData
->GetPrinterFile();
2221 int wxGetPrinterOrientation()
2223 return wxThePrintSetupData
->GetPrinterOrientation();
2226 void wxGetPrinterScaling(double* x
, double* y
)
2228 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2231 void wxGetPrinterTranslation(long *x
, long *y
)
2233 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2236 int wxGetPrinterMode()
2238 return wxThePrintSetupData
->GetPrinterMode();
2241 wxString
wxGetAFMPath()
2243 return wxThePrintSetupData
->GetAFMPath();
2250 wxPrintSetupData::wxPrintSetupData()
2252 m_printerOrient
= wxPORTRAIT
;
2253 m_printerScaleX
= (double)1.0;
2254 m_printerScaleY
= (double)1.0;
2255 m_printerTranslateX
= 0;
2256 m_printerTranslateY
= 0;
2257 m_printerMode
= wxPRINT_MODE_FILE
;
2258 m_printColour
= TRUE
;
2261 wxPrintSetupData::~wxPrintSetupData()
2265 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2267 SetPrinterCommand(data
.GetPrinterCommand());
2268 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2269 SetPrinterOptions(data
.GetPrinterOptions());
2271 data
.GetPrinterTranslation(&x
, &y
);
2272 SetPrinterTranslation(x
, y
);
2275 data
.GetPrinterScaling(&x1
, &y1
);
2276 SetPrinterScaling(x1
, y1
);
2278 SetPrinterOrientation(data
.GetPrinterOrientation());
2279 SetPrinterMode(data
.GetPrinterMode());
2280 SetAFMPath(data
.GetAFMPath());
2281 SetPaperName(data
.GetPaperName());
2282 SetColour(data
.GetColour());
2285 // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData).
2286 void wxPrintSetupData::operator=(const wxPrintData
& data
)
2288 SetPrinterCommand(data
.GetPrinterCommand());
2289 SetPrintPreviewCommand(data
.GetPreviewCommand());
2290 SetPrinterOptions(data
.GetPrinterOptions());
2291 SetPrinterTranslation(data
.GetPrinterTranslateX(), data
.GetPrinterTranslateY());
2292 SetPrinterScaling(data
.GetPrinterScaleX(), data
.GetPrinterScaleY());
2293 SetPrinterOrientation(data
.GetOrientation());
2294 SetPrinterMode((int) data
.GetPrintMode());
2295 SetAFMPath(data
.GetFontMetricPath());
2296 SetPaperName(wxThePrintPaperDatabase
->ConvertIdToName(data
.GetPaperId()));
2297 SetColour(data
.GetColour());
2298 SetPrinterFile(data
.GetFilename());
2301 void wxInitializePrintSetupData(bool init
)
2305 wxThePrintSetupData
= new wxPrintSetupData
;
2307 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2308 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
2309 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_PREVIEW
);
2310 wxThePrintSetupData
->SetPaperName(_("A4 sheet, 210 x 297 mm"));
2312 // Could have a .ini file to read in some defaults
2313 // - and/or use environment variables, e.g. WXWIN
2315 wxThePrintSetupData
->SetPrinterCommand("print");
2316 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2317 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2320 wxThePrintSetupData
->SetPrinterCommand("print");
2321 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2322 wxThePrintSetupData
->SetPrinterOptions("");
2324 #if !defined(__VMS__) && !defined(__WXMSW__)
2325 wxThePrintSetupData
->SetPrinterCommand("lpr");
2326 wxThePrintSetupData
->SetPrinterOptions("");
2327 wxThePrintSetupData
->SetAFMPath("");
2332 if (wxThePrintSetupData
)
2333 delete wxThePrintSetupData
;
2334 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2338 // A module to allow initialization/cleanup of PostScript-related
2339 // things without calling these functions from app.cpp.
2341 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2343 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2345 wxPostScriptModule() {}
2350 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2353 * Initialization/cleanup module
2356 bool wxPostScriptModule::OnInit()
2358 wxInitializePrintSetupData();
2363 void wxPostScriptModule::OnExit()
2365 wxInitializePrintSetupData(FALSE
);
2372 // wxUSE_PRINTING_ARCHITECTURE