1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 #include "wx/wxprec.h"
30 #include "wx/dcmemory.h"
33 #include "wx/filedlg.h"
35 #include "wx/msgdlg.h"
38 #include "wx/generic/dcpsg.h"
39 #include "wx/generic/prntdlgg.h"
40 #include "wx/button.h"
41 #include "wx/stattext.h"
42 #include "wx/radiobox.h"
43 #include "wx/textctrl.h"
72 //-----------------------------------------------------------------------------
73 // start and end of document/page
74 //-----------------------------------------------------------------------------
76 static const char *wxPostScriptHeaderEllipse
= "\
77 /ellipsedict 8 dict def\n\
78 ellipsedict /mtrx matrix put\n\
82 /startangle exch def\n\
87 /savematrix mtrx currentmatrix def\n\
90 0 0 1 startangle endangle arc\n\
91 savematrix setmatrix\n\
96 static const char *wxPostScriptHeaderEllipticArc
= "\
97 /ellipticarcdict 8 dict def\n\
98 ellipticarcdict /mtrx matrix put\n\
100 { ellipticarcdict begin\n\
102 /endangle exch def\n\
103 /startangle exch def\n\
108 /savematrix mtrx currentmatrix def\n\
111 do_fill { 0 0 moveto } if\n\
112 0 0 1 startangle endangle arc\n\
113 savematrix setmatrix\n\
114 do_fill { fill }{ stroke } ifelse\n\
118 static const char *wxPostScriptHeaderSpline
= "\
119 /DrawSplineSection {\n\
126 /xa x1 x2 x1 sub 0.666667 mul add def\n\
127 /ya y1 y2 y1 sub 0.666667 mul add def\n\
128 /xb x3 x2 x3 sub 0.666667 mul add def\n\
129 /yb y3 y2 y3 sub 0.666667 mul add def\n\
131 xa ya xb yb x3 y3 curveto\n\
135 static const char *wxPostScriptHeaderColourImage
= "\
136 % define 'colorimage' if it isn't defined\n\
137 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
139 /colorimage where % do we know about 'colorimage'?\n\
140 { pop } % yes: pop off the 'dict' returned\n\
141 { % no: define one\n\
142 /colortogray { % define an RGB->I function\n\
143 /rgbdata exch store % call input 'rgbdata'\n\
144 rgbdata length 3 idiv\n\
145 /npixls exch store\n\
147 0 1 npixls 1 sub {\n\
149 rgbdata rgbindx get 20 mul % Red\n\
150 rgbdata rgbindx 1 add get 32 mul % Green\n\
151 rgbdata rgbindx 2 add get 12 mul % Blue\n\
152 add add 64 idiv % I = .5G + .31R + .18B\n\
154 /rgbindx rgbindx 3 add store\n\
156 grays 0 npixls getinterval\n\
159 % Utility procedure for colorimage operator.\n\
160 % This procedure takes two procedures off the\n\
161 % stack and merges them into a single procedure.\n\
163 /mergeprocs { % def\n\
182 /colorimage { % def\n\
183 pop pop % remove 'false 3' operands\n\
184 {colortogray} mergeprocs\n\
187 } ifelse % end of 'false' case\n\
190 static char wxPostScriptHeaderReencodeISO1
[] =
192 "dup dup findfont dup length dict begin\n"
193 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
194 "/Encoding ISOLatin1Encoding def\n"
195 "currentdict end definefont\n"
197 "/ISOLatin1Encoding [\n"
198 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
199 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
200 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
201 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
202 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
203 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
204 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
205 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
206 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
207 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
208 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
209 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
210 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
211 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
212 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
214 static char wxPostScriptHeaderReencodeISO2
[] =
215 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
216 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
217 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
218 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
219 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
220 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
221 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
222 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
223 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
224 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
225 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
226 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
227 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
228 "/yacute/thorn/ydieresis\n"
231 //-------------------------------------------------------------------------------
233 //-------------------------------------------------------------------------------
235 wxPostScriptDC::wxPostScriptDC ()
237 m_pstream
= (ofstream
*) NULL
;
247 m_underlinePosition
= 0.0;
248 m_underlineThickness
= 0.0;
250 m_signX
= 1; // default x-axis left to right
251 m_signY
= -1; // default y-axis bottom up -> top down
254 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
256 m_pstream
= (ofstream
*) NULL
;
266 m_underlinePosition
= 0.0;
267 m_underlineThickness
= 0.0;
269 m_signX
= 1; // default x-axis left to right
270 m_signY
= -1; // default y-axis bottom up -> top down
272 Create(file
, interactive
, parent
);
275 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
277 m_isInteractive
= interactive
;
283 // Can only send to file in Windows
284 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
289 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
299 wxPostScriptDC::~wxPostScriptDC ()
301 if (m_pstream
) delete m_pstream
;
304 bool wxPostScriptDC::Ok() const
309 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
311 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
312 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
313 m_ok
= (dialog
.ShowModal () == wxID_OK
);
315 if (!m_ok
) return FALSE
;
317 if ((m_filename
== "") &&
318 (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
||
319 wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
323 wxThePrintSetupData
->SetPrinterFile("preview");
325 // For PS_PRINTER action this depends on a Unix-style print spooler
326 // since the wx_printer_file can be destroyed during a session
327 // @@@ TODO: a Windows-style answer for non-Unix
329 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
331 strcpy (tmp
, "/tmp/preview_");
332 strcat (tmp
, userId
);
333 wxThePrintSetupData
->SetPrinterFile(tmp
);
336 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
337 strcat (tmp2
, ".ps");
338 wxThePrintSetupData
->SetPrinterFile(tmp2
);
341 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
343 wxString file
= wxSaveFileSelector (_("PostScript"), "ps");
344 if ( file
.IsEmpty() )
350 wxThePrintSetupData
->SetPrinterFile(file
);
358 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
360 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
362 if (m_clipping
) return;
364 wxDC::SetClippingRegion( x
, y
, w
, h
);
367 *m_pstream
<< "gsave\n"
369 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
370 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
371 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
372 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
373 << "closepath clip newpath\n";
376 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
380 void wxPostScriptDC::DestroyClippingRegion()
382 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
384 wxDC::DestroyClippingRegion();
389 *m_pstream
<< "grestore\n";
393 void wxPostScriptDC::Clear()
395 wxFAIL_MSG( "wxPostScriptDC::Clear not implemented." );
398 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
400 wxFAIL_MSG( "wxPostScriptDC::FloodFill not implemented." );
403 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
405 wxFAIL_MSG( "wxPostScriptDC::GetPixel not implemented." );
409 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
411 wxFAIL_MSG( "wxPostScriptDC::CrossHair not implemented." );
414 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
416 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
418 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
422 *m_pstream
<< "newpath\n"
423 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
424 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
427 CalcBoundingBox( x1
, y1
);
428 CalcBoundingBox( x2
, y2
);
431 #define RAD2DEG 57.29577951308
433 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
435 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
439 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
440 double alpha1
, alpha2
;
442 if (x1
== x2
&& y1
== y2
)
446 } else if (radius
== 0.0)
448 alpha1
= alpha2
= 0.0;
451 alpha1
= (x1
- xc
== 0) ?
452 (y1
- yc
< 0) ? 90.0 : -90.0 :
453 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
454 alpha2
= (x2
- xc
== 0) ?
455 (y2
- yc
< 0) ? 90.0 : -90.0 :
456 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
458 while (alpha1
<= 0) alpha1
+= 360;
459 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
460 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
461 while (alpha2
> 360) alpha2
-= 360;
463 if (m_brush
.GetStyle() != wxTRANSPARENT
)
466 *m_pstream
<< "newpath\n"
467 << XLOG2DEV(xc
) << " "
468 << YLOG2DEV(yc
) << " "
469 << XLOG2DEVREL(radius
) << " "
470 << YLOG2DEVREL(radius
) << " "
472 << alpha2
<< " ellipse\n"
473 << XLOG2DEV(xc
) << " "
474 << YLOG2DEV(yc
) << " lineto\n"
479 if (m_pen
.GetStyle() != wxTRANSPARENT
)
482 *m_pstream
<< "newpath\n"
483 << XLOG2DEV(xc
) << " "
484 << YLOG2DEV(yc
) << " "
485 << XLOG2DEVREL(radius
) << " "
486 << YLOG2DEVREL(radius
) << " "
488 << alpha2
<< " ellipse\n"
492 CalcBoundingBox( xc
-radius
, yc
-radius
);
493 CalcBoundingBox( xc
+radius
, yc
+radius
);
496 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
498 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
500 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
501 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
507 DrawEllipse(x
,y
,w
,h
);
511 if (m_brush
.GetStyle () != wxTRANSPARENT
)
515 *m_pstream
<< "newpath\n"
516 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
517 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
518 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
520 CalcBoundingBox( x
,y
);
521 CalcBoundingBox( x
+w
, y
+h
);
524 if (m_pen
.GetStyle () != wxTRANSPARENT
)
528 *m_pstream
<< "newpath\n"
529 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
530 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
531 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
533 CalcBoundingBox( x
, y
);
534 CalcBoundingBox( x
+w
, y
+h
);
538 void wxPostScriptDC::DrawPoint (long x
, long y
)
540 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
542 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
546 *m_pstream
<< "newpath\n"
547 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
548 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
551 CalcBoundingBox( x
, y
);
554 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
556 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
560 if (m_brush
.GetStyle () != wxTRANSPARENT
)
564 *m_pstream
<< "newpath\n";
566 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
567 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
568 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
569 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
571 for (int i
= 1; i
< n
; i
++)
573 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
574 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
575 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
576 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
578 *m_pstream
<< "fill\n";
581 if (m_pen
.GetStyle () != wxTRANSPARENT
)
585 *m_pstream
<< "newpath\n";
587 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
588 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
589 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
590 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
592 for (int i
= 1; i
< n
; i
++)
594 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
595 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
596 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
597 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
600 *m_pstream
<< "stroke\n";
604 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
606 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
608 if (m_pen
.GetStyle() == wxTRANSPARENT
)
616 for ( i
=0; i
<n
; i
++ )
618 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
621 *m_pstream
<< "newpath\n"
622 << XLOG2DEV(points
[0].x
+xoffset
) << " "
623 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
625 for (i
= 1; i
< n
; i
++)
627 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
628 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
631 *m_pstream
<< "stroke\n";
634 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
636 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
638 if (m_brush
.GetStyle () != wxTRANSPARENT
)
642 *m_pstream
<< "newpath\n"
643 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
644 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
645 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
646 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
650 CalcBoundingBox( x
, y
);
651 CalcBoundingBox( x
+ width
, y
+ height
);
654 if (m_pen
.GetStyle () != wxTRANSPARENT
)
658 *m_pstream
<< "newpath\n"
659 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
660 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
661 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
662 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
666 CalcBoundingBox( x
, y
);
667 CalcBoundingBox( x
+ width
, y
+ height
);
671 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
673 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
677 // Now, a negative radius is interpreted to mean
678 // 'the proportion of the smallest X or Y dimension'
679 double smallest
= 0.0;
684 radius
= (-radius
* smallest
);
687 long rad
= (long) radius
;
689 if (m_brush
.GetStyle () != wxTRANSPARENT
)
693 // Draw rectangle anticlockwise
694 *m_pstream
<< "newpath\n"
695 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
696 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
697 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
698 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
699 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
700 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
701 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
702 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
706 CalcBoundingBox( x
, y
);
707 CalcBoundingBox( x
+ width
, y
+ height
);
710 if (m_pen
.GetStyle () != wxTRANSPARENT
)
714 // Draw rectangle anticlockwise
715 *m_pstream
<< "newpath\n"
716 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
717 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
718 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
719 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
720 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
721 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
722 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
723 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
727 CalcBoundingBox( x
, y
);
728 CalcBoundingBox( x
+ width
, y
+ height
);
732 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
734 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
736 if (m_brush
.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
);
749 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
753 *m_pstream
<< "newpath\n"
754 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
755 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
758 CalcBoundingBox( x
- width
, y
- height
);
759 CalcBoundingBox( x
+ width
, y
+ height
);
763 void wxPostScriptDC::DrawIcon( const wxIcon
& icon
, long x
, long y
)
765 DrawBitmap( icon
, x
, y
, TRUE
);
768 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool WXUNUSED(useMask
) )
770 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
772 if (!bitmap
.Ok()) return;
774 wxImage
image( bitmap
);
776 if (!image
.Ok()) return;
778 int ww
= XLOG2DEVREL(image
.GetWidth());
779 int hh
= YLOG2DEVREL(image
.GetHeight());
781 image
= image
.Scale( ww
, hh
);
783 if (!image
.Ok()) return;
785 int xx
= XLOG2DEV(x
);
786 int yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
788 *m_pstream
<< "/origstate save def\n"
790 << "/pix " << ww
<< " string def\n"
791 << "/grays " << ww
<< " string def\n"
792 << "/npixels 0 def\n"
793 << "/rgbindx 0 def\n"
794 << xx
<< " " << yy
<< " translate\n"
795 << ww
<< " " << hh
<< " scale\n"
796 << ww
<< " " << hh
<< " 8\n"
797 << "[" << ww
<< " 0 0 " << (-hh
) << " 0 " << hh
<< "]\n"
798 << "{currentfile pix readhexstring pop}\n"
799 << "false 3 colorimage\n";
801 for (int j
= 0; j
< hh
; j
++)
803 for (int i
= 0; i
< ww
; i
++)
807 wxDecToHex( image
.GetRed(i
,j
), buffer
);
808 *m_pstream
<< buffer
;
809 wxDecToHex( image
.GetGreen(i
,j
), buffer
);
810 *m_pstream
<< buffer
;
811 wxDecToHex( image
.GetBlue(i
,j
), buffer
);
812 *m_pstream
<< buffer
;
817 *m_pstream
<< "end\n";
818 *m_pstream
<< "origstate restore\n";
822 void wxPostScriptDC::SetFont( const wxFont
& font
)
824 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
826 if (!font
.Ok()) return;
831 const char *style
= "";
832 int Style
= m_font
.GetStyle();
833 int Weight
= m_font
.GetWeight();
835 switch (m_font
.GetFamily ())
845 // name = "/Times-Roman";
846 name
= "/Times"; // Altered by EDZ
849 name
= "/Zapf-Chancery-MediumItalic";
854 case wxDEFAULT
: // Sans Serif Font
855 name
= "/LucidaSans";
858 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
860 if (m_font
.GetFamily () == wxROMAN
)
865 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
869 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
871 if (m_font
.GetFamily () == wxROMAN
)
876 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
878 if (m_font
.GetFamily () == wxROMAN
)
879 style
= "-BoldItalic";
881 style
= "-BoldOblique";
883 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
885 if (m_font
.GetFamily () == wxROMAN
)
890 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
892 if (m_font
.GetFamily () == wxROMAN
)
893 style
= "-BoldItalic";
895 style
= "-BoldOblique";
906 *m_pstream
<< buf
<< " reencodeISO def\n";
907 *m_pstream
<< buf
<< " findfont\n";
908 *m_pstream
<< YLOG2DEVREL(m_font
.GetPointSize()) << " scalefont setfont\n";
911 void wxPostScriptDC::SetPen( const wxPen
& pen
)
913 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
915 if (!pen
.Ok()) return;
917 int oldStyle
= m_pen
.GetStyle();
921 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
924 Line style - WRONG: 2nd arg is OFFSET
926 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
927 operator correctly. You should look-up this in the Red Book: the 2nd parame-
928 ter is not number of values in the array of the first one, but an offset
929 into this description of the pattern. I mean a real *offset* not index
930 into array. I.e. If the command is [3 4] 1 setdash is used, then there
931 will be first black line *2* units long, then space 4 units, then the
932 pattern of *3* units black, 4 units space will be repeated.
935 static const char *dotted
= "[2 5] 2";
936 static const char *short_dashed
= "[4 4] 2";
937 static const char *long_dashed
= "[4 8] 2";
938 static const char *dotted_dashed
= "[6 6 2 6] 4";
940 const char *psdash
= (char *) NULL
;
941 switch (m_pen
.GetStyle ())
943 case wxDOT
: psdash
= dotted
; break;
944 case wxSHORT_DASH
: psdash
= short_dashed
; break;
945 case wxLONG_DASH
: psdash
= long_dashed
; break;
946 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
949 default: psdash
= "[] 0"; break;
952 if (oldStyle
!= m_pen
.GetStyle())
954 *m_pstream
<< psdash
<< " setdash\n";
958 unsigned char red
= m_pen
.GetColour().Red();
959 unsigned char blue
= m_pen
.GetColour().Blue();
960 unsigned char green
= m_pen
.GetColour().Green();
964 // Anything not white is black
965 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
966 && green
== (unsigned char) 255))
968 red
= (unsigned char) 0;
969 green
= (unsigned char) 0;
970 blue
= (unsigned char) 0;
976 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
978 long redPS
= (long) (((int) red
) / 255.0);
979 long bluePS
= (long) (((int) blue
) / 255.0);
980 long greenPS
= (long) (((int) green
) / 255.0);
982 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
985 m_currentBlue
= blue
;
986 m_currentGreen
= green
;
990 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
992 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
994 if (!brush
.Ok()) return;
999 unsigned char red
= m_brush
.GetColour ().Red ();
1000 unsigned char blue
= m_brush
.GetColour ().Blue ();
1001 unsigned char green
= m_brush
.GetColour ().Green ();
1005 // Anything not black is white
1006 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
1007 && green
== (unsigned char) 0))
1009 red
= (unsigned char) 255;
1010 green
= (unsigned char) 255;
1011 blue
= (unsigned char) 255;
1017 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1019 long redPS
= (long) (((int) red
) / 255.0);
1020 long bluePS
= (long) (((int) blue
) / 255.0);
1021 long greenPS
= (long) (((int) green
) / 255.0);
1022 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1024 m_currentBlue
= blue
;
1025 m_currentGreen
= green
;
1029 void wxPostScriptDC::DrawText( const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
) )
1031 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1035 if (m_textForegroundColour
.Ok ())
1037 unsigned char red
= m_textForegroundColour
.Red ();
1038 unsigned char blue
= m_textForegroundColour
.Blue ();
1039 unsigned char green
= m_textForegroundColour
.Green ();
1043 // Anything not white is black
1044 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
1045 && green
== (unsigned char) 255))
1047 red
= (unsigned char) 0;
1048 green
= (unsigned char) 0;
1049 blue
= (unsigned char) 0;
1053 // maybe setgray here ?
1055 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1057 long redPS
= (long) (((int) red
) / 255.0);
1058 long bluePS
= (long) (((int) blue
) / 255.0);
1059 long greenPS
= (long) (((int) green
) / 255.0);
1060 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1063 m_currentBlue
= blue
;
1064 m_currentGreen
= green
;
1068 int size
= m_font
.GetPointSize();
1070 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
1071 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
1074 int len
= strlen ((char *)(const char *)text
);
1076 for (i
= 0; i
< len
; i
++)
1078 int c
= (unsigned char) text
[i
];
1079 if ( c
== ')' || c
== '(' || c
== '\\')
1081 *m_pstream
<< "\\" << (char) c
;
1083 else if ( c
>= 128 )
1085 // Cope with character codes > 127
1087 sprintf(tmp
, "\\%o", c
);
1091 *m_pstream
<< (char) c
;
1094 *m_pstream
<< ")" << " show\n";
1096 if (m_font
.GetUnderlined())
1098 long uy
= (long)(y
+ size
- m_underlinePosition
);
1100 GetTextExtent(text
, &w
, &h
);
1102 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
1104 << (long)m_underlineThickness
<< " setlinewidth "
1105 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
1106 << " lineto stroke grestore\n";
1109 CalcBoundingBox( x
, y
);
1110 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1114 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1116 m_backgroundBrush
= brush
;
1119 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1121 wxFAIL_MSG( "wxPostScriptDC::SetLogicalFunction not implemented." );
1124 void wxPostScriptDC::DrawSpline( wxList
*points
)
1126 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1130 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1133 wxNode
*node
= points
->First();
1134 p
= (wxPoint
*)node
->Data();
1138 node
= node
->Next();
1139 p
= (wxPoint
*)node
->Data();
1142 x3
= a
= (double)(x1
+ c
) / 2;
1143 y3
= b
= (double)(y1
+ d
) / 2;
1145 *m_pstream
<< "newpath "
1146 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
1147 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
1149 CalcBoundingBox( (long)x1
, (long)y1
);
1150 CalcBoundingBox( (long)x3
, (long)y3
);
1152 while ((node
= node
->Next()) != NULL
)
1154 q
= (wxPoint
*)node
->Data();
1162 x3
= (double)(x2
+ c
) / 2;
1163 y3
= (double)(y2
+ d
) / 2;
1164 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
1165 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
1166 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
1168 CalcBoundingBox( (long)x1
, (long)y1
);
1169 CalcBoundingBox( (long)x3
, (long)y3
);
1173 At this point, (x2,y2) and (c,d) are the position of the
1174 next-to-last and last point respectively, in the point list
1177 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1180 long wxPostScriptDC::GetCharWidth ()
1182 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1183 return (long) (GetCharHeight() * 72.0 / 120.0);
1187 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1189 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1191 m_signX
= (xLeftRight
? 1 : -1);
1192 m_signY
= (yBottomUp
? 1 : -1);
1194 // FIXME there is no such function in MSW
1196 ComputeScaleAndOrigin();
1200 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1202 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1208 wxDC::SetDeviceOrigin( x
, h
-y
);
1211 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1213 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1215 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1217 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1219 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1223 if (width
) *width
= paper
->widthPixels
;
1224 if (height
) *height
= paper
->heightPixels
;
1228 if (width
) *width
= 595;
1229 if (height
) *height
= 842;
1233 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1235 wxCHECK_MSG( m_ok
, FALSE
, "invalid postscript dc" );
1237 if (m_filename
== "")
1239 m_filename
= wxGetTempFileName("ps");
1240 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1245 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1248 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1250 if (!m_pstream
|| !m_pstream
->good())
1252 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1259 SetBrush( *wxBLACK_BRUSH
);
1260 SetPen( *wxBLACK_PEN
);
1261 SetBackground( *wxWHITE_BRUSH
);
1262 SetTextForeground( *wxBLACK
);
1264 // set origin according to paper size
1265 SetDeviceOrigin( 0,0 );
1273 void wxPostScriptDC::EndDoc ()
1275 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1280 *m_pstream
<< "grestore\n";
1286 m_pstream
= (ofstream
*) NULL
;
1289 char *header_file
= wxGetTempFileName("ps");
1291 m_pstream
= new ofstream( header_file
);
1293 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1294 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1295 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1296 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1299 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1301 *m_pstream
<< "%%For: " << (char *)userID
;
1303 if (wxGetUserName(userName
, sizeof(userName
)))
1304 *m_pstream
<< " (" << (char *)userName
<< ")";
1307 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1309 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1312 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1314 long wx_printer_translate_x
, wx_printer_translate_y
;
1315 double wx_printer_scale_x
, wx_printer_scale_y
;
1316 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1317 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1319 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1321 *m_pstream
<< "%%Orientation: Landscape\n";
1325 *m_pstream
<< "%%Orientation: Portrait\n";
1328 // Compute the bounding box. Note that it is in the default user
1329 // coordinate system, thus we have to convert the values.
1330 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1331 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1332 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1333 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1335 // If we're landscape, our sense of "x" and "y" is reversed.
1336 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1339 tmp
= llx
; llx
= lly
; lly
= tmp
;
1340 tmp
= urx
; urx
= ury
; ury
= tmp
;
1342 // We need either the two lines that follow, or we need to subtract
1343 // min_x from real_translate_y, which is commented out below.
1344 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1345 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1348 // The Adobe specifications call for integers; we round as to make
1349 // the bounding larger.
1350 *m_pstream
<< "%%BoundingBox: "
1351 << floor((double)llx
) << " " << floor((double)lly
) << " "
1352 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1353 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1354 *m_pstream
<< "%%EndComments\n\n";
1356 // To check the correctness of the bounding box, postscript commands
1357 // to draw a box corresponding to the bounding box are generated below.
1358 // But since we typically don't want to print such a box, the postscript
1359 // commands are generated within comments. These lines appear before any
1360 // adjustment of scale, rotation, or translation, and hence are in the
1361 // default user coordinates.
1362 *m_pstream
<< "% newpath\n";
1363 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1364 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1365 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1366 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1368 *m_pstream
<< "%%BeginProlog\n";
1369 *m_pstream
<< wxPostScriptHeaderEllipse
;
1370 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1371 *m_pstream
<< wxPostScriptHeaderColourImage
;
1372 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1373 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1375 if (wxPostScriptHeaderSpline
)
1376 *m_pstream
<< wxPostScriptHeaderSpline
;
1377 *m_pstream
<< "%%EndProlog\n";
1380 m_pstream
= (ofstream
*) NULL
;
1382 char *tmp_file
= wxGetTempFileName("ps");
1384 // Paste header Before wx_printer_file
1385 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1386 wxRemoveFile (header_file
);
1387 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1388 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1390 #if defined(__X__) || defined(__WXGTK__)
1393 switch (wxThePrintSetupData
->GetPrinterMode()) {
1397 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1398 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1399 argv
[2] = (char *) NULL
;
1400 wxExecute (argv
, TRUE
);
1401 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1409 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1411 // !SM! If we simply assign to argv[1] here, if printer options
1412 // are blank, we get an annoying and confusing message from lpr.
1413 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1415 argv
[argc
++] = opts
;
1417 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1418 argv
[argc
++] = (char *) NULL
;
1419 wxExecute (argv
, TRUE
);
1420 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1431 void wxPostScriptDC::StartPage ()
1433 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1435 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1437 // *m_pstream << "matrix currentmatrix\n";
1439 // Added by Chris Breeze
1441 // Each page starts with an "initgraphics" which resets the
1442 // transformation and so we need to reset the origin
1443 // (and rotate the page for landscape printing)
1446 m_scaleFactor = 1.0;
1447 m_logicalOriginX = 0;
1448 m_logicalOriginY = 0;
1451 long translate_x
, translate_y
;
1452 double scale_x
, scale_y
;
1453 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1454 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1456 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1458 translate_y
-= m_maxY
;
1459 *m_pstream
<< "90 rotate\n";
1462 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1463 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1466 void wxPostScriptDC::EndPage ()
1468 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1470 *m_pstream
<< "showpage\n";
1473 bool wxPostScriptDC::Blit( long xdest
, long ydest
,
1474 long fwidth
, long fheight
,
1476 long xsrc
, long ysrc
,
1477 int rop
, bool WXUNUSED(useMask
) )
1479 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, "invalid postscript dc" );
1481 wxCHECK_MSG( source
, FALSE
, "invalid source dc" );
1483 wxClientDC
*srcDC
= (wxClientDC
*)source
;
1485 wxBitmap
bitmap( fwidth
, fheight
);
1488 /* just take any GC so we don't have to create our own. */
1490 GtkStyle
*style
= gtk_widget_get_default_style ();
1491 GdkGC
*gc
= style
->white_gc
;
1493 /* copy from either window or bitmap */
1495 gdk_window_copy_area( bitmap
.GetPixmap(), gc
, 0, 0,
1497 xsrc
, ysrc
, fwidth
, fheight
);
1500 memDC
.SelectObject(bitmap
);
1501 // TODO: Do we want to blit transparently?
1502 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
);
1503 memDC
.SelectObject(wxNullBitmap
);
1506 /* draw bitmap. scaling and positioning is done there */
1508 DrawBitmap( bitmap
, xdest
, ydest
);
1513 long wxPostScriptDC::GetCharHeight()
1516 return m_font
.GetPointSize();
1521 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1522 long *descent
, long *externalLeading
, wxFont
*theFont
,
1523 bool WXUNUSED(use16
))
1525 wxFont
*fontToUse
= theFont
;
1527 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1529 wxCHECK_RET( fontToUse
, "GetTextExtent: no font defined" );
1530 wxCHECK_RET( x
, "GetTextExtent: x == NULL" );
1531 wxCHECK_RET( y
, "GetTextExtent: y == NULL" );
1533 #if !USE_AFM_FOR_POSTSCRIPT
1534 /* Provide a VERY rough estimate (avoid using it).
1535 * Produces accurate results for mono-spaced font
1536 * such as Courier (aka wxMODERN) */
1541 height
= fontToUse
->GetPointSize();
1543 *x
= strlen (string
) * height
* 72 / 120;
1544 *y
= (long) (height
* 1.32); /* allow for descender */
1545 if (descent
) *descent
= 0;
1546 if (externalLeading
) *externalLeading
= 0;
1549 /* method for calculating string widths in postscript:
1550 / read in the AFM (adobe font metrics) file for the
1551 / actual font, parse it and extract the character widths
1552 / and also the descender. this may be improved, but for now
1553 / it works well. the AFM file is only read in if the
1554 / font is changed. this may be chached in the future.
1555 / calls to GetTextExtent with the font unchanged are rather
1558 / for each font and style used there is an AFM file necessary.
1559 / currently i have only files for the roman font family.
1560 / I try to get files for the other ones!
1562 / CAVE: the size of the string is currently always calculated
1563 / in 'points' (1/72 of an inch). this should later on be
1564 / changed to depend on the mapping mode.
1565 / CAVE: the path to the AFM files must be set before calling this
1566 / function. this is usually done by a call like the following:
1567 / wxSetAFMPath("d:\\wxw161\\afm\\");
1571 / wxPostScriptDC dc(NULL, TRUE);
1573 / wxSetAFMPath("d:\\wxw161\\afm\\");
1574 / dc.StartDoc("Test");
1577 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1578 / dc.GetTextExtent("Hallo",&w,&h);
1583 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1585 / updated: 14.05.95 */
1587 /* these static vars are for storing the state between calls */
1588 static int lastFamily
= INT_MIN
;
1589 static int lastSize
= INT_MIN
;
1590 static int lastStyle
= INT_MIN
;
1591 static int lastWeight
= INT_MIN
;
1592 static int lastDescender
= INT_MIN
;
1593 static int lastWidths
[256]; /* widths of the characters */
1595 /* get actual parameters */
1596 const int Family
= fontToUse
->GetFamily();
1597 const int Size
= fontToUse
->GetPointSize();
1598 const int Style
= fontToUse
->GetStyle();
1599 const int Weight
= fontToUse
->GetWeight();
1601 /* if we have another font, read the font-metrics */
1602 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1604 /* store actual values */
1605 lastFamily
= Family
;
1608 lastWeight
= Weight
;
1610 char *name
= (char*) NULL
;
1616 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO";
1617 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo";
1618 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Cour0";
1624 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO";
1625 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo";
1626 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO";
1627 else if name
= "TimesRo"; /* no typo */
1632 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO";
1633 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo";
1634 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Helv0";
1640 /* get the directory of the AFM files */
1643 if (wxGetAFMPath()) strcpy( afmName
, wxGetAFMPath() );
1645 /* 2. open and process the file
1646 / a short explanation of the AFM format:
1647 / we have for each character a line, which gives its size
1650 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1652 / that means, we have a character with ascii code 63, and width
1653 / (444/1000 * fontSize) points.
1654 / the other data is ignored for now!
1656 / when the font has changed, we read in the right AFM file and store the
1657 / character widths in an array, which is processed below (see point 3.). */
1659 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
1661 strcat(afmName
,name
);
1662 strcat(afmName
,".afm");
1663 FILE *afmFile
= fopen(afmName
,"r");
1664 if ( afmFile
==NULL
)
1666 wxLogDebug( "GetTextExtent: can't open AFM file '%s'\n", afmName
);
1667 wxLogDebug( " using approximate values\n");
1668 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
1669 lastDescender
= -150; /* dito. */
1673 /* init the widths array */
1674 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
1675 /* some variables for holding parts of a line */
1676 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1677 char upString
[30], utString
[30], encString
[50];
1680 /* read in the file and parse it */
1681 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
1683 /* A.) check for descender definition */
1684 if (strncmp(line
,"Descender",9)==0)
1686 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
1687 (strcmp(descString
,"Descender")!=0))
1689 wxLogDebug( "AFM-file '%s': line '%s' has error (bad descender)\n", afmName
,line
);
1692 /* JC 1.) check for UnderlinePosition */
1693 else if(strncmp(line
,"UnderlinePosition",17)==0)
1695 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
1696 (strcmp(upString
,"UnderlinePosition")!=0))
1698 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", afmName
, line
);
1701 /* JC 2.) check for UnderlineThickness */
1702 else if(strncmp(line
,"UnderlineThickness",18)==0)
1704 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
1705 (strcmp(utString
,"UnderlineThickness")!=0))
1707 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", afmName
, line
);
1710 /* JC 3.) check for EncodingScheme */
1711 else if(strncmp(line
,"EncodingScheme",14)==0)
1713 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
1714 (strcmp(utString
,"EncodingScheme")!=0))
1716 wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", afmName
, line
);
1718 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1720 wxLogDebug( "AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1721 afmName
,line
, encString
);
1724 /* B.) check for char-width */
1725 else if(strncmp(line
,"C ",2)==0)
1727 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
1729 wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1731 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
1733 wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1735 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
1736 if (ascii
>=0 && ascii
<256)
1738 lastWidths
[ascii
] = cWidth
; /* store width */
1742 /* MATTHEW: this happens a lot; don't print an error */
1743 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); */
1746 /* C.) ignore other entries. */
1750 /* hack to compute correct values for german 'Umlaute'
1751 / the correct way would be to map the character names
1752 / like 'adieresis' to corresp. positions of ISOEnc and read
1753 / these values from AFM files, too. Maybe later ... */
1754 lastWidths
[196] = lastWidths
['A']; // Ä
1755 lastWidths
[228] = lastWidths
['a']; // ä
1756 lastWidths
[214] = lastWidths
['O']; // Ö
1757 lastWidths
[246] = lastWidths
['o']; // ö
1758 lastWidths
[220] = lastWidths
['U']; // Ü
1759 lastWidths
[252] = lastWidths
['u']; // ü
1760 lastWidths
[223] = lastWidths
[251]; // ß
1763 /* JC: calculate UnderlineThickness/UnderlinePosition */
1764 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1765 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1767 /* 3. now the font metrics are read in, calc size this
1768 / is done by adding the widths of the characters in the
1769 / string. they are given in 1/1000 of the size! */
1772 long height
=Size
; /* by default */
1774 for(p
=(unsigned char *)(const char *)string
; *p
; p
++)
1776 if(lastWidths
[*p
]== INT_MIN
)
1778 wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n", *p
,*p
);
1779 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); /* assume space */
1783 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1787 /* add descender to height (it is usually a negative value) */
1788 if (lastDescender
!=INT_MIN
)
1790 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1793 /* return size values */
1797 /* return other parameters */
1800 if(lastDescender
!=INT_MIN
)
1802 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1810 /* currently no idea how to calculate this! */
1811 if (externalLeading
) *externalLeading
= 0;
1816 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
1818 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1820 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1822 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1824 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1828 if (width
) *width
= paper
->widthMM
;
1829 if (height
) *height
= paper
->heightMM
;
1833 if (width
) *width
= 210;
1834 if (height
) *height
= 297;
1838 // Determine the Default Postscript Previewer
1839 // available on the platform
1840 #if defined(__SUN__) && defined(__XVIEW__)
1841 // OpenWindow/NeWS's Postscript Previewer
1842 # define PS_VIEWER_PROG "pageview"
1843 #elif defined(__VMS__)
1844 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
1845 #elif defined(__SGI__)
1846 // SGI's Display Postscript Previewer
1847 //# define PS_VIEWER_PROG "dps"
1848 # define PS_VIEWER_PROG "xpsview"
1849 #elif defined(__X__) || defined(__WXGTK__)
1850 // Front-end to ghostscript
1851 # define PS_VIEWER_PROG "ghostview"
1853 // Windows ghostscript/ghostview
1854 # define PS_VIEWER_PROG NULL
1857 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
1859 #if !USE_SHARED_LIBRARY
1860 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
1861 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
1862 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
1863 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
1866 // Redundant now I think
1868 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
1870 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
1871 const wxPoint
& pos
, const wxSize
& size
, long style
):
1872 wxDialog(parent
, -1, title
, pos
, size
, style
)
1874 wxBeginBusyCursor();
1879 *orientation
= new wxString
[2],
1880 *print_modes
= new wxString
[3];
1882 long wx_printer_translate_x
, wx_printer_translate_y
;
1883 double wx_printer_scale_x
, wx_printer_scale_y
;
1885 orientation
[0] = _("Portrait");
1886 orientation
[1] = _("Landscape");
1888 print_modes
[0] = _("Send to Printer");
1889 print_modes
[1] = _("Print to File");
1890 print_modes
[2] = _("Preview Only");
1894 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
1895 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
1896 okBut
->SetDefault();
1899 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1900 (void) new wxStaticText( this, -1, _("Printer Command: "),
1902 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
1903 wxPoint(100, yPos
), wxSize(100, -1) );
1905 (void) new wxStaticText( this, -1, _("Printer Options: "),
1906 wxPoint(210, yPos
) );
1907 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
1908 wxPoint(305, yPos
), wxSize(150, -1) );
1914 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
1915 2,orientation
,2,wxRA_SPECIFY_ROWS
);
1916 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
1918 // @@@ Configuration hook
1919 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
1920 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
1922 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
1924 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
1925 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
1927 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
1929 wxSize(-1,-1), features
,
1930 print_modes
, features
, wxRA_SPECIFY_ROWS
);
1933 radio1
->Enable(0, FALSE
);
1934 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
1935 radio1
->Enable(2, FALSE
);
1938 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
1939 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1940 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1942 sprintf (buf
, "%.2f", wx_printer_scale_x
);
1945 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
1946 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1948 sprintf (buf
, "%.2f", wx_printer_scale_y
);
1949 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
1950 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1954 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
1955 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
1956 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1958 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
1959 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
1960 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1964 delete[] orientation
;
1965 delete[] print_modes
;
1970 int wxPostScriptPrintDialog::ShowModal ()
1972 if ( wxDialog::ShowModal() == wxID_OK
)
1974 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
1975 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
1976 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
1977 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
1978 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
1979 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
1980 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
1981 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
1983 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
1984 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
1985 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
1986 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
1989 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
1990 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
1993 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
1996 switch ( radio1
->GetSelection() ) {
1997 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
1998 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
1999 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2008 // PostScript printer settings
2009 // RETAINED FOR BACKWARD COMPATIBILITY
2010 void wxSetPrinterCommand(const char *cmd
)
2012 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2015 void wxSetPrintPreviewCommand(const char *cmd
)
2017 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2020 void wxSetPrinterOptions(const char *flags
)
2022 wxThePrintSetupData
->SetPrinterOptions(flags
);
2025 void wxSetPrinterFile(const char *f
)
2027 wxThePrintSetupData
->SetPrinterFile(f
);
2030 void wxSetPrinterOrientation(int orient
)
2032 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2035 void wxSetPrinterScaling(double x
, double y
)
2037 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2040 void wxSetPrinterTranslation(long x
, long y
)
2042 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2045 // 1 = Preview, 2 = print to file, 3 = send to printer
2046 void wxSetPrinterMode(int mode
)
2048 wxThePrintSetupData
->SetPrinterMode(mode
);
2051 void wxSetAFMPath(const char *f
)
2053 wxThePrintSetupData
->SetAFMPath(f
);
2056 // Get current values
2057 char *wxGetPrinterCommand()
2059 return wxThePrintSetupData
->GetPrinterCommand();
2062 char *wxGetPrintPreviewCommand()
2064 return wxThePrintSetupData
->GetPrintPreviewCommand();
2067 char *wxGetPrinterOptions()
2069 return wxThePrintSetupData
->GetPrinterOptions();
2072 char *wxGetPrinterFile()
2074 return wxThePrintSetupData
->GetPrinterFile();
2077 int wxGetPrinterOrientation()
2079 return wxThePrintSetupData
->GetPrinterOrientation();
2082 void wxGetPrinterScaling(double* x
, double* y
)
2084 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2087 void wxGetPrinterTranslation(long *x
, long *y
)
2089 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2092 int wxGetPrinterMode()
2094 return wxThePrintSetupData
->GetPrinterMode();
2097 char *wxGetAFMPath()
2099 return wxThePrintSetupData
->GetAFMPath();
2106 wxPrintSetupData::wxPrintSetupData()
2108 printerCommand
= (char *) NULL
;
2109 previewCommand
= (char *) NULL
;
2110 printerFlags
= (char *) NULL
;
2111 printerOrient
= PS_PORTRAIT
;
2112 printerScaleX
= (double)1.0;
2113 printerScaleY
= (double)1.0;
2114 printerTranslateX
= 0;
2115 printerTranslateY
= 0;
2116 // 1 = Preview, 2 = print to file, 3 = send to printer
2118 afmPath
= (char *) NULL
;
2119 paperName
= (char *) NULL
;
2121 printerFile
= (char *) NULL
;
2124 wxPrintSetupData::~wxPrintSetupData()
2127 delete[] printerCommand
;
2129 delete[] previewCommand
;
2131 delete[] printerFlags
;
2137 delete[] printerFile
;
2140 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2142 if (cmd
== printerCommand
)
2146 delete[] printerCommand
;
2148 printerCommand
= copystring(cmd
);
2150 printerCommand
= (char *) NULL
;
2153 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2155 if (cmd
== previewCommand
)
2159 delete[] previewCommand
;
2161 previewCommand
= copystring(cmd
);
2163 previewCommand
= (char *) NULL
;
2166 void wxPrintSetupData::SetPaperName(const char *name
)
2168 if (name
== paperName
)
2174 paperName
= copystring(name
);
2176 paperName
= (char *) NULL
;
2179 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2181 if (printerFlags
== flags
)
2185 delete[] printerFlags
;
2187 printerFlags
= copystring(flags
);
2189 printerFlags
= (char *) NULL
;
2192 void wxPrintSetupData::SetPrinterFile(const char *f
)
2194 if (f
== printerFile
)
2198 delete[] printerFile
;
2200 printerFile
= copystring(f
);
2202 printerFile
= (char *) NULL
;
2205 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2207 printerOrient
= orient
;
2210 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2216 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2218 printerTranslateX
= x
;
2219 printerTranslateY
= y
;
2222 // 1 = Preview, 2 = print to file, 3 = send to printer
2223 void wxPrintSetupData::SetPrinterMode(int mode
)
2228 void wxPrintSetupData::SetAFMPath(const char *f
)
2236 afmPath
= copystring(f
);
2238 afmPath
= (char *) NULL
;
2241 void wxPrintSetupData::SetColour(bool col
)
2246 // Get current values
2247 char *wxPrintSetupData::GetPrinterCommand()
2249 return printerCommand
;
2252 char *wxPrintSetupData::GetPrintPreviewCommand()
2254 return previewCommand
;
2257 char *wxPrintSetupData::GetPrinterOptions()
2259 return printerFlags
;
2262 char *wxPrintSetupData::GetPrinterFile()
2267 char *wxPrintSetupData::GetPaperName()
2272 int wxPrintSetupData::GetPrinterOrientation()
2274 return printerOrient
;
2277 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2283 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2285 *x
= printerTranslateX
;
2286 *y
= printerTranslateY
;
2289 int wxPrintSetupData::GetPrinterMode()
2294 char *wxPrintSetupData::GetAFMPath()
2299 bool wxPrintSetupData::GetColour()
2304 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2306 SetPrinterCommand(data
.GetPrinterCommand());
2307 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2308 SetPrinterOptions(data
.GetPrinterOptions());
2310 data
.GetPrinterTranslation(&x
, &y
);
2311 SetPrinterTranslation(x
, y
);
2314 data
.GetPrinterScaling(&x1
, &y1
);
2315 SetPrinterScaling(x1
, y1
);
2317 SetPrinterOrientation(data
.GetPrinterOrientation());
2318 SetPrinterMode(data
.GetPrinterMode());
2319 SetAFMPath(data
.GetAFMPath());
2320 SetPaperName(data
.GetPaperName());
2321 SetColour(data
.GetColour());
2324 void wxInitializePrintSetupData(bool init
)
2328 wxThePrintSetupData
= new wxPrintSetupData
;
2330 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2331 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2332 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2333 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2335 // Could have a .ini file to read in some defaults
2336 // - and/or use environment variables, e.g. WXWIN
2338 wxThePrintSetupData
->SetPrinterCommand("print");
2339 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2340 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2343 wxThePrintSetupData
->SetPrinterCommand("print");
2344 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2345 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2347 #if !defined(__VMS__) && !defined(__WXMSW__)
2348 wxThePrintSetupData
->SetPrinterCommand("lpr");
2349 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2350 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2355 if (wxThePrintSetupData
)
2356 delete wxThePrintSetupData
;
2357 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2362 * Paper size database for PostScript
2365 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2371 pageName
= copystring(name
);
2374 wxPrintPaperType::~wxPrintPaperType()
2380 * Print paper database for PostScript
2383 #if !USE_SHARED_LIBRARIES
2384 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
2387 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2389 DeleteContents(TRUE
);
2392 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2396 void wxPrintPaperDatabase::CreateDatabase()
2398 // Need correct values for page size in pixels.
2399 // Each unit is one 'point' = 1/72 of an inch.
2400 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2401 // in wxPostScriptDC code, so we can start from top left.
2402 // So access this database and translate by appropriate number
2403 // of points for this paper size. OR IS IT OK ALREADY?
2404 // Can't remember where the PostScript origin is by default.
2405 // Heck, someone will know how to make it hunky-dory...
2408 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2409 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2410 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2411 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2416 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 210*4, 297*4 );
2417 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 297*4, 420*4 );
2418 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 216*4, 279*4 );
2419 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 216*4, 356*4 );
2423 void wxPrintPaperDatabase::ClearDatabase()
2428 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2430 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2433 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2435 wxNode
*node
= Find(name
);
2437 return (wxPrintPaperType
*)node
->Data();
2439 return (wxPrintPaperType
*) NULL
;
2443 * Initialization/cleanup module
2446 bool wxPostScriptModule::OnInit()
2448 wxInitializePrintSetupData();
2449 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2450 wxThePrintPaperDatabase
->CreateDatabase();
2455 void wxPostScriptModule::OnExit()
2457 wxInitializePrintSetupData(FALSE
);
2458 delete wxThePrintPaperDatabase
;
2459 wxThePrintPaperDatabase
= NULL
;