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
);
656 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
658 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
660 for (int i
= 1; i
< n
; i
++)
662 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
663 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
665 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
667 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
670 fprintf( m_pstream
, "%d %d lineto\n", xx0
, yy0
);
671 fprintf( m_pstream
, "stroke\n" );
675 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
677 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
679 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
686 for ( i
=0; i
<n
; i
++ )
688 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
694 XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
696 for (i
= 1; i
< n
; i
++)
700 XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
703 fprintf( m_pstream
, "stroke\n" );
706 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
708 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
710 if (m_brush
.GetStyle () != wxTRANSPARENT
)
722 XLOG2DEV(x
), YLOG2DEV(y
),
723 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
724 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
725 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
727 CalcBoundingBox( x
, y
);
728 CalcBoundingBox( x
+ width
, y
+ height
);
731 if (m_pen
.GetStyle () != wxTRANSPARENT
)
743 XLOG2DEV(x
), YLOG2DEV(y
),
744 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
745 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
746 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
748 CalcBoundingBox( x
, y
);
749 CalcBoundingBox( x
+ width
, y
+ height
);
753 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
755 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
759 // Now, a negative radius is interpreted to mean
760 // 'the proportion of the smallest X or Y dimension'
761 double smallest
= 0.0;
766 radius
= (-radius
* smallest
);
769 wxCoord rad
= (wxCoord
) radius
;
771 if (m_brush
.GetStyle () != wxTRANSPARENT
)
775 /* Draw rectangle anticlockwise */
778 "%d %d %d 90 180 arc\n"
780 "%d %d %d 180 270 arc\n"
782 "%d %d %d 270 0 arc\n"
784 "%d %d %d 0 90 arc\n"
788 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
789 XLOG2DEV(x
), YLOG2DEV(y
+ rad
),
790 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
791 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
792 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
793 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
794 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
795 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
797 CalcBoundingBox( x
, y
);
798 CalcBoundingBox( x
+ width
, y
+ height
);
801 if (m_pen
.GetStyle () != wxTRANSPARENT
)
805 /* Draw rectangle anticlockwise */
808 "%d %d %d 90 180 arc\n"
810 "%d %d %d 180 270 arc\n"
812 "%d %d %d 270 0 arc\n"
814 "%d %d %d 0 90 arc\n"
818 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
819 XLOG2DEV(x
), YLOG2DEV(y
+ rad
),
820 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
821 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
822 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
823 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
824 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
825 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
827 CalcBoundingBox( x
, y
);
828 CalcBoundingBox( x
+ width
, y
+ height
);
832 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
834 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
836 if (m_brush
.GetStyle () != wxTRANSPARENT
)
842 "%d %d %d %d 0 360 ellipse\n"
844 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
845 XLOG2DEVREL(width
/ 2), YLOG2DEVREL(height
/ 2) );
847 CalcBoundingBox( x
- width
, y
- height
);
848 CalcBoundingBox( x
+ width
, y
+ height
);
851 if (m_pen
.GetStyle () != wxTRANSPARENT
)
857 "%d %d %d %d 0 360 ellipse\n"
859 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
860 XLOG2DEVREL(width
/ 2), YLOG2DEVREL(height
/ 2) );
862 CalcBoundingBox( x
- width
, y
- height
);
863 CalcBoundingBox( x
+ width
, y
+ height
);
867 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
869 DrawBitmap( icon
, x
, y
, TRUE
);
872 /* this has to be char, not wxChar */
873 static char hexArray
[] = "0123456789ABCDEF";
874 static void LocalDecToHex( int dec
, char *buf
)
876 int firstDigit
= (int)(dec
/16.0);
877 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
878 buf
[0] = hexArray
[firstDigit
];
879 buf
[1] = hexArray
[secondDigit
];
883 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
885 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
887 if (!bitmap
.Ok()) return;
889 wxImage
image( bitmap
);
891 if (!image
.Ok()) return;
893 wxCoord w
= image
.GetWidth();
894 wxCoord h
= image
.GetHeight();
896 wxCoord ww
= XLOG2DEVREL(image
.GetWidth());
897 wxCoord hh
= YLOG2DEVREL(image
.GetHeight());
899 wxCoord xx
= XLOG2DEV(x
);
900 wxCoord yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
903 "/origstate save def\n"
905 "/pix %d string def\n"
906 "/grays %d string def\n"
913 "{currentfile pix readhexstring pop}\n"
914 "false 3 colorimage\n",
915 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
918 for (int j
= 0; j
< h
; j
++)
920 for (int i
= 0; i
< w
; i
++)
923 LocalDecToHex( image
.GetRed(i
,j
), buffer
);
924 fprintf( m_pstream
, buffer
);
925 LocalDecToHex( image
.GetGreen(i
,j
), buffer
);
926 fprintf( m_pstream
, buffer
);
927 LocalDecToHex( image
.GetBlue(i
,j
), buffer
);
928 fprintf( m_pstream
, buffer
);
930 fprintf( m_pstream
, "\n" );
933 fprintf( m_pstream
, "end\n" );
934 fprintf( m_pstream
, "origstate restore\n" );
937 void wxPostScriptDC::SetFont( const wxFont
& font
)
939 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
941 if (!font
.Ok()) return;
946 const char *style
= "";
947 int Style
= m_font
.GetStyle();
948 int Weight
= m_font
.GetWeight();
950 switch (m_font
.GetFamily())
960 // name = "/Times-Roman";
961 name
= "/Times"; // Altered by EDZ
964 name
= "/Zapf-Chancery-MediumItalic";
969 case wxDEFAULT
: // Sans Serif Font
970 name
= "/LucidaSans";
973 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
975 if (m_font
.GetFamily () == wxROMAN
)
980 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
984 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
986 if (m_font
.GetFamily () == wxROMAN
)
991 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
993 if (m_font
.GetFamily () == wxROMAN
)
994 style
= "-BoldItalic";
996 style
= "-BoldOblique";
998 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
1000 if (m_font
.GetFamily () == wxROMAN
)
1005 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
1007 if (m_font
.GetFamily () == wxROMAN
)
1008 style
= "-BoldItalic";
1010 style
= "-BoldOblique";
1018 strcpy( buffer
, name
);
1019 strcat( buffer
, style
);
1021 fprintf( m_pstream
, buffer
);
1022 fprintf( m_pstream
, " reencodeISO def\n" );
1023 fprintf( m_pstream
, buffer
);
1024 fprintf( m_pstream
, " findfont\n" );
1026 sprintf( buffer
, "%f scalefont setfont\n", YLOG2DEVREL(m_font
.GetPointSize() * 1000) / 1000.0F
);
1027 // this is a hack - we must scale font size (in pts) according to m_scaleY but
1028 // YLOG2DEVREL works with wxCoord type (int or longint). Se we first convert font size
1029 // to 1/1000th of pt and then back.
1030 for (int i
= 0; i
< 100; i
++)
1031 if (buffer
[i
] == ',') buffer
[i
] = '.';
1032 fprintf( m_pstream
, buffer
);
1035 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1037 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1039 if (!pen
.Ok()) return;
1041 int oldStyle
= m_pen
.GetStyle();
1048 sprintf( buffer
, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen
.GetWidth()) / 1000.0f
);
1050 sprintf( buffer
, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen
.GetWidth()) / 1000.0f
);
1052 for (int i
= 0; i
< 100; i
++)
1053 if (buffer
[i
] == ',') buffer
[i
] = '.';
1054 fprintf( m_pstream
, buffer
);
1058 Line style - WRONG: 2nd arg is OFFSET
1060 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1061 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1062 ter is not number of values in the array of the first one, but an offset
1063 into this description of the pattern. I mean a real *offset* not index
1064 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1065 will be first black line *2* units wxCoord, then space 4 units, then the
1066 pattern of *3* units black, 4 units space will be repeated.
1069 static const char *dotted
= "[2 5] 2";
1070 static const char *short_dashed
= "[4 4] 2";
1071 static const char *wxCoord_dashed
= "[4 8] 2";
1072 static const char *dotted_dashed
= "[6 6 2 6] 4";
1074 const char *psdash
= (char *) NULL
;
1075 switch (m_pen
.GetStyle())
1077 case wxDOT
: psdash
= dotted
; break;
1078 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1079 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1080 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1083 default: psdash
= "[] 0"; break;
1086 if (oldStyle
!= m_pen
.GetStyle())
1088 fprintf( m_pstream
, psdash
);
1089 fprintf( m_pstream
," setdash\n" );
1093 unsigned char red
= m_pen
.GetColour().Red();
1094 unsigned char blue
= m_pen
.GetColour().Blue();
1095 unsigned char green
= m_pen
.GetColour().Green();
1099 // Anything not white is black
1100 if (! (red
== (unsigned char) 255 &&
1101 blue
== (unsigned char) 255 &&
1102 green
== (unsigned char) 255) )
1104 red
= (unsigned char) 0;
1105 green
= (unsigned char) 0;
1106 blue
= (unsigned char) 0;
1111 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1113 double redPS
= (double)(red
) / 255.0;
1114 double bluePS
= (double)(blue
) / 255.0;
1115 double greenPS
= (double)(green
) / 255.0;
1119 "%.8f %.8f %.8f setrgbcolor\n",
1120 redPS
, greenPS
, bluePS
);
1121 for (int i
= 0; i
< 100; i
++)
1122 if (buffer
[i
] == ',') buffer
[i
] = '.';
1123 fprintf( m_pstream
, buffer
);
1126 m_currentBlue
= blue
;
1127 m_currentGreen
= green
;
1131 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1133 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1135 if (!brush
.Ok()) return;
1140 unsigned char red
= m_brush
.GetColour().Red();
1141 unsigned char blue
= m_brush
.GetColour().Blue();
1142 unsigned char green
= m_brush
.GetColour().Green();
1146 // Anything not white is black
1147 if (! (red
== (unsigned char) 255 &&
1148 blue
== (unsigned char) 255 &&
1149 green
== (unsigned char) 255) )
1151 red
= (unsigned char) 0;
1152 green
= (unsigned char) 0;
1153 blue
= (unsigned char) 0;
1158 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1160 double redPS
= (double)(red
) / 255.0;
1161 double bluePS
= (double)(blue
) / 255.0;
1162 double greenPS
= (double)(green
) / 255.0;
1166 "%.8f %.8f %.8f setrgbcolor\n",
1167 redPS
, greenPS
, bluePS
);
1168 for (int i
= 0; i
< 100; i
++)
1169 if (buffer
[i
] == ',') buffer
[i
] = '.';
1170 fprintf( m_pstream
, buffer
);
1173 m_currentBlue
= blue
;
1174 m_currentGreen
= green
;
1178 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1180 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1182 wxCoord text_w
, text_h
, text_descent
;
1184 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1188 if (m_textForegroundColour
.Ok())
1190 unsigned char red
= m_textForegroundColour
.Red();
1191 unsigned char blue
= m_textForegroundColour
.Blue();
1192 unsigned char green
= m_textForegroundColour
.Green();
1196 // Anything not white is black
1197 if (! (red
== (unsigned char) 255 &&
1198 blue
== (unsigned char) 255 &&
1199 green
== (unsigned char) 255))
1201 red
= (unsigned char) 0;
1202 green
= (unsigned char) 0;
1203 blue
= (unsigned char) 0;
1207 // maybe setgray here ?
1208 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1210 double redPS
= (double)(red
) / 255.0;
1211 double bluePS
= (double)(blue
) / 255.0;
1212 double greenPS
= (double)(green
) / 255.0;
1216 "%.8f %.8f %.8f setrgbcolor\n",
1217 redPS
, greenPS
, bluePS
);
1218 for (int i
= 0; i
< 100; i
++)
1219 if (buffer
[i
] == ',') buffer
[i
] = '.';
1220 fprintf( m_pstream
, buffer
);
1223 m_currentBlue
= blue
;
1224 m_currentGreen
= green
;
1228 int size
= m_font
.GetPointSize();
1230 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1231 // commented by V. Slavik and replaced by accurate version
1232 // - note that there is still rounding error in text_descent!
1233 wxCoord by
= y
+ size
- text_descent
; // baseline
1234 fprintf( m_pstream
, "%d %d moveto\n", XLOG2DEV(x
), YLOG2DEV(by
) );
1236 /* I don't know how to write char to a stream, so I use a mini string */
1240 fprintf( m_pstream
, "(" );
1241 const wxWX2MBbuf textbuf
= text
.mb_str();
1242 int len
= strlen(textbuf
);
1244 for (i
= 0; i
< len
; i
++)
1246 int c
= (unsigned char) textbuf
[i
];
1247 if (c
== ')' || c
== '(' || c
== '\\')
1249 /* Cope with special characters */
1250 fprintf( m_pstream
, "\\" );
1251 tmpbuf
[0] = (char) c
;
1252 fprintf( m_pstream
, tmpbuf
);
1254 else if ( c
>= 128 )
1256 /* Cope with character codes > 127 */
1257 fprintf(m_pstream
, "\\%o", c
);
1261 tmpbuf
[0] = (char) c
;
1262 fprintf( m_pstream
, tmpbuf
);
1266 fprintf( m_pstream
, ") show\n" );
1268 if (m_font
.GetUnderlined())
1270 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1280 XLOG2DEV(x
), YLOG2DEV(uy
),
1281 m_underlineThickness
,
1282 XLOG2DEV(x
+ text_w
), YLOG2DEV(uy
) );
1283 for (i
= 0; i
< 100; i
++)
1284 if (buffer
[i
] == ',') buffer
[i
] = '.';
1285 fprintf( m_pstream
, buffer
);
1288 CalcBoundingBox( x
, y
);
1289 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1292 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1296 DoDrawText(text
, x
, y
);
1300 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1304 if (m_textForegroundColour
.Ok())
1306 unsigned char red
= m_textForegroundColour
.Red();
1307 unsigned char blue
= m_textForegroundColour
.Blue();
1308 unsigned char green
= m_textForegroundColour
.Green();
1312 // Anything not white is black
1313 if (! (red
== (unsigned char) 255 &&
1314 blue
== (unsigned char) 255 &&
1315 green
== (unsigned char) 255))
1317 red
= (unsigned char) 0;
1318 green
= (unsigned char) 0;
1319 blue
= (unsigned char) 0;
1323 // maybe setgray here ?
1324 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1326 double redPS
= (double)(red
) / 255.0;
1327 double bluePS
= (double)(blue
) / 255.0;
1328 double greenPS
= (double)(green
) / 255.0;
1332 "%.8f %.8f %.8f setrgbcolor\n",
1333 redPS
, greenPS
, bluePS
);
1334 for (int i
= 0; i
< 100; i
++)
1335 if (buffer
[i
] == ',') buffer
[i
] = '.';
1336 fprintf( m_pstream
, buffer
);
1339 m_currentBlue
= blue
;
1340 m_currentGreen
= green
;
1344 int size
= m_font
.GetPointSize();
1346 long by
= y
+ (long)floor( double(size
) * 2.0 / 3.0 ); // approximate baseline
1348 // FIXME only correct for 90 degrees
1349 fprintf(m_pstream
, "%d %d moveto\n",
1350 XLOG2DEV((wxCoord
)(x
+ size
)), YLOG2DEV((wxCoord
)by
) );
1353 sprintf(buffer
, "%.8f rotate\n", angle
);
1355 for (i
= 0; i
< 100; i
++)
1356 if (buffer
[i
] == ',') buffer
[i
] = '.';
1357 fprintf(m_pstream
, buffer
);
1359 /* I don't know how to write char to a stream, so I use a mini string */
1363 fprintf( m_pstream
, "(" );
1364 const wxWX2MBbuf textbuf
= text
.mb_str();
1365 int len
= strlen(textbuf
);
1366 for (i
= 0; i
< len
; i
++)
1368 int c
= (unsigned char) textbuf
[i
];
1369 if (c
== ')' || c
== '(' || c
== '\\')
1371 /* Cope with special characters */
1372 fprintf( m_pstream
, "\\" );
1373 tmpbuf
[0] = (char) c
;
1374 fprintf( m_pstream
, tmpbuf
);
1376 else if ( c
>= 128 )
1378 /* Cope with character codes > 127 */
1379 fprintf(m_pstream
, "\\%o", c
);
1383 tmpbuf
[0] = (char) c
;
1384 fprintf( m_pstream
, tmpbuf
);
1388 fprintf( m_pstream
, ") show\n" );
1390 sprintf( buffer
, "%.8f rotate\n", -angle
);
1391 for (i
= 0; i
< 100; i
++)
1392 if (buffer
[i
] == ',') buffer
[i
] = '.';
1393 fprintf( m_pstream
, buffer
);
1395 if (m_font
.GetUnderlined())
1397 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1400 GetTextExtent(text
, &w
, &h
);
1409 XLOG2DEV(x
), YLOG2DEV(uy
),
1410 m_underlineThickness
,
1411 XLOG2DEV(x
+ w
), YLOG2DEV(uy
) );
1412 for (i
= 0; i
< 100; i
++)
1413 if (buffer
[i
] == ',') buffer
[i
] = '.';
1414 fprintf( m_pstream
, buffer
);
1417 CalcBoundingBox( x
, y
);
1418 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1421 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1423 m_backgroundBrush
= brush
;
1426 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1428 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1431 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1433 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1437 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1440 wxNode
*node
= points
->First();
1441 p
= (wxPoint
*)node
->Data();
1445 node
= node
->Next();
1446 p
= (wxPoint
*)node
->Data();
1449 x3
= a
= (double)(x1
+ c
) / 2;
1450 y3
= b
= (double)(y1
+ d
) / 2;
1456 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1457 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1459 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1460 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1462 while ((node
= node
->Next()) != NULL
)
1464 q
= (wxPoint
*)node
->Data();
1472 x3
= (double)(x2
+ c
) / 2;
1473 y3
= (double)(y2
+ d
) / 2;
1476 "%d %d %d %d %d %d DrawSplineSection\n",
1477 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1478 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1479 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1481 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1482 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1486 At this point, (x2,y2) and (c,d) are the position of the
1487 next-to-last and last point respectively, in the point list
1493 XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1496 wxCoord
wxPostScriptDC::GetCharWidth() const
1498 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1499 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1503 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1505 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1507 m_signX
= (xLeftRight
? 1 : -1);
1508 m_signY
= (yBottomUp
? 1 : -1);
1510 // FIXME there is no such function in MSW nor in OS2/PM
1511 #if !defined(__WXMSW__) && !defined(__WXPM__)
1512 ComputeScaleAndOrigin();
1516 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1518 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1524 wxDC::SetDeviceOrigin( x
, h
-y
);
1527 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1529 wxPaperSize id
= m_printData
.GetPaperId();
1531 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1533 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1539 w
= paper
->GetSizeDeviceUnits().x
;
1540 h
= paper
->GetSizeDeviceUnits().y
;
1543 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1550 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1551 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1554 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1556 wxPaperSize id
= m_printData
.GetPaperId();
1558 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1560 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1566 w
= paper
->GetWidth() / 10;
1567 h
= paper
->GetHeight() / 10;
1570 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1577 if (width
) *width
= w
;
1578 if (height
) *height
= h
;
1581 // Resolution in pixels per logical inch
1582 wxSize
wxPostScriptDC::GetPPI(void) const
1584 return wxSize((int)(72 * ms_PSScaleFactor
),
1585 (int)(72 * ms_PSScaleFactor
));
1589 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1591 wxCHECK_MSG( m_ok
, FALSE
, wxT("invalid postscript dc") );
1593 if (m_printData
.GetFilename() == "")
1595 wxString filename
= wxGetTempFileName("ps");
1596 m_printData
.SetFilename(filename
);
1599 m_pstream
= fopen( m_printData
.GetFilename().fn_str(), "w+" );
1603 wxLogError( _("Cannot open file for PostScript printing!"));
1610 fprintf( m_pstream
, "%%%%BeginProlog\n" );
1611 fprintf( m_pstream
, wxPostScriptHeaderEllipse
);
1612 fprintf( m_pstream
, wxPostScriptHeaderEllipticArc
);
1613 fprintf( m_pstream
, wxPostScriptHeaderColourImage
);
1614 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO1
);
1615 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO2
);
1616 if (wxPostScriptHeaderSpline
)
1617 fprintf( m_pstream
, wxPostScriptHeaderSpline
);
1618 fprintf( m_pstream
, "%%%%EndProlog\n" );
1620 SetBrush( *wxBLACK_BRUSH
);
1621 SetPen( *wxBLACK_PEN
);
1622 SetBackground( *wxWHITE_BRUSH
);
1623 SetTextForeground( *wxBLACK
);
1625 // set origin according to paper size
1626 SetDeviceOrigin( 0,0 );
1634 void wxPostScriptDC::EndDoc ()
1636 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1641 fprintf( m_pstream
, "grestore\n" );
1644 fclose( m_pstream
);
1645 m_pstream
= (FILE *) NULL
;
1647 wxChar
*header_file
= wxGetTempFileName("ps");
1649 m_pstream
= fopen( wxConvFile
.cWX2MB(header_file
) , "w+" );
1651 fprintf( m_pstream
, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings
1652 fprintf( m_pstream
, "%%%%Title: %s\n", (const char *)m_title
.mb_str() );
1653 fprintf( m_pstream
, "%%%%Creator: %s\n", (const char*)wxConvCurrent
->cWX2MB(wxTheApp
->argv
[0]) );
1654 fprintf( m_pstream
, "%%%%CreationDate: %s\n", (const char *)wxNow().mb_str() );
1657 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1659 fprintf( m_pstream
, "%%%%For: %s ", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );
1660 wxChar userName
[245];
1661 if (wxGetUserName(userName
, sizeof(userName
)))
1662 fprintf( m_pstream
, " (%s)", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userName
) );
1663 fprintf( m_pstream
, "\n" );
1665 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1667 fprintf( m_pstream
, "%%%%For: %s\n", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );;
1670 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1672 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1673 double wx_printer_scale_x
, wx_printer_scale_y
;
1675 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1676 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1678 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1679 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1681 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1682 fprintf( m_pstream
, "%%%%Orientation: Landscape\n" );
1684 fprintf( m_pstream
, "%%%%Orientation: Portrait\n" );
1686 // Compute the bounding box. Note that it is in the default user
1687 // coordinate system, thus we have to convert the values.
1688 wxCoord llx
= (wxCoord
) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1689 wxCoord lly
= (wxCoord
) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1690 wxCoord urx
= (wxCoord
) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1691 wxCoord ury
= (wxCoord
) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1693 // If we're landscape, our sense of "x" and "y" is reversed.
1694 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1697 tmp
= llx
; llx
= lly
; lly
= tmp
;
1698 tmp
= urx
; urx
= ury
; ury
= tmp
;
1700 // We need either the two lines that follow, or we need to subtract
1701 // min_x from real_translate_y, which is commented out below.
1702 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1703 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1706 // The Adobe specifications call for integers; we round as to make
1707 // the bounding larger.
1709 "%%%%BoundingBox: %d %d %d %d\n",
1710 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1711 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1712 fprintf( m_pstream
, "%%%%Pages: %d\n", (wxPageNumber
- 1) );
1713 fprintf( m_pstream
, "%%%%EndComments\n\n" );
1715 // To check the correctness of the bounding box, postscript commands
1716 // to draw a box corresponding to the bounding box are generated below.
1717 // But since we typically don't want to print such a box, the postscript
1718 // commands are generated within comments. These lines appear before any
1719 // adjustment of scale, rotation, or translation, and hence are in the
1720 // default user coordinates.
1721 fprintf( m_pstream
, "%% newpath\n" );
1722 fprintf( m_pstream
, "%% %d %d moveto\n", llx
, lly
);
1723 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, lly
);
1724 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, ury
);
1725 fprintf( m_pstream
, "%% %d %d lineto closepath stroke\n", llx
, ury
);
1727 fclose( m_pstream
);
1728 m_pstream
= (FILE*) NULL
;
1730 wxChar
*tmp_file
= wxGetTempFileName("ps");
1732 // Paste header Before wx_printer_file
1733 wxConcatFiles (header_file
, m_printData
.GetFilename(), tmp_file
);
1734 wxRemoveFile( header_file
);
1735 wxRemoveFile( m_printData
.GetFilename() );
1736 wxRenameFile( tmp_file
, m_printData
.GetFilename() );
1738 #if defined(__X__) || defined(__WXGTK__)
1741 wxString
previewCommand(m_printData
.GetPreviewCommand());
1742 wxString
printerCommand(m_printData
.GetPrinterCommand());
1743 wxString
printerOptions(m_printData
.GetPrinterOptions());
1744 wxString
filename(m_printData
.GetFilename());
1746 switch (m_printData
.GetPrintMode())
1748 case wxPRINT_MODE_PREVIEW
:
1751 argv
[0] = WXSTRINGCAST previewCommand
;
1752 argv
[1] = WXSTRINGCAST filename
;
1753 argv
[2] = (wxChar
*) NULL
;
1754 wxExecute( argv
, TRUE
);
1755 wxRemoveFile( m_printData
.GetFilename() );
1758 case wxPRINT_MODE_PRINTER
:
1762 argv
[argc
++] = WXSTRINGCAST printerCommand
;
1764 // !SM! If we simply assign to argv[1] here, if printer options
1765 // are blank, we get an annoying and confusing message from lpr.
1766 wxChar
*opts
= WXSTRINGCAST printerOptions
;
1768 argv
[argc
++] = opts
;
1770 argv
[argc
++] = WXSTRINGCAST filename
;
1771 argv
[argc
++] = (wxChar
*) NULL
;
1772 wxExecute( argv
, TRUE
);
1773 wxRemoveFile( filename
);
1776 case wxPRINT_MODE_FILE
:
1777 case wxPRINT_MODE_NONE
:
1784 void wxPostScriptDC::StartPage()
1786 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1788 fprintf( m_pstream
, "%%%%Page: %d\n", wxPageNumber
++ );
1790 // What is this one supposed to do? RR.
1791 // *m_pstream << "matrix currentmatrix\n";
1793 // Added by Chris Breeze
1795 // Each page starts with an "initgraphics" which resets the
1796 // transformation and so we need to reset the origin
1797 // (and rotate the page for landscape printing)
1800 wxCoord translate_x
, translate_y
;
1801 double scale_x
, scale_y
;
1803 translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1804 translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1806 scale_x
= m_printData
.GetPrinterScaleX();
1807 scale_y
= m_printData
.GetPrinterScaleY();
1809 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1812 GetSize( (int*) NULL
, &h
);
1814 fprintf( m_pstream
, "90 rotate\n" );
1816 // I copied this one from a PostScript tutorial, but to no avail. RR.
1817 // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" );
1821 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1822 scale_y
/ ms_PSScaleFactor
);
1823 for (int i
= 0; i
< 100; i
++)
1824 if (buffer
[i
] == ',') buffer
[i
] = '.';
1825 fprintf( m_pstream
, buffer
);
1827 fprintf( m_pstream
, "%d %d translate\n", translate_x
, translate_y
);
1830 void wxPostScriptDC::EndPage ()
1832 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1834 fprintf( m_pstream
, "showpage\n" );
1837 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1838 wxCoord fwidth
, wxCoord fheight
,
1840 wxCoord xsrc
, wxCoord ysrc
,
1841 int rop
, bool WXUNUSED(useMask
) )
1843 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, wxT("invalid postscript dc") );
1845 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1847 /* blit into a bitmap */
1848 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1850 memDC
.SelectObject(bitmap
);
1851 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1852 memDC
.SelectObject(wxNullBitmap
);
1854 /* draw bitmap. scaling and positioning is done there */
1855 DrawBitmap( bitmap
, xdest
, ydest
);
1860 wxCoord
wxPostScriptDC::GetCharHeight() const
1863 return m_font
.GetPointSize();
1868 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1869 wxCoord
*x
, wxCoord
*y
,
1870 wxCoord
*descent
, wxCoord
*externalLeading
,
1871 wxFont
*theFont
) const
1873 wxFont
*fontToUse
= theFont
;
1875 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1877 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1879 const wxWX2MBbuf strbuf
= string
.mb_str();
1881 #if !wxUSE_AFM_FOR_POSTSCRIPT
1882 /* Provide a VERY rough estimate (avoid using it).
1883 * Produces accurate results for mono-spaced font
1884 * such as Courier (aka wxMODERN) */
1889 height
= fontToUse
->GetPointSize();
1892 *x
= strlen (strbuf
) * height
* 72 / 120;
1894 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
1895 if (descent
) *descent
= 0;
1896 if (externalLeading
) *externalLeading
= 0;
1899 /* method for calculating string widths in postscript:
1900 / read in the AFM (adobe font metrics) file for the
1901 / actual font, parse it and extract the character widths
1902 / and also the descender. this may be improved, but for now
1903 / it works well. the AFM file is only read in if the
1904 / font is changed. this may be chached in the future.
1905 / calls to GetTextExtent with the font unchanged are rather
1908 / for each font and style used there is an AFM file necessary.
1909 / currently i have only files for the roman font family.
1910 / I try to get files for the other ones!
1912 / CAVE: the size of the string is currently always calculated
1913 / in 'points' (1/72 of an inch). this should later on be
1914 / changed to depend on the mapping mode.
1915 / CAVE: the path to the AFM files must be set before calling this
1916 / function. this is usually done by a call like the following:
1917 / wxSetAFMPath("d:\\wxw161\\afm\\");
1921 / wxPostScriptDC dc(NULL, TRUE);
1923 / wxSetAFMPath("d:\\wxw161\\afm\\");
1924 / dc.StartDoc("Test");
1927 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1928 / dc.GetTextExtent("Hallo",&w,&h);
1933 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1935 / updated: 14.05.95 */
1937 /* these static vars are for storing the state between calls */
1938 static int lastFamily
= INT_MIN
;
1939 static int lastSize
= INT_MIN
;
1940 static int lastStyle
= INT_MIN
;
1941 static int lastWeight
= INT_MIN
;
1942 static int lastDescender
= INT_MIN
;
1943 static int lastWidths
[256]; /* widths of the characters */
1945 double UnderlinePosition
= 0.0;
1946 double UnderlineThickness
= 0.0;
1948 /* get actual parameters */
1949 const int Family
= fontToUse
->GetFamily();
1950 const int Size
= fontToUse
->GetPointSize();
1951 const int Style
= fontToUse
->GetStyle();
1952 const int Weight
= fontToUse
->GetWeight();
1954 /* if we have another font, read the font-metrics */
1955 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1957 /* store actual values */
1958 lastFamily
= Family
;
1961 lastWeight
= Weight
;
1963 char *name
= (char*) NULL
;
1969 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO";
1970 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo";
1971 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "CourO";
1977 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO";
1978 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo";
1979 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO";
1980 else name
= "TimesRo";
1985 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO";
1986 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo";
1987 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "HelvO";
1993 /* get the directory of the AFM files */
1994 wxString afmName
= wxEmptyString
;
1995 if (!m_printData
.GetFontMetricPath().IsEmpty())
1997 afmName
= m_printData
.GetFontMetricPath();
2000 /* 2. open and process the file
2001 / a short explanation of the AFM format:
2002 / we have for each character a line, which gives its size
2005 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2007 / that means, we have a character with ascii code 63, and width
2008 / (444/1000 * fontSize) points.
2009 / the other data is ignored for now!
2011 / when the font has changed, we read in the right AFM file and store the
2012 / character widths in an array, which is processed below (see point 3.). */
2014 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
2016 afmName
<< name
<< wxT(".afm");
2017 FILE *afmFile
= wxFopen(afmName
,wxT("r"));
2020 afmName
= wxThePrintSetupData
->GetAFMPath();
2021 afmName
<< wxFILE_SEP_PATH
<< name
<< wxT(".afm");
2022 afmFile
= wxFopen(afmName
,wxT("r"));
2028 /* please do NOT change the line above to "else if (afmFile==NULL)" -
2029 - afmFile = fopen() may fail and in that case the next if branch
2030 MUST be executed - and it would not if there was "else" */
2032 afmName
= wxINSTALL_PREFIX
;
2033 afmName
<< wxFILE_SEP_PATH
2034 << wxT("share") << wxFILE_SEP_PATH
2035 << wxT("wx") << wxFILE_SEP_PATH
2036 << wxT("afm") << wxFILE_SEP_PATH
2037 << name
<< wxT(".afm");
2038 afmFile
= wxFopen(afmName
,wxT("r"));
2045 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%hs'\n"), afmName
.c_str() );
2046 wxLogDebug( wxT(" using approximate values\n"));
2047 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2048 lastDescender
= -150; /* dito. */
2052 /* init the widths array */
2053 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2054 /* some variables for holding parts of a line */
2055 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2056 char upString
[30], utString
[30], encString
[50];
2059 /* read in the file and parse it */
2060 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2062 /* A.) check for descender definition */
2063 if (strncmp(line
,"Descender",9)==0)
2065 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2066 (strcmp(descString
,"Descender")!=0))
2068 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad descender)\n"), afmName
.c_str(),line
);
2071 /* JC 1.) check for UnderlinePosition */
2072 else if(strncmp(line
,"UnderlinePosition",17)==0)
2074 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2075 (strcmp(upString
,"UnderlinePosition")!=0))
2077 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlinePosition)\n"), afmName
.c_str(), line
);
2080 /* JC 2.) check for UnderlineThickness */
2081 else if(strncmp(line
,"UnderlineThickness",18)==0)
2083 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2084 (strcmp(utString
,"UnderlineThickness")!=0))
2086 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlineThickness)\n"), afmName
.c_str(), line
);
2089 /* JC 3.) check for EncodingScheme */
2090 else if(strncmp(line
,"EncodingScheme",14)==0)
2092 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2093 (strcmp(utString
,"EncodingScheme")!=0))
2095 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad EncodingScheme)\n"), afmName
.c_str(), line
);
2097 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2099 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (unsupported EncodingScheme %hs)\n"),
2100 afmName
.c_str(),line
, encString
);
2103 /* B.) check for char-width */
2104 else if(strncmp(line
,"C ",2)==0)
2106 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2108 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has an error (bad character width)\n"),afmName
.c_str(),line
);
2110 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2112 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has a format error\n"),afmName
.c_str(),line
);
2114 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2115 if (ascii
>=0 && ascii
<256)
2117 lastWidths
[ascii
] = cWidth
; /* store width */
2121 /* MATTHEW: this happens a lot; don't print an error */
2122 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName.c_str(),ascii); */
2125 /* C.) ignore other entries. */
2129 /* hack to compute correct values for german 'Umlaute'
2130 / the correct way would be to map the character names
2131 / like 'adieresis' to corresp. positions of ISOEnc and read
2132 / these values from AFM files, too. Maybe later ... */
2133 lastWidths
[196] = lastWidths
['A']; // Ä
2134 lastWidths
[228] = lastWidths
['a']; // ä
2135 lastWidths
[214] = lastWidths
['O']; // Ö
2136 lastWidths
[246] = lastWidths
['o']; // ö
2137 lastWidths
[220] = lastWidths
['U']; // Ü
2138 lastWidths
[252] = lastWidths
['u']; // ü
2139 lastWidths
[223] = lastWidths
[251]; // ß
2141 /* JC: calculate UnderlineThickness/UnderlinePosition */
2143 // VS: dirty, but is there any better solution?
2145 pt
= (double*) &m_underlinePosition
;
2146 *pt
= YLOG2DEVREL((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2147 pt
= (double*) &m_underlineThickness
;
2148 *pt
= YLOG2DEVREL((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2153 /* 3. now the font metrics are read in, calc size this
2154 / is done by adding the widths of the characters in the
2155 / string. they are given in 1/1000 of the size! */
2158 wxCoord height
=Size
; /* by default */
2160 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2162 if(lastWidths
[*p
]== INT_MIN
)
2164 wxLogDebug(wxT("GetTextExtent: undefined width for character '%hc' (%d)\n"), *p
,*p
);
2165 widthSum
+= (lastWidths
[' ']/1000.0F
* Size
); /* assume space */
2169 widthSum
+= ((lastWidths
[*p
]/1000.0F
)*Size
);
2173 /* add descender to height (it is usually a negative value) */
2174 //if (lastDescender != INT_MIN)
2176 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2178 // - commented by V. Slavik - height already contains descender in it
2179 // (judging from few experiments)
2181 /* return size values */
2183 *x
= (wxCoord
)widthSum
;
2187 /* return other parameters */
2190 if(lastDescender
!=INT_MIN
)
2192 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2200 /* currently no idea how to calculate this! */
2201 if (externalLeading
) *externalLeading
= 0;
2206 // Determine the Default Postscript Previewer
2207 // available on the platform
2208 #if defined(__SUN__) && defined(__XVIEW__)
2209 // OpenWindow/NeWS's Postscript Previewer
2210 # define PS_VIEWER_PROG "pageview"
2211 #elif defined(__VMS__)
2212 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
2213 #elif defined(__SGI__)
2214 // SGI's Display Postscript Previewer
2215 //# define PS_VIEWER_PROG "dps"
2216 # define PS_VIEWER_PROG "xpsview"
2217 #elif defined(__X__) || defined(__WXGTK__)
2218 // Front-end to ghostscript
2219 # define PS_VIEWER_PROG "ghostview"
2221 // Windows ghostscript/ghostview
2222 # define PS_VIEWER_PROG "gsview"
2225 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2227 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
2228 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
2230 // Redundant now I think
2232 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2234 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2235 const wxPoint
& pos
, const wxSize
& size
, wxCoord style
):
2236 wxDialog(parent
, -1, title
, pos
, size
, style
)
2238 wxBeginBusyCursor();
2243 *orientation
= new wxString
[2],
2244 *print_modes
= new wxString
[3];
2246 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
2247 double wx_printer_scale_x
, wx_printer_scale_y
;
2249 orientation
[0] = _("Portrait");
2250 orientation
[1] = _("Landscape");
2252 print_modes
[0] = _("Send to Printer");
2253 print_modes
[1] = _("Print to File");
2254 print_modes
[2] = _("Preview Only");
2258 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2259 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2260 okBut
->SetDefault();
2263 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2264 (void) new wxStaticText( this, -1, _("Printer Command: "),
2266 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2267 wxPoint(100, yPos
), wxSize(100, -1) );
2269 (void) new wxStaticText( this, -1, _("Printer Options: "),
2270 wxPoint(210, yPos
) );
2271 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2272 wxPoint(305, yPos
), wxSize(150, -1) );
2278 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2279 2,orientation
,2,wxRA_SPECIFY_ROWS
);
2280 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2282 // @@@ Configuration hook
2283 if ( !wxThePrintSetupData
->GetPrintPreviewCommand() )
2284 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2286 // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand);
2288 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
2289 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2291 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2293 wxSize(-1,-1), features
,
2294 print_modes
, features
, wxRA_SPECIFY_ROWS
);
2297 radio1
->Enable(0, FALSE
);
2298 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2299 radio1
->Enable(2, FALSE
);
2302 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2303 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2304 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2306 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2309 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2310 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2312 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2313 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2314 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2318 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2319 sprintf (buf
, "%.2d", wx_printer_translate_x
);
2320 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2322 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2323 sprintf (buf
, "%.2d", wx_printer_translate_y
);
2324 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2328 delete[] orientation
;
2329 delete[] print_modes
;
2334 int wxPostScriptPrintDialog::ShowModal ()
2336 if ( wxDialog::ShowModal() == wxID_OK
)
2338 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2339 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2340 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2341 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2342 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2343 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2344 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2345 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2347 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->m_printerScaleX
);
2348 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->m_printerScaleY
);
2351 StringToLong (WXSTRINGCAST text3
->GetValue (), &dummy
);
2352 wxThePrintSetupData
->m_printerTranslateX
= (wxCoord
)dummy
;
2353 StringToLong (WXSTRINGCAST text4
->GetValue (), &dummy
);
2354 wxThePrintSetupData
->m_printerTranslateY
= (wxCoord
)dummy
;
2357 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2358 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2361 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? wxLANDSCAPE
: wxPORTRAIT
));
2364 switch ( radio1
->GetSelection() ) {
2365 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2366 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2367 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2376 // PostScript printer settings
2377 // RETAINED FOR BACKWARD COMPATIBILITY
2378 void wxSetPrinterCommand(const wxString
& cmd
)
2380 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2383 void wxSetPrintPreviewCommand(const wxString
& cmd
)
2385 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2388 void wxSetPrinterOptions(const wxString
& flags
)
2390 wxThePrintSetupData
->SetPrinterOptions(flags
);
2393 void wxSetPrinterFile(const wxString
& f
)
2395 wxThePrintSetupData
->SetPrinterFile(f
);
2398 void wxSetPrinterOrientation(int orient
)
2400 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2403 void wxSetPrinterScaling(double x
, double y
)
2405 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2408 void wxSetPrinterTranslation(wxCoord x
, wxCoord y
)
2410 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2413 // 1 = Preview, 2 = print to file, 3 = send to printer
2414 void wxSetPrinterMode(int mode
)
2416 wxThePrintSetupData
->SetPrinterMode(mode
);
2419 void wxSetAFMPath(const wxString
& f
)
2421 wxThePrintSetupData
->SetAFMPath(f
);
2424 // Get current values
2425 wxString
wxGetPrinterCommand()
2427 return wxThePrintSetupData
->GetPrinterCommand();
2430 wxString
wxGetPrintPreviewCommand()
2432 return wxThePrintSetupData
->GetPrintPreviewCommand();
2435 wxString
wxGetPrinterOptions()
2437 return wxThePrintSetupData
->GetPrinterOptions();
2440 wxString
wxGetPrinterFile()
2442 return wxThePrintSetupData
->GetPrinterFile();
2445 int wxGetPrinterOrientation()
2447 return wxThePrintSetupData
->GetPrinterOrientation();
2450 void wxGetPrinterScaling(double* x
, double* y
)
2452 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2455 void wxGetPrinterTranslation(wxCoord
*x
, wxCoord
*y
)
2457 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2460 int wxGetPrinterMode()
2462 return wxThePrintSetupData
->GetPrinterMode();
2465 wxString
wxGetAFMPath()
2467 return wxThePrintSetupData
->GetAFMPath();
2474 wxPrintSetupData::wxPrintSetupData()
2476 m_printerOrient
= wxPORTRAIT
;
2477 m_printerScaleX
= (double)1.0;
2478 m_printerScaleY
= (double)1.0;
2479 m_printerTranslateX
= 0;
2480 m_printerTranslateY
= 0;
2481 m_printerMode
= wxPRINT_MODE_FILE
;
2482 m_printColour
= TRUE
;
2485 wxPrintSetupData::~wxPrintSetupData()
2489 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2491 SetPrinterCommand(data
.GetPrinterCommand());
2492 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2493 SetPrinterOptions(data
.GetPrinterOptions());
2495 data
.GetPrinterTranslation(&x
, &y
);
2496 SetPrinterTranslation(x
, y
);
2499 data
.GetPrinterScaling(&x1
, &y1
);
2500 SetPrinterScaling(x1
, y1
);
2502 SetPrinterOrientation(data
.GetPrinterOrientation());
2503 SetPrinterMode(data
.GetPrinterMode());
2504 SetAFMPath(data
.GetAFMPath());
2505 SetPaperName(data
.GetPaperName());
2506 SetColour(data
.GetColour());
2509 // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData).
2510 void wxPrintSetupData::operator=(const wxPrintData
& data
)
2512 SetPrinterCommand(data
.GetPrinterCommand());
2513 SetPrintPreviewCommand(data
.GetPreviewCommand());
2514 SetPrinterOptions(data
.GetPrinterOptions());
2515 SetPrinterTranslation((wxCoord
)data
.GetPrinterTranslateX(),
2516 (wxCoord
)data
.GetPrinterTranslateY());
2517 SetPrinterScaling(data
.GetPrinterScaleX(), data
.GetPrinterScaleY());
2518 SetPrinterOrientation(data
.GetOrientation());
2519 SetPrinterMode((int) data
.GetPrintMode());
2520 SetAFMPath(data
.GetFontMetricPath());
2521 SetPaperName(wxThePrintPaperDatabase
->ConvertIdToName(data
.GetPaperId()));
2522 SetColour(data
.GetColour());
2523 SetPrinterFile(data
.GetFilename());
2526 void wxInitializePrintSetupData(bool init
)
2530 wxThePrintSetupData
= new wxPrintSetupData
;
2532 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2533 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
2534 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_PREVIEW
);
2535 wxThePrintSetupData
->SetPaperName(_("A4 sheet, 210 x 297 mm"));
2537 // Could have a .ini file to read in some defaults
2538 // - and/or use environment variables, e.g. WXWIN
2540 wxThePrintSetupData
->SetPrinterCommand("print");
2541 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2542 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2545 wxThePrintSetupData
->SetPrinterCommand("print");
2546 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2547 wxThePrintSetupData
->SetPrinterOptions("");
2549 #if !defined(__VMS__) && !defined(__WXMSW__)
2550 wxThePrintSetupData
->SetPrinterCommand("lpr");
2551 wxThePrintSetupData
->SetPrinterOptions("");
2552 wxThePrintSetupData
->SetAFMPath("");
2557 if (wxThePrintSetupData
)
2558 delete wxThePrintSetupData
;
2559 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2563 // A module to allow initialization/cleanup of PostScript-related
2564 // things without calling these functions from app.cpp.
2566 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2568 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2570 wxPostScriptModule() {}
2575 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2578 * Initialization/cleanup module
2581 bool wxPostScriptModule::OnInit()
2583 wxInitializePrintSetupData();
2588 void wxPostScriptModule::OnExit()
2590 wxInitializePrintSetupData(FALSE
);
2597 // wxUSE_PRINTING_ARCHITECTURE