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"
30 #include "wx/dcmemory.h"
33 #include "wx/filedlg.h"
35 #include "wx/msgdlg.h"
38 #include "wx/generic/dcpsg.h"
39 #include "wx/generic/prntdlgg.h"
40 #include "wx/button.h"
41 #include "wx/stattext.h"
42 #include "wx/radiobox.h"
43 #include "wx/textctrl.h"
44 #include "wx/prntbase.h"
68 //-----------------------------------------------------------------------------
69 // start and end of document/page
70 //-----------------------------------------------------------------------------
72 static const char *wxPostScriptHeaderEllipse
= "\
73 /ellipsedict 8 dict def\n\
74 ellipsedict /mtrx matrix put\n\
78 /startangle exch def\n\
83 /savematrix mtrx currentmatrix def\n\
86 0 0 1 startangle endangle arc\n\
87 savematrix setmatrix\n\
92 static const char *wxPostScriptHeaderEllipticArc
= "\
93 /ellipticarcdict 8 dict def\n\
94 ellipticarcdict /mtrx matrix put\n\
96 { ellipticarcdict begin\n\
99 /startangle exch def\n\
104 /savematrix mtrx currentmatrix def\n\
107 do_fill { 0 0 moveto } if\n\
108 0 0 1 startangle endangle arc\n\
109 savematrix setmatrix\n\
110 do_fill { fill }{ stroke } ifelse\n\
114 static const char *wxPostScriptHeaderSpline
= "\
115 /DrawSplineSection {\n\
122 /xa x1 x2 x1 sub 0.666667 mul add def\n\
123 /ya y1 y2 y1 sub 0.666667 mul add def\n\
124 /xb x3 x2 x3 sub 0.666667 mul add def\n\
125 /yb y3 y2 y3 sub 0.666667 mul add def\n\
127 xa ya xb yb x3 y3 curveto\n\
131 static const char *wxPostScriptHeaderColourImage
= "\
132 % define 'colorimage' if it isn't defined\n\
133 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
135 /colorimage where % do we know about 'colorimage'?\n\
136 { pop } % yes: pop off the 'dict' returned\n\
137 { % no: define one\n\
138 /colortogray { % define an RGB->I function\n\
139 /rgbdata exch store % call input 'rgbdata'\n\
140 rgbdata length 3 idiv\n\
141 /npixls exch store\n\
143 0 1 npixls 1 sub {\n\
145 rgbdata rgbindx get 20 mul % Red\n\
146 rgbdata rgbindx 1 add get 32 mul % Green\n\
147 rgbdata rgbindx 2 add get 12 mul % Blue\n\
148 add add 64 idiv % I = .5G + .31R + .18B\n\
150 /rgbindx rgbindx 3 add store\n\
152 grays 0 npixls getinterval\n\
155 % Utility procedure for colorimage operator.\n\
156 % This procedure takes two procedures off the\n\
157 % stack and merges them into a single procedure.\n\
159 /mergeprocs { % def\n\
178 /colorimage { % def\n\
179 pop pop % remove 'false 3' operands\n\
180 {colortogray} mergeprocs\n\
183 } ifelse % end of 'false' case\n\
186 static char wxPostScriptHeaderReencodeISO1
[] =
188 "dup dup findfont dup length dict begin\n"
189 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
190 "/Encoding ISOLatin1Encoding def\n"
191 "currentdict end definefont\n"
193 "/ISOLatin1Encoding [\n"
194 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
195 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
196 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
197 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
198 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
199 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
200 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
201 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
202 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
203 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
204 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
205 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
206 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
207 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
208 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
210 static char wxPostScriptHeaderReencodeISO2
[] =
211 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
212 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
213 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
214 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
215 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
216 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
217 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
218 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
219 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
220 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
221 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
222 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
223 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
224 "/yacute/thorn/ydieresis\n"
227 //-------------------------------------------------------------------------------
229 //-------------------------------------------------------------------------------
231 wxPostScriptDC::wxPostScriptDC ()
233 m_pstream
= (ofstream
*) NULL
;
243 m_underlinePosition
= 0.0;
244 m_underlineThickness
= 0.0;
246 m_signX
= 1; // default x-axis left to right
247 m_signY
= -1; // default y-axis bottom up -> top down
250 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
252 m_pstream
= (ofstream
*) NULL
;
262 m_underlinePosition
= 0.0;
263 m_underlineThickness
= 0.0;
265 m_signX
= 1; // default x-axis left to right
266 m_signY
= -1; // default y-axis bottom up -> top down
268 Create(file
, interactive
, parent
);
271 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
273 m_isInteractive
= interactive
;
279 // Can only send to file in Windows
280 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
285 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
295 wxPostScriptDC::~wxPostScriptDC ()
297 if (m_pstream
) delete m_pstream
;
300 bool wxPostScriptDC::Ok() const
305 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
307 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
308 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
309 m_ok
= (dialog
.ShowModal () == wxID_OK
);
311 if (!m_ok
) return FALSE
;
313 if ((m_filename
== "") &&
314 (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
||
315 wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
319 wxThePrintSetupData
->SetPrinterFile("preview");
321 // For PS_PRINTER action this depends on a Unix-style print spooler
322 // since the wx_printer_file can be destroyed during a session
323 // @@@ TODO: a Windows-style answer for non-Unix
325 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
327 strcpy (tmp
, "/tmp/preview_");
328 strcat (tmp
, userId
);
329 wxThePrintSetupData
->SetPrinterFile(tmp
);
332 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
333 strcat (tmp2
, ".ps");
334 wxThePrintSetupData
->SetPrinterFile(tmp2
);
337 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
339 wxString file
= wxSaveFileSelector (_("PostScript"), "ps");
340 if ( file
.IsEmpty() )
346 wxThePrintSetupData
->SetPrinterFile(file
);
354 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
356 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
358 if (m_clipping
) return;
360 wxDC::SetClippingRegion( x
, y
, w
, h
);
363 *m_pstream
<< "gsave\n"
365 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
366 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
367 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
368 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
369 << "closepath clip newpath\n";
372 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
376 void wxPostScriptDC::DestroyClippingRegion()
378 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
380 wxDC::DestroyClippingRegion();
385 *m_pstream
<< "grestore\n";
389 void wxPostScriptDC::Clear()
391 wxFAIL_MSG( "wxPostScriptDC::Clear not implemented." );
394 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
396 wxFAIL_MSG( "wxPostScriptDC::FloodFill not implemented." );
399 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
401 wxFAIL_MSG( "wxPostScriptDC::GetPixel not implemented." );
405 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
407 wxFAIL_MSG( "wxPostScriptDC::CrossHair not implemented." );
410 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
412 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
414 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
418 *m_pstream
<< "newpath\n"
419 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
420 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
423 CalcBoundingBox( x1
, y1
);
424 CalcBoundingBox( x2
, y2
);
427 #define RAD2DEG 57.29577951308
429 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
431 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
435 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
436 double alpha1
, alpha2
;
438 if (x1
== x2
&& y1
== y2
)
442 } else if (radius
== 0.0)
444 alpha1
= alpha2
= 0.0;
447 alpha1
= (x1
- xc
== 0) ?
448 (y1
- yc
< 0) ? 90.0 : -90.0 :
449 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
450 alpha2
= (x2
- xc
== 0) ?
451 (y2
- yc
< 0) ? 90.0 : -90.0 :
452 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
454 while (alpha1
<= 0) alpha1
+= 360;
455 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
456 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
457 while (alpha2
> 360) alpha2
-= 360;
459 if (m_brush
.GetStyle() != wxTRANSPARENT
)
462 *m_pstream
<< "newpath\n"
463 << XLOG2DEV(xc
) << " "
464 << YLOG2DEV(yc
) << " "
465 << XLOG2DEVREL(radius
) << " "
466 << YLOG2DEVREL(radius
) << " "
468 << alpha2
<< " ellipse\n"
469 << XLOG2DEV(xc
) << " "
470 << YLOG2DEV(yc
) << " lineto\n"
475 if (m_pen
.GetStyle() != wxTRANSPARENT
)
478 *m_pstream
<< "newpath\n"
479 << XLOG2DEV(xc
) << " "
480 << YLOG2DEV(yc
) << " "
481 << XLOG2DEVREL(radius
) << " "
482 << YLOG2DEVREL(radius
) << " "
484 << alpha2
<< " ellipse\n"
488 CalcBoundingBox( xc
-radius
, yc
-radius
);
489 CalcBoundingBox( xc
+radius
, yc
+radius
);
492 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
494 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
496 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
497 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
503 DrawEllipse(x
,y
,w
,h
);
507 if (m_brush
.GetStyle () != wxTRANSPARENT
)
511 *m_pstream
<< "newpath\n"
512 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
513 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
514 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
516 CalcBoundingBox( x
,y
);
517 CalcBoundingBox( x
+w
, y
+h
);
520 if (m_pen
.GetStyle () != wxTRANSPARENT
)
524 *m_pstream
<< "newpath\n"
525 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
526 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
527 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
529 CalcBoundingBox( x
, y
);
530 CalcBoundingBox( x
+w
, y
+h
);
534 void wxPostScriptDC::DrawPoint (long x
, long y
)
536 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
538 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
542 *m_pstream
<< "newpath\n"
543 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
544 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
547 CalcBoundingBox( x
, y
);
550 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
552 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
556 if (m_brush
.GetStyle () != wxTRANSPARENT
)
560 *m_pstream
<< "newpath\n";
562 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
563 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
564 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
565 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
567 for (int i
= 1; i
< n
; i
++)
569 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
570 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
571 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
572 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
574 *m_pstream
<< "fill\n";
577 if (m_pen
.GetStyle () != wxTRANSPARENT
)
581 *m_pstream
<< "newpath\n";
583 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
584 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
585 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
586 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
588 for (int i
= 1; i
< n
; i
++)
590 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
591 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
592 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
593 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
596 *m_pstream
<< "stroke\n";
600 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
602 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
604 if (m_pen
.GetStyle() == wxTRANSPARENT
)
612 for ( i
=0; i
<n
; i
++ )
614 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
617 *m_pstream
<< "newpath\n"
618 << XLOG2DEV(points
[0].x
+xoffset
) << " "
619 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
621 for (i
= 1; i
< n
; i
++)
623 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
624 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
627 *m_pstream
<< "stroke\n";
630 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
632 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
634 if (m_brush
.GetStyle () != wxTRANSPARENT
)
638 *m_pstream
<< "newpath\n"
639 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
640 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
641 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
642 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
646 CalcBoundingBox( x
, y
);
647 CalcBoundingBox( x
+ width
, y
+ height
);
650 if (m_pen
.GetStyle () != wxTRANSPARENT
)
654 *m_pstream
<< "newpath\n"
655 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
656 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
657 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
658 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
662 CalcBoundingBox( x
, y
);
663 CalcBoundingBox( x
+ width
, y
+ height
);
667 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
669 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
673 // Now, a negative radius is interpreted to mean
674 // 'the proportion of the smallest X or Y dimension'
675 double smallest
= 0.0;
680 radius
= (-radius
* smallest
);
683 long rad
= (long) radius
;
685 if (m_brush
.GetStyle () != wxTRANSPARENT
)
689 // Draw rectangle anticlockwise
690 *m_pstream
<< "newpath\n"
691 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
692 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
693 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
694 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
695 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
696 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
697 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
698 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
702 CalcBoundingBox( x
, y
);
703 CalcBoundingBox( x
+ width
, y
+ height
);
706 if (m_pen
.GetStyle () != wxTRANSPARENT
)
710 // Draw rectangle anticlockwise
711 *m_pstream
<< "newpath\n"
712 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
713 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
714 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
715 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
716 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
717 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
718 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
719 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
723 CalcBoundingBox( x
, y
);
724 CalcBoundingBox( x
+ width
, y
+ height
);
728 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
730 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
732 if (m_brush
.GetStyle () != wxTRANSPARENT
)
736 *m_pstream
<< "newpath\n"
737 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
738 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
741 CalcBoundingBox( x
- width
, y
- height
);
742 CalcBoundingBox( x
+ width
, y
+ height
);
745 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
749 *m_pstream
<< "newpath\n"
750 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
751 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
754 CalcBoundingBox( x
- width
, y
- height
);
755 CalcBoundingBox( x
+ width
, y
+ height
);
759 void wxPostScriptDC::DrawIcon( const wxIcon
& icon
, long x
, long y
)
761 DrawBitmap( icon
, x
, y
, TRUE
);
764 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool WXUNUSED(useMask
) )
766 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
768 if (!bitmap
.Ok()) return;
770 wxImage
image( bitmap
);
772 if (!image
.Ok()) return;
774 int ww
= XLOG2DEVREL(image
.GetWidth());
775 int hh
= YLOG2DEVREL(image
.GetHeight());
777 image
= image
.Scale( ww
, hh
);
779 if (!image
.Ok()) return;
781 int xx
= XLOG2DEV(x
);
782 int yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
784 *m_pstream
<< "/origstate save def\n"
786 << "/pix " << ww
<< " string def\n"
787 << "/grays " << ww
<< " string def\n"
788 << "/npixels 0 def\n"
789 << "/rgbindx 0 def\n"
790 << xx
<< " " << yy
<< " translate\n"
791 << ww
<< " " << hh
<< " scale\n"
792 << ww
<< " " << hh
<< " 8\n"
793 << "[" << ww
<< " 0 0 " << (-hh
) << " 0 " << hh
<< "]\n"
794 << "{currentfile pix readhexstring pop}\n"
795 << "false 3 colorimage\n";
797 for (int j
= 0; j
< hh
; j
++)
799 for (int i
= 0; i
< ww
; i
++)
803 wxDecToHex( image
.GetRed(i
,j
), buffer
);
804 *m_pstream
<< buffer
;
805 wxDecToHex( image
.GetGreen(i
,j
), buffer
);
806 *m_pstream
<< buffer
;
807 wxDecToHex( image
.GetBlue(i
,j
), buffer
);
808 *m_pstream
<< buffer
;
813 *m_pstream
<< "end\n";
814 *m_pstream
<< "origstate restore\n";
818 void wxPostScriptDC::SetFont( const wxFont
& font
)
820 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
822 if (!font
.Ok()) return;
827 const char *style
= "";
828 int Style
= m_font
.GetStyle();
829 int Weight
= m_font
.GetWeight();
831 switch (m_font
.GetFamily ())
841 // name = "/Times-Roman";
842 name
= "/Times"; // Altered by EDZ
845 name
= "/Zapf-Chancery-MediumItalic";
850 case wxDEFAULT
: // Sans Serif Font
851 name
= "/LucidaSans";
854 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
856 if (m_font
.GetFamily () == wxROMAN
)
861 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
865 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
867 if (m_font
.GetFamily () == wxROMAN
)
872 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
874 if (m_font
.GetFamily () == wxROMAN
)
875 style
= "-BoldItalic";
877 style
= "-BoldOblique";
879 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
881 if (m_font
.GetFamily () == wxROMAN
)
886 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
888 if (m_font
.GetFamily () == wxROMAN
)
889 style
= "-BoldItalic";
891 style
= "-BoldOblique";
902 *m_pstream
<< buf
<< " reencodeISO def\n";
903 *m_pstream
<< buf
<< " findfont\n";
904 *m_pstream
<< YLOG2DEVREL(m_font
.GetPointSize()) << " scalefont setfont\n";
907 void wxPostScriptDC::SetPen( const wxPen
& pen
)
909 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
911 if (!pen
.Ok()) return;
913 int oldStyle
= m_pen
.GetStyle();
917 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
920 Line style - WRONG: 2nd arg is OFFSET
922 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
923 operator correctly. You should look-up this in the Red Book: the 2nd parame-
924 ter is not number of values in the array of the first one, but an offset
925 into this description of the pattern. I mean a real *offset* not index
926 into array. I.e. If the command is [3 4] 1 setdash is used, then there
927 will be first black line *2* units long, then space 4 units, then the
928 pattern of *3* units black, 4 units space will be repeated.
931 static const char *dotted
= "[2 5] 2";
932 static const char *short_dashed
= "[4 4] 2";
933 static const char *long_dashed
= "[4 8] 2";
934 static const char *dotted_dashed
= "[6 6 2 6] 4";
936 const char *psdash
= (char *) NULL
;
937 switch (m_pen
.GetStyle ())
939 case wxDOT
: psdash
= dotted
; break;
940 case wxSHORT_DASH
: psdash
= short_dashed
; break;
941 case wxLONG_DASH
: psdash
= long_dashed
; break;
942 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
945 default: psdash
= "[] 0"; break;
948 if (oldStyle
!= m_pen
.GetStyle())
950 *m_pstream
<< psdash
<< " setdash\n";
954 unsigned char red
= m_pen
.GetColour().Red();
955 unsigned char blue
= m_pen
.GetColour().Blue();
956 unsigned char green
= m_pen
.GetColour().Green();
960 // Anything not white is black
961 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
962 && green
== (unsigned char) 255))
964 red
= (unsigned char) 0;
965 green
= (unsigned char) 0;
966 blue
= (unsigned char) 0;
972 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
974 long redPS
= (long) (((int) red
) / 255.0);
975 long bluePS
= (long) (((int) blue
) / 255.0);
976 long greenPS
= (long) (((int) green
) / 255.0);
978 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
981 m_currentBlue
= blue
;
982 m_currentGreen
= green
;
986 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
988 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
990 if (!brush
.Ok()) return;
995 unsigned char red
= m_brush
.GetColour ().Red ();
996 unsigned char blue
= m_brush
.GetColour ().Blue ();
997 unsigned char green
= m_brush
.GetColour ().Green ();
1001 // Anything not black is white
1002 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
1003 && green
== (unsigned char) 0))
1005 red
= (unsigned char) 255;
1006 green
= (unsigned char) 255;
1007 blue
= (unsigned char) 255;
1013 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1015 long redPS
= (long) (((int) red
) / 255.0);
1016 long bluePS
= (long) (((int) blue
) / 255.0);
1017 long greenPS
= (long) (((int) green
) / 255.0);
1018 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1020 m_currentBlue
= blue
;
1021 m_currentGreen
= green
;
1025 void wxPostScriptDC::DrawText( const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
) )
1027 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1031 if (m_textForegroundColour
.Ok ())
1033 unsigned char red
= m_textForegroundColour
.Red ();
1034 unsigned char blue
= m_textForegroundColour
.Blue ();
1035 unsigned char green
= m_textForegroundColour
.Green ();
1039 // Anything not white is black
1040 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
1041 && green
== (unsigned char) 255))
1043 red
= (unsigned char) 0;
1044 green
= (unsigned char) 0;
1045 blue
= (unsigned char) 0;
1049 // maybe setgray here ?
1051 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1053 long redPS
= (long) (((int) red
) / 255.0);
1054 long bluePS
= (long) (((int) blue
) / 255.0);
1055 long greenPS
= (long) (((int) green
) / 255.0);
1056 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1059 m_currentBlue
= blue
;
1060 m_currentGreen
= green
;
1064 int size
= m_font
.GetPointSize();
1066 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
1067 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
1070 int len
= strlen ((char *)(const char *)text
);
1072 for (i
= 0; i
< len
; i
++)
1074 int c
= (unsigned char) text
[i
];
1075 if ( c
== ')' || c
== '(' || c
== '\\')
1077 *m_pstream
<< "\\" << (char) c
;
1079 else if ( c
>= 128 )
1081 // Cope with character codes > 127
1083 sprintf(tmp
, "\\%o", c
);
1087 *m_pstream
<< (char) c
;
1090 *m_pstream
<< ")" << " show\n";
1092 if (m_font
.GetUnderlined())
1094 long uy
= (long)(y
+ size
- m_underlinePosition
);
1096 GetTextExtent(text
, &w
, &h
);
1098 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
1100 << (long)m_underlineThickness
<< " setlinewidth "
1101 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
1102 << " lineto stroke grestore\n";
1105 CalcBoundingBox( x
, y
);
1106 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1110 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1112 m_backgroundBrush
= brush
;
1115 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1117 wxFAIL_MSG( "wxPostScriptDC::SetLogicalFunction not implemented." );
1120 void wxPostScriptDC::DrawSpline( wxList
*points
)
1122 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1126 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1129 wxNode
*node
= points
->First();
1130 p
= (wxPoint
*)node
->Data();
1134 node
= node
->Next();
1135 p
= (wxPoint
*)node
->Data();
1138 x3
= a
= (double)(x1
+ c
) / 2;
1139 y3
= b
= (double)(y1
+ d
) / 2;
1141 *m_pstream
<< "newpath "
1142 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
1143 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
1145 CalcBoundingBox( (long)x1
, (long)y1
);
1146 CalcBoundingBox( (long)x3
, (long)y3
);
1148 while ((node
= node
->Next()) != NULL
)
1150 q
= (wxPoint
*)node
->Data();
1158 x3
= (double)(x2
+ c
) / 2;
1159 y3
= (double)(y2
+ d
) / 2;
1160 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
1161 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
1162 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
1164 CalcBoundingBox( (long)x1
, (long)y1
);
1165 CalcBoundingBox( (long)x3
, (long)y3
);
1169 At this point, (x2,y2) and (c,d) are the position of the
1170 next-to-last and last point respectively, in the point list
1173 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1176 long wxPostScriptDC::GetCharWidth ()
1178 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1179 return (long) (GetCharHeight() * 72.0 / 120.0);
1183 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1185 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1187 m_signX
= (xLeftRight
? 1 : -1);
1188 m_signY
= (yBottomUp
? 1 : -1);
1190 // FIXME there is no such function in MSW
1192 ComputeScaleAndOrigin();
1196 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1198 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1204 wxDC::SetDeviceOrigin( x
, h
-y
);
1207 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1209 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1211 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1213 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1215 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1219 if (width
) *width
= paper
->widthPixels
;
1220 if (height
) *height
= paper
->heightPixels
;
1224 if (width
) *width
= 595;
1225 if (height
) *height
= 842;
1229 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1231 wxCHECK_MSG( m_ok
, FALSE
, "invalid postscript dc" );
1233 if (m_filename
== "")
1235 m_filename
= wxGetTempFileName("ps");
1236 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1241 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1244 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1246 if (!m_pstream
|| !m_pstream
->good())
1248 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1255 SetBrush( *wxBLACK_BRUSH
);
1256 SetPen( *wxBLACK_PEN
);
1257 SetBackground( *wxWHITE_BRUSH
);
1258 SetTextForeground( *wxBLACK
);
1260 // set origin according to paper size
1261 SetDeviceOrigin( 0,0 );
1269 void wxPostScriptDC::EndDoc ()
1271 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1276 *m_pstream
<< "grestore\n";
1282 m_pstream
= (ofstream
*) NULL
;
1285 char *header_file
= wxGetTempFileName("ps");
1287 m_pstream
= new ofstream( header_file
);
1289 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1290 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1291 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1292 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1295 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1297 *m_pstream
<< "%%For: " << (char *)userID
;
1299 if (wxGetUserName(userName
, sizeof(userName
)))
1300 *m_pstream
<< " (" << (char *)userName
<< ")";
1303 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1305 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1308 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1310 long wx_printer_translate_x
, wx_printer_translate_y
;
1311 double wx_printer_scale_x
, wx_printer_scale_y
;
1312 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1313 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1315 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1317 *m_pstream
<< "%%Orientation: Landscape\n";
1321 *m_pstream
<< "%%Orientation: Portrait\n";
1324 // Compute the bounding box. Note that it is in the default user
1325 // coordinate system, thus we have to convert the values.
1326 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1327 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1328 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1329 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1331 // If we're landscape, our sense of "x" and "y" is reversed.
1332 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1335 tmp
= llx
; llx
= lly
; lly
= tmp
;
1336 tmp
= urx
; urx
= ury
; ury
= tmp
;
1338 // We need either the two lines that follow, or we need to subtract
1339 // min_x from real_translate_y, which is commented out below.
1340 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1341 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1344 // The Adobe specifications call for integers; we round as to make
1345 // the bounding larger.
1346 *m_pstream
<< "%%BoundingBox: "
1347 << floor((double)llx
) << " " << floor((double)lly
) << " "
1348 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1349 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1350 *m_pstream
<< "%%EndComments\n\n";
1352 // To check the correctness of the bounding box, postscript commands
1353 // to draw a box corresponding to the bounding box are generated below.
1354 // But since we typically don't want to print such a box, the postscript
1355 // commands are generated within comments. These lines appear before any
1356 // adjustment of scale, rotation, or translation, and hence are in the
1357 // default user coordinates.
1358 *m_pstream
<< "% newpath\n";
1359 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1360 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1361 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1362 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1364 *m_pstream
<< "%%BeginProlog\n";
1365 *m_pstream
<< wxPostScriptHeaderEllipse
;
1366 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1367 *m_pstream
<< wxPostScriptHeaderColourImage
;
1368 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1369 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1371 if (wxPostScriptHeaderSpline
)
1372 *m_pstream
<< wxPostScriptHeaderSpline
;
1373 *m_pstream
<< "%%EndProlog\n";
1376 m_pstream
= (ofstream
*) NULL
;
1378 char *tmp_file
= wxGetTempFileName("ps");
1380 // Paste header Before wx_printer_file
1381 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1382 wxRemoveFile (header_file
);
1383 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1384 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1386 #if defined(__X__) || defined(__WXGTK__)
1389 switch (wxThePrintSetupData
->GetPrinterMode()) {
1393 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1394 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1395 argv
[2] = (char *) NULL
;
1396 wxExecute (argv
, TRUE
);
1397 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1405 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1407 // !SM! If we simply assign to argv[1] here, if printer options
1408 // are blank, we get an annoying and confusing message from lpr.
1409 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1411 argv
[argc
++] = opts
;
1413 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1414 argv
[argc
++] = (char *) NULL
;
1415 wxExecute (argv
, TRUE
);
1416 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1427 void wxPostScriptDC::StartPage ()
1429 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1431 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1433 // *m_pstream << "matrix currentmatrix\n";
1435 // Added by Chris Breeze
1437 // Each page starts with an "initgraphics" which resets the
1438 // transformation and so we need to reset the origin
1439 // (and rotate the page for landscape printing)
1442 m_scaleFactor = 1.0;
1443 m_logicalOriginX = 0;
1444 m_logicalOriginY = 0;
1447 long translate_x
, translate_y
;
1448 double scale_x
, scale_y
;
1449 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1450 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1452 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1454 translate_y
-= m_maxY
;
1455 *m_pstream
<< "90 rotate\n";
1458 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1459 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1462 void wxPostScriptDC::EndPage ()
1464 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1466 *m_pstream
<< "showpage\n";
1469 bool wxPostScriptDC::Blit( long xdest
, long ydest
,
1470 long fwidth
, long fheight
,
1472 long xsrc
, long ysrc
,
1473 int rop
, bool WXUNUSED(useMask
) )
1475 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, "invalid postscript dc" );
1477 wxCHECK_MSG( source
, FALSE
, "invalid source dc" );
1479 /* blit into a bitmap */
1481 wxBitmap
bitmap( fwidth
, fheight
);
1483 memDC
.SelectObject(bitmap
);
1484 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1485 memDC
.SelectObject(wxNullBitmap
);
1487 /* draw bitmap. scaling and positioning is done there */
1489 DrawBitmap( bitmap
, xdest
, ydest
);
1494 long wxPostScriptDC::GetCharHeight()
1497 return m_font
.GetPointSize();
1502 void wxPostScriptDC::GetTextExtent( const wxString
& string
, long *x
, long *y
,
1503 long *descent
, long *externalLeading
, wxFont
*theFont
,
1504 bool WXUNUSED(use16
) )
1506 wxFont
*fontToUse
= theFont
;
1508 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1510 wxCHECK_RET( fontToUse
, "GetTextExtent: no font defined" );
1511 wxCHECK_RET( x
, "GetTextExtent: x == NULL" );
1512 wxCHECK_RET( y
, "GetTextExtent: y == NULL" );
1514 #if !USE_AFM_FOR_POSTSCRIPT
1515 /* Provide a VERY rough estimate (avoid using it).
1516 * Produces accurate results for mono-spaced font
1517 * such as Courier (aka wxMODERN) */
1522 height
= fontToUse
->GetPointSize();
1524 *x
= strlen (string
) * height
* 72 / 120;
1525 *y
= (long) (height
* 1.32); /* allow for descender */
1526 if (descent
) *descent
= 0;
1527 if (externalLeading
) *externalLeading
= 0;
1530 /* method for calculating string widths in postscript:
1531 / read in the AFM (adobe font metrics) file for the
1532 / actual font, parse it and extract the character widths
1533 / and also the descender. this may be improved, but for now
1534 / it works well. the AFM file is only read in if the
1535 / font is changed. this may be chached in the future.
1536 / calls to GetTextExtent with the font unchanged are rather
1539 / for each font and style used there is an AFM file necessary.
1540 / currently i have only files for the roman font family.
1541 / I try to get files for the other ones!
1543 / CAVE: the size of the string is currently always calculated
1544 / in 'points' (1/72 of an inch). this should later on be
1545 / changed to depend on the mapping mode.
1546 / CAVE: the path to the AFM files must be set before calling this
1547 / function. this is usually done by a call like the following:
1548 / wxSetAFMPath("d:\\wxw161\\afm\\");
1552 / wxPostScriptDC dc(NULL, TRUE);
1554 / wxSetAFMPath("d:\\wxw161\\afm\\");
1555 / dc.StartDoc("Test");
1558 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1559 / dc.GetTextExtent("Hallo",&w,&h);
1564 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1566 / updated: 14.05.95 */
1568 /* these static vars are for storing the state between calls */
1569 static int lastFamily
= INT_MIN
;
1570 static int lastSize
= INT_MIN
;
1571 static int lastStyle
= INT_MIN
;
1572 static int lastWeight
= INT_MIN
;
1573 static int lastDescender
= INT_MIN
;
1574 static int lastWidths
[256]; /* widths of the characters */
1576 /* get actual parameters */
1577 const int Family
= fontToUse
->GetFamily();
1578 const int Size
= fontToUse
->GetPointSize();
1579 const int Style
= fontToUse
->GetStyle();
1580 const int Weight
= fontToUse
->GetWeight();
1582 /* if we have another font, read the font-metrics */
1583 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1585 /* store actual values */
1586 lastFamily
= Family
;
1589 lastWeight
= Weight
;
1591 char *name
= (char*) NULL
;
1597 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO";
1598 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo";
1599 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Cour0";
1605 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO";
1606 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo";
1607 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO";
1608 else if name
= "TimesRo"; /* no typo */
1613 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO";
1614 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo";
1615 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Helv0";
1621 /* get the directory of the AFM files */
1624 if (wxGetAFMPath()) strcpy( afmName
, wxGetAFMPath() );
1626 /* 2. open and process the file
1627 / a short explanation of the AFM format:
1628 / we have for each character a line, which gives its size
1631 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1633 / that means, we have a character with ascii code 63, and width
1634 / (444/1000 * fontSize) points.
1635 / the other data is ignored for now!
1637 / when the font has changed, we read in the right AFM file and store the
1638 / character widths in an array, which is processed below (see point 3.). */
1640 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
1642 strcat(afmName
,name
);
1643 strcat(afmName
,".afm");
1644 FILE *afmFile
= fopen(afmName
,"r");
1645 if ( afmFile
==NULL
)
1647 wxLogDebug( "GetTextExtent: can't open AFM file '%s'\n", afmName
);
1648 wxLogDebug( " using approximate values\n");
1649 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
1650 lastDescender
= -150; /* dito. */
1654 /* init the widths array */
1655 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
1656 /* some variables for holding parts of a line */
1657 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1658 char upString
[30], utString
[30], encString
[50];
1661 /* read in the file and parse it */
1662 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
1664 /* A.) check for descender definition */
1665 if (strncmp(line
,"Descender",9)==0)
1667 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
1668 (strcmp(descString
,"Descender")!=0))
1670 wxLogDebug( "AFM-file '%s': line '%s' has error (bad descender)\n", afmName
,line
);
1673 /* JC 1.) check for UnderlinePosition */
1674 else if(strncmp(line
,"UnderlinePosition",17)==0)
1676 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
1677 (strcmp(upString
,"UnderlinePosition")!=0))
1679 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", afmName
, line
);
1682 /* JC 2.) check for UnderlineThickness */
1683 else if(strncmp(line
,"UnderlineThickness",18)==0)
1685 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
1686 (strcmp(utString
,"UnderlineThickness")!=0))
1688 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", afmName
, line
);
1691 /* JC 3.) check for EncodingScheme */
1692 else if(strncmp(line
,"EncodingScheme",14)==0)
1694 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
1695 (strcmp(utString
,"EncodingScheme")!=0))
1697 wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", afmName
, line
);
1699 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1701 wxLogDebug( "AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1702 afmName
,line
, encString
);
1705 /* B.) check for char-width */
1706 else if(strncmp(line
,"C ",2)==0)
1708 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
1710 wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1712 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
1714 wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1716 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
1717 if (ascii
>=0 && ascii
<256)
1719 lastWidths
[ascii
] = cWidth
; /* store width */
1723 /* MATTHEW: this happens a lot; don't print an error */
1724 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); */
1727 /* C.) ignore other entries. */
1731 /* hack to compute correct values for german 'Umlaute'
1732 / the correct way would be to map the character names
1733 / like 'adieresis' to corresp. positions of ISOEnc and read
1734 / these values from AFM files, too. Maybe later ... */
1735 lastWidths
[196] = lastWidths
['A']; // Ä
1736 lastWidths
[228] = lastWidths
['a']; // ä
1737 lastWidths
[214] = lastWidths
['O']; // Ö
1738 lastWidths
[246] = lastWidths
['o']; // ö
1739 lastWidths
[220] = lastWidths
['U']; // Ü
1740 lastWidths
[252] = lastWidths
['u']; // ü
1741 lastWidths
[223] = lastWidths
[251]; // ß
1744 /* JC: calculate UnderlineThickness/UnderlinePosition */
1745 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1746 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1748 /* 3. now the font metrics are read in, calc size this
1749 / is done by adding the widths of the characters in the
1750 / string. they are given in 1/1000 of the size! */
1753 long height
=Size
; /* by default */
1755 for(p
=(unsigned char *)(const char *)string
; *p
; p
++)
1757 if(lastWidths
[*p
]== INT_MIN
)
1759 wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n", *p
,*p
);
1760 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); /* assume space */
1764 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1768 /* add descender to height (it is usually a negative value) */
1769 if (lastDescender
!=INT_MIN
)
1771 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1774 /* return size values */
1778 /* return other parameters */
1781 if(lastDescender
!=INT_MIN
)
1783 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1791 /* currently no idea how to calculate this! */
1792 if (externalLeading
) *externalLeading
= 0;
1797 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
1799 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1801 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1803 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1805 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1809 if (width
) *width
= paper
->widthMM
;
1810 if (height
) *height
= paper
->heightMM
;
1814 if (width
) *width
= 210;
1815 if (height
) *height
= 297;
1819 // Determine the Default Postscript Previewer
1820 // available on the platform
1821 #if defined(__SUN__) && defined(__XVIEW__)
1822 // OpenWindow/NeWS's Postscript Previewer
1823 # define PS_VIEWER_PROG "pageview"
1824 #elif defined(__VMS__)
1825 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
1826 #elif defined(__SGI__)
1827 // SGI's Display Postscript Previewer
1828 //# define PS_VIEWER_PROG "dps"
1829 # define PS_VIEWER_PROG "xpsview"
1830 #elif defined(__X__) || defined(__WXGTK__)
1831 // Front-end to ghostscript
1832 # define PS_VIEWER_PROG "ghostview"
1834 // Windows ghostscript/ghostview
1835 # define PS_VIEWER_PROG NULL
1838 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
1840 #if !USE_SHARED_LIBRARY
1841 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
1842 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
1845 // Redundant now I think
1847 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
1849 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
1850 const wxPoint
& pos
, const wxSize
& size
, long style
):
1851 wxDialog(parent
, -1, title
, pos
, size
, style
)
1853 wxBeginBusyCursor();
1858 *orientation
= new wxString
[2],
1859 *print_modes
= new wxString
[3];
1861 long wx_printer_translate_x
, wx_printer_translate_y
;
1862 double wx_printer_scale_x
, wx_printer_scale_y
;
1864 orientation
[0] = _("Portrait");
1865 orientation
[1] = _("Landscape");
1867 print_modes
[0] = _("Send to Printer");
1868 print_modes
[1] = _("Print to File");
1869 print_modes
[2] = _("Preview Only");
1873 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
1874 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
1875 okBut
->SetDefault();
1878 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1879 (void) new wxStaticText( this, -1, _("Printer Command: "),
1881 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
1882 wxPoint(100, yPos
), wxSize(100, -1) );
1884 (void) new wxStaticText( this, -1, _("Printer Options: "),
1885 wxPoint(210, yPos
) );
1886 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
1887 wxPoint(305, yPos
), wxSize(150, -1) );
1893 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
1894 2,orientation
,2,wxRA_SPECIFY_ROWS
);
1895 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
1897 // @@@ Configuration hook
1898 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
1899 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
1901 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
1903 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
1904 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
1906 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
1908 wxSize(-1,-1), features
,
1909 print_modes
, features
, wxRA_SPECIFY_ROWS
);
1912 radio1
->Enable(0, FALSE
);
1913 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
1914 radio1
->Enable(2, FALSE
);
1917 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
1918 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1919 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1921 sprintf (buf
, "%.2f", wx_printer_scale_x
);
1924 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
1925 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1927 sprintf (buf
, "%.2f", wx_printer_scale_y
);
1928 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
1929 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1933 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
1934 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
1935 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1937 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
1938 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
1939 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1943 delete[] orientation
;
1944 delete[] print_modes
;
1949 int wxPostScriptPrintDialog::ShowModal ()
1951 if ( wxDialog::ShowModal() == wxID_OK
)
1953 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
1954 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
1955 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
1956 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
1957 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
1958 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
1959 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
1960 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
1962 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
1963 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
1964 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
1965 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
1968 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
1969 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
1972 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
1975 switch ( radio1
->GetSelection() ) {
1976 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
1977 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
1978 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
1987 // PostScript printer settings
1988 // RETAINED FOR BACKWARD COMPATIBILITY
1989 void wxSetPrinterCommand(const char *cmd
)
1991 wxThePrintSetupData
->SetPrinterCommand(cmd
);
1994 void wxSetPrintPreviewCommand(const char *cmd
)
1996 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
1999 void wxSetPrinterOptions(const char *flags
)
2001 wxThePrintSetupData
->SetPrinterOptions(flags
);
2004 void wxSetPrinterFile(const char *f
)
2006 wxThePrintSetupData
->SetPrinterFile(f
);
2009 void wxSetPrinterOrientation(int orient
)
2011 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2014 void wxSetPrinterScaling(double x
, double y
)
2016 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2019 void wxSetPrinterTranslation(long x
, long y
)
2021 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2024 // 1 = Preview, 2 = print to file, 3 = send to printer
2025 void wxSetPrinterMode(int mode
)
2027 wxThePrintSetupData
->SetPrinterMode(mode
);
2030 void wxSetAFMPath(const char *f
)
2032 wxThePrintSetupData
->SetAFMPath(f
);
2035 // Get current values
2036 char *wxGetPrinterCommand()
2038 return wxThePrintSetupData
->GetPrinterCommand();
2041 char *wxGetPrintPreviewCommand()
2043 return wxThePrintSetupData
->GetPrintPreviewCommand();
2046 char *wxGetPrinterOptions()
2048 return wxThePrintSetupData
->GetPrinterOptions();
2051 char *wxGetPrinterFile()
2053 return wxThePrintSetupData
->GetPrinterFile();
2056 int wxGetPrinterOrientation()
2058 return wxThePrintSetupData
->GetPrinterOrientation();
2061 void wxGetPrinterScaling(double* x
, double* y
)
2063 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2066 void wxGetPrinterTranslation(long *x
, long *y
)
2068 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2071 int wxGetPrinterMode()
2073 return wxThePrintSetupData
->GetPrinterMode();
2076 char *wxGetAFMPath()
2078 return wxThePrintSetupData
->GetAFMPath();
2085 wxPrintSetupData::wxPrintSetupData()
2087 printerCommand
= (char *) NULL
;
2088 previewCommand
= (char *) NULL
;
2089 printerFlags
= (char *) NULL
;
2090 printerOrient
= PS_PORTRAIT
;
2091 printerScaleX
= (double)1.0;
2092 printerScaleY
= (double)1.0;
2093 printerTranslateX
= 0;
2094 printerTranslateY
= 0;
2095 // 1 = Preview, 2 = print to file, 3 = send to printer
2097 afmPath
= (char *) NULL
;
2098 paperName
= (char *) NULL
;
2100 printerFile
= (char *) NULL
;
2103 wxPrintSetupData::~wxPrintSetupData()
2106 delete[] printerCommand
;
2108 delete[] previewCommand
;
2110 delete[] printerFlags
;
2116 delete[] printerFile
;
2119 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2121 if (cmd
== printerCommand
)
2125 delete[] printerCommand
;
2127 printerCommand
= copystring(cmd
);
2129 printerCommand
= (char *) NULL
;
2132 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2134 if (cmd
== previewCommand
)
2138 delete[] previewCommand
;
2140 previewCommand
= copystring(cmd
);
2142 previewCommand
= (char *) NULL
;
2145 void wxPrintSetupData::SetPaperName(const char *name
)
2147 if (name
== paperName
)
2153 paperName
= copystring(name
);
2155 paperName
= (char *) NULL
;
2158 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2160 if (printerFlags
== flags
)
2164 delete[] printerFlags
;
2166 printerFlags
= copystring(flags
);
2168 printerFlags
= (char *) NULL
;
2171 void wxPrintSetupData::SetPrinterFile(const char *f
)
2173 if (f
== printerFile
)
2177 delete[] printerFile
;
2179 printerFile
= copystring(f
);
2181 printerFile
= (char *) NULL
;
2184 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2186 printerOrient
= orient
;
2189 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2195 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2197 printerTranslateX
= x
;
2198 printerTranslateY
= y
;
2201 // 1 = Preview, 2 = print to file, 3 = send to printer
2202 void wxPrintSetupData::SetPrinterMode(int mode
)
2207 void wxPrintSetupData::SetAFMPath(const char *f
)
2215 afmPath
= copystring(f
);
2217 afmPath
= (char *) NULL
;
2220 void wxPrintSetupData::SetColour(bool col
)
2225 // Get current values
2226 char *wxPrintSetupData::GetPrinterCommand()
2228 return printerCommand
;
2231 char *wxPrintSetupData::GetPrintPreviewCommand()
2233 return previewCommand
;
2236 char *wxPrintSetupData::GetPrinterOptions()
2238 return printerFlags
;
2241 char *wxPrintSetupData::GetPrinterFile()
2246 char *wxPrintSetupData::GetPaperName()
2251 int wxPrintSetupData::GetPrinterOrientation()
2253 return printerOrient
;
2256 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2262 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2264 *x
= printerTranslateX
;
2265 *y
= printerTranslateY
;
2268 int wxPrintSetupData::GetPrinterMode()
2273 char *wxPrintSetupData::GetAFMPath()
2278 bool wxPrintSetupData::GetColour()
2283 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2285 SetPrinterCommand(data
.GetPrinterCommand());
2286 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2287 SetPrinterOptions(data
.GetPrinterOptions());
2289 data
.GetPrinterTranslation(&x
, &y
);
2290 SetPrinterTranslation(x
, y
);
2293 data
.GetPrinterScaling(&x1
, &y1
);
2294 SetPrinterScaling(x1
, y1
);
2296 SetPrinterOrientation(data
.GetPrinterOrientation());
2297 SetPrinterMode(data
.GetPrinterMode());
2298 SetAFMPath(data
.GetAFMPath());
2299 SetPaperName(data
.GetPaperName());
2300 SetColour(data
.GetColour());
2303 void wxInitializePrintSetupData(bool init
)
2307 wxThePrintSetupData
= new wxPrintSetupData
;
2309 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2310 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2311 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2312 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2314 // Could have a .ini file to read in some defaults
2315 // - and/or use environment variables, e.g. WXWIN
2317 wxThePrintSetupData
->SetPrinterCommand("print");
2318 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2319 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2322 wxThePrintSetupData
->SetPrinterCommand("print");
2323 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2324 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2326 #if !defined(__VMS__) && !defined(__WXMSW__)
2327 wxThePrintSetupData
->SetPrinterCommand("lpr");
2328 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2329 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2334 if (wxThePrintSetupData
)
2335 delete wxThePrintSetupData
;
2336 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2340 // A module to allow initialization/cleanup of PostScript-related
2341 // things without calling these functions from app.cpp.
2343 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2345 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2347 wxPostScriptModule() {}
2352 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2355 * Initialization/cleanup module
2358 bool wxPostScriptModule::OnInit()
2360 wxInitializePrintSetupData();
2365 void wxPostScriptModule::OnExit()
2367 wxInitializePrintSetupData(FALSE
);