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/window.h"
33 #include "wx/dcmemory.h"
36 #include "wx/filedlg.h"
38 #include "wx/msgdlg.h"
41 #include "wx/generic/dcpsg.h"
42 #include "wx/generic/prntdlgg.h"
43 #include "wx/button.h"
44 #include "wx/stattext.h"
45 #include "wx/radiobox.h"
46 #include "wx/textctrl.h"
47 #include "wx/prntbase.h"
49 #include "wx/filefn.h"
73 //-----------------------------------------------------------------------------
74 // start and end of document/page
75 //-----------------------------------------------------------------------------
77 static const char *wxPostScriptHeaderEllipse
= "\
78 /ellipsedict 8 dict def\n\
79 ellipsedict /mtrx matrix put\n\
83 /startangle exch def\n\
88 /savematrix mtrx currentmatrix def\n\
91 0 0 1 startangle endangle arc\n\
92 savematrix setmatrix\n\
97 static const char *wxPostScriptHeaderEllipticArc
= "\
98 /ellipticarcdict 8 dict def\n\
99 ellipticarcdict /mtrx matrix put\n\
101 { ellipticarcdict begin\n\
103 /endangle exch def\n\
104 /startangle exch def\n\
109 /savematrix mtrx currentmatrix def\n\
112 do_fill { 0 0 moveto } if\n\
113 0 0 1 startangle endangle arc\n\
114 savematrix setmatrix\n\
115 do_fill { fill }{ stroke } ifelse\n\
119 static const char *wxPostScriptHeaderSpline
= "\
120 /DrawSplineSection {\n\
127 /xa x1 x2 x1 sub 0.666667 mul add def\n\
128 /ya y1 y2 y1 sub 0.666667 mul add def\n\
129 /xb x3 x2 x3 sub 0.666667 mul add def\n\
130 /yb y3 y2 y3 sub 0.666667 mul add def\n\
132 xa ya xb yb x3 y3 curveto\n\
136 static const char *wxPostScriptHeaderColourImage
= "\
137 %% define 'colorimage' if it isn't defined\n\
138 %% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
140 /colorimage where %% do we know about 'colorimage'?\n\
141 { pop } %% yes: pop off the 'dict' returned\n\
142 { %% no: define one\n\
143 /colortogray { %% define an RGB->I function\n\
144 /rgbdata exch store %% call input 'rgbdata'\n\
145 rgbdata length 3 idiv\n\
146 /npixls exch store\n\
148 0 1 npixls 1 sub {\n\
150 rgbdata rgbindx get 20 mul %% Red\n\
151 rgbdata rgbindx 1 add get 32 mul %% Green\n\
152 rgbdata rgbindx 2 add get 12 mul %% Blue\n\
153 add add 64 idiv %% I = .5G + .31R + .18B\n\
155 /rgbindx rgbindx 3 add store\n\
157 grays 0 npixls getinterval\n\
160 %% Utility procedure for colorimage operator.\n\
161 %% This procedure takes two procedures off the\n\
162 %% stack and merges them into a single procedure.\n\
164 /mergeprocs { %% def\n\
183 /colorimage { %% def\n\
184 pop pop %% remove 'false 3' operands\n\
185 {colortogray} mergeprocs\n\
188 } ifelse %% end of 'false' case\n\
191 static char wxPostScriptHeaderReencodeISO1
[] =
193 "dup dup findfont dup length dict begin\n"
194 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
195 "/Encoding ISOLatin1Encoding def\n"
196 "currentdict end definefont\n"
198 "/ISOLatin1Encoding [\n"
199 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
200 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
201 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
202 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
203 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
204 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
205 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
206 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
207 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
208 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
209 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
210 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
211 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
212 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
213 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
215 static char wxPostScriptHeaderReencodeISO2
[] =
216 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
217 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
218 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
219 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
220 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
221 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
222 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
223 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
224 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
225 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
226 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
227 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
228 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
229 "/yacute/thorn/ydieresis\n"
232 //-------------------------------------------------------------------------------
234 //-------------------------------------------------------------------------------
236 float wxPostScriptDC::ms_PSScaleFactor
= 10.0;
238 void wxPostScriptDC::SetResolution(int ppi
)
240 ms_PSScaleFactor
= (float)ppi
/ 72.0;
243 int wxPostScriptDC::GetResolution()
245 return (int)(ms_PSScaleFactor
* 72.0);
250 wxPostScriptDC::wxPostScriptDC ()
252 m_pstream
= (FILE*) NULL
;
262 m_underlinePosition
= 0.0;
263 m_underlineThickness
= 0.0;
265 m_signX
= 1; // default x-axis left to right
266 m_signY
= -1; // default y-axis bottom up -> top down
268 // Compatibility only
269 // HH: Doesn't seem to work for wxMSW...
271 m_printData
= * wxThePrintSetupData
;
275 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
277 m_pstream
= (FILE*) NULL
;
287 m_underlinePosition
= 0.0;
288 m_underlineThickness
= 0.0;
290 m_signX
= 1; // default x-axis left to right
291 m_signY
= -1; // default y-axis bottom up -> top down
293 Create(file
, interactive
, parent
);
296 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
298 m_isInteractive
= interactive
;
301 m_printData
.SetFilename(file
);
304 // Can only send to file in Windows
305 m_printData
.SetPrintMode(wxPRINT_MODE_FILE
);
310 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
320 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
322 m_pstream
= (FILE*) NULL
;
332 m_underlinePosition
= 0.0;
333 m_underlineThickness
= 0.0;
335 m_signX
= 1; // default x-axis left to right
336 m_signY
= -1; // default y-axis bottom up -> top down
338 m_printData
= printData
;
343 wxPostScriptDC::~wxPostScriptDC ()
348 m_pstream
= (FILE*) NULL
;
352 bool wxPostScriptDC::Ok() const
357 // This dialog is deprecated now: use wxGenericPrintDialog or the printing framework
358 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
360 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
361 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
362 m_ok
= (dialog
.ShowModal () == wxID_OK
);
364 if (!m_ok
) return FALSE
;
366 if ((m_printData
.GetFilename() == "") &&
367 (m_printData
.GetPrintMode() == wxPRINT_MODE_PREVIEW
||
368 m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
372 m_printData
.SetFilename("preview");
374 // For PS_PRINTER action this depends on a Unix-style print spooler
375 // since the wx_printer_file can be destroyed during a session
376 // @@@ TODO: a Windows-style answer for non-Unix
378 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
380 wxStrcpy (tmp
, wxT("/tmp/preview_"));
381 wxStrcat (tmp
, userId
);
382 m_printData
.SetFilename(tmp
);
385 wxStrcpy(tmp2
, m_printData
.GetFilename());
386 wxStrcat (tmp2
, wxT(".ps"));
387 m_printData
.SetFilename(tmp2
);
389 else if ((m_printData
.GetFilename() == wxT("")) && (m_printData
.GetPrintMode() == wxPRINT_MODE_FILE
))
391 wxString file
= wxSaveFileSelector (_("PostScript"), wxT("ps"));
392 if ( file
.IsEmpty() )
398 m_printData
.SetFilename(file
);
405 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
407 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
409 if (m_clipping
) DestroyClippingRegion();
411 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
420 "closepath clip newpath\n",
421 XLOG2DEV(x
), YLOG2DEV(y
),
422 XLOG2DEV(x
+w
), YLOG2DEV(y
),
423 XLOG2DEV(x
+w
), YLOG2DEV(y
+h
),
424 XLOG2DEV(x
), YLOG2DEV(y
+h
) );
428 void wxPostScriptDC::DestroyClippingRegion()
430 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
435 fprintf( m_pstream
, "grestore\n" );
438 wxDC::DestroyClippingRegion();
441 void wxPostScriptDC::Clear()
443 wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
446 void wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
448 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
451 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
453 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
457 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
459 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
462 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
464 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
466 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
475 XLOG2DEV(x1
), YLOG2DEV(y1
),
476 XLOG2DEV(x2
), YLOG2DEV (y2
) );
478 CalcBoundingBox( x1
, y1
);
479 CalcBoundingBox( x2
, y2
);
482 #define RAD2DEG 57.29577951308
484 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
486 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
488 wxCoord dx
= x1
- xc
;
489 wxCoord dy
= y1
- yc
;
490 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
491 double alpha1
, alpha2
;
493 if (x1
== x2
&& y1
== y2
)
498 else if (radius
== 0.0)
500 alpha1
= alpha2
= 0.0;
504 alpha1
= (x1
- xc
== 0) ?
505 (y1
- yc
< 0) ? 90.0 : -90.0 :
506 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
507 alpha2
= (x2
- xc
== 0) ?
508 (y2
- yc
< 0) ? 90.0 : -90.0 :
509 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
511 while (alpha1
<= 0) alpha1
+= 360;
512 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
513 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
514 while (alpha2
> 360) alpha2
-= 360;
516 if (m_brush
.GetStyle() != wxTRANSPARENT
)
522 "%d %d %d %d %d %d ellipse\n"
526 XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL(radius
), YLOG2DEVREL(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
527 XLOG2DEV(xc
), YLOG2DEV(yc
) );
529 CalcBoundingBox( xc
-radius
, yc
-radius
);
530 CalcBoundingBox( xc
+radius
, yc
+radius
);
533 if (m_pen
.GetStyle() != wxTRANSPARENT
)
539 "%d %d %d %d %d %d ellipse\n"
543 XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL(radius
), YLOG2DEVREL(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
544 XLOG2DEV(xc
), YLOG2DEV(yc
) );
546 CalcBoundingBox( xc
-radius
, yc
-radius
);
547 CalcBoundingBox( xc
+radius
, yc
+radius
);
551 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
553 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
555 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
556 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
562 DrawEllipse(x
,y
,w
,h
);
566 if (m_brush
.GetStyle () != wxTRANSPARENT
)
572 "%d %d %d %d %d %d true ellipticarc\n",
573 XLOG2DEV(x
+w
/2), YLOG2DEV(y
+h
/2), XLOG2DEVREL(w
/2), YLOG2DEVREL(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
575 CalcBoundingBox( x
,y
);
576 CalcBoundingBox( x
+w
, y
+h
);
579 if (m_pen
.GetStyle () != wxTRANSPARENT
)
585 "%d %d %d %d %d %d false ellipticarc\n",
586 XLOG2DEV(x
+w
/2), YLOG2DEV(y
+h
/2), XLOG2DEVREL(w
/2), YLOG2DEVREL(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
588 CalcBoundingBox( x
,y
);
589 CalcBoundingBox( x
+w
, y
+h
);
593 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
595 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
597 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
606 XLOG2DEV(x
), YLOG2DEV(y
),
607 XLOG2DEV(x
+1), YLOG2DEV(y
) );
609 CalcBoundingBox( x
, y
);
612 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
))
614 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
618 if (m_brush
.GetStyle () != wxTRANSPARENT
)
622 fprintf( m_pstream
, "newpath\n" );
624 wxCoord xx
= XLOG2DEV(points
[0].x
+ xoffset
);
625 wxCoord yy
= YLOG2DEV(points
[0].y
+ yoffset
);
627 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
629 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
631 for (int i
= 1; i
< n
; i
++)
633 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
634 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
636 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
638 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
641 fprintf( m_pstream
, "fill\n" );
644 if (m_pen
.GetStyle () != wxTRANSPARENT
)
648 fprintf( m_pstream
, "newpath\n" );
650 wxCoord xx
= XLOG2DEV(points
[0].x
+ xoffset
);
651 wxCoord yy
= YLOG2DEV(points
[0].y
+ yoffset
);
653 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
655 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
657 for (int i
= 1; i
< n
; i
++)
659 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
660 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
662 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
664 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
667 fprintf( m_pstream
, "closepath\n" );
668 fprintf( m_pstream
, "stroke\n" );
672 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
674 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
676 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
683 for ( i
=0; i
<n
; i
++ )
685 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
691 XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
693 for (i
= 1; i
< n
; i
++)
697 XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
700 fprintf( m_pstream
, "stroke\n" );
703 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
705 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
707 if (m_brush
.GetStyle () != wxTRANSPARENT
)
719 XLOG2DEV(x
), YLOG2DEV(y
),
720 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
721 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
722 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
724 CalcBoundingBox( x
, y
);
725 CalcBoundingBox( x
+ width
, y
+ height
);
728 if (m_pen
.GetStyle () != wxTRANSPARENT
)
740 XLOG2DEV(x
), YLOG2DEV(y
),
741 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
742 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
743 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
745 CalcBoundingBox( x
, y
);
746 CalcBoundingBox( x
+ width
, y
+ height
);
750 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
752 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
756 // Now, a negative radius is interpreted to mean
757 // 'the proportion of the smallest X or Y dimension'
758 double smallest
= 0.0;
763 radius
= (-radius
* smallest
);
766 wxCoord rad
= (wxCoord
) radius
;
768 if (m_brush
.GetStyle () != wxTRANSPARENT
)
772 /* Draw rectangle anticlockwise */
775 "%d %d %d 90 180 arc\n"
777 "%d %d %d 180 270 arc\n"
779 "%d %d %d 270 0 arc\n"
781 "%d %d %d 0 90 arc\n"
785 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
786 XLOG2DEV(x
), YLOG2DEV(y
+ rad
),
787 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
788 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
789 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
790 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
791 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
792 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
794 CalcBoundingBox( x
, y
);
795 CalcBoundingBox( x
+ width
, y
+ height
);
798 if (m_pen
.GetStyle () != wxTRANSPARENT
)
802 /* Draw rectangle anticlockwise */
805 "%d %d %d 90 180 arc\n"
807 "%d %d %d 180 270 arc\n"
809 "%d %d %d 270 0 arc\n"
811 "%d %d %d 0 90 arc\n"
815 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
816 XLOG2DEV(x
), YLOG2DEV(y
+ rad
),
817 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
818 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
819 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
820 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
821 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
822 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
824 CalcBoundingBox( x
, y
);
825 CalcBoundingBox( x
+ width
, y
+ height
);
829 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
831 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
833 if (m_brush
.GetStyle () != wxTRANSPARENT
)
839 "%d %d %d %d 0 360 ellipse\n"
841 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
842 XLOG2DEVREL(width
/ 2), YLOG2DEVREL(height
/ 2) );
844 CalcBoundingBox( x
- width
, y
- height
);
845 CalcBoundingBox( x
+ width
, y
+ height
);
848 if (m_pen
.GetStyle () != wxTRANSPARENT
)
854 "%d %d %d %d 0 360 ellipse\n"
856 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
857 XLOG2DEVREL(width
/ 2), YLOG2DEVREL(height
/ 2) );
859 CalcBoundingBox( x
- width
, y
- height
);
860 CalcBoundingBox( x
+ width
, y
+ height
);
864 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
866 DrawBitmap( icon
, x
, y
, TRUE
);
869 /* this has to be char, not wxChar */
870 static char hexArray
[] = "0123456789ABCDEF";
871 static void LocalDecToHex( int dec
, char *buf
)
873 int firstDigit
= (int)(dec
/16.0);
874 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
875 buf
[0] = hexArray
[firstDigit
];
876 buf
[1] = hexArray
[secondDigit
];
880 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
882 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
884 if (!bitmap
.Ok()) return;
886 wxImage
image( bitmap
);
888 if (!image
.Ok()) return;
890 wxCoord w
= image
.GetWidth();
891 wxCoord h
= image
.GetHeight();
893 wxCoord ww
= XLOG2DEVREL(image
.GetWidth());
894 wxCoord hh
= YLOG2DEVREL(image
.GetHeight());
896 wxCoord xx
= XLOG2DEV(x
);
897 wxCoord yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
900 "/origstate save def\n"
902 "/pix %d string def\n"
903 "/grays %d string def\n"
910 "{currentfile pix readhexstring pop}\n"
911 "false 3 colorimage\n",
912 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
915 for (int j
= 0; j
< h
; j
++)
917 for (int i
= 0; i
< w
; i
++)
920 LocalDecToHex( image
.GetRed(i
,j
), buffer
);
921 fprintf( m_pstream
, buffer
);
922 LocalDecToHex( image
.GetGreen(i
,j
), buffer
);
923 fprintf( m_pstream
, buffer
);
924 LocalDecToHex( image
.GetBlue(i
,j
), buffer
);
925 fprintf( m_pstream
, buffer
);
927 fprintf( m_pstream
, "\n" );
930 fprintf( m_pstream
, "end\n" );
931 fprintf( m_pstream
, "origstate restore\n" );
934 void wxPostScriptDC::SetFont( const wxFont
& font
)
936 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
938 if (!font
.Ok()) return;
942 int Style
= m_font
.GetStyle();
943 int Weight
= m_font
.GetWeight();
946 switch (m_font
.GetFamily())
951 if (Style
== wxITALIC
)
953 if (Weight
== wxBOLD
)
954 name
= "/Courier-BoldOblique";
956 name
= "/Courier-Oblique";
960 if (Weight
== wxBOLD
)
961 name
= "/Courier-Bold";
969 if (Style
== wxITALIC
)
971 if (Weight
== wxBOLD
)
972 name
= "/Times-BoldItalic";
974 name
= "/Times-Italic";
978 if (Weight
== wxBOLD
)
979 name
= "/Times-Bold";
981 name
= "/Times-Roman";
987 name
= "/ZapfChancery-MediumItalic";
995 if (Style
== wxITALIC
)
997 if (Weight
== wxBOLD
)
998 name
= "/Helvetica-BoldOblique";
1000 name
= "/Helvetica-Oblique";
1004 if (Weight
== wxBOLD
)
1005 name
= "/Helvetica-Bold";
1007 name
= "/Helvetica";
1013 fprintf( m_pstream
, name
);
1014 fprintf( m_pstream
, " reencodeISO def\n" );
1015 fprintf( m_pstream
, name
);
1016 fprintf( m_pstream
, " findfont\n" );
1019 sprintf( buffer
, "%f scalefont setfont\n", YLOG2DEVREL(m_font
.GetPointSize() * 1000) / 1000.0F
);
1020 // this is a hack - we must scale font size (in pts) according to m_scaleY but
1021 // YLOG2DEVREL works with wxCoord type (int or longint). Se we first convert font size
1022 // to 1/1000th of pt and then back.
1023 for (int i
= 0; i
< 100; i
++)
1024 if (buffer
[i
] == ',') buffer
[i
] = '.';
1025 fprintf( m_pstream
, buffer
);
1028 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1030 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1032 if (!pen
.Ok()) return;
1034 int oldStyle
= m_pen
.GetStyle();
1041 sprintf( buffer
, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen
.GetWidth()) / 1000.0f
);
1043 sprintf( buffer
, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen
.GetWidth()) / 1000.0f
);
1045 for (int i
= 0; i
< 100; i
++)
1046 if (buffer
[i
] == ',') buffer
[i
] = '.';
1047 fprintf( m_pstream
, buffer
);
1051 Line style - WRONG: 2nd arg is OFFSET
1053 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1054 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1055 ter is not number of values in the array of the first one, but an offset
1056 into this description of the pattern. I mean a real *offset* not index
1057 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1058 will be first black line *2* units wxCoord, then space 4 units, then the
1059 pattern of *3* units black, 4 units space will be repeated.
1062 static const char *dotted
= "[2 5] 2";
1063 static const char *short_dashed
= "[4 4] 2";
1064 static const char *wxCoord_dashed
= "[4 8] 2";
1065 static const char *dotted_dashed
= "[6 6 2 6] 4";
1067 const char *psdash
= (char *) NULL
;
1068 switch (m_pen
.GetStyle())
1070 case wxDOT
: psdash
= dotted
; break;
1071 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1072 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1073 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1076 default: psdash
= "[] 0"; break;
1079 if (oldStyle
!= m_pen
.GetStyle())
1081 fprintf( m_pstream
, psdash
);
1082 fprintf( m_pstream
," setdash\n" );
1086 unsigned char red
= m_pen
.GetColour().Red();
1087 unsigned char blue
= m_pen
.GetColour().Blue();
1088 unsigned char green
= m_pen
.GetColour().Green();
1092 // Anything not white is black
1093 if (! (red
== (unsigned char) 255 &&
1094 blue
== (unsigned char) 255 &&
1095 green
== (unsigned char) 255) )
1097 red
= (unsigned char) 0;
1098 green
= (unsigned char) 0;
1099 blue
= (unsigned char) 0;
1104 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1106 double redPS
= (double)(red
) / 255.0;
1107 double bluePS
= (double)(blue
) / 255.0;
1108 double greenPS
= (double)(green
) / 255.0;
1112 "%.8f %.8f %.8f setrgbcolor\n",
1113 redPS
, greenPS
, bluePS
);
1114 for (int i
= 0; i
< 100; i
++)
1115 if (buffer
[i
] == ',') buffer
[i
] = '.';
1116 fprintf( m_pstream
, buffer
);
1119 m_currentBlue
= blue
;
1120 m_currentGreen
= green
;
1124 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1126 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1128 if (!brush
.Ok()) return;
1133 unsigned char red
= m_brush
.GetColour().Red();
1134 unsigned char blue
= m_brush
.GetColour().Blue();
1135 unsigned char green
= m_brush
.GetColour().Green();
1139 // Anything not white is black
1140 if (! (red
== (unsigned char) 255 &&
1141 blue
== (unsigned char) 255 &&
1142 green
== (unsigned char) 255) )
1144 red
= (unsigned char) 0;
1145 green
= (unsigned char) 0;
1146 blue
= (unsigned char) 0;
1151 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1153 double redPS
= (double)(red
) / 255.0;
1154 double bluePS
= (double)(blue
) / 255.0;
1155 double greenPS
= (double)(green
) / 255.0;
1159 "%.8f %.8f %.8f setrgbcolor\n",
1160 redPS
, greenPS
, bluePS
);
1161 for (int i
= 0; i
< 100; i
++)
1162 if (buffer
[i
] == ',') buffer
[i
] = '.';
1163 fprintf( m_pstream
, buffer
);
1166 m_currentBlue
= blue
;
1167 m_currentGreen
= green
;
1171 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1173 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1175 wxCoord text_w
, text_h
, text_descent
;
1177 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1181 if (m_textForegroundColour
.Ok())
1183 unsigned char red
= m_textForegroundColour
.Red();
1184 unsigned char blue
= m_textForegroundColour
.Blue();
1185 unsigned char green
= m_textForegroundColour
.Green();
1189 // Anything not white is black
1190 if (! (red
== (unsigned char) 255 &&
1191 blue
== (unsigned char) 255 &&
1192 green
== (unsigned char) 255))
1194 red
= (unsigned char) 0;
1195 green
= (unsigned char) 0;
1196 blue
= (unsigned char) 0;
1200 // maybe setgray here ?
1201 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1203 double redPS
= (double)(red
) / 255.0;
1204 double bluePS
= (double)(blue
) / 255.0;
1205 double greenPS
= (double)(green
) / 255.0;
1209 "%.8f %.8f %.8f setrgbcolor\n",
1210 redPS
, greenPS
, bluePS
);
1211 for (int i
= 0; i
< 100; i
++)
1212 if (buffer
[i
] == ',') buffer
[i
] = '.';
1213 fprintf( m_pstream
, buffer
);
1216 m_currentBlue
= blue
;
1217 m_currentGreen
= green
;
1221 int size
= m_font
.GetPointSize();
1223 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1224 // commented by V. Slavik and replaced by accurate version
1225 // - note that there is still rounding error in text_descent!
1226 wxCoord by
= y
+ size
- text_descent
; // baseline
1227 fprintf( m_pstream
, "%d %d moveto\n", XLOG2DEV(x
), YLOG2DEV(by
) );
1229 fprintf( m_pstream
, "(" );
1230 const wxWX2MBbuf textbuf
= text
.mb_str();
1231 int len
= strlen(textbuf
);
1233 for (i
= 0; i
< len
; i
++)
1235 int c
= (unsigned char) textbuf
[i
];
1236 if (c
== ')' || c
== '(' || c
== '\\')
1238 /* Cope with special characters */
1239 fprintf( m_pstream
, "\\" );
1240 fputc(c
, m_pstream
);
1242 else if ( c
>= 128 )
1244 /* Cope with character codes > 127 */
1245 fprintf(m_pstream
, "\\%o", c
);
1249 fputc(c
, m_pstream
);
1253 fprintf( m_pstream
, ") show\n" );
1255 if (m_font
.GetUnderlined())
1257 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1267 XLOG2DEV(x
), YLOG2DEV(uy
),
1268 m_underlineThickness
,
1269 XLOG2DEV(x
+ text_w
), YLOG2DEV(uy
) );
1270 for (i
= 0; i
< 100; i
++)
1271 if (buffer
[i
] == ',') buffer
[i
] = '.';
1272 fprintf( m_pstream
, buffer
);
1275 CalcBoundingBox( x
, y
);
1276 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1279 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1283 DoDrawText(text
, x
, y
);
1287 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1291 if (m_textForegroundColour
.Ok())
1293 unsigned char red
= m_textForegroundColour
.Red();
1294 unsigned char blue
= m_textForegroundColour
.Blue();
1295 unsigned char green
= m_textForegroundColour
.Green();
1299 // Anything not white is black
1300 if (! (red
== (unsigned char) 255 &&
1301 blue
== (unsigned char) 255 &&
1302 green
== (unsigned char) 255))
1304 red
= (unsigned char) 0;
1305 green
= (unsigned char) 0;
1306 blue
= (unsigned char) 0;
1310 // maybe setgray here ?
1311 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1313 double redPS
= (double)(red
) / 255.0;
1314 double bluePS
= (double)(blue
) / 255.0;
1315 double greenPS
= (double)(green
) / 255.0;
1319 "%.8f %.8f %.8f setrgbcolor\n",
1320 redPS
, greenPS
, bluePS
);
1321 for (int i
= 0; i
< 100; i
++)
1322 if (buffer
[i
] == ',') buffer
[i
] = '.';
1323 fprintf( m_pstream
, buffer
);
1326 m_currentBlue
= blue
;
1327 m_currentGreen
= green
;
1331 int size
= m_font
.GetPointSize();
1333 long by
= y
+ (long)floor( double(size
) * 2.0 / 3.0 ); // approximate baseline
1335 // FIXME only correct for 90 degrees
1336 fprintf(m_pstream
, "%d %d moveto\n",
1337 XLOG2DEV((wxCoord
)(x
+ size
)), YLOG2DEV((wxCoord
)by
) );
1340 sprintf(buffer
, "%.8f rotate\n", angle
);
1342 for (i
= 0; i
< 100; i
++)
1343 if (buffer
[i
] == ',') buffer
[i
] = '.';
1344 fprintf(m_pstream
, buffer
);
1346 fprintf( m_pstream
, "(" );
1347 const wxWX2MBbuf textbuf
= text
.mb_str();
1348 int len
= strlen(textbuf
);
1349 for (i
= 0; i
< len
; i
++)
1351 int c
= (unsigned char) textbuf
[i
];
1352 if (c
== ')' || c
== '(' || c
== '\\')
1354 /* Cope with special characters */
1355 fprintf( m_pstream
, "\\" );
1356 fputc(c
, m_pstream
);
1358 else if ( c
>= 128 )
1360 /* Cope with character codes > 127 */
1361 fprintf(m_pstream
, "\\%o", c
);
1365 fputc(c
, m_pstream
);
1369 fprintf( m_pstream
, ") show\n" );
1371 sprintf( buffer
, "%.8f rotate\n", -angle
);
1372 for (i
= 0; i
< 100; i
++)
1373 if (buffer
[i
] == ',') buffer
[i
] = '.';
1374 fprintf( m_pstream
, buffer
);
1376 if (m_font
.GetUnderlined())
1378 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1381 GetTextExtent(text
, &w
, &h
);
1390 XLOG2DEV(x
), YLOG2DEV(uy
),
1391 m_underlineThickness
,
1392 XLOG2DEV(x
+ w
), YLOG2DEV(uy
) );
1393 for (i
= 0; i
< 100; i
++)
1394 if (buffer
[i
] == ',') buffer
[i
] = '.';
1395 fprintf( m_pstream
, buffer
);
1398 CalcBoundingBox( x
, y
);
1399 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1402 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1404 m_backgroundBrush
= brush
;
1407 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1409 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1412 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1414 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1418 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1421 wxNode
*node
= points
->First();
1422 p
= (wxPoint
*)node
->Data();
1426 node
= node
->Next();
1427 p
= (wxPoint
*)node
->Data();
1430 x3
= a
= (double)(x1
+ c
) / 2;
1431 y3
= b
= (double)(y1
+ d
) / 2;
1437 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1438 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1440 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1441 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1443 while ((node
= node
->Next()) != NULL
)
1445 q
= (wxPoint
*)node
->Data();
1453 x3
= (double)(x2
+ c
) / 2;
1454 y3
= (double)(y2
+ d
) / 2;
1457 "%d %d %d %d %d %d DrawSplineSection\n",
1458 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1459 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1460 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1462 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1463 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1467 At this point, (x2,y2) and (c,d) are the position of the
1468 next-to-last and last point respectively, in the point list
1474 XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1477 wxCoord
wxPostScriptDC::GetCharWidth() const
1479 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1480 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1484 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1486 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1488 m_signX
= (xLeftRight
? 1 : -1);
1489 m_signY
= (yBottomUp
? 1 : -1);
1491 // FIXME there is no such function in MSW nor in OS2/PM
1492 #if !defined(__WXMSW__) && !defined(__WXPM__)
1493 ComputeScaleAndOrigin();
1497 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1499 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1505 wxDC::SetDeviceOrigin( x
, h
-y
);
1508 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1510 wxPaperSize id
= m_printData
.GetPaperId();
1512 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1514 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1520 w
= paper
->GetSizeDeviceUnits().x
;
1521 h
= paper
->GetSizeDeviceUnits().y
;
1524 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1531 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1532 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1535 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1537 wxPaperSize id
= m_printData
.GetPaperId();
1539 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1541 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1547 w
= paper
->GetWidth() / 10;
1548 h
= paper
->GetHeight() / 10;
1551 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1558 if (width
) *width
= w
;
1559 if (height
) *height
= h
;
1562 // Resolution in pixels per logical inch
1563 wxSize
wxPostScriptDC::GetPPI(void) const
1565 return wxSize((int)(72 * ms_PSScaleFactor
),
1566 (int)(72 * ms_PSScaleFactor
));
1570 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1572 wxCHECK_MSG( m_ok
, FALSE
, wxT("invalid postscript dc") );
1574 if (m_printData
.GetFilename() == "")
1576 wxString filename
= wxGetTempFileName("ps");
1577 m_printData
.SetFilename(filename
);
1580 m_pstream
= fopen( m_printData
.GetFilename().fn_str(), "w+" );
1584 wxLogError( _("Cannot open file for PostScript printing!"));
1591 fprintf( m_pstream
, "%%%%BeginProlog\n" );
1592 fprintf( m_pstream
, wxPostScriptHeaderEllipse
);
1593 fprintf( m_pstream
, wxPostScriptHeaderEllipticArc
);
1594 fprintf( m_pstream
, wxPostScriptHeaderColourImage
);
1595 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO1
);
1596 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO2
);
1597 if (wxPostScriptHeaderSpline
)
1598 fprintf( m_pstream
, wxPostScriptHeaderSpline
);
1599 fprintf( m_pstream
, "%%%%EndProlog\n" );
1601 SetBrush( *wxBLACK_BRUSH
);
1602 SetPen( *wxBLACK_PEN
);
1603 SetBackground( *wxWHITE_BRUSH
);
1604 SetTextForeground( *wxBLACK
);
1606 // set origin according to paper size
1607 SetDeviceOrigin( 0,0 );
1615 void wxPostScriptDC::EndDoc ()
1617 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1622 fprintf( m_pstream
, "grestore\n" );
1625 fclose( m_pstream
);
1626 m_pstream
= (FILE *) NULL
;
1628 wxChar
*header_file
= wxGetTempFileName("ps");
1630 m_pstream
= fopen( wxConvFile
.cWX2MB(header_file
) , "w+" );
1632 fprintf( m_pstream
, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings
1633 fprintf( m_pstream
, "%%%%Title: %s\n", (const char *)m_title
.mb_str() );
1634 fprintf( m_pstream
, "%%%%Creator: %s\n", (const char*)wxConvCurrent
->cWX2MB(wxTheApp
->argv
[0]) );
1635 fprintf( m_pstream
, "%%%%CreationDate: %s\n", (const char *)wxNow().mb_str() );
1638 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1640 fprintf( m_pstream
, "%%%%For: %s ", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );
1641 wxChar userName
[245];
1642 if (wxGetUserName(userName
, sizeof(userName
)))
1643 fprintf( m_pstream
, " (%s)", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userName
) );
1644 fprintf( m_pstream
, "\n" );
1646 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1648 fprintf( m_pstream
, "%%%%For: %s\n", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );;
1651 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1653 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1654 double wx_printer_scale_x
, wx_printer_scale_y
;
1656 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1657 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1659 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1660 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1662 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1663 fprintf( m_pstream
, "%%%%Orientation: Landscape\n" );
1665 fprintf( m_pstream
, "%%%%Orientation: Portrait\n" );
1667 // Compute the bounding box. Note that it is in the default user
1668 // coordinate system, thus we have to convert the values.
1669 wxCoord llx
= (wxCoord
) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1670 wxCoord lly
= (wxCoord
) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1671 wxCoord urx
= (wxCoord
) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1672 wxCoord ury
= (wxCoord
) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1674 // If we're landscape, our sense of "x" and "y" is reversed.
1675 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1678 tmp
= llx
; llx
= lly
; lly
= tmp
;
1679 tmp
= urx
; urx
= ury
; ury
= tmp
;
1681 // We need either the two lines that follow, or we need to subtract
1682 // min_x from real_translate_y, which is commented out below.
1683 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1684 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1687 // The Adobe specifications call for integers; we round as to make
1688 // the bounding larger.
1690 "%%%%BoundingBox: %d %d %d %d\n",
1691 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1692 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1693 fprintf( m_pstream
, "%%%%Pages: %d\n", (wxPageNumber
- 1) );
1694 fprintf( m_pstream
, "%%%%EndComments\n\n" );
1696 // To check the correctness of the bounding box, postscript commands
1697 // to draw a box corresponding to the bounding box are generated below.
1698 // But since we typically don't want to print such a box, the postscript
1699 // commands are generated within comments. These lines appear before any
1700 // adjustment of scale, rotation, or translation, and hence are in the
1701 // default user coordinates.
1702 fprintf( m_pstream
, "%% newpath\n" );
1703 fprintf( m_pstream
, "%% %d %d moveto\n", llx
, lly
);
1704 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, lly
);
1705 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, ury
);
1706 fprintf( m_pstream
, "%% %d %d lineto closepath stroke\n", llx
, ury
);
1708 fclose( m_pstream
);
1709 m_pstream
= (FILE*) NULL
;
1711 wxChar
*tmp_file
= wxGetTempFileName("ps");
1713 // Paste header Before wx_printer_file
1714 wxConcatFiles (header_file
, m_printData
.GetFilename(), tmp_file
);
1715 wxRemoveFile( header_file
);
1716 wxRemoveFile( m_printData
.GetFilename() );
1717 wxRenameFile( tmp_file
, m_printData
.GetFilename() );
1719 #if defined(__X__) || defined(__WXGTK__)
1722 wxString
previewCommand(m_printData
.GetPreviewCommand());
1723 wxString
printerCommand(m_printData
.GetPrinterCommand());
1724 wxString
printerOptions(m_printData
.GetPrinterOptions());
1725 wxString
filename(m_printData
.GetFilename());
1727 switch (m_printData
.GetPrintMode())
1729 case wxPRINT_MODE_PREVIEW
:
1732 argv
[0] = WXSTRINGCAST previewCommand
;
1733 argv
[1] = WXSTRINGCAST filename
;
1734 argv
[2] = (wxChar
*) NULL
;
1735 wxExecute( argv
, TRUE
);
1736 wxRemoveFile( m_printData
.GetFilename() );
1739 case wxPRINT_MODE_PRINTER
:
1743 argv
[argc
++] = WXSTRINGCAST printerCommand
;
1745 // !SM! If we simply assign to argv[1] here, if printer options
1746 // are blank, we get an annoying and confusing message from lpr.
1747 wxChar
*opts
= WXSTRINGCAST printerOptions
;
1749 argv
[argc
++] = opts
;
1751 argv
[argc
++] = WXSTRINGCAST filename
;
1752 argv
[argc
++] = (wxChar
*) NULL
;
1753 wxExecute( argv
, TRUE
);
1754 wxRemoveFile( filename
);
1757 case wxPRINT_MODE_FILE
:
1758 case wxPRINT_MODE_NONE
:
1765 void wxPostScriptDC::StartPage()
1767 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1769 fprintf( m_pstream
, "%%%%Page: %d\n", wxPageNumber
++ );
1771 // What is this one supposed to do? RR.
1772 // *m_pstream << "matrix currentmatrix\n";
1774 // Added by Chris Breeze
1776 // Each page starts with an "initgraphics" which resets the
1777 // transformation and so we need to reset the origin
1778 // (and rotate the page for landscape printing)
1781 wxCoord translate_x
, translate_y
;
1782 double scale_x
, scale_y
;
1784 translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1785 translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1787 scale_x
= m_printData
.GetPrinterScaleX();
1788 scale_y
= m_printData
.GetPrinterScaleY();
1790 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1793 GetSize( (int*) NULL
, &h
);
1795 fprintf( m_pstream
, "90 rotate\n" );
1797 // I copied this one from a PostScript tutorial, but to no avail. RR.
1798 // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" );
1802 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1803 scale_y
/ ms_PSScaleFactor
);
1804 for (int i
= 0; i
< 100; i
++)
1805 if (buffer
[i
] == ',') buffer
[i
] = '.';
1806 fprintf( m_pstream
, buffer
);
1808 fprintf( m_pstream
, "%d %d translate\n", translate_x
, translate_y
);
1811 void wxPostScriptDC::EndPage ()
1813 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1815 fprintf( m_pstream
, "showpage\n" );
1818 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1819 wxCoord fwidth
, wxCoord fheight
,
1821 wxCoord xsrc
, wxCoord ysrc
,
1822 int rop
, bool WXUNUSED(useMask
) )
1824 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, wxT("invalid postscript dc") );
1826 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1828 /* blit into a bitmap */
1829 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1831 memDC
.SelectObject(bitmap
);
1832 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1833 memDC
.SelectObject(wxNullBitmap
);
1835 /* draw bitmap. scaling and positioning is done there */
1836 DrawBitmap( bitmap
, xdest
, ydest
);
1841 wxCoord
wxPostScriptDC::GetCharHeight() const
1844 return m_font
.GetPointSize();
1849 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1850 wxCoord
*x
, wxCoord
*y
,
1851 wxCoord
*descent
, wxCoord
*externalLeading
,
1852 wxFont
*theFont
) const
1854 wxFont
*fontToUse
= theFont
;
1856 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1858 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1860 const wxWX2MBbuf strbuf
= string
.mb_str();
1862 #if !wxUSE_AFM_FOR_POSTSCRIPT
1863 /* Provide a VERY rough estimate (avoid using it).
1864 * Produces accurate results for mono-spaced font
1865 * such as Courier (aka wxMODERN) */
1870 height
= fontToUse
->GetPointSize();
1873 *x
= strlen (strbuf
) * height
* 72 / 120;
1875 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
1876 if (descent
) *descent
= 0;
1877 if (externalLeading
) *externalLeading
= 0;
1880 /* method for calculating string widths in postscript:
1881 / read in the AFM (adobe font metrics) file for the
1882 / actual font, parse it and extract the character widths
1883 / and also the descender. this may be improved, but for now
1884 / it works well. the AFM file is only read in if the
1885 / font is changed. this may be chached in the future.
1886 / calls to GetTextExtent with the font unchanged are rather
1889 / for each font and style used there is an AFM file necessary.
1890 / currently i have only files for the roman font family.
1891 / I try to get files for the other ones!
1893 / CAVE: the size of the string is currently always calculated
1894 / in 'points' (1/72 of an inch). this should later on be
1895 / changed to depend on the mapping mode.
1896 / CAVE: the path to the AFM files must be set before calling this
1897 / function. this is usually done by a call like the following:
1898 / wxSetAFMPath("d:\\wxw161\\afm\\");
1902 / wxPostScriptDC dc(NULL, TRUE);
1904 / wxSetAFMPath("d:\\wxw161\\afm\\");
1905 / dc.StartDoc("Test");
1908 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1909 / dc.GetTextExtent("Hallo",&w,&h);
1914 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1916 / updated: 14.05.95 */
1918 /* these static vars are for storing the state between calls */
1919 static int lastFamily
= INT_MIN
;
1920 static int lastSize
= INT_MIN
;
1921 static int lastStyle
= INT_MIN
;
1922 static int lastWeight
= INT_MIN
;
1923 static int lastDescender
= INT_MIN
;
1924 static int lastWidths
[256]; /* widths of the characters */
1926 double UnderlinePosition
= 0.0;
1927 double UnderlineThickness
= 0.0;
1929 /* get actual parameters */
1930 int Family
= fontToUse
->GetFamily();
1931 int Size
= fontToUse
->GetPointSize();
1932 int Style
= fontToUse
->GetStyle();
1933 int Weight
= fontToUse
->GetWeight();
1935 /* if we have another font, read the font-metrics */
1936 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1938 /* store actual values */
1939 lastFamily
= Family
;
1942 lastWeight
= Weight
;
1944 char *name
= (char*) NULL
;
1951 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO.afm";
1952 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo.afm";
1953 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "CourO.afm";
1954 else name
= "Cour.afm";
1959 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO.afm";
1960 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo.afm";
1961 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO.afm";
1962 else name
= "TimesRo.afm";
1974 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO.afm";
1975 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo.afm";
1976 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "HelvO.afm";
1977 else name
= "Helv.afm";
1982 /* get the directory of the AFM files */
1983 wxString afmName
= wxEmptyString
;
1984 if (!m_printData
.GetFontMetricPath().IsEmpty())
1986 afmName
= m_printData
.GetFontMetricPath();
1989 /* 2. open and process the file
1990 / a short explanation of the AFM format:
1991 / we have for each character a line, which gives its size
1994 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1996 / that means, we have a character with ascii code 63, and width
1997 / (444/1000 * fontSize) points.
1998 / the other data is ignored for now!
2000 / when the font has changed, we read in the right AFM file and store the
2001 / character widths in an array, which is processed below (see point 3.). */
2003 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
2006 FILE *afmFile
= wxFopen(afmName
,wxT("r"));
2010 afmName
= wxThePrintSetupData
->GetAFMPath();
2011 afmName
<< wxFILE_SEP_PATH
<< name
;
2012 afmFile
= wxFopen(afmName
,wxT("r"));
2015 #if defined(__UNIX__) && !defined(__VMS__)
2017 /* please do NOT change the line above to "else if (afmFile==NULL)" -
2018 - afmFile = fopen() may fail and in that case the next if branch
2019 MUST be executed - and it would not if there was "else" */
2021 afmName
= wxINSTALL_PREFIX
;
2022 afmName
<< wxFILE_SEP_PATH
2023 << wxT("share") << wxFILE_SEP_PATH
2024 << wxT("wx") << wxFILE_SEP_PATH
2025 #if defined(__LINUX__) || defined(__FREEBSD__)
2026 << wxT("gs_afm") << wxFILE_SEP_PATH
2028 << wxT("afm") << wxFILE_SEP_PATH
2031 afmFile
= wxFopen(afmName
,wxT("r"));
2037 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%hs'\n"), afmName
.c_str() );
2038 wxLogDebug( wxT(" using approximate values\n"));
2039 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2040 lastDescender
= -150; /* dito. */
2044 /* init the widths array */
2045 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2046 /* some variables for holding parts of a line */
2047 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2048 char upString
[30], utString
[30], encString
[50];
2051 /* read in the file and parse it */
2052 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2054 /* A.) check for descender definition */
2055 if (strncmp(line
,"Descender",9)==0)
2057 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2058 (strcmp(descString
,"Descender")!=0))
2060 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad descender)\n"), afmName
.c_str(),line
);
2063 /* JC 1.) check for UnderlinePosition */
2064 else if(strncmp(line
,"UnderlinePosition",17)==0)
2066 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2067 (strcmp(upString
,"UnderlinePosition")!=0))
2069 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlinePosition)\n"), afmName
.c_str(), line
);
2072 /* JC 2.) check for UnderlineThickness */
2073 else if(strncmp(line
,"UnderlineThickness",18)==0)
2075 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2076 (strcmp(utString
,"UnderlineThickness")!=0))
2078 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlineThickness)\n"), afmName
.c_str(), line
);
2081 /* JC 3.) check for EncodingScheme */
2082 else if(strncmp(line
,"EncodingScheme",14)==0)
2084 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2085 (strcmp(utString
,"EncodingScheme")!=0))
2087 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad EncodingScheme)\n"), afmName
.c_str(), line
);
2089 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2091 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (unsupported EncodingScheme %hs)\n"),
2092 afmName
.c_str(),line
, encString
);
2095 /* B.) check for char-width */
2096 else if(strncmp(line
,"C ",2)==0)
2098 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2100 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has an error (bad character width)\n"),afmName
.c_str(),line
);
2102 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2104 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has a format error\n"),afmName
.c_str(),line
);
2106 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2107 if (ascii
>=0 && ascii
<256)
2109 lastWidths
[ascii
] = cWidth
; /* store width */
2113 /* MATTHEW: this happens a lot; don't print an error */
2114 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName.c_str(),ascii); */
2117 /* C.) ignore other entries. */
2121 /* hack to compute correct values for german 'Umlaute'
2122 / the correct way would be to map the character names
2123 / like 'adieresis' to corresp. positions of ISOEnc and read
2124 / these values from AFM files, too. Maybe later ... */
2125 lastWidths
[196] = lastWidths
['A']; // Ä
2126 lastWidths
[228] = lastWidths
['a']; // ä
2127 lastWidths
[214] = lastWidths
['O']; // Ö
2128 lastWidths
[246] = lastWidths
['o']; // ö
2129 lastWidths
[220] = lastWidths
['U']; // Ü
2130 lastWidths
[252] = lastWidths
['u']; // ü
2131 lastWidths
[223] = lastWidths
[251]; // ß
2133 /* JC: calculate UnderlineThickness/UnderlinePosition */
2135 // VS: dirty, but is there any better solution?
2137 pt
= (double*) &m_underlinePosition
;
2138 *pt
= YLOG2DEVREL((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2139 pt
= (double*) &m_underlineThickness
;
2140 *pt
= YLOG2DEVREL((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2145 /* 3. now the font metrics are read in, calc size this
2146 / is done by adding the widths of the characters in the
2147 / string. they are given in 1/1000 of the size! */
2150 wxCoord height
=Size
; /* by default */
2152 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2154 if(lastWidths
[*p
]== INT_MIN
)
2156 wxLogDebug(wxT("GetTextExtent: undefined width for character '%hc' (%d)\n"), *p
,*p
);
2157 sum
+= lastWidths
[' ']; /* assume space */
2161 sum
+= lastWidths
[*p
];
2165 double widthSum
= sum
;
2167 widthSum
/= 1000.0F
;
2169 /* add descender to height (it is usually a negative value) */
2170 //if (lastDescender != INT_MIN)
2172 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2174 // - commented by V. Slavik - height already contains descender in it
2175 // (judging from few experiments)
2177 /* return size values */
2179 *x
= (wxCoord
)widthSum
;
2183 /* return other parameters */
2186 if(lastDescender
!=INT_MIN
)
2188 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2196 /* currently no idea how to calculate this! */
2197 if (externalLeading
) *externalLeading
= 0;
2202 // Determine the Default Postscript Previewer
2203 // available on the platform
2204 #if defined(__SUN__) && defined(__XVIEW__)
2205 // OpenWindow/NeWS's Postscript Previewer
2206 # define PS_VIEWER_PROG "pageview"
2207 #elif defined(__VMS__)
2208 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
2209 #elif defined(__SGI__)
2210 // SGI's Display Postscript Previewer
2211 //# define PS_VIEWER_PROG "dps"
2212 # define PS_VIEWER_PROG "xpsview"
2213 #elif defined(__X__) || defined(__WXGTK__)
2214 // Front-end to ghostscript
2215 # define PS_VIEWER_PROG "ghostview"
2217 // Windows ghostscript/ghostview
2218 # define PS_VIEWER_PROG "gsview"
2221 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2223 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
2224 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
2226 // Redundant now I think
2228 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2230 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2231 const wxPoint
& pos
, const wxSize
& size
, wxCoord style
):
2232 wxDialog(parent
, -1, title
, pos
, size
, style
)
2234 wxBeginBusyCursor();
2239 *orientation
= new wxString
[2],
2240 *print_modes
= new wxString
[3];
2242 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
2243 double wx_printer_scale_x
, wx_printer_scale_y
;
2245 orientation
[0] = _("Portrait");
2246 orientation
[1] = _("Landscape");
2248 print_modes
[0] = _("Send to Printer");
2249 print_modes
[1] = _("Print to File");
2250 print_modes
[2] = _("Preview Only");
2254 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2255 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2256 okBut
->SetDefault();
2259 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2260 (void) new wxStaticText( this, -1, _("Printer Command: "),
2262 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2263 wxPoint(100, yPos
), wxSize(100, -1) );
2265 (void) new wxStaticText( this, -1, _("Printer Options: "),
2266 wxPoint(210, yPos
) );
2267 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2268 wxPoint(305, yPos
), wxSize(150, -1) );
2274 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2275 2,orientation
,2,wxRA_SPECIFY_ROWS
);
2276 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2278 // @@@ Configuration hook
2279 if ( !wxThePrintSetupData
->GetPrintPreviewCommand() )
2280 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2282 // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand);
2284 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
2285 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2287 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2289 wxSize(-1,-1), features
,
2290 print_modes
, features
, wxRA_SPECIFY_ROWS
);
2293 radio1
->Enable(0, FALSE
);
2294 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2295 radio1
->Enable(2, FALSE
);
2298 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2299 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2300 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2302 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2305 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2306 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2308 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2309 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2310 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2314 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2315 sprintf (buf
, "%.2d", wx_printer_translate_x
);
2316 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2318 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2319 sprintf (buf
, "%.2d", wx_printer_translate_y
);
2320 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2324 delete[] orientation
;
2325 delete[] print_modes
;
2330 int wxPostScriptPrintDialog::ShowModal ()
2332 if ( wxDialog::ShowModal() == wxID_OK
)
2334 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2335 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2336 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2337 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2338 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2339 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2340 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2341 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2343 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->m_printerScaleX
);
2344 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->m_printerScaleY
);
2347 StringToLong (WXSTRINGCAST text3
->GetValue (), &dummy
);
2348 wxThePrintSetupData
->m_printerTranslateX
= (wxCoord
)dummy
;
2349 StringToLong (WXSTRINGCAST text4
->GetValue (), &dummy
);
2350 wxThePrintSetupData
->m_printerTranslateY
= (wxCoord
)dummy
;
2353 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2354 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2357 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? wxLANDSCAPE
: wxPORTRAIT
));
2360 switch ( radio1
->GetSelection() ) {
2361 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2362 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2363 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2372 // PostScript printer settings
2373 // RETAINED FOR BACKWARD COMPATIBILITY
2374 void wxSetPrinterCommand(const wxString
& cmd
)
2376 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2379 void wxSetPrintPreviewCommand(const wxString
& cmd
)
2381 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2384 void wxSetPrinterOptions(const wxString
& flags
)
2386 wxThePrintSetupData
->SetPrinterOptions(flags
);
2389 void wxSetPrinterFile(const wxString
& f
)
2391 wxThePrintSetupData
->SetPrinterFile(f
);
2394 void wxSetPrinterOrientation(int orient
)
2396 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2399 void wxSetPrinterScaling(double x
, double y
)
2401 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2404 void wxSetPrinterTranslation(wxCoord x
, wxCoord y
)
2406 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2409 // 1 = Preview, 2 = print to file, 3 = send to printer
2410 void wxSetPrinterMode(int mode
)
2412 wxThePrintSetupData
->SetPrinterMode(mode
);
2415 void wxSetAFMPath(const wxString
& f
)
2417 wxThePrintSetupData
->SetAFMPath(f
);
2420 // Get current values
2421 wxString
wxGetPrinterCommand()
2423 return wxThePrintSetupData
->GetPrinterCommand();
2426 wxString
wxGetPrintPreviewCommand()
2428 return wxThePrintSetupData
->GetPrintPreviewCommand();
2431 wxString
wxGetPrinterOptions()
2433 return wxThePrintSetupData
->GetPrinterOptions();
2436 wxString
wxGetPrinterFile()
2438 return wxThePrintSetupData
->GetPrinterFile();
2441 int wxGetPrinterOrientation()
2443 return wxThePrintSetupData
->GetPrinterOrientation();
2446 void wxGetPrinterScaling(double* x
, double* y
)
2448 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2451 void wxGetPrinterTranslation(wxCoord
*x
, wxCoord
*y
)
2453 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2456 int wxGetPrinterMode()
2458 return wxThePrintSetupData
->GetPrinterMode();
2461 wxString
wxGetAFMPath()
2463 return wxThePrintSetupData
->GetAFMPath();
2470 wxPrintSetupData::wxPrintSetupData()
2472 m_printerOrient
= wxPORTRAIT
;
2473 m_printerScaleX
= (double)1.0;
2474 m_printerScaleY
= (double)1.0;
2475 m_printerTranslateX
= 0;
2476 m_printerTranslateY
= 0;
2477 m_printerMode
= wxPRINT_MODE_FILE
;
2478 m_printColour
= TRUE
;
2481 wxPrintSetupData::~wxPrintSetupData()
2485 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2487 SetPrinterCommand(data
.GetPrinterCommand());
2488 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2489 SetPrinterOptions(data
.GetPrinterOptions());
2491 data
.GetPrinterTranslation(&x
, &y
);
2492 SetPrinterTranslation(x
, y
);
2495 data
.GetPrinterScaling(&x1
, &y1
);
2496 SetPrinterScaling(x1
, y1
);
2498 SetPrinterOrientation(data
.GetPrinterOrientation());
2499 SetPrinterMode(data
.GetPrinterMode());
2500 SetAFMPath(data
.GetAFMPath());
2501 SetPaperName(data
.GetPaperName());
2502 SetColour(data
.GetColour());
2505 // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData).
2506 void wxPrintSetupData::operator=(const wxPrintData
& data
)
2508 SetPrinterCommand(data
.GetPrinterCommand());
2509 SetPrintPreviewCommand(data
.GetPreviewCommand());
2510 SetPrinterOptions(data
.GetPrinterOptions());
2511 SetPrinterTranslation((wxCoord
)data
.GetPrinterTranslateX(),
2512 (wxCoord
)data
.GetPrinterTranslateY());
2513 SetPrinterScaling(data
.GetPrinterScaleX(), data
.GetPrinterScaleY());
2514 SetPrinterOrientation(data
.GetOrientation());
2515 SetPrinterMode((int) data
.GetPrintMode());
2516 SetAFMPath(data
.GetFontMetricPath());
2517 SetPaperName(wxThePrintPaperDatabase
->ConvertIdToName(data
.GetPaperId()));
2518 SetColour(data
.GetColour());
2519 SetPrinterFile(data
.GetFilename());
2522 void wxInitializePrintSetupData(bool init
)
2526 wxThePrintSetupData
= new wxPrintSetupData
;
2528 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2529 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
2530 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_PREVIEW
);
2531 wxThePrintSetupData
->SetPaperName(_("A4 sheet, 210 x 297 mm"));
2533 // Could have a .ini file to read in some defaults
2534 // - and/or use environment variables, e.g. WXWIN
2536 wxThePrintSetupData
->SetPrinterCommand("print");
2537 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2538 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2541 wxThePrintSetupData
->SetPrinterCommand("print");
2542 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2543 wxThePrintSetupData
->SetPrinterOptions("");
2545 #if !defined(__VMS__) && !defined(__WXMSW__)
2546 wxThePrintSetupData
->SetPrinterCommand("lpr");
2547 wxThePrintSetupData
->SetPrinterOptions("");
2548 wxThePrintSetupData
->SetAFMPath("");
2553 if (wxThePrintSetupData
)
2554 delete wxThePrintSetupData
;
2555 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2559 // A module to allow initialization/cleanup of PostScript-related
2560 // things without calling these functions from app.cpp.
2562 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2564 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2566 wxPostScriptModule() {}
2571 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2574 * Initialization/cleanup module
2577 bool wxPostScriptModule::OnInit()
2579 wxInitializePrintSetupData();
2584 void wxPostScriptModule::OnExit()
2586 wxInitializePrintSetupData(FALSE
);
2593 // wxUSE_PRINTING_ARCHITECTURE