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
21 #include "wx/dcmemory.h"
24 #include "wx/filedlg.h"
26 #include "wx/msgdlg.h"
29 #include "wx/generic/dcpsg.h"
30 #include "wx/generic/prntdlgg.h"
31 #include "wx/button.h"
32 #include "wx/stattext.h"
33 #include "wx/radiobox.h"
34 #include "wx/textctrl.h"
63 //-----------------------------------------------------------------------------
64 // start and end of document/page
65 //-----------------------------------------------------------------------------
67 static const char *wxPostScriptHeaderEllipse
= "\
68 /ellipsedict 8 dict def\n\
69 ellipsedict /mtrx matrix put\n\
73 /startangle exch def\n\
78 /savematrix mtrx currentmatrix def\n\
81 0 0 1 startangle endangle arc\n\
82 savematrix setmatrix\n\
87 static const char *wxPostScriptHeaderEllipticArc
= "\
88 /ellipticarcdict 8 dict def\n\
89 ellipticarcdict /mtrx matrix put\n\
91 { ellipticarcdict begin\n\
94 /startangle exch def\n\
99 /savematrix mtrx currentmatrix def\n\
102 do_fill { 0 0 moveto } if\n\
103 0 0 1 startangle endangle arc\n\
104 savematrix setmatrix\n\
105 do_fill { fill }{ stroke } ifelse\n\
109 static const char *wxPostScriptHeaderSpline
= "\
110 /DrawSplineSection {\n\
117 /xa x1 x2 x1 sub 0.666667 mul add def\n\
118 /ya y1 y2 y1 sub 0.666667 mul add def\n\
119 /xb x3 x2 x3 sub 0.666667 mul add def\n\
120 /yb y3 y2 y3 sub 0.666667 mul add def\n\
122 xa ya xb yb x3 y3 curveto\n\
126 static const char *wxPostScriptHeaderColourImage
= "\
127 % define 'colorimage' if it isn't defined\n\
128 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
130 /colorimage where % do we know about 'colorimage'?\n\
131 { pop } % yes: pop off the 'dict' returned\n\
132 { % no: define one\n\
133 /colortogray { % define an RGB->I function\n\
134 /rgbdata exch store % call input 'rgbdata'\n\
135 rgbdata length 3 idiv\n\
136 /npixls exch store\n\
138 0 1 npixls 1 sub {\n\
140 rgbdata rgbindx get 20 mul % Red\n\
141 rgbdata rgbindx 1 add get 32 mul % Green\n\
142 rgbdata rgbindx 2 add get 12 mul % Blue\n\
143 add add 64 idiv % I = .5G + .31R + .18B\n\
145 /rgbindx rgbindx 3 add store\n\
147 grays 0 npixls getinterval\n\
150 % Utility procedure for colorimage operator.\n\
151 % This procedure takes two procedures off the\n\
152 % stack and merges them into a single procedure.\n\
154 /mergeprocs { % def\n\
173 /colorimage { % def\n\
174 pop pop % remove 'false 3' operands\n\
175 {colortogray} mergeprocs\n\
178 } ifelse % end of 'false' case\n\
181 static char wxPostScriptHeaderReencodeISO1
[] =
183 "dup dup findfont dup length dict begin\n"
184 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
185 "/Encoding ISOLatin1Encoding def\n"
186 "currentdict end definefont\n"
188 "/ISOLatin1Encoding [\n"
189 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
190 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
191 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
192 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
193 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
194 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
195 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
196 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
197 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
198 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
199 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
200 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
201 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
202 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
203 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
205 static char wxPostScriptHeaderReencodeISO2
[] =
206 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
207 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
208 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
209 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
210 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
211 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
212 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
213 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
214 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
215 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
216 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
217 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
218 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
219 "/yacute/thorn/ydieresis\n"
222 //-------------------------------------------------------------------------------
224 //-------------------------------------------------------------------------------
226 wxPostScriptDC::wxPostScriptDC ()
228 m_pstream
= (ofstream
*) NULL
;
238 m_underlinePosition
= 0.0;
239 m_underlineThickness
= 0.0;
241 m_signX
= 1; // default x-axis left to right
242 m_signY
= -1; // default y-axis bottom up -> top down
245 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
247 m_pstream
= (ofstream
*) NULL
;
257 m_underlinePosition
= 0.0;
258 m_underlineThickness
= 0.0;
260 m_signX
= 1; // default x-axis left to right
261 m_signY
= -1; // default y-axis bottom up -> top down
263 Create(file
, interactive
, parent
);
266 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
268 m_isInteractive
= interactive
;
274 // Can only send to file in Windows
275 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
280 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
290 wxPostScriptDC::~wxPostScriptDC ()
292 if (m_pstream
) delete m_pstream
;
295 bool wxPostScriptDC::Ok() const
300 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
302 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
303 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
304 m_ok
= (dialog
.ShowModal () == wxID_OK
);
306 if (!m_ok
) return FALSE
;
308 if ((m_filename
== "") &&
309 (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
||
310 wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
314 wxThePrintSetupData
->SetPrinterFile("preview");
316 // For PS_PRINTER action this depends on a Unix-style print spooler
317 // since the wx_printer_file can be destroyed during a session
318 // @@@ TODO: a Windows-style answer for non-Unix
320 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
322 strcpy (tmp
, "/tmp/preview_");
323 strcat (tmp
, userId
);
324 wxThePrintSetupData
->SetPrinterFile(tmp
);
327 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
328 strcat (tmp2
, ".ps");
329 wxThePrintSetupData
->SetPrinterFile(tmp2
);
332 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
334 char *file
= wxSaveFileSelector (_("PostScript"), "ps");
340 wxThePrintSetupData
->SetPrinterFile(file
);
348 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
350 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
352 if (m_clipping
) return;
354 wxDC::SetClippingRegion( x
, y
, w
, h
);
357 *m_pstream
<< "gsave\n"
359 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
360 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
361 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
362 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
363 << "closepath clip newpath\n";
366 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
370 void wxPostScriptDC::DestroyClippingRegion()
372 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
374 wxDC::DestroyClippingRegion();
379 *m_pstream
<< "grestore\n";
383 void wxPostScriptDC::Clear()
385 wxFAIL_MSG( "wxPostScriptDC::Clear not implemented." );
388 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
390 wxFAIL_MSG( "wxPostScriptDC::FloodFill not implemented." );
393 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
395 wxFAIL_MSG( "wxPostScriptDC::GetPixel not implemented." );
399 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
401 wxFAIL_MSG( "wxPostScriptDC::CrossHair not implemented." );
404 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
406 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
408 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
412 *m_pstream
<< "newpath\n"
413 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
414 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
417 CalcBoundingBox( x1
, y1
);
418 CalcBoundingBox( x2
, y2
);
421 #define RAD2DEG 57.29577951308
423 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
425 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
429 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
430 double alpha1
, alpha2
;
432 if (x1
== x2
&& y1
== y2
)
436 } else if (radius
== 0.0)
438 alpha1
= alpha2
= 0.0;
441 alpha1
= (x1
- xc
== 0) ?
442 (y1
- yc
< 0) ? 90.0 : -90.0 :
443 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
444 alpha2
= (x2
- xc
== 0) ?
445 (y2
- yc
< 0) ? 90.0 : -90.0 :
446 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
448 while (alpha1
<= 0) alpha1
+= 360;
449 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
450 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
451 while (alpha2
> 360) alpha2
-= 360;
453 if (m_brush
.GetStyle() != wxTRANSPARENT
)
456 *m_pstream
<< "newpath\n"
457 << XLOG2DEV(xc
) << " "
458 << YLOG2DEV(yc
) << " "
459 << XLOG2DEVREL(radius
) << " "
460 << YLOG2DEVREL(radius
) << " "
462 << alpha2
<< " ellipse\n"
463 << XLOG2DEV(xc
) << " "
464 << YLOG2DEV(yc
) << " lineto\n"
469 if (m_pen
.GetStyle() != wxTRANSPARENT
)
472 *m_pstream
<< "newpath\n"
473 << XLOG2DEV(xc
) << " "
474 << YLOG2DEV(yc
) << " "
475 << XLOG2DEVREL(radius
) << " "
476 << YLOG2DEVREL(radius
) << " "
478 << alpha2
<< " ellipse\n"
482 CalcBoundingBox( xc
-radius
, yc
-radius
);
483 CalcBoundingBox( xc
+radius
, yc
+radius
);
486 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
488 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
490 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
491 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
497 DrawEllipse(x
,y
,w
,h
);
501 if (m_brush
.GetStyle () != wxTRANSPARENT
)
505 *m_pstream
<< "newpath\n"
506 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
507 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
508 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
510 CalcBoundingBox( x
,y
);
511 CalcBoundingBox( x
+w
, y
+h
);
514 if (m_pen
.GetStyle () != wxTRANSPARENT
)
518 *m_pstream
<< "newpath\n"
519 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
520 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
521 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
523 CalcBoundingBox( x
, y
);
524 CalcBoundingBox( x
+w
, y
+h
);
528 void wxPostScriptDC::DrawPoint (long x
, long y
)
530 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
532 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
536 *m_pstream
<< "newpath\n"
537 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
538 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
541 CalcBoundingBox( x
, y
);
544 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
546 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
550 if (m_brush
.GetStyle () != wxTRANSPARENT
)
554 *m_pstream
<< "newpath\n";
556 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
557 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
558 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
559 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
561 for (int i
= 1; i
< n
; i
++)
563 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
564 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
565 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
566 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
568 *m_pstream
<< "fill\n";
571 if (m_pen
.GetStyle () != wxTRANSPARENT
)
575 *m_pstream
<< "newpath\n";
577 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
578 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
579 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
580 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
582 for (int i
= 1; i
< n
; i
++)
584 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
585 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
586 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
587 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
590 *m_pstream
<< "stroke\n";
594 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
596 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
598 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
603 for (int i
=0; i
<n
; ++i
)
605 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
608 *m_pstream
<< "newpath\n"
609 << XLOG2DEV(points
[0].x
+xoffset
) << " "
610 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
612 for (int i
= 1; i
< n
; i
++)
614 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
615 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
618 *m_pstream
<< "stroke\n";
621 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
623 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
625 if (m_brush
.GetStyle () != wxTRANSPARENT
)
629 *m_pstream
<< "newpath\n"
630 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
631 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
632 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
633 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
637 CalcBoundingBox( x
, y
);
638 CalcBoundingBox( x
+ width
, y
+ height
);
641 if (m_pen
.GetStyle () != wxTRANSPARENT
)
645 *m_pstream
<< "newpath\n"
646 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
647 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
648 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
649 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
653 CalcBoundingBox( x
, y
);
654 CalcBoundingBox( x
+ width
, y
+ height
);
658 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
660 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
664 // Now, a negative radius is interpreted to mean
665 // 'the proportion of the smallest X or Y dimension'
666 double smallest
= 0.0;
671 radius
= (-radius
* smallest
);
674 long rad
= (long) radius
;
676 if (m_brush
.GetStyle () != wxTRANSPARENT
)
680 // Draw rectangle anticlockwise
681 *m_pstream
<< "newpath\n"
682 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
683 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
684 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
685 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
686 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
687 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
688 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
689 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
693 CalcBoundingBox( x
, y
);
694 CalcBoundingBox( x
+ width
, y
+ height
);
697 if (m_pen
.GetStyle () != wxTRANSPARENT
)
701 // Draw rectangle anticlockwise
702 *m_pstream
<< "newpath\n"
703 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
704 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
705 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
706 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
707 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
708 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
709 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
710 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
714 CalcBoundingBox( x
, y
);
715 CalcBoundingBox( x
+ width
, y
+ height
);
719 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
721 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
723 if (m_brush
.GetStyle () != wxTRANSPARENT
)
727 *m_pstream
<< "newpath\n"
728 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
729 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
732 CalcBoundingBox( x
- width
, y
- height
);
733 CalcBoundingBox( x
+ width
, y
+ height
);
736 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
740 *m_pstream
<< "newpath\n"
741 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
742 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
745 CalcBoundingBox( x
- width
, y
- height
);
746 CalcBoundingBox( x
+ width
, y
+ height
);
750 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
752 DrawBitmap( icon
, x
, y
, TRUE
);
755 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool WXUNUSED(useMask
) )
757 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
759 if (!bitmap
.Ok()) return;
761 wxImage
image( bitmap
);
763 if (!image
.Ok()) return;
765 int ww
= XLOG2DEVREL(image
.GetWidth());
766 int hh
= YLOG2DEVREL(image
.GetHeight());
768 image
= image
.Scale( ww
, hh
);
770 if (!image
.Ok()) return;
772 int xx
= XLOG2DEV(x
);
773 int yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
775 *m_pstream
<< "/origstate save def\n"
777 << "/pix " << ww
<< " string def\n"
778 << "/grays " << ww
<< " string def\n"
779 << "/npixels 0 def\n"
780 << "/rgbindx 0 def\n"
781 << xx
<< " " << yy
<< " translate\n"
782 << ww
<< " " << hh
<< " scale\n"
783 << ww
<< " " << hh
<< " 8\n"
784 << "[" << ww
<< " 0 0 " << (-hh
) << " 0 " << hh
<< "]\n"
785 << "{currentfile pix readhexstring pop}\n"
786 << "false 3 colorimage\n";
788 for (int j
= 0; j
< hh
; j
++)
790 for (int i
= 0; i
< ww
; i
++)
794 wxDecToHex( image
.GetRed(i
,j
), buffer
);
795 *m_pstream
<< buffer
;
796 wxDecToHex( image
.GetGreen(i
,j
), buffer
);
797 *m_pstream
<< buffer
;
798 wxDecToHex( image
.GetBlue(i
,j
), buffer
);
799 *m_pstream
<< buffer
;
804 *m_pstream
<< "end\n";
805 *m_pstream
<< "origstate restore\n";
809 void wxPostScriptDC::SetFont (const wxFont
& font
)
811 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
813 if (!font
.Ok()) return;
818 char *name
= wxTheFontNameDirectory
->GetPostScriptName( m_font
.GetFamily(),
821 if (!name
) name
= "Times-Roman";
823 *m_pstream
<< "/" << name
<< " reencodeISO def\n"
824 << "/" << name
<< " findfont\n"
825 << YLOG2DEVREL(font
.GetPointSize())
826 << " scalefont setfont\n";
830 const char *style
= "";
831 int Style
= m_font
.GetStyle ();
832 int Weight
= m_font
.GetWeight ();
834 switch (m_font
.GetFamily ())
844 // name = "/Times-Roman";
845 name
= "/Times"; // Altered by EDZ
848 name
= "/Zapf-Chancery-MediumItalic";
853 case wxDEFAULT
: // Sans Serif Font
854 name
= "/LucidaSans";
857 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
859 if (m_font
.GetFamily () == wxROMAN
)
864 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
867 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
869 if (m_font
.GetFamily () == wxROMAN
)
874 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
876 if (m_font
.GetFamily () == wxROMAN
)
877 style
= "-BoldItalic";
879 style
= "-BoldOblique";
881 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
883 if (m_font
.GetFamily () == wxROMAN
)
888 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
890 if (m_font
.GetFamily () == wxROMAN
)
891 style
= "-BoldItalic";
893 style
= "-BoldOblique";
900 *m_pstream
<< buf
<< " findfont\n";
901 // *m_pstream << (m_font.GetPointSize() * m_scaleFactor) << " scalefont setfont\n";
902 // No scale factor in this implementation?
903 *m_pstream
<< (m_font
.GetPointSize()) << " scalefont setfont\n";
907 void wxPostScriptDC::SetPen( const wxPen
& pen
)
909 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
911 if (!pen
.Ok()) return;
913 int oldStyle
= m_pen
.GetStyle();
917 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
920 Line style - WRONG: 2nd arg is OFFSET
922 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
923 operator correctly. You should look-up this in the Red Book: the 2nd parame-
924 ter is not number of values in the array of the first one, but an offset
925 into this description of the pattern. I mean a real *offset* not index
926 into array. I.e. If the command is [3 4] 1 setdash is used, then there
927 will be first black line *2* units long, then space 4 units, then the
928 pattern of *3* units black, 4 units space will be repeated.
931 static const char *dotted
= "[2 5] 2";
932 static const char *short_dashed
= "[4 4] 2";
933 static const char *long_dashed
= "[4 8] 2";
934 static const char *dotted_dashed
= "[6 6 2 6] 4";
936 const char *psdash
= (char *) NULL
;
937 switch (m_pen
.GetStyle ())
939 case wxDOT
: psdash
= dotted
; break;
940 case wxSHORT_DASH
: psdash
= short_dashed
; break;
941 case wxLONG_DASH
: psdash
= long_dashed
; break;
942 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
945 default: psdash
= "[] 0"; break;
948 if (oldStyle
!= m_pen
.GetStyle())
950 *m_pstream
<< psdash
<< " setdash\n";
954 unsigned char red
= m_pen
.GetColour().Red();
955 unsigned char blue
= m_pen
.GetColour().Blue();
956 unsigned char green
= m_pen
.GetColour().Green();
960 // Anything not white is black
961 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
962 && green
== (unsigned char) 255))
964 red
= (unsigned char) 0;
965 green
= (unsigned char) 0;
966 blue
= (unsigned char) 0;
972 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
974 long redPS
= (long) (((int) red
) / 255.0);
975 long bluePS
= (long) (((int) blue
) / 255.0);
976 long greenPS
= (long) (((int) green
) / 255.0);
978 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
981 m_currentBlue
= blue
;
982 m_currentGreen
= green
;
986 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
988 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
990 if (!brush
.Ok()) return;
995 unsigned char red
= m_brush
.GetColour ().Red ();
996 unsigned char blue
= m_brush
.GetColour ().Blue ();
997 unsigned char green
= m_brush
.GetColour ().Green ();
1001 // Anything not black is white
1002 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
1003 && green
== (unsigned char) 0))
1005 red
= (unsigned char) 255;
1006 green
= (unsigned char) 255;
1007 blue
= (unsigned char) 255;
1013 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1015 long redPS
= (long) (((int) red
) / 255.0);
1016 long bluePS
= (long) (((int) blue
) / 255.0);
1017 long greenPS
= (long) (((int) green
) / 255.0);
1018 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1020 m_currentBlue
= blue
;
1021 m_currentGreen
= green
;
1025 void wxPostScriptDC::DrawText( const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
) )
1027 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1031 if (m_textForegroundColour
.Ok ())
1033 unsigned char red
= m_textForegroundColour
.Red ();
1034 unsigned char blue
= m_textForegroundColour
.Blue ();
1035 unsigned char green
= m_textForegroundColour
.Green ();
1039 // Anything not white is black
1040 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
1041 && green
== (unsigned char) 255))
1043 red
= (unsigned char) 0;
1044 green
= (unsigned char) 0;
1045 blue
= (unsigned char) 0;
1049 // maybe setgray here ?
1051 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1053 long redPS
= (long) (((int) red
) / 255.0);
1054 long bluePS
= (long) (((int) blue
) / 255.0);
1055 long greenPS
= (long) (((int) green
) / 255.0);
1056 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1059 m_currentBlue
= blue
;
1060 m_currentGreen
= green
;
1064 int size
= m_font
.GetPointSize();
1066 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
1067 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
1070 int len
= strlen ((char *)(const char *)text
);
1072 for (i
= 0; i
< len
; i
++)
1074 int c
= (unsigned char) text
[i
];
1075 if ( c
== ')' || c
== '(' || c
== '\\')
1077 *m_pstream
<< "\\" << (char) c
;
1079 else if ( c
>= 128 )
1081 // Cope with character codes > 127
1083 sprintf(tmp
, "\\%o", c
);
1087 *m_pstream
<< (char) c
;
1090 *m_pstream
<< ")" << " show\n";
1092 if (m_font
.GetUnderlined())
1094 long uy
= (long)(y
+ size
- m_underlinePosition
);
1096 GetTextExtent(text
, &w
, &h
);
1098 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
1100 << (long)m_underlineThickness
<< " setlinewidth "
1101 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
1102 << " lineto stroke grestore\n";
1105 CalcBoundingBox( x
, y
);
1106 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1110 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1112 m_backgroundBrush
= brush
;
1115 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1117 wxFAIL_MSG( "wxPostScriptDC::SetLogicalFunction not implemented." );
1120 void wxPostScriptDC::DrawSpline( wxList
*points
)
1122 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1126 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1129 wxNode
*node
= points
->First();
1130 p
= (wxPoint
*)node
->Data();
1134 node
= node
->Next();
1135 p
= (wxPoint
*)node
->Data();
1138 x3
= a
= (double)(x1
+ c
) / 2;
1139 y3
= b
= (double)(y1
+ d
) / 2;
1141 *m_pstream
<< "newpath "
1142 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
1143 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
1145 CalcBoundingBox( (long)x1
, (long)y1
);
1146 CalcBoundingBox( (long)x3
, (long)y3
);
1148 while ((node
= node
->Next()) != NULL
)
1150 q
= (wxPoint
*)node
->Data();
1158 x3
= (double)(x2
+ c
) / 2;
1159 y3
= (double)(y2
+ d
) / 2;
1160 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
1161 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
1162 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
1164 CalcBoundingBox( (long)x1
, (long)y1
);
1165 CalcBoundingBox( (long)x3
, (long)y3
);
1169 At this point, (x2,y2) and (c,d) are the position of the
1170 next-to-last and last point respectively, in the point list
1173 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1176 long wxPostScriptDC::GetCharWidth ()
1178 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1179 return (long) (GetCharHeight() * 72.0 / 120.0);
1183 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1185 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1187 m_signX
= (xLeftRight
? 1 : -1);
1188 m_signY
= (yBottomUp
? 1 : -1);
1190 ComputeScaleAndOrigin();
1193 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1195 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1201 wxDC::SetDeviceOrigin( x
, h
-y
);
1204 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1206 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1208 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1210 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1212 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1216 if (width
) *width
= paper
->widthPixels
;
1217 if (height
) *height
= paper
->heightPixels
;
1221 if (width
) *width
= 595;
1222 if (height
) *height
= 842;
1226 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1228 wxCHECK_MSG( m_ok
, FALSE
, "invalid postscript dc" );
1230 if (m_filename
== "")
1232 m_filename
= wxGetTempFileName("ps");
1233 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1238 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1241 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1243 if (!m_pstream
|| !m_pstream
->good())
1245 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1252 SetBrush( *wxBLACK_BRUSH
);
1253 SetPen( *wxBLACK_PEN
);
1254 SetBackground( *wxWHITE_BRUSH
);
1255 SetTextForeground( *wxBLACK
);
1257 // set origin according to paper size
1258 SetDeviceOrigin( 0,0 );
1266 void wxPostScriptDC::EndDoc ()
1268 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1273 *m_pstream
<< "grestore\n";
1279 m_pstream
= (ofstream
*) NULL
;
1282 char *header_file
= wxGetTempFileName("ps");
1284 m_pstream
= new ofstream( header_file
);
1286 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1287 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1288 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1289 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1292 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1294 *m_pstream
<< "%%For: " << (char *)userID
;
1296 if (wxGetUserName(userName
, sizeof(userName
)))
1297 *m_pstream
<< " (" << (char *)userName
<< ")";
1300 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1302 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1305 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1307 long wx_printer_translate_x
, wx_printer_translate_y
;
1308 double wx_printer_scale_x
, wx_printer_scale_y
;
1309 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1310 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1312 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1314 *m_pstream
<< "%%Orientation: Landscape\n";
1318 *m_pstream
<< "%%Orientation: Portrait\n";
1321 // Compute the bounding box. Note that it is in the default user
1322 // coordinate system, thus we have to convert the values.
1323 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1324 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1325 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1326 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1328 // If we're landscape, our sense of "x" and "y" is reversed.
1329 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1332 tmp
= llx
; llx
= lly
; lly
= tmp
;
1333 tmp
= urx
; urx
= ury
; ury
= tmp
;
1335 // We need either the two lines that follow, or we need to subtract
1336 // min_x from real_translate_y, which is commented out below.
1337 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1338 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1341 // The Adobe specifications call for integers; we round as to make
1342 // the bounding larger.
1343 *m_pstream
<< "%%BoundingBox: "
1344 << floor((double)llx
) << " " << floor((double)lly
) << " "
1345 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1346 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1347 *m_pstream
<< "%%EndComments\n\n";
1349 // To check the correctness of the bounding box, postscript commands
1350 // to draw a box corresponding to the bounding box are generated below.
1351 // But since we typically don't want to print such a box, the postscript
1352 // commands are generated within comments. These lines appear before any
1353 // adjustment of scale, rotation, or translation, and hence are in the
1354 // default user coordinates.
1355 *m_pstream
<< "% newpath\n";
1356 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1357 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1358 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1359 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1361 *m_pstream
<< "%%BeginProlog\n";
1362 *m_pstream
<< wxPostScriptHeaderEllipse
;
1363 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1364 *m_pstream
<< wxPostScriptHeaderColourImage
;
1365 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1366 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1368 if (wxPostScriptHeaderSpline
)
1369 *m_pstream
<< wxPostScriptHeaderSpline
;
1370 *m_pstream
<< "%%EndProlog\n";
1373 m_pstream
= (ofstream
*) NULL
;
1375 char *tmp_file
= wxGetTempFileName("ps");
1377 // Paste header Before wx_printer_file
1378 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1379 wxRemoveFile (header_file
);
1380 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1381 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1383 #if defined(__X__) || defined(__WXGTK__)
1386 switch (wxThePrintSetupData
->GetPrinterMode()) {
1390 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1391 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1392 argv
[2] = (char *) NULL
;
1393 wxExecute (argv
, TRUE
);
1394 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1402 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1404 // !SM! If we simply assign to argv[1] here, if printer options
1405 // are blank, we get an annoying and confusing message from lpr.
1406 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1408 argv
[argc
++] = opts
;
1410 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1411 argv
[argc
++] = (char *) NULL
;
1412 wxExecute (argv
, TRUE
);
1413 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1424 void wxPostScriptDC::StartPage ()
1426 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1428 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1430 // *m_pstream << "matrix currentmatrix\n";
1432 // Added by Chris Breeze
1434 // Each page starts with an "initgraphics" which resets the
1435 // transformation and so we need to reset the origin
1436 // (and rotate the page for landscape printing)
1439 m_scaleFactor = 1.0;
1440 m_logicalOriginX = 0;
1441 m_logicalOriginY = 0;
1445 long translate_x
, translate_y
;
1446 double scale_x
, scale_y
;
1447 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1448 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1450 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1452 translate_y
-= m_maxY
;
1453 *m_pstream
<< "90 rotate\n";
1456 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1457 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1460 void wxPostScriptDC::EndPage ()
1462 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1464 *m_pstream
<< "showpage\n";
1467 bool wxPostScriptDC::Blit( long WXUNUSED(xdest
), long WXUNUSED(ydest
),
1468 long WXUNUSED(fwidth
), long WXUNUSED(fheight
),
1469 wxDC
*WXUNUSED(source
),
1470 long WXUNUSED(xsrc
), long WXUNUSED(ysrc
),
1471 int WXUNUSED(rop
), bool WXUNUSED(useMask
) )
1473 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, "invalid postscript dc" );
1475 wxFAIL_MSG( "wxPostScriptDC::Blit no yet implemented." );
1480 long wxPostScriptDC::GetCharHeight ()
1483 return m_font
.GetPointSize();
1488 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1489 long *descent
, long *externalLeading
, wxFont
*theFont
,
1490 bool WXUNUSED(use16
))
1492 // if (!m_pstream) return;
1494 wxFont
*fontToUse
= theFont
;
1496 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1498 #if !USE_AFM_FOR_POSTSCRIPT
1499 // Provide a VERY rough estimate (avoid using it)
1500 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1501 // font such as Courier (aka wxMODERN)
1505 height
= fontToUse
->GetPointSize();
1507 *x
= strlen (string
) * height
* 72 / 120;
1508 *y
= (long) (height
* 1.32); // allow for descender
1512 if (externalLeading
)
1513 *externalLeading
= 0;
1515 // +++++ start of contributed code +++++
1517 // ************************************************************
1518 // method for calculating string widths in postscript:
1519 // read in the AFM (adobe font metrics) file for the
1520 // actual font, parse it and extract the character widths
1521 // and also the descender. this may be improved, but for now
1522 // it works well. the AFM file is only read in if the
1523 // font is changed. this may be chached in the future.
1524 // calls to GetTextExtent with the font unchanged are rather
1527 // for each font and style used there is an AFM file necessary.
1528 // currently i have only files for the roman font family.
1529 // i try to get files for the other ones!
1531 // CAVE: the size of the string is currently always calculated
1532 // in 'points' (1/72 of an inch). this should later on be
1533 // changed to depend on the mapping mode.
1534 // CAVE: the path to the AFM files must be set before calling this
1535 // function. this is usually done by a call like the following:
1536 // wxSetAFMPath("d:\\wxw161\\afm\\");
1540 // wxPostScriptDC dc(NULL, TRUE);
1542 // wxSetAFMPath("d:\\wxw161\\afm\\");
1543 // dc.StartDoc("Test");
1546 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1547 // dc.GetTextExtent("Hallo",&w,&h);
1552 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1553 // created: 10.09.94
1554 // updated: 14.05.95
1556 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1557 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1558 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1560 // these static vars are for storing the state between calls
1561 static int lastFamily
= INT_MIN
;
1562 static int lastSize
= INT_MIN
;
1563 static int lastStyle
= INT_MIN
;
1564 static int lastWeight
= INT_MIN
;
1565 static int lastDescender
= INT_MIN
;
1566 static int lastWidths
[256]; // widths of the characters
1568 // get actual parameters
1569 const int Family
= fontToUse
->GetFamily();
1570 const int Size
= fontToUse
->GetPointSize();
1571 const int Style
= fontToUse
->GetStyle();
1572 const int Weight
= fontToUse
->GetWeight();
1574 // if we have another font, read the font-metrics
1575 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1576 // store actual values
1577 lastFamily
= Family
;
1580 lastWeight
= Weight
;
1582 // read in new font metrics **************************************
1584 // 1. construct filename ******************************************
1585 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1588 // Julian - we'll need to do this a different way now we've removed the
1589 // font directory system. Must find Stefan's original code.
1591 name
= wxTheFontNameDirectory
->GetAFMName(Family
, Weight
, Style
);
1595 // get the directory of the AFM files
1599 strcpy(afmName
,wxGetAFMPath());
1601 // 2. open and process the file **********************************
1603 // a short explanation of the AFM format:
1604 // we have for each character a line, which gives its size
1607 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1609 // that means, we have a character with ascii code 63, and width
1610 // (444/1000 * fontSize) points.
1611 // the other data is ignored for now!
1613 // when the font has changed, we read in the right AFM file and store the
1614 // character widths in an array, which is processed below (see point 3.).
1616 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1619 strcat(afmName
,name
);
1620 strcat(afmName
,".afm");
1621 FILE *afmFile
= fopen(afmName
,"r");
1623 wxLogDebug("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1624 wxLogDebug(" using approximate values\n");
1626 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1627 lastDescender
= -150; // dito.
1630 // init the widths array
1631 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1632 // some variables for holding parts of a line
1633 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1634 char upString
[30], utString
[30], encString
[50];
1637 // read in the file and parse it
1638 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1639 // A.) check for descender definition
1640 if(strncmp(line
,"Descender",9)==0){
1641 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1642 || (strcmp(descString
,"Descender")!=0)) {
1643 wxLogDebug("AFM-file '%s': line '%s' has error (bad descender)\n",
1647 // JC 1.) check for UnderlinePosition
1648 else if(strncmp(line
,"UnderlinePosition",17)==0){
1649 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1650 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1651 wxLogDebug("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1655 // JC 2.) check for UnderlineThickness
1656 else if(strncmp(line
,"UnderlineThickness",18)==0){
1657 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1658 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1659 wxLogDebug("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1663 // JC 3.) check for EncodingScheme
1664 else if(strncmp(line
,"EncodingScheme",14)==0){
1665 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1666 || (strcmp(utString
,"EncodingScheme")!=0)) {
1667 wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1670 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1672 wxLogDebug("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1673 afmName
,line
, encString
);
1676 // B.) check for char-width
1677 else if(strncmp(line
,"C ",2)==0){
1678 if(sscanf(line
,"%s%d%s%s%d",
1679 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1680 wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1682 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1683 strcmp(WXString
,"WX")!=0){
1684 wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1686 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1687 if(ascii
>=0 && ascii
<256){
1688 lastWidths
[ascii
] = cWidth
; // store width
1690 /* MATTHEW: this happens a lot; don't print an error */
1691 // wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1694 // C.) ignore other entries.
1698 // hack to compute correct values for german 'Umlaute'
1699 // the correct way would be to map the character names
1700 // like 'adieresis' to corresp. positions of ISOEnc and read
1701 // these values from AFM files, too. Maybe later ...
1702 lastWidths
[196] = lastWidths
['A']; // Ä
1703 lastWidths
[228] = lastWidths
['a']; // ä
1704 lastWidths
[214] = lastWidths
['O']; // Ö
1705 lastWidths
[246] = lastWidths
['o']; // ö
1706 lastWidths
[220] = lastWidths
['U']; // Ü
1707 lastWidths
[252] = lastWidths
['u']; // ü
1708 lastWidths
[223] = lastWidths
[251]; // ß
1711 // JC: calculate UnderlineThickness/UnderlinePosition
1712 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1713 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1715 // 3. now the font metrics are read in, calc size *******************
1716 // this is done by adding the widths of the characters in the
1717 // string. they are given in 1/1000 of the size!
1720 long height
=Size
; // by default
1722 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1723 if(lastWidths
[*p
]== INT_MIN
){
1724 wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n",
1726 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1728 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1731 // add descender to height (it is usually a negative value)
1732 if(lastDescender
!=INT_MIN
){
1733 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1736 // return size values
1740 // return other parameters
1742 if(lastDescender
!=INT_MIN
){
1743 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1749 // currently no idea how to calculate this!
1750 // if (externalLeading) *externalLeading = 0;
1751 if (externalLeading
)
1752 *externalLeading
= 0;
1754 // ----- end of contributed code -----
1758 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
1760 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1762 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1764 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1766 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1770 if (width
) *width
= paper
->widthMM
;
1771 if (height
) *height
= paper
->heightMM
;
1775 if (width
) *width
= 210;
1776 if (height
) *height
= 297;
1780 // Determine the Default Postscript Previewer
1781 // available on the platform
1782 #if defined(__SUN__) && defined(__XVIEW__)
1783 // OpenWindow/NeWS's Postscript Previewer
1784 # define PS_VIEWER_PROG "pageview"
1785 #elif defined(__VMS__)
1786 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
1787 #elif defined(__SGI__)
1788 // SGI's Display Postscript Previewer
1789 //# define PS_VIEWER_PROG "dps"
1790 # define PS_VIEWER_PROG "xpsview"
1791 #elif defined(__X__) || defined(__WXGTK__)
1792 // Front-end to ghostscript
1793 # define PS_VIEWER_PROG "ghostview"
1795 // Windows ghostscript/ghostview
1796 # define PS_VIEWER_PROG NULL
1799 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
1801 #if !USE_SHARED_LIBRARY
1802 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
1803 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
1804 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
1805 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
1808 // Redundant now I think
1810 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
1812 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
1813 const wxPoint
& pos
, const wxSize
& size
, long style
):
1814 wxDialog(parent
, -1, title
, pos
, size
, style
)
1816 wxBeginBusyCursor();
1821 *orientation
= new wxString
[2],
1822 *print_modes
= new wxString
[3];
1824 long wx_printer_translate_x
, wx_printer_translate_y
;
1825 double wx_printer_scale_x
, wx_printer_scale_y
;
1827 orientation
[0] = _("Portrait");
1828 orientation
[1] = _("Landscape");
1830 print_modes
[0] = _("Send to Printer");
1831 print_modes
[1] = _("Print to File");
1832 print_modes
[2] = _("Preview Only");
1836 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
1837 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
1838 okBut
->SetDefault();
1841 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1842 (void) new wxStaticText( this, -1, _("Printer Command: "),
1844 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
1845 wxPoint(100, yPos
), wxSize(100, -1) );
1847 (void) new wxStaticText( this, -1, _("Printer Options: "),
1848 wxPoint(210, yPos
) );
1849 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
1850 wxPoint(305, yPos
), wxSize(150, -1) );
1856 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
1857 2,orientation
,2,wxRA_SPECIFY_ROWS
);
1858 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
1860 // @@@ Configuration hook
1861 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
1862 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
1864 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
1866 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
1867 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
1869 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
1871 wxSize(-1,-1), features
,
1872 print_modes
, features
, wxRA_SPECIFY_ROWS
);
1875 radio1
->Enable(0, FALSE
);
1876 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
1877 radio1
->Enable(2, FALSE
);
1880 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
1881 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1882 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1884 sprintf (buf
, "%.2f", wx_printer_scale_x
);
1887 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
1888 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1890 sprintf (buf
, "%.2f", wx_printer_scale_y
);
1891 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
1892 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1896 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
1897 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
1898 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1900 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
1901 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
1902 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1906 delete[] orientation
;
1907 delete[] print_modes
;
1912 int wxPostScriptPrintDialog::ShowModal ()
1914 if ( wxDialog::ShowModal() == wxID_OK
)
1916 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
1917 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
1918 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
1919 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
1920 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
1921 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
1922 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
1923 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
1925 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
1926 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
1927 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
1928 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
1931 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
1932 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
1935 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
1938 switch ( radio1
->GetSelection() ) {
1939 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
1940 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
1941 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
1950 // PostScript printer settings
1951 // RETAINED FOR BACKWARD COMPATIBILITY
1952 void wxSetPrinterCommand(const char *cmd
)
1954 wxThePrintSetupData
->SetPrinterCommand(cmd
);
1957 void wxSetPrintPreviewCommand(const char *cmd
)
1959 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
1962 void wxSetPrinterOptions(const char *flags
)
1964 wxThePrintSetupData
->SetPrinterOptions(flags
);
1967 void wxSetPrinterFile(const char *f
)
1969 wxThePrintSetupData
->SetPrinterFile(f
);
1972 void wxSetPrinterOrientation(int orient
)
1974 wxThePrintSetupData
->SetPrinterOrientation(orient
);
1977 void wxSetPrinterScaling(double x
, double y
)
1979 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
1982 void wxSetPrinterTranslation(long x
, long y
)
1984 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
1987 // 1 = Preview, 2 = print to file, 3 = send to printer
1988 void wxSetPrinterMode(int mode
)
1990 wxThePrintSetupData
->SetPrinterMode(mode
);
1993 void wxSetAFMPath(const char *f
)
1995 wxThePrintSetupData
->SetAFMPath(f
);
1998 // Get current values
1999 char *wxGetPrinterCommand()
2001 return wxThePrintSetupData
->GetPrinterCommand();
2004 char *wxGetPrintPreviewCommand()
2006 return wxThePrintSetupData
->GetPrintPreviewCommand();
2009 char *wxGetPrinterOptions()
2011 return wxThePrintSetupData
->GetPrinterOptions();
2014 char *wxGetPrinterFile()
2016 return wxThePrintSetupData
->GetPrinterFile();
2019 int wxGetPrinterOrientation()
2021 return wxThePrintSetupData
->GetPrinterOrientation();
2024 void wxGetPrinterScaling(double* x
, double* y
)
2026 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2029 void wxGetPrinterTranslation(long *x
, long *y
)
2031 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2034 int wxGetPrinterMode()
2036 return wxThePrintSetupData
->GetPrinterMode();
2039 char *wxGetAFMPath()
2041 return wxThePrintSetupData
->GetAFMPath();
2048 wxPrintSetupData::wxPrintSetupData()
2050 printerCommand
= (char *) NULL
;
2051 previewCommand
= (char *) NULL
;
2052 printerFlags
= (char *) NULL
;
2053 printerOrient
= PS_PORTRAIT
;
2054 printerScaleX
= (double)1.0;
2055 printerScaleY
= (double)1.0;
2056 printerTranslateX
= 0;
2057 printerTranslateY
= 0;
2058 // 1 = Preview, 2 = print to file, 3 = send to printer
2060 afmPath
= (char *) NULL
;
2061 paperName
= (char *) NULL
;
2063 printerFile
= (char *) NULL
;
2066 wxPrintSetupData::~wxPrintSetupData()
2069 delete[] printerCommand
;
2071 delete[] previewCommand
;
2073 delete[] printerFlags
;
2079 delete[] printerFile
;
2082 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2084 if (cmd
== printerCommand
)
2088 delete[] printerCommand
;
2090 printerCommand
= copystring(cmd
);
2092 printerCommand
= (char *) NULL
;
2095 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2097 if (cmd
== previewCommand
)
2101 delete[] previewCommand
;
2103 previewCommand
= copystring(cmd
);
2105 previewCommand
= (char *) NULL
;
2108 void wxPrintSetupData::SetPaperName(const char *name
)
2110 if (name
== paperName
)
2116 paperName
= copystring(name
);
2118 paperName
= (char *) NULL
;
2121 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2123 if (printerFlags
== flags
)
2127 delete[] printerFlags
;
2129 printerFlags
= copystring(flags
);
2131 printerFlags
= (char *) NULL
;
2134 void wxPrintSetupData::SetPrinterFile(const char *f
)
2136 if (f
== printerFile
)
2140 delete[] printerFile
;
2142 printerFile
= copystring(f
);
2144 printerFile
= (char *) NULL
;
2147 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2149 printerOrient
= orient
;
2152 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2158 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2160 printerTranslateX
= x
;
2161 printerTranslateY
= y
;
2164 // 1 = Preview, 2 = print to file, 3 = send to printer
2165 void wxPrintSetupData::SetPrinterMode(int mode
)
2170 void wxPrintSetupData::SetAFMPath(const char *f
)
2178 afmPath
= copystring(f
);
2180 afmPath
= (char *) NULL
;
2183 void wxPrintSetupData::SetColour(bool col
)
2188 // Get current values
2189 char *wxPrintSetupData::GetPrinterCommand()
2191 return printerCommand
;
2194 char *wxPrintSetupData::GetPrintPreviewCommand()
2196 return previewCommand
;
2199 char *wxPrintSetupData::GetPrinterOptions()
2201 return printerFlags
;
2204 char *wxPrintSetupData::GetPrinterFile()
2209 char *wxPrintSetupData::GetPaperName()
2214 int wxPrintSetupData::GetPrinterOrientation()
2216 return printerOrient
;
2219 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2225 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2227 *x
= printerTranslateX
;
2228 *y
= printerTranslateY
;
2231 int wxPrintSetupData::GetPrinterMode()
2236 char *wxPrintSetupData::GetAFMPath()
2241 bool wxPrintSetupData::GetColour()
2246 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2248 SetPrinterCommand(data
.GetPrinterCommand());
2249 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2250 SetPrinterOptions(data
.GetPrinterOptions());
2252 data
.GetPrinterTranslation(&x
, &y
);
2253 SetPrinterTranslation(x
, y
);
2256 data
.GetPrinterScaling(&x1
, &y1
);
2257 SetPrinterScaling(x1
, y1
);
2259 SetPrinterOrientation(data
.GetPrinterOrientation());
2260 SetPrinterMode(data
.GetPrinterMode());
2261 SetAFMPath(data
.GetAFMPath());
2262 SetPaperName(data
.GetPaperName());
2263 SetColour(data
.GetColour());
2266 void wxInitializePrintSetupData(bool init
)
2270 wxThePrintSetupData
= new wxPrintSetupData
;
2272 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2273 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2274 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2275 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2277 // Could have a .ini file to read in some defaults
2278 // - and/or use environment variables, e.g. WXWIN
2280 wxThePrintSetupData
->SetPrinterCommand("print");
2281 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2282 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2285 wxThePrintSetupData
->SetPrinterCommand("print");
2286 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2287 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2289 #if !defined(__VMS__) && !defined(__WXMSW__)
2290 wxThePrintSetupData
->SetPrinterCommand("lpr");
2291 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2292 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2297 if (wxThePrintSetupData
)
2298 delete wxThePrintSetupData
;
2299 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2304 * Paper size database for PostScript
2307 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2313 pageName
= copystring(name
);
2316 wxPrintPaperType::~wxPrintPaperType()
2322 * Print paper database for PostScript
2325 #if !USE_SHARED_LIBRARIES
2326 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
2329 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2331 DeleteContents(TRUE
);
2334 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2338 void wxPrintPaperDatabase::CreateDatabase()
2340 // Need correct values for page size in pixels.
2341 // Each unit is one 'point' = 1/72 of an inch.
2342 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2343 // in wxPostScriptDC code, so we can start from top left.
2344 // So access this database and translate by appropriate number
2345 // of points for this paper size. OR IS IT OK ALREADY?
2346 // Can't remember where the PostScript origin is by default.
2347 // Heck, someone will know how to make it hunky-dory...
2350 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2351 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2352 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2353 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2358 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 210*4, 297*4 );
2359 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 297*4, 420*4 );
2360 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 216*4, 279*4 );
2361 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 216*4, 356*4 );
2365 void wxPrintPaperDatabase::ClearDatabase()
2370 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2372 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2375 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2377 wxNode
*node
= Find(name
);
2379 return (wxPrintPaperType
*)node
->Data();
2381 return (wxPrintPaperType
*) NULL
;
2385 * Initialization/cleanup module
2388 bool wxPostScriptModule::OnInit()
2390 wxInitializePrintSetupData();
2391 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2392 wxThePrintPaperDatabase
->CreateDatabase();
2397 void wxPostScriptModule::OnExit()
2399 wxInitializePrintSetupData(FALSE
);
2400 delete wxThePrintPaperDatabase
;
2401 wxThePrintPaperDatabase
= NULL
;