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"
26 #if wxUSE_PRINTING_ARCHITECTURE
30 #include "wx/window.h"
31 #include "wx/dcmemory.h"
34 #include "wx/filedlg.h"
36 #include "wx/msgdlg.h"
39 #include "wx/generic/dcpsg.h"
40 #include "wx/printdlg.h"
41 #include "wx/button.h"
42 #include "wx/stattext.h"
43 #include "wx/radiobox.h"
44 #include "wx/textctrl.h"
45 #include "wx/prntbase.h"
47 #include "wx/filefn.h"
71 //-----------------------------------------------------------------------------
72 // start and end of document/page
73 //-----------------------------------------------------------------------------
75 static const char *wxPostScriptHeaderEllipse
= "\
76 /ellipsedict 8 dict def\n\
77 ellipsedict /mtrx matrix put\n\
81 /startangle exch def\n\
86 /savematrix mtrx currentmatrix def\n\
89 0 0 1 startangle endangle arc\n\
90 savematrix setmatrix\n\
95 static const char *wxPostScriptHeaderEllipticArc
= "\
96 /ellipticarcdict 8 dict def\n\
97 ellipticarcdict /mtrx matrix put\n\
99 { ellipticarcdict begin\n\
101 /endangle exch def\n\
102 /startangle exch def\n\
107 /savematrix mtrx currentmatrix def\n\
110 do_fill { 0 0 moveto } if\n\
111 0 0 1 startangle endangle arc\n\
112 savematrix setmatrix\n\
113 do_fill { fill }{ stroke } ifelse\n\
117 static const char *wxPostScriptHeaderSpline
= "\
118 /DrawSplineSection {\n\
125 /xa x1 x2 x1 sub 0.666667 mul add def\n\
126 /ya y1 y2 y1 sub 0.666667 mul add def\n\
127 /xb x3 x2 x3 sub 0.666667 mul add def\n\
128 /yb y3 y2 y3 sub 0.666667 mul add def\n\
130 xa ya xb yb x3 y3 curveto\n\
134 static const char *wxPostScriptHeaderColourImage
= "\
135 %% define 'colorimage' if it isn't defined\n\
136 %% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
138 /colorimage where %% do we know about 'colorimage'?\n\
139 { pop } %% yes: pop off the 'dict' returned\n\
140 { %% no: define one\n\
141 /colortogray { %% define an RGB->I function\n\
142 /rgbdata exch store %% call input 'rgbdata'\n\
143 rgbdata length 3 idiv\n\
144 /npixls exch store\n\
146 0 1 npixls 1 sub {\n\
148 rgbdata rgbindx get 20 mul %% Red\n\
149 rgbdata rgbindx 1 add get 32 mul %% Green\n\
150 rgbdata rgbindx 2 add get 12 mul %% Blue\n\
151 add add 64 idiv %% I = .5G + .31R + .18B\n\
153 /rgbindx rgbindx 3 add store\n\
155 grays 0 npixls getinterval\n\
158 %% Utility procedure for colorimage operator.\n\
159 %% This procedure takes two procedures off the\n\
160 %% stack and merges them into a single procedure.\n\
162 /mergeprocs { %% def\n\
181 /colorimage { %% def\n\
182 pop pop %% remove 'false 3' operands\n\
183 {colortogray} mergeprocs\n\
186 } ifelse %% end of 'false' case\n\
189 static char wxPostScriptHeaderReencodeISO1
[] =
191 "dup dup findfont dup length dict begin\n"
192 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
193 "/Encoding ISOLatin1Encoding def\n"
194 "currentdict end definefont\n"
196 "/ISOLatin1Encoding [\n"
197 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
198 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
199 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
200 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
201 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
202 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
203 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
204 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
205 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
206 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
207 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
208 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
209 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
210 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
211 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
213 static char wxPostScriptHeaderReencodeISO2
[] =
214 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
215 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
216 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
217 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
218 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
219 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
220 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
221 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
222 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
223 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
224 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
225 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
226 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
227 "/yacute/thorn/ydieresis\n"
230 //-------------------------------------------------------------------------------
232 //-------------------------------------------------------------------------------
234 float wxPostScriptDC::ms_PSScaleFactor
= 10.0;
236 void wxPostScriptDC::SetResolution(int ppi
)
238 ms_PSScaleFactor
= (float)ppi
/ 72.0;
241 int wxPostScriptDC::GetResolution()
243 return (int)(ms_PSScaleFactor
* 72.0);
248 wxPostScriptDC::wxPostScriptDC ()
250 m_pstream
= (FILE*) NULL
;
260 m_underlinePosition
= 0.0;
261 m_underlineThickness
= 0.0;
263 m_signX
= 1; // default x-axis left to right
264 m_signY
= -1; // default y-axis bottom up -> top down
266 // Compatibility only
267 // HH: Doesn't seem to work for wxMSW...
269 m_printData
= * wxThePrintSetupData
;
273 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
275 m_pstream
= (FILE*) NULL
;
285 m_underlinePosition
= 0.0;
286 m_underlineThickness
= 0.0;
288 m_signX
= 1; // default x-axis left to right
289 m_signY
= -1; // default y-axis bottom up -> top down
291 Create(file
, interactive
, parent
);
294 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
296 m_isInteractive
= interactive
;
299 m_printData
.SetFilename(file
);
302 // Can only send to file in Windows
303 m_printData
.SetPrintMode(wxPRINT_MODE_FILE
);
308 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
318 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
320 m_pstream
= (FILE*) NULL
;
330 m_underlinePosition
= 0.0;
331 m_underlineThickness
= 0.0;
333 m_signX
= 1; // default x-axis left to right
334 m_signY
= -1; // default y-axis bottom up -> top down
336 m_printData
= printData
;
341 wxPostScriptDC::~wxPostScriptDC ()
346 m_pstream
= (FILE*) NULL
;
350 bool wxPostScriptDC::Ok() const
355 // This dialog is deprecated now: use wxGenericPrintDialog or the printing framework
356 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
358 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
359 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
360 m_ok
= (dialog
.ShowModal () == wxID_OK
);
362 if (!m_ok
) return FALSE
;
364 if ((m_printData
.GetFilename() == "") &&
365 (m_printData
.GetPrintMode() == wxPRINT_MODE_PREVIEW
||
366 m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
370 m_printData
.SetFilename("preview");
372 // For PS_PRINTER action this depends on a Unix-style print spooler
373 // since the wx_printer_file can be destroyed during a session
374 // @@@ TODO: a Windows-style answer for non-Unix
376 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
378 wxStrcpy (tmp
, wxT("/tmp/preview_"));
379 wxStrcat (tmp
, userId
);
380 m_printData
.SetFilename(tmp
);
383 wxStrcpy(tmp2
, m_printData
.GetFilename());
384 wxStrcat (tmp2
, wxT(".ps"));
385 m_printData
.SetFilename(tmp2
);
387 else if ((m_printData
.GetFilename() == wxT("")) && (m_printData
.GetPrintMode() == wxPRINT_MODE_FILE
))
389 wxString file
= wxSaveFileSelector (_("PostScript"), wxT("ps"));
390 if ( file
.IsEmpty() )
396 m_printData
.SetFilename(file
);
403 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
405 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
407 if (m_clipping
) DestroyClippingRegion();
409 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
418 "closepath clip newpath\n",
419 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
420 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
421 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
422 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
426 void wxPostScriptDC::DestroyClippingRegion()
428 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
433 fprintf( m_pstream
, "grestore\n" );
436 wxDC::DestroyClippingRegion();
439 void wxPostScriptDC::Clear()
441 wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
444 bool wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
446 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
450 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
452 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
456 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
458 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
461 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
463 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
465 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
474 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
475 LogicalToDeviceX(x2
), LogicalToDeviceY (y2
) );
477 CalcBoundingBox( x1
, y1
);
478 CalcBoundingBox( x2
, y2
);
481 #define RAD2DEG 57.29577951308
483 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
485 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
487 wxCoord dx
= x1
- xc
;
488 wxCoord dy
= y1
- yc
;
489 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
490 double alpha1
, alpha2
;
492 if (x1
== x2
&& y1
== y2
)
497 else if (radius
== 0.0)
499 alpha1
= alpha2
= 0.0;
503 alpha1
= (x1
- xc
== 0) ?
504 (y1
- yc
< 0) ? 90.0 : -90.0 :
505 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
506 alpha2
= (x2
- xc
== 0) ?
507 (y2
- yc
< 0) ? 90.0 : -90.0 :
508 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
510 while (alpha1
<= 0) alpha1
+= 360;
511 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
512 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
513 while (alpha2
> 360) alpha2
-= 360;
515 if (m_brush
.GetStyle() != wxTRANSPARENT
)
521 "%d %d %d %d %d %d ellipse\n"
525 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
526 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
528 CalcBoundingBox( xc
-radius
, yc
-radius
);
529 CalcBoundingBox( xc
+radius
, yc
+radius
);
532 if (m_pen
.GetStyle() != wxTRANSPARENT
)
538 "%d %d %d %d %d %d ellipse\n"
542 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
543 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
545 CalcBoundingBox( xc
-radius
, yc
-radius
);
546 CalcBoundingBox( xc
+radius
, yc
+radius
);
550 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
552 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
554 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
555 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
561 DrawEllipse(x
,y
,w
,h
);
565 if (m_brush
.GetStyle () != wxTRANSPARENT
)
571 "%d %d %d %d %d %d true ellipticarc\n",
572 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
574 CalcBoundingBox( x
,y
);
575 CalcBoundingBox( x
+w
, y
+h
);
578 if (m_pen
.GetStyle () != wxTRANSPARENT
)
584 "%d %d %d %d %d %d false ellipticarc\n",
585 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
587 CalcBoundingBox( x
,y
);
588 CalcBoundingBox( x
+w
, y
+h
);
592 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
594 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
596 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
605 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
606 LogicalToDeviceX(x
+1), LogicalToDeviceY(y
) );
608 CalcBoundingBox( x
, y
);
611 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
))
613 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
617 if (m_brush
.GetStyle () != wxTRANSPARENT
)
621 fprintf( m_pstream
, "newpath\n" );
623 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
624 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
626 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
628 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
630 for (int i
= 1; i
< n
; i
++)
632 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
633 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
635 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
637 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
640 fprintf( m_pstream
, "fill\n" );
643 if (m_pen
.GetStyle () != wxTRANSPARENT
)
647 fprintf( m_pstream
, "newpath\n" );
649 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
650 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
652 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
654 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
656 for (int i
= 1; i
< n
; i
++)
658 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
659 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
661 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
663 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
666 fprintf( m_pstream
, "closepath\n" );
667 fprintf( m_pstream
, "stroke\n" );
671 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
673 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
675 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
682 for ( i
=0; i
<n
; i
++ )
684 CalcBoundingBox( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
690 LogicalToDeviceX(points
[0].x
+xoffset
), LogicalToDeviceY(points
[0].y
+yoffset
) );
692 for (i
= 1; i
< n
; i
++)
696 LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
) );
699 fprintf( m_pstream
, "stroke\n" );
702 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
704 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
706 if (m_brush
.GetStyle () != wxTRANSPARENT
)
718 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
719 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
720 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
721 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
723 CalcBoundingBox( x
, y
);
724 CalcBoundingBox( x
+ width
, y
+ height
);
727 if (m_pen
.GetStyle () != wxTRANSPARENT
)
739 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
740 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
741 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
742 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
744 CalcBoundingBox( x
, y
);
745 CalcBoundingBox( x
+ width
, y
+ height
);
749 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
751 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
755 // Now, a negative radius is interpreted to mean
756 // 'the proportion of the smallest X or Y dimension'
757 double smallest
= 0.0;
762 radius
= (-radius
* smallest
);
765 wxCoord rad
= (wxCoord
) radius
;
767 if (m_brush
.GetStyle () != wxTRANSPARENT
)
771 /* Draw rectangle anticlockwise */
774 "%d %d %d 90 180 arc\n"
776 "%d %d %d 180 270 arc\n"
778 "%d %d %d 270 0 arc\n"
780 "%d %d %d 0 90 arc\n"
784 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
785 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
786 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
787 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
788 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
789 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
790 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
791 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
793 CalcBoundingBox( x
, y
);
794 CalcBoundingBox( x
+ width
, y
+ height
);
797 if (m_pen
.GetStyle () != wxTRANSPARENT
)
801 /* Draw rectangle anticlockwise */
804 "%d %d %d 90 180 arc\n"
806 "%d %d %d 180 270 arc\n"
808 "%d %d %d 270 0 arc\n"
810 "%d %d %d 0 90 arc\n"
814 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
815 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
816 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
817 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
818 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
819 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
820 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
821 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
823 CalcBoundingBox( x
, y
);
824 CalcBoundingBox( x
+ width
, y
+ height
);
828 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
830 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
832 if (m_brush
.GetStyle () != wxTRANSPARENT
)
838 "%d %d %d %d 0 360 ellipse\n"
840 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
841 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
843 CalcBoundingBox( x
- width
, y
- height
);
844 CalcBoundingBox( x
+ width
, y
+ height
);
847 if (m_pen
.GetStyle () != wxTRANSPARENT
)
853 "%d %d %d %d 0 360 ellipse\n"
855 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
856 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
858 CalcBoundingBox( x
- width
, y
- height
);
859 CalcBoundingBox( x
+ width
, y
+ height
);
863 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
865 DrawBitmap( icon
, x
, y
, TRUE
);
868 /* this has to be char, not wxChar */
869 static char hexArray
[] = "0123456789ABCDEF";
870 static void LocalDecToHex( int dec
, char *buf
)
872 int firstDigit
= (int)(dec
/16.0);
873 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
874 buf
[0] = hexArray
[firstDigit
];
875 buf
[1] = hexArray
[secondDigit
];
879 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
881 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
883 if (!bitmap
.Ok()) return;
885 wxImage image
= bitmap
.ConvertToImage();
887 if (!image
.Ok()) return;
889 wxCoord w
= image
.GetWidth();
890 wxCoord h
= image
.GetHeight();
892 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
893 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
895 wxCoord xx
= LogicalToDeviceX(x
);
896 wxCoord yy
= LogicalToDeviceY(y
+ bitmap
.GetHeight());
899 "/origstate save def\n"
901 "/pix %d string def\n"
902 "/grays %d string def\n"
909 "{currentfile pix readhexstring pop}\n"
910 "false 3 colorimage\n",
911 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
914 for (int j
= 0; j
< h
; j
++)
916 for (int i
= 0; i
< w
; i
++)
919 LocalDecToHex( image
.GetRed(i
,j
), buffer
);
920 fprintf( m_pstream
, buffer
);
921 LocalDecToHex( image
.GetGreen(i
,j
), buffer
);
922 fprintf( m_pstream
, buffer
);
923 LocalDecToHex( image
.GetBlue(i
,j
), buffer
);
924 fprintf( m_pstream
, buffer
);
926 fprintf( m_pstream
, "\n" );
929 fprintf( m_pstream
, "end\n" );
930 fprintf( m_pstream
, "origstate restore\n" );
933 void wxPostScriptDC::SetFont( const wxFont
& font
)
935 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
937 if (!font
.Ok()) return;
941 int Style
= m_font
.GetStyle();
942 int Weight
= m_font
.GetWeight();
945 switch (m_font
.GetFamily())
950 if (Style
== wxITALIC
)
952 if (Weight
== wxBOLD
)
953 name
= "/Courier-BoldOblique";
955 name
= "/Courier-Oblique";
959 if (Weight
== wxBOLD
)
960 name
= "/Courier-Bold";
968 if (Style
== wxITALIC
)
970 if (Weight
== wxBOLD
)
971 name
= "/Times-BoldItalic";
973 name
= "/Times-Italic";
977 if (Weight
== wxBOLD
)
978 name
= "/Times-Bold";
980 name
= "/Times-Roman";
986 name
= "/ZapfChancery-MediumItalic";
994 if (Style
== wxITALIC
)
996 if (Weight
== wxBOLD
)
997 name
= "/Helvetica-BoldOblique";
999 name
= "/Helvetica-Oblique";
1003 if (Weight
== wxBOLD
)
1004 name
= "/Helvetica-Bold";
1006 name
= "/Helvetica";
1012 fprintf( m_pstream
, name
);
1013 fprintf( m_pstream
, " reencodeISO def\n" );
1014 fprintf( m_pstream
, name
);
1015 fprintf( m_pstream
, " findfont\n" );
1018 sprintf( buffer
, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
1019 // this is a hack - we must scale font size (in pts) according to m_scaleY but
1020 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
1021 // to 1/1000th of pt and then back.
1022 for (int i
= 0; i
< 100; i
++)
1023 if (buffer
[i
] == ',') buffer
[i
] = '.';
1024 fprintf( m_pstream
, buffer
);
1027 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1029 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1031 if (!pen
.Ok()) return;
1033 int oldStyle
= m_pen
.GetStyle();
1040 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
1042 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
1044 for (int i
= 0; i
< 100; i
++)
1045 if (buffer
[i
] == ',') buffer
[i
] = '.';
1046 fprintf( m_pstream
, buffer
);
1050 Line style - WRONG: 2nd arg is OFFSET
1052 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1053 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1054 ter is not number of values in the array of the first one, but an offset
1055 into this description of the pattern. I mean a real *offset* not index
1056 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1057 will be first black line *2* units wxCoord, then space 4 units, then the
1058 pattern of *3* units black, 4 units space will be repeated.
1061 static const char *dotted
= "[2 5] 2";
1062 static const char *short_dashed
= "[4 4] 2";
1063 static const char *wxCoord_dashed
= "[4 8] 2";
1064 static const char *dotted_dashed
= "[6 6 2 6] 4";
1066 const char *psdash
= (char *) NULL
;
1067 switch (m_pen
.GetStyle())
1069 case wxDOT
: psdash
= dotted
; break;
1070 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1071 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1072 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1075 default: psdash
= "[] 0"; break;
1078 if (oldStyle
!= m_pen
.GetStyle())
1080 fprintf( m_pstream
, psdash
);
1081 fprintf( m_pstream
," setdash\n" );
1085 unsigned char red
= m_pen
.GetColour().Red();
1086 unsigned char blue
= m_pen
.GetColour().Blue();
1087 unsigned char green
= m_pen
.GetColour().Green();
1091 // Anything not white is black
1092 if (! (red
== (unsigned char) 255 &&
1093 blue
== (unsigned char) 255 &&
1094 green
== (unsigned char) 255) )
1096 red
= (unsigned char) 0;
1097 green
= (unsigned char) 0;
1098 blue
= (unsigned char) 0;
1103 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1105 double redPS
= (double)(red
) / 255.0;
1106 double bluePS
= (double)(blue
) / 255.0;
1107 double greenPS
= (double)(green
) / 255.0;
1111 "%.8f %.8f %.8f setrgbcolor\n",
1112 redPS
, greenPS
, bluePS
);
1113 for (int i
= 0; i
< 100; i
++)
1114 if (buffer
[i
] == ',') buffer
[i
] = '.';
1115 fprintf( m_pstream
, buffer
);
1118 m_currentBlue
= blue
;
1119 m_currentGreen
= green
;
1123 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1125 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1127 if (!brush
.Ok()) return;
1132 unsigned char red
= m_brush
.GetColour().Red();
1133 unsigned char blue
= m_brush
.GetColour().Blue();
1134 unsigned char green
= m_brush
.GetColour().Green();
1138 // Anything not white is black
1139 if (! (red
== (unsigned char) 255 &&
1140 blue
== (unsigned char) 255 &&
1141 green
== (unsigned char) 255) )
1143 red
= (unsigned char) 0;
1144 green
= (unsigned char) 0;
1145 blue
= (unsigned char) 0;
1150 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1152 double redPS
= (double)(red
) / 255.0;
1153 double bluePS
= (double)(blue
) / 255.0;
1154 double greenPS
= (double)(green
) / 255.0;
1158 "%.8f %.8f %.8f setrgbcolor\n",
1159 redPS
, greenPS
, bluePS
);
1160 for (int i
= 0; i
< 100; i
++)
1161 if (buffer
[i
] == ',') buffer
[i
] = '.';
1162 fprintf( m_pstream
, buffer
);
1165 m_currentBlue
= blue
;
1166 m_currentGreen
= green
;
1170 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1172 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1174 wxCoord text_w
, text_h
, text_descent
;
1176 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1178 // VZ: this seems to be unnecessary, so taking it out for now, if it
1179 // doesn't create any problems, remove this comment entirely
1180 //SetFont( m_font );
1182 if (m_textForegroundColour
.Ok())
1184 unsigned char red
= m_textForegroundColour
.Red();
1185 unsigned char blue
= m_textForegroundColour
.Blue();
1186 unsigned char green
= m_textForegroundColour
.Green();
1190 // Anything not white is black
1191 if (! (red
== (unsigned char) 255 &&
1192 blue
== (unsigned char) 255 &&
1193 green
== (unsigned char) 255))
1195 red
= (unsigned char) 0;
1196 green
= (unsigned char) 0;
1197 blue
= (unsigned char) 0;
1201 // maybe setgray here ?
1202 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1204 double redPS
= (double)(red
) / 255.0;
1205 double bluePS
= (double)(blue
) / 255.0;
1206 double greenPS
= (double)(green
) / 255.0;
1210 "%.8f %.8f %.8f setrgbcolor\n",
1211 redPS
, greenPS
, bluePS
);
1212 for (int i
= 0; i
< 100; i
++)
1213 if (buffer
[i
] == ',') buffer
[i
] = '.';
1214 fprintf( m_pstream
, buffer
);
1217 m_currentBlue
= blue
;
1218 m_currentGreen
= green
;
1222 int size
= m_font
.GetPointSize();
1224 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1225 // commented by V. Slavik and replaced by accurate version
1226 // - note that there is still rounding error in text_descent!
1227 wxCoord by
= y
+ size
- text_descent
; // baseline
1228 fprintf( m_pstream
, "%d %d moveto\n", LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1230 fprintf( m_pstream
, "(" );
1231 const wxWX2MBbuf textbuf
= text
.mb_str();
1232 size_t len
= strlen(textbuf
);
1234 for (i
= 0; i
< len
; i
++)
1236 int c
= (unsigned char) textbuf
[i
];
1237 if (c
== ')' || c
== '(' || c
== '\\')
1239 /* Cope with special characters */
1240 fprintf( m_pstream
, "\\" );
1241 fputc(c
, m_pstream
);
1243 else if ( c
>= 128 )
1245 /* Cope with character codes > 127 */
1246 fprintf(m_pstream
, "\\%o", c
);
1250 fputc(c
, m_pstream
);
1254 fprintf( m_pstream
, ") show\n" );
1256 if (m_font
.GetUnderlined())
1258 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1268 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1269 m_underlineThickness
,
1270 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1271 for (i
= 0; i
< 100; i
++)
1272 if (buffer
[i
] == ',') buffer
[i
] = '.';
1273 fprintf( m_pstream
, buffer
);
1276 CalcBoundingBox( x
, y
);
1277 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1280 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1284 DoDrawText(text
, x
, y
);
1288 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1292 if (m_textForegroundColour
.Ok())
1294 unsigned char red
= m_textForegroundColour
.Red();
1295 unsigned char blue
= m_textForegroundColour
.Blue();
1296 unsigned char green
= m_textForegroundColour
.Green();
1300 // Anything not white is black
1301 if (! (red
== (unsigned char) 255 &&
1302 blue
== (unsigned char) 255 &&
1303 green
== (unsigned char) 255))
1305 red
= (unsigned char) 0;
1306 green
= (unsigned char) 0;
1307 blue
= (unsigned char) 0;
1311 // maybe setgray here ?
1312 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1314 double redPS
= (double)(red
) / 255.0;
1315 double bluePS
= (double)(blue
) / 255.0;
1316 double greenPS
= (double)(green
) / 255.0;
1320 "%.8f %.8f %.8f setrgbcolor\n",
1321 redPS
, greenPS
, bluePS
);
1322 for (int i
= 0; i
< 100; i
++)
1323 if (buffer
[i
] == ',') buffer
[i
] = '.';
1324 fprintf( m_pstream
, buffer
);
1327 m_currentBlue
= blue
;
1328 m_currentGreen
= green
;
1332 int size
= m_font
.GetPointSize();
1334 long by
= y
+ (long)floor( double(size
) * 2.0 / 3.0 ); // approximate baseline
1336 // FIXME only correct for 90 degrees
1337 fprintf(m_pstream
, "%d %d moveto\n",
1338 LogicalToDeviceX((wxCoord
)(x
+ size
)), LogicalToDeviceY((wxCoord
)by
) );
1341 sprintf(buffer
, "%.8f rotate\n", angle
);
1343 for (i
= 0; i
< 100; i
++)
1344 if (buffer
[i
] == ',') buffer
[i
] = '.';
1345 fprintf(m_pstream
, buffer
);
1347 fprintf( m_pstream
, "(" );
1348 const wxWX2MBbuf textbuf
= text
.mb_str();
1349 size_t len
= strlen(textbuf
);
1350 for (i
= 0; i
< len
; i
++)
1352 int c
= (unsigned char) textbuf
[i
];
1353 if (c
== ')' || c
== '(' || c
== '\\')
1355 /* Cope with special characters */
1356 fprintf( m_pstream
, "\\" );
1357 fputc(c
, m_pstream
);
1359 else if ( c
>= 128 )
1361 /* Cope with character codes > 127 */
1362 fprintf(m_pstream
, "\\%o", c
);
1366 fputc(c
, m_pstream
);
1370 fprintf( m_pstream
, ") show\n" );
1372 sprintf( buffer
, "%.8f rotate\n", -angle
);
1373 for (i
= 0; i
< 100; i
++)
1374 if (buffer
[i
] == ',') buffer
[i
] = '.';
1375 fprintf( m_pstream
, buffer
);
1377 if (m_font
.GetUnderlined())
1379 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1382 GetTextExtent(text
, &w
, &h
);
1391 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1392 m_underlineThickness
,
1393 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1394 for (i
= 0; i
< 100; i
++)
1395 if (buffer
[i
] == ',') buffer
[i
] = '.';
1396 fprintf( m_pstream
, buffer
);
1399 CalcBoundingBox( x
, y
);
1400 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1403 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1405 m_backgroundBrush
= brush
;
1408 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1410 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1413 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1415 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1419 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1422 wxNode
*node
= points
->First();
1423 p
= (wxPoint
*)node
->Data();
1427 node
= node
->Next();
1428 p
= (wxPoint
*)node
->Data();
1431 x3
= a
= (double)(x1
+ c
) / 2;
1432 y3
= b
= (double)(y1
+ d
) / 2;
1438 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1439 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1441 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1442 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1444 while ((node
= node
->Next()) != NULL
)
1446 q
= (wxPoint
*)node
->Data();
1454 x3
= (double)(x2
+ c
) / 2;
1455 y3
= (double)(y2
+ d
) / 2;
1458 "%d %d %d %d %d %d DrawSplineSection\n",
1459 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1460 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1461 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1463 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1464 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1468 At this point, (x2,y2) and (c,d) are the position of the
1469 next-to-last and last point respectively, in the point list
1475 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1478 wxCoord
wxPostScriptDC::GetCharWidth() const
1480 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1481 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1485 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1487 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1489 m_signX
= (xLeftRight
? 1 : -1);
1490 m_signY
= (yBottomUp
? 1 : -1);
1492 // FIXME there is no such function in MSW nor in OS2/PM
1493 #if !defined(__WXMSW__) && !defined(__WXPM__)
1494 ComputeScaleAndOrigin();
1498 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1500 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1506 wxDC::SetDeviceOrigin( x
, h
-y
);
1509 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1511 wxPaperSize id
= m_printData
.GetPaperId();
1513 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1515 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1521 w
= paper
->GetSizeDeviceUnits().x
;
1522 h
= paper
->GetSizeDeviceUnits().y
;
1525 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1532 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1533 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1536 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1538 wxPaperSize id
= m_printData
.GetPaperId();
1540 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1542 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1548 w
= paper
->GetWidth() / 10;
1549 h
= paper
->GetHeight() / 10;
1552 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1559 if (width
) *width
= w
;
1560 if (height
) *height
= h
;
1563 // Resolution in pixels per logical inch
1564 wxSize
wxPostScriptDC::GetPPI(void) const
1566 return wxSize((int)(72 * ms_PSScaleFactor
),
1567 (int)(72 * ms_PSScaleFactor
));
1571 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1573 wxCHECK_MSG( m_ok
, FALSE
, wxT("invalid postscript dc") );
1575 if (m_printData
.GetFilename() == "")
1577 wxString filename
= wxGetTempFileName("ps");
1578 m_printData
.SetFilename(filename
);
1581 m_pstream
= wxFopen( m_printData
.GetFilename().fn_str(), wxT("w+") );
1585 wxLogError( _("Cannot open file for PostScript printing!"));
1592 fprintf( m_pstream
, "%%%%BeginProlog\n" );
1593 fprintf( m_pstream
, wxPostScriptHeaderEllipse
);
1594 fprintf( m_pstream
, wxPostScriptHeaderEllipticArc
);
1595 fprintf( m_pstream
, wxPostScriptHeaderColourImage
);
1596 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO1
);
1597 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO2
);
1598 if (wxPostScriptHeaderSpline
)
1599 fprintf( m_pstream
, wxPostScriptHeaderSpline
);
1600 fprintf( m_pstream
, "%%%%EndProlog\n" );
1602 SetBrush( *wxBLACK_BRUSH
);
1603 SetPen( *wxBLACK_PEN
);
1604 SetBackground( *wxWHITE_BRUSH
);
1605 SetTextForeground( *wxBLACK
);
1607 // set origin according to paper size
1608 SetDeviceOrigin( 0,0 );
1616 void wxPostScriptDC::EndDoc ()
1618 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1623 fprintf( m_pstream
, "grestore\n" );
1626 fclose( m_pstream
);
1627 m_pstream
= (FILE *) NULL
;
1629 wxChar
*header_file
= wxGetTempFileName("ps");
1631 m_pstream
= fopen( wxConvFile
.cWX2MB(header_file
) , "w+" );
1633 fprintf( m_pstream
, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings
1634 fprintf( m_pstream
, "%%%%Title: %s\n", (const char *)m_title
.mb_str() );
1635 fprintf( m_pstream
, "%%%%Creator: %s\n", (const char*)wxConvCurrent
->cWX2MB(wxTheApp
->argv
[0]) );
1636 fprintf( m_pstream
, "%%%%CreationDate: %s\n", (const char *)wxNow().mb_str() );
1639 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1641 fprintf( m_pstream
, "%%%%For: %s ", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );
1642 wxChar userName
[245];
1643 if (wxGetUserName(userName
, sizeof(userName
)))
1644 fprintf( m_pstream
, " (%s)", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userName
) );
1645 fprintf( m_pstream
, "\n" );
1647 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1649 fprintf( m_pstream
, "%%%%For: %s\n", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );;
1652 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1654 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1655 double wx_printer_scale_x
, wx_printer_scale_y
;
1657 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1658 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1660 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1661 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1663 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1664 fprintf( m_pstream
, "%%%%Orientation: Landscape\n" );
1666 fprintf( m_pstream
, "%%%%Orientation: Portrait\n" );
1668 // Compute the bounding box. Note that it is in the default user
1669 // coordinate system, thus we have to convert the values.
1670 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1671 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1672 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1673 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1675 // LOG2DEV may have changed the minimum to maximum vice versa
1676 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1677 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1679 // account for used scaling (boundingbox is before scaling in ps-file)
1680 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1681 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1683 wxCoord llx
, lly
, urx
, ury
;
1684 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1685 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1686 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1687 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1688 // (end of bounding box computation)
1691 // If we're landscape, our sense of "x" and "y" is reversed.
1692 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1695 tmp
= llx
; llx
= lly
; lly
= tmp
;
1696 tmp
= urx
; urx
= ury
; ury
= tmp
;
1698 // We need either the two lines that follow, or we need to subtract
1699 // min_x from real_translate_y, which is commented out below.
1700 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1701 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1704 // The Adobe specifications call for integers; we round as to make
1705 // the bounding larger.
1707 "%%%%BoundingBox: %d %d %d %d\n",
1708 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1709 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1710 fprintf( m_pstream
, "%%%%Pages: %d\n", (wxPageNumber
- 1) );
1711 fprintf( m_pstream
, "%%%%EndComments\n\n" );
1713 // To check the correctness of the bounding box, postscript commands
1714 // to draw a box corresponding to the bounding box are generated below.
1715 // But since we typically don't want to print such a box, the postscript
1716 // commands are generated within comments. These lines appear before any
1717 // adjustment of scale, rotation, or translation, and hence are in the
1718 // default user coordinates.
1719 fprintf( m_pstream
, "%% newpath\n" );
1720 fprintf( m_pstream
, "%% %d %d moveto\n", llx
, lly
);
1721 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, lly
);
1722 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, ury
);
1723 fprintf( m_pstream
, "%% %d %d lineto closepath stroke\n", llx
, ury
);
1725 fclose( m_pstream
);
1726 m_pstream
= (FILE*) NULL
;
1728 wxChar
*tmp_file
= wxGetTempFileName("ps");
1730 // Paste header Before wx_printer_file
1731 wxConcatFiles (header_file
, m_printData
.GetFilename(), tmp_file
);
1732 wxRemoveFile( header_file
);
1733 wxRemoveFile( m_printData
.GetFilename() );
1734 wxRenameFile( tmp_file
, m_printData
.GetFilename() );
1736 #if defined(__X__) || defined(__WXGTK__)
1739 wxString
previewCommand(m_printData
.GetPreviewCommand());
1740 wxString
printerCommand(m_printData
.GetPrinterCommand());
1741 wxString
printerOptions(m_printData
.GetPrinterOptions());
1742 wxString
filename(m_printData
.GetFilename());
1744 switch (m_printData
.GetPrintMode())
1746 case wxPRINT_MODE_PREVIEW
:
1749 argv
[0] = WXSTRINGCAST previewCommand
;
1750 argv
[1] = WXSTRINGCAST filename
;
1751 argv
[2] = (wxChar
*) NULL
;
1752 wxExecute( argv
, TRUE
);
1753 wxRemoveFile( m_printData
.GetFilename() );
1756 case wxPRINT_MODE_PRINTER
:
1760 argv
[argc
++] = WXSTRINGCAST printerCommand
;
1762 // !SM! If we simply assign to argv[1] here, if printer options
1763 // are blank, we get an annoying and confusing message from lpr.
1764 wxChar
*opts
= WXSTRINGCAST printerOptions
;
1766 argv
[argc
++] = opts
;
1768 argv
[argc
++] = WXSTRINGCAST filename
;
1769 argv
[argc
++] = (wxChar
*) NULL
;
1770 wxExecute( argv
, TRUE
);
1771 wxRemoveFile( filename
);
1774 case wxPRINT_MODE_FILE
:
1775 case wxPRINT_MODE_NONE
:
1782 void wxPostScriptDC::StartPage()
1784 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1786 fprintf( m_pstream
, "%%%%Page: %d\n", wxPageNumber
++ );
1788 // What is this one supposed to do? RR.
1789 // *m_pstream << "matrix currentmatrix\n";
1791 // Added by Chris Breeze
1793 // Each page starts with an "initgraphics" which resets the
1794 // transformation and so we need to reset the origin
1795 // (and rotate the page for landscape printing)
1798 wxCoord translate_x
, translate_y
;
1799 double scale_x
, scale_y
;
1801 translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1802 translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1804 scale_x
= m_printData
.GetPrinterScaleX();
1805 scale_y
= m_printData
.GetPrinterScaleY();
1807 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1810 GetSize( (int*) NULL
, &h
);
1812 fprintf( m_pstream
, "90 rotate\n" );
1814 // I copied this one from a PostScript tutorial, but to no avail. RR.
1815 // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" );
1819 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1820 scale_y
/ ms_PSScaleFactor
);
1821 for (int i
= 0; i
< 100; i
++)
1822 if (buffer
[i
] == ',') buffer
[i
] = '.';
1823 fprintf( m_pstream
, buffer
);
1825 fprintf( m_pstream
, "%d %d translate\n", translate_x
, translate_y
);
1828 void wxPostScriptDC::EndPage ()
1830 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1832 fprintf( m_pstream
, "showpage\n" );
1835 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1836 wxCoord fwidth
, wxCoord fheight
,
1838 wxCoord xsrc
, wxCoord ysrc
,
1839 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
1841 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, wxT("invalid postscript dc") );
1843 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1845 /* blit into a bitmap */
1846 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1848 memDC
.SelectObject(bitmap
);
1849 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1850 memDC
.SelectObject(wxNullBitmap
);
1852 /* draw bitmap. scaling and positioning is done there */
1853 DrawBitmap( bitmap
, xdest
, ydest
);
1858 wxCoord
wxPostScriptDC::GetCharHeight() const
1861 return m_font
.GetPointSize();
1866 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1867 wxCoord
*x
, wxCoord
*y
,
1868 wxCoord
*descent
, wxCoord
*externalLeading
,
1869 wxFont
*theFont
) const
1871 wxFont
*fontToUse
= theFont
;
1873 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1875 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1877 const wxWX2MBbuf strbuf
= string
.mb_str();
1879 #if !wxUSE_AFM_FOR_POSTSCRIPT
1880 /* Provide a VERY rough estimate (avoid using it).
1881 * Produces accurate results for mono-spaced font
1882 * such as Courier (aka wxMODERN) */
1887 height
= fontToUse
->GetPointSize();
1890 *x
= strlen (strbuf
) * height
* 72 / 120;
1892 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
1893 if (descent
) *descent
= 0;
1894 if (externalLeading
) *externalLeading
= 0;
1897 /* method for calculating string widths in postscript:
1898 / read in the AFM (adobe font metrics) file for the
1899 / actual font, parse it and extract the character widths
1900 / and also the descender. this may be improved, but for now
1901 / it works well. the AFM file is only read in if the
1902 / font is changed. this may be chached in the future.
1903 / calls to GetTextExtent with the font unchanged are rather
1906 / for each font and style used there is an AFM file necessary.
1907 / currently i have only files for the roman font family.
1908 / I try to get files for the other ones!
1910 / CAVE: the size of the string is currently always calculated
1911 / in 'points' (1/72 of an inch). this should later on be
1912 / changed to depend on the mapping mode.
1913 / CAVE: the path to the AFM files must be set before calling this
1914 / function. this is usually done by a call like the following:
1915 / wxSetAFMPath("d:\\wxw161\\afm\\");
1919 / wxPostScriptDC dc(NULL, TRUE);
1921 / wxSetAFMPath("d:\\wxw161\\afm\\");
1922 / dc.StartDoc("Test");
1925 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1926 / dc.GetTextExtent("Hallo",&w,&h);
1931 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1933 / updated: 14.05.95 */
1935 /* these static vars are for storing the state between calls */
1936 static int lastFamily
= INT_MIN
;
1937 static int lastSize
= INT_MIN
;
1938 static int lastStyle
= INT_MIN
;
1939 static int lastWeight
= INT_MIN
;
1940 static int lastDescender
= INT_MIN
;
1941 static int lastWidths
[256]; /* widths of the characters */
1943 double UnderlinePosition
= 0.0;
1944 double UnderlineThickness
= 0.0;
1946 /* get actual parameters */
1947 int Family
= fontToUse
->GetFamily();
1948 int Size
= fontToUse
->GetPointSize();
1949 int Style
= fontToUse
->GetStyle();
1950 int Weight
= fontToUse
->GetWeight();
1952 /* if we have another font, read the font-metrics */
1953 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1955 /* store actual values */
1956 lastFamily
= Family
;
1959 lastWeight
= Weight
;
1961 const char *name
= NULL
;
1968 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO.afm";
1969 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo.afm";
1970 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "CourO.afm";
1971 else name
= "Cour.afm";
1976 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO.afm";
1977 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo.afm";
1978 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO.afm";
1979 else name
= "TimesRo.afm";
1991 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO.afm";
1992 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo.afm";
1993 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "HelvO.afm";
1994 else name
= "Helv.afm";
1999 /* get the directory of the AFM files */
2000 wxString afmName
= wxEmptyString
;
2001 if (!m_printData
.GetFontMetricPath().IsEmpty())
2003 afmName
= m_printData
.GetFontMetricPath();
2006 /* 2. open and process the file
2007 / a short explanation of the AFM format:
2008 / we have for each character a line, which gives its size
2011 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2013 / that means, we have a character with ascii code 63, and width
2014 / (444/1000 * fontSize) points.
2015 / the other data is ignored for now!
2017 / when the font has changed, we read in the right AFM file and store the
2018 / character widths in an array, which is processed below (see point 3.). */
2020 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
2023 FILE *afmFile
= wxFopen(afmName
,wxT("r"));
2027 afmName
= wxThePrintSetupData
->GetAFMPath();
2028 afmName
<< wxFILE_SEP_PATH
<< name
;
2029 afmFile
= wxFopen(afmName
,wxT("r"));
2032 #if defined(__UNIX__) && !defined(__VMS__)
2034 /* please do NOT change the line above to "else if (afmFile==NULL)" -
2035 - afmFile = fopen() may fail and in that case the next if branch
2036 MUST be executed - and it would not if there was "else" */
2038 afmName
= wxGetDataDir();
2039 afmName
<< wxFILE_SEP_PATH
2040 #if defined(__LINUX__) || defined(__FREEBSD__)
2041 << wxT("gs_afm") << wxFILE_SEP_PATH
2043 << wxT("afm") << wxFILE_SEP_PATH
2046 afmFile
= wxFopen(afmName
,wxT("r"));
2052 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%hs'"), afmName
.c_str() );
2053 wxLogDebug( wxT(" using approximate values"));
2054 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2055 lastDescender
= -150; /* dito. */
2059 /* init the widths array */
2060 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2061 /* some variables for holding parts of a line */
2062 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2063 char upString
[30], utString
[30], encString
[50];
2066 /* read in the file and parse it */
2067 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2069 /* A.) check for descender definition */
2070 if (strncmp(line
,"Descender",9)==0)
2072 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2073 (strcmp(descString
,"Descender")!=0))
2075 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad descender)"), afmName
.c_str(),line
);
2078 /* JC 1.) check for UnderlinePosition */
2079 else if(strncmp(line
,"UnderlinePosition",17)==0)
2081 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2082 (strcmp(upString
,"UnderlinePosition")!=0))
2084 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2087 /* JC 2.) check for UnderlineThickness */
2088 else if(strncmp(line
,"UnderlineThickness",18)==0)
2090 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2091 (strcmp(utString
,"UnderlineThickness")!=0))
2093 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2096 /* JC 3.) check for EncodingScheme */
2097 else if(strncmp(line
,"EncodingScheme",14)==0)
2099 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2100 (strcmp(utString
,"EncodingScheme")!=0))
2102 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2104 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2106 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (unsupported EncodingScheme %hs)"),
2107 afmName
.c_str(),line
, encString
);
2110 /* B.) check for char-width */
2111 else if(strncmp(line
,"C ",2)==0)
2113 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2115 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has an error (bad character width)"),afmName
.c_str(),line
);
2117 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2119 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has a format error"),afmName
.c_str(),line
);
2121 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2122 if (ascii
>=0 && ascii
<256)
2124 lastWidths
[ascii
] = cWidth
; /* store width */
2128 /* MATTHEW: this happens a lot; don't print an error */
2129 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2132 /* C.) ignore other entries. */
2136 /* hack to compute correct values for german 'Umlaute'
2137 / the correct way would be to map the character names
2138 / like 'adieresis' to corresp. positions of ISOEnc and read
2139 / these values from AFM files, too. Maybe later ... */
2140 lastWidths
[196] = lastWidths
['A']; // Ä
2141 lastWidths
[228] = lastWidths
['a']; // ä
2142 lastWidths
[214] = lastWidths
['O']; // Ö
2143 lastWidths
[246] = lastWidths
['o']; // ö
2144 lastWidths
[220] = lastWidths
['U']; // Ü
2145 lastWidths
[252] = lastWidths
['u']; // ü
2146 lastWidths
[223] = lastWidths
[251]; // ß
2148 /* JC: calculate UnderlineThickness/UnderlinePosition */
2150 // VS: dirty, but is there any better solution?
2152 pt
= (double*) &m_underlinePosition
;
2153 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2154 pt
= (double*) &m_underlineThickness
;
2155 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2160 /* 3. now the font metrics are read in, calc size this
2161 / is done by adding the widths of the characters in the
2162 / string. they are given in 1/1000 of the size! */
2165 wxCoord height
=Size
; /* by default */
2167 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2169 if(lastWidths
[*p
]== INT_MIN
)
2171 wxLogDebug(wxT("GetTextExtent: undefined width for character '%hc' (%d)"), *p
,*p
);
2172 sum
+= lastWidths
[' ']; /* assume space */
2176 sum
+= lastWidths
[*p
];
2180 double widthSum
= sum
;
2182 widthSum
/= 1000.0F
;
2184 /* add descender to height (it is usually a negative value) */
2185 //if (lastDescender != INT_MIN)
2187 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2189 // - commented by V. Slavik - height already contains descender in it
2190 // (judging from few experiments)
2192 /* return size values */
2194 *x
= (wxCoord
)widthSum
;
2198 /* return other parameters */
2201 if(lastDescender
!=INT_MIN
)
2203 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2211 /* currently no idea how to calculate this! */
2212 if (externalLeading
) *externalLeading
= 0;
2217 // Determine the Default Postscript Previewer
2218 // available on the platform
2219 #if defined(__SUN__) && defined(__XVIEW__)
2220 // OpenWindow/NeWS's Postscript Previewer
2221 # define PS_VIEWER_PROG "pageview"
2222 #elif defined(__VMS__)
2223 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
2224 #elif defined(__SGI__)
2225 // SGI's Display Postscript Previewer
2226 //# define PS_VIEWER_PROG "dps"
2227 # define PS_VIEWER_PROG "xpsview"
2228 #elif defined(__X__) || defined(__WXGTK__)
2229 // Front-end to ghostscript
2230 # define PS_VIEWER_PROG "ghostview"
2232 // Windows ghostscript/ghostview
2233 # define PS_VIEWER_PROG "gsview"
2236 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2238 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
2239 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
2241 // Redundant now I think
2243 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2245 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2246 const wxPoint
& pos
, const wxSize
& size
, wxCoord style
):
2247 wxDialog(parent
, -1, title
, pos
, size
, style
)
2249 wxBeginBusyCursor();
2254 *orientation
= new wxString
[2],
2255 *print_modes
= new wxString
[3];
2257 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
2258 double wx_printer_scale_x
, wx_printer_scale_y
;
2260 orientation
[0] = _("Portrait");
2261 orientation
[1] = _("Landscape");
2263 print_modes
[0] = _("Send to Printer");
2264 print_modes
[1] = _("Print to File");
2265 print_modes
[2] = _("Preview Only");
2269 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2270 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2271 okBut
->SetDefault();
2274 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2275 (void) new wxStaticText( this, -1, _("Printer Command: "),
2277 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2278 wxPoint(100, yPos
), wxSize(100, -1) );
2280 (void) new wxStaticText( this, -1, _("Printer Options: "),
2281 wxPoint(210, yPos
) );
2282 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2283 wxPoint(305, yPos
), wxSize(150, -1) );
2289 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2290 2,orientation
,2,wxRA_SPECIFY_ROWS
);
2291 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2293 // @@@ Configuration hook
2294 if ( !wxThePrintSetupData
->GetPrintPreviewCommand() )
2295 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2297 // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand);
2299 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
2300 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2302 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2304 wxSize(-1,-1), features
,
2305 print_modes
, features
, wxRA_SPECIFY_ROWS
);
2308 radio1
->Enable(0, FALSE
);
2309 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2310 radio1
->Enable(2, FALSE
);
2313 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2314 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2315 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2317 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2320 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2321 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2323 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2324 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2325 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2329 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2330 sprintf (buf
, "%.2d", wx_printer_translate_x
);
2331 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2333 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2334 sprintf (buf
, "%.2d", wx_printer_translate_y
);
2335 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2339 delete[] orientation
;
2340 delete[] print_modes
;
2345 int wxPostScriptPrintDialog::ShowModal ()
2347 if ( wxDialog::ShowModal() == wxID_OK
)
2349 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2350 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2351 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2352 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2353 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2354 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2355 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2356 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2358 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->m_printerScaleX
);
2359 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->m_printerScaleY
);
2362 StringToLong (WXSTRINGCAST text3
->GetValue (), &dummy
);
2363 wxThePrintSetupData
->m_printerTranslateX
= (wxCoord
)dummy
;
2364 StringToLong (WXSTRINGCAST text4
->GetValue (), &dummy
);
2365 wxThePrintSetupData
->m_printerTranslateY
= (wxCoord
)dummy
;
2368 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2369 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2372 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? wxLANDSCAPE
: wxPORTRAIT
));
2375 switch ( radio1
->GetSelection() ) {
2376 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2377 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2378 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2387 // PostScript printer settings
2388 // RETAINED FOR BACKWARD COMPATIBILITY
2389 void wxSetPrinterCommand(const wxString
& cmd
)
2391 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2394 void wxSetPrintPreviewCommand(const wxString
& cmd
)
2396 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2399 void wxSetPrinterOptions(const wxString
& flags
)
2401 wxThePrintSetupData
->SetPrinterOptions(flags
);
2404 void wxSetPrinterFile(const wxString
& f
)
2406 wxThePrintSetupData
->SetPrinterFile(f
);
2409 void wxSetPrinterOrientation(int orient
)
2411 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2414 void wxSetPrinterScaling(double x
, double y
)
2416 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2419 void wxSetPrinterTranslation(wxCoord x
, wxCoord y
)
2421 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2424 // 1 = Preview, 2 = print to file, 3 = send to printer
2425 void wxSetPrinterMode(int mode
)
2427 wxThePrintSetupData
->SetPrinterMode(mode
);
2430 void wxSetAFMPath(const wxString
& f
)
2432 wxThePrintSetupData
->SetAFMPath(f
);
2435 // Get current values
2436 wxString
wxGetPrinterCommand()
2438 return wxThePrintSetupData
->GetPrinterCommand();
2441 wxString
wxGetPrintPreviewCommand()
2443 return wxThePrintSetupData
->GetPrintPreviewCommand();
2446 wxString
wxGetPrinterOptions()
2448 return wxThePrintSetupData
->GetPrinterOptions();
2451 wxString
wxGetPrinterFile()
2453 return wxThePrintSetupData
->GetPrinterFile();
2456 int wxGetPrinterOrientation()
2458 return wxThePrintSetupData
->GetPrinterOrientation();
2461 void wxGetPrinterScaling(double* x
, double* y
)
2463 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2466 void wxGetPrinterTranslation(wxCoord
*x
, wxCoord
*y
)
2468 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2471 int wxGetPrinterMode()
2473 return wxThePrintSetupData
->GetPrinterMode();
2476 wxString
wxGetAFMPath()
2478 return wxThePrintSetupData
->GetAFMPath();
2485 wxPrintSetupData::wxPrintSetupData()
2487 m_printerOrient
= wxPORTRAIT
;
2488 m_printerScaleX
= (double)1.0;
2489 m_printerScaleY
= (double)1.0;
2490 m_printerTranslateX
= 0;
2491 m_printerTranslateY
= 0;
2492 m_printerMode
= wxPRINT_MODE_FILE
;
2493 m_printColour
= TRUE
;
2496 wxPrintSetupData::~wxPrintSetupData()
2500 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2502 SetPrinterCommand(data
.GetPrinterCommand());
2503 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2504 SetPrinterOptions(data
.GetPrinterOptions());
2506 data
.GetPrinterTranslation(&x
, &y
);
2507 SetPrinterTranslation(x
, y
);
2510 data
.GetPrinterScaling(&x1
, &y1
);
2511 SetPrinterScaling(x1
, y1
);
2513 SetPrinterOrientation(data
.GetPrinterOrientation());
2514 SetPrinterMode(data
.GetPrinterMode());
2515 SetAFMPath(data
.GetAFMPath());
2516 SetPaperName(data
.GetPaperName());
2517 SetColour(data
.GetColour());
2520 // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData).
2521 void wxPrintSetupData::operator=(const wxPrintData
& data
)
2523 SetPrinterCommand(data
.GetPrinterCommand());
2524 SetPrintPreviewCommand(data
.GetPreviewCommand());
2525 SetPrinterOptions(data
.GetPrinterOptions());
2526 SetPrinterTranslation((wxCoord
)data
.GetPrinterTranslateX(),
2527 (wxCoord
)data
.GetPrinterTranslateY());
2528 SetPrinterScaling(data
.GetPrinterScaleX(), data
.GetPrinterScaleY());
2529 SetPrinterOrientation(data
.GetOrientation());
2530 SetPrinterMode((int) data
.GetPrintMode());
2531 SetAFMPath(data
.GetFontMetricPath());
2532 SetPaperName(wxThePrintPaperDatabase
->ConvertIdToName(data
.GetPaperId()));
2533 SetColour(data
.GetColour());
2534 SetPrinterFile(data
.GetFilename());
2537 void wxInitializePrintSetupData(bool init
)
2541 wxThePrintSetupData
= new wxPrintSetupData
;
2543 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2544 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
2545 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_PREVIEW
);
2546 wxThePrintSetupData
->SetPaperName(_("A4 sheet, 210 x 297 mm"));
2548 // Could have a .ini file to read in some defaults
2549 // - and/or use environment variables, e.g. WXWIN
2551 wxThePrintSetupData
->SetPrinterCommand("print");
2552 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2553 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2556 wxThePrintSetupData
->SetPrinterCommand("print");
2557 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2558 wxThePrintSetupData
->SetPrinterOptions("");
2560 #if !defined(__VMS__) && !defined(__WXMSW__)
2561 wxThePrintSetupData
->SetPrinterCommand("lpr");
2562 wxThePrintSetupData
->SetPrinterOptions("");
2563 wxThePrintSetupData
->SetAFMPath("");
2568 if (wxThePrintSetupData
)
2569 delete wxThePrintSetupData
;
2570 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2574 // A module to allow initialization/cleanup of PostScript-related
2575 // things without calling these functions from app.cpp.
2577 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2579 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2581 wxPostScriptModule() {}
2586 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2589 * Initialization/cleanup module
2592 bool wxPostScriptModule::OnInit()
2594 wxInitializePrintSetupData();
2599 void wxPostScriptModule::OnExit()
2601 wxInitializePrintSetupData(FALSE
);
2608 // wxUSE_PRINTING_ARCHITECTURE