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"
72 //-----------------------------------------------------------------------------
73 // start and end of document/page
74 //-----------------------------------------------------------------------------
76 static const char *wxPostScriptHeaderEllipse
= "\
77 /ellipsedict 8 dict def\n\
78 ellipsedict /mtrx matrix put\n\
82 /startangle exch def\n\
87 /savematrix mtrx currentmatrix def\n\
90 0 0 1 startangle endangle arc\n\
91 savematrix setmatrix\n\
96 static const char *wxPostScriptHeaderEllipticArc
= "\
97 /ellipticarcdict 8 dict def\n\
98 ellipticarcdict /mtrx matrix put\n\
100 { ellipticarcdict begin\n\
102 /endangle exch def\n\
103 /startangle exch def\n\
108 /savematrix mtrx currentmatrix def\n\
111 do_fill { 0 0 moveto } if\n\
112 0 0 1 startangle endangle arc\n\
113 savematrix setmatrix\n\
114 do_fill { fill }{ stroke } ifelse\n\
118 static const char *wxPostScriptHeaderSpline
= "\
119 /DrawSplineSection {\n\
126 /xa x1 x2 x1 sub 0.666667 mul add def\n\
127 /ya y1 y2 y1 sub 0.666667 mul add def\n\
128 /xb x3 x2 x3 sub 0.666667 mul add def\n\
129 /yb y3 y2 y3 sub 0.666667 mul add def\n\
131 xa ya xb yb x3 y3 curveto\n\
135 static const char *wxPostScriptHeaderColourImage
= "\
136 % define 'colorimage' if it isn't defined\n\
137 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
139 /colorimage where % do we know about 'colorimage'?\n\
140 { pop } % yes: pop off the 'dict' returned\n\
141 { % no: define one\n\
142 /colortogray { % define an RGB->I function\n\
143 /rgbdata exch store % call input 'rgbdata'\n\
144 rgbdata length 3 idiv\n\
145 /npixls exch store\n\
147 0 1 npixls 1 sub {\n\
149 rgbdata rgbindx get 20 mul % Red\n\
150 rgbdata rgbindx 1 add get 32 mul % Green\n\
151 rgbdata rgbindx 2 add get 12 mul % Blue\n\
152 add add 64 idiv % I = .5G + .31R + .18B\n\
154 /rgbindx rgbindx 3 add store\n\
156 grays 0 npixls getinterval\n\
159 % Utility procedure for colorimage operator.\n\
160 % This procedure takes two procedures off the\n\
161 % stack and merges them into a single procedure.\n\
163 /mergeprocs { % def\n\
182 /colorimage { % def\n\
183 pop pop % remove 'false 3' operands\n\
184 {colortogray} mergeprocs\n\
187 } ifelse % end of 'false' case\n\
190 static char wxPostScriptHeaderReencodeISO1
[] =
192 "dup dup findfont dup length dict begin\n"
193 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
194 "/Encoding ISOLatin1Encoding def\n"
195 "currentdict end definefont\n"
197 "/ISOLatin1Encoding [\n"
198 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
199 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
200 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
201 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
202 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
203 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
204 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
205 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
206 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
207 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
208 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
209 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
210 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
211 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
212 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
214 static char wxPostScriptHeaderReencodeISO2
[] =
215 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
216 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
217 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
218 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
219 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
220 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
221 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
222 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
223 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
224 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
225 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
226 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
227 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
228 "/yacute/thorn/ydieresis\n"
231 //-------------------------------------------------------------------------------
233 //-------------------------------------------------------------------------------
235 wxPostScriptDC::wxPostScriptDC ()
237 m_pstream
= (ofstream
*) NULL
;
247 m_underlinePosition
= 0.0;
248 m_underlineThickness
= 0.0;
250 m_signX
= 1; // default x-axis left to right
251 m_signY
= -1; // default y-axis bottom up -> top down
254 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
256 m_pstream
= (ofstream
*) NULL
;
266 m_underlinePosition
= 0.0;
267 m_underlineThickness
= 0.0;
269 m_signX
= 1; // default x-axis left to right
270 m_signY
= -1; // default y-axis bottom up -> top down
272 Create(file
, interactive
, parent
);
275 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
277 m_isInteractive
= interactive
;
283 // Can only send to file in Windows
284 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
289 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
299 wxPostScriptDC::~wxPostScriptDC ()
301 if (m_pstream
) delete m_pstream
;
304 bool wxPostScriptDC::Ok() const
309 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
311 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
312 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
313 m_ok
= (dialog
.ShowModal () == wxID_OK
);
315 if (!m_ok
) return FALSE
;
317 if ((m_filename
== "") &&
318 (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
||
319 wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
323 wxThePrintSetupData
->SetPrinterFile("preview");
325 // For PS_PRINTER action this depends on a Unix-style print spooler
326 // since the wx_printer_file can be destroyed during a session
327 // @@@ TODO: a Windows-style answer for non-Unix
329 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
331 strcpy (tmp
, "/tmp/preview_");
332 strcat (tmp
, userId
);
333 wxThePrintSetupData
->SetPrinterFile(tmp
);
336 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
337 strcat (tmp2
, ".ps");
338 wxThePrintSetupData
->SetPrinterFile(tmp2
);
341 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
343 char *file
= wxSaveFileSelector (_("PostScript"), "ps");
349 wxThePrintSetupData
->SetPrinterFile(file
);
357 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
359 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
361 if (m_clipping
) return;
363 wxDC::SetClippingRegion( x
, y
, w
, h
);
366 *m_pstream
<< "gsave\n"
368 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
369 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
370 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
371 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
372 << "closepath clip newpath\n";
375 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
379 void wxPostScriptDC::DestroyClippingRegion()
381 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
383 wxDC::DestroyClippingRegion();
388 *m_pstream
<< "grestore\n";
392 void wxPostScriptDC::Clear()
394 wxFAIL_MSG( "wxPostScriptDC::Clear not implemented." );
397 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
399 wxFAIL_MSG( "wxPostScriptDC::FloodFill not implemented." );
402 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
404 wxFAIL_MSG( "wxPostScriptDC::GetPixel not implemented." );
408 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
410 wxFAIL_MSG( "wxPostScriptDC::CrossHair not implemented." );
413 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
415 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
417 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
421 *m_pstream
<< "newpath\n"
422 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
423 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
426 CalcBoundingBox( x1
, y1
);
427 CalcBoundingBox( x2
, y2
);
430 #define RAD2DEG 57.29577951308
432 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
434 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
438 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
439 double alpha1
, alpha2
;
441 if (x1
== x2
&& y1
== y2
)
445 } else if (radius
== 0.0)
447 alpha1
= alpha2
= 0.0;
450 alpha1
= (x1
- xc
== 0) ?
451 (y1
- yc
< 0) ? 90.0 : -90.0 :
452 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
453 alpha2
= (x2
- xc
== 0) ?
454 (y2
- yc
< 0) ? 90.0 : -90.0 :
455 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
457 while (alpha1
<= 0) alpha1
+= 360;
458 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
459 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
460 while (alpha2
> 360) alpha2
-= 360;
462 if (m_brush
.GetStyle() != wxTRANSPARENT
)
465 *m_pstream
<< "newpath\n"
466 << XLOG2DEV(xc
) << " "
467 << YLOG2DEV(yc
) << " "
468 << XLOG2DEVREL(radius
) << " "
469 << YLOG2DEVREL(radius
) << " "
471 << alpha2
<< " ellipse\n"
472 << XLOG2DEV(xc
) << " "
473 << YLOG2DEV(yc
) << " lineto\n"
478 if (m_pen
.GetStyle() != wxTRANSPARENT
)
481 *m_pstream
<< "newpath\n"
482 << XLOG2DEV(xc
) << " "
483 << YLOG2DEV(yc
) << " "
484 << XLOG2DEVREL(radius
) << " "
485 << YLOG2DEVREL(radius
) << " "
487 << alpha2
<< " ellipse\n"
491 CalcBoundingBox( xc
-radius
, yc
-radius
);
492 CalcBoundingBox( xc
+radius
, yc
+radius
);
495 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
497 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
499 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
500 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
506 DrawEllipse(x
,y
,w
,h
);
510 if (m_brush
.GetStyle () != wxTRANSPARENT
)
514 *m_pstream
<< "newpath\n"
515 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
516 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
517 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
519 CalcBoundingBox( x
,y
);
520 CalcBoundingBox( x
+w
, y
+h
);
523 if (m_pen
.GetStyle () != wxTRANSPARENT
)
527 *m_pstream
<< "newpath\n"
528 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
529 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
530 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
532 CalcBoundingBox( x
, y
);
533 CalcBoundingBox( x
+w
, y
+h
);
537 void wxPostScriptDC::DrawPoint (long x
, long y
)
539 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
541 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
545 *m_pstream
<< "newpath\n"
546 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
547 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
550 CalcBoundingBox( x
, y
);
553 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
555 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
559 if (m_brush
.GetStyle () != wxTRANSPARENT
)
563 *m_pstream
<< "newpath\n";
565 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
566 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
567 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
568 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
570 for (int i
= 1; i
< n
; i
++)
572 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
573 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
574 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
575 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
577 *m_pstream
<< "fill\n";
580 if (m_pen
.GetStyle () != wxTRANSPARENT
)
584 *m_pstream
<< "newpath\n";
586 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
587 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
588 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
589 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
591 for (int i
= 1; i
< n
; i
++)
593 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
594 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
595 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
596 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
599 *m_pstream
<< "stroke\n";
603 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
605 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
607 if (m_pen
.GetStyle() == wxTRANSPARENT
)
615 for ( i
=0; i
<n
; i
++ )
617 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
620 *m_pstream
<< "newpath\n"
621 << XLOG2DEV(points
[0].x
+xoffset
) << " "
622 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
624 for (i
= 1; i
< n
; i
++)
626 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
627 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
630 *m_pstream
<< "stroke\n";
633 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
635 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
637 if (m_brush
.GetStyle () != wxTRANSPARENT
)
641 *m_pstream
<< "newpath\n"
642 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
643 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
644 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
645 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
649 CalcBoundingBox( x
, y
);
650 CalcBoundingBox( x
+ width
, y
+ height
);
653 if (m_pen
.GetStyle () != wxTRANSPARENT
)
657 *m_pstream
<< "newpath\n"
658 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
659 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
660 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
661 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
665 CalcBoundingBox( x
, y
);
666 CalcBoundingBox( x
+ width
, y
+ height
);
670 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
672 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
676 // Now, a negative radius is interpreted to mean
677 // 'the proportion of the smallest X or Y dimension'
678 double smallest
= 0.0;
683 radius
= (-radius
* smallest
);
686 long rad
= (long) radius
;
688 if (m_brush
.GetStyle () != wxTRANSPARENT
)
692 // Draw rectangle anticlockwise
693 *m_pstream
<< "newpath\n"
694 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
695 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
696 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
697 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
698 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
699 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
700 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
701 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
705 CalcBoundingBox( x
, y
);
706 CalcBoundingBox( x
+ width
, y
+ height
);
709 if (m_pen
.GetStyle () != wxTRANSPARENT
)
713 // Draw rectangle anticlockwise
714 *m_pstream
<< "newpath\n"
715 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
716 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
717 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
718 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
719 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
720 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
721 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
722 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
726 CalcBoundingBox( x
, y
);
727 CalcBoundingBox( x
+ width
, y
+ height
);
731 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
733 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
735 if (m_brush
.GetStyle () != wxTRANSPARENT
)
739 *m_pstream
<< "newpath\n"
740 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
741 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
744 CalcBoundingBox( x
- width
, y
- height
);
745 CalcBoundingBox( x
+ width
, y
+ height
);
748 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
752 *m_pstream
<< "newpath\n"
753 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
754 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
757 CalcBoundingBox( x
- width
, y
- height
);
758 CalcBoundingBox( x
+ width
, y
+ height
);
762 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
764 DrawBitmap( icon
, x
, y
, TRUE
);
767 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool WXUNUSED(useMask
) )
769 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
771 if (!bitmap
.Ok()) return;
773 wxImage
image( bitmap
);
775 if (!image
.Ok()) return;
777 int ww
= XLOG2DEVREL(image
.GetWidth());
778 int hh
= YLOG2DEVREL(image
.GetHeight());
780 image
= image
.Scale( ww
, hh
);
782 if (!image
.Ok()) return;
784 int xx
= XLOG2DEV(x
);
785 int yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
787 *m_pstream
<< "/origstate save def\n"
789 << "/pix " << ww
<< " string def\n"
790 << "/grays " << ww
<< " string def\n"
791 << "/npixels 0 def\n"
792 << "/rgbindx 0 def\n"
793 << xx
<< " " << yy
<< " translate\n"
794 << ww
<< " " << hh
<< " scale\n"
795 << ww
<< " " << hh
<< " 8\n"
796 << "[" << ww
<< " 0 0 " << (-hh
) << " 0 " << hh
<< "]\n"
797 << "{currentfile pix readhexstring pop}\n"
798 << "false 3 colorimage\n";
800 for (int j
= 0; j
< hh
; j
++)
802 for (int i
= 0; i
< ww
; i
++)
806 wxDecToHex( image
.GetRed(i
,j
), buffer
);
807 *m_pstream
<< buffer
;
808 wxDecToHex( image
.GetGreen(i
,j
), buffer
);
809 *m_pstream
<< buffer
;
810 wxDecToHex( image
.GetBlue(i
,j
), buffer
);
811 *m_pstream
<< buffer
;
816 *m_pstream
<< "end\n";
817 *m_pstream
<< "origstate restore\n";
821 void wxPostScriptDC::SetFont (const wxFont
& font
)
823 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
825 if (!font
.Ok()) return;
830 char *name
= wxTheFontNameDirectory
->GetPostScriptName( m_font
.GetFamily(),
833 if (!name
) name
= "Times-Roman";
835 *m_pstream
<< "/" << name
<< " reencodeISO def\n"
836 << "/" << name
<< " findfont\n"
837 << YLOG2DEVREL(font
.GetPointSize())
838 << " scalefont setfont\n";
842 const char *style
= "";
843 int Style
= m_font
.GetStyle ();
844 int Weight
= m_font
.GetWeight ();
846 switch (m_font
.GetFamily ())
856 // name = "/Times-Roman";
857 name
= "/Times"; // Altered by EDZ
860 name
= "/Zapf-Chancery-MediumItalic";
865 case wxDEFAULT
: // Sans Serif Font
866 name
= "/LucidaSans";
869 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
871 if (m_font
.GetFamily () == wxROMAN
)
876 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
879 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
881 if (m_font
.GetFamily () == wxROMAN
)
886 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
888 if (m_font
.GetFamily () == wxROMAN
)
889 style
= "-BoldItalic";
891 style
= "-BoldOblique";
893 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
895 if (m_font
.GetFamily () == wxROMAN
)
900 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
902 if (m_font
.GetFamily () == wxROMAN
)
903 style
= "-BoldItalic";
905 style
= "-BoldOblique";
912 *m_pstream
<< buf
<< " findfont\n";
913 // *m_pstream << (m_font.GetPointSize() * m_scaleFactor) << " scalefont setfont\n";
914 // No scale factor in this implementation?
915 *m_pstream
<< (m_font
.GetPointSize()) << " scalefont setfont\n";
919 void wxPostScriptDC::SetPen( const wxPen
& pen
)
921 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
923 if (!pen
.Ok()) return;
925 int oldStyle
= m_pen
.GetStyle();
929 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
932 Line style - WRONG: 2nd arg is OFFSET
934 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
935 operator correctly. You should look-up this in the Red Book: the 2nd parame-
936 ter is not number of values in the array of the first one, but an offset
937 into this description of the pattern. I mean a real *offset* not index
938 into array. I.e. If the command is [3 4] 1 setdash is used, then there
939 will be first black line *2* units long, then space 4 units, then the
940 pattern of *3* units black, 4 units space will be repeated.
943 static const char *dotted
= "[2 5] 2";
944 static const char *short_dashed
= "[4 4] 2";
945 static const char *long_dashed
= "[4 8] 2";
946 static const char *dotted_dashed
= "[6 6 2 6] 4";
948 const char *psdash
= (char *) NULL
;
949 switch (m_pen
.GetStyle ())
951 case wxDOT
: psdash
= dotted
; break;
952 case wxSHORT_DASH
: psdash
= short_dashed
; break;
953 case wxLONG_DASH
: psdash
= long_dashed
; break;
954 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
957 default: psdash
= "[] 0"; break;
960 if (oldStyle
!= m_pen
.GetStyle())
962 *m_pstream
<< psdash
<< " setdash\n";
966 unsigned char red
= m_pen
.GetColour().Red();
967 unsigned char blue
= m_pen
.GetColour().Blue();
968 unsigned char green
= m_pen
.GetColour().Green();
972 // Anything not white is black
973 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
974 && green
== (unsigned char) 255))
976 red
= (unsigned char) 0;
977 green
= (unsigned char) 0;
978 blue
= (unsigned char) 0;
984 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
986 long redPS
= (long) (((int) red
) / 255.0);
987 long bluePS
= (long) (((int) blue
) / 255.0);
988 long greenPS
= (long) (((int) green
) / 255.0);
990 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
993 m_currentBlue
= blue
;
994 m_currentGreen
= green
;
998 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1000 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1002 if (!brush
.Ok()) return;
1007 unsigned char red
= m_brush
.GetColour ().Red ();
1008 unsigned char blue
= m_brush
.GetColour ().Blue ();
1009 unsigned char green
= m_brush
.GetColour ().Green ();
1013 // Anything not black is white
1014 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
1015 && green
== (unsigned char) 0))
1017 red
= (unsigned char) 255;
1018 green
= (unsigned char) 255;
1019 blue
= (unsigned char) 255;
1025 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1027 long redPS
= (long) (((int) red
) / 255.0);
1028 long bluePS
= (long) (((int) blue
) / 255.0);
1029 long greenPS
= (long) (((int) green
) / 255.0);
1030 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1032 m_currentBlue
= blue
;
1033 m_currentGreen
= green
;
1037 void wxPostScriptDC::DrawText( const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
) )
1039 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1043 if (m_textForegroundColour
.Ok ())
1045 unsigned char red
= m_textForegroundColour
.Red ();
1046 unsigned char blue
= m_textForegroundColour
.Blue ();
1047 unsigned char green
= m_textForegroundColour
.Green ();
1051 // Anything not white is black
1052 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
1053 && green
== (unsigned char) 255))
1055 red
= (unsigned char) 0;
1056 green
= (unsigned char) 0;
1057 blue
= (unsigned char) 0;
1061 // maybe setgray here ?
1063 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1065 long redPS
= (long) (((int) red
) / 255.0);
1066 long bluePS
= (long) (((int) blue
) / 255.0);
1067 long greenPS
= (long) (((int) green
) / 255.0);
1068 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1071 m_currentBlue
= blue
;
1072 m_currentGreen
= green
;
1076 int size
= m_font
.GetPointSize();
1078 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
1079 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
1082 int len
= strlen ((char *)(const char *)text
);
1084 for (i
= 0; i
< len
; i
++)
1086 int c
= (unsigned char) text
[i
];
1087 if ( c
== ')' || c
== '(' || c
== '\\')
1089 *m_pstream
<< "\\" << (char) c
;
1091 else if ( c
>= 128 )
1093 // Cope with character codes > 127
1095 sprintf(tmp
, "\\%o", c
);
1099 *m_pstream
<< (char) c
;
1102 *m_pstream
<< ")" << " show\n";
1104 if (m_font
.GetUnderlined())
1106 long uy
= (long)(y
+ size
- m_underlinePosition
);
1108 GetTextExtent(text
, &w
, &h
);
1110 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
1112 << (long)m_underlineThickness
<< " setlinewidth "
1113 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
1114 << " lineto stroke grestore\n";
1117 CalcBoundingBox( x
, y
);
1118 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1122 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1124 m_backgroundBrush
= brush
;
1127 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1129 wxFAIL_MSG( "wxPostScriptDC::SetLogicalFunction not implemented." );
1132 void wxPostScriptDC::DrawSpline( wxList
*points
)
1134 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1138 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1141 wxNode
*node
= points
->First();
1142 p
= (wxPoint
*)node
->Data();
1146 node
= node
->Next();
1147 p
= (wxPoint
*)node
->Data();
1150 x3
= a
= (double)(x1
+ c
) / 2;
1151 y3
= b
= (double)(y1
+ d
) / 2;
1153 *m_pstream
<< "newpath "
1154 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
1155 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
1157 CalcBoundingBox( (long)x1
, (long)y1
);
1158 CalcBoundingBox( (long)x3
, (long)y3
);
1160 while ((node
= node
->Next()) != NULL
)
1162 q
= (wxPoint
*)node
->Data();
1170 x3
= (double)(x2
+ c
) / 2;
1171 y3
= (double)(y2
+ d
) / 2;
1172 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
1173 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
1174 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
1176 CalcBoundingBox( (long)x1
, (long)y1
);
1177 CalcBoundingBox( (long)x3
, (long)y3
);
1181 At this point, (x2,y2) and (c,d) are the position of the
1182 next-to-last and last point respectively, in the point list
1185 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1188 long wxPostScriptDC::GetCharWidth ()
1190 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1191 return (long) (GetCharHeight() * 72.0 / 120.0);
1195 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1197 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1199 m_signX
= (xLeftRight
? 1 : -1);
1200 m_signY
= (yBottomUp
? 1 : -1);
1202 // FIXME there is no such function in MSW
1204 ComputeScaleAndOrigin();
1208 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1210 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1216 wxDC::SetDeviceOrigin( x
, h
-y
);
1219 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1221 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1223 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1225 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1227 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1231 if (width
) *width
= paper
->widthPixels
;
1232 if (height
) *height
= paper
->heightPixels
;
1236 if (width
) *width
= 595;
1237 if (height
) *height
= 842;
1241 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1243 wxCHECK_MSG( m_ok
, FALSE
, "invalid postscript dc" );
1245 if (m_filename
== "")
1247 m_filename
= wxGetTempFileName("ps");
1248 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1253 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1256 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1258 if (!m_pstream
|| !m_pstream
->good())
1260 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1267 SetBrush( *wxBLACK_BRUSH
);
1268 SetPen( *wxBLACK_PEN
);
1269 SetBackground( *wxWHITE_BRUSH
);
1270 SetTextForeground( *wxBLACK
);
1272 // set origin according to paper size
1273 SetDeviceOrigin( 0,0 );
1281 void wxPostScriptDC::EndDoc ()
1283 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1288 *m_pstream
<< "grestore\n";
1294 m_pstream
= (ofstream
*) NULL
;
1297 char *header_file
= wxGetTempFileName("ps");
1299 m_pstream
= new ofstream( header_file
);
1301 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1302 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1303 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1304 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1307 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1309 *m_pstream
<< "%%For: " << (char *)userID
;
1311 if (wxGetUserName(userName
, sizeof(userName
)))
1312 *m_pstream
<< " (" << (char *)userName
<< ")";
1315 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1317 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1320 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1322 long wx_printer_translate_x
, wx_printer_translate_y
;
1323 double wx_printer_scale_x
, wx_printer_scale_y
;
1324 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1325 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1327 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1329 *m_pstream
<< "%%Orientation: Landscape\n";
1333 *m_pstream
<< "%%Orientation: Portrait\n";
1336 // Compute the bounding box. Note that it is in the default user
1337 // coordinate system, thus we have to convert the values.
1338 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1339 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1340 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1341 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1343 // If we're landscape, our sense of "x" and "y" is reversed.
1344 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1347 tmp
= llx
; llx
= lly
; lly
= tmp
;
1348 tmp
= urx
; urx
= ury
; ury
= tmp
;
1350 // We need either the two lines that follow, or we need to subtract
1351 // min_x from real_translate_y, which is commented out below.
1352 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1353 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1356 // The Adobe specifications call for integers; we round as to make
1357 // the bounding larger.
1358 *m_pstream
<< "%%BoundingBox: "
1359 << floor((double)llx
) << " " << floor((double)lly
) << " "
1360 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1361 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1362 *m_pstream
<< "%%EndComments\n\n";
1364 // To check the correctness of the bounding box, postscript commands
1365 // to draw a box corresponding to the bounding box are generated below.
1366 // But since we typically don't want to print such a box, the postscript
1367 // commands are generated within comments. These lines appear before any
1368 // adjustment of scale, rotation, or translation, and hence are in the
1369 // default user coordinates.
1370 *m_pstream
<< "% newpath\n";
1371 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1372 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1373 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1374 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1376 *m_pstream
<< "%%BeginProlog\n";
1377 *m_pstream
<< wxPostScriptHeaderEllipse
;
1378 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1379 *m_pstream
<< wxPostScriptHeaderColourImage
;
1380 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1381 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1383 if (wxPostScriptHeaderSpline
)
1384 *m_pstream
<< wxPostScriptHeaderSpline
;
1385 *m_pstream
<< "%%EndProlog\n";
1388 m_pstream
= (ofstream
*) NULL
;
1390 char *tmp_file
= wxGetTempFileName("ps");
1392 // Paste header Before wx_printer_file
1393 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1394 wxRemoveFile (header_file
);
1395 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1396 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1398 #if defined(__X__) || defined(__WXGTK__)
1401 switch (wxThePrintSetupData
->GetPrinterMode()) {
1405 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1406 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1407 argv
[2] = (char *) NULL
;
1408 wxExecute (argv
, TRUE
);
1409 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1417 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1419 // !SM! If we simply assign to argv[1] here, if printer options
1420 // are blank, we get an annoying and confusing message from lpr.
1421 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1423 argv
[argc
++] = opts
;
1425 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1426 argv
[argc
++] = (char *) NULL
;
1427 wxExecute (argv
, TRUE
);
1428 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1439 void wxPostScriptDC::StartPage ()
1441 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1443 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1445 // *m_pstream << "matrix currentmatrix\n";
1447 // Added by Chris Breeze
1449 // Each page starts with an "initgraphics" which resets the
1450 // transformation and so we need to reset the origin
1451 // (and rotate the page for landscape printing)
1454 m_scaleFactor = 1.0;
1455 m_logicalOriginX = 0;
1456 m_logicalOriginY = 0;
1460 long translate_x
, translate_y
;
1461 double scale_x
, scale_y
;
1462 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1463 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1465 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1467 translate_y
-= m_maxY
;
1468 *m_pstream
<< "90 rotate\n";
1471 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1472 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1475 void wxPostScriptDC::EndPage ()
1477 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1479 *m_pstream
<< "showpage\n";
1482 bool wxPostScriptDC::Blit( long WXUNUSED(xdest
), long WXUNUSED(ydest
),
1483 long WXUNUSED(fwidth
), long WXUNUSED(fheight
),
1484 wxDC
*WXUNUSED(source
),
1485 long WXUNUSED(xsrc
), long WXUNUSED(ysrc
),
1486 int WXUNUSED(rop
), bool WXUNUSED(useMask
) )
1488 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, "invalid postscript dc" );
1490 wxFAIL_MSG( "wxPostScriptDC::Blit no yet implemented." );
1495 long wxPostScriptDC::GetCharHeight ()
1498 return m_font
.GetPointSize();
1503 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1504 long *descent
, long *externalLeading
, wxFont
*theFont
,
1505 bool WXUNUSED(use16
))
1507 // if (!m_pstream) return;
1509 wxFont
*fontToUse
= theFont
;
1511 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1513 #if !USE_AFM_FOR_POSTSCRIPT
1514 // Provide a VERY rough estimate (avoid using it)
1515 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1516 // font such as Courier (aka wxMODERN)
1520 height
= fontToUse
->GetPointSize();
1522 *x
= strlen (string
) * height
* 72 / 120;
1523 *y
= (long) (height
* 1.32); // allow for descender
1527 if (externalLeading
)
1528 *externalLeading
= 0;
1530 // +++++ start of contributed code +++++
1532 // ************************************************************
1533 // method for calculating string widths in postscript:
1534 // read in the AFM (adobe font metrics) file for the
1535 // actual font, parse it and extract the character widths
1536 // and also the descender. this may be improved, but for now
1537 // it works well. the AFM file is only read in if the
1538 // font is changed. this may be chached in the future.
1539 // calls to GetTextExtent with the font unchanged are rather
1542 // for each font and style used there is an AFM file necessary.
1543 // currently i have only files for the roman font family.
1544 // i try to get files for the other ones!
1546 // CAVE: the size of the string is currently always calculated
1547 // in 'points' (1/72 of an inch). this should later on be
1548 // changed to depend on the mapping mode.
1549 // CAVE: the path to the AFM files must be set before calling this
1550 // function. this is usually done by a call like the following:
1551 // wxSetAFMPath("d:\\wxw161\\afm\\");
1555 // wxPostScriptDC dc(NULL, TRUE);
1557 // wxSetAFMPath("d:\\wxw161\\afm\\");
1558 // dc.StartDoc("Test");
1561 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1562 // dc.GetTextExtent("Hallo",&w,&h);
1567 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1568 // created: 10.09.94
1569 // updated: 14.05.95
1571 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1572 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1573 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1575 // these static vars are for storing the state between calls
1576 static int lastFamily
= INT_MIN
;
1577 static int lastSize
= INT_MIN
;
1578 static int lastStyle
= INT_MIN
;
1579 static int lastWeight
= INT_MIN
;
1580 static int lastDescender
= INT_MIN
;
1581 static int lastWidths
[256]; // widths of the characters
1583 // get actual parameters
1584 const int Family
= fontToUse
->GetFamily();
1585 const int Size
= fontToUse
->GetPointSize();
1586 const int Style
= fontToUse
->GetStyle();
1587 const int Weight
= fontToUse
->GetWeight();
1589 // if we have another font, read the font-metrics
1590 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1591 // store actual values
1592 lastFamily
= Family
;
1595 lastWeight
= Weight
;
1597 // read in new font metrics **************************************
1599 // 1. construct filename ******************************************
1600 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1603 // Julian - we'll need to do this a different way now we've removed the
1604 // font directory system. Must find Stefan's original code.
1606 name
= wxTheFontNameDirectory
->GetAFMName(Family
, Weight
, Style
);
1610 // get the directory of the AFM files
1614 strcpy(afmName
,wxGetAFMPath());
1616 // 2. open and process the file **********************************
1618 // a short explanation of the AFM format:
1619 // we have for each character a line, which gives its size
1622 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1624 // that means, we have a character with ascii code 63, and width
1625 // (444/1000 * fontSize) points.
1626 // the other data is ignored for now!
1628 // when the font has changed, we read in the right AFM file and store the
1629 // character widths in an array, which is processed below (see point 3.).
1631 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1634 strcat(afmName
,name
);
1635 strcat(afmName
,".afm");
1636 FILE *afmFile
= fopen(afmName
,"r");
1638 wxLogDebug("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1639 wxLogDebug(" using approximate values\n");
1641 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1642 lastDescender
= -150; // dito.
1645 // init the widths array
1646 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1647 // some variables for holding parts of a line
1648 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1649 char upString
[30], utString
[30], encString
[50];
1652 // read in the file and parse it
1653 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1654 // A.) check for descender definition
1655 if(strncmp(line
,"Descender",9)==0){
1656 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1657 || (strcmp(descString
,"Descender")!=0)) {
1658 wxLogDebug("AFM-file '%s': line '%s' has error (bad descender)\n",
1662 // JC 1.) check for UnderlinePosition
1663 else if(strncmp(line
,"UnderlinePosition",17)==0){
1664 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1665 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1666 wxLogDebug("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1670 // JC 2.) check for UnderlineThickness
1671 else if(strncmp(line
,"UnderlineThickness",18)==0){
1672 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1673 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1674 wxLogDebug("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1678 // JC 3.) check for EncodingScheme
1679 else if(strncmp(line
,"EncodingScheme",14)==0){
1680 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1681 || (strcmp(utString
,"EncodingScheme")!=0)) {
1682 wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1685 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1687 wxLogDebug("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1688 afmName
,line
, encString
);
1691 // B.) check for char-width
1692 else if(strncmp(line
,"C ",2)==0){
1693 if(sscanf(line
,"%s%d%s%s%d",
1694 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1695 wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1697 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1698 strcmp(WXString
,"WX")!=0){
1699 wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1701 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1702 if(ascii
>=0 && ascii
<256){
1703 lastWidths
[ascii
] = cWidth
; // store width
1705 /* MATTHEW: this happens a lot; don't print an error */
1706 // wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1709 // C.) ignore other entries.
1713 // hack to compute correct values for german 'Umlaute'
1714 // the correct way would be to map the character names
1715 // like 'adieresis' to corresp. positions of ISOEnc and read
1716 // these values from AFM files, too. Maybe later ...
1717 lastWidths
[196] = lastWidths
['A']; // Ä
1718 lastWidths
[228] = lastWidths
['a']; // ä
1719 lastWidths
[214] = lastWidths
['O']; // Ö
1720 lastWidths
[246] = lastWidths
['o']; // ö
1721 lastWidths
[220] = lastWidths
['U']; // Ü
1722 lastWidths
[252] = lastWidths
['u']; // ü
1723 lastWidths
[223] = lastWidths
[251]; // ß
1726 // JC: calculate UnderlineThickness/UnderlinePosition
1727 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1728 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1730 // 3. now the font metrics are read in, calc size *******************
1731 // this is done by adding the widths of the characters in the
1732 // string. they are given in 1/1000 of the size!
1735 long height
=Size
; // by default
1737 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1738 if(lastWidths
[*p
]== INT_MIN
){
1739 wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n",
1741 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1743 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1746 // add descender to height (it is usually a negative value)
1747 if(lastDescender
!=INT_MIN
){
1748 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1751 // return size values
1755 // return other parameters
1757 if(lastDescender
!=INT_MIN
){
1758 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1764 // currently no idea how to calculate this!
1765 // if (externalLeading) *externalLeading = 0;
1766 if (externalLeading
)
1767 *externalLeading
= 0;
1769 // ----- end of contributed code -----
1773 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
1775 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1777 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1779 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1781 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1785 if (width
) *width
= paper
->widthMM
;
1786 if (height
) *height
= paper
->heightMM
;
1790 if (width
) *width
= 210;
1791 if (height
) *height
= 297;
1795 // Determine the Default Postscript Previewer
1796 // available on the platform
1797 #if defined(__SUN__) && defined(__XVIEW__)
1798 // OpenWindow/NeWS's Postscript Previewer
1799 # define PS_VIEWER_PROG "pageview"
1800 #elif defined(__VMS__)
1801 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
1802 #elif defined(__SGI__)
1803 // SGI's Display Postscript Previewer
1804 //# define PS_VIEWER_PROG "dps"
1805 # define PS_VIEWER_PROG "xpsview"
1806 #elif defined(__X__) || defined(__WXGTK__)
1807 // Front-end to ghostscript
1808 # define PS_VIEWER_PROG "ghostview"
1810 // Windows ghostscript/ghostview
1811 # define PS_VIEWER_PROG NULL
1814 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
1816 #if !USE_SHARED_LIBRARY
1817 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
1818 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
1819 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
1820 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
1823 // Redundant now I think
1825 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
1827 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
1828 const wxPoint
& pos
, const wxSize
& size
, long style
):
1829 wxDialog(parent
, -1, title
, pos
, size
, style
)
1831 wxBeginBusyCursor();
1836 *orientation
= new wxString
[2],
1837 *print_modes
= new wxString
[3];
1839 long wx_printer_translate_x
, wx_printer_translate_y
;
1840 double wx_printer_scale_x
, wx_printer_scale_y
;
1842 orientation
[0] = _("Portrait");
1843 orientation
[1] = _("Landscape");
1845 print_modes
[0] = _("Send to Printer");
1846 print_modes
[1] = _("Print to File");
1847 print_modes
[2] = _("Preview Only");
1851 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
1852 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
1853 okBut
->SetDefault();
1856 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1857 (void) new wxStaticText( this, -1, _("Printer Command: "),
1859 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
1860 wxPoint(100, yPos
), wxSize(100, -1) );
1862 (void) new wxStaticText( this, -1, _("Printer Options: "),
1863 wxPoint(210, yPos
) );
1864 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
1865 wxPoint(305, yPos
), wxSize(150, -1) );
1871 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
1872 2,orientation
,2,wxRA_SPECIFY_ROWS
);
1873 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
1875 // @@@ Configuration hook
1876 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
1877 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
1879 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
1881 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
1882 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
1884 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
1886 wxSize(-1,-1), features
,
1887 print_modes
, features
, wxRA_SPECIFY_ROWS
);
1890 radio1
->Enable(0, FALSE
);
1891 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
1892 radio1
->Enable(2, FALSE
);
1895 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
1896 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1897 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1899 sprintf (buf
, "%.2f", wx_printer_scale_x
);
1902 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
1903 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1905 sprintf (buf
, "%.2f", wx_printer_scale_y
);
1906 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
1907 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1911 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
1912 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
1913 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1915 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
1916 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
1917 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1921 delete[] orientation
;
1922 delete[] print_modes
;
1927 int wxPostScriptPrintDialog::ShowModal ()
1929 if ( wxDialog::ShowModal() == wxID_OK
)
1931 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
1932 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
1933 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
1934 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
1935 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
1936 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
1937 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
1938 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
1940 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
1941 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
1942 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
1943 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
1946 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
1947 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
1950 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
1953 switch ( radio1
->GetSelection() ) {
1954 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
1955 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
1956 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
1965 // PostScript printer settings
1966 // RETAINED FOR BACKWARD COMPATIBILITY
1967 void wxSetPrinterCommand(const char *cmd
)
1969 wxThePrintSetupData
->SetPrinterCommand(cmd
);
1972 void wxSetPrintPreviewCommand(const char *cmd
)
1974 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
1977 void wxSetPrinterOptions(const char *flags
)
1979 wxThePrintSetupData
->SetPrinterOptions(flags
);
1982 void wxSetPrinterFile(const char *f
)
1984 wxThePrintSetupData
->SetPrinterFile(f
);
1987 void wxSetPrinterOrientation(int orient
)
1989 wxThePrintSetupData
->SetPrinterOrientation(orient
);
1992 void wxSetPrinterScaling(double x
, double y
)
1994 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
1997 void wxSetPrinterTranslation(long x
, long y
)
1999 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2002 // 1 = Preview, 2 = print to file, 3 = send to printer
2003 void wxSetPrinterMode(int mode
)
2005 wxThePrintSetupData
->SetPrinterMode(mode
);
2008 void wxSetAFMPath(const char *f
)
2010 wxThePrintSetupData
->SetAFMPath(f
);
2013 // Get current values
2014 char *wxGetPrinterCommand()
2016 return wxThePrintSetupData
->GetPrinterCommand();
2019 char *wxGetPrintPreviewCommand()
2021 return wxThePrintSetupData
->GetPrintPreviewCommand();
2024 char *wxGetPrinterOptions()
2026 return wxThePrintSetupData
->GetPrinterOptions();
2029 char *wxGetPrinterFile()
2031 return wxThePrintSetupData
->GetPrinterFile();
2034 int wxGetPrinterOrientation()
2036 return wxThePrintSetupData
->GetPrinterOrientation();
2039 void wxGetPrinterScaling(double* x
, double* y
)
2041 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2044 void wxGetPrinterTranslation(long *x
, long *y
)
2046 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2049 int wxGetPrinterMode()
2051 return wxThePrintSetupData
->GetPrinterMode();
2054 char *wxGetAFMPath()
2056 return wxThePrintSetupData
->GetAFMPath();
2063 wxPrintSetupData::wxPrintSetupData()
2065 printerCommand
= (char *) NULL
;
2066 previewCommand
= (char *) NULL
;
2067 printerFlags
= (char *) NULL
;
2068 printerOrient
= PS_PORTRAIT
;
2069 printerScaleX
= (double)1.0;
2070 printerScaleY
= (double)1.0;
2071 printerTranslateX
= 0;
2072 printerTranslateY
= 0;
2073 // 1 = Preview, 2 = print to file, 3 = send to printer
2075 afmPath
= (char *) NULL
;
2076 paperName
= (char *) NULL
;
2078 printerFile
= (char *) NULL
;
2081 wxPrintSetupData::~wxPrintSetupData()
2084 delete[] printerCommand
;
2086 delete[] previewCommand
;
2088 delete[] printerFlags
;
2094 delete[] printerFile
;
2097 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2099 if (cmd
== printerCommand
)
2103 delete[] printerCommand
;
2105 printerCommand
= copystring(cmd
);
2107 printerCommand
= (char *) NULL
;
2110 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2112 if (cmd
== previewCommand
)
2116 delete[] previewCommand
;
2118 previewCommand
= copystring(cmd
);
2120 previewCommand
= (char *) NULL
;
2123 void wxPrintSetupData::SetPaperName(const char *name
)
2125 if (name
== paperName
)
2131 paperName
= copystring(name
);
2133 paperName
= (char *) NULL
;
2136 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2138 if (printerFlags
== flags
)
2142 delete[] printerFlags
;
2144 printerFlags
= copystring(flags
);
2146 printerFlags
= (char *) NULL
;
2149 void wxPrintSetupData::SetPrinterFile(const char *f
)
2151 if (f
== printerFile
)
2155 delete[] printerFile
;
2157 printerFile
= copystring(f
);
2159 printerFile
= (char *) NULL
;
2162 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2164 printerOrient
= orient
;
2167 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2173 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2175 printerTranslateX
= x
;
2176 printerTranslateY
= y
;
2179 // 1 = Preview, 2 = print to file, 3 = send to printer
2180 void wxPrintSetupData::SetPrinterMode(int mode
)
2185 void wxPrintSetupData::SetAFMPath(const char *f
)
2193 afmPath
= copystring(f
);
2195 afmPath
= (char *) NULL
;
2198 void wxPrintSetupData::SetColour(bool col
)
2203 // Get current values
2204 char *wxPrintSetupData::GetPrinterCommand()
2206 return printerCommand
;
2209 char *wxPrintSetupData::GetPrintPreviewCommand()
2211 return previewCommand
;
2214 char *wxPrintSetupData::GetPrinterOptions()
2216 return printerFlags
;
2219 char *wxPrintSetupData::GetPrinterFile()
2224 char *wxPrintSetupData::GetPaperName()
2229 int wxPrintSetupData::GetPrinterOrientation()
2231 return printerOrient
;
2234 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2240 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2242 *x
= printerTranslateX
;
2243 *y
= printerTranslateY
;
2246 int wxPrintSetupData::GetPrinterMode()
2251 char *wxPrintSetupData::GetAFMPath()
2256 bool wxPrintSetupData::GetColour()
2261 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2263 SetPrinterCommand(data
.GetPrinterCommand());
2264 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2265 SetPrinterOptions(data
.GetPrinterOptions());
2267 data
.GetPrinterTranslation(&x
, &y
);
2268 SetPrinterTranslation(x
, y
);
2271 data
.GetPrinterScaling(&x1
, &y1
);
2272 SetPrinterScaling(x1
, y1
);
2274 SetPrinterOrientation(data
.GetPrinterOrientation());
2275 SetPrinterMode(data
.GetPrinterMode());
2276 SetAFMPath(data
.GetAFMPath());
2277 SetPaperName(data
.GetPaperName());
2278 SetColour(data
.GetColour());
2281 void wxInitializePrintSetupData(bool init
)
2285 wxThePrintSetupData
= new wxPrintSetupData
;
2287 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2288 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2289 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2290 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2292 // Could have a .ini file to read in some defaults
2293 // - and/or use environment variables, e.g. WXWIN
2295 wxThePrintSetupData
->SetPrinterCommand("print");
2296 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2297 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2300 wxThePrintSetupData
->SetPrinterCommand("print");
2301 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2302 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2304 #if !defined(__VMS__) && !defined(__WXMSW__)
2305 wxThePrintSetupData
->SetPrinterCommand("lpr");
2306 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2307 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2312 if (wxThePrintSetupData
)
2313 delete wxThePrintSetupData
;
2314 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2319 * Paper size database for PostScript
2322 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2328 pageName
= copystring(name
);
2331 wxPrintPaperType::~wxPrintPaperType()
2337 * Print paper database for PostScript
2340 #if !USE_SHARED_LIBRARIES
2341 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
2344 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2346 DeleteContents(TRUE
);
2349 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2353 void wxPrintPaperDatabase::CreateDatabase()
2355 // Need correct values for page size in pixels.
2356 // Each unit is one 'point' = 1/72 of an inch.
2357 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2358 // in wxPostScriptDC code, so we can start from top left.
2359 // So access this database and translate by appropriate number
2360 // of points for this paper size. OR IS IT OK ALREADY?
2361 // Can't remember where the PostScript origin is by default.
2362 // Heck, someone will know how to make it hunky-dory...
2365 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2366 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2367 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2368 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2373 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 210*4, 297*4 );
2374 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 297*4, 420*4 );
2375 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 216*4, 279*4 );
2376 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 216*4, 356*4 );
2380 void wxPrintPaperDatabase::ClearDatabase()
2385 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2387 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2390 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2392 wxNode
*node
= Find(name
);
2394 return (wxPrintPaperType
*)node
->Data();
2396 return (wxPrintPaperType
*) NULL
;
2400 * Initialization/cleanup module
2403 bool wxPostScriptModule::OnInit()
2405 wxInitializePrintSetupData();
2406 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2407 wxThePrintPaperDatabase
->CreateDatabase();
2412 void wxPostScriptModule::OnExit()
2414 wxInitializePrintSetupData(FALSE
);
2415 delete wxThePrintPaperDatabase
;
2416 wxThePrintPaperDatabase
= NULL
;