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