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"
33 #include "wx/filedlg.h"
34 #include "wx/msgdlg.h"
36 #include "wx/button.h"
37 #include "wx/radiobox.h"
38 #include "wx/textctrl.h"
39 #include "wx/stattext.h"
44 #include "wx/postscrp.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
)
174 wxPostScriptDC::wxPostScriptDC ()
176 // m_yOrigin = 792; // For EPS output
177 m_yOrigin
= 842; // For A4 output
185 m_pstream
= (ofstream
*) NULL
;
188 // Can only send to file in Windows
189 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
193 m_currentGreen
= 255;
197 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
199 Create(file
, interactive
, parent
);
202 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
204 m_isInteractive
= interactive
;
206 m_yOrigin
= 792; // For EPS output
207 // m_yOrigin = 842; // For A4 output
215 m_pstream
= (ofstream
*) NULL
;
218 // Can only send to file in Windows
219 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
224 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
230 m_currentGreen
= 255;
238 wxPostScriptDC::~wxPostScriptDC ()
244 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
246 wxPostScriptPrintDialog
dialog (parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
247 m_ok
= (dialog
.ShowModal () == wxID_OK
) ;
252 if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
|| wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
256 wxThePrintSetupData
->SetPrinterFile("preview");
258 // For PS_PRINTER action this depends on a Unix-style print spooler
259 // since the wx_printer_file can be destroyed during a session
260 // @@@ TODO: a Windows-style answer for non-Unix
262 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
264 strcpy (tmp
, "/tmp/preview_");
265 strcat (tmp
, userId
);
266 wxThePrintSetupData
->SetPrinterFile(tmp
);
269 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
270 strcat (tmp2
, ".ps");
271 wxThePrintSetupData
->SetPrinterFile(tmp2
);
274 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
276 char *file
= wxSaveFileSelector (_("PostScript"), "ps");
282 wxThePrintSetupData
->SetPrinterFile(file
);
290 void wxPostScriptDC::SetClippingRegion (long cx
, long cy
, long cw
, long ch
)
298 *m_pstream
<< "gsave\n";
299 *m_pstream
<< "newpath\n";
300 *m_pstream
<< cx
<< " " << YSCALE (cy
) << " moveto\n";
301 *m_pstream
<< (cx
+ cw
) << " " << YSCALE (cy
) << " lineto\n";
302 *m_pstream
<< cx
+ cw
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
303 *m_pstream
<< cx
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
304 *m_pstream
<< "closepath clip newpath\n";
307 void wxPostScriptDC::DestroyClippingRegion ()
314 *m_pstream
<< "grestore\n";
318 void wxPostScriptDC::Clear ()
322 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
), int WXUNUSED(style
))
326 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
331 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
335 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
341 *m_pstream
<< "newpath\n";
342 *m_pstream
<< x1
<< " " << YSCALE (y1
) << " moveto\n";
343 *m_pstream
<< x2
<< " " << YSCALE (y2
) << " lineto\n";
344 *m_pstream
<< "stroke\n";
345 CalcBoundingBox (x1
, (long)YSCALE (y1
));
346 CalcBoundingBox (x2
, (long)YSCALE (y2
));
349 #define RAD2DEG 57.29577951308
351 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
358 long radius
= (long) sqrt((double) (dx
*dx
+dy
*dy
));
359 double alpha1
, alpha2
;
361 if (x1
== x2
&& y1
== y2
) {
364 } else if (radius
== 0.0) {
365 alpha1
= alpha2
= 0.0;
367 alpha1
= (x1
- xc
== 0) ?
368 (y1
- yc
< 0) ? 90.0 : -90.0 :
369 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
370 alpha2
= (x2
- xc
== 0) ?
371 (y2
- yc
< 0) ? 90.0 : -90.0 :
372 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
374 while (alpha1
<= 0) alpha1
+= 360;
375 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
376 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
377 while (alpha2
> 360) alpha2
-= 360;
379 if (m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
) {
381 *m_pstream
<< "newpath\n"
382 << xc
<< " " << YSCALE(yc
) << " "
383 << radius
<< " " << radius
<< " "
384 << alpha1
<< " " << alpha2
<< " ellipse\n"
385 << xc
<< " " << YSCALE(yc
) << " lineto\n"
389 if (m_pen
.Ok() && m_pen
.GetStyle() != wxTRANSPARENT
) {
391 *m_pstream
<< "newpath\n"
392 << xc
<< " " << YSCALE(yc
) << " "
393 << radius
<< " " << radius
<< " "
394 << alpha1
<< " " << alpha2
<< " ellipse\n"
397 CalcBoundingBox(x1
, (long)YSCALE(y1
));
398 CalcBoundingBox(x2
, (long)YSCALE(y2
));
401 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
406 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
407 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
412 DrawEllipse(x
,y
,w
,h
);
416 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
422 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
423 w
/2 << " " << (h
/2) << " " <<
424 int(sa
) <<" "<< int(ea
)<<" true ellipticarc\n";
426 CalcBoundingBox (x
, (long)YSCALE (y
));
427 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
429 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
435 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
436 (w
/2) << " " << (h
/2) << " " <<
437 int(sa
) <<" "<< int(ea
)<<" false ellipticarc\n";
439 CalcBoundingBox (x
, (long)YSCALE (y
));
440 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
444 void wxPostScriptDC::DrawPoint (long x
, long y
)
450 *m_pstream
<< "newpath\n";
451 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
452 *m_pstream
<< (x
+1) << " " << YSCALE (y
) << " lineto\n";
453 *m_pstream
<< "stroke\n";
454 CalcBoundingBox (x
, (long)YSCALE (y
));
457 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
463 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
466 *m_pstream
<< "newpath\n";
468 long xx
= points
[0].x
+ xoffset
;
469 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
470 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
471 CalcBoundingBox (xx
, yy
);
474 for (i
= 1; i
< n
; i
++)
476 xx
= points
[i
].x
+ xoffset
;
477 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
478 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
479 CalcBoundingBox (xx
, yy
);
481 *m_pstream
<< "fill\n";
484 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
487 *m_pstream
<< "newpath\n";
489 long xx
= points
[0].x
+ xoffset
;
490 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
491 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
492 CalcBoundingBox (xx
, yy
);
495 for (i
= 1; i
< n
; i
++)
497 xx
= points
[i
].x
+ xoffset
;
498 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
499 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
500 CalcBoundingBox (xx
, yy
);
504 xx
= points
[0].x
+ xoffset
;
505 yy
= (long) YSCALE (points
[0].y
+ yoffset
);
506 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
509 *m_pstream
<< "stroke\n";
514 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
523 *m_pstream
<< "newpath\n";
525 long xx
= points
[0].x
+ xoffset
;
526 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
527 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
528 CalcBoundingBox (xx
, yy
);
531 for (i
= 1; i
< n
; i
++)
533 xx
= points
[i
].x
+ xoffset
;
534 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
535 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
536 CalcBoundingBox (xx
, yy
);
538 *m_pstream
<< "stroke\n";
542 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
546 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
550 *m_pstream
<< "newpath\n";
551 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
552 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
553 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
554 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
555 *m_pstream
<< "closepath\n";
556 *m_pstream
<< "fill\n";
558 CalcBoundingBox (x
, (long)YSCALE (y
));
559 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
561 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
565 *m_pstream
<< "newpath\n";
566 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
567 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
568 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
569 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
570 *m_pstream
<< "closepath\n";
571 *m_pstream
<< "stroke\n";
573 CalcBoundingBox (x
, (long)YSCALE (y
));
574 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
578 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
585 // Now, a negative radius is interpreted to mean
586 // 'the proportion of the smallest X or Y dimension'
587 double smallest
= 0.0;
592 radius
= (-radius
* smallest
);
595 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
598 // Draw rectangle anticlockwise
599 *m_pstream
<< "newpath\n";
600 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
602 *m_pstream
<< x
<< " " << YSCALE (y
+ radius
) << " moveto\n";
604 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
605 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
607 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
608 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
610 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
612 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
614 *m_pstream
<< "closepath\n";
616 *m_pstream
<< "fill\n";
618 CalcBoundingBox (x
, (long)YSCALE (y
));
619 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
621 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
624 // Draw rectangle anticlockwise
625 *m_pstream
<< "newpath\n";
626 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
628 *m_pstream
<< x
<< " " << YSCALE (y
+ height
- radius
) << " lineto\n";
630 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
631 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
633 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
634 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
636 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
638 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
640 *m_pstream
<< "closepath\n";
642 *m_pstream
<< "stroke\n";
644 CalcBoundingBox (x
, (long)YSCALE (y
));
645 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
649 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
653 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
657 *m_pstream
<< "newpath\n";
658 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
659 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
660 *m_pstream
<< "fill\n";
662 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
663 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
665 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
669 *m_pstream
<< "newpath\n";
670 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
671 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
672 *m_pstream
<< "stroke\n";
674 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
675 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
679 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
681 #if defined(__X__) || defined(__WXGTK__)
683 memDC
.SelectObject(icon
);
684 Blit(x
, y
, icon
.GetWidth(), icon
.GetHeight(), &memDC
, 0, 0);
688 void wxPostScriptDC::SetFont (const wxFont
& the_font
)
693 if (m_font
== the_font
)
703 const char *style
= "";
704 int Style
= m_font
.GetStyle ();
705 int Weight
= m_font
.GetWeight ();
707 switch (m_font
.GetFamily ())
717 // name = "/Times-Roman";
718 name
= "/Times"; // Altered by EDZ
721 name
= "/Zapf-Chancery-MediumItalic";
726 case wxDEFAULT
: // Sans Serif Font
727 name
= "/LucidaSans";
730 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
732 if (m_font
.GetFamily () == wxROMAN
)
737 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
740 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
742 if (m_font
.GetFamily () == wxROMAN
)
747 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
749 if (m_font
.GetFamily () == wxROMAN
)
750 style
= "-BoldItalic";
752 style
= "-BoldOblique";
754 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
756 if (m_font
.GetFamily () == wxROMAN
)
761 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
763 if (m_font
.GetFamily () == wxROMAN
)
764 style
= "-BoldItalic";
766 style
= "-BoldOblique";
773 *m_pstream
<< buf
<< " findfont\n";
774 *m_pstream
<< (m_font
.GetPointSize() * m_scaleFactor
) << " scalefont setfont\n";
777 void wxPostScriptDC::SetPen (const wxPen
& pen
)
782 int oldStyle
= m_pen
.GetStyle();
790 *m_pstream
<< m_pen
.GetWidth () << " setlinewidth\n";
792 // Line style - WRONG: 2nd arg is OFFSET
794 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
795 operator correctly. You should look-up this in the Red Book: the 2nd parame-
796 ter is not number of values in the array of the first one, but an offset
797 into this description of the pattern. I mean a real *offset* not index
798 into array. I.e. If the command is [3 4] 1 setdash is used, then there
799 will be first black line *2* units long, then space 4 units, then the
800 pattern of *3* units black, 4 units space will be repeated.
802 static const char *dotted
= "[2 5] 2";
803 static const char *short_dashed
= "[4 4] 2";
804 static const char *long_dashed
= "[4 8] 2";
805 static const char *dotted_dashed
= "[6 6 2 6] 4";
807 const char *psdash
= (char *) NULL
;
808 switch (m_pen
.GetStyle ())
814 psdash
= short_dashed
;
817 psdash
= long_dashed
;
820 psdash
= dotted_dashed
;
828 if (oldStyle
!= m_pen
.GetStyle())
829 *m_pstream
<< psdash
<< " setdash\n";
832 unsigned char red
= m_pen
.GetColour ().Red ();
833 unsigned char blue
= m_pen
.GetColour ().Blue ();
834 unsigned char green
= m_pen
.GetColour ().Green ();
838 // Anything not white is black
839 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
840 && green
== (unsigned char) 255))
842 red
= (unsigned char) 0;
843 green
= (unsigned char) 0;
844 blue
= (unsigned char) 0;
848 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
850 long redPS
= (long) (((int) red
) / 255.0);
851 long bluePS
= (long) (((int) blue
) / 255.0);
852 long greenPS
= (long) (((int) green
) / 255.0);
854 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
857 m_currentBlue
= blue
;
858 m_currentGreen
= green
;
862 void wxPostScriptDC::SetBrush (const wxBrush
& brush
)
873 unsigned char red
= m_brush
.GetColour ().Red ();
874 unsigned char blue
= m_brush
.GetColour ().Blue ();
875 unsigned char green
= m_brush
.GetColour ().Green ();
879 // Anything not black is white
880 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
881 && green
== (unsigned char) 0))
883 red
= (unsigned char) 255;
884 green
= (unsigned char) 255;
885 blue
= (unsigned char) 255;
889 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
891 long redPS
= (long) (((int) red
) / 255.0);
892 long bluePS
= (long) (((int) blue
) / 255.0);
893 long greenPS
= (long) (((int) green
) / 255.0);
894 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
896 m_currentBlue
= blue
;
897 m_currentGreen
= green
;
901 void wxPostScriptDC::DrawText (const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
))
906 // TODO: SetFont checks for identity so this will always be a NULL operation
910 if (m_textForegroundColour
.Ok ())
912 unsigned char red
= m_textForegroundColour
.Red ();
913 unsigned char blue
= m_textForegroundColour
.Blue ();
914 unsigned char green
= m_textForegroundColour
.Green ();
918 // Anything not white is black
919 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
920 && green
== (unsigned char) 255))
922 red
= (unsigned char) 0;
923 green
= (unsigned char) 0;
924 blue
= (unsigned char) 0;
927 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
929 long redPS
= (long) (((int) red
) / 255.0);
930 long bluePS
= (long) (((int) blue
) / 255.0);
931 long greenPS
= (long) (((int) green
) / 255.0);
932 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
935 m_currentBlue
= blue
;
936 m_currentGreen
= green
;
942 size
= m_font
.GetPointSize ();
944 *m_pstream
<< x
<< " " << YSCALE (y
+ size
) << " moveto\n";
946 // *m_pstream << "(" << text << ")" << " show\n";
948 int len
= strlen ((char *)(const char *)text
);
950 for (i
= 0; i
< len
; i
++)
954 if (ch == ')' || ch == '(' || ch == '\\')
958 int c
= (unsigned char) text
[i
];
959 if ( c
== ')' || c
== '(' || c
== '\\')
961 *m_pstream
<< "\\" << (char) c
;
965 // Cope with character codes > 127
967 sprintf(tmp
, "\\%o", c
);
971 *m_pstream
<< (char) c
;
974 *m_pstream
<< ")" << " show\n";
976 if (m_font
.GetUnderlined())
979 GetTextExtent(text
, &w
, &h
);
980 *m_pstream
<< "gsave " << x
<< " " << YSCALE (y
+ size
- UnderlinePosition
)
982 << UnderlineThickness
<< " setlinewidth "
983 << (x
+ w
) << " " << YSCALE (y
+ size
- UnderlinePosition
)
984 << " lineto stroke grestore\n";
987 CalcBoundingBox (x
, (long)YSCALE (y
+ size
));
988 CalcBoundingBox (x
+ size
* strlen ((char *)(const char *)text
), (long)YSCALE (y
));
992 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
994 m_backgroundBrush
= brush
;
997 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1001 static const char *wxPostScriptHeaderEllipse
= "\
1002 /ellipsedict 8 dict def\n\
1003 ellipsedict /mtrx matrix put\n\
1005 { ellipsedict begin\n\
1006 /endangle exch def\n\
1007 /startangle exch def\n\
1012 /savematrix mtrx currentmatrix def\n\
1015 0 0 1 startangle endangle arc\n\
1016 savematrix setmatrix\n\
1021 static const char *wxPostScriptHeaderEllipticArc
= "\
1022 /ellipticarcdict 8 dict def\n\
1023 ellipticarcdict /mtrx matrix put\n\
1025 { ellipticarcdict begin\n\
1026 /do_fill exch def\n\
1027 /endangle exch def\n\
1028 /startangle exch def\n\
1033 /savematrix mtrx currentmatrix def\n\
1036 do_fill { 0 0 moveto } if\n\
1037 0 0 1 startangle endangle arc\n\
1038 savematrix setmatrix\n\
1039 do_fill { fill }{ stroke } ifelse\n\
1043 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1045 if (m_filename
== "")
1048 m_filename
= "wxtmp.ps";
1050 m_filename
= wxGetTempFileName("ps");
1052 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1056 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1061 m_pstream
= new ofstream
;
1062 if(fileBuffer
) delete[] fileBuffer
;
1063 fileBuffer
= new char[VMS_BUFSIZ
];
1064 m_pstream
->setbuf(fileBuffer
,VMS_BUFSIZ
);
1065 m_pstream
->open(wxThePrintSetupData
->GetPrinterFile());
1067 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1069 if (!m_pstream
|| !m_pstream
->good())
1071 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1077 SetBrush (*wxBLACK_BRUSH
);
1078 SetPen (*wxBLACK_PEN
);
1086 void wxPostScriptDC::EndDoc ()
1088 static char wxPostScriptHeaderReencodeISO1
[] =
1089 "\n/reencodeISO {\n"
1090 "dup dup findfont dup length dict begin\n"
1091 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
1092 "/Encoding ISOLatin1Encoding def\n"
1093 "currentdict end definefont\n"
1095 "/ISOLatin1Encoding [\n"
1096 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\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 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
1101 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
1102 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
1103 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
1104 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
1105 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
1106 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
1107 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1108 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1109 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
1110 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
1112 static char wxPostScriptHeaderReencodeISO2
[] =
1113 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
1114 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
1115 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
1116 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
1117 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
1118 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
1119 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
1120 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
1121 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
1122 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
1123 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
1124 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
1125 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
1126 "/yacute/thorn/ydieresis\n"
1134 *m_pstream
<< "grestore\n";
1137 // Will reuse m_pstream for header
1139 // see the definition of fileBuffer for explanation
1140 m_pstream
->close(); // steve, 05.09.94
1141 if(fileBuffer
) delete[] fileBuffer
;
1146 m_pstream
= (ofstream
*) NULL
;
1152 char *header_file
= "header.ps";
1154 char *header_file
= wxGetTempFileName("ps");
1156 m_pstream
= new ofstream (header_file
);
1158 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1159 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1160 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1161 // time_t when; time (&when);
1162 // *m_pstream << "%%CreationDate: " << ctime (&when);
1163 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1165 // User Id information
1167 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1169 *m_pstream
<< "%%For: " << (char *)userID
;
1171 if (wxGetUserName(userName
, sizeof(userName
)))
1172 *m_pstream
<< " (" << (char *)userName
<< ")";
1175 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1177 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1180 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1182 long wx_printer_translate_x
, wx_printer_translate_y
;
1183 double wx_printer_scale_x
, wx_printer_scale_y
;
1184 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1185 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1187 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1189 *m_pstream
<< "%%Orientation: Landscape\n";
1193 *m_pstream
<< "%%Orientation: Portrait\n";
1196 // Compute the bounding box. Note that it is in the default user
1197 // coordinate system, thus we have to convert the values.
1198 long llx
= (long) ((m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1199 long lly
= (long) ((m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1200 long urx
= (long) ((m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1201 long ury
= (long) ((m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1204 // If we're landscape, our sense of "x" and "y" is reversed.
1205 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1208 tmp
= llx
; llx
= lly
; lly
= tmp
;
1209 tmp
= urx
; urx
= ury
; ury
= tmp
;
1211 // We need either the two lines that follow, or we need to subtract
1212 // min_x from real_translate_y, which is commented out below.
1213 llx
= llx
- m_minX
*wx_printer_scale_y
;
1214 urx
= urx
- m_minX
*wx_printer_scale_y
;
1218 // The Adobe specifications call for integers; we round as to make
1219 // the bounding larger.
1220 *m_pstream
<< "%%BoundingBox: "
1221 << floor((double)llx
) << " " << floor((double)lly
) << " "
1222 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1223 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1224 *m_pstream
<< "%%EndComments\n\n";
1226 // To check the correctness of the bounding box, postscript commands
1227 // to draw a box corresponding to the bounding box are generated below.
1228 // But since we typically don't want to print such a box, the postscript
1229 // commands are generated within comments. These lines appear before any
1230 // adjustment of scale, rotation, or translation, and hence are in the
1231 // default user coordinates.
1232 *m_pstream
<< "% newpath\n";
1233 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1234 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1235 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1236 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1240 long real_translate_y
= wx_printer_translate_y
;
1241 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1243 real_translate_y
-= m_maxY
;
1244 // The following line can be used instead of the adjustment to
1245 // llx and urx above.
1246 // real_translate_y -= m_minX;
1247 *m_pstream
<< "90 rotate\n";
1250 /* Probably don't want this now we have it in EndPage, below.
1251 * We should rationalise the scaling code to one place. JACS, October 1995
1252 * Do we take the next 2 lines out or not?
1255 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1256 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1259 *m_pstream
<< "%%BeginProlog\n";
1260 *m_pstream
<< wxPostScriptHeaderEllipse
;
1261 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1262 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1263 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1265 if (wxPostScriptHeaderSpline
)
1266 *m_pstream
<< wxPostScriptHeaderSpline
;
1267 *m_pstream
<< "%%EndProlog\n";
1270 m_pstream
= (ofstream
*) NULL
;
1273 char *tmp_file
= "tmp.ps";
1275 char *tmp_file
= wxGetTempFileName("ps");
1278 // Paste header Before wx_printer_file
1279 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1280 wxRemoveFile (header_file
);
1281 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1282 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1284 #if defined(__X__) || defined(__WXGTK__)
1287 switch (wxThePrintSetupData
->GetPrinterMode()) {
1291 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1292 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1293 argv
[2] = (char *) NULL
;
1294 wxExecute (argv
, TRUE
);
1295 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1303 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1305 // !SM! If we simply assign to argv[1] here, if printer options
1306 // are blank, we get an annoying and confusing message from lpr.
1307 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1309 argv
[argc
++] = opts
;
1311 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1312 argv
[argc
++] = (char *) NULL
;
1313 wxExecute (argv
, TRUE
);
1314 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1325 void wxPostScriptDC::StartPage ()
1329 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1330 // *m_pstream << "matrix currentmatrix\n";
1332 // Added by Chris Breeze
1334 // Each page starts with an "initgraphics" which resets the
1335 // transformation and so we need to reset the origin
1336 // (and rotate the page for landscape printing)
1337 m_scaleFactor
= 1.0;
1338 m_logicalOriginX
= 0;
1339 m_logicalOriginY
= 0;
1342 long translate_x
, translate_y
;
1343 double scale_x
, scale_y
;
1344 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1345 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1347 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1349 translate_y
-= GetYOrigin();
1350 *m_pstream
<< "90 rotate\n";
1353 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1354 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1357 void wxPostScriptDC::EndPage ()
1361 *m_pstream
<< "showpage\n";
1363 // Removed by Chris Breeze
1365 *m_pstream
<< "setmatrix\n";
1367 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1369 long wx_printer_translate_x
, wx_printer_translate_y
;
1370 double wx_printer_scale_x
, wx_printer_scale_y
;
1371 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1372 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1374 // Compute the bounding box. Note that it is in the default user
1375 // coordinate system, thus we have to convert the values.
1376 long llx
= (m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1377 long lly
= (m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1378 long urx
= (m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1379 long ury
= (m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1381 // If we're landscape, our sense of "x" and "y" is reversed.
1382 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1385 tmp
= llx
; llx
= lly
; lly
= tmp
;
1386 tmp
= urx
; urx
= ury
; ury
= tmp
;
1388 // We need either the two lines that follow, or we need to subtract
1389 // m_minX from real_translate_y, which is commented out below.
1390 llx
= llx
- m_minX
*wx_printer_scale_y
;
1391 urx
= urx
- m_minX
*wx_printer_scale_y
;
1395 long real_translate_y
= wx_printer_translate_y
;
1396 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1398 real_translate_y
-= m_maxY
;
1399 // The following line can be used instead of the adjustment to
1400 // llx and urx above.
1401 // real_translate_y -= m_minX;
1402 *m_pstream
<< "90 rotate\n";
1405 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1406 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1410 bool wxPostScriptDC::
1411 Blit (long xdest
, long ydest
, long fwidth
, long fheight
,
1412 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(rop
), bool WXUNUSED(useMask
))
1414 long width
, height
, x
, y
;
1416 #if !defined(__X__) && !defined(__WXGTK__)
1420 if (!source
->IsKindOf(CLASSINFO(wxPaintDC
))) return FALSE
;
1422 width
= (long)floor((double)fwidth
);
1423 height
= (long)floor((double)fheight
);
1424 x
= (long)floor((double)xsrc
);
1425 y
= (long)floor((double)ysrc
);
1427 /* PostScript setup: */
1428 *m_pstream
<< "gsave\n";
1429 *m_pstream
<< xdest
<< " " << YSCALE(ydest
+ fheight
) << " translate\n";
1430 *m_pstream
<< fwidth
<< " " << fheight
<< " scale\n";
1431 *m_pstream
<< "/DataString " << width
<< " string def\n";
1432 *m_pstream
<< width
<< " " << height
<< " 8 [ ";
1433 *m_pstream
<< width
<< " 0 0 " << (-height
) << " 0 " << height
;
1434 *m_pstream
<< " ]\n{\n";
1435 *m_pstream
<< " currentfile DataString readhexstring pop\n";
1436 *m_pstream
<< "} bind image\n";
1438 #if defined(__X__) || defined(__WXGTK__)
1440 /* Output data as hex digits: */
1450 cm
= ((GdkColormapPrivate
*)gdk_colormap_get_system())->xcolormap
;
1451 GdkWindow
*gwin
= ((wxClientDC
*)source
)->GetWindow();
1452 image
= XGetImage(d
, ((GdkWindowPrivate
*)gwin
)->xwindow
, x
, y
, width
, height
, AllPlanes
, ZPixmap
);
1457 // TODO. for now, use global display
1458 // d = source->display;
1459 d
= (Display
*) wxGetDisplay();
1461 d
= (Display
*) wxGetDisplay();
1464 cm
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) d
);
1465 // TODO - implement GetPixmap() and uncomment this line
1466 // image = XGetImage(d, source->GetPixmap(), x, y, width, height, AllPlanes, ZPixmap);
1473 #define CM_CACHE_SIZE 256
1474 unsigned long cachesrc
[CM_CACHE_SIZE
];
1475 int cachedest
[CM_CACHE_SIZE
], cache_pos
= 0, all_cache
= FALSE
;
1477 for (j
= 0; j
< height
; j
++) {
1478 for (i
= 0; i
< width
; i
++) {
1480 unsigned long spixel
;
1482 const unsigned short MAX_COLOR
= 0xFFFF;
1484 spixel
= XGetPixel(image
, i
, j
);
1486 for (k
= cache_pos
; k
--; )
1487 if (cachesrc
[k
] == spixel
) {
1488 pixel
= cachedest
[k
];
1492 for (k
= CM_CACHE_SIZE
; k
-- > cache_pos
; )
1493 if (cachesrc
[k
] == spixel
) {
1494 pixel
= cachedest
[k
];
1498 cachesrc
[cache_pos
] = xcol
.pixel
= spixel
;
1499 XQueryColor(d
, cm
, &xcol
);
1503 r
= (long)((double)(xcol
.red
) / MAX_COLOR
);
1504 g
= (long)((double)(xcol
.green
) / MAX_COLOR
);
1505 b
= (long)((double)(xcol
.blue
) / MAX_COLOR
);
1507 pixel
= (int)(255 * sqrt(((r
* r
) + (g
* g
) + (b
* b
)) / 3));
1509 cachedest
[cache_pos
] = pixel
;
1511 if (++cache_pos
>= CM_CACHE_SIZE
) {
1519 h
= (pixel
>> 4) & 0xF;
1525 s
[0] = 'a' + (h
- 10);
1529 s
[1] = 'a' + (l
- 10);
1536 XDestroyImage(image
);
1539 *m_pstream
<< "grestore\n";
1541 CalcBoundingBox(xdest
, (long)YSCALE(ydest
));
1542 CalcBoundingBox(xdest
+ fwidth
, (long)YSCALE(ydest
+ fheight
));
1547 long wxPostScriptDC::GetCharHeight ()
1550 return m_font
.GetPointSize ();
1555 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1556 long *descent
, long *externalLeading
, wxFont
*theFont
,
1557 bool WXUNUSED(use16
))
1559 wxFont
*fontToUse
= theFont
;
1561 fontToUse
= (wxFont
*) &m_font
;
1565 #if !USE_AFM_FOR_POSTSCRIPT
1566 // Provide a VERY rough estimate (avoid using it)
1567 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1568 // font such as Courier (aka wxMODERN)
1572 height
= fontToUse
->GetPointSize();
1574 *x
= strlen (string
) * height
* 72 / 120;
1575 *y
= (long) (height
* 1.32); // allow for descender
1579 if (externalLeading
)
1580 *externalLeading
= 0;
1582 // +++++ start of contributed code +++++
1584 // ************************************************************
1585 // method for calculating string widths in postscript:
1586 // read in the AFM (adobe font metrics) file for the
1587 // actual font, parse it and extract the character widths
1588 // and also the descender. this may be improved, but for now
1589 // it works well. the AFM file is only read in if the
1590 // font is changed. this may be chached in the future.
1591 // calls to GetTextExtent with the font unchanged are rather
1594 // for each font and style used there is an AFM file necessary.
1595 // currently i have only files for the roman font family.
1596 // i try to get files for the other ones!
1598 // CAVE: the size of the string is currently always calculated
1599 // in 'points' (1/72 of an inch). this should later on be
1600 // changed to depend on the mapping mode.
1601 // CAVE: the path to the AFM files must be set before calling this
1602 // function. this is usually done by a call like the following:
1603 // wxSetAFMPath("d:\\wxw161\\afm\\");
1607 // wxPostScriptDC dc(NULL, TRUE);
1609 // wxSetAFMPath("d:\\wxw161\\afm\\");
1610 // dc.StartDoc("Test");
1613 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1614 // dc.GetTextExtent("Hallo",&w,&h);
1619 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1620 // created: 10.09.94
1621 // updated: 14.05.95
1623 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1624 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1625 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1627 // these static vars are for storing the state between calls
1628 static int lastFamily
= INT_MIN
;
1629 static int lastSize
= INT_MIN
;
1630 static int lastStyle
= INT_MIN
;
1631 static int lastWeight
= INT_MIN
;
1632 static int lastDescender
= INT_MIN
;
1633 static int lastWidths
[256]; // widths of the characters
1635 // get actual parameters
1636 const int Family
= fontToUse
->GetFamily();
1637 const int Size
= fontToUse
->GetPointSize();
1638 const int Style
= fontToUse
->GetStyle();
1639 const int Weight
= fontToUse
->GetWeight();
1641 // if we have another font, read the font-metrics
1642 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1643 // store actual values
1644 lastFamily
= Family
;
1647 lastWeight
= Weight
;
1649 // read in new font metrics **************************************
1651 // 1. construct filename ******************************************
1652 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1655 // Julian - we'll need to do this a different way now we've removed the
1656 // font directory system. Must find Stefan's original code.
1658 name
= wxTheFontNameDirectory
->GetAFMName(Family
, Weight
, Style
);
1662 // get the directory of the AFM files
1666 strcpy(afmName
,wxGetAFMPath());
1668 // 2. open and process the file **********************************
1670 // a short explanation of the AFM format:
1671 // we have for each character a line, which gives its size
1674 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1676 // that means, we have a character with ascii code 63, and width
1677 // (444/1000 * fontSize) points.
1678 // the other data is ignored for now!
1680 // when the font has changed, we read in the right AFM file and store the
1681 // character widths in an array, which is processed below (see point 3.).
1683 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1686 strcat(afmName
,name
);
1687 strcat(afmName
,".afm");
1688 FILE *afmFile
= fopen(afmName
,"r");
1690 wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1691 wxDebugMsg(" using approximate values\n");
1693 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1694 lastDescender
= -150; // dito.
1697 // init the widths array
1698 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1699 // some variables for holding parts of a line
1700 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1701 char upString
[30], utString
[30], encString
[50];
1704 // read in the file and parse it
1705 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1706 // A.) check for descender definition
1707 if(strncmp(line
,"Descender",9)==0){
1708 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1709 || (strcmp(descString
,"Descender")!=0)) {
1710 wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n",
1714 // JC 1.) check for UnderlinePosition
1715 else if(strncmp(line
,"UnderlinePosition",17)==0){
1716 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1717 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1718 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1722 // JC 2.) check for UnderlineThickness
1723 else if(strncmp(line
,"UnderlineThickness",18)==0){
1724 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1725 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1726 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1730 // JC 3.) check for EncodingScheme
1731 else if(strncmp(line
,"EncodingScheme",14)==0){
1732 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1733 || (strcmp(utString
,"EncodingScheme")!=0)) {
1734 wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1737 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1739 wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1740 afmName
,line
, encString
);
1743 // B.) check for char-width
1744 else if(strncmp(line
,"C ",2)==0){
1745 if(sscanf(line
,"%s%d%s%s%d",
1746 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1747 wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1749 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1750 strcmp(WXString
,"WX")!=0){
1751 wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1753 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1754 if(ascii
>=0 && ascii
<256){
1755 lastWidths
[ascii
] = cWidth
; // store width
1757 /* MATTHEW: this happens a lot; don't print an error */
1758 // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1761 // C.) ignore other entries.
1765 // hack to compute correct values for german 'Umlaute'
1766 // the correct way would be to map the character names
1767 // like 'adieresis' to corresp. positions of ISOEnc and read
1768 // these values from AFM files, too. Maybe later ...
1769 lastWidths
[196] = lastWidths
['A']; // Ä
1770 lastWidths
[228] = lastWidths
['a']; // ä
1771 lastWidths
[214] = lastWidths
['O']; // Ö
1772 lastWidths
[246] = lastWidths
['o']; // ö
1773 lastWidths
[220] = lastWidths
['U']; // Ü
1774 lastWidths
[252] = lastWidths
['u']; // ü
1775 lastWidths
[223] = lastWidths
[251]; // ß
1778 // JC: calculate UnderlineThickness/UnderlinePosition
1779 UnderlinePosition
= UnderlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1780 UnderlineThickness
= UnderlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1782 // 3. now the font metrics are read in, calc size *******************
1783 // this is done by adding the widths of the characters in the
1784 // string. they are given in 1/1000 of the size!
1787 long height
=Size
; // by default
1789 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1790 if(lastWidths
[*p
]== INT_MIN
){
1791 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1793 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1795 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1798 // add descender to height (it is usually a negative value)
1799 if(lastDescender
!=INT_MIN
){
1800 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1803 // return size values
1807 // return other parameters
1809 if(lastDescender
!=INT_MIN
){
1810 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1816 // currently no idea how to calculate this!
1817 // if (externalLeading) *externalLeading = 0;
1818 if (externalLeading
)
1819 *externalLeading
= 0;
1821 // ----- end of contributed code -----
1825 void wxPostScriptDC::DrawSpline( wxList
*points
)
1827 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1830 wxNode
*node
= points
->First();
1831 p
= (wxPoint
*)node
->Data();
1833 x1
= p
->x
; y1
= p
->y
;
1835 node
= node
->Next();
1836 p
= (wxPoint
*)node
->Data();
1838 x3
= a
= (double)(x1
+ c
) / 2;
1839 y3
= b
= (double)(y1
+ d
) / 2;
1841 *(GetStream()) << "newpath " << x1
<< " " << (GetYOrigin() - y1
) << " moveto " << x3
<< " " << (GetYOrigin() - y3
);
1842 *(GetStream()) << " lineto\n";
1843 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1844 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1846 while ((node
= node
->Next()) != NULL
)
1848 q
= (wxPoint
*)node
->Data();
1853 x3
= (double)(x2
+ c
) / 2;
1854 y3
= (double)(y2
+ d
) / 2;
1855 *(GetStream()) << x1
<< " " << (GetYOrigin() - y1
) << " " << x2
<< " " << (GetYOrigin() - y2
) << " ";
1856 *(GetStream()) << x3
<< " " << (GetYOrigin() - y3
) << " DrawSplineSection\n";
1858 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1859 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1862 * At this point, (x2,y2) and (c,d) are the position of the
1863 * next-to-last and last point respectively, in the point list
1865 *(GetStream()) << c
<< " " << (GetYOrigin() - d
) << " lineto stroke\n";
1868 long wxPostScriptDC::GetCharWidth ()
1870 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1871 return (long) (GetCharHeight() * 72.0 / 120.0);
1875 void wxPostScriptDC::SetMapMode (int mode
)
1877 m_mappingMode
= mode
;
1878 SetLogicalOrigin(0, 0);
1879 if(m_mappingMode
== MM_METRIC
)
1881 SetUserScale(72.0f
/ 25.4f
, 72.0f
/ 25.4f
);
1885 SetUserScale(1.0, 1.0);
1891 * Set the logical origin.
1892 * Actually we are setting the printer's origin and since
1893 * postscript transformations are cumulative we need to reset
1894 * the previous origin. We also need to allow for the user scale
1895 * factor (which affects printer coords but not logical)
1897 void wxPostScriptDC::SetLogicalOrigin(long x
, long y
)
1901 long xOffset
= (long) ((m_logicalOriginX
- x
) / m_scaleFactor
);
1902 long yOffset
= (long) ((y
- m_logicalOriginY
) / m_scaleFactor
);
1906 *m_pstream
<< xOffset
<< " " << yOffset
<< " translate\n";
1909 m_logicalOriginX
= x
;
1910 m_logicalOriginY
= y
;
1914 * Obsolete - now performed by SetUserScale() and SetLogicalOrigin()
1917 wxPostScriptDC::SetupCTM()
1922 * Set the user scale.
1923 * NB: Postscript transformations are cumulative and so we
1924 * need to take into account the current scale. Also, this
1925 * affects the logical origin
1927 void wxPostScriptDC::SetUserScale (double x
, double y
)
1929 // reset logical origin
1930 long xOrg
= m_logicalOriginX
;
1931 long yOrg
= m_logicalOriginY
;
1932 SetLogicalOrigin(0, 0);
1934 // set new scale factor
1938 factor
/= m_scaleFactor
;
1942 *m_pstream
<< factor
<< " " << factor
<< " scale\n";
1945 // set logical origin at new scale
1946 SetLogicalOrigin(xOrg
, yOrg
);
1951 m_scaleFactor
= m_userScaleX
;
1954 long wxPostScriptDC::DeviceToLogicalX (int x
) const
1959 long wxPostScriptDC::DeviceToLogicalXRel (int x
) const
1964 long wxPostScriptDC::DeviceToLogicalY (int y
) const
1969 long wxPostScriptDC::DeviceToLogicalYRel (int y
) const
1974 long wxPostScriptDC::LogicalToDeviceX (long x
) const
1979 long wxPostScriptDC::LogicalToDeviceXRel (long x
) const
1984 long wxPostScriptDC::LogicalToDeviceY (long y
) const
1989 long wxPostScriptDC::LogicalToDeviceYRel (long y
) const
1994 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1996 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1998 paperType
= _("A4 210 x 297 mm");
2000 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2002 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2005 *width
= paper
->widthPixels
;
2006 *height
= paper
->heightPixels
;
2015 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
2017 const char *paperType
= wxThePrintSetupData
->GetPaperName();
2019 paperType
= _("A4 210 x 297 mm");
2021 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2023 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2026 *width
= paper
->widthMM
;
2027 *height
= paper
->heightMM
;
2036 void wxPostScriptDC::CalcBoundingBox(long x
, long y
)
2038 long device_x
= (long) (x
- m_logicalOriginX
* m_scaleFactor
);
2039 long device_y
= (long) (y
+ m_logicalOriginY
* m_scaleFactor
);
2041 if (device_x
< m_minX
) m_minX
= device_x
;
2042 if (device_y
< m_minY
) m_minY
= device_y
;
2043 if (device_x
> m_maxX
) m_maxX
= device_x
;
2044 if (device_y
> m_maxY
) m_maxY
= device_y
;
2047 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2049 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2050 const wxPoint
& pos
, const wxSize
& size
, long style
):
2051 wxDialog(parent
, -1, title
, pos
, size
, style
)
2053 wxBeginBusyCursor();
2058 *orientation
= new wxString
[2],
2059 *print_modes
= new wxString
[3];
2061 long wx_printer_translate_x
, wx_printer_translate_y
;
2062 double wx_printer_scale_x
, wx_printer_scale_y
;
2064 orientation
[0] = _("Portrait");
2065 orientation
[1] = _("Landscape");
2067 print_modes
[0] = _("Send to Printer");
2068 print_modes
[1] = _("Print to File");
2069 print_modes
[2] = _("Preview Only");
2073 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2074 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2075 okBut
->SetDefault();
2078 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2079 (void) new wxStaticText( this, -1, _("Printer Command: "),
2081 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2082 wxPoint(100, yPos
), wxSize(100, -1) );
2084 (void) new wxStaticText( this, -1, _("Printer Options: "),
2085 wxPoint(210, yPos
) );
2086 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2087 wxPoint(305, yPos
), wxSize(150, -1) );
2093 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2095 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2097 // @@@ Configuration hook
2098 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
2099 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2101 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
2103 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
2104 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2106 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2108 wxSize(-1,-1), features
,
2109 print_modes
, features
, 0);
2112 radio1
->Enable(0, FALSE
);
2113 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2114 radio1
->Enable(2, FALSE
);
2117 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2118 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2119 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2121 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2124 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2125 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2127 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2128 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2129 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2133 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2134 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
2135 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2137 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2138 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
2139 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2143 delete[] orientation
;
2144 delete[] print_modes
;
2149 int wxPostScriptPrintDialog::ShowModal ()
2151 if ( wxDialog::ShowModal() == wxID_OK
)
2153 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2154 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2155 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2156 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2157 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2158 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2159 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2160 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2162 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
2163 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
2164 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
2165 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
2168 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2169 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2172 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
2175 switch ( radio1
->GetSelection() ) {
2176 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2177 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2178 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2185 // PostScript printer settings
2186 // RETAINED FOR BACKWARD COMPATIBILITY
2187 void wxSetPrinterCommand(const char *cmd
)
2189 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2192 void wxSetPrintPreviewCommand(const char *cmd
)
2194 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2197 void wxSetPrinterOptions(const char *flags
)
2199 wxThePrintSetupData
->SetPrinterOptions(flags
);
2202 void wxSetPrinterFile(const char *f
)
2204 wxThePrintSetupData
->SetPrinterFile(f
);
2207 void wxSetPrinterOrientation(int orient
)
2209 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2212 void wxSetPrinterScaling(double x
, double y
)
2214 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2217 void wxSetPrinterTranslation(long x
, long y
)
2219 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2222 // 1 = Preview, 2 = print to file, 3 = send to printer
2223 void wxSetPrinterMode(int mode
)
2225 wxThePrintSetupData
->SetPrinterMode(mode
);
2228 void wxSetAFMPath(const char *f
)
2230 wxThePrintSetupData
->SetAFMPath(f
);
2233 // Get current values
2234 char *wxGetPrinterCommand()
2236 return wxThePrintSetupData
->GetPrinterCommand();
2239 char *wxGetPrintPreviewCommand()
2241 return wxThePrintSetupData
->GetPrintPreviewCommand();
2244 char *wxGetPrinterOptions()
2246 return wxThePrintSetupData
->GetPrinterOptions();
2249 char *wxGetPrinterFile()
2251 return wxThePrintSetupData
->GetPrinterFile();
2254 int wxGetPrinterOrientation()
2256 return wxThePrintSetupData
->GetPrinterOrientation();
2259 void wxGetPrinterScaling(double* x
, double* y
)
2261 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2264 void wxGetPrinterTranslation(long *x
, long *y
)
2266 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2269 int wxGetPrinterMode()
2271 return wxThePrintSetupData
->GetPrinterMode();
2274 char *wxGetAFMPath()
2276 return wxThePrintSetupData
->GetAFMPath();
2283 wxPrintSetupData::wxPrintSetupData()
2285 printerCommand
= (char *) NULL
;
2286 previewCommand
= (char *) NULL
;
2287 printerFlags
= (char *) NULL
;
2288 printerOrient
= PS_PORTRAIT
;
2289 printerScaleX
= (double)1.0;
2290 printerScaleY
= (double)1.0;
2291 printerTranslateX
= 0;
2292 printerTranslateY
= 0;
2293 // 1 = Preview, 2 = print to file, 3 = send to printer
2295 afmPath
= (char *) NULL
;
2296 paperName
= (char *) NULL
;
2298 printerFile
= (char *) NULL
;
2301 wxPrintSetupData::~wxPrintSetupData()
2304 delete[] printerCommand
;
2306 delete[] previewCommand
;
2308 delete[] printerFlags
;
2314 delete[] printerFile
;
2317 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2319 if (cmd
== printerCommand
)
2323 delete[] printerCommand
;
2325 printerCommand
= copystring(cmd
);
2327 printerCommand
= (char *) NULL
;
2330 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2332 if (cmd
== previewCommand
)
2336 delete[] previewCommand
;
2338 previewCommand
= copystring(cmd
);
2340 previewCommand
= (char *) NULL
;
2343 void wxPrintSetupData::SetPaperName(const char *name
)
2345 if (name
== paperName
)
2351 paperName
= copystring(name
);
2353 paperName
= (char *) NULL
;
2356 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2358 if (printerFlags
== flags
)
2362 delete[] printerFlags
;
2364 printerFlags
= copystring(flags
);
2366 printerFlags
= (char *) NULL
;
2369 void wxPrintSetupData::SetPrinterFile(const char *f
)
2371 if (f
== printerFile
)
2375 delete[] printerFile
;
2377 printerFile
= copystring(f
);
2379 printerFile
= (char *) NULL
;
2382 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2384 printerOrient
= orient
;
2387 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2393 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2395 printerTranslateX
= x
;
2396 printerTranslateY
= y
;
2399 // 1 = Preview, 2 = print to file, 3 = send to printer
2400 void wxPrintSetupData::SetPrinterMode(int mode
)
2405 void wxPrintSetupData::SetAFMPath(const char *f
)
2413 afmPath
= copystring(f
);
2415 afmPath
= (char *) NULL
;
2418 void wxPrintSetupData::SetColour(bool col
)
2423 // Get current values
2424 char *wxPrintSetupData::GetPrinterCommand()
2426 return printerCommand
;
2429 char *wxPrintSetupData::GetPrintPreviewCommand()
2431 return previewCommand
;
2434 char *wxPrintSetupData::GetPrinterOptions()
2436 return printerFlags
;
2439 char *wxPrintSetupData::GetPrinterFile()
2444 char *wxPrintSetupData::GetPaperName()
2449 int wxPrintSetupData::GetPrinterOrientation()
2451 return printerOrient
;
2454 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2460 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2462 *x
= printerTranslateX
;
2463 *y
= printerTranslateY
;
2466 int wxPrintSetupData::GetPrinterMode()
2471 char *wxPrintSetupData::GetAFMPath()
2476 bool wxPrintSetupData::GetColour()
2481 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2483 SetPrinterCommand(data
.GetPrinterCommand());
2484 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2485 SetPrinterOptions(data
.GetPrinterOptions());
2487 data
.GetPrinterTranslation(&x
, &y
);
2488 SetPrinterTranslation(x
, y
);
2491 data
.GetPrinterScaling(&x1
, &y1
);
2492 SetPrinterScaling(x1
, y1
);
2494 SetPrinterOrientation(data
.GetPrinterOrientation());
2495 SetPrinterMode(data
.GetPrinterMode());
2496 SetAFMPath(data
.GetAFMPath());
2497 SetPaperName(data
.GetPaperName());
2498 SetColour(data
.GetColour());
2501 void wxInitializePrintSetupData(bool init
)
2505 wxThePrintSetupData
= new wxPrintSetupData
;
2507 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2508 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2509 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2510 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2512 // Could have a .ini file to read in some defaults
2513 // - and/or use environment variables, e.g. WXWIN
2515 wxThePrintSetupData
->SetPrinterCommand("print");
2516 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2517 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2520 wxThePrintSetupData
->SetPrinterCommand("print");
2521 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2522 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2524 #if !defined(__VMS__) && !defined(__WXMSW__)
2525 wxThePrintSetupData
->SetPrinterCommand("lpr");
2526 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2527 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2532 if (wxThePrintSetupData
)
2533 delete wxThePrintSetupData
;
2534 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2539 * Paper size database for PostScript
2542 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2548 pageName
= copystring(name
);
2551 wxPrintPaperType::~wxPrintPaperType()
2557 * Print paper database for PostScript
2560 #if !USE_SHARED_LIBRARIES
2561 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
2564 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2566 DeleteContents(TRUE
);
2569 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2573 void wxPrintPaperDatabase::CreateDatabase()
2575 // Need correct values for page size in pixels.
2576 // Each unit is one 'point' = 1/72 of an inch.
2577 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2578 // in wxPostScriptDC code, so we can start from top left.
2579 // So access this database and translate by appropriate number
2580 // of points for this paper size. OR IS IT OK ALREADY?
2581 // Can't remember where the PostScript origin is by default.
2582 // Heck, someone will know how to make it hunky-dory...
2585 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2586 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2587 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2588 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2591 void wxPrintPaperDatabase::ClearDatabase()
2596 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2598 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2601 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2603 wxNode
*node
= Find(name
);
2605 return (wxPrintPaperType
*)node
->Data();
2607 return (wxPrintPaperType
*) NULL
;
2611 * Initialization/cleanup module
2614 bool wxPostScriptModule::OnInit()
2616 wxInitializePrintSetupData();
2617 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2618 wxThePrintPaperDatabase
->CreateDatabase();
2623 void wxPostScriptModule::OnExit()
2625 wxInitializePrintSetupData(FALSE
);
2626 delete wxThePrintPaperDatabase
;
2627 wxThePrintPaperDatabase
= NULL
;