1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 #include "wx/wxprec.h"
28 #if wxUSE_PRINTING_ARCHITECTURE
32 #include "wx/window.h"
33 #include "wx/dcmemory.h"
36 #include "wx/filedlg.h"
38 #include "wx/msgdlg.h"
41 #include "wx/generic/dcpsg.h"
42 #include "wx/generic/prntdlgg.h"
43 #include "wx/button.h"
44 #include "wx/stattext.h"
45 #include "wx/radiobox.h"
46 #include "wx/textctrl.h"
47 #include "wx/prntbase.h"
49 #include "wx/filefn.h"
73 //-----------------------------------------------------------------------------
74 // start and end of document/page
75 //-----------------------------------------------------------------------------
77 static const char *wxPostScriptHeaderEllipse
= "\
78 /ellipsedict 8 dict def\n\
79 ellipsedict /mtrx matrix put\n\
83 /startangle exch def\n\
88 /savematrix mtrx currentmatrix def\n\
91 0 0 1 startangle endangle arc\n\
92 savematrix setmatrix\n\
97 static const char *wxPostScriptHeaderEllipticArc
= "\
98 /ellipticarcdict 8 dict def\n\
99 ellipticarcdict /mtrx matrix put\n\
101 { ellipticarcdict begin\n\
103 /endangle exch def\n\
104 /startangle exch def\n\
109 /savematrix mtrx currentmatrix def\n\
112 do_fill { 0 0 moveto } if\n\
113 0 0 1 startangle endangle arc\n\
114 savematrix setmatrix\n\
115 do_fill { fill }{ stroke } ifelse\n\
119 static const char *wxPostScriptHeaderSpline
= "\
120 /DrawSplineSection {\n\
127 /xa x1 x2 x1 sub 0.666667 mul add def\n\
128 /ya y1 y2 y1 sub 0.666667 mul add def\n\
129 /xb x3 x2 x3 sub 0.666667 mul add def\n\
130 /yb y3 y2 y3 sub 0.666667 mul add def\n\
132 xa ya xb yb x3 y3 curveto\n\
136 static const char *wxPostScriptHeaderColourImage
= "\
137 %% define 'colorimage' if it isn't defined\n\
138 %% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
140 /colorimage where %% do we know about 'colorimage'?\n\
141 { pop } %% yes: pop off the 'dict' returned\n\
142 { %% no: define one\n\
143 /colortogray { %% define an RGB->I function\n\
144 /rgbdata exch store %% call input 'rgbdata'\n\
145 rgbdata length 3 idiv\n\
146 /npixls exch store\n\
148 0 1 npixls 1 sub {\n\
150 rgbdata rgbindx get 20 mul %% Red\n\
151 rgbdata rgbindx 1 add get 32 mul %% Green\n\
152 rgbdata rgbindx 2 add get 12 mul %% Blue\n\
153 add add 64 idiv %% I = .5G + .31R + .18B\n\
155 /rgbindx rgbindx 3 add store\n\
157 grays 0 npixls getinterval\n\
160 %% Utility procedure for colorimage operator.\n\
161 %% This procedure takes two procedures off the\n\
162 %% stack and merges them into a single procedure.\n\
164 /mergeprocs { %% def\n\
183 /colorimage { %% def\n\
184 pop pop %% remove 'false 3' operands\n\
185 {colortogray} mergeprocs\n\
188 } ifelse %% end of 'false' case\n\
191 static char wxPostScriptHeaderReencodeISO1
[] =
193 "dup dup findfont dup length dict begin\n"
194 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
195 "/Encoding ISOLatin1Encoding def\n"
196 "currentdict end definefont\n"
198 "/ISOLatin1Encoding [\n"
199 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
200 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
201 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
202 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
203 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
204 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
205 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
206 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
207 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
208 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
209 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
210 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
211 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
212 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
213 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
215 static char wxPostScriptHeaderReencodeISO2
[] =
216 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
217 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
218 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
219 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
220 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
221 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
222 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
223 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
224 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
225 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
226 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
227 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
228 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
229 "/yacute/thorn/ydieresis\n"
232 //-------------------------------------------------------------------------------
234 //-------------------------------------------------------------------------------
236 wxPostScriptDC::wxPostScriptDC ()
238 m_pstream
= (FILE*) NULL
;
248 m_underlinePosition
= 0.0;
249 m_underlineThickness
= 0.0;
251 m_signX
= 1; // default x-axis left to right
252 m_signY
= -1; // default y-axis bottom up -> top down
254 // Compatibility only
255 // HH: Doesn't seem to work for wxMSW...
257 m_printData
= * wxThePrintSetupData
;
261 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
263 m_pstream
= (FILE*) NULL
;
273 m_underlinePosition
= 0.0;
274 m_underlineThickness
= 0.0;
276 m_signX
= 1; // default x-axis left to right
277 m_signY
= -1; // default y-axis bottom up -> top down
279 Create(file
, interactive
, parent
);
282 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
284 m_isInteractive
= interactive
;
287 m_printData
.SetFilename(file
);
290 // Can only send to file in Windows
291 m_printData
.SetPrintMode(wxPRINT_MODE_FILE
);
296 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
306 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
308 m_pstream
= (FILE*) NULL
;
318 m_underlinePosition
= 0.0;
319 m_underlineThickness
= 0.0;
321 m_signX
= 1; // default x-axis left to right
322 m_signY
= -1; // default y-axis bottom up -> top down
324 m_printData
= printData
;
329 wxPostScriptDC::~wxPostScriptDC ()
334 m_pstream
= (FILE*) NULL
;
338 bool wxPostScriptDC::Ok() const
343 // This dialog is deprecated now: use wxGenericPrintDialog or the printing framework
344 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
346 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
347 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
348 m_ok
= (dialog
.ShowModal () == wxID_OK
);
350 if (!m_ok
) return FALSE
;
352 if ((m_printData
.GetFilename() == "") &&
353 (m_printData
.GetPrintMode() == wxPRINT_MODE_PREVIEW
||
354 m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
358 m_printData
.SetFilename("preview");
360 // For PS_PRINTER action this depends on a Unix-style print spooler
361 // since the wx_printer_file can be destroyed during a session
362 // @@@ TODO: a Windows-style answer for non-Unix
364 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
366 wxStrcpy (tmp
, wxT("/tmp/preview_"));
367 wxStrcat (tmp
, userId
);
368 m_printData
.SetFilename(tmp
);
371 wxStrcpy(tmp2
, m_printData
.GetFilename());
372 wxStrcat (tmp2
, wxT(".ps"));
373 m_printData
.SetFilename(tmp2
);
375 else if ((m_printData
.GetFilename() == wxT("")) && (m_printData
.GetPrintMode() == wxPRINT_MODE_FILE
))
377 wxString file
= wxSaveFileSelector (_("PostScript"), wxT("ps"));
378 if ( file
.IsEmpty() )
384 m_printData
.SetFilename(file
);
391 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
393 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
395 if (m_clipping
) DestroyClippingRegion();
397 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
406 "closepath clip newpath\n",
407 XLOG2DEV(x
), YLOG2DEV(y
),
408 XLOG2DEV(x
+w
), YLOG2DEV(y
),
409 XLOG2DEV(x
+w
), YLOG2DEV(y
+h
),
410 XLOG2DEV(x
), YLOG2DEV(y
+h
) );
414 void wxPostScriptDC::DestroyClippingRegion()
416 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
421 fprintf( m_pstream
, "grestore\n" );
424 wxDC::DestroyClippingRegion();
427 void wxPostScriptDC::Clear()
429 wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
432 void wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
434 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
437 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
439 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
443 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
445 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
448 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
450 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
452 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
461 XLOG2DEV(x1
), YLOG2DEV(y1
),
462 XLOG2DEV(x2
), YLOG2DEV (y2
) );
464 CalcBoundingBox( x1
, y1
);
465 CalcBoundingBox( x2
, y2
);
468 #define RAD2DEG 57.29577951308
470 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
472 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
474 wxCoord dx
= x1
- xc
;
475 wxCoord dy
= y1
- yc
;
476 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
477 double alpha1
, alpha2
;
479 if (x1
== x2
&& y1
== y2
)
484 else if (radius
== 0.0)
486 alpha1
= alpha2
= 0.0;
490 alpha1
= (x1
- xc
== 0) ?
491 (y1
- yc
< 0) ? 90.0 : -90.0 :
492 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
493 alpha2
= (x2
- xc
== 0) ?
494 (y2
- yc
< 0) ? 90.0 : -90.0 :
495 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
497 while (alpha1
<= 0) alpha1
+= 360;
498 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
499 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
500 while (alpha2
> 360) alpha2
-= 360;
502 if (m_brush
.GetStyle() != wxTRANSPARENT
)
508 "%d %d %d %d %d %d ellipse\n"
512 XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL(radius
), YLOG2DEVREL(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
513 XLOG2DEV(xc
), YLOG2DEV(yc
) );
515 CalcBoundingBox( xc
-radius
, yc
-radius
);
516 CalcBoundingBox( xc
+radius
, yc
+radius
);
519 if (m_pen
.GetStyle() != wxTRANSPARENT
)
525 "%d %d %d %d %d %d ellipse\n"
529 XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL(radius
), YLOG2DEVREL(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
530 XLOG2DEV(xc
), YLOG2DEV(yc
) );
532 CalcBoundingBox( xc
-radius
, yc
-radius
);
533 CalcBoundingBox( xc
+radius
, yc
+radius
);
537 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
539 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
541 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
542 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
548 DrawEllipse(x
,y
,w
,h
);
552 if (m_brush
.GetStyle () != wxTRANSPARENT
)
558 "%d %d %d %d %d %d true ellipticarc\n",
559 XLOG2DEV(x
+w
/2), YLOG2DEV(y
+h
/2), XLOG2DEVREL(w
/2), YLOG2DEVREL(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
561 CalcBoundingBox( x
,y
);
562 CalcBoundingBox( x
+w
, y
+h
);
565 if (m_pen
.GetStyle () != wxTRANSPARENT
)
571 "%d %d %d %d %d %d false ellipticarc\n",
572 XLOG2DEV(x
+w
/2), YLOG2DEV(y
+h
/2), XLOG2DEVREL(w
/2), YLOG2DEVREL(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
574 CalcBoundingBox( x
,y
);
575 CalcBoundingBox( x
+w
, y
+h
);
579 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
581 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
583 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
592 XLOG2DEV(x
), YLOG2DEV(y
),
593 XLOG2DEV(x
+1), YLOG2DEV(y
) );
595 CalcBoundingBox( x
, y
);
598 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
))
600 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
604 if (m_brush
.GetStyle () != wxTRANSPARENT
)
608 fprintf( m_pstream
, "newpath\n" );
610 wxCoord xx
= XLOG2DEV(points
[0].x
+ xoffset
);
611 wxCoord yy
= YLOG2DEV(points
[0].y
+ yoffset
);
613 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
615 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
617 for (int i
= 1; i
< n
; i
++)
619 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
620 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
622 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
624 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
627 fprintf( m_pstream
, "fill\n" );
630 if (m_pen
.GetStyle () != wxTRANSPARENT
)
634 fprintf( m_pstream
, "newpath\n" );
636 wxCoord xx
= XLOG2DEV(points
[0].x
+ xoffset
);
637 wxCoord yy
= YLOG2DEV(points
[0].y
+ yoffset
);
639 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
641 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
643 for (int i
= 1; i
< n
; i
++)
645 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
646 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
648 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
650 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
653 fprintf( m_pstream
, "fill\n" );
657 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
659 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
661 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
668 for ( i
=0; i
<n
; i
++ )
670 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
676 XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
678 for (i
= 1; i
< n
; i
++)
682 XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
685 fprintf( m_pstream
, "stroke\n" );
688 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
690 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
692 if (m_brush
.GetStyle () != wxTRANSPARENT
)
704 XLOG2DEV(x
), YLOG2DEV(y
),
705 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
706 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
707 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
709 CalcBoundingBox( x
, y
);
710 CalcBoundingBox( x
+ width
, y
+ height
);
713 if (m_pen
.GetStyle () != wxTRANSPARENT
)
725 XLOG2DEV(x
), YLOG2DEV(y
),
726 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
727 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
728 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
730 CalcBoundingBox( x
, y
);
731 CalcBoundingBox( x
+ width
, y
+ height
);
735 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
737 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
741 // Now, a negative radius is interpreted to mean
742 // 'the proportion of the smallest X or Y dimension'
743 double smallest
= 0.0;
748 radius
= (-radius
* smallest
);
751 wxCoord rad
= (wxCoord
) radius
;
753 if (m_brush
.GetStyle () != wxTRANSPARENT
)
757 /* Draw rectangle anticlockwise */
760 "%d %d %d 90 180 arc\n"
762 "%d %d %d 180 270 arc\n"
764 "%d %d %d 270 0 arc\n"
766 "%d %d %d 0 90 arc\n"
770 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
771 XLOG2DEV(x
), YLOG2DEV(y
+ rad
),
772 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
773 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
774 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
775 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
776 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
777 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
779 CalcBoundingBox( x
, y
);
780 CalcBoundingBox( x
+ width
, y
+ height
);
783 if (m_pen
.GetStyle () != wxTRANSPARENT
)
787 /* Draw rectangle anticlockwise */
790 "%d %d %d 90 180 arc\n"
792 "%d %d %d 180 270 arc\n"
794 "%d %d %d 270 0 arc\n"
796 "%d %d %d 0 90 arc\n"
800 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
801 XLOG2DEV(x
), YLOG2DEV(y
+ rad
),
802 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
803 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
804 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
805 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
806 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
807 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
809 CalcBoundingBox( x
, y
);
810 CalcBoundingBox( x
+ width
, y
+ height
);
814 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
816 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
818 if (m_brush
.GetStyle () != wxTRANSPARENT
)
824 "%d %d %d %d 0 360 ellipse\n"
826 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
827 XLOG2DEV(width
/ 2), YLOG2DEVREL(height
/ 2) );
829 CalcBoundingBox( x
- width
, y
- height
);
830 CalcBoundingBox( x
+ width
, y
+ height
);
833 if (m_pen
.GetStyle () != wxTRANSPARENT
)
839 "%d %d %d %d 0 360 ellipse\n"
841 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
842 XLOG2DEV(width
/ 2), YLOG2DEVREL(height
/ 2) );
844 CalcBoundingBox( x
- width
, y
- height
);
845 CalcBoundingBox( x
+ width
, y
+ height
);
849 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
851 DrawBitmap( icon
, x
, y
, TRUE
);
854 /* this has to be char, not wxChar */
855 static char hexArray
[] = "0123456789ABCDEF";
856 static void LocalDecToHex( int dec
, char *buf
)
858 int firstDigit
= (int)(dec
/16.0);
859 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
860 buf
[0] = hexArray
[firstDigit
];
861 buf
[1] = hexArray
[secondDigit
];
865 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
867 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
869 if (!bitmap
.Ok()) return;
871 wxImage
image( bitmap
);
873 if (!image
.Ok()) return;
875 wxCoord ww
= XLOG2DEVREL(image
.GetWidth());
876 wxCoord hh
= YLOG2DEVREL(image
.GetHeight());
878 image
= image
.Scale( ww
, hh
);
880 if (!image
.Ok()) return;
882 wxCoord xx
= XLOG2DEV(x
);
883 wxCoord yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
886 "/origstate save def\n"
888 "/pix %d string def\n"
889 "/grays %d string def\n"
896 "{currentfile pix readhexstring pop}\n"
897 "false 3 colorimage\n",
898 ww
, ww
, xx
, yy
, ww
, hh
, ww
, hh
, ww
, -hh
, hh
);
900 for (int j
= 0; j
< hh
; j
++)
902 for (int i
= 0; i
< ww
; i
++)
905 LocalDecToHex( image
.GetRed(i
,j
), buffer
);
906 fprintf( m_pstream
, buffer
);
907 LocalDecToHex( image
.GetGreen(i
,j
), buffer
);
908 fprintf( m_pstream
, buffer
);
909 LocalDecToHex( image
.GetBlue(i
,j
), buffer
);
910 fprintf( m_pstream
, buffer
);
912 fprintf( m_pstream
, "\n" );
915 fprintf( m_pstream
, "end\n" );
916 fprintf( m_pstream
, "origstate restore\n" );
919 void wxPostScriptDC::SetFont( const wxFont
& font
)
921 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
923 if (!font
.Ok()) return;
928 const char *style
= "";
929 int Style
= m_font
.GetStyle();
930 int Weight
= m_font
.GetWeight();
932 switch (m_font
.GetFamily())
942 // name = "/Times-Roman";
943 name
= "/Times"; // Altered by EDZ
946 name
= "/Zapf-Chancery-MediumItalic";
951 case wxDEFAULT
: // Sans Serif Font
952 name
= "/LucidaSans";
955 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
957 if (m_font
.GetFamily () == wxROMAN
)
962 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
966 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
968 if (m_font
.GetFamily () == wxROMAN
)
973 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
975 if (m_font
.GetFamily () == wxROMAN
)
976 style
= "-BoldItalic";
978 style
= "-BoldOblique";
980 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
982 if (m_font
.GetFamily () == wxROMAN
)
987 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
989 if (m_font
.GetFamily () == wxROMAN
)
990 style
= "-BoldItalic";
992 style
= "-BoldOblique";
1000 strcpy( buffer
, name
);
1001 strcat( buffer
, style
);
1003 fprintf( m_pstream
, buffer
);
1004 fprintf( m_pstream
, " reencodeISO def\n" );
1005 fprintf( m_pstream
, buffer
);
1006 fprintf( m_pstream
, " findfont\n" );
1008 sprintf( buffer
, "%f scalefont setfont\n", YLOG2DEVREL(m_font
.GetPointSize() * 1000) / 1000.0F
);
1009 for (int i
= 0; i
< 100; i
++)
1010 if (buffer
[i
] == ',') buffer
[i
] = '.';
1011 fprintf( m_pstream
, buffer
);
1012 // this is a hack - we must scale font size (in pts) according to m_scaleY but
1013 // YLOG2DEVREL works with wxCoord type (int or longint). Se we first convert font size
1014 // to 1/1000th of pt and then back.
1017 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1019 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1021 if (!pen
.Ok()) return;
1023 int oldStyle
= m_pen
.GetStyle();
1030 sprintf( buffer
, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen
.GetWidth()) / 1000.0f
);
1032 sprintf( buffer
, "%f setlinewidth\n", XLOG2DEVREL(1000 * m_pen
.GetWidth()) / 1000.0f
);
1034 for (int i
= 0; i
< 100; i
++)
1035 if (buffer
[i
] == ',') buffer
[i
] = '.';
1036 fprintf( m_pstream
, buffer
);
1040 Line style - WRONG: 2nd arg is OFFSET
1042 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1043 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1044 ter is not number of values in the array of the first one, but an offset
1045 into this description of the pattern. I mean a real *offset* not index
1046 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1047 will be first black line *2* units wxCoord, then space 4 units, then the
1048 pattern of *3* units black, 4 units space will be repeated.
1051 static const char *dotted
= "[2 5] 2";
1052 static const char *short_dashed
= "[4 4] 2";
1053 static const char *wxCoord_dashed
= "[4 8] 2";
1054 static const char *dotted_dashed
= "[6 6 2 6] 4";
1056 const char *psdash
= (char *) NULL
;
1057 switch (m_pen
.GetStyle())
1059 case wxDOT
: psdash
= dotted
; break;
1060 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1061 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1062 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1065 default: psdash
= "[] 0"; break;
1068 if (oldStyle
!= m_pen
.GetStyle())
1070 fprintf( m_pstream
, psdash
);
1071 fprintf( m_pstream
," setdash\n" );
1075 unsigned char red
= m_pen
.GetColour().Red();
1076 unsigned char blue
= m_pen
.GetColour().Blue();
1077 unsigned char green
= m_pen
.GetColour().Green();
1081 // Anything not white is black
1082 if (! (red
== (unsigned char) 255 &&
1083 blue
== (unsigned char) 255 &&
1084 green
== (unsigned char) 255) )
1086 red
= (unsigned char) 0;
1087 green
= (unsigned char) 0;
1088 blue
= (unsigned char) 0;
1093 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1095 double redPS
= (double)(red
) / 255.0;
1096 double bluePS
= (double)(blue
) / 255.0;
1097 double greenPS
= (double)(green
) / 255.0;
1101 "%.8f %.8f %.8f setrgbcolor\n",
1102 redPS
, greenPS
, bluePS
);
1103 for (int i
= 0; i
< 100; i
++)
1104 if (buffer
[i
] == ',') buffer
[i
] = '.';
1105 fprintf( m_pstream
, buffer
);
1108 m_currentBlue
= blue
;
1109 m_currentGreen
= green
;
1113 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1115 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1117 if (!brush
.Ok()) return;
1122 unsigned char red
= m_brush
.GetColour().Red();
1123 unsigned char blue
= m_brush
.GetColour().Blue();
1124 unsigned char green
= m_brush
.GetColour().Green();
1128 // Anything not white is black
1129 if (! (red
== (unsigned char) 255 &&
1130 blue
== (unsigned char) 255 &&
1131 green
== (unsigned char) 255) )
1133 red
= (unsigned char) 0;
1134 green
= (unsigned char) 0;
1135 blue
= (unsigned char) 0;
1140 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1142 double redPS
= (double)(red
) / 255.0;
1143 double bluePS
= (double)(blue
) / 255.0;
1144 double greenPS
= (double)(green
) / 255.0;
1148 "%.8f %.8f %.8f setrgbcolor\n",
1149 redPS
, greenPS
, bluePS
);
1150 for (int i
= 0; i
< 100; i
++)
1151 if (buffer
[i
] == ',') buffer
[i
] = '.';
1152 fprintf( m_pstream
, buffer
);
1155 m_currentBlue
= blue
;
1156 m_currentGreen
= green
;
1160 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1162 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1164 wxCoord text_w
, text_h
, text_descent
;
1166 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1170 if (m_textForegroundColour
.Ok())
1172 unsigned char red
= m_textForegroundColour
.Red();
1173 unsigned char blue
= m_textForegroundColour
.Blue();
1174 unsigned char green
= m_textForegroundColour
.Green();
1178 // Anything not white is black
1179 if (! (red
== (unsigned char) 255 &&
1180 blue
== (unsigned char) 255 &&
1181 green
== (unsigned char) 255))
1183 red
= (unsigned char) 0;
1184 green
= (unsigned char) 0;
1185 blue
= (unsigned char) 0;
1189 // maybe setgray here ?
1190 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1192 double redPS
= (double)(red
) / 255.0;
1193 double bluePS
= (double)(blue
) / 255.0;
1194 double greenPS
= (double)(green
) / 255.0;
1198 "%.8f %.8f %.8f setrgbcolor\n",
1199 redPS
, greenPS
, bluePS
);
1200 for (int i
= 0; i
< 100; i
++)
1201 if (buffer
[i
] == ',') buffer
[i
] = '.';
1202 fprintf( m_pstream
, buffer
);
1205 m_currentBlue
= blue
;
1206 m_currentGreen
= green
;
1210 int size
= m_font
.GetPointSize();
1212 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1213 // commented by V. Slavik and replaced by accurate version
1214 // - note that there is still rounding error in text_descent!
1215 wxCoord by
= y
+ size
- text_descent
; // baseline
1216 fprintf( m_pstream
, "%d %d moveto\n", XLOG2DEV(x
), YLOG2DEV(by
) );
1218 /* I don't know how to write char to a stream, so I use a mini string */
1222 fprintf( m_pstream
, "(" );
1223 const wxWX2MBbuf textbuf
= text
.mb_str();
1224 int len
= strlen(textbuf
);
1226 for (i
= 0; i
< len
; i
++)
1228 int c
= (unsigned char) textbuf
[i
];
1229 if (c
== ')' || c
== '(' || c
== '\\')
1231 /* Cope with special characters */
1232 fprintf( m_pstream
, "\\" );
1233 tmpbuf
[0] = (char) c
;
1234 fprintf( m_pstream
, tmpbuf
);
1236 else if ( c
>= 128 )
1238 /* Cope with character codes > 127 */
1239 fprintf(m_pstream
, "\\%o", c
);
1243 tmpbuf
[0] = (char) c
;
1244 fprintf( m_pstream
, tmpbuf
);
1248 fprintf( m_pstream
, ") show\n" );
1250 if (m_font
.GetUnderlined())
1252 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1262 XLOG2DEV(x
), YLOG2DEV(uy
),
1263 m_underlineThickness
,
1264 XLOG2DEV(x
+ text_w
), YLOG2DEV(uy
) );
1265 for (i
= 0; i
< 100; i
++)
1266 if (buffer
[i
] == ',') buffer
[i
] = '.';
1267 fprintf( m_pstream
, buffer
);
1270 CalcBoundingBox( x
, y
);
1271 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1274 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1278 DoDrawText(text
, x
, y
);
1282 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1286 if (m_textForegroundColour
.Ok())
1288 unsigned char red
= m_textForegroundColour
.Red();
1289 unsigned char blue
= m_textForegroundColour
.Blue();
1290 unsigned char green
= m_textForegroundColour
.Green();
1294 // Anything not white is black
1295 if (! (red
== (unsigned char) 255 &&
1296 blue
== (unsigned char) 255 &&
1297 green
== (unsigned char) 255))
1299 red
= (unsigned char) 0;
1300 green
= (unsigned char) 0;
1301 blue
= (unsigned char) 0;
1305 // maybe setgray here ?
1306 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1308 double redPS
= (double)(red
) / 255.0;
1309 double bluePS
= (double)(blue
) / 255.0;
1310 double greenPS
= (double)(green
) / 255.0;
1314 "%.8f %.8f %.8f setrgbcolor\n",
1315 redPS
, greenPS
, bluePS
);
1316 for (int i
= 0; i
< 100; i
++)
1317 if (buffer
[i
] == ',') buffer
[i
] = '.';
1318 fprintf( m_pstream
, buffer
);
1321 m_currentBlue
= blue
;
1322 m_currentGreen
= green
;
1326 int size
= m_font
.GetPointSize();
1328 long by
= y
+ (long)floor( double(size
) * 2.0 / 3.0 ); // approximate baseline
1330 // FIXME only correct for 90 degrees
1331 fprintf(m_pstream
, "%d %d moveto\n",
1332 XLOG2DEV((wxCoord
)(x
+ size
)), YLOG2DEV(by
) );
1335 sprintf(buffer
, "%.8f rotate\n", angle
);
1337 for (i
= 0; i
< 100; i
++)
1338 if (buffer
[i
] == ',') buffer
[i
] = '.';
1339 fprintf(m_pstream
, buffer
);
1341 /* I don't know how to write char to a stream, so I use a mini string */
1345 fprintf( m_pstream
, "(" );
1346 const wxWX2MBbuf textbuf
= text
.mb_str();
1347 int len
= strlen(textbuf
);
1348 for (i
= 0; i
< len
; i
++)
1350 int c
= (unsigned char) textbuf
[i
];
1351 if (c
== ')' || c
== '(' || c
== '\\')
1353 /* Cope with special characters */
1354 fprintf( m_pstream
, "\\" );
1355 tmpbuf
[0] = (char) c
;
1356 fprintf( m_pstream
, tmpbuf
);
1358 else if ( c
>= 128 )
1360 /* Cope with character codes > 127 */
1361 fprintf(m_pstream
, "\\%o", c
);
1365 tmpbuf
[0] = (char) c
;
1366 fprintf( m_pstream
, tmpbuf
);
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 XLOG2DEV(x
), YLOG2DEV(uy
),
1392 m_underlineThickness
,
1393 XLOG2DEV(x
+ w
), YLOG2DEV(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 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1439 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((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 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1460 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1461 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((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 XLOG2DEV((wxCoord
)c
), YLOG2DEV((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
= w
;
1533 if (height
) *height
= h
;
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(72, 72);
1570 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1572 wxCHECK_MSG( m_ok
, FALSE
, wxT("invalid postscript dc") );
1574 if (m_printData
.GetFilename() == "")
1576 wxString filename
= wxGetTempFileName("ps");
1577 m_printData
.SetFilename(filename
);
1580 m_pstream
= fopen( m_printData
.GetFilename().fn_str(), "w+" );
1584 wxLogError( _("Cannot open file for PostScript printing!"));
1591 fprintf( m_pstream
, "%%%%BeginProlog\n" );
1592 fprintf( m_pstream
, wxPostScriptHeaderEllipse
);
1593 fprintf( m_pstream
, wxPostScriptHeaderEllipticArc
);
1594 fprintf( m_pstream
, wxPostScriptHeaderColourImage
);
1595 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO1
);
1596 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO2
);
1597 if (wxPostScriptHeaderSpline
)
1598 fprintf( m_pstream
, wxPostScriptHeaderSpline
);
1599 fprintf( m_pstream
, "%%%%EndProlog\n" );
1601 SetBrush( *wxBLACK_BRUSH
);
1602 SetPen( *wxBLACK_PEN
);
1603 SetBackground( *wxWHITE_BRUSH
);
1604 SetTextForeground( *wxBLACK
);
1606 // set origin according to paper size
1607 SetDeviceOrigin( 0,0 );
1615 void wxPostScriptDC::EndDoc ()
1617 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1622 fprintf( m_pstream
, "grestore\n" );
1625 fclose( m_pstream
);
1626 m_pstream
= (FILE *) NULL
;
1628 wxChar
*header_file
= wxGetTempFileName("ps");
1630 m_pstream
= fopen( wxConvFile
.cWX2MB(header_file
) , "w+" );
1632 fprintf( m_pstream
, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings
1633 fprintf( m_pstream
, "%%%%Title: %s\n", (const char *)m_title
.mb_str() );
1634 fprintf( m_pstream
, "%%%%Creator: %s\n", (const char*)wxConvCurrent
->cWX2MB(wxTheApp
->argv
[0]) );
1635 fprintf( m_pstream
, "%%%%CreationDate: %s\n", (const char *)wxNow().mb_str() );
1638 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1640 fprintf( m_pstream
, "%%%%For: %s ", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );
1641 wxChar userName
[245];
1642 if (wxGetUserName(userName
, sizeof(userName
)))
1643 fprintf( m_pstream
, " (%s)", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userName
) );
1644 fprintf( m_pstream
, "\n" );
1646 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1648 fprintf( m_pstream
, "%%%%For: %s\n", wxMBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) );;
1651 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1653 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1654 double wx_printer_scale_x
, wx_printer_scale_y
;
1656 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1657 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1659 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1660 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1662 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1663 fprintf( m_pstream
, "%%%%Orientation: Landscape\n" );
1665 fprintf( m_pstream
, "%%%%Orientation: Portrait\n" );
1667 // Compute the bounding box. Note that it is in the default user
1668 // coordinate system, thus we have to convert the values.
1669 wxCoord llx
= (wxCoord
) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1670 wxCoord lly
= (wxCoord
) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1671 wxCoord urx
= (wxCoord
) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1672 wxCoord ury
= (wxCoord
) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1674 // If we're landscape, our sense of "x" and "y" is reversed.
1675 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1678 tmp
= llx
; llx
= lly
; lly
= tmp
;
1679 tmp
= urx
; urx
= ury
; ury
= tmp
;
1681 // We need either the two lines that follow, or we need to subtract
1682 // min_x from real_translate_y, which is commented out below.
1683 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1684 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1687 // The Adobe specifications call for integers; we round as to make
1688 // the bounding larger.
1690 "%%%%BoundingBox: %d %d %d %d\n",
1691 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1692 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1693 fprintf( m_pstream
, "%%%%Pages: %d\n", (wxPageNumber
- 1) );
1694 fprintf( m_pstream
, "%%%%EndComments\n\n" );
1696 // To check the correctness of the bounding box, postscript commands
1697 // to draw a box corresponding to the bounding box are generated below.
1698 // But since we typically don't want to print such a box, the postscript
1699 // commands are generated within comments. These lines appear before any
1700 // adjustment of scale, rotation, or translation, and hence are in the
1701 // default user coordinates.
1702 fprintf( m_pstream
, "%% newpath\n" );
1703 fprintf( m_pstream
, "%% %d %d moveto\n", llx
, lly
);
1704 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, lly
);
1705 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, ury
);
1706 fprintf( m_pstream
, "%% %d %d lineto closepath stroke\n", llx
, ury
);
1708 fclose( m_pstream
);
1709 m_pstream
= (FILE*) NULL
;
1711 wxChar
*tmp_file
= wxGetTempFileName("ps");
1713 // Paste header Before wx_printer_file
1714 wxConcatFiles (header_file
, m_printData
.GetFilename(), tmp_file
);
1715 wxRemoveFile( header_file
);
1716 wxRemoveFile( m_printData
.GetFilename() );
1717 wxRenameFile( tmp_file
, m_printData
.GetFilename() );
1719 #if defined(__X__) || defined(__WXGTK__)
1722 wxString
previewCommand(m_printData
.GetPreviewCommand());
1723 wxString
printerCommand(m_printData
.GetPrinterCommand());
1724 wxString
printerOptions(m_printData
.GetPrinterOptions());
1725 wxString
filename(m_printData
.GetFilename());
1727 switch (m_printData
.GetPrintMode())
1729 case wxPRINT_MODE_PREVIEW
:
1732 argv
[0] = WXSTRINGCAST previewCommand
;
1733 argv
[1] = WXSTRINGCAST filename
;
1734 argv
[2] = (wxChar
*) NULL
;
1735 wxExecute( argv
, TRUE
);
1736 wxRemoveFile( m_printData
.GetFilename() );
1739 case wxPRINT_MODE_PRINTER
:
1743 argv
[argc
++] = WXSTRINGCAST printerCommand
;
1745 // !SM! If we simply assign to argv[1] here, if printer options
1746 // are blank, we get an annoying and confusing message from lpr.
1747 wxChar
*opts
= WXSTRINGCAST printerOptions
;
1749 argv
[argc
++] = opts
;
1751 argv
[argc
++] = WXSTRINGCAST filename
;
1752 argv
[argc
++] = (wxChar
*) NULL
;
1753 wxExecute( argv
, TRUE
);
1754 wxRemoveFile( filename
);
1757 case wxPRINT_MODE_FILE
:
1758 case wxPRINT_MODE_NONE
:
1765 void wxPostScriptDC::StartPage()
1767 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1769 fprintf( m_pstream
, "%%%%Page: %d\n", wxPageNumber
++ );
1771 // What is this one supposed to do? RR.
1772 // *m_pstream << "matrix currentmatrix\n";
1774 // Added by Chris Breeze
1776 // Each page starts with an "initgraphics" which resets the
1777 // transformation and so we need to reset the origin
1778 // (and rotate the page for landscape printing)
1781 wxCoord translate_x
, translate_y
;
1782 double scale_x
, scale_y
;
1784 translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1785 translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1787 scale_x
= m_printData
.GetPrinterScaleX();
1788 scale_y
= m_printData
.GetPrinterScaleY();
1790 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1793 GetSize( (int*) NULL
, &h
);
1795 fprintf( m_pstream
, "90 rotate\n" );
1797 // I copied this one from a PostScript tutorial, but to no avail. RR.
1798 // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" );
1802 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
, scale_y
);
1803 for (int i
= 0; i
< 100; i
++)
1804 if (buffer
[i
] == ',') buffer
[i
] = '.';
1805 fprintf( m_pstream
, buffer
);
1807 fprintf( m_pstream
, "%d %d translate\n", translate_x
, translate_y
);
1810 void wxPostScriptDC::EndPage ()
1812 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1814 fprintf( m_pstream
, "showpage\n" );
1817 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1818 wxCoord fwidth
, wxCoord fheight
,
1820 wxCoord xsrc
, wxCoord ysrc
,
1821 int rop
, bool WXUNUSED(useMask
) )
1823 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, wxT("invalid postscript dc") );
1825 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1827 /* blit into a bitmap */
1828 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1830 memDC
.SelectObject(bitmap
);
1831 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1832 memDC
.SelectObject(wxNullBitmap
);
1834 /* draw bitmap. scaling and positioning is done there */
1835 DrawBitmap( bitmap
, xdest
, ydest
);
1840 wxCoord
wxPostScriptDC::GetCharHeight() const
1843 return m_font
.GetPointSize();
1848 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1849 wxCoord
*x
, wxCoord
*y
,
1850 wxCoord
*descent
, wxCoord
*externalLeading
,
1851 wxFont
*theFont
) const
1853 wxFont
*fontToUse
= theFont
;
1855 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1857 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1858 wxCHECK_RET( x
, wxT("GetTextExtent: x == NULL") );
1859 wxCHECK_RET( y
, wxT("GetTextExtent: y == NULL") );
1861 const wxWX2MBbuf strbuf
= string
.mb_str();
1863 #if !wxUSE_AFM_FOR_POSTSCRIPT
1864 /* Provide a VERY rough estimate (avoid using it).
1865 * Produces accurate results for mono-spaced font
1866 * such as Courier (aka wxMODERN) */
1871 height
= fontToUse
->GetPointSize();
1874 *x
= strlen (strbuf
) * height
* 72 / 120;
1876 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
1877 if (descent
) *descent
= 0;
1878 if (externalLeading
) *externalLeading
= 0;
1881 /* method for calculating string widths in postscript:
1882 / read in the AFM (adobe font metrics) file for the
1883 / actual font, parse it and extract the character widths
1884 / and also the descender. this may be improved, but for now
1885 / it works well. the AFM file is only read in if the
1886 / font is changed. this may be chached in the future.
1887 / calls to GetTextExtent with the font unchanged are rather
1890 / for each font and style used there is an AFM file necessary.
1891 / currently i have only files for the roman font family.
1892 / I try to get files for the other ones!
1894 / CAVE: the size of the string is currently always calculated
1895 / in 'points' (1/72 of an inch). this should later on be
1896 / changed to depend on the mapping mode.
1897 / CAVE: the path to the AFM files must be set before calling this
1898 / function. this is usually done by a call like the following:
1899 / wxSetAFMPath("d:\\wxw161\\afm\\");
1903 / wxPostScriptDC dc(NULL, TRUE);
1905 / wxSetAFMPath("d:\\wxw161\\afm\\");
1906 / dc.StartDoc("Test");
1909 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1910 / dc.GetTextExtent("Hallo",&w,&h);
1915 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1917 / updated: 14.05.95 */
1919 /* these static vars are for storing the state between calls */
1920 static int lastFamily
= INT_MIN
;
1921 static int lastSize
= INT_MIN
;
1922 static int lastStyle
= INT_MIN
;
1923 static int lastWeight
= INT_MIN
;
1924 static int lastDescender
= INT_MIN
;
1925 static int lastWidths
[256]; /* widths of the characters */
1927 double UnderlinePosition
= 0.0;
1928 double UnderlineThickness
= 0.0;
1930 /* get actual parameters */
1931 const int Family
= fontToUse
->GetFamily();
1932 const int Size
= fontToUse
->GetPointSize();
1933 const int Style
= fontToUse
->GetStyle();
1934 const int Weight
= fontToUse
->GetWeight();
1936 /* if we have another font, read the font-metrics */
1937 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1939 /* store actual values */
1940 lastFamily
= Family
;
1943 lastWeight
= Weight
;
1945 char *name
= (char*) NULL
;
1951 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO";
1952 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo";
1953 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "CourO";
1959 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO";
1960 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo";
1961 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO";
1962 else name
= "TimesRo";
1967 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO";
1968 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo";
1969 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "HelvO";
1975 /* get the directory of the AFM files */
1976 wxString afmName
= wxEmptyString
;
1977 if (!m_printData
.GetFontMetricPath().IsEmpty())
1979 afmName
= m_printData
.GetFontMetricPath();
1982 /* 2. open and process the file
1983 / a short explanation of the AFM format:
1984 / we have for each character a line, which gives its size
1987 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1989 / that means, we have a character with ascii code 63, and width
1990 / (444/1000 * fontSize) points.
1991 / the other data is ignored for now!
1993 / when the font has changed, we read in the right AFM file and store the
1994 / character widths in an array, which is processed below (see point 3.). */
1996 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
1998 afmName
<< name
<< wxT(".afm");
1999 FILE *afmFile
= wxFopen(afmName
,wxT("r"));
2002 afmName
= wxThePrintSetupData
->GetAFMPath();
2003 afmName
<< wxFILE_SEP_PATH
<< name
<< wxT(".afm");
2004 afmFile
= wxFopen(afmName
,wxT("r"));
2010 /* please do NOT change the line above to "else if (afmFile==NULL)" -
2011 - afmFile = fopen() may fail and in that case the next if branch
2012 MUST be executed - and it would not if there was "else" */
2014 afmName
= wxINSTALL_PREFIX
;
2015 afmName
<< wxFILE_SEP_PATH
2016 << wxT("share") << wxFILE_SEP_PATH
2017 << wxT("wx") << wxFILE_SEP_PATH
2018 << wxT("afm") << wxFILE_SEP_PATH
2019 << name
<< wxT(".afm");
2020 afmFile
= wxFopen(afmName
,wxT("r"));
2027 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%hs'\n"), afmName
.c_str() );
2028 wxLogDebug( wxT(" using approximate values\n"));
2029 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2030 lastDescender
= -150; /* dito. */
2034 /* init the widths array */
2035 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2036 /* some variables for holding parts of a line */
2037 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2038 char upString
[30], utString
[30], encString
[50];
2041 /* read in the file and parse it */
2042 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2044 /* A.) check for descender definition */
2045 if (strncmp(line
,"Descender",9)==0)
2047 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2048 (strcmp(descString
,"Descender")!=0))
2050 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad descender)\n"), afmName
.c_str(),line
);
2053 /* JC 1.) check for UnderlinePosition */
2054 else if(strncmp(line
,"UnderlinePosition",17)==0)
2056 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2057 (strcmp(upString
,"UnderlinePosition")!=0))
2059 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlinePosition)\n"), afmName
.c_str(), line
);
2062 /* JC 2.) check for UnderlineThickness */
2063 else if(strncmp(line
,"UnderlineThickness",18)==0)
2065 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2066 (strcmp(utString
,"UnderlineThickness")!=0))
2068 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlineThickness)\n"), afmName
.c_str(), line
);
2071 /* JC 3.) check for EncodingScheme */
2072 else if(strncmp(line
,"EncodingScheme",14)==0)
2074 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2075 (strcmp(utString
,"EncodingScheme")!=0))
2077 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad EncodingScheme)\n"), afmName
.c_str(), line
);
2079 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2081 wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (unsupported EncodingScheme %hs)\n"),
2082 afmName
.c_str(),line
, encString
);
2085 /* B.) check for char-width */
2086 else if(strncmp(line
,"C ",2)==0)
2088 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2090 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has an error (bad character width)\n"),afmName
.c_str(),line
);
2092 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2094 wxLogDebug(wxT("AFM-file '%hs': line '%hs' has a format error\n"),afmName
.c_str(),line
);
2096 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2097 if (ascii
>=0 && ascii
<256)
2099 lastWidths
[ascii
] = cWidth
; /* store width */
2103 /* MATTHEW: this happens a lot; don't print an error */
2104 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName.c_str(),ascii); */
2107 /* C.) ignore other entries. */
2111 /* hack to compute correct values for german 'Umlaute'
2112 / the correct way would be to map the character names
2113 / like 'adieresis' to corresp. positions of ISOEnc and read
2114 / these values from AFM files, too. Maybe later ... */
2115 lastWidths
[196] = lastWidths
['A']; // Ä
2116 lastWidths
[228] = lastWidths
['a']; // ä
2117 lastWidths
[214] = lastWidths
['O']; // Ö
2118 lastWidths
[246] = lastWidths
['o']; // ö
2119 lastWidths
[220] = lastWidths
['U']; // Ü
2120 lastWidths
[252] = lastWidths
['u']; // ü
2121 lastWidths
[223] = lastWidths
[251]; // ß
2123 /* JC: calculate UnderlineThickness/UnderlinePosition */
2125 // VS: dirty, but is there any better solution?
2127 pt
= (double*) &m_underlinePosition
;
2128 *pt
= YLOG2DEVREL(UnderlinePosition
* fontToUse
->GetPointSize()) / 1000.0f
;
2129 pt
= (double*) &m_underlineThickness
;
2130 *pt
= YLOG2DEVREL(UnderlineThickness
* fontToUse
->GetPointSize()) / 1000.0f
;
2135 /* 3. now the font metrics are read in, calc size this
2136 / is done by adding the widths of the characters in the
2137 / string. they are given in 1/1000 of the size! */
2140 wxCoord height
=Size
; /* by default */
2142 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2144 if(lastWidths
[*p
]== INT_MIN
)
2146 wxLogDebug(wxT("GetTextExtent: undefined width for character '%hc' (%d)\n"), *p
,*p
);
2147 widthSum
+= (lastWidths
[' ']/1000.0F
* Size
); /* assume space */
2151 widthSum
+= ((lastWidths
[*p
]/1000.0F
)*Size
);
2155 /* add descender to height (it is usually a negative value) */
2156 //if (lastDescender != INT_MIN)
2158 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2160 // - commented by V. Slavik - height already contains descender in it
2161 // (judging from few experiments)
2163 /* return size values */
2165 *x
= (wxCoord
)widthSum
;
2169 /* return other parameters */
2172 if(lastDescender
!=INT_MIN
)
2174 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2182 /* currently no idea how to calculate this! */
2183 if (externalLeading
) *externalLeading
= 0;
2188 // Determine the Default Postscript Previewer
2189 // available on the platform
2190 #if defined(__SUN__) && defined(__XVIEW__)
2191 // OpenWindow/NeWS's Postscript Previewer
2192 # define PS_VIEWER_PROG "pageview"
2193 #elif defined(__VMS__)
2194 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
2195 #elif defined(__SGI__)
2196 // SGI's Display Postscript Previewer
2197 //# define PS_VIEWER_PROG "dps"
2198 # define PS_VIEWER_PROG "xpsview"
2199 #elif defined(__X__) || defined(__WXGTK__)
2200 // Front-end to ghostscript
2201 # define PS_VIEWER_PROG "ghostview"
2203 // Windows ghostscript/ghostview
2204 # define PS_VIEWER_PROG "gsview"
2207 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2209 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
2210 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
2212 // Redundant now I think
2214 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2216 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2217 const wxPoint
& pos
, const wxSize
& size
, wxCoord style
):
2218 wxDialog(parent
, -1, title
, pos
, size
, style
)
2220 wxBeginBusyCursor();
2225 *orientation
= new wxString
[2],
2226 *print_modes
= new wxString
[3];
2228 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
2229 double wx_printer_scale_x
, wx_printer_scale_y
;
2231 orientation
[0] = _("Portrait");
2232 orientation
[1] = _("Landscape");
2234 print_modes
[0] = _("Send to Printer");
2235 print_modes
[1] = _("Print to File");
2236 print_modes
[2] = _("Preview Only");
2240 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2241 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2242 okBut
->SetDefault();
2245 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2246 (void) new wxStaticText( this, -1, _("Printer Command: "),
2248 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2249 wxPoint(100, yPos
), wxSize(100, -1) );
2251 (void) new wxStaticText( this, -1, _("Printer Options: "),
2252 wxPoint(210, yPos
) );
2253 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2254 wxPoint(305, yPos
), wxSize(150, -1) );
2260 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2261 2,orientation
,2,wxRA_SPECIFY_ROWS
);
2262 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2264 // @@@ Configuration hook
2265 if ( !wxThePrintSetupData
->GetPrintPreviewCommand() )
2266 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2268 // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand);
2270 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
2271 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2273 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2275 wxSize(-1,-1), features
,
2276 print_modes
, features
, wxRA_SPECIFY_ROWS
);
2279 radio1
->Enable(0, FALSE
);
2280 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2281 radio1
->Enable(2, FALSE
);
2284 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2285 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2286 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2288 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2291 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2292 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2294 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2295 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2296 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2300 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2301 sprintf (buf
, "%.2d", wx_printer_translate_x
);
2302 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2304 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2305 sprintf (buf
, "%.2d", wx_printer_translate_y
);
2306 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2310 delete[] orientation
;
2311 delete[] print_modes
;
2316 int wxPostScriptPrintDialog::ShowModal ()
2318 if ( wxDialog::ShowModal() == wxID_OK
)
2320 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2321 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2322 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2323 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2324 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2325 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2326 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2327 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2329 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->m_printerScaleX
);
2330 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->m_printerScaleY
);
2333 StringToLong (WXSTRINGCAST text3
->GetValue (), &dummy
);
2334 wxThePrintSetupData
->m_printerTranslateX
= (wxCoord
)dummy
;
2335 StringToLong (WXSTRINGCAST text4
->GetValue (), &dummy
);
2336 wxThePrintSetupData
->m_printerTranslateY
= (wxCoord
)dummy
;
2339 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2340 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2343 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? wxLANDSCAPE
: wxPORTRAIT
));
2346 switch ( radio1
->GetSelection() ) {
2347 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2348 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2349 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2358 // PostScript printer settings
2359 // RETAINED FOR BACKWARD COMPATIBILITY
2360 void wxSetPrinterCommand(const wxString
& cmd
)
2362 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2365 void wxSetPrintPreviewCommand(const wxString
& cmd
)
2367 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2370 void wxSetPrinterOptions(const wxString
& flags
)
2372 wxThePrintSetupData
->SetPrinterOptions(flags
);
2375 void wxSetPrinterFile(const wxString
& f
)
2377 wxThePrintSetupData
->SetPrinterFile(f
);
2380 void wxSetPrinterOrientation(int orient
)
2382 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2385 void wxSetPrinterScaling(double x
, double y
)
2387 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2390 void wxSetPrinterTranslation(wxCoord x
, wxCoord y
)
2392 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2395 // 1 = Preview, 2 = print to file, 3 = send to printer
2396 void wxSetPrinterMode(int mode
)
2398 wxThePrintSetupData
->SetPrinterMode(mode
);
2401 void wxSetAFMPath(const wxString
& f
)
2403 wxThePrintSetupData
->SetAFMPath(f
);
2406 // Get current values
2407 wxString
wxGetPrinterCommand()
2409 return wxThePrintSetupData
->GetPrinterCommand();
2412 wxString
wxGetPrintPreviewCommand()
2414 return wxThePrintSetupData
->GetPrintPreviewCommand();
2417 wxString
wxGetPrinterOptions()
2419 return wxThePrintSetupData
->GetPrinterOptions();
2422 wxString
wxGetPrinterFile()
2424 return wxThePrintSetupData
->GetPrinterFile();
2427 int wxGetPrinterOrientation()
2429 return wxThePrintSetupData
->GetPrinterOrientation();
2432 void wxGetPrinterScaling(double* x
, double* y
)
2434 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2437 void wxGetPrinterTranslation(wxCoord
*x
, wxCoord
*y
)
2439 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2442 int wxGetPrinterMode()
2444 return wxThePrintSetupData
->GetPrinterMode();
2447 wxString
wxGetAFMPath()
2449 return wxThePrintSetupData
->GetAFMPath();
2456 wxPrintSetupData::wxPrintSetupData()
2458 m_printerOrient
= wxPORTRAIT
;
2459 m_printerScaleX
= (double)1.0;
2460 m_printerScaleY
= (double)1.0;
2461 m_printerTranslateX
= 0;
2462 m_printerTranslateY
= 0;
2463 m_printerMode
= wxPRINT_MODE_FILE
;
2464 m_printColour
= TRUE
;
2467 wxPrintSetupData::~wxPrintSetupData()
2471 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2473 SetPrinterCommand(data
.GetPrinterCommand());
2474 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2475 SetPrinterOptions(data
.GetPrinterOptions());
2477 data
.GetPrinterTranslation(&x
, &y
);
2478 SetPrinterTranslation(x
, y
);
2481 data
.GetPrinterScaling(&x1
, &y1
);
2482 SetPrinterScaling(x1
, y1
);
2484 SetPrinterOrientation(data
.GetPrinterOrientation());
2485 SetPrinterMode(data
.GetPrinterMode());
2486 SetAFMPath(data
.GetAFMPath());
2487 SetPaperName(data
.GetPaperName());
2488 SetColour(data
.GetColour());
2491 // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData).
2492 void wxPrintSetupData::operator=(const wxPrintData
& data
)
2494 SetPrinterCommand(data
.GetPrinterCommand());
2495 SetPrintPreviewCommand(data
.GetPreviewCommand());
2496 SetPrinterOptions(data
.GetPrinterOptions());
2497 SetPrinterTranslation(data
.GetPrinterTranslateX(), data
.GetPrinterTranslateY());
2498 SetPrinterScaling(data
.GetPrinterScaleX(), data
.GetPrinterScaleY());
2499 SetPrinterOrientation(data
.GetOrientation());
2500 SetPrinterMode((int) data
.GetPrintMode());
2501 SetAFMPath(data
.GetFontMetricPath());
2502 SetPaperName(wxThePrintPaperDatabase
->ConvertIdToName(data
.GetPaperId()));
2503 SetColour(data
.GetColour());
2504 SetPrinterFile(data
.GetFilename());
2507 void wxInitializePrintSetupData(bool init
)
2511 wxThePrintSetupData
= new wxPrintSetupData
;
2513 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2514 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
2515 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_PREVIEW
);
2516 wxThePrintSetupData
->SetPaperName(_("A4 sheet, 210 x 297 mm"));
2518 // Could have a .ini file to read in some defaults
2519 // - and/or use environment variables, e.g. WXWIN
2521 wxThePrintSetupData
->SetPrinterCommand("print");
2522 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2523 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2526 wxThePrintSetupData
->SetPrinterCommand("print");
2527 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2528 wxThePrintSetupData
->SetPrinterOptions("");
2530 #if !defined(__VMS__) && !defined(__WXMSW__)
2531 wxThePrintSetupData
->SetPrinterCommand("lpr");
2532 wxThePrintSetupData
->SetPrinterOptions("");
2533 wxThePrintSetupData
->SetAFMPath("");
2538 if (wxThePrintSetupData
)
2539 delete wxThePrintSetupData
;
2540 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2544 // A module to allow initialization/cleanup of PostScript-related
2545 // things without calling these functions from app.cpp.
2547 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2549 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2551 wxPostScriptModule() {}
2556 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2559 * Initialization/cleanup module
2562 bool wxPostScriptModule::OnInit()
2564 wxInitializePrintSetupData();
2569 void wxPostScriptModule::OnExit()
2571 wxInitializePrintSetupData(FALSE
);
2578 // wxUSE_PRINTING_ARCHITECTURE