1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPostScriptDC implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "postscrp.h"
14 #pragma implementation
18 // For compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
32 #include "wx/postscrp.h"
34 #include "wx/filedlg.h"
35 #include "wx/msgdlg.h"
37 #include "wx/button.h"
38 #include "wx/radiobox.h"
39 #include "wx/textctrl.h"
40 #include "wx/stattext.h"
45 #include "wx/dcmemory.h"
48 #include "wx/msw/private.h"
71 #include "gdk/gdkx.h" // GDK_DISPLAY
72 #include "gdk/gdkprivate.h" // XImage
74 #include <X11/Xutil.h>
80 #include <X11/Xutil.h>
103 // Declarations local to this file
104 #define YSCALE(y) (m_yOrigin / m_scaleFactor - (y))
106 // Determine the Default Postscript Previewer
107 // available on the platform
108 #if defined(__SUN__) && defined(__XVIEW__)
109 // OpenWindow/NeWS's Postscript Previewer
110 # define PS_VIEWER_PROG "pageview"
111 #elif defined(__VMS__)
112 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
113 #elif defined(__SGI__)
114 // SGI's Display Postscript Previewer
115 //# define PS_VIEWER_PROG "dps"
116 # define PS_VIEWER_PROG "xpsview"
117 #elif defined(__X__) || defined(__WXGTK__)
118 // Front-end to ghostscript
119 # define PS_VIEWER_PROG "ghostview"
121 // Windows ghostscript/ghostview
122 # define PS_VIEWER_PROG NULL
125 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
127 // these should move into wxPostscriptDC:
128 double UnderlinePosition
= 0.0F
;
129 double UnderlineThickness
= 0.0F
;
131 #define _MAXPATHLEN 500
133 /* See "wxspline.inc" and "xfspline.inc" */
134 #if wxUSE_XFIG_SPLINE_CODE
135 static const char *wxPostScriptHeaderSpline
= " \
136 /DrawSplineSection {\n\
143 /xa x1 x2 x1 sub 0.666667 mul add def\n\
144 /ya y1 y2 y1 sub 0.666667 mul add def\n\
145 /xb x3 x2 x3 sub 0.666667 mul add def\n\
146 /yb y3 y2 y3 sub 0.666667 mul add def\n\
148 xa ya xb yb x3 y3 curveto\n\
152 // No extra PS header for this spline implementation.
153 static const char *wxPostScriptHeaderSpline
= (char *) NULL
;
155 #endif /* wxUSE_XFIG_SPLINE_CODE */
158 // VMS has a bug in the ofstream class.
159 // the buffering doesn't work correctly. therefore
160 // we will allocate (temporarily) a very big buffer (1MB), so
161 // that a buffer overflow will not occur.
163 #define VMS_BUFSIZ (1024L*1024L)
164 static char *fileBuffer
= NULL
;
167 #if !USE_SHARED_LIBRARY
168 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
169 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
170 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
171 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
172 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
175 wxPostScriptDC::wxPostScriptDC ()
177 // m_yOrigin = 792; // For EPS output
178 m_yOrigin
= 842; // For A4 output
186 m_pstream
= (ofstream
*) NULL
;
189 // Can only send to file in Windows
190 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
194 m_currentGreen
= 255;
198 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
200 Create(file
, interactive
, parent
);
203 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
205 m_isInteractive
= interactive
;
207 m_yOrigin
= 792; // For EPS output
208 // m_yOrigin = 842; // For A4 output
216 m_pstream
= (ofstream
*) NULL
;
219 // Can only send to file in Windows
220 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
225 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
231 m_currentGreen
= 255;
239 wxPostScriptDC::~wxPostScriptDC ()
245 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
247 wxPostScriptPrintDialog
dialog (parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
248 m_ok
= (dialog
.ShowModal () == wxID_OK
) ;
253 if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
|| wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
257 wxThePrintSetupData
->SetPrinterFile("preview");
259 // For PS_PRINTER action this depends on a Unix-style print spooler
260 // since the wx_printer_file can be destroyed during a session
261 // @@@ TODO: a Windows-style answer for non-Unix
263 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
265 strcpy (tmp
, "/tmp/preview_");
266 strcat (tmp
, userId
);
267 wxThePrintSetupData
->SetPrinterFile(tmp
);
270 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
271 strcat (tmp2
, ".ps");
272 wxThePrintSetupData
->SetPrinterFile(tmp2
);
275 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
277 char *file
= wxSaveFileSelector (_("PostScript"), "ps");
283 wxThePrintSetupData
->SetPrinterFile(file
);
291 void wxPostScriptDC::SetClippingRegion (long cx
, long cy
, long cw
, long ch
)
299 *m_pstream
<< "gsave\n";
300 *m_pstream
<< "newpath\n";
301 *m_pstream
<< cx
<< " " << YSCALE (cy
) << " moveto\n";
302 *m_pstream
<< (cx
+ cw
) << " " << YSCALE (cy
) << " lineto\n";
303 *m_pstream
<< cx
+ cw
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
304 *m_pstream
<< cx
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
305 *m_pstream
<< "closepath clip newpath\n";
308 void wxPostScriptDC::DestroyClippingRegion ()
315 *m_pstream
<< "grestore\n";
319 void wxPostScriptDC::Clear ()
323 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
), int WXUNUSED(style
))
327 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
332 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
336 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
342 *m_pstream
<< "newpath\n";
343 *m_pstream
<< x1
<< " " << YSCALE (y1
) << " moveto\n";
344 *m_pstream
<< x2
<< " " << YSCALE (y2
) << " lineto\n";
345 *m_pstream
<< "stroke\n";
346 CalcBoundingBox (x1
, (long)YSCALE (y1
));
347 CalcBoundingBox (x2
, (long)YSCALE (y2
));
350 #define RAD2DEG 57.29577951308
352 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
359 long radius
= (long) sqrt((double) (dx
*dx
+dy
*dy
));
360 double alpha1
, alpha2
;
362 if (x1
== x2
&& y1
== y2
) {
365 } else if (radius
== 0.0) {
366 alpha1
= alpha2
= 0.0;
368 alpha1
= (x1
- xc
== 0) ?
369 (y1
- yc
< 0) ? 90.0 : -90.0 :
370 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
371 alpha2
= (x2
- xc
== 0) ?
372 (y2
- yc
< 0) ? 90.0 : -90.0 :
373 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
375 while (alpha1
<= 0) alpha1
+= 360;
376 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
377 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
378 while (alpha2
> 360) alpha2
-= 360;
380 if (m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
) {
382 *m_pstream
<< "newpath\n"
383 << xc
<< " " << YSCALE(yc
) << " "
384 << radius
<< " " << radius
<< " "
385 << alpha1
<< " " << alpha2
<< " ellipse\n"
386 << xc
<< " " << YSCALE(yc
) << " lineto\n"
390 if (m_pen
.Ok() && m_pen
.GetStyle() != wxTRANSPARENT
) {
392 *m_pstream
<< "newpath\n"
393 << xc
<< " " << YSCALE(yc
) << " "
394 << radius
<< " " << radius
<< " "
395 << alpha1
<< " " << alpha2
<< " ellipse\n"
398 CalcBoundingBox(x1
, (long)YSCALE(y1
));
399 CalcBoundingBox(x2
, (long)YSCALE(y2
));
402 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
407 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
408 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
413 DrawEllipse(x
,y
,w
,h
);
417 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
423 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
424 w
/2 << " " << (h
/2) << " " <<
425 int(sa
) <<" "<< int(ea
)<<" true ellipticarc\n";
427 CalcBoundingBox (x
, (long)YSCALE (y
));
428 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
430 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
436 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
437 (w
/2) << " " << (h
/2) << " " <<
438 int(sa
) <<" "<< int(ea
)<<" false ellipticarc\n";
440 CalcBoundingBox (x
, (long)YSCALE (y
));
441 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
445 void wxPostScriptDC::DrawPoint (long x
, long y
)
451 *m_pstream
<< "newpath\n";
452 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
453 *m_pstream
<< (x
+1) << " " << YSCALE (y
) << " lineto\n";
454 *m_pstream
<< "stroke\n";
455 CalcBoundingBox (x
, (long)YSCALE (y
));
458 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
464 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
467 *m_pstream
<< "newpath\n";
469 long xx
= points
[0].x
+ xoffset
;
470 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
471 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
472 CalcBoundingBox (xx
, yy
);
475 for (i
= 1; i
< n
; i
++)
477 xx
= points
[i
].x
+ xoffset
;
478 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
479 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
480 CalcBoundingBox (xx
, yy
);
482 *m_pstream
<< "fill\n";
485 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
488 *m_pstream
<< "newpath\n";
490 long xx
= points
[0].x
+ xoffset
;
491 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
492 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
493 CalcBoundingBox (xx
, yy
);
496 for (i
= 1; i
< n
; i
++)
498 xx
= points
[i
].x
+ xoffset
;
499 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
500 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
501 CalcBoundingBox (xx
, yy
);
505 xx
= points
[0].x
+ xoffset
;
506 yy
= (long) YSCALE (points
[0].y
+ yoffset
);
507 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
510 *m_pstream
<< "stroke\n";
515 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
524 *m_pstream
<< "newpath\n";
526 long xx
= points
[0].x
+ xoffset
;
527 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
528 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
529 CalcBoundingBox (xx
, yy
);
532 for (i
= 1; i
< n
; i
++)
534 xx
= points
[i
].x
+ xoffset
;
535 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
536 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
537 CalcBoundingBox (xx
, yy
);
539 *m_pstream
<< "stroke\n";
543 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
547 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
551 *m_pstream
<< "newpath\n";
552 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
553 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
554 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
555 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
556 *m_pstream
<< "closepath\n";
557 *m_pstream
<< "fill\n";
559 CalcBoundingBox (x
, (long)YSCALE (y
));
560 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
562 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
566 *m_pstream
<< "newpath\n";
567 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
568 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
569 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
570 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
571 *m_pstream
<< "closepath\n";
572 *m_pstream
<< "stroke\n";
574 CalcBoundingBox (x
, (long)YSCALE (y
));
575 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
579 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
586 // Now, a negative radius is interpreted to mean
587 // 'the proportion of the smallest X or Y dimension'
588 double smallest
= 0.0;
593 radius
= (-radius
* smallest
);
596 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
599 // Draw rectangle anticlockwise
600 *m_pstream
<< "newpath\n";
601 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
603 *m_pstream
<< x
<< " " << YSCALE (y
+ radius
) << " moveto\n";
605 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
606 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
608 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
609 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
611 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
613 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
615 *m_pstream
<< "closepath\n";
617 *m_pstream
<< "fill\n";
619 CalcBoundingBox (x
, (long)YSCALE (y
));
620 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
622 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
625 // Draw rectangle anticlockwise
626 *m_pstream
<< "newpath\n";
627 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
629 *m_pstream
<< x
<< " " << YSCALE (y
+ height
- radius
) << " lineto\n";
631 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
632 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
634 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
635 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
637 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
639 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
641 *m_pstream
<< "closepath\n";
643 *m_pstream
<< "stroke\n";
645 CalcBoundingBox (x
, (long)YSCALE (y
));
646 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
650 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
654 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
658 *m_pstream
<< "newpath\n";
659 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
660 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
661 *m_pstream
<< "fill\n";
663 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
664 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
666 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
670 *m_pstream
<< "newpath\n";
671 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
672 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
673 *m_pstream
<< "stroke\n";
675 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
676 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
680 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
682 #if defined(__X__) || defined(__WXGTK__)
684 memDC
.SelectObject(icon
);
685 Blit(x
, y
, icon
.GetWidth(), icon
.GetHeight(), &memDC
, 0, 0);
689 void wxPostScriptDC::SetFont (const wxFont
& the_font
)
694 if (m_font
== the_font
)
704 const char *style
= "";
705 int Style
= m_font
.GetStyle ();
706 int Weight
= m_font
.GetWeight ();
708 switch (m_font
.GetFamily ())
718 // name = "/Times-Roman";
719 name
= "/Times"; // Altered by EDZ
722 name
= "/Zapf-Chancery-MediumItalic";
727 case wxDEFAULT
: // Sans Serif Font
728 name
= "/LucidaSans";
731 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
733 if (m_font
.GetFamily () == wxROMAN
)
738 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
741 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
743 if (m_font
.GetFamily () == wxROMAN
)
748 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
750 if (m_font
.GetFamily () == wxROMAN
)
751 style
= "-BoldItalic";
753 style
= "-BoldOblique";
755 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
757 if (m_font
.GetFamily () == wxROMAN
)
762 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
764 if (m_font
.GetFamily () == wxROMAN
)
765 style
= "-BoldItalic";
767 style
= "-BoldOblique";
774 *m_pstream
<< buf
<< " findfont\n";
775 *m_pstream
<< (m_font
.GetPointSize() * m_scaleFactor
) << " scalefont setfont\n";
778 void wxPostScriptDC::SetPen (const wxPen
& pen
)
783 int oldStyle
= m_pen
.GetStyle();
791 *m_pstream
<< m_pen
.GetWidth () << " setlinewidth\n";
793 // Line style - WRONG: 2nd arg is OFFSET
795 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
796 operator correctly. You should look-up this in the Red Book: the 2nd parame-
797 ter is not number of values in the array of the first one, but an offset
798 into this description of the pattern. I mean a real *offset* not index
799 into array. I.e. If the command is [3 4] 1 setdash is used, then there
800 will be first black line *2* units long, then space 4 units, then the
801 pattern of *3* units black, 4 units space will be repeated.
803 static const char *dotted
= "[2 5] 2";
804 static const char *short_dashed
= "[4 4] 2";
805 static const char *long_dashed
= "[4 8] 2";
806 static const char *dotted_dashed
= "[6 6 2 6] 4";
808 const char *psdash
= (char *) NULL
;
809 switch (m_pen
.GetStyle ())
815 psdash
= short_dashed
;
818 psdash
= long_dashed
;
821 psdash
= dotted_dashed
;
829 if (oldStyle
!= m_pen
.GetStyle())
830 *m_pstream
<< psdash
<< " setdash\n";
833 unsigned char red
= m_pen
.GetColour ().Red ();
834 unsigned char blue
= m_pen
.GetColour ().Blue ();
835 unsigned char green
= m_pen
.GetColour ().Green ();
839 // Anything not white is black
840 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
841 && green
== (unsigned char) 255))
843 red
= (unsigned char) 0;
844 green
= (unsigned char) 0;
845 blue
= (unsigned char) 0;
849 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
851 long redPS
= (long) (((int) red
) / 255.0);
852 long bluePS
= (long) (((int) blue
) / 255.0);
853 long greenPS
= (long) (((int) green
) / 255.0);
855 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
858 m_currentBlue
= blue
;
859 m_currentGreen
= green
;
863 void wxPostScriptDC::SetBrush (const wxBrush
& brush
)
874 unsigned char red
= m_brush
.GetColour ().Red ();
875 unsigned char blue
= m_brush
.GetColour ().Blue ();
876 unsigned char green
= m_brush
.GetColour ().Green ();
880 // Anything not black is white
881 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
882 && green
== (unsigned char) 0))
884 red
= (unsigned char) 255;
885 green
= (unsigned char) 255;
886 blue
= (unsigned char) 255;
890 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
892 long redPS
= (long) (((int) red
) / 255.0);
893 long bluePS
= (long) (((int) blue
) / 255.0);
894 long greenPS
= (long) (((int) green
) / 255.0);
895 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
897 m_currentBlue
= blue
;
898 m_currentGreen
= green
;
902 void wxPostScriptDC::DrawText (const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
))
907 // TODO: SetFont checks for identity so this will always be a NULL operation
911 if (m_textForegroundColour
.Ok ())
913 unsigned char red
= m_textForegroundColour
.Red ();
914 unsigned char blue
= m_textForegroundColour
.Blue ();
915 unsigned char green
= m_textForegroundColour
.Green ();
919 // Anything not white is black
920 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
921 && green
== (unsigned char) 255))
923 red
= (unsigned char) 0;
924 green
= (unsigned char) 0;
925 blue
= (unsigned char) 0;
928 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
930 long redPS
= (long) (((int) red
) / 255.0);
931 long bluePS
= (long) (((int) blue
) / 255.0);
932 long greenPS
= (long) (((int) green
) / 255.0);
933 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
936 m_currentBlue
= blue
;
937 m_currentGreen
= green
;
943 size
= m_font
.GetPointSize ();
945 *m_pstream
<< x
<< " " << YSCALE (y
+ size
) << " moveto\n";
947 // *m_pstream << "(" << text << ")" << " show\n";
949 int len
= strlen ((char *)(const char *)text
);
951 for (i
= 0; i
< len
; i
++)
955 if (ch == ')' || ch == '(' || ch == '\\')
959 int c
= (unsigned char) text
[i
];
960 if ( c
== ')' || c
== '(' || c
== '\\')
962 *m_pstream
<< "\\" << (char) c
;
966 // Cope with character codes > 127
968 sprintf(tmp
, "\\%o", c
);
972 *m_pstream
<< (char) c
;
975 *m_pstream
<< ")" << " show\n";
977 if (m_font
.GetUnderlined())
980 GetTextExtent(text
, &w
, &h
);
981 *m_pstream
<< "gsave " << x
<< " " << YSCALE (y
+ size
- UnderlinePosition
)
983 << UnderlineThickness
<< " setlinewidth "
984 << (x
+ w
) << " " << YSCALE (y
+ size
- UnderlinePosition
)
985 << " lineto stroke grestore\n";
988 CalcBoundingBox (x
, (long)YSCALE (y
+ size
));
989 CalcBoundingBox (x
+ size
* strlen ((char *)(const char *)text
), (long)YSCALE (y
));
993 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
995 m_backgroundBrush
= brush
;
998 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1002 static const char *wxPostScriptHeaderEllipse
= "\
1003 /ellipsedict 8 dict def\n\
1004 ellipsedict /mtrx matrix put\n\
1006 { ellipsedict begin\n\
1007 /endangle exch def\n\
1008 /startangle exch def\n\
1013 /savematrix mtrx currentmatrix def\n\
1016 0 0 1 startangle endangle arc\n\
1017 savematrix setmatrix\n\
1022 static const char *wxPostScriptHeaderEllipticArc
= "\
1023 /ellipticarcdict 8 dict def\n\
1024 ellipticarcdict /mtrx matrix put\n\
1026 { ellipticarcdict begin\n\
1027 /do_fill exch def\n\
1028 /endangle exch def\n\
1029 /startangle exch def\n\
1034 /savematrix mtrx currentmatrix def\n\
1037 do_fill { 0 0 moveto } if\n\
1038 0 0 1 startangle endangle arc\n\
1039 savematrix setmatrix\n\
1040 do_fill { fill }{ stroke } ifelse\n\
1044 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1046 if (m_filename
== "")
1049 m_filename
= "wxtmp.ps";
1051 m_filename
= wxGetTempFileName("ps");
1053 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1057 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1062 m_pstream
= new ofstream
;
1063 if(fileBuffer
) delete[] fileBuffer
;
1064 fileBuffer
= new char[VMS_BUFSIZ
];
1065 m_pstream
->setbuf(fileBuffer
,VMS_BUFSIZ
);
1066 m_pstream
->open(wxThePrintSetupData
->GetPrinterFile());
1068 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1070 if (!m_pstream
|| !m_pstream
->good())
1072 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1078 SetBrush (*wxBLACK_BRUSH
);
1079 SetPen (*wxBLACK_PEN
);
1087 void wxPostScriptDC::EndDoc ()
1089 static char wxPostScriptHeaderReencodeISO1
[] =
1090 "\n/reencodeISO {\n"
1091 "dup dup findfont dup length dict begin\n"
1092 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
1093 "/Encoding ISOLatin1Encoding def\n"
1094 "currentdict end definefont\n"
1096 "/ISOLatin1Encoding [\n"
1097 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1098 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1099 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1100 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1101 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
1102 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
1103 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
1104 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
1105 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
1106 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
1107 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
1108 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1109 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1110 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
1111 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
1113 static char wxPostScriptHeaderReencodeISO2
[] =
1114 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
1115 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
1116 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
1117 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
1118 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
1119 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
1120 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
1121 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
1122 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
1123 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
1124 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
1125 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
1126 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
1127 "/yacute/thorn/ydieresis\n"
1135 *m_pstream
<< "grestore\n";
1138 // Will reuse m_pstream for header
1140 // see the definition of fileBuffer for explanation
1141 m_pstream
->close(); // steve, 05.09.94
1142 if(fileBuffer
) delete[] fileBuffer
;
1147 m_pstream
= (ofstream
*) NULL
;
1153 char *header_file
= "header.ps";
1155 char *header_file
= wxGetTempFileName("ps");
1157 m_pstream
= new ofstream (header_file
);
1159 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1160 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1161 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1162 // time_t when; time (&when);
1163 // *m_pstream << "%%CreationDate: " << ctime (&when);
1164 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1166 // User Id information
1168 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1170 *m_pstream
<< "%%For: " << (char *)userID
;
1172 if (wxGetUserName(userName
, sizeof(userName
)))
1173 *m_pstream
<< " (" << (char *)userName
<< ")";
1176 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1178 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1181 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1183 long wx_printer_translate_x
, wx_printer_translate_y
;
1184 double wx_printer_scale_x
, wx_printer_scale_y
;
1185 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1186 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1188 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1190 *m_pstream
<< "%%Orientation: Landscape\n";
1194 *m_pstream
<< "%%Orientation: Portrait\n";
1197 // Compute the bounding box. Note that it is in the default user
1198 // coordinate system, thus we have to convert the values.
1199 long llx
= (long) ((m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1200 long lly
= (long) ((m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1201 long urx
= (long) ((m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1202 long ury
= (long) ((m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1205 // If we're landscape, our sense of "x" and "y" is reversed.
1206 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1209 tmp
= llx
; llx
= lly
; lly
= tmp
;
1210 tmp
= urx
; urx
= ury
; ury
= tmp
;
1212 // We need either the two lines that follow, or we need to subtract
1213 // min_x from real_translate_y, which is commented out below.
1214 llx
= llx
- m_minX
*wx_printer_scale_y
;
1215 urx
= urx
- m_minX
*wx_printer_scale_y
;
1219 // The Adobe specifications call for integers; we round as to make
1220 // the bounding larger.
1221 *m_pstream
<< "%%BoundingBox: "
1222 << floor((double)llx
) << " " << floor((double)lly
) << " "
1223 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1224 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1225 *m_pstream
<< "%%EndComments\n\n";
1227 // To check the correctness of the bounding box, postscript commands
1228 // to draw a box corresponding to the bounding box are generated below.
1229 // But since we typically don't want to print such a box, the postscript
1230 // commands are generated within comments. These lines appear before any
1231 // adjustment of scale, rotation, or translation, and hence are in the
1232 // default user coordinates.
1233 *m_pstream
<< "% newpath\n";
1234 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1235 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1236 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1237 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1241 long real_translate_y
= wx_printer_translate_y
;
1242 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1244 real_translate_y
-= m_maxY
;
1245 // The following line can be used instead of the adjustment to
1246 // llx and urx above.
1247 // real_translate_y -= m_minX;
1248 *m_pstream
<< "90 rotate\n";
1251 /* Probably don't want this now we have it in EndPage, below.
1252 * We should rationalise the scaling code to one place. JACS, October 1995
1253 * Do we take the next 2 lines out or not?
1256 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1257 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1260 *m_pstream
<< "%%BeginProlog\n";
1261 *m_pstream
<< wxPostScriptHeaderEllipse
;
1262 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1263 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1264 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1266 if (wxPostScriptHeaderSpline
)
1267 *m_pstream
<< wxPostScriptHeaderSpline
;
1268 *m_pstream
<< "%%EndProlog\n";
1271 m_pstream
= (ofstream
*) NULL
;
1274 char *tmp_file
= "tmp.ps";
1276 char *tmp_file
= wxGetTempFileName("ps");
1279 // Paste header Before wx_printer_file
1280 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1281 wxRemoveFile (header_file
);
1282 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1283 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1285 #if defined(__X__) || defined(__WXGTK__)
1288 switch (wxThePrintSetupData
->GetPrinterMode()) {
1292 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1293 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1294 argv
[2] = (char *) NULL
;
1295 wxExecute (argv
, TRUE
);
1296 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1304 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1306 // !SM! If we simply assign to argv[1] here, if printer options
1307 // are blank, we get an annoying and confusing message from lpr.
1308 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1310 argv
[argc
++] = opts
;
1312 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1313 argv
[argc
++] = (char *) NULL
;
1314 wxExecute (argv
, TRUE
);
1315 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1326 void wxPostScriptDC::StartPage ()
1330 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1331 // *m_pstream << "matrix currentmatrix\n";
1333 // Added by Chris Breeze
1335 // Each page starts with an "initgraphics" which resets the
1336 // transformation and so we need to reset the origin
1337 // (and rotate the page for landscape printing)
1338 m_scaleFactor
= 1.0;
1339 m_logicalOriginX
= 0;
1340 m_logicalOriginY
= 0;
1343 long translate_x
, translate_y
;
1344 double scale_x
, scale_y
;
1345 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1346 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1348 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1350 translate_y
-= GetYOrigin();
1351 *m_pstream
<< "90 rotate\n";
1354 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1355 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1358 void wxPostScriptDC::EndPage ()
1362 *m_pstream
<< "showpage\n";
1364 // Removed by Chris Breeze
1366 *m_pstream
<< "setmatrix\n";
1368 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1370 long wx_printer_translate_x
, wx_printer_translate_y
;
1371 double wx_printer_scale_x
, wx_printer_scale_y
;
1372 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1373 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1375 // Compute the bounding box. Note that it is in the default user
1376 // coordinate system, thus we have to convert the values.
1377 long llx
= (m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1378 long lly
= (m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1379 long urx
= (m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1380 long ury
= (m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1382 // If we're landscape, our sense of "x" and "y" is reversed.
1383 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1386 tmp
= llx
; llx
= lly
; lly
= tmp
;
1387 tmp
= urx
; urx
= ury
; ury
= tmp
;
1389 // We need either the two lines that follow, or we need to subtract
1390 // m_minX from real_translate_y, which is commented out below.
1391 llx
= llx
- m_minX
*wx_printer_scale_y
;
1392 urx
= urx
- m_minX
*wx_printer_scale_y
;
1396 long real_translate_y
= wx_printer_translate_y
;
1397 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1399 real_translate_y
-= m_maxY
;
1400 // The following line can be used instead of the adjustment to
1401 // llx and urx above.
1402 // real_translate_y -= m_minX;
1403 *m_pstream
<< "90 rotate\n";
1406 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1407 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1411 bool wxPostScriptDC::
1412 Blit (long xdest
, long ydest
, long fwidth
, long fheight
,
1413 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(rop
), bool WXUNUSED(useMask
))
1415 long width
, height
, x
, y
;
1417 #if !defined(__X__) && !defined(__WXGTK__)
1421 if (!source
->IsKindOf(CLASSINFO(wxPaintDC
))) return FALSE
;
1423 width
= (long)floor((double)fwidth
);
1424 height
= (long)floor((double)fheight
);
1425 x
= (long)floor((double)xsrc
);
1426 y
= (long)floor((double)ysrc
);
1428 /* PostScript setup: */
1429 *m_pstream
<< "gsave\n";
1430 *m_pstream
<< xdest
<< " " << YSCALE(ydest
+ fheight
) << " translate\n";
1431 *m_pstream
<< fwidth
<< " " << fheight
<< " scale\n";
1432 *m_pstream
<< "/DataString " << width
<< " string def\n";
1433 *m_pstream
<< width
<< " " << height
<< " 8 [ ";
1434 *m_pstream
<< width
<< " 0 0 " << (-height
) << " 0 " << height
;
1435 *m_pstream
<< " ]\n{\n";
1436 *m_pstream
<< " currentfile DataString readhexstring pop\n";
1437 *m_pstream
<< "} bind image\n";
1439 #if defined(__X__) || defined(__WXGTK__)
1441 /* Output data as hex digits: */
1451 cm
= ((GdkColormapPrivate
*)gdk_colormap_get_system())->xcolormap
;
1452 GdkWindow
*gwin
= ((wxClientDC
*)source
)->GetWindow();
1453 image
= XGetImage(d
, ((GdkWindowPrivate
*)gwin
)->xwindow
, x
, y
, width
, height
, AllPlanes
, ZPixmap
);
1458 // TODO. for now, use global display
1459 // d = source->display;
1460 d
= (Display
*) wxGetDisplay();
1462 d
= (Display
*) wxGetDisplay();
1465 cm
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) d
);
1466 // TODO - implement GetPixmap() and uncomment this line
1467 // image = XGetImage(d, source->GetPixmap(), x, y, width, height, AllPlanes, ZPixmap);
1474 #define CM_CACHE_SIZE 256
1475 unsigned long cachesrc
[CM_CACHE_SIZE
];
1476 int cachedest
[CM_CACHE_SIZE
], cache_pos
= 0, all_cache
= FALSE
;
1478 for (j
= 0; j
< height
; j
++) {
1479 for (i
= 0; i
< width
; i
++) {
1481 unsigned long spixel
;
1483 const unsigned short MAX_COLOR
= 0xFFFF;
1485 spixel
= XGetPixel(image
, i
, j
);
1487 for (k
= cache_pos
; k
--; )
1488 if (cachesrc
[k
] == spixel
) {
1489 pixel
= cachedest
[k
];
1493 for (k
= CM_CACHE_SIZE
; k
-- > cache_pos
; )
1494 if (cachesrc
[k
] == spixel
) {
1495 pixel
= cachedest
[k
];
1499 cachesrc
[cache_pos
] = xcol
.pixel
= spixel
;
1500 XQueryColor(d
, cm
, &xcol
);
1504 r
= (long)((double)(xcol
.red
) / MAX_COLOR
);
1505 g
= (long)((double)(xcol
.green
) / MAX_COLOR
);
1506 b
= (long)((double)(xcol
.blue
) / MAX_COLOR
);
1508 pixel
= (int)(255 * sqrt(((r
* r
) + (g
* g
) + (b
* b
)) / 3));
1510 cachedest
[cache_pos
] = pixel
;
1512 if (++cache_pos
>= CM_CACHE_SIZE
) {
1520 h
= (pixel
>> 4) & 0xF;
1526 s
[0] = 'a' + (h
- 10);
1530 s
[1] = 'a' + (l
- 10);
1537 XDestroyImage(image
);
1540 *m_pstream
<< "grestore\n";
1542 CalcBoundingBox(xdest
, (long)YSCALE(ydest
));
1543 CalcBoundingBox(xdest
+ fwidth
, (long)YSCALE(ydest
+ fheight
));
1548 long wxPostScriptDC::GetCharHeight ()
1551 return m_font
.GetPointSize ();
1556 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1557 long *descent
, long *externalLeading
, wxFont
*theFont
,
1558 bool WXUNUSED(use16
))
1560 wxFont
*fontToUse
= theFont
;
1562 fontToUse
= (wxFont
*) &m_font
;
1566 #if !USE_AFM_FOR_POSTSCRIPT
1567 // Provide a VERY rough estimate (avoid using it)
1568 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1569 // font such as Courier (aka wxMODERN)
1573 height
= fontToUse
->GetPointSize();
1575 *x
= strlen (string
) * height
* 72 / 120;
1576 *y
= (long) (height
* 1.32); // allow for descender
1580 if (externalLeading
)
1581 *externalLeading
= 0;
1583 // +++++ start of contributed code +++++
1585 // ************************************************************
1586 // method for calculating string widths in postscript:
1587 // read in the AFM (adobe font metrics) file for the
1588 // actual font, parse it and extract the character widths
1589 // and also the descender. this may be improved, but for now
1590 // it works well. the AFM file is only read in if the
1591 // font is changed. this may be chached in the future.
1592 // calls to GetTextExtent with the font unchanged are rather
1595 // for each font and style used there is an AFM file necessary.
1596 // currently i have only files for the roman font family.
1597 // i try to get files for the other ones!
1599 // CAVE: the size of the string is currently always calculated
1600 // in 'points' (1/72 of an inch). this should later on be
1601 // changed to depend on the mapping mode.
1602 // CAVE: the path to the AFM files must be set before calling this
1603 // function. this is usually done by a call like the following:
1604 // wxSetAFMPath("d:\\wxw161\\afm\\");
1608 // wxPostScriptDC dc(NULL, TRUE);
1610 // wxSetAFMPath("d:\\wxw161\\afm\\");
1611 // dc.StartDoc("Test");
1614 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1615 // dc.GetTextExtent("Hallo",&w,&h);
1620 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1621 // created: 10.09.94
1622 // updated: 14.05.95
1624 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1625 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1626 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1628 // these static vars are for storing the state between calls
1629 static int lastFamily
= INT_MIN
;
1630 static int lastSize
= INT_MIN
;
1631 static int lastStyle
= INT_MIN
;
1632 static int lastWeight
= INT_MIN
;
1633 static int lastDescender
= INT_MIN
;
1634 static int lastWidths
[256]; // widths of the characters
1636 // get actual parameters
1637 const int Family
= fontToUse
->GetFamily();
1638 const int Size
= fontToUse
->GetPointSize();
1639 const int Style
= fontToUse
->GetStyle();
1640 const int Weight
= fontToUse
->GetWeight();
1642 // if we have another font, read the font-metrics
1643 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1644 // store actual values
1645 lastFamily
= Family
;
1648 lastWeight
= Weight
;
1650 // read in new font metrics **************************************
1652 // 1. construct filename ******************************************
1653 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1656 // Julian - we'll need to do this a different way now we've removed the
1657 // font directory system. Must find Stefan's original code.
1659 name
= wxTheFontNameDirectory
->GetAFMName(Family
, Weight
, Style
);
1663 // get the directory of the AFM files
1667 strcpy(afmName
,wxGetAFMPath());
1669 // 2. open and process the file **********************************
1671 // a short explanation of the AFM format:
1672 // we have for each character a line, which gives its size
1675 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1677 // that means, we have a character with ascii code 63, and width
1678 // (444/1000 * fontSize) points.
1679 // the other data is ignored for now!
1681 // when the font has changed, we read in the right AFM file and store the
1682 // character widths in an array, which is processed below (see point 3.).
1684 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1687 strcat(afmName
,name
);
1688 strcat(afmName
,".afm");
1689 FILE *afmFile
= fopen(afmName
,"r");
1691 wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1692 wxDebugMsg(" using approximate values\n");
1694 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1695 lastDescender
= -150; // dito.
1698 // init the widths array
1699 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1700 // some variables for holding parts of a line
1701 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1702 char upString
[30], utString
[30], encString
[50];
1705 // read in the file and parse it
1706 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1707 // A.) check for descender definition
1708 if(strncmp(line
,"Descender",9)==0){
1709 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1710 || (strcmp(descString
,"Descender")!=0)) {
1711 wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n",
1715 // JC 1.) check for UnderlinePosition
1716 else if(strncmp(line
,"UnderlinePosition",17)==0){
1717 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1718 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1719 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1723 // JC 2.) check for UnderlineThickness
1724 else if(strncmp(line
,"UnderlineThickness",18)==0){
1725 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1726 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1727 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1731 // JC 3.) check for EncodingScheme
1732 else if(strncmp(line
,"EncodingScheme",14)==0){
1733 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1734 || (strcmp(utString
,"EncodingScheme")!=0)) {
1735 wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1738 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1740 wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1741 afmName
,line
, encString
);
1744 // B.) check for char-width
1745 else if(strncmp(line
,"C ",2)==0){
1746 if(sscanf(line
,"%s%d%s%s%d",
1747 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1748 wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1750 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1751 strcmp(WXString
,"WX")!=0){
1752 wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1754 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1755 if(ascii
>=0 && ascii
<256){
1756 lastWidths
[ascii
] = cWidth
; // store width
1758 /* MATTHEW: this happens a lot; don't print an error */
1759 // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1762 // C.) ignore other entries.
1766 // hack to compute correct values for german 'Umlaute'
1767 // the correct way would be to map the character names
1768 // like 'adieresis' to corresp. positions of ISOEnc and read
1769 // these values from AFM files, too. Maybe later ...
1770 lastWidths
[196] = lastWidths
['A']; // Ä
1771 lastWidths
[228] = lastWidths
['a']; // ä
1772 lastWidths
[214] = lastWidths
['O']; // Ö
1773 lastWidths
[246] = lastWidths
['o']; // ö
1774 lastWidths
[220] = lastWidths
['U']; // Ü
1775 lastWidths
[252] = lastWidths
['u']; // ü
1776 lastWidths
[223] = lastWidths
[251]; // ß
1779 // JC: calculate UnderlineThickness/UnderlinePosition
1780 UnderlinePosition
= UnderlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1781 UnderlineThickness
= UnderlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1783 // 3. now the font metrics are read in, calc size *******************
1784 // this is done by adding the widths of the characters in the
1785 // string. they are given in 1/1000 of the size!
1788 long height
=Size
; // by default
1790 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1791 if(lastWidths
[*p
]== INT_MIN
){
1792 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1794 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1796 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1799 // add descender to height (it is usually a negative value)
1800 if(lastDescender
!=INT_MIN
){
1801 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1804 // return size values
1808 // return other parameters
1810 if(lastDescender
!=INT_MIN
){
1811 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1817 // currently no idea how to calculate this!
1818 // if (externalLeading) *externalLeading = 0;
1819 if (externalLeading
)
1820 *externalLeading
= 0;
1822 // ----- end of contributed code -----
1826 void wxPostScriptDC::DrawSpline( wxList
*points
)
1828 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1831 wxNode
*node
= points
->First();
1832 p
= (wxPoint
*)node
->Data();
1834 x1
= p
->x
; y1
= p
->y
;
1836 node
= node
->Next();
1837 p
= (wxPoint
*)node
->Data();
1839 x3
= a
= (double)(x1
+ c
) / 2;
1840 y3
= b
= (double)(y1
+ d
) / 2;
1842 *(GetStream()) << "newpath " << x1
<< " " << (GetYOrigin() - y1
) << " moveto " << x3
<< " " << (GetYOrigin() - y3
);
1843 *(GetStream()) << " lineto\n";
1844 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1845 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1847 while ((node
= node
->Next()) != NULL
)
1849 q
= (wxPoint
*)node
->Data();
1854 x3
= (double)(x2
+ c
) / 2;
1855 y3
= (double)(y2
+ d
) / 2;
1856 *(GetStream()) << x1
<< " " << (GetYOrigin() - y1
) << " " << x2
<< " " << (GetYOrigin() - y2
) << " ";
1857 *(GetStream()) << x3
<< " " << (GetYOrigin() - y3
) << " DrawSplineSection\n";
1859 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1860 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1863 * At this point, (x2,y2) and (c,d) are the position of the
1864 * next-to-last and last point respectively, in the point list
1866 *(GetStream()) << c
<< " " << (GetYOrigin() - d
) << " lineto stroke\n";
1869 long wxPostScriptDC::GetCharWidth ()
1871 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1872 return (long) (GetCharHeight() * 72.0 / 120.0);
1876 void wxPostScriptDC::SetMapMode (int mode
)
1878 m_mappingMode
= mode
;
1879 SetLogicalOrigin(0, 0);
1880 if(m_mappingMode
== MM_METRIC
)
1882 SetUserScale(72.0f
/ 25.4f
, 72.0f
/ 25.4f
);
1886 SetUserScale(1.0, 1.0);
1892 * Set the logical origin.
1893 * Actually we are setting the printer's origin and since
1894 * postscript transformations are cumulative we need to reset
1895 * the previous origin. We also need to allow for the user scale
1896 * factor (which affects printer coords but not logical)
1898 void wxPostScriptDC::SetLogicalOrigin(long x
, long y
)
1902 long xOffset
= (long) ((m_logicalOriginX
- x
) / m_scaleFactor
);
1903 long yOffset
= (long) ((y
- m_logicalOriginY
) / m_scaleFactor
);
1907 *m_pstream
<< xOffset
<< " " << yOffset
<< " translate\n";
1910 m_logicalOriginX
= x
;
1911 m_logicalOriginY
= y
;
1915 * Obsolete - now performed by SetUserScale() and SetLogicalOrigin()
1918 wxPostScriptDC::SetupCTM()
1923 * Set the user scale.
1924 * NB: Postscript transformations are cumulative and so we
1925 * need to take into account the current scale. Also, this
1926 * affects the logical origin
1928 void wxPostScriptDC::SetUserScale (double x
, double y
)
1930 // reset logical origin
1931 long xOrg
= m_logicalOriginX
;
1932 long yOrg
= m_logicalOriginY
;
1933 SetLogicalOrigin(0, 0);
1935 // set new scale factor
1939 factor
/= m_scaleFactor
;
1943 *m_pstream
<< factor
<< " " << factor
<< " scale\n";
1946 // set logical origin at new scale
1947 SetLogicalOrigin(xOrg
, yOrg
);
1952 m_scaleFactor
= m_userScaleX
;
1955 long wxPostScriptDC::DeviceToLogicalX (int x
) const
1960 long wxPostScriptDC::DeviceToLogicalXRel (int x
) const
1965 long wxPostScriptDC::DeviceToLogicalY (int y
) const
1970 long wxPostScriptDC::DeviceToLogicalYRel (int y
) const
1975 long wxPostScriptDC::LogicalToDeviceX (long x
) const
1980 long wxPostScriptDC::LogicalToDeviceXRel (long x
) const
1985 long wxPostScriptDC::LogicalToDeviceY (long y
) const
1990 long wxPostScriptDC::LogicalToDeviceYRel (long y
) const
1995 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1997 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1999 paperType
= _("A4 210 x 297 mm");
2001 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2003 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2006 *width
= paper
->widthPixels
;
2007 *height
= paper
->heightPixels
;
2016 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
2018 const char *paperType
= wxThePrintSetupData
->GetPaperName();
2020 paperType
= _("A4 210 x 297 mm");
2022 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2024 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2027 *width
= paper
->widthMM
;
2028 *height
= paper
->heightMM
;
2037 void wxPostScriptDC::CalcBoundingBox(long x
, long y
)
2039 long device_x
= (long) (x
- m_logicalOriginX
* m_scaleFactor
);
2040 long device_y
= (long) (y
+ m_logicalOriginY
* m_scaleFactor
);
2042 if (device_x
< m_minX
) m_minX
= device_x
;
2043 if (device_y
< m_minY
) m_minY
= device_y
;
2044 if (device_x
> m_maxX
) m_maxX
= device_x
;
2045 if (device_y
> m_maxY
) m_maxY
= device_y
;
2048 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2050 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2051 const wxPoint
& pos
, const wxSize
& size
, long style
):
2052 wxDialog(parent
, -1, title
, pos
, size
, style
)
2054 wxBeginBusyCursor();
2057 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2058 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2059 okBut
->SetDefault();
2063 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2064 (void) new wxStaticText( this, -1, _("Printer Command: "),
2066 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2067 wxPoint(100, yPos
), wxSize(100, -1) );
2069 (void) new wxStaticText( this, -1, _("Printer Options: "),
2070 wxPoint(210, yPos
) );
2071 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2072 wxPoint(305, yPos
), wxSize(150, -1) );
2077 wxString orientation
[2];
2078 orientation
[0] = _("Portrait");
2079 orientation
[1] = _("Landscape");
2081 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2083 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2085 // @@@ Configuration hook
2086 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
2087 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2089 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
2091 wxString print_modes
[3];
2092 print_modes
[0] = _("Send to Printer");
2093 print_modes
[1] = _("Print to File");
2094 print_modes
[2] = _("Preview Only");
2096 int features
= (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2097 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2098 wxPoint(150, yPos
), wxSize(-1,-1), features
, print_modes
, features
, 0);
2101 radio1
->Enable(0, FALSE
);
2102 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2103 radio1
->Enable(2, FALSE
);
2106 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2108 long wx_printer_translate_x
, wx_printer_translate_y
;
2109 double wx_printer_scale_x
, wx_printer_scale_y
;
2110 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2111 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2113 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2117 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2118 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2120 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2121 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2122 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2126 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2127 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
2128 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2130 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2131 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
2132 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2139 int wxPostScriptPrintDialog::ShowModal ()
2141 if ( wxDialog::ShowModal() == wxID_OK
)
2143 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2144 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2145 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2146 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2147 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2148 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2149 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2150 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2152 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
2153 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
2154 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
2155 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
2158 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2159 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2162 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
2165 switch ( radio1
->GetSelection() ) {
2166 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2167 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2168 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2175 // PostScript printer settings
2176 // RETAINED FOR BACKWARD COMPATIBILITY
2177 void wxSetPrinterCommand(const char *cmd
)
2179 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2182 void wxSetPrintPreviewCommand(const char *cmd
)
2184 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2187 void wxSetPrinterOptions(const char *flags
)
2189 wxThePrintSetupData
->SetPrinterOptions(flags
);
2192 void wxSetPrinterFile(const char *f
)
2194 wxThePrintSetupData
->SetPrinterFile(f
);
2197 void wxSetPrinterOrientation(int orient
)
2199 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2202 void wxSetPrinterScaling(double x
, double y
)
2204 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2207 void wxSetPrinterTranslation(long x
, long y
)
2209 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2212 // 1 = Preview, 2 = print to file, 3 = send to printer
2213 void wxSetPrinterMode(int mode
)
2215 wxThePrintSetupData
->SetPrinterMode(mode
);
2218 void wxSetAFMPath(const char *f
)
2220 wxThePrintSetupData
->SetAFMPath(f
);
2223 // Get current values
2224 char *wxGetPrinterCommand()
2226 return wxThePrintSetupData
->GetPrinterCommand();
2229 char *wxGetPrintPreviewCommand()
2231 return wxThePrintSetupData
->GetPrintPreviewCommand();
2234 char *wxGetPrinterOptions()
2236 return wxThePrintSetupData
->GetPrinterOptions();
2239 char *wxGetPrinterFile()
2241 return wxThePrintSetupData
->GetPrinterFile();
2244 int wxGetPrinterOrientation()
2246 return wxThePrintSetupData
->GetPrinterOrientation();
2249 void wxGetPrinterScaling(double* x
, double* y
)
2251 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2254 void wxGetPrinterTranslation(long *x
, long *y
)
2256 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2259 int wxGetPrinterMode()
2261 return wxThePrintSetupData
->GetPrinterMode();
2264 char *wxGetAFMPath()
2266 return wxThePrintSetupData
->GetAFMPath();
2273 wxPrintSetupData::wxPrintSetupData()
2275 printerCommand
= (char *) NULL
;
2276 previewCommand
= (char *) NULL
;
2277 printerFlags
= (char *) NULL
;
2278 printerOrient
= PS_PORTRAIT
;
2279 printerScaleX
= (double)1.0;
2280 printerScaleY
= (double)1.0;
2281 printerTranslateX
= 0;
2282 printerTranslateY
= 0;
2283 // 1 = Preview, 2 = print to file, 3 = send to printer
2285 afmPath
= (char *) NULL
;
2286 paperName
= (char *) NULL
;
2288 printerFile
= (char *) NULL
;
2291 wxPrintSetupData::~wxPrintSetupData()
2294 delete[] printerCommand
;
2296 delete[] previewCommand
;
2298 delete[] printerFlags
;
2304 delete[] printerFile
;
2307 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2309 if (cmd
== printerCommand
)
2313 delete[] printerCommand
;
2315 printerCommand
= copystring(cmd
);
2317 printerCommand
= (char *) NULL
;
2320 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2322 if (cmd
== previewCommand
)
2326 delete[] previewCommand
;
2328 previewCommand
= copystring(cmd
);
2330 previewCommand
= (char *) NULL
;
2333 void wxPrintSetupData::SetPaperName(const char *name
)
2335 if (name
== paperName
)
2341 paperName
= copystring(name
);
2343 paperName
= (char *) NULL
;
2346 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2348 if (printerFlags
== flags
)
2352 delete[] printerFlags
;
2354 printerFlags
= copystring(flags
);
2356 printerFlags
= (char *) NULL
;
2359 void wxPrintSetupData::SetPrinterFile(const char *f
)
2361 if (f
== printerFile
)
2365 delete[] printerFile
;
2367 printerFile
= copystring(f
);
2369 printerFile
= (char *) NULL
;
2372 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2374 printerOrient
= orient
;
2377 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2383 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2385 printerTranslateX
= x
;
2386 printerTranslateY
= y
;
2389 // 1 = Preview, 2 = print to file, 3 = send to printer
2390 void wxPrintSetupData::SetPrinterMode(int mode
)
2395 void wxPrintSetupData::SetAFMPath(const char *f
)
2403 afmPath
= copystring(f
);
2405 afmPath
= (char *) NULL
;
2408 void wxPrintSetupData::SetColour(bool col
)
2413 // Get current values
2414 char *wxPrintSetupData::GetPrinterCommand()
2416 return printerCommand
;
2419 char *wxPrintSetupData::GetPrintPreviewCommand()
2421 return previewCommand
;
2424 char *wxPrintSetupData::GetPrinterOptions()
2426 return printerFlags
;
2429 char *wxPrintSetupData::GetPrinterFile()
2434 char *wxPrintSetupData::GetPaperName()
2439 int wxPrintSetupData::GetPrinterOrientation()
2441 return printerOrient
;
2444 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2450 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2452 *x
= printerTranslateX
;
2453 *y
= printerTranslateY
;
2456 int wxPrintSetupData::GetPrinterMode()
2461 char *wxPrintSetupData::GetAFMPath()
2466 bool wxPrintSetupData::GetColour()
2471 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2473 SetPrinterCommand(data
.GetPrinterCommand());
2474 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2475 SetPrinterOptions(data
.GetPrinterOptions());
2477 data
.GetPrinterTranslation(&x
, &y
);
2478 SetPrinterTranslation(x
, y
);
2481 data
.GetPrinterScaling(&x1
, &y1
);
2482 SetPrinterScaling(x1
, y1
);
2484 SetPrinterOrientation(data
.GetPrinterOrientation());
2485 SetPrinterMode(data
.GetPrinterMode());
2486 SetAFMPath(data
.GetAFMPath());
2487 SetPaperName(data
.GetPaperName());
2488 SetColour(data
.GetColour());
2491 void wxInitializePrintSetupData(bool init
)
2495 wxThePrintSetupData
= new wxPrintSetupData
;
2497 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2498 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2499 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2500 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2502 // Could have a .ini file to read in some defaults
2503 // - and/or use environment variables, e.g. WXWIN
2505 wxThePrintSetupData
->SetPrinterCommand("print");
2506 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2507 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2510 wxThePrintSetupData
->SetPrinterCommand("print");
2511 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2512 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2514 #if !defined(__VMS__) && !defined(__WXMSW__)
2515 wxThePrintSetupData
->SetPrinterCommand("lpr");
2516 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2517 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2522 if (wxThePrintSetupData
)
2523 delete wxThePrintSetupData
;
2524 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2529 * Paper size database for PostScript
2532 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2538 pageName
= copystring(name
);
2541 wxPrintPaperType::~wxPrintPaperType()
2546 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2548 DeleteContents(TRUE
);
2551 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2555 void wxPrintPaperDatabase::CreateDatabase()
2557 // Need correct values for page size in pixels.
2558 // Each unit is one 'point' = 1/72 of an inch.
2559 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2560 // in wxPostScriptDC code, so we can start from top left.
2561 // So access this database and translate by appropriate number
2562 // of points for this paper size. OR IS IT OK ALREADY?
2563 // Can't remember where the PostScript origin is by default.
2564 // Heck, someone will know how to make it hunky-dory...
2567 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2568 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2569 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2570 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2573 void wxPrintPaperDatabase::ClearDatabase()
2578 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2580 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2583 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2585 wxNode
*node
= Find(name
);
2587 return (wxPrintPaperType
*)node
->Data();
2589 return (wxPrintPaperType
*) NULL
;
2593 * Initialization/cleanup module
2596 bool wxPostScriptModule::OnInit()
2598 wxInitializePrintSetupData();
2599 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2600 wxThePrintPaperDatabase
->CreateDatabase();
2605 void wxPostScriptModule::OnExit()
2607 wxInitializePrintSetupData(FALSE
);
2608 delete wxThePrintPaperDatabase
;
2609 wxThePrintPaperDatabase
= NULL
;