1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "postscrp.h"
14 #pragma implementation
18 //-------------------------------------------------------------------------------
20 //-------------------------------------------------------------------------------
22 // For compilers that support precompilation, includes "wx.h".
23 #include "wx/wxprec.h"
37 #include "wx/filedlg.h"
38 #include "wx/msgdlg.h"
40 #include "wx/button.h"
41 #include "wx/radiobox.h"
42 #include "wx/textctrl.h"
43 #include "wx/stattext.h"
48 #include "wx/postscrp.h"
49 #include "wx/dcmemory.h"
52 #include "wx/msw/private.h"
75 #include "gdk/gdkx.h" // GDK_DISPLAY
76 #include "gdk/gdkprivate.h" // XImage
78 #include <X11/Xutil.h>
84 #include <X11/Xutil.h>
107 //-------------------------------------------------------------------------------
109 //-------------------------------------------------------------------------------
111 // Determine the Default Postscript Previewer
112 // available on the platform
113 #if defined(__SUN__) && defined(__XVIEW__)
114 // OpenWindow/NeWS's Postscript Previewer
115 # define PS_VIEWER_PROG "pageview"
116 #elif defined(__VMS__)
117 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
118 #elif defined(__SGI__)
119 // SGI's Display Postscript Previewer
120 //# define PS_VIEWER_PROG "dps"
121 # define PS_VIEWER_PROG "xpsview"
122 #elif defined(__X__) || defined(__WXGTK__)
123 // Front-end to ghostscript
124 # define PS_VIEWER_PROG "ghostview"
126 // Windows ghostscript/ghostview
127 # define PS_VIEWER_PROG NULL
130 //-------------------------------------------------------------------------------
132 //-------------------------------------------------------------------------------
134 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
136 //-----------------------------------------------------------------------------
137 // start and end of document/page
138 //-----------------------------------------------------------------------------
140 static const char *wxPostScriptHeaderEllipse
= "\
141 /ellipsedict 8 dict def\n\
142 ellipsedict /mtrx matrix put\n\
145 /endangle exch def\n\
146 /startangle exch def\n\
151 /savematrix mtrx currentmatrix def\n\
154 0 0 1 startangle endangle arc\n\
155 savematrix setmatrix\n\
160 static const char *wxPostScriptHeaderEllipticArc
= "\
161 /ellipticarcdict 8 dict def\n\
162 ellipticarcdict /mtrx matrix put\n\
164 { ellipticarcdict begin\n\
166 /endangle exch def\n\
167 /startangle exch def\n\
172 /savematrix mtrx currentmatrix def\n\
175 do_fill { 0 0 moveto } if\n\
176 0 0 1 startangle endangle arc\n\
177 savematrix setmatrix\n\
178 do_fill { fill }{ stroke } ifelse\n\
182 static const char *wxPostScriptHeaderSpline
= "\
183 /DrawSplineSection {\n\
190 /xa x1 x2 x1 sub 0.666667 mul add def\n\
191 /ya y1 y2 y1 sub 0.666667 mul add def\n\
192 /xb x3 x2 x3 sub 0.666667 mul add def\n\
193 /yb y3 y2 y3 sub 0.666667 mul add def\n\
195 xa ya xb yb x3 y3 curveto\n\
199 static const char *wxPostScriptHeaderColourImage
= "\
200 % define 'colorimage' if it isn't defined\n\
201 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
203 /colorimage where % do we know about 'colorimage'?\n\
204 { pop } % yes: pop off the 'dict' returned\n\
205 { % no: define one\n\
206 /colortogray { % define an RGB->I function\n\
207 /rgbdata exch store % call input 'rgbdata'\n\
208 rgbdata length 3 idiv\n\
209 /npixls exch store\n\
211 0 1 npixls 1 sub {\n\
213 rgbdata rgbindx get 20 mul % Red\n\
214 rgbdata rgbindx 1 add get 32 mul % Green\n\
215 rgbdata rgbindx 2 add get 12 mul % Blue\n\
216 add add 64 idiv % I = .5G + .31R + .18B\n\
218 /rgbindx rgbindx 3 add store\n\
220 grays 0 npixls getinterval\n\
223 % Utility procedure for colorimage operator.\n\
224 % This procedure takes two procedures off the\n\
225 % stack and merges them into a single procedure.\n\
227 /mergeprocs { % def\n\
246 /colorimage { % def\n\
247 pop pop % remove 'false 3' operands\n\
248 {colortogray} mergeprocs\n\
251 } ifelse % end of 'false' case\n\
254 static char wxPostScriptHeaderReencodeISO1
[] =
256 "dup dup findfont dup length dict begin\n"
257 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
258 "/Encoding ISOLatin1Encoding def\n"
259 "currentdict end definefont\n"
261 "/ISOLatin1Encoding [\n"
262 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
263 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
264 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
265 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
266 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
267 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
268 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
269 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
270 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
271 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
272 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
273 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
274 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
275 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
276 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
278 static char wxPostScriptHeaderReencodeISO2
[] =
279 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
280 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
281 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
282 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
283 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
284 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
285 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
286 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
287 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
288 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
289 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
290 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
291 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
292 "/yacute/thorn/ydieresis\n"
295 //-------------------------------------------------------------------------------
297 //-------------------------------------------------------------------------------
299 #if !USE_SHARED_LIBRARY
300 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
301 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
302 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
303 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
306 //-------------------------------------------------------------------------------
308 //-------------------------------------------------------------------------------
310 wxPostScriptDC::wxPostScriptDC ()
312 m_pstream
= (ofstream
*) NULL
;
322 m_underlinePosition
= 0.0;
323 m_underlineThickness
= 0.0;
325 m_signX
= 1; // default x-axis left to right
326 m_signY
= -1; // default y-axis bottom up -> top down
329 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
331 m_pstream
= (ofstream
*) NULL
;
341 m_underlinePosition
= 0.0;
342 m_underlineThickness
= 0.0;
344 m_signX
= 1; // default x-axis left to right
345 m_signY
= -1; // default y-axis bottom up -> top down
347 Create(file
, interactive
, parent
);
350 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
352 m_isInteractive
= interactive
;
358 // Can only send to file in Windows
359 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
364 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
374 wxPostScriptDC::~wxPostScriptDC ()
376 if (m_pstream
) delete m_pstream
;
379 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
381 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
382 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
383 m_ok
= (dialog
.ShowModal () == wxID_OK
);
385 if (!m_ok
) return FALSE
;
387 if ((m_filename
== "") &&
388 (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
||
389 wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
393 wxThePrintSetupData
->SetPrinterFile("preview");
395 // For PS_PRINTER action this depends on a Unix-style print spooler
396 // since the wx_printer_file can be destroyed during a session
397 // @@@ TODO: a Windows-style answer for non-Unix
399 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
401 strcpy (tmp
, "/tmp/preview_");
402 strcat (tmp
, userId
);
403 wxThePrintSetupData
->SetPrinterFile(tmp
);
406 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
407 strcat (tmp2
, ".ps");
408 wxThePrintSetupData
->SetPrinterFile(tmp2
);
411 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
413 char *file
= wxSaveFileSelector (_("PostScript"), "ps");
419 wxThePrintSetupData
->SetPrinterFile(file
);
427 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
429 if (m_clipping
) return;
431 if (!m_pstream
) return;
433 wxDC::SetClippingRegion( x
, y
, w
, h
);
436 *m_pstream
<< "gsave\n"
438 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
439 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
440 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
441 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
442 << "closepath clip newpath\n";
445 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
449 void wxPostScriptDC::DestroyClippingRegion()
451 if (!m_pstream
) return;
453 wxDC::DestroyClippingRegion();
458 *m_pstream
<< "grestore\n";
462 void wxPostScriptDC::Clear()
464 wxFAIL_MSG( "wxPostScriptDC::Clear not implemented." );
467 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
469 wxFAIL_MSG( "wxPostScriptDC::FloodFill not implemented." );
472 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
474 wxFAIL_MSG( "wxPostScriptDC::GetPixel not implemented." );
478 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
480 wxFAIL_MSG( "wxPostScriptDC::CrossHair not implemented." );
483 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
485 if (!m_pstream
) return;
487 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
491 *m_pstream
<< "newpath\n"
492 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
493 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
496 CalcBoundingBox( x1
, y1
);
497 CalcBoundingBox( x2
, y2
);
500 #define RAD2DEG 57.29577951308
502 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
504 if (!m_pstream
) return;
508 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
509 double alpha1
, alpha2
;
511 if (x1
== x2
&& y1
== y2
)
515 } else if (radius
== 0.0)
517 alpha1
= alpha2
= 0.0;
520 alpha1
= (x1
- xc
== 0) ?
521 (y1
- yc
< 0) ? 90.0 : -90.0 :
522 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
523 alpha2
= (x2
- xc
== 0) ?
524 (y2
- yc
< 0) ? 90.0 : -90.0 :
525 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
527 while (alpha1
<= 0) alpha1
+= 360;
528 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
529 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
530 while (alpha2
> 360) alpha2
-= 360;
532 if (m_brush
.GetStyle() != wxTRANSPARENT
)
535 *m_pstream
<< "newpath\n"
536 << XLOG2DEV(xc
) << " "
537 << YLOG2DEV(yc
) << " "
538 << XLOG2DEVREL(radius
) << " "
539 << YLOG2DEVREL(radius
) << " "
541 << alpha2
<< " ellipse\n"
542 << XLOG2DEV(xc
) << " "
543 << YLOG2DEV(yc
) << " lineto\n"
548 if (m_pen
.GetStyle() != wxTRANSPARENT
)
551 *m_pstream
<< "newpath\n"
552 << XLOG2DEV(xc
) << " "
553 << YLOG2DEV(yc
) << " "
554 << XLOG2DEVREL(radius
) << " "
555 << YLOG2DEVREL(radius
) << " "
557 << alpha2
<< " ellipse\n"
561 CalcBoundingBox( xc
-radius
, yc
-radius
);
562 CalcBoundingBox( xc
+radius
, yc
+radius
);
565 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
567 if (!m_pstream
) return;
569 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
570 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
576 DrawEllipse(x
,y
,w
,h
);
580 if (m_brush
.GetStyle () != wxTRANSPARENT
)
584 *m_pstream
<< "newpath\n"
585 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
586 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
587 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
589 CalcBoundingBox( x
,y
);
590 CalcBoundingBox( x
+w
, y
+h
);
593 if (m_pen
.GetStyle () != wxTRANSPARENT
)
597 *m_pstream
<< "newpath\n"
598 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
599 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
600 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
602 CalcBoundingBox( x
, y
);
603 CalcBoundingBox( x
+w
, y
+h
);
607 void wxPostScriptDC::DrawPoint (long x
, long y
)
609 if (!m_pstream
) return;
611 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
615 *m_pstream
<< "newpath\n"
616 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
617 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
620 CalcBoundingBox( x
, y
);
623 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
625 if (!m_pstream
) return;
629 if (m_brush
.GetStyle () != wxTRANSPARENT
)
633 *m_pstream
<< "newpath\n";
635 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
636 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
637 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
638 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
640 for (int i
= 1; i
< n
; i
++)
642 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
643 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
644 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
645 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
647 *m_pstream
<< "fill\n";
650 if (m_pen
.GetStyle () != wxTRANSPARENT
)
654 *m_pstream
<< "newpath\n";
656 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
657 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
658 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
659 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
661 for (int i
= 1; i
< n
; i
++)
663 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
664 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
665 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
666 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
669 *m_pstream
<< "stroke\n";
673 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
675 if (!m_pstream
) return;
677 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
682 for (int i
=0; i
<n
; ++i
)
684 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
687 *m_pstream
<< "newpath\n"
688 << XLOG2DEV(points
[0].x
+xoffset
) << " "
689 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
691 for (int i
= 1; i
< n
; i
++)
693 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
694 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
697 *m_pstream
<< "stroke\n";
700 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
702 if (!m_pstream
) return;
704 if (m_brush
.GetStyle () != wxTRANSPARENT
)
708 *m_pstream
<< "newpath\n"
709 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
710 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
711 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
712 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
716 CalcBoundingBox( x
, y
);
717 CalcBoundingBox( x
+ width
, y
+ height
);
720 if (m_pen
.GetStyle () != wxTRANSPARENT
)
724 *m_pstream
<< "newpath\n"
725 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
726 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
727 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
728 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
732 CalcBoundingBox( x
, y
);
733 CalcBoundingBox( x
+ width
, y
+ height
);
737 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
739 if (!m_pstream
) return;
743 // Now, a negative radius is interpreted to mean
744 // 'the proportion of the smallest X or Y dimension'
745 double smallest
= 0.0;
750 radius
= (-radius
* smallest
);
753 long rad
= (long) radius
;
755 if (m_brush
.GetStyle () != wxTRANSPARENT
)
759 // Draw rectangle anticlockwise
760 *m_pstream
<< "newpath\n"
761 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
762 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
763 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
764 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
765 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
766 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
767 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
768 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
772 CalcBoundingBox( x
, y
);
773 CalcBoundingBox( x
+ width
, y
+ height
);
776 if (m_pen
.GetStyle () != wxTRANSPARENT
)
780 // Draw rectangle anticlockwise
781 *m_pstream
<< "newpath\n"
782 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
783 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
784 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
785 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
786 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
787 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
788 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
789 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
793 CalcBoundingBox( x
, y
);
794 CalcBoundingBox( x
+ width
, y
+ height
);
798 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
800 if (!m_pstream
) return;
802 if (m_brush
.GetStyle () != wxTRANSPARENT
)
806 *m_pstream
<< "newpath\n"
807 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
808 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
811 CalcBoundingBox( x
- width
, y
- height
);
812 CalcBoundingBox( x
+ width
, y
+ height
);
815 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
819 *m_pstream
<< "newpath\n"
820 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
821 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
824 CalcBoundingBox( x
- width
, y
- height
);
825 CalcBoundingBox( x
+ width
, y
+ height
);
829 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
832 memDC
.SelectObject( icon
);
833 Blit(x
, y
, icon
.GetWidth(), icon
.GetHeight(), &memDC
, 0, 0);
836 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool useMask
)
839 memDC
.SelectObject( bitmap
);
840 Blit( x
, y
, bitmap
.GetWidth(), bitmap
.GetHeight(), &memDC
, 0, 0, useMask
);
843 void wxPostScriptDC::SetFont (const wxFont
& font
)
845 if (!m_pstream
) return;
847 if (!font
.Ok()) return;
851 char *name
= wxTheFontNameDirectory
->GetPostScriptName( m_font
.GetFamily(),
854 if (!name
) name
= "Times-Roman";
856 *m_pstream
<< "/" << name
<< " reencodeISO def\n"
857 << "/" << name
<< " findfont\n"
858 << YLOG2DEVREL(font
.GetPointSize())
859 << " scalefont setfont\n";
862 void wxPostScriptDC::SetPen( const wxPen
& pen
)
864 if (!m_pstream
) return;
866 if (!pen
.Ok()) return;
868 int oldStyle
= m_pen
.GetStyle();
872 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
875 Line style - WRONG: 2nd arg is OFFSET
877 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
878 operator correctly. You should look-up this in the Red Book: the 2nd parame-
879 ter is not number of values in the array of the first one, but an offset
880 into this description of the pattern. I mean a real *offset* not index
881 into array. I.e. If the command is [3 4] 1 setdash is used, then there
882 will be first black line *2* units long, then space 4 units, then the
883 pattern of *3* units black, 4 units space will be repeated.
886 static const char *dotted
= "[2 5] 2";
887 static const char *short_dashed
= "[4 4] 2";
888 static const char *long_dashed
= "[4 8] 2";
889 static const char *dotted_dashed
= "[6 6 2 6] 4";
891 const char *psdash
= (char *) NULL
;
892 switch (m_pen
.GetStyle ())
894 case wxDOT
: psdash
= dotted
; break;
895 case wxSHORT_DASH
: psdash
= short_dashed
; break;
896 case wxLONG_DASH
: psdash
= long_dashed
; break;
897 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
900 default: psdash
= "[] 0"; break;
903 if (oldStyle
!= m_pen
.GetStyle())
905 *m_pstream
<< psdash
<< " setdash\n";
909 unsigned char red
= m_pen
.GetColour().Red();
910 unsigned char blue
= m_pen
.GetColour().Blue();
911 unsigned char green
= m_pen
.GetColour().Green();
915 // Anything not white is black
916 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
917 && green
== (unsigned char) 255))
919 red
= (unsigned char) 0;
920 green
= (unsigned char) 0;
921 blue
= (unsigned char) 0;
927 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
929 long redPS
= (long) (((int) red
) / 255.0);
930 long bluePS
= (long) (((int) blue
) / 255.0);
931 long greenPS
= (long) (((int) green
) / 255.0);
933 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
936 m_currentBlue
= blue
;
937 m_currentGreen
= green
;
941 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
943 if (!m_pstream
) return;
945 if (!brush
.Ok()) return;
950 unsigned char red
= m_brush
.GetColour ().Red ();
951 unsigned char blue
= m_brush
.GetColour ().Blue ();
952 unsigned char green
= m_brush
.GetColour ().Green ();
956 // Anything not black is white
957 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
958 && green
== (unsigned char) 0))
960 red
= (unsigned char) 255;
961 green
= (unsigned char) 255;
962 blue
= (unsigned char) 255;
968 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
970 long redPS
= (long) (((int) red
) / 255.0);
971 long bluePS
= (long) (((int) blue
) / 255.0);
972 long greenPS
= (long) (((int) green
) / 255.0);
973 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
975 m_currentBlue
= blue
;
976 m_currentGreen
= green
;
980 void wxPostScriptDC::DrawText( const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
) )
982 if (!m_pstream
) return;
986 if (m_textForegroundColour
.Ok ())
988 unsigned char red
= m_textForegroundColour
.Red ();
989 unsigned char blue
= m_textForegroundColour
.Blue ();
990 unsigned char green
= m_textForegroundColour
.Green ();
994 // Anything not white is black
995 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
996 && green
== (unsigned char) 255))
998 red
= (unsigned char) 0;
999 green
= (unsigned char) 0;
1000 blue
= (unsigned char) 0;
1004 // maybe setgray here ?
1006 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1008 long redPS
= (long) (((int) red
) / 255.0);
1009 long bluePS
= (long) (((int) blue
) / 255.0);
1010 long greenPS
= (long) (((int) green
) / 255.0);
1011 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1014 m_currentBlue
= blue
;
1015 m_currentGreen
= green
;
1019 int size
= m_font
.GetPointSize();
1021 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
1022 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
1025 int len
= strlen ((char *)(const char *)text
);
1027 for (i
= 0; i
< len
; i
++)
1029 int c
= (unsigned char) text
[i
];
1030 if ( c
== ')' || c
== '(' || c
== '\\')
1032 *m_pstream
<< "\\" << (char) c
;
1034 else if ( c
>= 128 )
1036 // Cope with character codes > 127
1038 sprintf(tmp
, "\\%o", c
);
1042 *m_pstream
<< (char) c
;
1045 *m_pstream
<< ")" << " show\n";
1047 if (m_font
.GetUnderlined())
1049 long uy
= (long)(y
+ size
- m_underlinePosition
);
1051 GetTextExtent(text
, &w
, &h
);
1053 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
1055 << (long)m_underlineThickness
<< " setlinewidth "
1056 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
1057 << " lineto stroke grestore\n";
1060 CalcBoundingBox( x
, y
);
1061 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1065 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1067 m_backgroundBrush
= brush
;
1070 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1072 wxFAIL_MSG( "wxPostScriptDC::SetLogicalFunction not implemented." );
1075 void wxPostScriptDC::DrawSpline( wxList
*points
)
1077 if (!m_pstream
) return;
1081 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1084 wxNode
*node
= points
->First();
1085 p
= (wxPoint
*)node
->Data();
1089 node
= node
->Next();
1090 p
= (wxPoint
*)node
->Data();
1093 x3
= a
= (double)(x1
+ c
) / 2;
1094 y3
= b
= (double)(y1
+ d
) / 2;
1096 *m_pstream
<< "newpath "
1097 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
1098 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
1100 CalcBoundingBox( (long)x1
, (long)y1
);
1101 CalcBoundingBox( (long)x3
, (long)y3
);
1103 while ((node
= node
->Next()) != NULL
)
1105 q
= (wxPoint
*)node
->Data();
1113 x3
= (double)(x2
+ c
) / 2;
1114 y3
= (double)(y2
+ d
) / 2;
1115 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
1116 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
1117 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
1119 CalcBoundingBox( (long)x1
, (long)y1
);
1120 CalcBoundingBox( (long)x3
, (long)y3
);
1124 At this point, (x2,y2) and (c,d) are the position of the
1125 next-to-last and last point respectively, in the point list
1128 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1131 long wxPostScriptDC::GetCharWidth ()
1133 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1134 return (long) (GetCharHeight() * 72.0 / 120.0);
1138 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1140 m_signX
= (xLeftRight
? 1 : -1);
1141 m_signY
= (yBottomUp
? 1 : -1);
1143 ComputeScaleAndOrigin();
1146 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1152 wxDC::SetDeviceOrigin( x
, h
-y
);
1155 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1157 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1159 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1161 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1163 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1167 *width
= paper
->widthPixels
;
1168 *height
= paper
->heightPixels
;
1177 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1179 if (m_filename
== "")
1181 m_filename
= wxGetTempFileName("ps");
1182 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1187 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1190 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1192 if (!m_pstream
|| !m_pstream
->good())
1194 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1201 SetBrush( *wxBLACK_BRUSH
);
1202 SetPen( *wxBLACK_PEN
);
1203 SetBackground( *wxWHITE_BRUSH
);
1204 SetTextForeground( *wxBLACK
);
1206 // set origin according to paper size
1207 SetDeviceOrigin( 0,0 );
1215 void wxPostScriptDC::EndDoc ()
1217 if (!m_pstream
) return;
1222 *m_pstream
<< "grestore\n";
1228 m_pstream
= (ofstream
*) NULL
;
1231 char *header_file
= wxGetTempFileName("ps");
1233 m_pstream
= new ofstream( header_file
);
1235 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1236 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1237 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1238 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1241 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1243 *m_pstream
<< "%%For: " << (char *)userID
;
1245 if (wxGetUserName(userName
, sizeof(userName
)))
1246 *m_pstream
<< " (" << (char *)userName
<< ")";
1249 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1251 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1254 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1256 long wx_printer_translate_x
, wx_printer_translate_y
;
1257 double wx_printer_scale_x
, wx_printer_scale_y
;
1258 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1259 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1261 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1263 *m_pstream
<< "%%Orientation: Landscape\n";
1267 *m_pstream
<< "%%Orientation: Portrait\n";
1270 // Compute the bounding box. Note that it is in the default user
1271 // coordinate system, thus we have to convert the values.
1272 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1273 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1274 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1275 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1277 // If we're landscape, our sense of "x" and "y" is reversed.
1278 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1281 tmp
= llx
; llx
= lly
; lly
= tmp
;
1282 tmp
= urx
; urx
= ury
; ury
= tmp
;
1284 // We need either the two lines that follow, or we need to subtract
1285 // min_x from real_translate_y, which is commented out below.
1286 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1287 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1290 // The Adobe specifications call for integers; we round as to make
1291 // the bounding larger.
1292 *m_pstream
<< "%%BoundingBox: "
1293 << floor((double)llx
) << " " << floor((double)lly
) << " "
1294 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1295 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1296 *m_pstream
<< "%%EndComments\n\n";
1298 // To check the correctness of the bounding box, postscript commands
1299 // to draw a box corresponding to the bounding box are generated below.
1300 // But since we typically don't want to print such a box, the postscript
1301 // commands are generated within comments. These lines appear before any
1302 // adjustment of scale, rotation, or translation, and hence are in the
1303 // default user coordinates.
1304 *m_pstream
<< "% newpath\n";
1305 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1306 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1307 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1308 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1310 *m_pstream
<< "%%BeginProlog\n";
1311 *m_pstream
<< wxPostScriptHeaderEllipse
;
1312 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1313 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1314 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1316 if (wxPostScriptHeaderSpline
)
1317 *m_pstream
<< wxPostScriptHeaderSpline
;
1318 *m_pstream
<< "%%EndProlog\n";
1321 m_pstream
= (ofstream
*) NULL
;
1323 char *tmp_file
= wxGetTempFileName("ps");
1325 // Paste header Before wx_printer_file
1326 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1327 wxRemoveFile (header_file
);
1328 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1329 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1331 #if defined(__X__) || defined(__WXGTK__)
1334 switch (wxThePrintSetupData
->GetPrinterMode()) {
1338 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1339 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1340 argv
[2] = (char *) NULL
;
1341 wxExecute (argv
, TRUE
);
1342 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1350 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1352 // !SM! If we simply assign to argv[1] here, if printer options
1353 // are blank, we get an annoying and confusing message from lpr.
1354 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1356 argv
[argc
++] = opts
;
1358 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1359 argv
[argc
++] = (char *) NULL
;
1360 wxExecute (argv
, TRUE
);
1361 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1372 void wxPostScriptDC::StartPage ()
1374 if (!m_pstream
) return;
1376 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1378 // *m_pstream << "matrix currentmatrix\n";
1380 // Added by Chris Breeze
1382 // Each page starts with an "initgraphics" which resets the
1383 // transformation and so we need to reset the origin
1384 // (and rotate the page for landscape printing)
1387 m_scaleFactor = 1.0;
1388 m_logicalOriginX = 0;
1389 m_logicalOriginY = 0;
1393 long translate_x
, translate_y
;
1394 double scale_x
, scale_y
;
1395 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1396 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1398 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1400 translate_y
-= m_maxY
;
1401 *m_pstream
<< "90 rotate\n";
1404 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1405 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1408 void wxPostScriptDC::EndPage ()
1410 if (!m_pstream
) return;
1412 *m_pstream
<< "showpage\n";
1415 bool wxPostScriptDC::Blit (long xdest
, long ydest
, long fwidth
, long fheight
,
1416 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(rop
), bool WXUNUSED(useMask
))
1421 long wxPostScriptDC::GetCharHeight ()
1424 return m_font
.GetPointSize();
1429 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1430 long *descent
, long *externalLeading
, wxFont
*theFont
,
1431 bool WXUNUSED(use16
))
1433 // if (!m_pstream) return;
1435 wxFont
*fontToUse
= theFont
;
1437 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1439 #if !USE_AFM_FOR_POSTSCRIPT
1440 // Provide a VERY rough estimate (avoid using it)
1441 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1442 // font such as Courier (aka wxMODERN)
1446 height
= fontToUse
->GetPointSize();
1448 *x
= strlen (string
) * height
* 72 / 120;
1449 *y
= (long) (height
* 1.32); // allow for descender
1453 if (externalLeading
)
1454 *externalLeading
= 0;
1456 // +++++ start of contributed code +++++
1458 // ************************************************************
1459 // method for calculating string widths in postscript:
1460 // read in the AFM (adobe font metrics) file for the
1461 // actual font, parse it and extract the character widths
1462 // and also the descender. this may be improved, but for now
1463 // it works well. the AFM file is only read in if the
1464 // font is changed. this may be chached in the future.
1465 // calls to GetTextExtent with the font unchanged are rather
1468 // for each font and style used there is an AFM file necessary.
1469 // currently i have only files for the roman font family.
1470 // i try to get files for the other ones!
1472 // CAVE: the size of the string is currently always calculated
1473 // in 'points' (1/72 of an inch). this should later on be
1474 // changed to depend on the mapping mode.
1475 // CAVE: the path to the AFM files must be set before calling this
1476 // function. this is usually done by a call like the following:
1477 // wxSetAFMPath("d:\\wxw161\\afm\\");
1481 // wxPostScriptDC dc(NULL, TRUE);
1483 // wxSetAFMPath("d:\\wxw161\\afm\\");
1484 // dc.StartDoc("Test");
1487 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1488 // dc.GetTextExtent("Hallo",&w,&h);
1493 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1494 // created: 10.09.94
1495 // updated: 14.05.95
1497 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1498 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1499 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1501 // these static vars are for storing the state between calls
1502 static int lastFamily
= INT_MIN
;
1503 static int lastSize
= INT_MIN
;
1504 static int lastStyle
= INT_MIN
;
1505 static int lastWeight
= INT_MIN
;
1506 static int lastDescender
= INT_MIN
;
1507 static int lastWidths
[256]; // widths of the characters
1509 // get actual parameters
1510 const int Family
= fontToUse
->GetFamily();
1511 const int Size
= fontToUse
->GetPointSize();
1512 const int Style
= fontToUse
->GetStyle();
1513 const int Weight
= fontToUse
->GetWeight();
1515 // if we have another font, read the font-metrics
1516 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1517 // store actual values
1518 lastFamily
= Family
;
1521 lastWeight
= Weight
;
1523 // read in new font metrics **************************************
1525 // 1. construct filename ******************************************
1526 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1529 // Julian - we'll need to do this a different way now we've removed the
1530 // font directory system. Must find Stefan's original code.
1532 name
= wxTheFontNameDirectory
->GetAFMName(Family
, Weight
, Style
);
1536 // get the directory of the AFM files
1540 strcpy(afmName
,wxGetAFMPath());
1542 // 2. open and process the file **********************************
1544 // a short explanation of the AFM format:
1545 // we have for each character a line, which gives its size
1548 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1550 // that means, we have a character with ascii code 63, and width
1551 // (444/1000 * fontSize) points.
1552 // the other data is ignored for now!
1554 // when the font has changed, we read in the right AFM file and store the
1555 // character widths in an array, which is processed below (see point 3.).
1557 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1560 strcat(afmName
,name
);
1561 strcat(afmName
,".afm");
1562 FILE *afmFile
= fopen(afmName
,"r");
1564 wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1565 wxDebugMsg(" using approximate values\n");
1567 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1568 lastDescender
= -150; // dito.
1571 // init the widths array
1572 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1573 // some variables for holding parts of a line
1574 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1575 char upString
[30], utString
[30], encString
[50];
1578 // read in the file and parse it
1579 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1580 // A.) check for descender definition
1581 if(strncmp(line
,"Descender",9)==0){
1582 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1583 || (strcmp(descString
,"Descender")!=0)) {
1584 wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n",
1588 // JC 1.) check for UnderlinePosition
1589 else if(strncmp(line
,"UnderlinePosition",17)==0){
1590 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1591 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1592 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1596 // JC 2.) check for UnderlineThickness
1597 else if(strncmp(line
,"UnderlineThickness",18)==0){
1598 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1599 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1600 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1604 // JC 3.) check for EncodingScheme
1605 else if(strncmp(line
,"EncodingScheme",14)==0){
1606 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1607 || (strcmp(utString
,"EncodingScheme")!=0)) {
1608 wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1611 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1613 wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1614 afmName
,line
, encString
);
1617 // B.) check for char-width
1618 else if(strncmp(line
,"C ",2)==0){
1619 if(sscanf(line
,"%s%d%s%s%d",
1620 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1621 wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1623 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1624 strcmp(WXString
,"WX")!=0){
1625 wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1627 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1628 if(ascii
>=0 && ascii
<256){
1629 lastWidths
[ascii
] = cWidth
; // store width
1631 /* MATTHEW: this happens a lot; don't print an error */
1632 // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1635 // C.) ignore other entries.
1639 // hack to compute correct values for german 'Umlaute'
1640 // the correct way would be to map the character names
1641 // like 'adieresis' to corresp. positions of ISOEnc and read
1642 // these values from AFM files, too. Maybe later ...
1643 lastWidths
[196] = lastWidths
['A']; // Ä
1644 lastWidths
[228] = lastWidths
['a']; // ä
1645 lastWidths
[214] = lastWidths
['O']; // Ö
1646 lastWidths
[246] = lastWidths
['o']; // ö
1647 lastWidths
[220] = lastWidths
['U']; // Ü
1648 lastWidths
[252] = lastWidths
['u']; // ü
1649 lastWidths
[223] = lastWidths
[251]; // ß
1652 // JC: calculate UnderlineThickness/UnderlinePosition
1653 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1654 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1656 // 3. now the font metrics are read in, calc size *******************
1657 // this is done by adding the widths of the characters in the
1658 // string. they are given in 1/1000 of the size!
1661 long height
=Size
; // by default
1663 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1664 if(lastWidths
[*p
]== INT_MIN
){
1665 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1667 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1669 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1672 // add descender to height (it is usually a negative value)
1673 if(lastDescender
!=INT_MIN
){
1674 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1677 // return size values
1681 // return other parameters
1683 if(lastDescender
!=INT_MIN
){
1684 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1690 // currently no idea how to calculate this!
1691 // if (externalLeading) *externalLeading = 0;
1692 if (externalLeading
)
1693 *externalLeading
= 0;
1695 // ----- end of contributed code -----
1699 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
1701 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1703 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1705 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1707 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1711 *width
= paper
->widthMM
;
1712 *height
= paper
->heightMM
;
1721 //-------------------------------------------------------------------------------
1722 // remaining PostScript classes
1723 //-------------------------------------------------------------------------------
1725 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
1727 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
1728 const wxPoint
& pos
, const wxSize
& size
, long style
):
1729 wxDialog(parent
, -1, title
, pos
, size
, style
)
1731 wxBeginBusyCursor();
1736 *orientation
= new wxString
[2],
1737 *print_modes
= new wxString
[3];
1739 long wx_printer_translate_x
, wx_printer_translate_y
;
1740 double wx_printer_scale_x
, wx_printer_scale_y
;
1742 orientation
[0] = _("Portrait");
1743 orientation
[1] = _("Landscape");
1745 print_modes
[0] = _("Send to Printer");
1746 print_modes
[1] = _("Print to File");
1747 print_modes
[2] = _("Preview Only");
1751 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
1752 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
1753 okBut
->SetDefault();
1756 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1757 (void) new wxStaticText( this, -1, _("Printer Command: "),
1759 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
1760 wxPoint(100, yPos
), wxSize(100, -1) );
1762 (void) new wxStaticText( this, -1, _("Printer Options: "),
1763 wxPoint(210, yPos
) );
1764 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
1765 wxPoint(305, yPos
), wxSize(150, -1) );
1771 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
1773 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
1775 // @@@ Configuration hook
1776 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
1777 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
1779 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
1781 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
1782 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
1784 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
1786 wxSize(-1,-1), features
,
1787 print_modes
, features
, 0);
1790 radio1
->Enable(0, FALSE
);
1791 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
1792 radio1
->Enable(2, FALSE
);
1795 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
1796 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1797 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1799 sprintf (buf
, "%.2f", wx_printer_scale_x
);
1802 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
1803 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1805 sprintf (buf
, "%.2f", wx_printer_scale_y
);
1806 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
1807 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1811 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
1812 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
1813 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1815 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
1816 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
1817 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1821 delete[] orientation
;
1822 delete[] print_modes
;
1827 int wxPostScriptPrintDialog::ShowModal ()
1829 if ( wxDialog::ShowModal() == wxID_OK
)
1831 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
1832 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
1833 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
1834 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
1835 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
1836 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
1837 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
1838 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
1840 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
1841 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
1842 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
1843 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
1846 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
1847 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
1850 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
1853 switch ( radio1
->GetSelection() ) {
1854 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
1855 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
1856 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
1863 // PostScript printer settings
1864 // RETAINED FOR BACKWARD COMPATIBILITY
1865 void wxSetPrinterCommand(const char *cmd
)
1867 wxThePrintSetupData
->SetPrinterCommand(cmd
);
1870 void wxSetPrintPreviewCommand(const char *cmd
)
1872 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
1875 void wxSetPrinterOptions(const char *flags
)
1877 wxThePrintSetupData
->SetPrinterOptions(flags
);
1880 void wxSetPrinterFile(const char *f
)
1882 wxThePrintSetupData
->SetPrinterFile(f
);
1885 void wxSetPrinterOrientation(int orient
)
1887 wxThePrintSetupData
->SetPrinterOrientation(orient
);
1890 void wxSetPrinterScaling(double x
, double y
)
1892 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
1895 void wxSetPrinterTranslation(long x
, long y
)
1897 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
1900 // 1 = Preview, 2 = print to file, 3 = send to printer
1901 void wxSetPrinterMode(int mode
)
1903 wxThePrintSetupData
->SetPrinterMode(mode
);
1906 void wxSetAFMPath(const char *f
)
1908 wxThePrintSetupData
->SetAFMPath(f
);
1911 // Get current values
1912 char *wxGetPrinterCommand()
1914 return wxThePrintSetupData
->GetPrinterCommand();
1917 char *wxGetPrintPreviewCommand()
1919 return wxThePrintSetupData
->GetPrintPreviewCommand();
1922 char *wxGetPrinterOptions()
1924 return wxThePrintSetupData
->GetPrinterOptions();
1927 char *wxGetPrinterFile()
1929 return wxThePrintSetupData
->GetPrinterFile();
1932 int wxGetPrinterOrientation()
1934 return wxThePrintSetupData
->GetPrinterOrientation();
1937 void wxGetPrinterScaling(double* x
, double* y
)
1939 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
1942 void wxGetPrinterTranslation(long *x
, long *y
)
1944 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
1947 int wxGetPrinterMode()
1949 return wxThePrintSetupData
->GetPrinterMode();
1952 char *wxGetAFMPath()
1954 return wxThePrintSetupData
->GetAFMPath();
1961 wxPrintSetupData::wxPrintSetupData()
1963 printerCommand
= (char *) NULL
;
1964 previewCommand
= (char *) NULL
;
1965 printerFlags
= (char *) NULL
;
1966 printerOrient
= PS_PORTRAIT
;
1967 printerScaleX
= (double)1.0;
1968 printerScaleY
= (double)1.0;
1969 printerTranslateX
= 0;
1970 printerTranslateY
= 0;
1971 // 1 = Preview, 2 = print to file, 3 = send to printer
1973 afmPath
= (char *) NULL
;
1974 paperName
= (char *) NULL
;
1976 printerFile
= (char *) NULL
;
1979 wxPrintSetupData::~wxPrintSetupData()
1982 delete[] printerCommand
;
1984 delete[] previewCommand
;
1986 delete[] printerFlags
;
1992 delete[] printerFile
;
1995 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
1997 if (cmd
== printerCommand
)
2001 delete[] printerCommand
;
2003 printerCommand
= copystring(cmd
);
2005 printerCommand
= (char *) NULL
;
2008 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2010 if (cmd
== previewCommand
)
2014 delete[] previewCommand
;
2016 previewCommand
= copystring(cmd
);
2018 previewCommand
= (char *) NULL
;
2021 void wxPrintSetupData::SetPaperName(const char *name
)
2023 if (name
== paperName
)
2029 paperName
= copystring(name
);
2031 paperName
= (char *) NULL
;
2034 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2036 if (printerFlags
== flags
)
2040 delete[] printerFlags
;
2042 printerFlags
= copystring(flags
);
2044 printerFlags
= (char *) NULL
;
2047 void wxPrintSetupData::SetPrinterFile(const char *f
)
2049 if (f
== printerFile
)
2053 delete[] printerFile
;
2055 printerFile
= copystring(f
);
2057 printerFile
= (char *) NULL
;
2060 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2062 printerOrient
= orient
;
2065 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2071 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2073 printerTranslateX
= x
;
2074 printerTranslateY
= y
;
2077 // 1 = Preview, 2 = print to file, 3 = send to printer
2078 void wxPrintSetupData::SetPrinterMode(int mode
)
2083 void wxPrintSetupData::SetAFMPath(const char *f
)
2091 afmPath
= copystring(f
);
2093 afmPath
= (char *) NULL
;
2096 void wxPrintSetupData::SetColour(bool col
)
2101 // Get current values
2102 char *wxPrintSetupData::GetPrinterCommand()
2104 return printerCommand
;
2107 char *wxPrintSetupData::GetPrintPreviewCommand()
2109 return previewCommand
;
2112 char *wxPrintSetupData::GetPrinterOptions()
2114 return printerFlags
;
2117 char *wxPrintSetupData::GetPrinterFile()
2122 char *wxPrintSetupData::GetPaperName()
2127 int wxPrintSetupData::GetPrinterOrientation()
2129 return printerOrient
;
2132 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2138 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2140 *x
= printerTranslateX
;
2141 *y
= printerTranslateY
;
2144 int wxPrintSetupData::GetPrinterMode()
2149 char *wxPrintSetupData::GetAFMPath()
2154 bool wxPrintSetupData::GetColour()
2159 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2161 SetPrinterCommand(data
.GetPrinterCommand());
2162 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2163 SetPrinterOptions(data
.GetPrinterOptions());
2165 data
.GetPrinterTranslation(&x
, &y
);
2166 SetPrinterTranslation(x
, y
);
2169 data
.GetPrinterScaling(&x1
, &y1
);
2170 SetPrinterScaling(x1
, y1
);
2172 SetPrinterOrientation(data
.GetPrinterOrientation());
2173 SetPrinterMode(data
.GetPrinterMode());
2174 SetAFMPath(data
.GetAFMPath());
2175 SetPaperName(data
.GetPaperName());
2176 SetColour(data
.GetColour());
2179 void wxInitializePrintSetupData(bool init
)
2183 wxThePrintSetupData
= new wxPrintSetupData
;
2185 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2186 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2187 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2188 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2190 // Could have a .ini file to read in some defaults
2191 // - and/or use environment variables, e.g. WXWIN
2193 wxThePrintSetupData
->SetPrinterCommand("print");
2194 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2195 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2198 wxThePrintSetupData
->SetPrinterCommand("print");
2199 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2200 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2202 #if !defined(__VMS__) && !defined(__WXMSW__)
2203 wxThePrintSetupData
->SetPrinterCommand("lpr");
2204 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2205 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2210 if (wxThePrintSetupData
)
2211 delete wxThePrintSetupData
;
2212 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2217 * Paper size database for PostScript
2220 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2226 pageName
= copystring(name
);
2229 wxPrintPaperType::~wxPrintPaperType()
2235 * Print paper database for PostScript
2238 #if !USE_SHARED_LIBRARIES
2239 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
2242 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2244 DeleteContents(TRUE
);
2247 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2251 void wxPrintPaperDatabase::CreateDatabase()
2253 // Need correct values for page size in pixels.
2254 // Each unit is one 'point' = 1/72 of an inch.
2255 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2256 // in wxPostScriptDC code, so we can start from top left.
2257 // So access this database and translate by appropriate number
2258 // of points for this paper size. OR IS IT OK ALREADY?
2259 // Can't remember where the PostScript origin is by default.
2260 // Heck, someone will know how to make it hunky-dory...
2263 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2264 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2265 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2266 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2269 void wxPrintPaperDatabase::ClearDatabase()
2274 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2276 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2279 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2281 wxNode
*node
= Find(name
);
2283 return (wxPrintPaperType
*)node
->Data();
2285 return (wxPrintPaperType
*) NULL
;
2289 * Initialization/cleanup module
2292 bool wxPostScriptModule::OnInit()
2294 wxInitializePrintSetupData();
2295 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2296 wxThePrintPaperDatabase
->CreateDatabase();
2301 void wxPostScriptModule::OnExit()
2303 wxInitializePrintSetupData(FALSE
);
2304 delete wxThePrintPaperDatabase
;
2305 wxThePrintPaperDatabase
= NULL
;