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 "dcpsg.h"
16 #include "wx/wxprec.h"
25 #if wxUSE_PRINTING_ARCHITECTURE
31 #include "wx/window.h"
32 #include "wx/dcmemory.h"
35 #include "wx/filedlg.h"
37 #include "wx/msgdlg.h"
40 #include "wx/generic/dcpsg.h"
41 #include "wx/printdlg.h"
42 #include "wx/button.h"
43 #include "wx/stattext.h"
44 #include "wx/radiobox.h"
45 #include "wx/textctrl.h"
46 #include "wx/prntbase.h"
48 #include "wx/filefn.h"
72 //-----------------------------------------------------------------------------
73 // start and end of document/page
74 //-----------------------------------------------------------------------------
76 static const char *wxPostScriptHeaderEllipse
= "\
77 /ellipsedict 8 dict def\n\
78 ellipsedict /mtrx matrix put\n\
82 /startangle exch def\n\
87 /savematrix mtrx currentmatrix def\n\
90 0 0 1 startangle endangle arc\n\
91 savematrix setmatrix\n\
96 static const char *wxPostScriptHeaderEllipticArc
= "\
97 /ellipticarcdict 8 dict def\n\
98 ellipticarcdict /mtrx matrix put\n\
100 { ellipticarcdict begin\n\
102 /endangle exch def\n\
103 /startangle exch def\n\
108 /savematrix mtrx currentmatrix def\n\
111 do_fill { 0 0 moveto } if\n\
112 0 0 1 startangle endangle arc\n\
113 savematrix setmatrix\n\
114 do_fill { fill }{ stroke } ifelse\n\
118 static const char *wxPostScriptHeaderSpline
= "\
119 /DrawSplineSection {\n\
126 /xa x1 x2 x1 sub 0.666667 mul add def\n\
127 /ya y1 y2 y1 sub 0.666667 mul add def\n\
128 /xb x3 x2 x3 sub 0.666667 mul add def\n\
129 /yb y3 y2 y3 sub 0.666667 mul add def\n\
131 xa ya xb yb x3 y3 curveto\n\
135 static const char *wxPostScriptHeaderColourImage
= "\
136 %% define 'colorimage' if it isn't defined\n\
137 %% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
139 /colorimage where %% do we know about 'colorimage'?\n\
140 { pop } %% yes: pop off the 'dict' returned\n\
141 { %% no: define one\n\
142 /colortogray { %% define an RGB->I function\n\
143 /rgbdata exch store %% call input 'rgbdata'\n\
144 rgbdata length 3 idiv\n\
145 /npixls exch store\n\
147 0 1 npixls 1 sub {\n\
149 rgbdata rgbindx get 20 mul %% Red\n\
150 rgbdata rgbindx 1 add get 32 mul %% Green\n\
151 rgbdata rgbindx 2 add get 12 mul %% Blue\n\
152 add add 64 idiv %% I = .5G + .31R + .18B\n\
154 /rgbindx rgbindx 3 add store\n\
156 grays 0 npixls getinterval\n\
159 %% Utility procedure for colorimage operator.\n\
160 %% This procedure takes two procedures off the\n\
161 %% stack and merges them into a single procedure.\n\
163 /mergeprocs { %% def\n\
182 /colorimage { %% def\n\
183 pop pop %% remove 'false 3' operands\n\
184 {colortogray} mergeprocs\n\
187 } ifelse %% end of 'false' case\n\
190 static char wxPostScriptHeaderReencodeISO1
[] =
192 "dup dup findfont dup length dict begin\n"
193 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
194 "/Encoding ISOLatin1Encoding def\n"
195 "currentdict end definefont\n"
197 "/ISOLatin1Encoding [\n"
198 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
199 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
200 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
201 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
202 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
203 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
204 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
205 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
206 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
207 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
208 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
209 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
210 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
211 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
212 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
214 static char wxPostScriptHeaderReencodeISO2
[] =
215 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
216 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
217 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
218 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
219 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
220 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
221 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
222 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
223 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
224 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
225 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
226 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
227 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
228 "/yacute/thorn/ydieresis\n"
231 //-------------------------------------------------------------------------------
233 //-------------------------------------------------------------------------------
235 float wxPostScriptDC::ms_PSScaleFactor
= 10.0;
237 void wxPostScriptDC::SetResolution(int ppi
)
239 ms_PSScaleFactor
= (float)ppi
/ 72.0;
242 int wxPostScriptDC::GetResolution()
244 return (int)(ms_PSScaleFactor
* 72.0);
249 wxPostScriptDC::wxPostScriptDC ()
251 m_pstream
= (FILE*) NULL
;
261 m_underlinePosition
= 0.0;
262 m_underlineThickness
= 0.0;
264 m_signX
= 1; // default x-axis left to right
265 m_signY
= -1; // default y-axis bottom up -> top down
267 // Compatibility only
268 // HH: Doesn't seem to work for wxMSW...
269 #if !defined(__WXMSW__)
270 m_printData
= * wxThePrintSetupData
;
274 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
276 m_pstream
= (FILE*) NULL
;
286 m_underlinePosition
= 0.0;
287 m_underlineThickness
= 0.0;
289 m_signX
= 1; // default x-axis left to right
290 m_signY
= -1; // default y-axis bottom up -> top down
292 Create(file
, interactive
, parent
);
295 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
297 m_isInteractive
= interactive
;
300 m_printData
.SetFilename(file
);
303 // Can only send to file in Windows
304 m_printData
.SetPrintMode(wxPRINT_MODE_FILE
);
309 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
319 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
321 m_pstream
= (FILE*) NULL
;
331 m_underlinePosition
= 0.0;
332 m_underlineThickness
= 0.0;
334 m_signX
= 1; // default x-axis left to right
335 m_signY
= -1; // default y-axis bottom up -> top down
337 m_printData
= printData
;
342 wxPostScriptDC::~wxPostScriptDC ()
347 m_pstream
= (FILE*) NULL
;
351 bool wxPostScriptDC::Ok() const
356 // This dialog is deprecated now: use wxGenericPrintDialog or the printing framework
357 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
359 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
360 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
361 m_ok
= (dialog
.ShowModal () == wxID_OK
);
363 if (!m_ok
) return FALSE
;
365 if ((m_printData
.GetFilename() == "") &&
366 (m_printData
.GetPrintMode() == wxPRINT_MODE_PREVIEW
||
367 m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
371 m_printData
.SetFilename("preview");
373 // For PS_PRINTER action this depends on a Unix-style print spooler
374 // since the wx_printer_file can be destroyed during a session
375 // @@@ TODO: a Windows-style answer for non-Unix
377 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
379 wxStrcpy (tmp
, wxT("/tmp/preview_"));
380 wxStrcat (tmp
, userId
);
381 m_printData
.SetFilename(tmp
);
384 wxStrcpy(tmp2
, m_printData
.GetFilename());
385 wxStrcat (tmp2
, wxT(".ps"));
386 m_printData
.SetFilename(tmp2
);
388 else if ((m_printData
.GetFilename() == wxT("")) && (m_printData
.GetPrintMode() == wxPRINT_MODE_FILE
))
390 wxString file
= wxSaveFileSelector (_("PostScript"), wxT("ps"));
391 if ( file
.IsEmpty() )
397 m_printData
.SetFilename(file
);
404 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
406 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
408 if (m_clipping
) DestroyClippingRegion();
410 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
419 "closepath clip newpath\n",
420 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
421 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
422 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
423 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
427 void wxPostScriptDC::DestroyClippingRegion()
429 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
434 fprintf( m_pstream
, "grestore\n" );
437 wxDC::DestroyClippingRegion();
440 void wxPostScriptDC::Clear()
442 wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
445 bool wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
447 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 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
476 LogicalToDeviceX(x2
), LogicalToDeviceY (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 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
527 LogicalToDeviceX(xc
), LogicalToDeviceY(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 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
544 LogicalToDeviceX(xc
), LogicalToDeviceY(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 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(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 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(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 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
607 LogicalToDeviceX(x
+1), LogicalToDeviceY(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
= LogicalToDeviceX(points
[0].x
+ xoffset
);
625 wxCoord yy
= LogicalToDeviceY(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
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
634 yy
= LogicalToDeviceY(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
= LogicalToDeviceX(points
[0].x
+ xoffset
);
651 wxCoord yy
= LogicalToDeviceY(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
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
660 yy
= LogicalToDeviceY(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( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
691 LogicalToDeviceX(points
[0].x
+xoffset
), LogicalToDeviceY(points
[0].y
+yoffset
) );
693 for (i
= 1; i
< n
; i
++)
697 LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(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 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
720 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
721 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
722 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
724 CalcBoundingBox( x
, y
);
725 CalcBoundingBox( x
+ width
, y
+ height
);
728 if (m_pen
.GetStyle () != wxTRANSPARENT
)
740 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
741 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
742 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
743 LogicalToDeviceX(x
), LogicalToDeviceY(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 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
786 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
787 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
788 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
789 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
790 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
791 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
792 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(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 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
816 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
817 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
818 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
819 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
820 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
821 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
822 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(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 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
842 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(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 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
857 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(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
.ConvertToImage();
888 if (!image
.Ok()) return;
890 wxCoord w
= image
.GetWidth();
891 wxCoord h
= image
.GetHeight();
893 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
894 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
896 wxCoord xx
= LogicalToDeviceX(x
);
897 wxCoord yy
= LogicalToDeviceY(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", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
1020 // this is a hack - we must scale font size (in pts) according to m_scaleY but
1021 // LogicalToDeviceYRel 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", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
1043 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(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
);
1179 // VZ: this seems to be unnecessary, so taking it out for now, if it
1180 // doesn't create any problems, remove this comment entirely
1181 //SetFont( m_font );
1183 if (m_textForegroundColour
.Ok())
1185 unsigned char red
= m_textForegroundColour
.Red();
1186 unsigned char blue
= m_textForegroundColour
.Blue();
1187 unsigned char green
= m_textForegroundColour
.Green();
1191 // Anything not white is black
1192 if (! (red
== (unsigned char) 255 &&
1193 blue
== (unsigned char) 255 &&
1194 green
== (unsigned char) 255))
1196 red
= (unsigned char) 0;
1197 green
= (unsigned char) 0;
1198 blue
= (unsigned char) 0;
1202 // maybe setgray here ?
1203 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1205 double redPS
= (double)(red
) / 255.0;
1206 double bluePS
= (double)(blue
) / 255.0;
1207 double greenPS
= (double)(green
) / 255.0;
1211 "%.8f %.8f %.8f setrgbcolor\n",
1212 redPS
, greenPS
, bluePS
);
1213 for (int i
= 0; i
< 100; i
++)
1214 if (buffer
[i
] == ',') buffer
[i
] = '.';
1215 fprintf( m_pstream
, buffer
);
1218 m_currentBlue
= blue
;
1219 m_currentGreen
= green
;
1223 int size
= m_font
.GetPointSize();
1225 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1226 // commented by V. Slavik and replaced by accurate version
1227 // - note that there is still rounding error in text_descent!
1228 wxCoord by
= y
+ size
- text_descent
; // baseline
1229 fprintf( m_pstream
, "%d %d moveto\n", LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1231 fprintf( m_pstream
, "(" );
1232 const wxWX2MBbuf textbuf
= text
.mb_str();
1233 size_t len
= strlen(textbuf
);
1235 for (i
= 0; i
< len
; i
++)
1237 int c
= (unsigned char) textbuf
[i
];
1238 if (c
== ')' || c
== '(' || c
== '\\')
1240 /* Cope with special characters */
1241 fprintf( m_pstream
, "\\" );
1242 fputc(c
, m_pstream
);
1244 else if ( c
>= 128 )
1246 /* Cope with character codes > 127 */
1247 fprintf(m_pstream
, "\\%o", c
);
1251 fputc(c
, m_pstream
);
1255 fprintf( m_pstream
, ") show\n" );
1257 if (m_font
.GetUnderlined())
1259 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1269 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1270 m_underlineThickness
,
1271 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1272 for (i
= 0; i
< 100; i
++)
1273 if (buffer
[i
] == ',') buffer
[i
] = '.';
1274 fprintf( m_pstream
, buffer
);
1277 CalcBoundingBox( x
, y
);
1278 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1281 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1285 DoDrawText(text
, x
, y
);
1289 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1293 if (m_textForegroundColour
.Ok())
1295 unsigned char red
= m_textForegroundColour
.Red();
1296 unsigned char blue
= m_textForegroundColour
.Blue();
1297 unsigned char green
= m_textForegroundColour
.Green();
1301 // Anything not white is black
1302 if (! (red
== (unsigned char) 255 &&
1303 blue
== (unsigned char) 255 &&
1304 green
== (unsigned char) 255))
1306 red
= (unsigned char) 0;
1307 green
= (unsigned char) 0;
1308 blue
= (unsigned char) 0;
1312 // maybe setgray here ?
1313 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1315 double redPS
= (double)(red
) / 255.0;
1316 double bluePS
= (double)(blue
) / 255.0;
1317 double greenPS
= (double)(green
) / 255.0;
1321 "%.8f %.8f %.8f setrgbcolor\n",
1322 redPS
, greenPS
, bluePS
);
1323 for (int i
= 0; i
< 100; i
++)
1324 if (buffer
[i
] == ',') buffer
[i
] = '.';
1325 fprintf( m_pstream
, buffer
);
1328 m_currentBlue
= blue
;
1329 m_currentGreen
= green
;
1333 int size
= m_font
.GetPointSize();
1335 long by
= y
+ (long)floor( double(size
) * 2.0 / 3.0 ); // approximate baseline
1337 // FIXME only correct for 90 degrees
1338 fprintf(m_pstream
, "%d %d moveto\n",
1339 LogicalToDeviceX((wxCoord
)(x
+ size
)), LogicalToDeviceY((wxCoord
)by
) );
1342 sprintf(buffer
, "%.8f rotate\n", angle
);
1344 for (i
= 0; i
< 100; i
++)
1345 if (buffer
[i
] == ',') buffer
[i
] = '.';
1346 fprintf(m_pstream
, buffer
);
1348 fprintf( m_pstream
, "(" );
1349 const wxWX2MBbuf textbuf
= text
.mb_str();
1350 size_t len
= strlen(textbuf
);
1351 for (i
= 0; i
< len
; i
++)
1353 int c
= (unsigned char) textbuf
[i
];
1354 if (c
== ')' || c
== '(' || c
== '\\')
1356 /* Cope with special characters */
1357 fprintf( m_pstream
, "\\" );
1358 fputc(c
, m_pstream
);
1360 else if ( c
>= 128 )
1362 /* Cope with character codes > 127 */
1363 fprintf(m_pstream
, "\\%o", c
);
1367 fputc(c
, m_pstream
);
1371 fprintf( m_pstream
, ") show\n" );
1373 sprintf( buffer
, "%.8f rotate\n", -angle
);
1374 for (i
= 0; i
< 100; i
++)
1375 if (buffer
[i
] == ',') buffer
[i
] = '.';
1376 fprintf( m_pstream
, buffer
);
1378 if (m_font
.GetUnderlined())
1380 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1383 GetTextExtent(text
, &w
, &h
);
1392 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1393 m_underlineThickness
,
1394 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1395 for (i
= 0; i
< 100; i
++)
1396 if (buffer
[i
] == ',') buffer
[i
] = '.';
1397 fprintf( m_pstream
, buffer
);
1400 CalcBoundingBox( x
, y
);
1401 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1404 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1406 m_backgroundBrush
= brush
;
1409 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1411 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1414 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1416 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1420 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1423 wxNode
*node
= points
->First();
1424 p
= (wxPoint
*)node
->Data();
1428 node
= node
->Next();
1429 p
= (wxPoint
*)node
->Data();
1432 x3
= a
= (double)(x1
+ c
) / 2;
1433 y3
= b
= (double)(y1
+ d
) / 2;
1439 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1440 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1442 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1443 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1445 while ((node
= node
->Next()) != NULL
)
1447 q
= (wxPoint
*)node
->Data();
1455 x3
= (double)(x2
+ c
) / 2;
1456 y3
= (double)(y2
+ d
) / 2;
1459 "%d %d %d %d %d %d DrawSplineSection\n",
1460 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1461 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1462 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1464 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1465 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1469 At this point, (x2,y2) and (c,d) are the position of the
1470 next-to-last and last point respectively, in the point list
1476 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1479 wxCoord
wxPostScriptDC::GetCharWidth() const
1481 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1482 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1486 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1488 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1490 m_signX
= (xLeftRight
? 1 : -1);
1491 m_signY
= (yBottomUp
? 1 : -1);
1493 // FIXME there is no such function in MSW nor in OS2/PM
1494 #if !defined(__WXMSW__) && !defined(__WXPM__)
1495 ComputeScaleAndOrigin();
1499 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1501 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1507 wxDC::SetDeviceOrigin( x
, h
-y
);
1510 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1512 wxPaperSize id
= m_printData
.GetPaperId();
1514 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1516 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1522 w
= paper
->GetSizeDeviceUnits().x
;
1523 h
= paper
->GetSizeDeviceUnits().y
;
1526 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1533 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1534 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1537 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1539 wxPaperSize id
= m_printData
.GetPaperId();
1541 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1543 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1549 w
= paper
->GetWidth() / 10;
1550 h
= paper
->GetHeight() / 10;
1553 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1560 if (width
) *width
= w
;
1561 if (height
) *height
= h
;
1564 // Resolution in pixels per logical inch
1565 wxSize
wxPostScriptDC::GetPPI(void) const
1567 return wxSize((int)(72 * ms_PSScaleFactor
),
1568 (int)(72 * ms_PSScaleFactor
));
1572 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1574 wxCHECK_MSG( m_ok
, FALSE
, wxT("invalid postscript dc") );
1576 if (m_printData
.GetFilename() == "")
1578 wxString filename
= wxGetTempFileName("ps");
1579 m_printData
.SetFilename(filename
);
1582 m_pstream
= wxFopen( m_printData
.GetFilename().c_str(), wxT("w+") ); // FIXME: use fn_str() here under Unicode?
1586 wxLogError( _("Cannot open file for PostScript printing!"));
1593 fprintf( m_pstream
, "%%%%BeginProlog\n" );
1594 fprintf( m_pstream
, wxPostScriptHeaderEllipse
);
1595 fprintf( m_pstream
, wxPostScriptHeaderEllipticArc
);
1596 fprintf( m_pstream
, wxPostScriptHeaderColourImage
);
1597 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO1
);
1598 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO2
);
1599 if (wxPostScriptHeaderSpline
)
1600 fprintf( m_pstream
, wxPostScriptHeaderSpline
);
1601 fprintf( m_pstream
, "%%%%EndProlog\n" );
1603 SetBrush( *wxBLACK_BRUSH
);
1604 SetPen( *wxBLACK_PEN
);
1605 SetBackground( *wxWHITE_BRUSH
);
1606 SetTextForeground( *wxBLACK
);
1608 // set origin according to paper size
1609 SetDeviceOrigin( 0,0 );
1617 void wxPostScriptDC::EndDoc ()
1619 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1624 fprintf( m_pstream
, "grestore\n" );
1627 fclose( m_pstream
);
1628 m_pstream
= (FILE *) NULL
;
1630 wxChar
*header_file
= wxGetTempFileName("ps");
1632 m_pstream
= fopen( wxConvFile
.cWX2MB(header_file
) , "w+" );
1634 fprintf( m_pstream
, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings
1635 fprintf( m_pstream
, "%%%%Title: %s\n", (const char *)m_title
.mb_str() );
1636 fprintf( m_pstream
, "%%%%Creator: %s\n", (const char*)wxConvCurrent
->cWX2MB(wxTheApp
->argv
[0]) );
1637 fprintf( m_pstream
, "%%%%CreationDate: %s\n", (const char *)wxNow().mb_str() );
1640 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1642 fprintf( m_pstream
, "%%%%For: %s ", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );
1643 wxChar userName
[245];
1644 if (wxGetUserName(userName
, sizeof(userName
)))
1645 fprintf( m_pstream
, " (%s)", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userName
) );
1646 fprintf( m_pstream
, "\n" );
1648 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1650 fprintf( m_pstream
, "%%%%For: %s\n", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );;
1653 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1655 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1656 double wx_printer_scale_x
, wx_printer_scale_y
;
1658 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1659 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1661 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1662 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1664 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1665 fprintf( m_pstream
, "%%%%Orientation: Landscape\n" );
1667 fprintf( m_pstream
, "%%%%Orientation: Portrait\n" );
1669 // Compute the bounding box. Note that it is in the default user
1670 // coordinate system, thus we have to convert the values.
1671 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1672 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1673 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1674 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1676 // LOG2DEV may have changed the minimum to maximum vice versa
1677 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1678 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1680 // account for used scaling (boundingbox is before scaling in ps-file)
1681 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1682 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1684 wxCoord llx
, lly
, urx
, ury
;
1685 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1686 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1687 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1688 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1689 // (end of bounding box computation)
1692 // If we're landscape, our sense of "x" and "y" is reversed.
1693 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1696 tmp
= llx
; llx
= lly
; lly
= tmp
;
1697 tmp
= urx
; urx
= ury
; ury
= tmp
;
1699 // We need either the two lines that follow, or we need to subtract
1700 // min_x from real_translate_y, which is commented out below.
1701 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1702 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1705 // The Adobe specifications call for integers; we round as to make
1706 // the bounding larger.
1708 "%%%%BoundingBox: %d %d %d %d\n",
1709 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1710 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1711 fprintf( m_pstream
, "%%%%Pages: %d\n", (wxPageNumber
- 1) );
1712 fprintf( m_pstream
, "%%%%EndComments\n\n" );
1714 // To check the correctness of the bounding box, postscript commands
1715 // to draw a box corresponding to the bounding box are generated below.
1716 // But since we typically don't want to print such a box, the postscript
1717 // commands are generated within comments. These lines appear before any
1718 // adjustment of scale, rotation, or translation, and hence are in the
1719 // default user coordinates.
1720 fprintf( m_pstream
, "%% newpath\n" );
1721 fprintf( m_pstream
, "%% %d %d moveto\n", llx
, lly
);
1722 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, lly
);
1723 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, ury
);
1724 fprintf( m_pstream
, "%% %d %d lineto closepath stroke\n", llx
, ury
);
1726 fclose( m_pstream
);
1727 m_pstream
= (FILE*) NULL
;
1729 wxChar
*tmp_file
= wxGetTempFileName("ps");
1731 // Paste header Before wx_printer_file
1732 wxConcatFiles (header_file
, m_printData
.GetFilename(), tmp_file
);
1733 wxRemoveFile( header_file
);
1734 wxRemoveFile( m_printData
.GetFilename() );
1735 wxRenameFile( tmp_file
, m_printData
.GetFilename() );
1737 #if defined(__X__) || defined(__WXGTK__)
1740 wxString
previewCommand(m_printData
.GetPreviewCommand());
1741 wxString
printerCommand(m_printData
.GetPrinterCommand());
1742 wxString
printerOptions(m_printData
.GetPrinterOptions());
1743 wxString
filename(m_printData
.GetFilename());
1745 switch (m_printData
.GetPrintMode())
1747 case wxPRINT_MODE_PREVIEW
:
1750 argv
[0] = WXSTRINGCAST previewCommand
;
1751 argv
[1] = WXSTRINGCAST filename
;
1752 argv
[2] = (wxChar
*) NULL
;
1753 #if defined(__WXGTK20__) && wxUSE_UNICODE
1755 wxExecute( argv
, TRUE
);
1757 wxRemoveFile( m_printData
.GetFilename() );
1760 case wxPRINT_MODE_PRINTER
:
1764 argv
[argc
++] = WXSTRINGCAST printerCommand
;
1766 // !SM! If we simply assign to argv[1] here, if printer options
1767 // are blank, we get an annoying and confusing message from lpr.
1768 wxChar
*opts
= WXSTRINGCAST printerOptions
;
1770 argv
[argc
++] = opts
;
1772 argv
[argc
++] = WXSTRINGCAST filename
;
1773 argv
[argc
++] = (wxChar
*) NULL
;
1774 #if defined(__WXGTK20__) && wxUSE_UNICODE
1776 wxExecute( argv
, TRUE
);
1778 wxRemoveFile( filename
);
1781 case wxPRINT_MODE_FILE
:
1782 case wxPRINT_MODE_NONE
:
1789 void wxPostScriptDC::StartPage()
1791 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1793 fprintf( m_pstream
, "%%%%Page: %d\n", wxPageNumber
++ );
1795 // What is this one supposed to do? RR.
1796 // *m_pstream << "matrix currentmatrix\n";
1798 // Added by Chris Breeze
1800 // Each page starts with an "initgraphics" which resets the
1801 // transformation and so we need to reset the origin
1802 // (and rotate the page for landscape printing)
1805 wxCoord translate_x
, translate_y
;
1806 double scale_x
, scale_y
;
1808 translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1809 translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1811 scale_x
= m_printData
.GetPrinterScaleX();
1812 scale_y
= m_printData
.GetPrinterScaleY();
1814 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1817 GetSize( (int*) NULL
, &h
);
1819 fprintf( m_pstream
, "90 rotate\n" );
1821 // I copied this one from a PostScript tutorial, but to no avail. RR.
1822 // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" );
1826 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1827 scale_y
/ ms_PSScaleFactor
);
1828 for (int i
= 0; i
< 100; i
++)
1829 if (buffer
[i
] == ',') buffer
[i
] = '.';
1830 fprintf( m_pstream
, buffer
);
1832 fprintf( m_pstream
, "%d %d translate\n", translate_x
, translate_y
);
1835 void wxPostScriptDC::EndPage ()
1837 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1839 fprintf( m_pstream
, "showpage\n" );
1842 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1843 wxCoord fwidth
, wxCoord fheight
,
1845 wxCoord xsrc
, wxCoord ysrc
,
1846 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
1848 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, wxT("invalid postscript dc") );
1850 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1852 /* blit into a bitmap */
1853 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1855 memDC
.SelectObject(bitmap
);
1856 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1857 memDC
.SelectObject(wxNullBitmap
);
1859 /* draw bitmap. scaling and positioning is done there */
1860 DrawBitmap( bitmap
, xdest
, ydest
);
1865 wxCoord
wxPostScriptDC::GetCharHeight() const
1868 return m_font
.GetPointSize();
1873 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1874 wxCoord
*x
, wxCoord
*y
,
1875 wxCoord
*descent
, wxCoord
*externalLeading
,
1876 wxFont
*theFont
) const
1878 wxFont
*fontToUse
= theFont
;
1880 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1882 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1884 const wxWX2MBbuf strbuf
= string
.mb_str();
1886 #if !wxUSE_AFM_FOR_POSTSCRIPT
1887 /* Provide a VERY rough estimate (avoid using it).
1888 * Produces accurate results for mono-spaced font
1889 * such as Courier (aka wxMODERN) */
1894 height
= fontToUse
->GetPointSize();
1897 *x
= strlen (strbuf
) * height
* 72 / 120;
1899 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
1900 if (descent
) *descent
= 0;
1901 if (externalLeading
) *externalLeading
= 0;
1904 /* method for calculating string widths in postscript:
1905 / read in the AFM (adobe font metrics) file for the
1906 / actual font, parse it and extract the character widths
1907 / and also the descender. this may be improved, but for now
1908 / it works well. the AFM file is only read in if the
1909 / font is changed. this may be chached in the future.
1910 / calls to GetTextExtent with the font unchanged are rather
1913 / for each font and style used there is an AFM file necessary.
1914 / currently i have only files for the roman font family.
1915 / I try to get files for the other ones!
1917 / CAVE: the size of the string is currently always calculated
1918 / in 'points' (1/72 of an inch). this should later on be
1919 / changed to depend on the mapping mode.
1920 / CAVE: the path to the AFM files must be set before calling this
1921 / function. this is usually done by a call like the following:
1922 / wxSetAFMPath("d:\\wxw161\\afm\\");
1926 / wxPostScriptDC dc(NULL, TRUE);
1928 / wxSetAFMPath("d:\\wxw161\\afm\\");
1929 / dc.StartDoc("Test");
1932 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1933 / dc.GetTextExtent("Hallo",&w,&h);
1938 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1940 / updated: 14.05.95 */
1942 /* these static vars are for storing the state between calls */
1943 static int lastFamily
= INT_MIN
;
1944 static int lastSize
= INT_MIN
;
1945 static int lastStyle
= INT_MIN
;
1946 static int lastWeight
= INT_MIN
;
1947 static int lastDescender
= INT_MIN
;
1948 static int lastWidths
[256]; /* widths of the characters */
1950 double UnderlinePosition
= 0.0;
1951 double UnderlineThickness
= 0.0;
1953 /* get actual parameters */
1954 int Family
= fontToUse
->GetFamily();
1955 int Size
= fontToUse
->GetPointSize();
1956 int Style
= fontToUse
->GetStyle();
1957 int Weight
= fontToUse
->GetWeight();
1959 /* if we have another font, read the font-metrics */
1960 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1962 /* store actual values */
1963 lastFamily
= Family
;
1966 lastWeight
= Weight
;
1968 const char *name
= NULL
;
1975 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO.afm";
1976 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo.afm";
1977 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "CourO.afm";
1978 else name
= "Cour.afm";
1983 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO.afm";
1984 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo.afm";
1985 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO.afm";
1986 else name
= "TimesRo.afm";
1998 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO.afm";
1999 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo.afm";
2000 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "HelvO.afm";
2001 else name
= "Helv.afm";
2006 /* get the directory of the AFM files */
2007 wxString afmName
= wxEmptyString
;
2008 if (!m_printData
.GetFontMetricPath().IsEmpty())
2010 afmName
= m_printData
.GetFontMetricPath();
2013 /* 2. open and process the file
2014 / a short explanation of the AFM format:
2015 / we have for each character a line, which gives its size
2018 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2020 / that means, we have a character with ascii code 63, and width
2021 / (444/1000 * fontSize) points.
2022 / the other data is ignored for now!
2024 / when the font has changed, we read in the right AFM file and store the
2025 / character widths in an array, which is processed below (see point 3.). */
2027 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
2030 FILE *afmFile
= wxFopen(afmName
,wxT("r"));
2034 afmName
= wxThePrintSetupData
->GetAFMPath();
2035 afmName
<< wxFILE_SEP_PATH
<< name
;
2036 afmFile
= wxFopen(afmName
,wxT("r"));
2039 #if defined(__UNIX__) && !defined(__VMS__)
2041 /* please do NOT change the line above to "else if (afmFile==NULL)" -
2042 - afmFile = fopen() may fail and in that case the next if branch
2043 MUST be executed - and it would not if there was "else" */
2045 afmName
= wxGetDataDir();
2046 afmName
<< wxFILE_SEP_PATH
2047 #if defined(__LINUX__) || defined(__FREEBSD__)
2048 << wxT("gs_afm") << wxFILE_SEP_PATH
2050 << wxT("afm") << wxFILE_SEP_PATH
2053 afmFile
= wxFopen(afmName
,wxT("r"));
2059 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2060 wxLogDebug( wxT(" using approximate values"));
2061 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2062 lastDescender
= -150; /* dito. */
2066 /* init the widths array */
2067 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2068 /* some variables for holding parts of a line */
2069 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2070 char upString
[30], utString
[30], encString
[50];
2073 /* read in the file and parse it */
2074 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2076 /* A.) check for descender definition */
2077 if (strncmp(line
,"Descender",9)==0)
2079 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2080 (strcmp(descString
,"Descender")!=0))
2082 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2085 /* JC 1.) check for UnderlinePosition */
2086 else if(strncmp(line
,"UnderlinePosition",17)==0)
2088 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2089 (strcmp(upString
,"UnderlinePosition")!=0))
2091 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2094 /* JC 2.) check for UnderlineThickness */
2095 else if(strncmp(line
,"UnderlineThickness",18)==0)
2097 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2098 (strcmp(utString
,"UnderlineThickness")!=0))
2100 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2103 /* JC 3.) check for EncodingScheme */
2104 else if(strncmp(line
,"EncodingScheme",14)==0)
2106 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2107 (strcmp(utString
,"EncodingScheme")!=0))
2109 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2111 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2113 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2114 afmName
.c_str(),line
, encString
);
2117 /* B.) check for char-width */
2118 else if(strncmp(line
,"C ",2)==0)
2120 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2122 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2124 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2126 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2128 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2129 if (ascii
>=0 && ascii
<256)
2131 lastWidths
[ascii
] = cWidth
; /* store width */
2135 /* MATTHEW: this happens a lot; don't print an error */
2136 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2139 /* C.) ignore other entries. */
2143 /* hack to compute correct values for german 'Umlaute'
2144 / the correct way would be to map the character names
2145 / like 'adieresis' to corresp. positions of ISOEnc and read
2146 / these values from AFM files, too. Maybe later ... */
2147 lastWidths
[196] = lastWidths
['A']; // Ä
2148 lastWidths
[228] = lastWidths
['a']; // ä
2149 lastWidths
[214] = lastWidths
['O']; // Ö
2150 lastWidths
[246] = lastWidths
['o']; // ö
2151 lastWidths
[220] = lastWidths
['U']; // Ü
2152 lastWidths
[252] = lastWidths
['u']; // ü
2153 lastWidths
[223] = lastWidths
[251]; // ß
2155 /* JC: calculate UnderlineThickness/UnderlinePosition */
2157 // VS: dirty, but is there any better solution?
2159 pt
= (double*) &m_underlinePosition
;
2160 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2161 pt
= (double*) &m_underlineThickness
;
2162 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2167 /* 3. now the font metrics are read in, calc size this
2168 / is done by adding the widths of the characters in the
2169 / string. they are given in 1/1000 of the size! */
2172 wxCoord height
=Size
; /* by default */
2174 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2176 if(lastWidths
[*p
]== INT_MIN
)
2178 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2179 sum
+= lastWidths
[' ']; /* assume space */
2183 sum
+= lastWidths
[*p
];
2187 double widthSum
= sum
;
2189 widthSum
/= 1000.0F
;
2191 /* add descender to height (it is usually a negative value) */
2192 //if (lastDescender != INT_MIN)
2194 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2196 // - commented by V. Slavik - height already contains descender in it
2197 // (judging from few experiments)
2199 /* return size values */
2201 *x
= (wxCoord
)widthSum
;
2205 /* return other parameters */
2208 if(lastDescender
!=INT_MIN
)
2210 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2218 /* currently no idea how to calculate this! */
2219 if (externalLeading
) *externalLeading
= 0;
2224 // Determine the Default Postscript Previewer
2225 // available on the platform
2226 #if defined(__SUN__) && defined(__XVIEW__)
2227 // OpenWindow/NeWS's Postscript Previewer
2228 # define PS_VIEWER_PROG "pageview"
2229 #elif defined(__VMS__)
2230 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
2231 #elif defined(__SGI__)
2232 // SGI's Display Postscript Previewer
2233 //# define PS_VIEWER_PROG "dps"
2234 # define PS_VIEWER_PROG "xpsview"
2235 #elif defined(__X__) || defined(__WXGTK__)
2236 // Front-end to ghostscript
2237 # define PS_VIEWER_PROG "ghostview"
2239 // Windows ghostscript/ghostview
2240 # define PS_VIEWER_PROG "gsview"
2243 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2245 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
2246 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
2248 // Redundant now I think
2250 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2252 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2253 const wxPoint
& pos
, const wxSize
& size
, wxCoord style
):
2254 wxDialog(parent
, -1, title
, pos
, size
, style
)
2256 wxBeginBusyCursor();
2261 *orientation
= new wxString
[2],
2262 *print_modes
= new wxString
[3];
2264 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
2265 double wx_printer_scale_x
, wx_printer_scale_y
;
2267 orientation
[0] = _("Portrait");
2268 orientation
[1] = _("Landscape");
2270 print_modes
[0] = _("Send to Printer");
2271 print_modes
[1] = _("Print to File");
2272 print_modes
[2] = _("Preview Only");
2276 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2277 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2278 okBut
->SetDefault();
2281 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2282 (void) new wxStaticText( this, -1, _("Printer Command: "),
2284 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2285 wxPoint(100, yPos
), wxSize(100, -1) );
2287 (void) new wxStaticText( this, -1, _("Printer Options: "),
2288 wxPoint(210, yPos
) );
2289 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2290 wxPoint(305, yPos
), wxSize(150, -1) );
2296 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2297 2,orientation
,2,wxRA_SPECIFY_ROWS
);
2298 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2300 // @@@ Configuration hook
2301 if ( !wxThePrintSetupData
->GetPrintPreviewCommand() )
2302 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2304 // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand);
2306 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
2307 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2309 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2311 wxSize(-1,-1), features
,
2312 print_modes
, features
, wxRA_SPECIFY_ROWS
);
2315 radio1
->Enable(0, FALSE
);
2316 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2317 radio1
->Enable(2, FALSE
);
2320 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2321 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2322 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2324 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2327 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2328 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2330 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2331 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2332 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2336 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2337 sprintf (buf
, "%.2d", wx_printer_translate_x
);
2338 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2340 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2341 sprintf (buf
, "%.2d", wx_printer_translate_y
);
2342 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2346 delete[] orientation
;
2347 delete[] print_modes
;
2352 int wxPostScriptPrintDialog::ShowModal ()
2354 if ( wxDialog::ShowModal() == wxID_OK
)
2356 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2357 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2358 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2359 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2360 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2361 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2362 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2363 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2365 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->m_printerScaleX
);
2366 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->m_printerScaleY
);
2369 StringToLong (WXSTRINGCAST text3
->GetValue (), &dummy
);
2370 wxThePrintSetupData
->m_printerTranslateX
= (wxCoord
)dummy
;
2371 StringToLong (WXSTRINGCAST text4
->GetValue (), &dummy
);
2372 wxThePrintSetupData
->m_printerTranslateY
= (wxCoord
)dummy
;
2375 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2376 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2379 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? wxLANDSCAPE
: wxPORTRAIT
));
2382 switch ( radio1
->GetSelection() ) {
2383 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2384 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2385 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2394 // PostScript printer settings
2395 // RETAINED FOR BACKWARD COMPATIBILITY
2396 void wxSetPrinterCommand(const wxString
& cmd
)
2398 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2401 void wxSetPrintPreviewCommand(const wxString
& cmd
)
2403 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2406 void wxSetPrinterOptions(const wxString
& flags
)
2408 wxThePrintSetupData
->SetPrinterOptions(flags
);
2411 void wxSetPrinterFile(const wxString
& f
)
2413 wxThePrintSetupData
->SetPrinterFile(f
);
2416 void wxSetPrinterOrientation(int orient
)
2418 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2421 void wxSetPrinterScaling(double x
, double y
)
2423 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2426 void wxSetPrinterTranslation(wxCoord x
, wxCoord y
)
2428 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2431 // 1 = Preview, 2 = print to file, 3 = send to printer
2432 void wxSetPrinterMode(int mode
)
2434 wxThePrintSetupData
->SetPrinterMode(mode
);
2437 void wxSetAFMPath(const wxString
& f
)
2439 wxThePrintSetupData
->SetAFMPath(f
);
2442 // Get current values
2443 wxString
wxGetPrinterCommand()
2445 return wxThePrintSetupData
->GetPrinterCommand();
2448 wxString
wxGetPrintPreviewCommand()
2450 return wxThePrintSetupData
->GetPrintPreviewCommand();
2453 wxString
wxGetPrinterOptions()
2455 return wxThePrintSetupData
->GetPrinterOptions();
2458 wxString
wxGetPrinterFile()
2460 return wxThePrintSetupData
->GetPrinterFile();
2463 int wxGetPrinterOrientation()
2465 return wxThePrintSetupData
->GetPrinterOrientation();
2468 void wxGetPrinterScaling(double* x
, double* y
)
2470 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2473 void wxGetPrinterTranslation(wxCoord
*x
, wxCoord
*y
)
2475 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2478 int wxGetPrinterMode()
2480 return wxThePrintSetupData
->GetPrinterMode();
2483 wxString
wxGetAFMPath()
2485 return wxThePrintSetupData
->GetAFMPath();
2492 wxPrintSetupData::wxPrintSetupData()
2494 m_printerOrient
= wxPORTRAIT
;
2495 m_printerScaleX
= (double)1.0;
2496 m_printerScaleY
= (double)1.0;
2497 m_printerTranslateX
= 0;
2498 m_printerTranslateY
= 0;
2499 m_printerMode
= wxPRINT_MODE_FILE
;
2500 m_printColour
= TRUE
;
2503 wxPrintSetupData::~wxPrintSetupData()
2507 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2509 SetPrinterCommand(data
.GetPrinterCommand());
2510 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2511 SetPrinterOptions(data
.GetPrinterOptions());
2513 data
.GetPrinterTranslation(&x
, &y
);
2514 SetPrinterTranslation(x
, y
);
2517 data
.GetPrinterScaling(&x1
, &y1
);
2518 SetPrinterScaling(x1
, y1
);
2520 SetPrinterOrientation(data
.GetPrinterOrientation());
2521 SetPrinterMode(data
.GetPrinterMode());
2522 SetAFMPath(data
.GetAFMPath());
2523 SetPaperName(data
.GetPaperName());
2524 SetColour(data
.GetColour());
2527 // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData).
2528 void wxPrintSetupData::operator=(const wxPrintData
& data
)
2530 SetPrinterCommand(data
.GetPrinterCommand());
2531 SetPrintPreviewCommand(data
.GetPreviewCommand());
2532 SetPrinterOptions(data
.GetPrinterOptions());
2533 SetPrinterTranslation((wxCoord
)data
.GetPrinterTranslateX(),
2534 (wxCoord
)data
.GetPrinterTranslateY());
2535 SetPrinterScaling(data
.GetPrinterScaleX(), data
.GetPrinterScaleY());
2536 SetPrinterOrientation(data
.GetOrientation());
2537 SetPrinterMode((int) data
.GetPrintMode());
2538 SetAFMPath(data
.GetFontMetricPath());
2539 SetPaperName(wxThePrintPaperDatabase
->ConvertIdToName(data
.GetPaperId()));
2540 SetColour(data
.GetColour());
2541 SetPrinterFile(data
.GetFilename());
2544 void wxInitializePrintSetupData(bool init
)
2548 wxThePrintSetupData
= new wxPrintSetupData
;
2550 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2551 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
2552 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_PREVIEW
);
2553 wxThePrintSetupData
->SetPaperName(_("A4 sheet, 210 x 297 mm"));
2555 // Could have a .ini file to read in some defaults
2556 // - and/or use environment variables, e.g. WXWIN
2558 wxThePrintSetupData
->SetPrinterCommand("print");
2559 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2560 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2563 wxThePrintSetupData
->SetPrinterCommand("print");
2564 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2565 wxThePrintSetupData
->SetPrinterOptions("");
2567 #if !defined(__VMS__) && !defined(__WXMSW__)
2568 wxThePrintSetupData
->SetPrinterCommand("lpr");
2569 wxThePrintSetupData
->SetPrinterOptions("");
2570 wxThePrintSetupData
->SetAFMPath("");
2575 if (wxThePrintSetupData
)
2576 delete wxThePrintSetupData
;
2577 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2581 // A module to allow initialization/cleanup of PostScript-related
2582 // things without calling these functions from app.cpp.
2584 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2586 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2588 wxPostScriptModule() {}
2593 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2596 * Initialization/cleanup module
2599 bool wxPostScriptModule::OnInit()
2601 wxInitializePrintSetupData();
2606 void wxPostScriptModule::OnExit()
2608 wxInitializePrintSetupData(FALSE
);
2615 // wxUSE_PRINTING_ARCHITECTURE