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/dcmemory.h"
35 #include "wx/filedlg.h"
37 #include "wx/msgdlg.h"
40 #include "wx/generic/dcpsg.h"
41 #include "wx/generic/prntdlgg.h"
42 #include "wx/button.h"
43 #include "wx/stattext.h"
44 #include "wx/radiobox.h"
45 #include "wx/textctrl.h"
46 #include "wx/prntbase.h"
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 wxPostScriptDC::wxPostScriptDC ()
236 m_pstream
= (ofstream
*) NULL
;
246 m_underlinePosition
= 0.0;
247 m_underlineThickness
= 0.0;
249 m_signX
= 1; // default x-axis left to right
250 m_signY
= -1; // default y-axis bottom up -> top down
252 // Compatibility only
253 m_printData
= * wxThePrintSetupData
;
256 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
258 m_pstream
= (ofstream
*) NULL
;
268 m_underlinePosition
= 0.0;
269 m_underlineThickness
= 0.0;
271 m_signX
= 1; // default x-axis left to right
272 m_signY
= -1; // default y-axis bottom up -> top down
274 Create(file
, interactive
, parent
);
277 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
279 m_isInteractive
= interactive
;
282 m_printData
.SetFilename(file
);
285 // Can only send to file in Windows
286 m_printData
.SetPrintMode(wxPRINT_MODE_FILE
);
291 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
301 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
303 m_pstream
= (ofstream
*) NULL
;
313 m_underlinePosition
= 0.0;
314 m_underlineThickness
= 0.0;
316 m_signX
= 1; // default x-axis left to right
317 m_signY
= -1; // default y-axis bottom up -> top down
319 m_printData
= printData
;
324 wxPostScriptDC::~wxPostScriptDC ()
326 if (m_pstream
) delete m_pstream
;
329 bool wxPostScriptDC::Ok() const
334 // This dialog is deprecated now: use wxGenericPrintDialog or the printing framework
335 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
337 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
338 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
339 m_ok
= (dialog
.ShowModal () == wxID_OK
);
341 if (!m_ok
) return FALSE
;
343 if ((m_printData
.GetFilename() == "") &&
344 (m_printData
.GetPrintMode() == wxPRINT_MODE_PREVIEW
||
345 m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
349 m_printData
.SetFilename("preview");
351 // For PS_PRINTER action this depends on a Unix-style print spooler
352 // since the wx_printer_file can be destroyed during a session
353 // @@@ TODO: a Windows-style answer for non-Unix
355 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
357 wxStrcpy (tmp
, _T("/tmp/preview_"));
358 wxStrcat (tmp
, userId
);
359 m_printData
.SetFilename(tmp
);
362 wxStrcpy(tmp2
, m_printData
.GetFilename());
363 wxStrcat (tmp2
, _T(".ps"));
364 m_printData
.SetFilename(tmp2
);
366 else if ((m_printData
.GetFilename() == _T("")) && (m_printData
.GetPrintMode() == wxPRINT_MODE_FILE
))
368 wxString file
= wxSaveFileSelector (_("PostScript"), _T("ps"));
369 if ( file
.IsEmpty() )
375 m_printData
.SetFilename(file
);
382 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
384 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
386 if (m_clipping
) return;
388 wxDC::SetClippingRegion( x
, y
, w
, h
);
391 *m_pstream
<< "gsave\n"
393 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
394 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
395 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
396 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
397 << "closepath clip newpath\n";
400 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
404 void wxPostScriptDC::DestroyClippingRegion()
406 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
408 wxDC::DestroyClippingRegion();
413 *m_pstream
<< "grestore\n";
417 void wxPostScriptDC::Clear()
419 wxFAIL_MSG( _T("wxPostScriptDC::Clear not implemented.") );
422 void wxPostScriptDC::DoFloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
424 wxFAIL_MSG( _T("wxPostScriptDC::FloodFill not implemented.") );
427 bool wxPostScriptDC::DoGetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
429 wxFAIL_MSG( _T("wxPostScriptDC::GetPixel not implemented.") );
433 void wxPostScriptDC::DoCrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
435 wxFAIL_MSG( _T("wxPostScriptDC::CrossHair not implemented.") );
438 void wxPostScriptDC::DoDrawLine (long x1
, long y1
, long x2
, long y2
)
440 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
442 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
446 *m_pstream
<< "newpath\n"
447 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
448 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
451 CalcBoundingBox( x1
, y1
);
452 CalcBoundingBox( x2
, y2
);
455 #define RAD2DEG 57.29577951308
457 void wxPostScriptDC::DoDrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
459 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
463 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
464 double alpha1
, alpha2
;
466 if (x1
== x2
&& y1
== y2
)
470 } else if (radius
== 0.0)
472 alpha1
= alpha2
= 0.0;
475 alpha1
= (x1
- xc
== 0) ?
476 (y1
- yc
< 0) ? 90.0 : -90.0 :
477 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
478 alpha2
= (x2
- xc
== 0) ?
479 (y2
- yc
< 0) ? 90.0 : -90.0 :
480 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
482 while (alpha1
<= 0) alpha1
+= 360;
483 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
484 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
485 while (alpha2
> 360) alpha2
-= 360;
487 if (m_brush
.GetStyle() != wxTRANSPARENT
)
490 *m_pstream
<< "newpath\n"
491 << XLOG2DEV(xc
) << " "
492 << YLOG2DEV(yc
) << " "
493 << XLOG2DEVREL(radius
) << " "
494 << YLOG2DEVREL(radius
) << " "
496 << alpha2
<< " ellipse\n"
497 << XLOG2DEV(xc
) << " "
498 << YLOG2DEV(yc
) << " lineto\n"
503 if (m_pen
.GetStyle() != wxTRANSPARENT
)
506 *m_pstream
<< "newpath\n"
507 << XLOG2DEV(xc
) << " "
508 << YLOG2DEV(yc
) << " "
509 << XLOG2DEVREL(radius
) << " "
510 << YLOG2DEVREL(radius
) << " "
512 << alpha2
<< " ellipse\n"
516 CalcBoundingBox( xc
-radius
, yc
-radius
);
517 CalcBoundingBox( xc
+radius
, yc
+radius
);
520 void wxPostScriptDC::DoDrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
522 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
524 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
525 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
531 DrawEllipse(x
,y
,w
,h
);
535 if (m_brush
.GetStyle () != wxTRANSPARENT
)
539 *m_pstream
<< "newpath\n"
540 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
541 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
542 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
544 CalcBoundingBox( x
,y
);
545 CalcBoundingBox( x
+w
, y
+h
);
548 if (m_pen
.GetStyle () != wxTRANSPARENT
)
552 *m_pstream
<< "newpath\n"
553 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
554 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
555 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
557 CalcBoundingBox( x
, y
);
558 CalcBoundingBox( x
+w
, y
+h
);
562 void wxPostScriptDC::DoDrawPoint (long x
, long y
)
564 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
566 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
570 *m_pstream
<< "newpath\n"
571 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
572 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
575 CalcBoundingBox( x
, y
);
578 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
580 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
584 if (m_brush
.GetStyle () != wxTRANSPARENT
)
588 *m_pstream
<< "newpath\n";
590 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
591 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
592 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
593 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
595 for (int i
= 1; i
< n
; i
++)
597 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
598 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
599 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
600 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
602 *m_pstream
<< "fill\n";
605 if (m_pen
.GetStyle () != wxTRANSPARENT
)
609 *m_pstream
<< "newpath\n";
611 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
612 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
613 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
614 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
616 for (int i
= 1; i
< n
; i
++)
618 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
619 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
620 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
621 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
624 *m_pstream
<< "stroke\n";
628 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
630 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
632 if (m_pen
.GetStyle() == wxTRANSPARENT
)
640 for ( i
=0; i
<n
; i
++ )
642 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
645 *m_pstream
<< "newpath\n"
646 << XLOG2DEV(points
[0].x
+xoffset
) << " "
647 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
649 for (i
= 1; i
< n
; i
++)
651 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
652 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
655 *m_pstream
<< "stroke\n";
658 void wxPostScriptDC::DoDrawRectangle (long x
, long y
, long width
, long height
)
660 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
662 if (m_brush
.GetStyle () != wxTRANSPARENT
)
666 *m_pstream
<< "newpath\n"
667 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
668 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
669 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
670 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
674 CalcBoundingBox( x
, y
);
675 CalcBoundingBox( x
+ width
, y
+ height
);
678 if (m_pen
.GetStyle () != wxTRANSPARENT
)
682 *m_pstream
<< "newpath\n"
683 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
684 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
685 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
686 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
690 CalcBoundingBox( x
, y
);
691 CalcBoundingBox( x
+ width
, y
+ height
);
695 void wxPostScriptDC::DoDrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
697 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
701 // Now, a negative radius is interpreted to mean
702 // 'the proportion of the smallest X or Y dimension'
703 double smallest
= 0.0;
708 radius
= (-radius
* smallest
);
711 long rad
= (long) radius
;
713 if (m_brush
.GetStyle () != wxTRANSPARENT
)
717 // Draw rectangle anticlockwise
718 *m_pstream
<< "newpath\n"
719 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
720 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
721 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
722 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
723 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
724 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
725 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
726 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
730 CalcBoundingBox( x
, y
);
731 CalcBoundingBox( x
+ width
, y
+ height
);
734 if (m_pen
.GetStyle () != wxTRANSPARENT
)
738 // Draw rectangle anticlockwise
739 *m_pstream
<< "newpath\n"
740 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
741 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
742 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
743 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
744 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
745 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
746 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
747 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
751 CalcBoundingBox( x
, y
);
752 CalcBoundingBox( x
+ width
, y
+ height
);
756 void wxPostScriptDC::DoDrawEllipse (long x
, long y
, long width
, long height
)
758 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
760 if (m_brush
.GetStyle () != wxTRANSPARENT
)
764 *m_pstream
<< "newpath\n"
765 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
766 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
769 CalcBoundingBox( x
- width
, y
- height
);
770 CalcBoundingBox( x
+ width
, y
+ height
);
773 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
777 *m_pstream
<< "newpath\n"
778 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
779 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
782 CalcBoundingBox( x
- width
, y
- height
);
783 CalcBoundingBox( x
+ width
, y
+ height
);
787 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, long x
, long y
)
789 DrawBitmap( icon
, x
, y
, TRUE
);
792 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool WXUNUSED(useMask
) )
794 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
796 if (!bitmap
.Ok()) return;
798 wxImage
image( bitmap
);
800 if (!image
.Ok()) return;
802 int ww
= XLOG2DEVREL(image
.GetWidth());
803 int hh
= YLOG2DEVREL(image
.GetHeight());
805 image
= image
.Scale( ww
, hh
);
807 if (!image
.Ok()) return;
809 int xx
= XLOG2DEV(x
);
810 int yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
812 *m_pstream
<< "/origstate save def\n"
814 << "/pix " << ww
<< " string def\n"
815 << "/grays " << ww
<< " string def\n"
816 << "/npixels 0 def\n"
817 << "/rgbindx 0 def\n"
818 << xx
<< " " << yy
<< " translate\n"
819 << ww
<< " " << hh
<< " scale\n"
820 << ww
<< " " << hh
<< " 8\n"
821 << "[" << ww
<< " 0 0 " << (-hh
) << " 0 " << hh
<< "]\n"
822 << "{currentfile pix readhexstring pop}\n"
823 << "false 3 colorimage\n";
825 for (int j
= 0; j
< hh
; j
++)
827 for (int i
= 0; i
< ww
; i
++)
831 wxDecToHex( image
.GetRed(i
,j
), buffer
);
832 *m_pstream
<< buffer
;
833 wxDecToHex( image
.GetGreen(i
,j
), buffer
);
834 *m_pstream
<< buffer
;
835 wxDecToHex( image
.GetBlue(i
,j
), buffer
);
836 *m_pstream
<< buffer
;
841 *m_pstream
<< "end\n";
842 *m_pstream
<< "origstate restore\n";
846 void wxPostScriptDC::SetFont( const wxFont
& font
)
848 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
850 if (!font
.Ok()) return;
855 const char *style
= "";
856 int Style
= m_font
.GetStyle();
857 int Weight
= m_font
.GetWeight();
859 switch (m_font
.GetFamily ())
869 // name = "/Times-Roman";
870 name
= "/Times"; // Altered by EDZ
873 name
= "/Zapf-Chancery-MediumItalic";
878 case wxDEFAULT
: // Sans Serif Font
879 name
= "/LucidaSans";
882 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
884 if (m_font
.GetFamily () == wxROMAN
)
889 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
893 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
895 if (m_font
.GetFamily () == wxROMAN
)
900 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
902 if (m_font
.GetFamily () == wxROMAN
)
903 style
= "-BoldItalic";
905 style
= "-BoldOblique";
907 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
909 if (m_font
.GetFamily () == wxROMAN
)
914 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
916 if (m_font
.GetFamily () == wxROMAN
)
917 style
= "-BoldItalic";
919 style
= "-BoldOblique";
930 *m_pstream
<< buf
<< " reencodeISO def\n";
931 *m_pstream
<< buf
<< " findfont\n";
932 *m_pstream
<< YLOG2DEVREL(m_font
.GetPointSize()) << " scalefont setfont\n";
935 void wxPostScriptDC::SetPen( const wxPen
& pen
)
937 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
939 if (!pen
.Ok()) return;
941 int oldStyle
= m_pen
.GetStyle();
945 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
948 Line style - WRONG: 2nd arg is OFFSET
950 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
951 operator correctly. You should look-up this in the Red Book: the 2nd parame-
952 ter is not number of values in the array of the first one, but an offset
953 into this description of the pattern. I mean a real *offset* not index
954 into array. I.e. If the command is [3 4] 1 setdash is used, then there
955 will be first black line *2* units long, then space 4 units, then the
956 pattern of *3* units black, 4 units space will be repeated.
959 static const char *dotted
= "[2 5] 2";
960 static const char *short_dashed
= "[4 4] 2";
961 static const char *long_dashed
= "[4 8] 2";
962 static const char *dotted_dashed
= "[6 6 2 6] 4";
964 const char *psdash
= (char *) NULL
;
965 switch (m_pen
.GetStyle ())
967 case wxDOT
: psdash
= dotted
; break;
968 case wxSHORT_DASH
: psdash
= short_dashed
; break;
969 case wxLONG_DASH
: psdash
= long_dashed
; break;
970 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
973 default: psdash
= "[] 0"; break;
976 if (oldStyle
!= m_pen
.GetStyle())
978 *m_pstream
<< psdash
<< " setdash\n";
982 unsigned char red
= m_pen
.GetColour().Red();
983 unsigned char blue
= m_pen
.GetColour().Blue();
984 unsigned char green
= m_pen
.GetColour().Green();
988 // Anything not white is black
989 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
990 && green
== (unsigned char) 255))
992 red
= (unsigned char) 0;
993 green
= (unsigned char) 0;
994 blue
= (unsigned char) 0;
1000 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1002 float redPS
= (float)(red
) / 255.0;
1003 float bluePS
= (float)(blue
) / 255.0;
1004 float greenPS
= (float)(green
) / 255.0;
1005 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1008 m_currentBlue
= blue
;
1009 m_currentGreen
= green
;
1013 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1015 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1017 if (!brush
.Ok()) return;
1022 unsigned char red
= m_brush
.GetColour().Red();
1023 unsigned char blue
= m_brush
.GetColour().Blue();
1024 unsigned char green
= m_brush
.GetColour().Green();
1028 // Anything not black is white
1029 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
1030 && green
== (unsigned char) 0))
1032 red
= (unsigned char) 255;
1033 green
= (unsigned char) 255;
1034 blue
= (unsigned char) 255;
1040 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1042 float redPS
= (float)(red
) / 255.0;
1043 float bluePS
= (float)(blue
) / 255.0;
1044 float greenPS
= (float)(green
) / 255.0;
1045 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1047 m_currentBlue
= blue
;
1048 m_currentGreen
= green
;
1052 void wxPostScriptDC::DoDrawText( const wxString
& text
, long x
, long y
)
1054 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1058 if (m_textForegroundColour
.Ok ())
1060 unsigned char red
= m_textForegroundColour
.Red ();
1061 unsigned char blue
= m_textForegroundColour
.Blue ();
1062 unsigned char green
= m_textForegroundColour
.Green ();
1066 // Anything not white is black
1067 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
1068 && green
== (unsigned char) 255))
1070 red
= (unsigned char) 0;
1071 green
= (unsigned char) 0;
1072 blue
= (unsigned char) 0;
1076 // maybe setgray here ?
1078 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1080 float redPS
= (float)(red
) / 255.0;
1081 float bluePS
= (float)(blue
) / 255.0;
1082 float greenPS
= (float)(green
) / 255.0;
1083 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1086 m_currentBlue
= blue
;
1087 m_currentGreen
= green
;
1091 int size
= m_font
.GetPointSize();
1093 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
1094 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
1097 const wxWX2MBbuf textbuf
= text
.mb_str();
1098 int len
= strlen (textbuf
);
1100 for (i
= 0; i
< len
; i
++)
1102 int c
= (unsigned char) textbuf
[i
];
1103 if ( c
== ')' || c
== '(' || c
== '\\')
1105 *m_pstream
<< "\\" << (char) c
;
1107 else if ( c
>= 128 )
1109 // Cope with character codes > 127
1111 sprintf(tmp
, "\\%o", c
);
1115 *m_pstream
<< (char) c
;
1118 *m_pstream
<< ")" << " show\n";
1120 if (m_font
.GetUnderlined())
1122 long uy
= (long)(y
+ size
- m_underlinePosition
);
1124 GetTextExtent(text
, &w
, &h
);
1126 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
1128 << (long)m_underlineThickness
<< " setlinewidth "
1129 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
1130 << " lineto stroke grestore\n";
1133 CalcBoundingBox( x
, y
);
1134 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1138 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1140 m_backgroundBrush
= brush
;
1143 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1145 wxFAIL_MSG( _T("wxPostScriptDC::SetLogicalFunction not implemented.") );
1148 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1150 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1154 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1157 wxNode
*node
= points
->First();
1158 p
= (wxPoint
*)node
->Data();
1162 node
= node
->Next();
1163 p
= (wxPoint
*)node
->Data();
1166 x3
= a
= (double)(x1
+ c
) / 2;
1167 y3
= b
= (double)(y1
+ d
) / 2;
1169 *m_pstream
<< "newpath "
1170 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
1171 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
1173 CalcBoundingBox( (long)x1
, (long)y1
);
1174 CalcBoundingBox( (long)x3
, (long)y3
);
1176 while ((node
= node
->Next()) != NULL
)
1178 q
= (wxPoint
*)node
->Data();
1186 x3
= (double)(x2
+ c
) / 2;
1187 y3
= (double)(y2
+ d
) / 2;
1188 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
1189 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
1190 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
1192 CalcBoundingBox( (long)x1
, (long)y1
);
1193 CalcBoundingBox( (long)x3
, (long)y3
);
1197 At this point, (x2,y2) and (c,d) are the position of the
1198 next-to-last and last point respectively, in the point list
1201 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1204 long wxPostScriptDC::GetCharWidth() const
1206 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1207 return (long) (GetCharHeight() * 72.0 / 120.0);
1211 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1213 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1215 m_signX
= (xLeftRight
? 1 : -1);
1216 m_signY
= (yBottomUp
? 1 : -1);
1218 // FIXME there is no such function in MSW
1220 ComputeScaleAndOrigin();
1224 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1226 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1232 wxDC::SetDeviceOrigin( x
, h
-y
);
1235 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1237 wxPaperSize id
= m_printData
.GetPaperId();
1239 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1241 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1245 if (width
) *width
= paper
->GetSizeDeviceUnits().x
;
1246 if (height
) *height
= paper
->GetSizeDeviceUnits().y
;
1250 if (width
) *width
= 595;
1251 if (height
) *height
= 842;
1255 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1257 wxPaperSize id
= m_printData
.GetPaperId();
1259 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1261 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1265 if (width
) *width
= paper
->GetWidth() / 10;
1266 if (height
) *height
= paper
->GetHeight() / 10;
1270 if (width
) *width
= 210;
1271 if (height
) *height
= 297;
1275 // Resolution in pixels per logical inch
1276 wxSize
wxPostScriptDC::GetPPI(void) const
1278 return wxSize(72, 72);
1282 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1284 wxCHECK_MSG( m_ok
, FALSE
, _T("invalid postscript dc") );
1286 if (m_printData
.GetFilename() == "")
1288 wxString filename
= wxGetTempFileName("ps");
1289 m_printData
.SetFilename(filename
);
1294 m_pstream
= new ofstream (m_printData
.GetFilename().fn_str());
1296 if (!m_pstream
|| !m_pstream
->good())
1298 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1305 SetBrush( *wxBLACK_BRUSH
);
1306 SetPen( *wxBLACK_PEN
);
1307 SetBackground( *wxWHITE_BRUSH
);
1308 SetTextForeground( *wxBLACK
);
1310 // set origin according to paper size
1311 SetDeviceOrigin( 0,0 );
1319 void wxPostScriptDC::EndDoc ()
1321 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1326 *m_pstream
<< "grestore\n";
1332 m_pstream
= (ofstream
*) NULL
;
1335 wxChar
*header_file
= wxGetTempFileName("ps");
1337 m_pstream
= new ofstream( wxConvCurrent
->cWX2MB(header_file
) );
1339 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1340 *m_pstream
<< "%%Title: " << m_title
.mb_str() << "\n";
1341 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1342 *m_pstream
<< "%%CreationDate: " << wxNow().mb_str() << "\n";
1345 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1347 *m_pstream
<< "%%For: " << MBSTRINGCAST wxConvCurrent
->cWX2MB(userID
);
1348 wxChar userName
[245];
1349 if (wxGetUserName(userName
, sizeof(userName
)))
1350 *m_pstream
<< " (" << MBSTRINGCAST wxConvCurrent
->cWX2MB(userName
) << ")";
1353 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1355 *m_pstream
<< "%%For: " << MBSTRINGCAST wxConvCurrent
->cWX2MB(userID
) << "\n";
1358 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1360 long wx_printer_translate_x
, wx_printer_translate_y
;
1361 double wx_printer_scale_x
, wx_printer_scale_y
;
1363 wx_printer_translate_x
= m_printData
.GetPrinterTranslateX();
1364 wx_printer_translate_y
= m_printData
.GetPrinterTranslateY();
1366 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1367 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1369 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1371 *m_pstream
<< "%%Orientation: Landscape\n";
1375 *m_pstream
<< "%%Orientation: Portrait\n";
1378 // Compute the bounding box. Note that it is in the default user
1379 // coordinate system, thus we have to convert the values.
1380 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1381 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1382 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1383 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1385 // If we're landscape, our sense of "x" and "y" is reversed.
1386 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1389 tmp
= llx
; llx
= lly
; lly
= tmp
;
1390 tmp
= urx
; urx
= ury
; ury
= tmp
;
1392 // We need either the two lines that follow, or we need to subtract
1393 // min_x from real_translate_y, which is commented out below.
1394 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1395 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1398 // The Adobe specifications call for integers; we round as to make
1399 // the bounding larger.
1400 *m_pstream
<< "%%BoundingBox: "
1401 << floor((double)llx
) << " " << floor((double)lly
) << " "
1402 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1403 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1404 *m_pstream
<< "%%EndComments\n\n";
1406 // To check the correctness of the bounding box, postscript commands
1407 // to draw a box corresponding to the bounding box are generated below.
1408 // But since we typically don't want to print such a box, the postscript
1409 // commands are generated within comments. These lines appear before any
1410 // adjustment of scale, rotation, or translation, and hence are in the
1411 // default user coordinates.
1412 *m_pstream
<< "% newpath\n";
1413 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1414 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1415 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1416 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1418 *m_pstream
<< "%%BeginProlog\n";
1419 *m_pstream
<< wxPostScriptHeaderEllipse
;
1420 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1421 *m_pstream
<< wxPostScriptHeaderColourImage
;
1422 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1423 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1425 if (wxPostScriptHeaderSpline
)
1426 *m_pstream
<< wxPostScriptHeaderSpline
;
1427 *m_pstream
<< "%%EndProlog\n";
1430 m_pstream
= (ofstream
*) NULL
;
1432 wxChar
*tmp_file
= wxGetTempFileName("ps");
1434 // Paste header Before wx_printer_file
1435 wxConcatFiles (header_file
, m_printData
.GetFilename(), tmp_file
);
1436 wxRemoveFile (header_file
);
1437 wxRemoveFile (m_printData
.GetFilename());
1438 wxRenameFile(tmp_file
, m_printData
.GetFilename());
1440 #if defined(__X__) || defined(__WXGTK__)
1443 wxString
previewCommand(m_printData
.GetPreviewCommand());
1444 wxString
printerCommand(m_printData
.GetPrinterCommand());
1445 wxString
printerOptions(m_printData
.GetPrinterOptions());
1446 wxString
filename(m_printData
.GetFilename());
1448 switch (m_printData
.GetPrintMode()) {
1450 case wxPRINT_MODE_PREVIEW
:
1453 argv
[0] = WXSTRINGCAST previewCommand
;
1454 argv
[1] = WXSTRINGCAST filename
;
1455 argv
[2] = (wxChar
*) NULL
;
1456 wxExecute (argv
, TRUE
);
1457 wxRemoveFile(m_printData
.GetFilename());
1461 case wxPRINT_MODE_PRINTER
:
1465 argv
[argc
++] = WXSTRINGCAST printerCommand
;
1467 // !SM! If we simply assign to argv[1] here, if printer options
1468 // are blank, we get an annoying and confusing message from lpr.
1469 wxChar
* opts
= WXSTRINGCAST printerOptions
;
1471 argv
[argc
++] = opts
;
1473 argv
[argc
++] = WXSTRINGCAST filename
;
1474 argv
[argc
++] = (wxChar
*) NULL
;
1475 wxExecute (argv
, TRUE
);
1476 wxRemoveFile(filename
);
1480 case wxPRINT_MODE_FILE
:
1481 case wxPRINT_MODE_NONE
:
1488 void wxPostScriptDC::StartPage ()
1490 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1492 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1494 // *m_pstream << "matrix currentmatrix\n";
1496 // Added by Chris Breeze
1498 // Each page starts with an "initgraphics" which resets the
1499 // transformation and so we need to reset the origin
1500 // (and rotate the page for landscape printing)
1503 m_scaleFactor = 1.0;
1504 m_logicalOriginX = 0;
1505 m_logicalOriginY = 0;
1508 long translate_x
, translate_y
;
1509 double scale_x
, scale_y
;
1511 translate_x
= m_printData
.GetPrinterTranslateX();
1512 translate_y
= m_printData
.GetPrinterTranslateY();
1514 scale_x
= m_printData
.GetPrinterScaleX();
1515 scale_y
= m_printData
.GetPrinterScaleY();
1517 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1519 translate_y
-= m_maxY
;
1520 *m_pstream
<< "90 rotate\n";
1523 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1524 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1527 void wxPostScriptDC::EndPage ()
1529 wxCHECK_RET( m_ok
&& m_pstream
, _T("invalid postscript dc") );
1531 *m_pstream
<< "showpage\n";
1534 bool wxPostScriptDC::DoBlit( long xdest
, long ydest
,
1535 long fwidth
, long fheight
,
1537 long xsrc
, long ysrc
,
1538 int rop
, bool WXUNUSED(useMask
) )
1540 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, _T("invalid postscript dc") );
1542 wxCHECK_MSG( source
, FALSE
, _T("invalid source dc") );
1544 /* blit into a bitmap */
1546 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1548 memDC
.SelectObject(bitmap
);
1549 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1550 memDC
.SelectObject(wxNullBitmap
);
1552 /* draw bitmap. scaling and positioning is done there */
1554 DrawBitmap( bitmap
, xdest
, ydest
);
1559 long wxPostScriptDC::GetCharHeight() const
1562 return m_font
.GetPointSize();
1567 void wxPostScriptDC::GetTextExtent( const wxString
& string
, long *x
, long *y
,
1568 long *descent
, long *externalLeading
, wxFont
*theFont
) const
1570 wxFont
*fontToUse
= theFont
;
1572 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1574 wxCHECK_RET( fontToUse
, _T("GetTextExtent: no font defined") );
1575 wxCHECK_RET( x
, _T("GetTextExtent: x == NULL") );
1576 wxCHECK_RET( y
, _T("GetTextExtent: y == NULL") );
1578 const wxWX2MBbuf strbuf
= string
.mb_str();
1580 #if !USE_AFM_FOR_POSTSCRIPT
1581 /* Provide a VERY rough estimate (avoid using it).
1582 * Produces accurate results for mono-spaced font
1583 * such as Courier (aka wxMODERN) */
1588 height
= fontToUse
->GetPointSize();
1590 *x
= strlen (strbuf
) * height
* 72 / 120;
1591 *y
= (long) (height
* 1.32); /* allow for descender */
1592 if (descent
) *descent
= 0;
1593 if (externalLeading
) *externalLeading
= 0;
1596 /* method for calculating string widths in postscript:
1597 / read in the AFM (adobe font metrics) file for the
1598 / actual font, parse it and extract the character widths
1599 / and also the descender. this may be improved, but for now
1600 / it works well. the AFM file is only read in if the
1601 / font is changed. this may be chached in the future.
1602 / calls to GetTextExtent with the font unchanged are rather
1605 / for each font and style used there is an AFM file necessary.
1606 / currently i have only files for the roman font family.
1607 / I try to get files for the other ones!
1609 / CAVE: the size of the string is currently always calculated
1610 / in 'points' (1/72 of an inch). this should later on be
1611 / changed to depend on the mapping mode.
1612 / CAVE: the path to the AFM files must be set before calling this
1613 / function. this is usually done by a call like the following:
1614 / wxSetAFMPath("d:\\wxw161\\afm\\");
1618 / wxPostScriptDC dc(NULL, TRUE);
1620 / wxSetAFMPath("d:\\wxw161\\afm\\");
1621 / dc.StartDoc("Test");
1624 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1625 / dc.GetTextExtent("Hallo",&w,&h);
1630 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1632 / updated: 14.05.95 */
1634 /* these static vars are for storing the state between calls */
1635 static int lastFamily
= INT_MIN
;
1636 static int lastSize
= INT_MIN
;
1637 static int lastStyle
= INT_MIN
;
1638 static int lastWeight
= INT_MIN
;
1639 static int lastDescender
= INT_MIN
;
1640 static int lastWidths
[256]; /* widths of the characters */
1642 /* get actual parameters */
1643 const int Family
= fontToUse
->GetFamily();
1644 const int Size
= fontToUse
->GetPointSize();
1645 const int Style
= fontToUse
->GetStyle();
1646 const int Weight
= fontToUse
->GetWeight();
1648 /* if we have another font, read the font-metrics */
1649 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1651 /* store actual values */
1652 lastFamily
= Family
;
1655 lastWeight
= Weight
;
1657 char *name
= (char*) NULL
;
1663 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO";
1664 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo";
1665 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Cour0";
1671 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO";
1672 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo";
1673 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO";
1674 else if name
= "TimesRo"; /* no typo */
1679 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO";
1680 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo";
1681 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Helv0";
1687 /* get the directory of the AFM files */
1691 if (!m_printData
.GetFontMetricPath().IsEmpty())
1693 strcpy( afmName
, m_printData
.GetFontMetricPath().mb_str() )
1696 /* 2. open and process the file
1697 / a short explanation of the AFM format:
1698 / we have for each character a line, which gives its size
1701 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1703 / that means, we have a character with ascii code 63, and width
1704 / (444/1000 * fontSize) points.
1705 / the other data is ignored for now!
1707 / when the font has changed, we read in the right AFM file and store the
1708 / character widths in an array, which is processed below (see point 3.). */
1710 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
1712 strcat(afmName
,name
);
1713 strcat(afmName
,".afm");
1714 FILE *afmFile
= fopen(afmName
,"r");
1719 strcpy( afmName
, "/usr/local/share/wx/gs_afm/" );
1720 strcat(afmName
,name
);
1721 strcat(afmName
,".afm");
1722 FILE *afmFile
= fopen(afmName
,"r");
1727 strcpy( afmName
, "/usr/share/wx/gs_afm/" );
1728 strcat(afmName
,name
);
1729 strcat(afmName
,".afm");
1730 FILE *afmFile
= fopen(afmName
,"r");
1736 wxLogDebug( "GetTextExtent: can't open AFM file '%s'\n", afmName
);
1737 wxLogDebug( " using approximate values\n");
1738 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
1739 lastDescender
= -150; /* dito. */
1743 /* init the widths array */
1744 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
1745 /* some variables for holding parts of a line */
1746 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1747 char upString
[30], utString
[30], encString
[50];
1750 /* read in the file and parse it */
1751 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
1753 /* A.) check for descender definition */
1754 if (strncmp(line
,"Descender",9)==0)
1756 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
1757 (strcmp(descString
,"Descender")!=0))
1759 wxLogDebug( "AFM-file '%s': line '%s' has error (bad descender)\n", afmName
,line
);
1762 /* JC 1.) check for UnderlinePosition */
1763 else if(strncmp(line
,"UnderlinePosition",17)==0)
1765 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
1766 (strcmp(upString
,"UnderlinePosition")!=0))
1768 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", afmName
, line
);
1771 /* JC 2.) check for UnderlineThickness */
1772 else if(strncmp(line
,"UnderlineThickness",18)==0)
1774 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
1775 (strcmp(utString
,"UnderlineThickness")!=0))
1777 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", afmName
, line
);
1780 /* JC 3.) check for EncodingScheme */
1781 else if(strncmp(line
,"EncodingScheme",14)==0)
1783 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
1784 (strcmp(utString
,"EncodingScheme")!=0))
1786 wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", afmName
, line
);
1788 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1790 wxLogDebug( "AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1791 afmName
,line
, encString
);
1794 /* B.) check for char-width */
1795 else if(strncmp(line
,"C ",2)==0)
1797 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
1799 wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1801 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
1803 wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1805 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
1806 if (ascii
>=0 && ascii
<256)
1808 lastWidths
[ascii
] = cWidth
; /* store width */
1812 /* MATTHEW: this happens a lot; don't print an error */
1813 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); */
1816 /* C.) ignore other entries. */
1820 /* hack to compute correct values for german 'Umlaute'
1821 / the correct way would be to map the character names
1822 / like 'adieresis' to corresp. positions of ISOEnc and read
1823 / these values from AFM files, too. Maybe later ... */
1824 lastWidths
[196] = lastWidths
['A']; // Ä
1825 lastWidths
[228] = lastWidths
['a']; // ä
1826 lastWidths
[214] = lastWidths
['O']; // Ö
1827 lastWidths
[246] = lastWidths
['o']; // ö
1828 lastWidths
[220] = lastWidths
['U']; // Ü
1829 lastWidths
[252] = lastWidths
['u']; // ü
1830 lastWidths
[223] = lastWidths
[251]; // ß
1833 /* JC: calculate UnderlineThickness/UnderlinePosition */
1834 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1835 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1837 /* 3. now the font metrics are read in, calc size this
1838 / is done by adding the widths of the characters in the
1839 / string. they are given in 1/1000 of the size! */
1842 long height
=Size
; /* by default */
1844 for(p
=(unsigned char *)strbuf
; *p
; p
++)
1846 if(lastWidths
[*p
]== INT_MIN
)
1848 wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n", *p
,*p
);
1849 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); /* assume space */
1853 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1857 /* add descender to height (it is usually a negative value) */
1858 if (lastDescender
!=INT_MIN
)
1860 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1863 /* return size values */
1867 /* return other parameters */
1870 if(lastDescender
!=INT_MIN
)
1872 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1880 /* currently no idea how to calculate this! */
1881 if (externalLeading
) *externalLeading
= 0;
1886 // Determine the Default Postscript Previewer
1887 // available on the platform
1888 #if defined(__SUN__) && defined(__XVIEW__)
1889 // OpenWindow/NeWS's Postscript Previewer
1890 # define PS_VIEWER_PROG "pageview"
1891 #elif defined(__VMS__)
1892 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
1893 #elif defined(__SGI__)
1894 // SGI's Display Postscript Previewer
1895 //# define PS_VIEWER_PROG "dps"
1896 # define PS_VIEWER_PROG "xpsview"
1897 #elif defined(__X__) || defined(__WXGTK__)
1898 // Front-end to ghostscript
1899 # define PS_VIEWER_PROG "ghostview"
1901 // Windows ghostscript/ghostview
1902 # define PS_VIEWER_PROG NULL
1905 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
1907 #if !USE_SHARED_LIBRARY
1908 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
1909 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
1912 // Redundant now I think
1914 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
1916 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
1917 const wxPoint
& pos
, const wxSize
& size
, long style
):
1918 wxDialog(parent
, -1, title
, pos
, size
, style
)
1920 wxBeginBusyCursor();
1925 *orientation
= new wxString
[2],
1926 *print_modes
= new wxString
[3];
1928 long wx_printer_translate_x
, wx_printer_translate_y
;
1929 double wx_printer_scale_x
, wx_printer_scale_y
;
1931 orientation
[0] = _("Portrait");
1932 orientation
[1] = _("Landscape");
1934 print_modes
[0] = _("Send to Printer");
1935 print_modes
[1] = _("Print to File");
1936 print_modes
[2] = _("Preview Only");
1940 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
1941 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
1942 okBut
->SetDefault();
1945 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1946 (void) new wxStaticText( this, -1, _("Printer Command: "),
1948 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
1949 wxPoint(100, yPos
), wxSize(100, -1) );
1951 (void) new wxStaticText( this, -1, _("Printer Options: "),
1952 wxPoint(210, yPos
) );
1953 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
1954 wxPoint(305, yPos
), wxSize(150, -1) );
1960 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
1961 2,orientation
,2,wxRA_SPECIFY_ROWS
);
1962 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
1964 // @@@ Configuration hook
1965 if ( !wxThePrintSetupData
->GetPrintPreviewCommand() )
1966 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
1968 // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand);
1970 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
1971 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
1973 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
1975 wxSize(-1,-1), features
,
1976 print_modes
, features
, wxRA_SPECIFY_ROWS
);
1979 radio1
->Enable(0, FALSE
);
1980 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
1981 radio1
->Enable(2, FALSE
);
1984 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
1985 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1986 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1988 sprintf (buf
, "%.2f", wx_printer_scale_x
);
1991 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
1992 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1994 sprintf (buf
, "%.2f", wx_printer_scale_y
);
1995 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
1996 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2000 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2001 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
2002 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2004 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2005 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
2006 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2010 delete[] orientation
;
2011 delete[] print_modes
;
2016 int wxPostScriptPrintDialog::ShowModal ()
2018 if ( wxDialog::ShowModal() == wxID_OK
)
2020 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2021 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2022 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2023 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2024 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2025 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2026 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2027 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2029 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->m_printerScaleX
);
2030 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->m_printerScaleY
);
2031 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->m_printerTranslateX
);
2032 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->m_printerTranslateY
);
2035 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2036 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2039 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? wxLANDSCAPE
: wxPORTRAIT
));
2042 switch ( radio1
->GetSelection() ) {
2043 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2044 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2045 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2054 // PostScript printer settings
2055 // RETAINED FOR BACKWARD COMPATIBILITY
2056 void wxSetPrinterCommand(const wxString
& cmd
)
2058 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2061 void wxSetPrintPreviewCommand(const wxString
& cmd
)
2063 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2066 void wxSetPrinterOptions(const wxString
& flags
)
2068 wxThePrintSetupData
->SetPrinterOptions(flags
);
2071 void wxSetPrinterFile(const wxString
& f
)
2073 wxThePrintSetupData
->SetPrinterFile(f
);
2076 void wxSetPrinterOrientation(int orient
)
2078 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2081 void wxSetPrinterScaling(double x
, double y
)
2083 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2086 void wxSetPrinterTranslation(long x
, long y
)
2088 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2091 // 1 = Preview, 2 = print to file, 3 = send to printer
2092 void wxSetPrinterMode(int mode
)
2094 wxThePrintSetupData
->SetPrinterMode(mode
);
2097 void wxSetAFMPath(const wxString
& f
)
2099 wxThePrintSetupData
->SetAFMPath(f
);
2102 // Get current values
2103 wxString
wxGetPrinterCommand()
2105 return wxThePrintSetupData
->GetPrinterCommand();
2108 wxString
wxGetPrintPreviewCommand()
2110 return wxThePrintSetupData
->GetPrintPreviewCommand();
2113 wxString
wxGetPrinterOptions()
2115 return wxThePrintSetupData
->GetPrinterOptions();
2118 wxString
wxGetPrinterFile()
2120 return wxThePrintSetupData
->GetPrinterFile();
2123 int wxGetPrinterOrientation()
2125 return wxThePrintSetupData
->GetPrinterOrientation();
2128 void wxGetPrinterScaling(double* x
, double* y
)
2130 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2133 void wxGetPrinterTranslation(long *x
, long *y
)
2135 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2138 int wxGetPrinterMode()
2140 return wxThePrintSetupData
->GetPrinterMode();
2143 wxString
wxGetAFMPath()
2145 return wxThePrintSetupData
->GetAFMPath();
2152 wxPrintSetupData::wxPrintSetupData()
2154 m_printerOrient
= wxPORTRAIT
;
2155 m_printerScaleX
= (double)1.0;
2156 m_printerScaleY
= (double)1.0;
2157 m_printerTranslateX
= 0;
2158 m_printerTranslateY
= 0;
2159 m_printerMode
= wxPRINT_MODE_FILE
;
2160 m_printColour
= TRUE
;
2163 wxPrintSetupData::~wxPrintSetupData()
2167 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2169 SetPrinterCommand(data
.GetPrinterCommand());
2170 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2171 SetPrinterOptions(data
.GetPrinterOptions());
2173 data
.GetPrinterTranslation(&x
, &y
);
2174 SetPrinterTranslation(x
, y
);
2177 data
.GetPrinterScaling(&x1
, &y1
);
2178 SetPrinterScaling(x1
, y1
);
2180 SetPrinterOrientation(data
.GetPrinterOrientation());
2181 SetPrinterMode(data
.GetPrinterMode());
2182 SetAFMPath(data
.GetAFMPath());
2183 SetPaperName(data
.GetPaperName());
2184 SetColour(data
.GetColour());
2187 // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData).
2188 void wxPrintSetupData::operator=(const wxPrintData
& data
)
2190 SetPrinterCommand(data
.GetPrinterCommand());
2191 SetPrintPreviewCommand(data
.GetPreviewCommand());
2192 SetPrinterOptions(data
.GetPrinterOptions());
2193 SetPrinterTranslation(data
.GetPrinterTranslateX(), data
.GetPrinterTranslateY());
2194 SetPrinterScaling(data
.GetPrinterScaleX(), data
.GetPrinterScaleY());
2195 SetPrinterOrientation(data
.GetOrientation());
2196 SetPrinterMode((int) data
.GetPrintMode());
2197 SetAFMPath(data
.GetFontMetricPath());
2198 SetPaperName(wxThePrintPaperDatabase
->ConvertIdToName(data
.GetPaperId()));
2199 SetColour(data
.GetColour());
2200 SetPrinterFile(data
.GetFilename());
2203 void wxInitializePrintSetupData(bool init
)
2207 wxThePrintSetupData
= new wxPrintSetupData
;
2209 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2210 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
2211 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_PREVIEW
);
2212 wxThePrintSetupData
->SetPaperName(_("A4 sheet, 210 x 297 mm"));
2214 // Could have a .ini file to read in some defaults
2215 // - and/or use environment variables, e.g. WXWIN
2217 wxThePrintSetupData
->SetPrinterCommand("print");
2218 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2219 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2222 wxThePrintSetupData
->SetPrinterCommand("print");
2223 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2224 wxThePrintSetupData
->SetPrinterOptions("");
2226 #if !defined(__VMS__) && !defined(__WXMSW__)
2227 wxThePrintSetupData
->SetPrinterCommand("lpr");
2228 wxThePrintSetupData
->SetPrinterOptions("");
2229 wxThePrintSetupData
->SetAFMPath("");
2234 if (wxThePrintSetupData
)
2235 delete wxThePrintSetupData
;
2236 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2240 // A module to allow initialization/cleanup of PostScript-related
2241 // things without calling these functions from app.cpp.
2243 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2245 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2247 wxPostScriptModule() {}
2252 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2255 * Initialization/cleanup module
2258 bool wxPostScriptModule::OnInit()
2260 wxInitializePrintSetupData();
2265 void wxPostScriptModule::OnExit()
2267 wxInitializePrintSetupData(FALSE
);
2274 // wxUSE_PRINTING_ARCHITECTURE