1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 #include "wx/wxprec.h"
30 #include "wx/dcmemory.h"
33 #include "wx/filedlg.h"
35 #include "wx/msgdlg.h"
38 #include "wx/generic/dcpsg.h"
39 #include "wx/generic/prntdlgg.h"
40 #include "wx/button.h"
41 #include "wx/stattext.h"
42 #include "wx/radiobox.h"
43 #include "wx/textctrl.h"
67 //-----------------------------------------------------------------------------
68 // start and end of document/page
69 //-----------------------------------------------------------------------------
71 static const char *wxPostScriptHeaderEllipse
= "\
72 /ellipsedict 8 dict def\n\
73 ellipsedict /mtrx matrix put\n\
77 /startangle exch def\n\
82 /savematrix mtrx currentmatrix def\n\
85 0 0 1 startangle endangle arc\n\
86 savematrix setmatrix\n\
91 static const char *wxPostScriptHeaderEllipticArc
= "\
92 /ellipticarcdict 8 dict def\n\
93 ellipticarcdict /mtrx matrix put\n\
95 { ellipticarcdict begin\n\
98 /startangle exch def\n\
103 /savematrix mtrx currentmatrix def\n\
106 do_fill { 0 0 moveto } if\n\
107 0 0 1 startangle endangle arc\n\
108 savematrix setmatrix\n\
109 do_fill { fill }{ stroke } ifelse\n\
113 static const char *wxPostScriptHeaderSpline
= "\
114 /DrawSplineSection {\n\
121 /xa x1 x2 x1 sub 0.666667 mul add def\n\
122 /ya y1 y2 y1 sub 0.666667 mul add def\n\
123 /xb x3 x2 x3 sub 0.666667 mul add def\n\
124 /yb y3 y2 y3 sub 0.666667 mul add def\n\
126 xa ya xb yb x3 y3 curveto\n\
130 static const char *wxPostScriptHeaderColourImage
= "\
131 % define 'colorimage' if it isn't defined\n\
132 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
134 /colorimage where % do we know about 'colorimage'?\n\
135 { pop } % yes: pop off the 'dict' returned\n\
136 { % no: define one\n\
137 /colortogray { % define an RGB->I function\n\
138 /rgbdata exch store % call input 'rgbdata'\n\
139 rgbdata length 3 idiv\n\
140 /npixls exch store\n\
142 0 1 npixls 1 sub {\n\
144 rgbdata rgbindx get 20 mul % Red\n\
145 rgbdata rgbindx 1 add get 32 mul % Green\n\
146 rgbdata rgbindx 2 add get 12 mul % Blue\n\
147 add add 64 idiv % I = .5G + .31R + .18B\n\
149 /rgbindx rgbindx 3 add store\n\
151 grays 0 npixls getinterval\n\
154 % Utility procedure for colorimage operator.\n\
155 % This procedure takes two procedures off the\n\
156 % stack and merges them into a single procedure.\n\
158 /mergeprocs { % def\n\
177 /colorimage { % def\n\
178 pop pop % remove 'false 3' operands\n\
179 {colortogray} mergeprocs\n\
182 } ifelse % end of 'false' case\n\
185 static char wxPostScriptHeaderReencodeISO1
[] =
187 "dup dup findfont dup length dict begin\n"
188 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
189 "/Encoding ISOLatin1Encoding def\n"
190 "currentdict end definefont\n"
192 "/ISOLatin1Encoding [\n"
193 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
194 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
195 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
196 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
197 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
198 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
199 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
200 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
201 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
202 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
203 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
204 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
205 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
206 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
207 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
209 static char wxPostScriptHeaderReencodeISO2
[] =
210 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
211 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
212 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
213 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
214 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
215 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
216 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
217 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
218 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
219 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
220 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
221 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
222 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
223 "/yacute/thorn/ydieresis\n"
226 //-------------------------------------------------------------------------------
228 //-------------------------------------------------------------------------------
230 wxPostScriptDC::wxPostScriptDC ()
232 m_pstream
= (ofstream
*) NULL
;
242 m_underlinePosition
= 0.0;
243 m_underlineThickness
= 0.0;
245 m_signX
= 1; // default x-axis left to right
246 m_signY
= -1; // default y-axis bottom up -> top down
249 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
251 m_pstream
= (ofstream
*) NULL
;
261 m_underlinePosition
= 0.0;
262 m_underlineThickness
= 0.0;
264 m_signX
= 1; // default x-axis left to right
265 m_signY
= -1; // default y-axis bottom up -> top down
267 Create(file
, interactive
, parent
);
270 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
272 m_isInteractive
= interactive
;
278 // Can only send to file in Windows
279 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
284 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
294 wxPostScriptDC::~wxPostScriptDC ()
296 if (m_pstream
) delete m_pstream
;
299 bool wxPostScriptDC::Ok() const
304 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
306 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
307 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
308 m_ok
= (dialog
.ShowModal () == wxID_OK
);
310 if (!m_ok
) return FALSE
;
312 if ((m_filename
== "") &&
313 (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
||
314 wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
318 wxThePrintSetupData
->SetPrinterFile("preview");
320 // For PS_PRINTER action this depends on a Unix-style print spooler
321 // since the wx_printer_file can be destroyed during a session
322 // @@@ TODO: a Windows-style answer for non-Unix
324 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
326 strcpy (tmp
, "/tmp/preview_");
327 strcat (tmp
, userId
);
328 wxThePrintSetupData
->SetPrinterFile(tmp
);
331 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
332 strcat (tmp2
, ".ps");
333 wxThePrintSetupData
->SetPrinterFile(tmp2
);
336 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
338 char *file
= wxSaveFileSelector (_("PostScript"), "ps");
344 wxThePrintSetupData
->SetPrinterFile(file
);
352 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
354 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
356 if (m_clipping
) return;
358 wxDC::SetClippingRegion( x
, y
, w
, h
);
361 *m_pstream
<< "gsave\n"
363 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
364 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
365 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
366 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
367 << "closepath clip newpath\n";
370 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
374 void wxPostScriptDC::DestroyClippingRegion()
376 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
378 wxDC::DestroyClippingRegion();
383 *m_pstream
<< "grestore\n";
387 void wxPostScriptDC::Clear()
389 wxFAIL_MSG( "wxPostScriptDC::Clear not implemented." );
392 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
394 wxFAIL_MSG( "wxPostScriptDC::FloodFill not implemented." );
397 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
399 wxFAIL_MSG( "wxPostScriptDC::GetPixel not implemented." );
403 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
405 wxFAIL_MSG( "wxPostScriptDC::CrossHair not implemented." );
408 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
410 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
412 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
416 *m_pstream
<< "newpath\n"
417 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
418 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
421 CalcBoundingBox( x1
, y1
);
422 CalcBoundingBox( x2
, y2
);
425 #define RAD2DEG 57.29577951308
427 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
429 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
433 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
434 double alpha1
, alpha2
;
436 if (x1
== x2
&& y1
== y2
)
440 } else if (radius
== 0.0)
442 alpha1
= alpha2
= 0.0;
445 alpha1
= (x1
- xc
== 0) ?
446 (y1
- yc
< 0) ? 90.0 : -90.0 :
447 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
448 alpha2
= (x2
- xc
== 0) ?
449 (y2
- yc
< 0) ? 90.0 : -90.0 :
450 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
452 while (alpha1
<= 0) alpha1
+= 360;
453 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
454 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
455 while (alpha2
> 360) alpha2
-= 360;
457 if (m_brush
.GetStyle() != wxTRANSPARENT
)
460 *m_pstream
<< "newpath\n"
461 << XLOG2DEV(xc
) << " "
462 << YLOG2DEV(yc
) << " "
463 << XLOG2DEVREL(radius
) << " "
464 << YLOG2DEVREL(radius
) << " "
466 << alpha2
<< " ellipse\n"
467 << XLOG2DEV(xc
) << " "
468 << YLOG2DEV(yc
) << " lineto\n"
473 if (m_pen
.GetStyle() != wxTRANSPARENT
)
476 *m_pstream
<< "newpath\n"
477 << XLOG2DEV(xc
) << " "
478 << YLOG2DEV(yc
) << " "
479 << XLOG2DEVREL(radius
) << " "
480 << YLOG2DEVREL(radius
) << " "
482 << alpha2
<< " ellipse\n"
486 CalcBoundingBox( xc
-radius
, yc
-radius
);
487 CalcBoundingBox( xc
+radius
, yc
+radius
);
490 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
492 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
494 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
495 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
501 DrawEllipse(x
,y
,w
,h
);
505 if (m_brush
.GetStyle () != wxTRANSPARENT
)
509 *m_pstream
<< "newpath\n"
510 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
511 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
512 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
514 CalcBoundingBox( x
,y
);
515 CalcBoundingBox( x
+w
, y
+h
);
518 if (m_pen
.GetStyle () != wxTRANSPARENT
)
522 *m_pstream
<< "newpath\n"
523 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
524 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
525 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
527 CalcBoundingBox( x
, y
);
528 CalcBoundingBox( x
+w
, y
+h
);
532 void wxPostScriptDC::DrawPoint (long x
, long y
)
534 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
536 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
540 *m_pstream
<< "newpath\n"
541 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
542 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
545 CalcBoundingBox( x
, y
);
548 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
550 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
554 if (m_brush
.GetStyle () != wxTRANSPARENT
)
558 *m_pstream
<< "newpath\n";
560 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
561 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
562 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
563 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
565 for (int i
= 1; i
< n
; i
++)
567 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
568 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
569 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
570 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
572 *m_pstream
<< "fill\n";
575 if (m_pen
.GetStyle () != wxTRANSPARENT
)
579 *m_pstream
<< "newpath\n";
581 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
582 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
583 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
584 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
586 for (int i
= 1; i
< n
; i
++)
588 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
589 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
590 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
591 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
594 *m_pstream
<< "stroke\n";
598 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
600 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
602 if (m_pen
.GetStyle() == wxTRANSPARENT
)
610 for ( i
=0; i
<n
; i
++ )
612 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
615 *m_pstream
<< "newpath\n"
616 << XLOG2DEV(points
[0].x
+xoffset
) << " "
617 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
619 for (i
= 1; i
< n
; i
++)
621 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
622 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
625 *m_pstream
<< "stroke\n";
628 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
630 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
632 if (m_brush
.GetStyle () != wxTRANSPARENT
)
636 *m_pstream
<< "newpath\n"
637 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
638 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
639 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
640 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
644 CalcBoundingBox( x
, y
);
645 CalcBoundingBox( x
+ width
, y
+ height
);
648 if (m_pen
.GetStyle () != wxTRANSPARENT
)
652 *m_pstream
<< "newpath\n"
653 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
654 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
655 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
656 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
660 CalcBoundingBox( x
, y
);
661 CalcBoundingBox( x
+ width
, y
+ height
);
665 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
667 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
671 // Now, a negative radius is interpreted to mean
672 // 'the proportion of the smallest X or Y dimension'
673 double smallest
= 0.0;
678 radius
= (-radius
* smallest
);
681 long rad
= (long) radius
;
683 if (m_brush
.GetStyle () != wxTRANSPARENT
)
687 // Draw rectangle anticlockwise
688 *m_pstream
<< "newpath\n"
689 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
690 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
691 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
692 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
693 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
694 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
695 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
696 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
700 CalcBoundingBox( x
, y
);
701 CalcBoundingBox( x
+ width
, y
+ height
);
704 if (m_pen
.GetStyle () != wxTRANSPARENT
)
708 // Draw rectangle anticlockwise
709 *m_pstream
<< "newpath\n"
710 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
711 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
712 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
713 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
714 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
715 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
716 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
717 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
721 CalcBoundingBox( x
, y
);
722 CalcBoundingBox( x
+ width
, y
+ height
);
726 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
728 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
730 if (m_brush
.GetStyle () != wxTRANSPARENT
)
734 *m_pstream
<< "newpath\n"
735 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
736 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
739 CalcBoundingBox( x
- width
, y
- height
);
740 CalcBoundingBox( x
+ width
, y
+ height
);
743 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
747 *m_pstream
<< "newpath\n"
748 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
749 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
752 CalcBoundingBox( x
- width
, y
- height
);
753 CalcBoundingBox( x
+ width
, y
+ height
);
757 void wxPostScriptDC::DrawIcon( const wxIcon
& icon
, long x
, long y
)
759 DrawBitmap( icon
, x
, y
, TRUE
);
762 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool WXUNUSED(useMask
) )
764 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
766 if (!bitmap
.Ok()) return;
768 wxImage
image( bitmap
);
770 if (!image
.Ok()) return;
772 int ww
= XLOG2DEVREL(image
.GetWidth());
773 int hh
= YLOG2DEVREL(image
.GetHeight());
775 image
= image
.Scale( ww
, hh
);
777 if (!image
.Ok()) return;
779 int xx
= XLOG2DEV(x
);
780 int yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
782 *m_pstream
<< "/origstate save def\n"
784 << "/pix " << ww
<< " string def\n"
785 << "/grays " << ww
<< " string def\n"
786 << "/npixels 0 def\n"
787 << "/rgbindx 0 def\n"
788 << xx
<< " " << yy
<< " translate\n"
789 << ww
<< " " << hh
<< " scale\n"
790 << ww
<< " " << hh
<< " 8\n"
791 << "[" << ww
<< " 0 0 " << (-hh
) << " 0 " << hh
<< "]\n"
792 << "{currentfile pix readhexstring pop}\n"
793 << "false 3 colorimage\n";
795 for (int j
= 0; j
< hh
; j
++)
797 for (int i
= 0; i
< ww
; i
++)
801 wxDecToHex( image
.GetRed(i
,j
), buffer
);
802 *m_pstream
<< buffer
;
803 wxDecToHex( image
.GetGreen(i
,j
), buffer
);
804 *m_pstream
<< buffer
;
805 wxDecToHex( image
.GetBlue(i
,j
), buffer
);
806 *m_pstream
<< buffer
;
811 *m_pstream
<< "end\n";
812 *m_pstream
<< "origstate restore\n";
816 void wxPostScriptDC::SetFont( const wxFont
& font
)
818 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
820 if (!font
.Ok()) return;
825 const char *style
= "";
826 int Style
= m_font
.GetStyle();
827 int Weight
= m_font
.GetWeight();
829 switch (m_font
.GetFamily ())
839 // name = "/Times-Roman";
840 name
= "/Times"; // Altered by EDZ
843 name
= "/Zapf-Chancery-MediumItalic";
848 case wxDEFAULT
: // Sans Serif Font
849 name
= "/LucidaSans";
852 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
854 if (m_font
.GetFamily () == wxROMAN
)
859 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
863 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
865 if (m_font
.GetFamily () == wxROMAN
)
870 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
872 if (m_font
.GetFamily () == wxROMAN
)
873 style
= "-BoldItalic";
875 style
= "-BoldOblique";
877 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
879 if (m_font
.GetFamily () == wxROMAN
)
884 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
886 if (m_font
.GetFamily () == wxROMAN
)
887 style
= "-BoldItalic";
889 style
= "-BoldOblique";
900 *m_pstream
<< buf
<< " reencodeISO def\n";
901 *m_pstream
<< buf
<< " findfont\n";
902 *m_pstream
<< YLOG2DEVREL(m_font
.GetPointSize()) << " scalefont setfont\n";
905 void wxPostScriptDC::SetPen( const wxPen
& pen
)
907 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
909 if (!pen
.Ok()) return;
911 int oldStyle
= m_pen
.GetStyle();
915 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
918 Line style - WRONG: 2nd arg is OFFSET
920 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
921 operator correctly. You should look-up this in the Red Book: the 2nd parame-
922 ter is not number of values in the array of the first one, but an offset
923 into this description of the pattern. I mean a real *offset* not index
924 into array. I.e. If the command is [3 4] 1 setdash is used, then there
925 will be first black line *2* units long, then space 4 units, then the
926 pattern of *3* units black, 4 units space will be repeated.
929 static const char *dotted
= "[2 5] 2";
930 static const char *short_dashed
= "[4 4] 2";
931 static const char *long_dashed
= "[4 8] 2";
932 static const char *dotted_dashed
= "[6 6 2 6] 4";
934 const char *psdash
= (char *) NULL
;
935 switch (m_pen
.GetStyle ())
937 case wxDOT
: psdash
= dotted
; break;
938 case wxSHORT_DASH
: psdash
= short_dashed
; break;
939 case wxLONG_DASH
: psdash
= long_dashed
; break;
940 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
943 default: psdash
= "[] 0"; break;
946 if (oldStyle
!= m_pen
.GetStyle())
948 *m_pstream
<< psdash
<< " setdash\n";
952 unsigned char red
= m_pen
.GetColour().Red();
953 unsigned char blue
= m_pen
.GetColour().Blue();
954 unsigned char green
= m_pen
.GetColour().Green();
958 // Anything not white is black
959 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
960 && green
== (unsigned char) 255))
962 red
= (unsigned char) 0;
963 green
= (unsigned char) 0;
964 blue
= (unsigned char) 0;
970 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
972 long redPS
= (long) (((int) red
) / 255.0);
973 long bluePS
= (long) (((int) blue
) / 255.0);
974 long greenPS
= (long) (((int) green
) / 255.0);
976 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
979 m_currentBlue
= blue
;
980 m_currentGreen
= green
;
984 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
986 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
988 if (!brush
.Ok()) return;
993 unsigned char red
= m_brush
.GetColour ().Red ();
994 unsigned char blue
= m_brush
.GetColour ().Blue ();
995 unsigned char green
= m_brush
.GetColour ().Green ();
999 // Anything not black is white
1000 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
1001 && green
== (unsigned char) 0))
1003 red
= (unsigned char) 255;
1004 green
= (unsigned char) 255;
1005 blue
= (unsigned char) 255;
1011 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1013 long redPS
= (long) (((int) red
) / 255.0);
1014 long bluePS
= (long) (((int) blue
) / 255.0);
1015 long greenPS
= (long) (((int) green
) / 255.0);
1016 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1018 m_currentBlue
= blue
;
1019 m_currentGreen
= green
;
1023 void wxPostScriptDC::DrawText( const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
) )
1025 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1029 if (m_textForegroundColour
.Ok ())
1031 unsigned char red
= m_textForegroundColour
.Red ();
1032 unsigned char blue
= m_textForegroundColour
.Blue ();
1033 unsigned char green
= m_textForegroundColour
.Green ();
1037 // Anything not white is black
1038 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
1039 && green
== (unsigned char) 255))
1041 red
= (unsigned char) 0;
1042 green
= (unsigned char) 0;
1043 blue
= (unsigned char) 0;
1047 // maybe setgray here ?
1049 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1051 long redPS
= (long) (((int) red
) / 255.0);
1052 long bluePS
= (long) (((int) blue
) / 255.0);
1053 long greenPS
= (long) (((int) green
) / 255.0);
1054 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
1057 m_currentBlue
= blue
;
1058 m_currentGreen
= green
;
1062 int size
= m_font
.GetPointSize();
1064 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
1065 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
1068 int len
= strlen ((char *)(const char *)text
);
1070 for (i
= 0; i
< len
; i
++)
1072 int c
= (unsigned char) text
[i
];
1073 if ( c
== ')' || c
== '(' || c
== '\\')
1075 *m_pstream
<< "\\" << (char) c
;
1077 else if ( c
>= 128 )
1079 // Cope with character codes > 127
1081 sprintf(tmp
, "\\%o", c
);
1085 *m_pstream
<< (char) c
;
1088 *m_pstream
<< ")" << " show\n";
1090 if (m_font
.GetUnderlined())
1092 long uy
= (long)(y
+ size
- m_underlinePosition
);
1094 GetTextExtent(text
, &w
, &h
);
1096 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
1098 << (long)m_underlineThickness
<< " setlinewidth "
1099 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
1100 << " lineto stroke grestore\n";
1103 CalcBoundingBox( x
, y
);
1104 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1108 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1110 m_backgroundBrush
= brush
;
1113 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1115 wxFAIL_MSG( "wxPostScriptDC::SetLogicalFunction not implemented." );
1118 void wxPostScriptDC::DrawSpline( wxList
*points
)
1120 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1124 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1127 wxNode
*node
= points
->First();
1128 p
= (wxPoint
*)node
->Data();
1132 node
= node
->Next();
1133 p
= (wxPoint
*)node
->Data();
1136 x3
= a
= (double)(x1
+ c
) / 2;
1137 y3
= b
= (double)(y1
+ d
) / 2;
1139 *m_pstream
<< "newpath "
1140 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
1141 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
1143 CalcBoundingBox( (long)x1
, (long)y1
);
1144 CalcBoundingBox( (long)x3
, (long)y3
);
1146 while ((node
= node
->Next()) != NULL
)
1148 q
= (wxPoint
*)node
->Data();
1156 x3
= (double)(x2
+ c
) / 2;
1157 y3
= (double)(y2
+ d
) / 2;
1158 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
1159 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
1160 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
1162 CalcBoundingBox( (long)x1
, (long)y1
);
1163 CalcBoundingBox( (long)x3
, (long)y3
);
1167 At this point, (x2,y2) and (c,d) are the position of the
1168 next-to-last and last point respectively, in the point list
1171 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1174 long wxPostScriptDC::GetCharWidth ()
1176 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1177 return (long) (GetCharHeight() * 72.0 / 120.0);
1181 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1183 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1185 m_signX
= (xLeftRight
? 1 : -1);
1186 m_signY
= (yBottomUp
? 1 : -1);
1188 // FIXME there is no such function in MSW
1190 ComputeScaleAndOrigin();
1194 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1196 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1202 wxDC::SetDeviceOrigin( x
, h
-y
);
1205 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1207 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1209 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1211 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1213 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1217 if (width
) *width
= paper
->widthPixels
;
1218 if (height
) *height
= paper
->heightPixels
;
1222 if (width
) *width
= 595;
1223 if (height
) *height
= 842;
1227 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1229 wxCHECK_MSG( m_ok
, FALSE
, "invalid postscript dc" );
1231 if (m_filename
== "")
1233 m_filename
= wxGetTempFileName("ps");
1234 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1239 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1242 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1244 if (!m_pstream
|| !m_pstream
->good())
1246 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1253 SetBrush( *wxBLACK_BRUSH
);
1254 SetPen( *wxBLACK_PEN
);
1255 SetBackground( *wxWHITE_BRUSH
);
1256 SetTextForeground( *wxBLACK
);
1258 // set origin according to paper size
1259 SetDeviceOrigin( 0,0 );
1267 void wxPostScriptDC::EndDoc ()
1269 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1274 *m_pstream
<< "grestore\n";
1280 m_pstream
= (ofstream
*) NULL
;
1283 char *header_file
= wxGetTempFileName("ps");
1285 m_pstream
= new ofstream( header_file
);
1287 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1288 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1289 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1290 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1293 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1295 *m_pstream
<< "%%For: " << (char *)userID
;
1297 if (wxGetUserName(userName
, sizeof(userName
)))
1298 *m_pstream
<< " (" << (char *)userName
<< ")";
1301 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1303 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1306 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1308 long wx_printer_translate_x
, wx_printer_translate_y
;
1309 double wx_printer_scale_x
, wx_printer_scale_y
;
1310 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1311 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1313 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1315 *m_pstream
<< "%%Orientation: Landscape\n";
1319 *m_pstream
<< "%%Orientation: Portrait\n";
1322 // Compute the bounding box. Note that it is in the default user
1323 // coordinate system, thus we have to convert the values.
1324 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1325 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1326 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1327 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1329 // If we're landscape, our sense of "x" and "y" is reversed.
1330 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1333 tmp
= llx
; llx
= lly
; lly
= tmp
;
1334 tmp
= urx
; urx
= ury
; ury
= tmp
;
1336 // We need either the two lines that follow, or we need to subtract
1337 // min_x from real_translate_y, which is commented out below.
1338 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1339 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1342 // The Adobe specifications call for integers; we round as to make
1343 // the bounding larger.
1344 *m_pstream
<< "%%BoundingBox: "
1345 << floor((double)llx
) << " " << floor((double)lly
) << " "
1346 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1347 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1348 *m_pstream
<< "%%EndComments\n\n";
1350 // To check the correctness of the bounding box, postscript commands
1351 // to draw a box corresponding to the bounding box are generated below.
1352 // But since we typically don't want to print such a box, the postscript
1353 // commands are generated within comments. These lines appear before any
1354 // adjustment of scale, rotation, or translation, and hence are in the
1355 // default user coordinates.
1356 *m_pstream
<< "% newpath\n";
1357 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1358 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1359 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1360 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1362 *m_pstream
<< "%%BeginProlog\n";
1363 *m_pstream
<< wxPostScriptHeaderEllipse
;
1364 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1365 *m_pstream
<< wxPostScriptHeaderColourImage
;
1366 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1367 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1369 if (wxPostScriptHeaderSpline
)
1370 *m_pstream
<< wxPostScriptHeaderSpline
;
1371 *m_pstream
<< "%%EndProlog\n";
1374 m_pstream
= (ofstream
*) NULL
;
1376 char *tmp_file
= wxGetTempFileName("ps");
1378 // Paste header Before wx_printer_file
1379 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1380 wxRemoveFile (header_file
);
1381 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1382 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1384 #if defined(__X__) || defined(__WXGTK__)
1387 switch (wxThePrintSetupData
->GetPrinterMode()) {
1391 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1392 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1393 argv
[2] = (char *) NULL
;
1394 wxExecute (argv
, TRUE
);
1395 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1403 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1405 // !SM! If we simply assign to argv[1] here, if printer options
1406 // are blank, we get an annoying and confusing message from lpr.
1407 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1409 argv
[argc
++] = opts
;
1411 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1412 argv
[argc
++] = (char *) NULL
;
1413 wxExecute (argv
, TRUE
);
1414 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1425 void wxPostScriptDC::StartPage ()
1427 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1429 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1431 // *m_pstream << "matrix currentmatrix\n";
1433 // Added by Chris Breeze
1435 // Each page starts with an "initgraphics" which resets the
1436 // transformation and so we need to reset the origin
1437 // (and rotate the page for landscape printing)
1440 m_scaleFactor = 1.0;
1441 m_logicalOriginX = 0;
1442 m_logicalOriginY = 0;
1445 long translate_x
, translate_y
;
1446 double scale_x
, scale_y
;
1447 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1448 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1450 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1452 translate_y
-= m_maxY
;
1453 *m_pstream
<< "90 rotate\n";
1456 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1457 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1460 void wxPostScriptDC::EndPage ()
1462 wxCHECK_RET( m_ok
&& m_pstream
, "invalid postscript dc" );
1464 *m_pstream
<< "showpage\n";
1467 bool wxPostScriptDC::Blit( long WXUNUSED(xdest
), long WXUNUSED(ydest
),
1468 long WXUNUSED(fwidth
), long WXUNUSED(fheight
),
1469 wxDC
*WXUNUSED(source
),
1470 long WXUNUSED(xsrc
), long WXUNUSED(ysrc
),
1471 int WXUNUSED(rop
), bool WXUNUSED(useMask
) )
1473 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, "invalid postscript dc" );
1475 wxFAIL_MSG( "wxPostScriptDC::Blit no yet implemented." );
1480 long wxPostScriptDC::GetCharHeight ()
1483 return m_font
.GetPointSize();
1488 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1489 long *descent
, long *externalLeading
, wxFont
*theFont
,
1490 bool WXUNUSED(use16
))
1492 wxFont
*fontToUse
= theFont
;
1494 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1496 wxCHECK_RET( fontToUse
, "GetTextExtent: no font defined" );
1497 wxCHECK_RET( x
, "GetTextExtent: x == NULL" );
1498 wxCHECK_RET( y
, "GetTextExtent: y == NULL" );
1500 #if !USE_AFM_FOR_POSTSCRIPT
1501 /* Provide a VERY rough estimate (avoid using it).
1502 * Produces accurate results for mono-spaced font
1503 * such as Courier (aka wxMODERN) */
1508 height
= fontToUse
->GetPointSize();
1510 *x
= strlen (string
) * height
* 72 / 120;
1511 *y
= (long) (height
* 1.32); /* allow for descender */
1512 if (descent
) *descent
= 0;
1513 if (externalLeading
) *externalLeading
= 0;
1516 /* method for calculating string widths in postscript:
1517 / read in the AFM (adobe font metrics) file for the
1518 / actual font, parse it and extract the character widths
1519 / and also the descender. this may be improved, but for now
1520 / it works well. the AFM file is only read in if the
1521 / font is changed. this may be chached in the future.
1522 / calls to GetTextExtent with the font unchanged are rather
1525 / for each font and style used there is an AFM file necessary.
1526 / currently i have only files for the roman font family.
1527 / I try to get files for the other ones!
1529 / CAVE: the size of the string is currently always calculated
1530 / in 'points' (1/72 of an inch). this should later on be
1531 / changed to depend on the mapping mode.
1532 / CAVE: the path to the AFM files must be set before calling this
1533 / function. this is usually done by a call like the following:
1534 / wxSetAFMPath("d:\\wxw161\\afm\\");
1538 / wxPostScriptDC dc(NULL, TRUE);
1540 / wxSetAFMPath("d:\\wxw161\\afm\\");
1541 / dc.StartDoc("Test");
1544 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1545 / dc.GetTextExtent("Hallo",&w,&h);
1550 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1552 / updated: 14.05.95 */
1554 /* these static vars are for storing the state between calls */
1555 static int lastFamily
= INT_MIN
;
1556 static int lastSize
= INT_MIN
;
1557 static int lastStyle
= INT_MIN
;
1558 static int lastWeight
= INT_MIN
;
1559 static int lastDescender
= INT_MIN
;
1560 static int lastWidths
[256]; /* widths of the characters */
1562 /* get actual parameters */
1563 const int Family
= fontToUse
->GetFamily();
1564 const int Size
= fontToUse
->GetPointSize();
1565 const int Style
= fontToUse
->GetStyle();
1566 const int Weight
= fontToUse
->GetWeight();
1568 /* if we have another font, read the font-metrics */
1569 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1571 /* store actual values */
1572 lastFamily
= Family
;
1575 lastWeight
= Weight
;
1577 char *name
= (char*) NULL
;
1583 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO";
1584 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo";
1585 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Cour0";
1591 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO";
1592 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo";
1593 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO";
1594 else if name
= "TimesRo"; /* no typo */
1599 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO";
1600 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo";
1601 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Helv0";
1602 else if ((Style
!= wxITALIC
) && (Weight
!= wxBOLD
)) name
= "Helv";
1607 /* get the directory of the AFM files */
1610 if (wxGetAFMPath()) strcpy( afmName
, wxGetAFMPath() );
1612 /* 2. open and process the file
1613 / a short explanation of the AFM format:
1614 / we have for each character a line, which gives its size
1617 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1619 / that means, we have a character with ascii code 63, and width
1620 / (444/1000 * fontSize) points.
1621 / the other data is ignored for now!
1623 / when the font has changed, we read in the right AFM file and store the
1624 / character widths in an array, which is processed below (see point 3.). */
1626 /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */
1628 strcat(afmName
,name
);
1629 strcat(afmName
,".afm");
1630 FILE *afmFile
= fopen(afmName
,"r");
1631 if ( afmFile
==NULL
)
1633 wxLogDebug( "GetTextExtent: can't open AFM file '%s'\n", afmName
);
1634 wxLogDebug( " using approximate values\n");
1635 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
1636 lastDescender
= -150; /* dito. */
1640 /* init the widths array */
1641 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
1642 /* some variables for holding parts of a line */
1643 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1644 char upString
[30], utString
[30], encString
[50];
1647 /* read in the file and parse it */
1648 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
1650 /* A.) check for descender definition */
1651 if (strncmp(line
,"Descender",9)==0)
1653 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
1654 (strcmp(descString
,"Descender")!=0))
1656 wxLogDebug( "AFM-file '%s': line '%s' has error (bad descender)\n", afmName
,line
);
1659 /* JC 1.) check for UnderlinePosition */
1660 else if(strncmp(line
,"UnderlinePosition",17)==0)
1662 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
1663 (strcmp(upString
,"UnderlinePosition")!=0))
1665 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", afmName
, line
);
1668 /* JC 2.) check for UnderlineThickness */
1669 else if(strncmp(line
,"UnderlineThickness",18)==0)
1671 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
1672 (strcmp(utString
,"UnderlineThickness")!=0))
1674 wxLogDebug( "AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", afmName
, line
);
1677 /* JC 3.) check for EncodingScheme */
1678 else if(strncmp(line
,"EncodingScheme",14)==0)
1680 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
1681 (strcmp(utString
,"EncodingScheme")!=0))
1683 wxLogDebug("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", afmName
, line
);
1685 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1687 wxLogDebug( "AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1688 afmName
,line
, encString
);
1691 /* B.) check for char-width */
1692 else if(strncmp(line
,"C ",2)==0)
1694 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
1696 wxLogDebug("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1698 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
1700 wxLogDebug("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1702 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
1703 if (ascii
>=0 && ascii
<256)
1705 lastWidths
[ascii
] = cWidth
; /* store width */
1709 /* MATTHEW: this happens a lot; don't print an error */
1710 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); */
1713 /* C.) ignore other entries. */
1717 /* hack to compute correct values for german 'Umlaute'
1718 / the correct way would be to map the character names
1719 / like 'adieresis' to corresp. positions of ISOEnc and read
1720 / these values from AFM files, too. Maybe later ... */
1721 lastWidths
[196] = lastWidths
['A']; // Ä
1722 lastWidths
[228] = lastWidths
['a']; // ä
1723 lastWidths
[214] = lastWidths
['O']; // Ö
1724 lastWidths
[246] = lastWidths
['o']; // ö
1725 lastWidths
[220] = lastWidths
['U']; // Ü
1726 lastWidths
[252] = lastWidths
['u']; // ü
1727 lastWidths
[223] = lastWidths
[251]; // ß
1730 /* JC: calculate UnderlineThickness/UnderlinePosition */
1731 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1732 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1734 /* 3. now the font metrics are read in, calc size this
1735 / is done by adding the widths of the characters in the
1736 / string. they are given in 1/1000 of the size! */
1739 long height
=Size
; /* by default */
1741 for(p
=(unsigned char *)(const char *)string
; *p
; p
++)
1743 if(lastWidths
[*p
]== INT_MIN
)
1745 wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n", *p
,*p
);
1746 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); /* assume space */
1750 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1754 /* add descender to height (it is usually a negative value) */
1755 if (lastDescender
!=INT_MIN
)
1757 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1760 /* return size values */
1764 /* return other parameters */
1767 if(lastDescender
!=INT_MIN
)
1769 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1777 /* currently no idea how to calculate this! */
1778 if (externalLeading
) *externalLeading
= 0;
1783 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
1785 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1787 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1789 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1791 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1795 if (width
) *width
= paper
->widthMM
;
1796 if (height
) *height
= paper
->heightMM
;
1800 if (width
) *width
= 210;
1801 if (height
) *height
= 297;
1805 // Determine the Default Postscript Previewer
1806 // available on the platform
1807 #if defined(__SUN__) && defined(__XVIEW__)
1808 // OpenWindow/NeWS's Postscript Previewer
1809 # define PS_VIEWER_PROG "pageview"
1810 #elif defined(__VMS__)
1811 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
1812 #elif defined(__SGI__)
1813 // SGI's Display Postscript Previewer
1814 //# define PS_VIEWER_PROG "dps"
1815 # define PS_VIEWER_PROG "xpsview"
1816 #elif defined(__X__) || defined(__WXGTK__)
1817 // Front-end to ghostscript
1818 # define PS_VIEWER_PROG "ghostview"
1820 // Windows ghostscript/ghostview
1821 # define PS_VIEWER_PROG NULL
1824 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
1826 #if !USE_SHARED_LIBRARY
1827 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
1828 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
1829 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
1830 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
1833 // Redundant now I think
1835 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
1837 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
1838 const wxPoint
& pos
, const wxSize
& size
, long style
):
1839 wxDialog(parent
, -1, title
, pos
, size
, style
)
1841 wxBeginBusyCursor();
1846 *orientation
= new wxString
[2],
1847 *print_modes
= new wxString
[3];
1849 long wx_printer_translate_x
, wx_printer_translate_y
;
1850 double wx_printer_scale_x
, wx_printer_scale_y
;
1852 orientation
[0] = _("Portrait");
1853 orientation
[1] = _("Landscape");
1855 print_modes
[0] = _("Send to Printer");
1856 print_modes
[1] = _("Print to File");
1857 print_modes
[2] = _("Preview Only");
1861 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
1862 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
1863 okBut
->SetDefault();
1866 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1867 (void) new wxStaticText( this, -1, _("Printer Command: "),
1869 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
1870 wxPoint(100, yPos
), wxSize(100, -1) );
1872 (void) new wxStaticText( this, -1, _("Printer Options: "),
1873 wxPoint(210, yPos
) );
1874 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
1875 wxPoint(305, yPos
), wxSize(150, -1) );
1881 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
1882 2,orientation
,2,wxRA_SPECIFY_ROWS
);
1883 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
1885 // @@@ Configuration hook
1886 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
1887 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
1889 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
1891 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
1892 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
1894 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
1896 wxSize(-1,-1), features
,
1897 print_modes
, features
, wxRA_SPECIFY_ROWS
);
1900 radio1
->Enable(0, FALSE
);
1901 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
1902 radio1
->Enable(2, FALSE
);
1905 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
1906 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1907 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1909 sprintf (buf
, "%.2f", wx_printer_scale_x
);
1912 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
1913 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1915 sprintf (buf
, "%.2f", wx_printer_scale_y
);
1916 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
1917 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1921 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
1922 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
1923 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
1925 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
1926 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
1927 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
1931 delete[] orientation
;
1932 delete[] print_modes
;
1937 int wxPostScriptPrintDialog::ShowModal ()
1939 if ( wxDialog::ShowModal() == wxID_OK
)
1941 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
1942 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
1943 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
1944 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
1945 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
1946 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
1947 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
1948 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
1950 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
1951 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
1952 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
1953 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
1956 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
1957 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
1960 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
1963 switch ( radio1
->GetSelection() ) {
1964 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
1965 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
1966 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
1975 // PostScript printer settings
1976 // RETAINED FOR BACKWARD COMPATIBILITY
1977 void wxSetPrinterCommand(const char *cmd
)
1979 wxThePrintSetupData
->SetPrinterCommand(cmd
);
1982 void wxSetPrintPreviewCommand(const char *cmd
)
1984 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
1987 void wxSetPrinterOptions(const char *flags
)
1989 wxThePrintSetupData
->SetPrinterOptions(flags
);
1992 void wxSetPrinterFile(const char *f
)
1994 wxThePrintSetupData
->SetPrinterFile(f
);
1997 void wxSetPrinterOrientation(int orient
)
1999 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2002 void wxSetPrinterScaling(double x
, double y
)
2004 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2007 void wxSetPrinterTranslation(long x
, long y
)
2009 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2012 // 1 = Preview, 2 = print to file, 3 = send to printer
2013 void wxSetPrinterMode(int mode
)
2015 wxThePrintSetupData
->SetPrinterMode(mode
);
2018 void wxSetAFMPath(const char *f
)
2020 wxThePrintSetupData
->SetAFMPath(f
);
2023 // Get current values
2024 char *wxGetPrinterCommand()
2026 return wxThePrintSetupData
->GetPrinterCommand();
2029 char *wxGetPrintPreviewCommand()
2031 return wxThePrintSetupData
->GetPrintPreviewCommand();
2034 char *wxGetPrinterOptions()
2036 return wxThePrintSetupData
->GetPrinterOptions();
2039 char *wxGetPrinterFile()
2041 return wxThePrintSetupData
->GetPrinterFile();
2044 int wxGetPrinterOrientation()
2046 return wxThePrintSetupData
->GetPrinterOrientation();
2049 void wxGetPrinterScaling(double* x
, double* y
)
2051 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2054 void wxGetPrinterTranslation(long *x
, long *y
)
2056 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2059 int wxGetPrinterMode()
2061 return wxThePrintSetupData
->GetPrinterMode();
2064 char *wxGetAFMPath()
2066 return wxThePrintSetupData
->GetAFMPath();
2073 wxPrintSetupData::wxPrintSetupData()
2075 printerCommand
= (char *) NULL
;
2076 previewCommand
= (char *) NULL
;
2077 printerFlags
= (char *) NULL
;
2078 printerOrient
= PS_PORTRAIT
;
2079 printerScaleX
= (double)1.0;
2080 printerScaleY
= (double)1.0;
2081 printerTranslateX
= 0;
2082 printerTranslateY
= 0;
2083 // 1 = Preview, 2 = print to file, 3 = send to printer
2085 afmPath
= (char *) NULL
;
2086 paperName
= (char *) NULL
;
2088 printerFile
= (char *) NULL
;
2091 wxPrintSetupData::~wxPrintSetupData()
2094 delete[] printerCommand
;
2096 delete[] previewCommand
;
2098 delete[] printerFlags
;
2104 delete[] printerFile
;
2107 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2109 if (cmd
== printerCommand
)
2113 delete[] printerCommand
;
2115 printerCommand
= copystring(cmd
);
2117 printerCommand
= (char *) NULL
;
2120 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2122 if (cmd
== previewCommand
)
2126 delete[] previewCommand
;
2128 previewCommand
= copystring(cmd
);
2130 previewCommand
= (char *) NULL
;
2133 void wxPrintSetupData::SetPaperName(const char *name
)
2135 if (name
== paperName
)
2141 paperName
= copystring(name
);
2143 paperName
= (char *) NULL
;
2146 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2148 if (printerFlags
== flags
)
2152 delete[] printerFlags
;
2154 printerFlags
= copystring(flags
);
2156 printerFlags
= (char *) NULL
;
2159 void wxPrintSetupData::SetPrinterFile(const char *f
)
2161 if (f
== printerFile
)
2165 delete[] printerFile
;
2167 printerFile
= copystring(f
);
2169 printerFile
= (char *) NULL
;
2172 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2174 printerOrient
= orient
;
2177 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2183 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2185 printerTranslateX
= x
;
2186 printerTranslateY
= y
;
2189 // 1 = Preview, 2 = print to file, 3 = send to printer
2190 void wxPrintSetupData::SetPrinterMode(int mode
)
2195 void wxPrintSetupData::SetAFMPath(const char *f
)
2203 afmPath
= copystring(f
);
2205 afmPath
= (char *) NULL
;
2208 void wxPrintSetupData::SetColour(bool col
)
2213 // Get current values
2214 char *wxPrintSetupData::GetPrinterCommand()
2216 return printerCommand
;
2219 char *wxPrintSetupData::GetPrintPreviewCommand()
2221 return previewCommand
;
2224 char *wxPrintSetupData::GetPrinterOptions()
2226 return printerFlags
;
2229 char *wxPrintSetupData::GetPrinterFile()
2234 char *wxPrintSetupData::GetPaperName()
2239 int wxPrintSetupData::GetPrinterOrientation()
2241 return printerOrient
;
2244 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2250 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2252 *x
= printerTranslateX
;
2253 *y
= printerTranslateY
;
2256 int wxPrintSetupData::GetPrinterMode()
2261 char *wxPrintSetupData::GetAFMPath()
2266 bool wxPrintSetupData::GetColour()
2271 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2273 SetPrinterCommand(data
.GetPrinterCommand());
2274 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2275 SetPrinterOptions(data
.GetPrinterOptions());
2277 data
.GetPrinterTranslation(&x
, &y
);
2278 SetPrinterTranslation(x
, y
);
2281 data
.GetPrinterScaling(&x1
, &y1
);
2282 SetPrinterScaling(x1
, y1
);
2284 SetPrinterOrientation(data
.GetPrinterOrientation());
2285 SetPrinterMode(data
.GetPrinterMode());
2286 SetAFMPath(data
.GetAFMPath());
2287 SetPaperName(data
.GetPaperName());
2288 SetColour(data
.GetColour());
2291 void wxInitializePrintSetupData(bool init
)
2295 wxThePrintSetupData
= new wxPrintSetupData
;
2297 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2298 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2299 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2300 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2302 // Could have a .ini file to read in some defaults
2303 // - and/or use environment variables, e.g. WXWIN
2305 wxThePrintSetupData
->SetPrinterCommand("print");
2306 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2307 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2310 wxThePrintSetupData
->SetPrinterCommand("print");
2311 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2312 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2314 #if !defined(__VMS__) && !defined(__WXMSW__)
2315 wxThePrintSetupData
->SetPrinterCommand("lpr");
2316 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2317 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2322 if (wxThePrintSetupData
)
2323 delete wxThePrintSetupData
;
2324 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2329 * Paper size database for PostScript
2332 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2338 pageName
= copystring(name
);
2341 wxPrintPaperType::~wxPrintPaperType()
2347 * Print paper database for PostScript
2350 #if !USE_SHARED_LIBRARIES
2351 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
2354 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2356 DeleteContents(TRUE
);
2359 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2363 void wxPrintPaperDatabase::CreateDatabase()
2365 // Need correct values for page size in pixels.
2366 // Each unit is one 'point' = 1/72 of an inch.
2367 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2368 // in wxPostScriptDC code, so we can start from top left.
2369 // So access this database and translate by appropriate number
2370 // of points for this paper size. OR IS IT OK ALREADY?
2371 // Can't remember where the PostScript origin is by default.
2372 // Heck, someone will know how to make it hunky-dory...
2375 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2376 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2377 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2378 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2383 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 210*4, 297*4 );
2384 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 297*4, 420*4 );
2385 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 216*4, 279*4 );
2386 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 216*4, 356*4 );
2390 void wxPrintPaperDatabase::ClearDatabase()
2395 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2397 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2400 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2402 wxNode
*node
= Find(name
);
2404 return (wxPrintPaperType
*)node
->Data();
2406 return (wxPrintPaperType
*) NULL
;
2410 * Initialization/cleanup module
2413 bool wxPostScriptModule::OnInit()
2415 wxInitializePrintSetupData();
2416 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2417 wxThePrintPaperDatabase
->CreateDatabase();
2422 void wxPostScriptModule::OnExit()
2424 wxInitializePrintSetupData(FALSE
);
2425 delete wxThePrintPaperDatabase
;
2426 wxThePrintPaperDatabase
= NULL
;