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"
67 //-----------------------------------------------------------------------------
68 // start and end of document/page
69 //-----------------------------------------------------------------------------
71 static const char *wxPostScriptHeaderEllipse
= "\
72 /ellipsedict 8 dict def\n\
73 ellipsedict /mtrx matrix put\n\
77 /startangle exch def\n\
82 /savematrix mtrx currentmatrix def\n\
85 0 0 1 startangle endangle arc\n\
86 savematrix setmatrix\n\
91 static const char *wxPostScriptHeaderEllipticArc
= "\
92 /ellipticarcdict 8 dict def\n\
93 ellipticarcdict /mtrx matrix put\n\
95 { ellipticarcdict begin\n\
98 /startangle exch def\n\
103 /savematrix mtrx currentmatrix def\n\
106 do_fill { 0 0 moveto } if\n\
107 0 0 1 startangle endangle arc\n\
108 savematrix setmatrix\n\
109 do_fill { fill }{ stroke } ifelse\n\
113 static const char *wxPostScriptHeaderSpline
= "\
114 /DrawSplineSection {\n\
121 /xa x1 x2 x1 sub 0.666667 mul add def\n\
122 /ya y1 y2 y1 sub 0.666667 mul add def\n\
123 /xb x3 x2 x3 sub 0.666667 mul add def\n\
124 /yb y3 y2 y3 sub 0.666667 mul add def\n\
126 xa ya xb yb x3 y3 curveto\n\
130 static const char *wxPostScriptHeaderColourImage
= "\
131 % define 'colorimage' if it isn't defined\n\
132 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
134 /colorimage where % do we know about 'colorimage'?\n\
135 { pop } % yes: pop off the 'dict' returned\n\
136 { % no: define one\n\
137 /colortogray { % define an RGB->I function\n\
138 /rgbdata exch store % call input 'rgbdata'\n\
139 rgbdata length 3 idiv\n\
140 /npixls exch store\n\
142 0 1 npixls 1 sub {\n\
144 rgbdata rgbindx get 20 mul % Red\n\
145 rgbdata rgbindx 1 add get 32 mul % Green\n\
146 rgbdata rgbindx 2 add get 12 mul % Blue\n\
147 add add 64 idiv % I = .5G + .31R + .18B\n\
149 /rgbindx rgbindx 3 add store\n\
151 grays 0 npixls getinterval\n\
154 % Utility procedure for colorimage operator.\n\
155 % This procedure takes two procedures off the\n\
156 % stack and merges them into a single procedure.\n\
158 /mergeprocs { % def\n\
177 /colorimage { % def\n\
178 pop pop % remove 'false 3' operands\n\
179 {colortogray} mergeprocs\n\
182 } ifelse % end of 'false' case\n\
185 static char wxPostScriptHeaderReencodeISO1
[] =
187 "dup dup findfont dup length dict begin\n"
188 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
189 "/Encoding ISOLatin1Encoding def\n"
190 "currentdict end definefont\n"
192 "/ISOLatin1Encoding [\n"
193 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\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 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
198 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
199 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
200 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
201 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
202 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
203 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
204 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
205 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
206 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
207 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
209 static char wxPostScriptHeaderReencodeISO2
[] =
210 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
211 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
212 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
213 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
214 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
215 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
216 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
217 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
218 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
219 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
220 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
221 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
222 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
223 "/yacute/thorn/ydieresis\n"
226 //-------------------------------------------------------------------------------
228 //-------------------------------------------------------------------------------
230 wxPostScriptDC::wxPostScriptDC ()
232 m_pstream
= (ofstream
*) NULL
;
242 m_underlinePosition
= 0.0;
243 m_underlineThickness
= 0.0;
245 m_signX
= 1; // default x-axis left to right
246 m_signY
= -1; // default y-axis bottom up -> top down
249 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
251 m_pstream
= (ofstream
*) NULL
;
261 m_underlinePosition
= 0.0;
262 m_underlineThickness
= 0.0;
264 m_signX
= 1; // default x-axis left to right
265 m_signY
= -1; // default y-axis bottom up -> top down
267 Create(file
, interactive
, parent
);
270 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
272 m_isInteractive
= interactive
;
278 // Can only send to file in Windows
279 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
284 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
294 wxPostScriptDC::~wxPostScriptDC ()
296 if (m_pstream
) delete m_pstream
;
299 bool wxPostScriptDC::Ok() const
304 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
306 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
307 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
308 m_ok
= (dialog
.ShowModal () == wxID_OK
);
310 if (!m_ok
) return FALSE
;
312 if ((m_filename
== "") &&
313 (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
||
314 wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
318 wxThePrintSetupData
->SetPrinterFile("preview");
320 // For PS_PRINTER action this depends on a Unix-style print spooler
321 // since the wx_printer_file can be destroyed during a session
322 // @@@ TODO: a Windows-style answer for non-Unix
324 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
326 strcpy (tmp
, "/tmp/preview_");
327 strcat (tmp
, userId
);
328 wxThePrintSetupData
->SetPrinterFile(tmp
);
331 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
332 strcat (tmp2
, ".ps");
333 wxThePrintSetupData
->SetPrinterFile(tmp2
);
336 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
338 wxString file
= wxSaveFileSelector (_("PostScript"), "ps");
339 if ( file
.IsEmpty() )
345 wxThePrintSetupData
->SetPrinterFile(file
);
353 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
355 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
357 if (m_clipping
) return;
359 wxDC::SetClippingRegion( x
, y
, w
, h
);
362 *m_pstream
<< "gsave\n"
364 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
365 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
366 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
367 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
368 << "closepath clip newpath\n";
371 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
375 void wxPostScriptDC::DestroyClippingRegion()
377 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
379 wxDC::DestroyClippingRegion();
384 *m_pstream
<< "grestore\n";
388 void wxPostScriptDC::Clear()
390 wxFAIL_MSG( "wxPostScriptDC::Clear not implemented." );
393 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
395 wxFAIL_MSG( "wxPostScriptDC::FloodFill not implemented." );
398 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
400 wxFAIL_MSG( "wxPostScriptDC::GetPixel not implemented." );
404 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
406 wxFAIL_MSG( "wxPostScriptDC::CrossHair not implemented." );
409 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
411 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
413 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
417 *m_pstream
<< "newpath\n"
418 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
419 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
422 CalcBoundingBox( x1
, y1
);
423 CalcBoundingBox( x2
, y2
);
426 #define RAD2DEG 57.29577951308
428 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
430 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
434 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
435 double alpha1
, alpha2
;
437 if (x1
== x2
&& y1
== y2
)
441 } else if (radius
== 0.0)
443 alpha1
= alpha2
= 0.0;
446 alpha1
= (x1
- xc
== 0) ?
447 (y1
- yc
< 0) ? 90.0 : -90.0 :
448 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
449 alpha2
= (x2
- xc
== 0) ?
450 (y2
- yc
< 0) ? 90.0 : -90.0 :
451 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
453 while (alpha1
<= 0) alpha1
+= 360;
454 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
455 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
456 while (alpha2
> 360) alpha2
-= 360;
458 if (m_brush
.GetStyle() != wxTRANSPARENT
)
461 *m_pstream
<< "newpath\n"
462 << XLOG2DEV(xc
) << " "
463 << YLOG2DEV(yc
) << " "
464 << XLOG2DEVREL(radius
) << " "
465 << YLOG2DEVREL(radius
) << " "
467 << alpha2
<< " ellipse\n"
468 << XLOG2DEV(xc
) << " "
469 << YLOG2DEV(yc
) << " lineto\n"
474 if (m_pen
.GetStyle() != wxTRANSPARENT
)
477 *m_pstream
<< "newpath\n"
478 << XLOG2DEV(xc
) << " "
479 << YLOG2DEV(yc
) << " "
480 << XLOG2DEVREL(radius
) << " "
481 << YLOG2DEVREL(radius
) << " "
483 << alpha2
<< " ellipse\n"
487 CalcBoundingBox( xc
-radius
, yc
-radius
);
488 CalcBoundingBox( xc
+radius
, yc
+radius
);
491 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
493 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
495 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
496 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
502 DrawEllipse(x
,y
,w
,h
);
506 if (m_brush
.GetStyle () != wxTRANSPARENT
)
510 *m_pstream
<< "newpath\n"
511 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
512 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
513 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
515 CalcBoundingBox( x
,y
);
516 CalcBoundingBox( x
+w
, y
+h
);
519 if (m_pen
.GetStyle () != wxTRANSPARENT
)
523 *m_pstream
<< "newpath\n"
524 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
525 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
526 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
528 CalcBoundingBox( x
, y
);
529 CalcBoundingBox( x
+w
, y
+h
);
533 void wxPostScriptDC::DrawPoint (long x
, long y
)
535 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
537 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
541 *m_pstream
<< "newpath\n"
542 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
543 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
546 CalcBoundingBox( x
, y
);
549 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
551 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
555 if (m_brush
.GetStyle () != wxTRANSPARENT
)
559 *m_pstream
<< "newpath\n";
561 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
562 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
563 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
564 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
566 for (int i
= 1; i
< n
; i
++)
568 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
569 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
570 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
571 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
573 *m_pstream
<< "fill\n";
576 if (m_pen
.GetStyle () != wxTRANSPARENT
)
580 *m_pstream
<< "newpath\n";
582 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
583 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
584 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
585 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
587 for (int i
= 1; i
< n
; i
++)
589 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
590 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
591 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
592 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
595 *m_pstream
<< "stroke\n";
599 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
601 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
603 if (m_pen
.GetStyle() == wxTRANSPARENT
)
611 for ( i
=0; i
<n
; i
++ )
613 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
616 *m_pstream
<< "newpath\n"
617 << XLOG2DEV(points
[0].x
+xoffset
) << " "
618 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
620 for (i
= 1; i
< n
; i
++)
622 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
623 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
626 *m_pstream
<< "stroke\n";
629 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
631 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
633 if (m_brush
.GetStyle () != wxTRANSPARENT
)
637 *m_pstream
<< "newpath\n"
638 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
639 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
640 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
641 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
645 CalcBoundingBox( x
, y
);
646 CalcBoundingBox( x
+ width
, y
+ height
);
649 if (m_pen
.GetStyle () != wxTRANSPARENT
)
653 *m_pstream
<< "newpath\n"
654 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
655 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
656 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
657 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
661 CalcBoundingBox( x
, y
);
662 CalcBoundingBox( x
+ width
, y
+ height
);
666 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
668 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
672 // Now, a negative radius is interpreted to mean
673 // 'the proportion of the smallest X or Y dimension'
674 double smallest
= 0.0;
679 radius
= (-radius
* smallest
);
682 long rad
= (long) radius
;
684 if (m_brush
.GetStyle () != wxTRANSPARENT
)
688 // Draw rectangle anticlockwise
689 *m_pstream
<< "newpath\n"
690 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
691 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
692 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
693 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
694 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
695 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
696 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
697 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
701 CalcBoundingBox( x
, y
);
702 CalcBoundingBox( x
+ width
, y
+ height
);
705 if (m_pen
.GetStyle () != wxTRANSPARENT
)
709 // Draw rectangle anticlockwise
710 *m_pstream
<< "newpath\n"
711 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
712 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
713 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
714 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
715 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
716 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
717 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
718 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
722 CalcBoundingBox( x
, y
);
723 CalcBoundingBox( x
+ width
, y
+ height
);
727 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
729 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
731 if (m_brush
.GetStyle () != wxTRANSPARENT
)
735 *m_pstream
<< "newpath\n"
736 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
737 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
740 CalcBoundingBox( x
- width
, y
- height
);
741 CalcBoundingBox( x
+ width
, y
+ height
);
744 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
748 *m_pstream
<< "newpath\n"
749 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
750 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
753 CalcBoundingBox( x
- width
, y
- height
);
754 CalcBoundingBox( x
+ width
, y
+ height
);
758 void wxPostScriptDC::DrawIcon( const wxIcon
& icon
, long x
, long y
)
760 DrawBitmap( icon
, x
, y
, TRUE
);
763 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool WXUNUSED(useMask
) )
765 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
767 if (!bitmap
.Ok()) return;
769 wxImage
image( bitmap
);
771 if (!image
.Ok()) return;
773 int ww
= XLOG2DEVREL(image
.GetWidth());
774 int hh
= YLOG2DEVREL(image
.GetHeight());
776 image
= image
.Scale( ww
, hh
);
778 if (!image
.Ok()) return;
780 int xx
= XLOG2DEV(x
);
781 int yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
783 *m_pstream
<< "/origstate save def\n"
785 << "/pix " << ww
<< " string def\n"
786 << "/grays " << ww
<< " string def\n"
787 << "/npixels 0 def\n"
788 << "/rgbindx 0 def\n"
789 << xx
<< " " << yy
<< " translate\n"
790 << ww
<< " " << hh
<< " scale\n"
791 << ww
<< " " << hh
<< " 8\n"
792 << "[" << ww
<< " 0 0 " << (-hh
) << " 0 " << hh
<< "]\n"
793 << "{currentfile pix readhexstring pop}\n"
794 << "false 3 colorimage\n";
796 for (int j
= 0; j
< hh
; j
++)
798 for (int i
= 0; i
< ww
; i
++)
802 wxDecToHex( image
.GetRed(i
,j
), buffer
);
803 *m_pstream
<< buffer
;
804 wxDecToHex( image
.GetGreen(i
,j
), buffer
);
805 *m_pstream
<< buffer
;
806 wxDecToHex( image
.GetBlue(i
,j
), buffer
);
807 *m_pstream
<< buffer
;
812 *m_pstream
<< "end\n";
813 *m_pstream
<< "origstate restore\n";
817 void wxPostScriptDC::SetFont( const wxFont
& font
)
819 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
821 if (!font
.Ok()) return;
826 const char *style
= "";
827 int Style
= m_font
.GetStyle();
828 int Weight
= m_font
.GetWeight();
830 switch (m_font
.GetFamily ())
840 // name = "/Times-Roman";
841 name
= "/Times"; // Altered by EDZ
844 name
= "/Zapf-Chancery-MediumItalic";
849 case wxDEFAULT
: // Sans Serif Font
850 name
= "/LucidaSans";
853 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
855 if (m_font
.GetFamily () == wxROMAN
)
860 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
864 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
866 if (m_font
.GetFamily () == wxROMAN
)
871 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
873 if (m_font
.GetFamily () == wxROMAN
)
874 style
= "-BoldItalic";
876 style
= "-BoldOblique";
878 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
880 if (m_font
.GetFamily () == wxROMAN
)
885 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
887 if (m_font
.GetFamily () == wxROMAN
)
888 style
= "-BoldItalic";
890 style
= "-BoldOblique";
901 *m_pstream
<< buf
<< " reencodeISO def\n";
902 *m_pstream
<< buf
<< " findfont\n";
903 *m_pstream
<< YLOG2DEVREL(m_font
.GetPointSize()) << " scalefont setfont\n";
906 void wxPostScriptDC::SetPen( const wxPen
& pen
)
908 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
910 if (!pen
.Ok()) return;
912 int oldStyle
= m_pen
.GetStyle();
916 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
919 Line style - WRONG: 2nd arg is OFFSET
921 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
922 operator correctly. You should look-up this in the Red Book: the 2nd parame-
923 ter is not number of values in the array of the first one, but an offset
924 into this description of the pattern. I mean a real *offset* not index
925 into array. I.e. If the command is [3 4] 1 setdash is used, then there
926 will be first black line *2* units long, then space 4 units, then the
927 pattern of *3* units black, 4 units space will be repeated.
930 static const char *dotted
= "[2 5] 2";
931 static const char *short_dashed
= "[4 4] 2";
932 static const char *long_dashed
= "[4 8] 2";
933 static const char *dotted_dashed
= "[6 6 2 6] 4";
935 const char *psdash
= (char *) NULL
;
936 switch (m_pen
.GetStyle ())
938 case wxDOT
: psdash
= dotted
; break;
939 case wxSHORT_DASH
: psdash
= short_dashed
; break;
940 case wxLONG_DASH
: psdash
= long_dashed
; break;
941 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
944 default: psdash
= "[] 0"; break;
947 if (oldStyle
!= m_pen
.GetStyle())
949 *m_pstream
<< psdash
<< " setdash\n";
953 unsigned char red
= m_pen
.GetColour().Red();
954 unsigned char blue
= m_pen
.GetColour().Blue();
955 unsigned char green
= m_pen
.GetColour().Green();
959 // Anything not white is black
960 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
961 && green
== (unsigned char) 255))
963 red
= (unsigned char) 0;
964 green
= (unsigned char) 0;
965 blue
= (unsigned char) 0;
971 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
973 long redPS
= (long) (((int) red
) / 255.0);
974 long bluePS
= (long) (((int) blue
) / 255.0);
975 long greenPS
= (long) (((int) green
) / 255.0);
977 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
980 m_currentBlue
= blue
;
981 m_currentGreen
= green
;
985 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
987 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
989 if (!brush
.Ok()) return;
994 unsigned char red
= m_brush
.GetColour ().Red ();
995 unsigned char blue
= m_brush
.GetColour ().Blue ();
996 unsigned char green
= m_brush
.GetColour ().Green ();
1000 // Anything not black is white
1001 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
1002 && green
== (unsigned char) 0))
1004 red
= (unsigned char) 255;
1005 green
= (unsigned char) 255;
1006 blue
= (unsigned char) 255;
1012 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1014 long redPS
= (long) (((int) red
) / 255.0);
1015 long bluePS
= (long) (((int) blue
) / 255.0);
1016 long greenPS
= (long) (((int) green
) / 255.0);
1017 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1019 m_currentBlue
= blue
;
1020 m_currentGreen
= green
;
1024 void wxPostScriptDC::DrawText( const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
) )
1026 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1030 if (m_textForegroundColour
.Ok ())
1032 unsigned char red
= m_textForegroundColour
.Red ();
1033 unsigned char blue
= m_textForegroundColour
.Blue ();
1034 unsigned char green
= m_textForegroundColour
.Green ();
1038 // Anything not white is black
1039 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
1040 && green
== (unsigned char) 255))
1042 red
= (unsigned char) 0;
1043 green
= (unsigned char) 0;
1044 blue
= (unsigned char) 0;
1048 // maybe setgray here ?
1050 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1052 long redPS
= (long) (((int) red
) / 255.0);
1053 long bluePS
= (long) (((int) blue
) / 255.0);
1054 long greenPS
= (long) (((int) green
) / 255.0);
1055 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1058 m_currentBlue
= blue
;
1059 m_currentGreen
= green
;
1063 int size
= m_font
.GetPointSize();
1065 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
1066 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
1069 int len
= strlen ((char *)(const char *)text
);
1071 for (i
= 0; i
< len
; i
++)
1073 int c
= (unsigned char) text
[i
];
1074 if ( c
== ')' || c
== '(' || c
== '\\')
1076 *m_pstream
<< "\\" << (char) c
;
1078 else if ( c
>= 128 )
1080 // Cope with character codes > 127
1082 sprintf(tmp
, "\\%o", c
);
1086 *m_pstream
<< (char) c
;
1089 *m_pstream
<< ")" << " show\n";
1091 if (m_font
.GetUnderlined())
1093 long uy
= (long)(y
+ size
- m_underlinePosition
);
1095 GetTextExtent(text
, &w
, &h
);
1097 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
1099 << (long)m_underlineThickness
<< " setlinewidth "
1100 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
1101 << " lineto stroke grestore\n";
1104 CalcBoundingBox( x
, y
);
1105 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1109 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1111 m_backgroundBrush
= brush
;
1114 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1116 wxFAIL_MSG( "wxPostScriptDC::SetLogicalFunction not implemented." );
1119 void wxPostScriptDC::DrawSpline( wxList
*points
)
1121 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1125 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1128 wxNode
*node
= points
->First();
1129 p
= (wxPoint
*)node
->Data();
1133 node
= node
->Next();
1134 p
= (wxPoint
*)node
->Data();
1137 x3
= a
= (double)(x1
+ c
) / 2;
1138 y3
= b
= (double)(y1
+ d
) / 2;
1140 *m_pstream
<< "newpath "
1141 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
1142 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
1144 CalcBoundingBox( (long)x1
, (long)y1
);
1145 CalcBoundingBox( (long)x3
, (long)y3
);
1147 while ((node
= node
->Next()) != NULL
)
1149 q
= (wxPoint
*)node
->Data();
1157 x3
= (double)(x2
+ c
) / 2;
1158 y3
= (double)(y2
+ d
) / 2;
1159 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
1160 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
1161 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
1163 CalcBoundingBox( (long)x1
, (long)y1
);
1164 CalcBoundingBox( (long)x3
, (long)y3
);
1168 At this point, (x2,y2) and (c,d) are the position of the
1169 next-to-last and last point respectively, in the point list
1172 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1175 long wxPostScriptDC::GetCharWidth ()
1177 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1178 return (long) (GetCharHeight() * 72.0 / 120.0);
1182 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1184 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1186 m_signX
= (xLeftRight
? 1 : -1);
1187 m_signY
= (yBottomUp
? 1 : -1);
1189 // FIXME there is no such function in MSW
1191 ComputeScaleAndOrigin();
1195 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1197 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1203 wxDC::SetDeviceOrigin( x
, h
-y
);
1206 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1208 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1210 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1212 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1214 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1218 if (width
) *width
= paper
->widthPixels
;
1219 if (height
) *height
= paper
->heightPixels
;
1223 if (width
) *width
= 595;
1224 if (height
) *height
= 842;
1228 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1230 wxCHECK_MSG( m_ok
, FALSE
, "invalid postscript dc" );
1232 if (m_filename
== "")
1234 m_filename
= wxGetTempFileName("ps");
1235 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1240 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1243 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1245 if (!m_pstream
|| !m_pstream
->good())
1247 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1254 SetBrush( *wxBLACK_BRUSH
);
1255 SetPen( *wxBLACK_PEN
);
1256 SetBackground( *wxWHITE_BRUSH
);
1257 SetTextForeground( *wxBLACK
);
1259 // set origin according to paper size
1260 SetDeviceOrigin( 0,0 );
1268 void wxPostScriptDC::EndDoc ()
1270 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1275 *m_pstream
<< "grestore\n";
1281 m_pstream
= (ofstream
*) NULL
;
1284 char *header_file
= wxGetTempFileName("ps");
1286 m_pstream
= new ofstream( header_file
);
1288 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1289 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1290 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1291 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1294 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1296 *m_pstream
<< "%%For: " << (char *)userID
;
1298 if (wxGetUserName(userName
, sizeof(userName
)))
1299 *m_pstream
<< " (" << (char *)userName
<< ")";
1302 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1304 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1307 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1309 long wx_printer_translate_x
, wx_printer_translate_y
;
1310 double wx_printer_scale_x
, wx_printer_scale_y
;
1311 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1312 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1314 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1316 *m_pstream
<< "%%Orientation: Landscape\n";
1320 *m_pstream
<< "%%Orientation: Portrait\n";
1323 // Compute the bounding box. Note that it is in the default user
1324 // coordinate system, thus we have to convert the values.
1325 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1326 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1327 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1328 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1330 // If we're landscape, our sense of "x" and "y" is reversed.
1331 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1334 tmp
= llx
; llx
= lly
; lly
= tmp
;
1335 tmp
= urx
; urx
= ury
; ury
= tmp
;
1337 // We need either the two lines that follow, or we need to subtract
1338 // min_x from real_translate_y, which is commented out below.
1339 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1340 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1343 // The Adobe specifications call for integers; we round as to make
1344 // the bounding larger.
1345 *m_pstream
<< "%%BoundingBox: "
1346 << floor((double)llx
) << " " << floor((double)lly
) << " "
1347 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1348 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1349 *m_pstream
<< "%%EndComments\n\n";
1351 // To check the correctness of the bounding box, postscript commands
1352 // to draw a box corresponding to the bounding box are generated below.
1353 // But since we typically don't want to print such a box, the postscript
1354 // commands are generated within comments. These lines appear before any
1355 // adjustment of scale, rotation, or translation, and hence are in the
1356 // default user coordinates.
1357 *m_pstream
<< "% newpath\n";
1358 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1359 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1360 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1361 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1363 *m_pstream
<< "%%BeginProlog\n";
1364 *m_pstream
<< wxPostScriptHeaderEllipse
;
1365 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1366 *m_pstream
<< wxPostScriptHeaderColourImage
;
1367 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1368 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1370 if (wxPostScriptHeaderSpline
)
1371 *m_pstream
<< wxPostScriptHeaderSpline
;
1372 *m_pstream
<< "%%EndProlog\n";
1375 m_pstream
= (ofstream
*) NULL
;
1377 char *tmp_file
= wxGetTempFileName("ps");
1379 // Paste header Before wx_printer_file
1380 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1381 wxRemoveFile (header_file
);
1382 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1383 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1385 #if defined(__X__) || defined(__WXGTK__)
1388 switch (wxThePrintSetupData
->GetPrinterMode()) {
1392 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1393 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1394 argv
[2] = (char *) NULL
;
1395 wxExecute (argv
, TRUE
);
1396 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1404 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1406 // !SM! If we simply assign to argv[1] here, if printer options
1407 // are blank, we get an annoying and confusing message from lpr.
1408 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1410 argv
[argc
++] = opts
;
1412 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1413 argv
[argc
++] = (char *) NULL
;
1414 wxExecute (argv
, TRUE
);
1415 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1426 void wxPostScriptDC::StartPage ()
1428 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1430 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1432 // *m_pstream << "matrix currentmatrix\n";
1434 // Added by Chris Breeze
1436 // Each page starts with an "initgraphics" which resets the
1437 // transformation and so we need to reset the origin
1438 // (and rotate the page for landscape printing)
1441 m_scaleFactor = 1.0;
1442 m_logicalOriginX = 0;
1443 m_logicalOriginY = 0;
1446 long translate_x
, translate_y
;
1447 double scale_x
, scale_y
;
1448 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1449 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1451 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1453 translate_y
-= m_maxY
;
1454 *m_pstream
<< "90 rotate\n";
1457 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1458 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1461 void wxPostScriptDC::EndPage ()
1463 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1465 *m_pstream
<< "showpage\n";
1468 bool wxPostScriptDC::Blit( long xdest
, long ydest
,
1469 long fwidth
, long fheight
,
1471 long xsrc
, long ysrc
,
1472 int rop
, bool WXUNUSED(useMask
) )
1474 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, "invalid postscript dc" );
1476 wxCHECK_MSG( source
, FALSE
, "invalid source dc" );
1478 /* blit into a bitmap */
1480 wxBitmap
bitmap( fwidth
, fheight
);
1482 memDC
.SelectObject(bitmap
);
1483 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1484 memDC
.SelectObject(wxNullBitmap
);
1486 /* draw bitmap. scaling and positioning is done there */
1488 DrawBitmap( bitmap
, xdest
, ydest
);
1493 long wxPostScriptDC::GetCharHeight()
1496 return m_font
.GetPointSize();
1501 void wxPostScriptDC::GetTextExtent( const wxString
& string
, long *x
, long *y
,
1502 long *descent
, long *externalLeading
, wxFont
*theFont
,
1503 bool WXUNUSED(use16
) )
1505 wxFont
*fontToUse
= theFont
;
1507 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1509 wxCHECK_RET( fontToUse
, "GetTextExtent: no font defined" );
1510 wxCHECK_RET( x
, "GetTextExtent: x == NULL" );
1511 wxCHECK_RET( y
, "GetTextExtent: y == NULL" );
1513 #if !USE_AFM_FOR_POSTSCRIPT
1514 /* Provide a VERY rough estimate (avoid using it).
1515 * Produces accurate results for mono-spaced font
1516 * such as Courier (aka wxMODERN) */
1521 height
= fontToUse
->GetPointSize();
1523 *x
= strlen (string
) * height
* 72 / 120;
1524 *y
= (long) (height
* 1.32); /* allow for descender */
1525 if (descent
) *descent
= 0;
1526 if (externalLeading
) *externalLeading
= 0;
1529 /* method for calculating string widths in postscript:
1530 / read in the AFM (adobe font metrics) file for the
1531 / actual font, parse it and extract the character widths
1532 / and also the descender. this may be improved, but for now
1533 / it works well. the AFM file is only read in if the
1534 / font is changed. this may be chached in the future.
1535 / calls to GetTextExtent with the font unchanged are rather
1538 / for each font and style used there is an AFM file necessary.
1539 / currently i have only files for the roman font family.
1540 / I try to get files for the other ones!
1542 / CAVE: the size of the string is currently always calculated
1543 / in 'points' (1/72 of an inch). this should later on be
1544 / changed to depend on the mapping mode.
1545 / CAVE: the path to the AFM files must be set before calling this
1546 / function. this is usually done by a call like the following:
1547 / wxSetAFMPath("d:\\wxw161\\afm\\");
1551 / wxPostScriptDC dc(NULL, TRUE);
1553 / wxSetAFMPath("d:\\wxw161\\afm\\");
1554 / dc.StartDoc("Test");
1557 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1558 / dc.GetTextExtent("Hallo",&w,&h);
1563 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1565 / updated: 14.05.95 */
1567 /* these static vars are for storing the state between calls */
1568 static int lastFamily
= INT_MIN
;
1569 static int lastSize
= INT_MIN
;
1570 static int lastStyle
= INT_MIN
;
1571 static int lastWeight
= INT_MIN
;
1572 static int lastDescender
= INT_MIN
;
1573 static int lastWidths
[256]; /* widths of the characters */
1575 /* get actual parameters */
1576 const int Family
= fontToUse
->GetFamily();
1577 const int Size
= fontToUse
->GetPointSize();
1578 const int Style
= fontToUse
->GetStyle();
1579 const int Weight
= fontToUse
->GetWeight();
1581 /* if we have another font, read the font-metrics */
1582 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1584 /* store actual values */
1585 lastFamily
= Family
;
1588 lastWeight
= Weight
;
1590 char *name
= (char*) NULL
;
1596 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO";
1597 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo";
1598 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Cour0";
1604 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO";
1605 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo";
1606 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO";
1607 else if name
= "TimesRo"; /* no typo */
1612 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO";
1613 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo";
1614 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Helv0";
1620 /* get the directory of the AFM files */
1623 if (wxGetAFMPath()) strcpy( afmName
, wxGetAFMPath() );
1625 /* 2. open and process the file
1626 / a short explanation of the AFM format:
1627 / we have for each character a line, which gives its size
1630 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1632 / that means, we have a character with ascii code 63, and width
1633 / (444/1000 * fontSize) points.
1634 / the other data is ignored for now!
1636 / when the font has changed, we read in the right AFM file and store the
1637 / character widths in an array, which is processed below (see point 3.). */
1639 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
1641 strcat(afmName
,name
);
1642 strcat(afmName
,".afm");
1643 FILE *afmFile
= fopen(afmName
,"r");
1644 if ( afmFile
==NULL
)
1646 wxLogDebug( "GetTextExtent: can't open AFM file '%s'\n", afmName
);
1647 wxLogDebug( " using approximate values\n");
1648 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
1649 lastDescender
= -150; /* dito. */
1653 /* init the widths array */
1654 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
1655 /* some variables for holding parts of a line */
1656 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1657 char upString
[30], utString
[30], encString
[50];
1660 /* read in the file and parse it */
1661 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
1663 /* A.) check for descender definition */
1664 if (strncmp(line
,"Descender",9)==0)
1666 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
1667 (strcmp(descString
,"Descender")!=0))
1669 wxLogDebug( "AFM-file '%s': line '%s' has error (bad descender)\n", afmName
,line
);
1672 /* JC 1.) check for UnderlinePosition */
1673 else if(strncmp(line
,"UnderlinePosition",17)==0)
1675 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
1676 (strcmp(upString
,"UnderlinePosition")!=0))
1678 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", afmName
, line
);
1681 /* JC 2.) check for UnderlineThickness */
1682 else if(strncmp(line
,"UnderlineThickness",18)==0)
1684 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
1685 (strcmp(utString
,"UnderlineThickness")!=0))
1687 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", afmName
, line
);
1690 /* JC 3.) check for EncodingScheme */
1691 else if(strncmp(line
,"EncodingScheme",14)==0)
1693 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
1694 (strcmp(utString
,"EncodingScheme")!=0))
1696 wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", afmName
, line
);
1698 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1700 wxLogDebug( "AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1701 afmName
,line
, encString
);
1704 /* B.) check for char-width */
1705 else if(strncmp(line
,"C ",2)==0)
1707 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
1709 wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1711 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
1713 wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1715 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
1716 if (ascii
>=0 && ascii
<256)
1718 lastWidths
[ascii
] = cWidth
; /* store width */
1722 /* MATTHEW: this happens a lot; don't print an error */
1723 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); */
1726 /* C.) ignore other entries. */
1730 /* hack to compute correct values for german 'Umlaute'
1731 / the correct way would be to map the character names
1732 / like 'adieresis' to corresp. positions of ISOEnc and read
1733 / these values from AFM files, too. Maybe later ... */
1734 lastWidths
[196] = lastWidths
['A']; // Ä
1735 lastWidths
[228] = lastWidths
['a']; // ä
1736 lastWidths
[214] = lastWidths
['O']; // Ö
1737 lastWidths
[246] = lastWidths
['o']; // ö
1738 lastWidths
[220] = lastWidths
['U']; // Ü
1739 lastWidths
[252] = lastWidths
['u']; // ü
1740 lastWidths
[223] = lastWidths
[251]; // ß
1743 /* JC: calculate UnderlineThickness/UnderlinePosition */
1744 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1745 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1747 /* 3. now the font metrics are read in, calc size this
1748 / is done by adding the widths of the characters in the
1749 / string. they are given in 1/1000 of the size! */
1752 long height
=Size
; /* by default */
1754 for(p
=(unsigned char *)(const char *)string
; *p
; p
++)
1756 if(lastWidths
[*p
]== INT_MIN
)
1758 wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n", *p
,*p
);
1759 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); /* assume space */
1763 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1767 /* add descender to height (it is usually a negative value) */
1768 if (lastDescender
!=INT_MIN
)
1770 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1773 /* return size values */
1777 /* return other parameters */
1780 if(lastDescender
!=INT_MIN
)
1782 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1790 /* currently no idea how to calculate this! */
1791 if (externalLeading
) *externalLeading
= 0;
1796 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
1798 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1800 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1802 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1804 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1808 if (width
) *width
= paper
->widthMM
;
1809 if (height
) *height
= paper
->heightMM
;
1813 if (width
) *width
= 210;
1814 if (height
) *height
= 297;
1818 // Determine the Default Postscript Previewer
1819 // available on the platform
1820 #if defined(__SUN__) && defined(__XVIEW__)
1821 // OpenWindow/NeWS's Postscript Previewer
1822 # define PS_VIEWER_PROG "pageview"
1823 #elif defined(__VMS__)
1824 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
1825 #elif defined(__SGI__)
1826 // SGI's Display Postscript Previewer
1827 //# define PS_VIEWER_PROG "dps"
1828 # define PS_VIEWER_PROG "xpsview"
1829 #elif defined(__X__) || defined(__WXGTK__)
1830 // Front-end to ghostscript
1831 # define PS_VIEWER_PROG "ghostview"
1833 // Windows ghostscript/ghostview
1834 # define PS_VIEWER_PROG NULL
1837 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
1839 #if !USE_SHARED_LIBRARY
1840 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
1841 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
1842 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
1843 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
1846 // Redundant now I think
1848 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
1850 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
1851 const wxPoint
& pos
, const wxSize
& size
, long style
):
1852 wxDialog(parent
, -1, title
, pos
, size
, style
)
1854 wxBeginBusyCursor();
1859 *orientation
= new wxString
[2],
1860 *print_modes
= new wxString
[3];
1862 long wx_printer_translate_x
, wx_printer_translate_y
;
1863 double wx_printer_scale_x
, wx_printer_scale_y
;
1865 orientation
[0] = _("Portrait");
1866 orientation
[1] = _("Landscape");
1868 print_modes
[0] = _("Send to Printer");
1869 print_modes
[1] = _("Print to File");
1870 print_modes
[2] = _("Preview Only");
1874 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
1875 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
1876 okBut
->SetDefault();
1879 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1880 (void) new wxStaticText( this, -1, _("Printer Command: "),
1882 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
1883 wxPoint(100, yPos
), wxSize(100, -1) );
1885 (void) new wxStaticText( this, -1, _("Printer Options: "),
1886 wxPoint(210, yPos
) );
1887 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
1888 wxPoint(305, yPos
), wxSize(150, -1) );
1894 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
1895 2,orientation
,2,wxRA_SPECIFY_ROWS
);
1896 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
1898 // @@@ Configuration hook
1899 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
1900 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
1902 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
1904 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
1905 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
1907 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
1909 wxSize(-1,-1), features
,
1910 print_modes
, features
, wxRA_SPECIFY_ROWS
);
1913 radio1
->Enable(0, FALSE
);
1914 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
1915 radio1
->Enable(2, FALSE
);
1918 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
1919 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1920 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1922 sprintf (buf
, "%.2f", wx_printer_scale_x
);
1925 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
1926 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1928 sprintf (buf
, "%.2f", wx_printer_scale_y
);
1929 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
1930 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1934 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
1935 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
1936 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1938 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
1939 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
1940 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1944 delete[] orientation
;
1945 delete[] print_modes
;
1950 int wxPostScriptPrintDialog::ShowModal ()
1952 if ( wxDialog::ShowModal() == wxID_OK
)
1954 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
1955 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
1956 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
1957 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
1958 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
1959 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
1960 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
1961 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
1963 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
1964 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
1965 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
1966 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
1969 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
1970 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
1973 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
1976 switch ( radio1
->GetSelection() ) {
1977 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
1978 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
1979 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
1988 // PostScript printer settings
1989 // RETAINED FOR BACKWARD COMPATIBILITY
1990 void wxSetPrinterCommand(const char *cmd
)
1992 wxThePrintSetupData
->SetPrinterCommand(cmd
);
1995 void wxSetPrintPreviewCommand(const char *cmd
)
1997 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2000 void wxSetPrinterOptions(const char *flags
)
2002 wxThePrintSetupData
->SetPrinterOptions(flags
);
2005 void wxSetPrinterFile(const char *f
)
2007 wxThePrintSetupData
->SetPrinterFile(f
);
2010 void wxSetPrinterOrientation(int orient
)
2012 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2015 void wxSetPrinterScaling(double x
, double y
)
2017 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2020 void wxSetPrinterTranslation(long x
, long y
)
2022 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2025 // 1 = Preview, 2 = print to file, 3 = send to printer
2026 void wxSetPrinterMode(int mode
)
2028 wxThePrintSetupData
->SetPrinterMode(mode
);
2031 void wxSetAFMPath(const char *f
)
2033 wxThePrintSetupData
->SetAFMPath(f
);
2036 // Get current values
2037 char *wxGetPrinterCommand()
2039 return wxThePrintSetupData
->GetPrinterCommand();
2042 char *wxGetPrintPreviewCommand()
2044 return wxThePrintSetupData
->GetPrintPreviewCommand();
2047 char *wxGetPrinterOptions()
2049 return wxThePrintSetupData
->GetPrinterOptions();
2052 char *wxGetPrinterFile()
2054 return wxThePrintSetupData
->GetPrinterFile();
2057 int wxGetPrinterOrientation()
2059 return wxThePrintSetupData
->GetPrinterOrientation();
2062 void wxGetPrinterScaling(double* x
, double* y
)
2064 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2067 void wxGetPrinterTranslation(long *x
, long *y
)
2069 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2072 int wxGetPrinterMode()
2074 return wxThePrintSetupData
->GetPrinterMode();
2077 char *wxGetAFMPath()
2079 return wxThePrintSetupData
->GetAFMPath();
2086 wxPrintSetupData::wxPrintSetupData()
2088 printerCommand
= (char *) NULL
;
2089 previewCommand
= (char *) NULL
;
2090 printerFlags
= (char *) NULL
;
2091 printerOrient
= PS_PORTRAIT
;
2092 printerScaleX
= (double)1.0;
2093 printerScaleY
= (double)1.0;
2094 printerTranslateX
= 0;
2095 printerTranslateY
= 0;
2096 // 1 = Preview, 2 = print to file, 3 = send to printer
2098 afmPath
= (char *) NULL
;
2099 paperName
= (char *) NULL
;
2101 printerFile
= (char *) NULL
;
2104 wxPrintSetupData::~wxPrintSetupData()
2107 delete[] printerCommand
;
2109 delete[] previewCommand
;
2111 delete[] printerFlags
;
2117 delete[] printerFile
;
2120 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2122 if (cmd
== printerCommand
)
2126 delete[] printerCommand
;
2128 printerCommand
= copystring(cmd
);
2130 printerCommand
= (char *) NULL
;
2133 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2135 if (cmd
== previewCommand
)
2139 delete[] previewCommand
;
2141 previewCommand
= copystring(cmd
);
2143 previewCommand
= (char *) NULL
;
2146 void wxPrintSetupData::SetPaperName(const char *name
)
2148 if (name
== paperName
)
2154 paperName
= copystring(name
);
2156 paperName
= (char *) NULL
;
2159 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2161 if (printerFlags
== flags
)
2165 delete[] printerFlags
;
2167 printerFlags
= copystring(flags
);
2169 printerFlags
= (char *) NULL
;
2172 void wxPrintSetupData::SetPrinterFile(const char *f
)
2174 if (f
== printerFile
)
2178 delete[] printerFile
;
2180 printerFile
= copystring(f
);
2182 printerFile
= (char *) NULL
;
2185 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2187 printerOrient
= orient
;
2190 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2196 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2198 printerTranslateX
= x
;
2199 printerTranslateY
= y
;
2202 // 1 = Preview, 2 = print to file, 3 = send to printer
2203 void wxPrintSetupData::SetPrinterMode(int mode
)
2208 void wxPrintSetupData::SetAFMPath(const char *f
)
2216 afmPath
= copystring(f
);
2218 afmPath
= (char *) NULL
;
2221 void wxPrintSetupData::SetColour(bool col
)
2226 // Get current values
2227 char *wxPrintSetupData::GetPrinterCommand()
2229 return printerCommand
;
2232 char *wxPrintSetupData::GetPrintPreviewCommand()
2234 return previewCommand
;
2237 char *wxPrintSetupData::GetPrinterOptions()
2239 return printerFlags
;
2242 char *wxPrintSetupData::GetPrinterFile()
2247 char *wxPrintSetupData::GetPaperName()
2252 int wxPrintSetupData::GetPrinterOrientation()
2254 return printerOrient
;
2257 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2263 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2265 *x
= printerTranslateX
;
2266 *y
= printerTranslateY
;
2269 int wxPrintSetupData::GetPrinterMode()
2274 char *wxPrintSetupData::GetAFMPath()
2279 bool wxPrintSetupData::GetColour()
2284 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2286 SetPrinterCommand(data
.GetPrinterCommand());
2287 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2288 SetPrinterOptions(data
.GetPrinterOptions());
2290 data
.GetPrinterTranslation(&x
, &y
);
2291 SetPrinterTranslation(x
, y
);
2294 data
.GetPrinterScaling(&x1
, &y1
);
2295 SetPrinterScaling(x1
, y1
);
2297 SetPrinterOrientation(data
.GetPrinterOrientation());
2298 SetPrinterMode(data
.GetPrinterMode());
2299 SetAFMPath(data
.GetAFMPath());
2300 SetPaperName(data
.GetPaperName());
2301 SetColour(data
.GetColour());
2304 void wxInitializePrintSetupData(bool init
)
2308 wxThePrintSetupData
= new wxPrintSetupData
;
2310 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2311 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2312 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2313 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2315 // Could have a .ini file to read in some defaults
2316 // - and/or use environment variables, e.g. WXWIN
2318 wxThePrintSetupData
->SetPrinterCommand("print");
2319 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2320 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2323 wxThePrintSetupData
->SetPrinterCommand("print");
2324 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2325 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2327 #if !defined(__VMS__) && !defined(__WXMSW__)
2328 wxThePrintSetupData
->SetPrinterCommand("lpr");
2329 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2330 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2335 if (wxThePrintSetupData
)
2336 delete wxThePrintSetupData
;
2337 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2342 * Paper size database for PostScript
2345 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2351 pageName
= copystring(name
);
2354 wxPrintPaperType::~wxPrintPaperType()
2360 * Print paper database for PostScript
2363 #if !USE_SHARED_LIBRARIES
2364 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
2367 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2369 DeleteContents(TRUE
);
2372 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2376 void wxPrintPaperDatabase::CreateDatabase()
2378 // Need correct values for page size in pixels.
2379 // Each unit is one 'point' = 1/72 of an inch.
2380 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2381 // in wxPostScriptDC code, so we can start from top left.
2382 // So access this database and translate by appropriate number
2383 // of points for this paper size. OR IS IT OK ALREADY?
2384 // Can't remember where the PostScript origin is by default.
2385 // Heck, someone will know how to make it hunky-dory...
2388 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2389 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2390 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2391 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2396 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 210*4, 297*4 );
2397 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 297*4, 420*4 );
2398 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 216*4, 279*4 );
2399 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 216*4, 356*4 );
2403 void wxPrintPaperDatabase::ClearDatabase()
2408 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2410 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2413 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2415 wxNode
*node
= Find(name
);
2417 return (wxPrintPaperType
*)node
->Data();
2419 return (wxPrintPaperType
*) NULL
;
2423 * Initialization/cleanup module
2426 bool wxPostScriptModule::OnInit()
2428 wxInitializePrintSetupData();
2429 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2430 wxThePrintPaperDatabase
->CreateDatabase();
2435 void wxPostScriptModule::OnExit()
2437 wxInitializePrintSetupData(FALSE
);
2438 delete wxThePrintPaperDatabase
;
2439 wxThePrintPaperDatabase
= NULL
;