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 #if !USE_SHARED_LIBRARY
128 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
129 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
130 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
131 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
136 // these should move into wxPostscriptDC:
137 double UnderlinePosition
= 0.0F
;
138 double UnderlineThickness
= 0.0F
;
140 #define _MAXPATHLEN 500
142 /* See "wxspline.inc" and "xfspline.inc" */
143 #if wxUSE_XFIG_SPLINE_CODE
144 static const char *wxPostScriptHeaderSpline
= " \
145 /DrawSplineSection {\n\
152 /xa x1 x2 x1 sub 0.666667 mul add def\n\
153 /ya y1 y2 y1 sub 0.666667 mul add def\n\
154 /xb x3 x2 x3 sub 0.666667 mul add def\n\
155 /yb y3 y2 y3 sub 0.666667 mul add def\n\
157 xa ya xb yb x3 y3 curveto\n\
161 // No extra PS header for this spline implementation.
162 static const char *wxPostScriptHeaderSpline
= (char *) NULL
;
164 #endif /* wxUSE_XFIG_SPLINE_CODE */
167 // VMS has a bug in the ofstream class.
168 // the buffering doesn't work correctly. therefore
169 // we will allocate (temporarily) a very big buffer (1MB), so
170 // that a buffer overflow will not occur.
172 #define VMS_BUFSIZ (1024L*1024L)
173 static char *fileBuffer
= NULL
;
176 wxPostScriptDC::wxPostScriptDC ()
178 // m_yOrigin = 792; // For EPS output
179 m_yOrigin
= 842; // For A4 output
187 m_pstream
= (ofstream
*) NULL
;
190 // Can only send to file in Windows
191 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
195 m_currentGreen
= 255;
199 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
201 Create(file
, interactive
, parent
);
204 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
206 m_isInteractive
= interactive
;
208 m_yOrigin
= 792; // For EPS output
209 // m_yOrigin = 842; // For A4 output
217 m_pstream
= (ofstream
*) NULL
;
220 // Can only send to file in Windows
221 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
226 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
232 m_currentGreen
= 255;
240 wxPostScriptDC::~wxPostScriptDC ()
246 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
248 wxPostScriptPrintDialog
dialog (parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
249 m_ok
= (dialog
.ShowModal () == wxID_OK
) ;
254 if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
|| wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
258 wxThePrintSetupData
->SetPrinterFile("preview");
260 // For PS_PRINTER action this depends on a Unix-style print spooler
261 // since the wx_printer_file can be destroyed during a session
262 // @@@ TODO: a Windows-style answer for non-Unix
264 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
266 strcpy (tmp
, "/tmp/preview_");
267 strcat (tmp
, userId
);
268 wxThePrintSetupData
->SetPrinterFile(tmp
);
271 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
272 strcat (tmp2
, ".ps");
273 wxThePrintSetupData
->SetPrinterFile(tmp2
);
276 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
278 char *file
= wxSaveFileSelector (_("PostScript"), "ps");
284 wxThePrintSetupData
->SetPrinterFile(file
);
292 void wxPostScriptDC::SetClippingRegion (long cx
, long cy
, long cw
, long ch
)
300 *m_pstream
<< "gsave\n";
301 *m_pstream
<< "newpath\n";
302 *m_pstream
<< cx
<< " " << YSCALE (cy
) << " moveto\n";
303 *m_pstream
<< (cx
+ cw
) << " " << YSCALE (cy
) << " lineto\n";
304 *m_pstream
<< cx
+ cw
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
305 *m_pstream
<< cx
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
306 *m_pstream
<< "closepath clip newpath\n";
309 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
313 void wxPostScriptDC::DestroyClippingRegion ()
320 *m_pstream
<< "grestore\n";
324 void wxPostScriptDC::Clear ()
328 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
332 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
337 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
341 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
347 *m_pstream
<< "newpath\n";
348 *m_pstream
<< x1
<< " " << YSCALE (y1
) << " moveto\n";
349 *m_pstream
<< x2
<< " " << YSCALE (y2
) << " lineto\n";
350 *m_pstream
<< "stroke\n";
351 CalcBoundingBox (x1
, (long)YSCALE (y1
));
352 CalcBoundingBox (x2
, (long)YSCALE (y2
));
355 #define RAD2DEG 57.29577951308
357 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
364 long radius
= (long) sqrt((double) (dx
*dx
+dy
*dy
));
365 double alpha1
, alpha2
;
367 if (x1
== x2
&& y1
== y2
) {
370 } else if (radius
== 0.0) {
371 alpha1
= alpha2
= 0.0;
373 alpha1
= (x1
- xc
== 0) ?
374 (y1
- yc
< 0) ? 90.0 : -90.0 :
375 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
376 alpha2
= (x2
- xc
== 0) ?
377 (y2
- yc
< 0) ? 90.0 : -90.0 :
378 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
380 while (alpha1
<= 0) alpha1
+= 360;
381 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
382 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
383 while (alpha2
> 360) alpha2
-= 360;
385 if (m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
) {
387 *m_pstream
<< "newpath\n"
388 << xc
<< " " << YSCALE(yc
) << " "
389 << radius
<< " " << radius
<< " "
390 << alpha1
<< " " << alpha2
<< " ellipse\n"
391 << xc
<< " " << YSCALE(yc
) << " lineto\n"
395 if (m_pen
.Ok() && m_pen
.GetStyle() != wxTRANSPARENT
) {
397 *m_pstream
<< "newpath\n"
398 << xc
<< " " << YSCALE(yc
) << " "
399 << radius
<< " " << radius
<< " "
400 << alpha1
<< " " << alpha2
<< " ellipse\n"
403 CalcBoundingBox(x1
, (long)YSCALE(y1
));
404 CalcBoundingBox(x2
, (long)YSCALE(y2
));
407 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
412 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
413 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
418 DrawEllipse(x
,y
,w
,h
);
422 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
428 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
429 w
/2 << " " << (h
/2) << " " <<
430 int(sa
) <<" "<< int(ea
)<<" true ellipticarc\n";
432 CalcBoundingBox (x
, (long)YSCALE (y
));
433 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
435 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
441 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
442 (w
/2) << " " << (h
/2) << " " <<
443 int(sa
) <<" "<< int(ea
)<<" false ellipticarc\n";
445 CalcBoundingBox (x
, (long)YSCALE (y
));
446 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
450 void wxPostScriptDC::DrawPoint (long x
, long y
)
456 *m_pstream
<< "newpath\n";
457 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
458 *m_pstream
<< (x
+1) << " " << YSCALE (y
) << " lineto\n";
459 *m_pstream
<< "stroke\n";
460 CalcBoundingBox (x
, (long)YSCALE (y
));
463 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
469 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
472 *m_pstream
<< "newpath\n";
474 long xx
= points
[0].x
+ xoffset
;
475 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
476 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
477 CalcBoundingBox (xx
, yy
);
480 for (i
= 1; i
< n
; i
++)
482 xx
= points
[i
].x
+ xoffset
;
483 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
484 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
485 CalcBoundingBox (xx
, yy
);
487 *m_pstream
<< "fill\n";
490 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
493 *m_pstream
<< "newpath\n";
495 long xx
= points
[0].x
+ xoffset
;
496 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
497 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
498 CalcBoundingBox (xx
, yy
);
501 for (i
= 1; i
< n
; i
++)
503 xx
= points
[i
].x
+ xoffset
;
504 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
505 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
506 CalcBoundingBox (xx
, yy
);
510 xx
= points
[0].x
+ xoffset
;
511 yy
= (long) YSCALE (points
[0].y
+ yoffset
);
512 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
515 *m_pstream
<< "stroke\n";
520 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
529 *m_pstream
<< "newpath\n";
531 long xx
= points
[0].x
+ xoffset
;
532 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
533 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
534 CalcBoundingBox (xx
, yy
);
537 for (i
= 1; i
< n
; i
++)
539 xx
= points
[i
].x
+ xoffset
;
540 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
541 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
542 CalcBoundingBox (xx
, yy
);
544 *m_pstream
<< "stroke\n";
548 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
552 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
556 *m_pstream
<< "newpath\n";
557 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
558 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
559 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
560 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
561 *m_pstream
<< "closepath\n";
562 *m_pstream
<< "fill\n";
564 CalcBoundingBox (x
, (long)YSCALE (y
));
565 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
567 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
571 *m_pstream
<< "newpath\n";
572 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
573 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
574 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
575 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
576 *m_pstream
<< "closepath\n";
577 *m_pstream
<< "stroke\n";
579 CalcBoundingBox (x
, (long)YSCALE (y
));
580 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
584 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
591 // Now, a negative radius is interpreted to mean
592 // 'the proportion of the smallest X or Y dimension'
593 double smallest
= 0.0;
598 radius
= (-radius
* smallest
);
601 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
604 // Draw rectangle anticlockwise
605 *m_pstream
<< "newpath\n";
606 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
608 *m_pstream
<< x
<< " " << YSCALE (y
+ radius
) << " moveto\n";
610 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
611 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
613 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
614 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
616 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
618 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
620 *m_pstream
<< "closepath\n";
622 *m_pstream
<< "fill\n";
624 CalcBoundingBox (x
, (long)YSCALE (y
));
625 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
627 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
630 // Draw rectangle anticlockwise
631 *m_pstream
<< "newpath\n";
632 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
634 *m_pstream
<< x
<< " " << YSCALE (y
+ height
- radius
) << " lineto\n";
636 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
637 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
639 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
640 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
642 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
644 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
646 *m_pstream
<< "closepath\n";
648 *m_pstream
<< "stroke\n";
650 CalcBoundingBox (x
, (long)YSCALE (y
));
651 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
655 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
659 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
663 *m_pstream
<< "newpath\n";
664 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
665 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
666 *m_pstream
<< "fill\n";
668 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
669 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
671 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
675 *m_pstream
<< "newpath\n";
676 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
677 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
678 *m_pstream
<< "stroke\n";
680 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
681 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
685 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
687 #if defined(__X__) || defined(__WXGTK__)
689 memDC
.SelectObject(icon
);
690 Blit(x
, y
, icon
.GetWidth(), icon
.GetHeight(), &memDC
, 0, 0);
694 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool useMask
)
698 void wxPostScriptDC::SetFont (const wxFont
& the_font
)
703 if (m_font
== the_font
)
713 const char *style
= "";
714 int Style
= m_font
.GetStyle ();
715 int Weight
= m_font
.GetWeight ();
717 switch (m_font
.GetFamily ())
727 // name = "/Times-Roman";
728 name
= "/Times"; // Altered by EDZ
731 name
= "/Zapf-Chancery-MediumItalic";
736 case wxDEFAULT
: // Sans Serif Font
737 name
= "/LucidaSans";
740 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
742 if (m_font
.GetFamily () == wxROMAN
)
747 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
750 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
752 if (m_font
.GetFamily () == wxROMAN
)
757 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
759 if (m_font
.GetFamily () == wxROMAN
)
760 style
= "-BoldItalic";
762 style
= "-BoldOblique";
764 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
766 if (m_font
.GetFamily () == wxROMAN
)
771 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
773 if (m_font
.GetFamily () == wxROMAN
)
774 style
= "-BoldItalic";
776 style
= "-BoldOblique";
783 *m_pstream
<< buf
<< " findfont\n";
784 *m_pstream
<< (m_font
.GetPointSize() * m_scaleFactor
) << " scalefont setfont\n";
787 void wxPostScriptDC::SetPen (const wxPen
& pen
)
792 int oldStyle
= m_pen
.GetStyle();
800 *m_pstream
<< m_pen
.GetWidth () << " setlinewidth\n";
802 // Line style - WRONG: 2nd arg is OFFSET
804 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
805 operator correctly. You should look-up this in the Red Book: the 2nd parame-
806 ter is not number of values in the array of the first one, but an offset
807 into this description of the pattern. I mean a real *offset* not index
808 into array. I.e. If the command is [3 4] 1 setdash is used, then there
809 will be first black line *2* units long, then space 4 units, then the
810 pattern of *3* units black, 4 units space will be repeated.
812 static const char *dotted
= "[2 5] 2";
813 static const char *short_dashed
= "[4 4] 2";
814 static const char *long_dashed
= "[4 8] 2";
815 static const char *dotted_dashed
= "[6 6 2 6] 4";
817 const char *psdash
= (char *) NULL
;
818 switch (m_pen
.GetStyle ())
824 psdash
= short_dashed
;
827 psdash
= long_dashed
;
830 psdash
= dotted_dashed
;
838 if (oldStyle
!= m_pen
.GetStyle())
839 *m_pstream
<< psdash
<< " setdash\n";
842 unsigned char red
= m_pen
.GetColour ().Red ();
843 unsigned char blue
= m_pen
.GetColour ().Blue ();
844 unsigned char green
= m_pen
.GetColour ().Green ();
848 // Anything not white is black
849 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
850 && green
== (unsigned char) 255))
852 red
= (unsigned char) 0;
853 green
= (unsigned char) 0;
854 blue
= (unsigned char) 0;
858 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
860 long redPS
= (long) (((int) red
) / 255.0);
861 long bluePS
= (long) (((int) blue
) / 255.0);
862 long greenPS
= (long) (((int) green
) / 255.0);
864 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
867 m_currentBlue
= blue
;
868 m_currentGreen
= green
;
872 void wxPostScriptDC::SetBrush (const wxBrush
& brush
)
883 unsigned char red
= m_brush
.GetColour ().Red ();
884 unsigned char blue
= m_brush
.GetColour ().Blue ();
885 unsigned char green
= m_brush
.GetColour ().Green ();
889 // Anything not black is white
890 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
891 && green
== (unsigned char) 0))
893 red
= (unsigned char) 255;
894 green
= (unsigned char) 255;
895 blue
= (unsigned char) 255;
899 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
901 long redPS
= (long) (((int) red
) / 255.0);
902 long bluePS
= (long) (((int) blue
) / 255.0);
903 long greenPS
= (long) (((int) green
) / 255.0);
904 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
906 m_currentBlue
= blue
;
907 m_currentGreen
= green
;
911 void wxPostScriptDC::DrawText (const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
))
916 // TODO: SetFont checks for identity so this will always be a NULL operation
920 if (m_textForegroundColour
.Ok ())
922 unsigned char red
= m_textForegroundColour
.Red ();
923 unsigned char blue
= m_textForegroundColour
.Blue ();
924 unsigned char green
= m_textForegroundColour
.Green ();
928 // Anything not white is black
929 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
930 && green
== (unsigned char) 255))
932 red
= (unsigned char) 0;
933 green
= (unsigned char) 0;
934 blue
= (unsigned char) 0;
937 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
939 long redPS
= (long) (((int) red
) / 255.0);
940 long bluePS
= (long) (((int) blue
) / 255.0);
941 long greenPS
= (long) (((int) green
) / 255.0);
942 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
945 m_currentBlue
= blue
;
946 m_currentGreen
= green
;
952 size
= m_font
.GetPointSize ();
954 *m_pstream
<< x
<< " " << YSCALE (y
+ size
) << " moveto\n";
956 // *m_pstream << "(" << text << ")" << " show\n";
958 int len
= strlen ((char *)(const char *)text
);
960 for (i
= 0; i
< len
; i
++)
964 if (ch == ')' || ch == '(' || ch == '\\')
968 int c
= (unsigned char) text
[i
];
969 if ( c
== ')' || c
== '(' || c
== '\\')
971 *m_pstream
<< "\\" << (char) c
;
975 // Cope with character codes > 127
977 sprintf(tmp
, "\\%o", c
);
981 *m_pstream
<< (char) c
;
984 *m_pstream
<< ")" << " show\n";
986 if (m_font
.GetUnderlined())
989 GetTextExtent(text
, &w
, &h
);
990 *m_pstream
<< "gsave " << x
<< " " << YSCALE (y
+ size
- UnderlinePosition
)
992 << UnderlineThickness
<< " setlinewidth "
993 << (x
+ w
) << " " << YSCALE (y
+ size
- UnderlinePosition
)
994 << " lineto stroke grestore\n";
997 CalcBoundingBox (x
, (long)YSCALE (y
+ size
));
998 CalcBoundingBox (x
+ size
* strlen ((char *)(const char *)text
), (long)YSCALE (y
));
1002 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1004 m_backgroundBrush
= brush
;
1007 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1011 static const char *wxPostScriptHeaderEllipse
= "\
1012 /ellipsedict 8 dict def\n\
1013 ellipsedict /mtrx matrix put\n\
1015 { ellipsedict begin\n\
1016 /endangle exch def\n\
1017 /startangle exch def\n\
1022 /savematrix mtrx currentmatrix def\n\
1025 0 0 1 startangle endangle arc\n\
1026 savematrix setmatrix\n\
1031 static const char *wxPostScriptHeaderEllipticArc
= "\
1032 /ellipticarcdict 8 dict def\n\
1033 ellipticarcdict /mtrx matrix put\n\
1035 { ellipticarcdict begin\n\
1036 /do_fill exch def\n\
1037 /endangle exch def\n\
1038 /startangle exch def\n\
1043 /savematrix mtrx currentmatrix def\n\
1046 do_fill { 0 0 moveto } if\n\
1047 0 0 1 startangle endangle arc\n\
1048 savematrix setmatrix\n\
1049 do_fill { fill }{ stroke } ifelse\n\
1053 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1055 if (m_filename
== "")
1058 m_filename
= "wxtmp.ps";
1060 m_filename
= wxGetTempFileName("ps");
1062 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1066 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1071 m_pstream
= new ofstream
;
1072 if(fileBuffer
) delete[] fileBuffer
;
1073 fileBuffer
= new char[VMS_BUFSIZ
];
1074 m_pstream
->setbuf(fileBuffer
,VMS_BUFSIZ
);
1075 m_pstream
->open(wxThePrintSetupData
->GetPrinterFile());
1077 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1079 if (!m_pstream
|| !m_pstream
->good())
1081 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1087 SetBrush (*wxBLACK_BRUSH
);
1088 SetPen (*wxBLACK_PEN
);
1096 void wxPostScriptDC::EndDoc ()
1098 static char wxPostScriptHeaderReencodeISO1
[] =
1099 "\n/reencodeISO {\n"
1100 "dup dup findfont dup length dict begin\n"
1101 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
1102 "/Encoding ISOLatin1Encoding def\n"
1103 "currentdict end definefont\n"
1105 "/ISOLatin1Encoding [\n"
1106 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1107 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1108 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1109 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1110 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
1111 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
1112 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
1113 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
1114 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
1115 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
1116 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
1117 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1118 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1119 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
1120 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
1122 static char wxPostScriptHeaderReencodeISO2
[] =
1123 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
1124 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
1125 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
1126 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
1127 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
1128 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
1129 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
1130 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
1131 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
1132 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
1133 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
1134 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
1135 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
1136 "/yacute/thorn/ydieresis\n"
1144 *m_pstream
<< "grestore\n";
1147 // Will reuse m_pstream for header
1149 // see the definition of fileBuffer for explanation
1150 m_pstream
->close(); // steve, 05.09.94
1151 if(fileBuffer
) delete[] fileBuffer
;
1156 m_pstream
= (ofstream
*) NULL
;
1162 char *header_file
= "header.ps";
1164 char *header_file
= wxGetTempFileName("ps");
1166 m_pstream
= new ofstream (header_file
);
1168 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1169 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1170 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1171 // time_t when; time (&when);
1172 // *m_pstream << "%%CreationDate: " << ctime (&when);
1173 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1175 // User Id information
1177 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1179 *m_pstream
<< "%%For: " << (char *)userID
;
1181 if (wxGetUserName(userName
, sizeof(userName
)))
1182 *m_pstream
<< " (" << (char *)userName
<< ")";
1185 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1187 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1190 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1192 long wx_printer_translate_x
, wx_printer_translate_y
;
1193 double wx_printer_scale_x
, wx_printer_scale_y
;
1194 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1195 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1197 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1199 *m_pstream
<< "%%Orientation: Landscape\n";
1203 *m_pstream
<< "%%Orientation: Portrait\n";
1206 // Compute the bounding box. Note that it is in the default user
1207 // coordinate system, thus we have to convert the values.
1208 long llx
= (long) ((m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1209 long lly
= (long) ((m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1210 long urx
= (long) ((m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1211 long ury
= (long) ((m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1214 // If we're landscape, our sense of "x" and "y" is reversed.
1215 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1218 tmp
= llx
; llx
= lly
; lly
= tmp
;
1219 tmp
= urx
; urx
= ury
; ury
= tmp
;
1221 // We need either the two lines that follow, or we need to subtract
1222 // min_x from real_translate_y, which is commented out below.
1223 llx
= llx
- m_minX
*wx_printer_scale_y
;
1224 urx
= urx
- m_minX
*wx_printer_scale_y
;
1228 // The Adobe specifications call for integers; we round as to make
1229 // the bounding larger.
1230 *m_pstream
<< "%%BoundingBox: "
1231 << floor((double)llx
) << " " << floor((double)lly
) << " "
1232 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1233 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1234 *m_pstream
<< "%%EndComments\n\n";
1236 // To check the correctness of the bounding box, postscript commands
1237 // to draw a box corresponding to the bounding box are generated below.
1238 // But since we typically don't want to print such a box, the postscript
1239 // commands are generated within comments. These lines appear before any
1240 // adjustment of scale, rotation, or translation, and hence are in the
1241 // default user coordinates.
1242 *m_pstream
<< "% newpath\n";
1243 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1244 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1245 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1246 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1250 long real_translate_y
= wx_printer_translate_y
;
1251 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1253 real_translate_y
-= m_maxY
;
1254 // The following line can be used instead of the adjustment to
1255 // llx and urx above.
1256 // real_translate_y -= m_minX;
1257 *m_pstream
<< "90 rotate\n";
1260 /* Probably don't want this now we have it in EndPage, below.
1261 * We should rationalise the scaling code to one place. JACS, October 1995
1262 * Do we take the next 2 lines out or not?
1265 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1266 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1269 *m_pstream
<< "%%BeginProlog\n";
1270 *m_pstream
<< wxPostScriptHeaderEllipse
;
1271 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1272 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1273 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1275 if (wxPostScriptHeaderSpline
)
1276 *m_pstream
<< wxPostScriptHeaderSpline
;
1277 *m_pstream
<< "%%EndProlog\n";
1280 m_pstream
= (ofstream
*) NULL
;
1283 char *tmp_file
= "tmp.ps";
1285 char *tmp_file
= wxGetTempFileName("ps");
1288 // Paste header Before wx_printer_file
1289 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1290 wxRemoveFile (header_file
);
1291 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1292 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1294 #if defined(__X__) || defined(__WXGTK__)
1297 switch (wxThePrintSetupData
->GetPrinterMode()) {
1301 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1302 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1303 argv
[2] = (char *) NULL
;
1304 wxExecute (argv
, TRUE
);
1305 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1313 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1315 // !SM! If we simply assign to argv[1] here, if printer options
1316 // are blank, we get an annoying and confusing message from lpr.
1317 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1319 argv
[argc
++] = opts
;
1321 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1322 argv
[argc
++] = (char *) NULL
;
1323 wxExecute (argv
, TRUE
);
1324 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1335 void wxPostScriptDC::StartPage ()
1339 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1340 // *m_pstream << "matrix currentmatrix\n";
1342 // Added by Chris Breeze
1344 // Each page starts with an "initgraphics" which resets the
1345 // transformation and so we need to reset the origin
1346 // (and rotate the page for landscape printing)
1347 m_scaleFactor
= 1.0;
1348 m_logicalOriginX
= 0;
1349 m_logicalOriginY
= 0;
1352 long translate_x
, translate_y
;
1353 double scale_x
, scale_y
;
1354 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1355 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1357 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1359 translate_y
-= GetYOrigin();
1360 *m_pstream
<< "90 rotate\n";
1363 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1364 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1367 void wxPostScriptDC::EndPage ()
1371 *m_pstream
<< "showpage\n";
1373 // Removed by Chris Breeze
1375 *m_pstream
<< "setmatrix\n";
1377 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1379 long wx_printer_translate_x
, wx_printer_translate_y
;
1380 double wx_printer_scale_x
, wx_printer_scale_y
;
1381 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1382 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1384 // Compute the bounding box. Note that it is in the default user
1385 // coordinate system, thus we have to convert the values.
1386 long llx
= (m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1387 long lly
= (m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1388 long urx
= (m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1389 long ury
= (m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1391 // If we're landscape, our sense of "x" and "y" is reversed.
1392 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1395 tmp
= llx
; llx
= lly
; lly
= tmp
;
1396 tmp
= urx
; urx
= ury
; ury
= tmp
;
1398 // We need either the two lines that follow, or we need to subtract
1399 // m_minX from real_translate_y, which is commented out below.
1400 llx
= llx
- m_minX
*wx_printer_scale_y
;
1401 urx
= urx
- m_minX
*wx_printer_scale_y
;
1405 long real_translate_y
= wx_printer_translate_y
;
1406 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1408 real_translate_y
-= m_maxY
;
1409 // The following line can be used instead of the adjustment to
1410 // llx and urx above.
1411 // real_translate_y -= m_minX;
1412 *m_pstream
<< "90 rotate\n";
1415 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1416 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1420 bool wxPostScriptDC::
1421 Blit (long xdest
, long ydest
, long fwidth
, long fheight
,
1422 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(rop
), bool WXUNUSED(useMask
))
1424 long width
, height
, x
, y
;
1426 #if !defined(__X__) && !defined(__WXGTK__)
1430 if (!source
->IsKindOf(CLASSINFO(wxPaintDC
))) return FALSE
;
1432 width
= (long)floor((double)fwidth
);
1433 height
= (long)floor((double)fheight
);
1434 x
= (long)floor((double)xsrc
);
1435 y
= (long)floor((double)ysrc
);
1437 /* PostScript setup: */
1438 *m_pstream
<< "gsave\n";
1439 *m_pstream
<< xdest
<< " " << YSCALE(ydest
+ fheight
) << " translate\n";
1440 *m_pstream
<< fwidth
<< " " << fheight
<< " scale\n";
1441 *m_pstream
<< "/DataString " << width
<< " string def\n";
1442 *m_pstream
<< width
<< " " << height
<< " 8 [ ";
1443 *m_pstream
<< width
<< " 0 0 " << (-height
) << " 0 " << height
;
1444 *m_pstream
<< " ]\n{\n";
1445 *m_pstream
<< " currentfile DataString readhexstring pop\n";
1446 *m_pstream
<< "} bind image\n";
1448 #if defined(__X__) || defined(__WXGTK__)
1450 /* Output data as hex digits: */
1460 cm
= ((GdkColormapPrivate
*)gdk_colormap_get_system())->xcolormap
;
1461 GdkWindow
*gwin
= ((wxClientDC
*)source
)->GetWindow();
1462 image
= XGetImage(d
, ((GdkWindowPrivate
*)gwin
)->xwindow
, x
, y
, width
, height
, AllPlanes
, ZPixmap
);
1467 // TODO. for now, use global display
1468 // d = source->display;
1469 d
= (Display
*) wxGetDisplay();
1471 d
= (Display
*) wxGetDisplay();
1474 cm
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) d
);
1475 // TODO - implement GetPixmap() and uncomment this line
1476 // image = XGetImage(d, source->GetPixmap(), x, y, width, height, AllPlanes, ZPixmap);
1483 #define CM_CACHE_SIZE 256
1484 unsigned long cachesrc
[CM_CACHE_SIZE
];
1485 int cachedest
[CM_CACHE_SIZE
], cache_pos
= 0, all_cache
= FALSE
;
1487 for (j
= 0; j
< height
; j
++) {
1488 for (i
= 0; i
< width
; i
++) {
1490 unsigned long spixel
;
1492 const unsigned short MAX_COLOR
= 0xFFFF;
1494 spixel
= XGetPixel(image
, i
, j
);
1496 for (k
= cache_pos
; k
--; )
1497 if (cachesrc
[k
] == spixel
) {
1498 pixel
= cachedest
[k
];
1502 for (k
= CM_CACHE_SIZE
; k
-- > cache_pos
; )
1503 if (cachesrc
[k
] == spixel
) {
1504 pixel
= cachedest
[k
];
1508 cachesrc
[cache_pos
] = xcol
.pixel
= spixel
;
1509 XQueryColor(d
, cm
, &xcol
);
1513 r
= (long)((double)(xcol
.red
) / MAX_COLOR
);
1514 g
= (long)((double)(xcol
.green
) / MAX_COLOR
);
1515 b
= (long)((double)(xcol
.blue
) / MAX_COLOR
);
1517 pixel
= (int)(255 * sqrt(((r
* r
) + (g
* g
) + (b
* b
)) / 3));
1519 cachedest
[cache_pos
] = pixel
;
1521 if (++cache_pos
>= CM_CACHE_SIZE
) {
1529 h
= (pixel
>> 4) & 0xF;
1535 s
[0] = 'a' + (h
- 10);
1539 s
[1] = 'a' + (l
- 10);
1546 XDestroyImage(image
);
1549 *m_pstream
<< "grestore\n";
1551 CalcBoundingBox(xdest
, (long)YSCALE(ydest
));
1552 CalcBoundingBox(xdest
+ fwidth
, (long)YSCALE(ydest
+ fheight
));
1557 long wxPostScriptDC::GetCharHeight ()
1560 return m_font
.GetPointSize ();
1565 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1566 long *descent
, long *externalLeading
, wxFont
*theFont
,
1567 bool WXUNUSED(use16
))
1569 wxFont
*fontToUse
= theFont
;
1571 fontToUse
= (wxFont
*) &m_font
;
1575 #if !USE_AFM_FOR_POSTSCRIPT
1576 // Provide a VERY rough estimate (avoid using it)
1577 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1578 // font such as Courier (aka wxMODERN)
1582 height
= fontToUse
->GetPointSize();
1584 *x
= strlen (string
) * height
* 72 / 120;
1585 *y
= (long) (height
* 1.32); // allow for descender
1589 if (externalLeading
)
1590 *externalLeading
= 0;
1592 // +++++ start of contributed code +++++
1594 // ************************************************************
1595 // method for calculating string widths in postscript:
1596 // read in the AFM (adobe font metrics) file for the
1597 // actual font, parse it and extract the character widths
1598 // and also the descender. this may be improved, but for now
1599 // it works well. the AFM file is only read in if the
1600 // font is changed. this may be chached in the future.
1601 // calls to GetTextExtent with the font unchanged are rather
1604 // for each font and style used there is an AFM file necessary.
1605 // currently i have only files for the roman font family.
1606 // i try to get files for the other ones!
1608 // CAVE: the size of the string is currently always calculated
1609 // in 'points' (1/72 of an inch). this should later on be
1610 // changed to depend on the mapping mode.
1611 // CAVE: the path to the AFM files must be set before calling this
1612 // function. this is usually done by a call like the following:
1613 // wxSetAFMPath("d:\\wxw161\\afm\\");
1617 // wxPostScriptDC dc(NULL, TRUE);
1619 // wxSetAFMPath("d:\\wxw161\\afm\\");
1620 // dc.StartDoc("Test");
1623 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1624 // dc.GetTextExtent("Hallo",&w,&h);
1629 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1630 // created: 10.09.94
1631 // updated: 14.05.95
1633 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1634 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1635 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1637 // these static vars are for storing the state between calls
1638 static int lastFamily
= INT_MIN
;
1639 static int lastSize
= INT_MIN
;
1640 static int lastStyle
= INT_MIN
;
1641 static int lastWeight
= INT_MIN
;
1642 static int lastDescender
= INT_MIN
;
1643 static int lastWidths
[256]; // widths of the characters
1645 // get actual parameters
1646 const int Family
= fontToUse
->GetFamily();
1647 const int Size
= fontToUse
->GetPointSize();
1648 const int Style
= fontToUse
->GetStyle();
1649 const int Weight
= fontToUse
->GetWeight();
1651 // if we have another font, read the font-metrics
1652 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1653 // store actual values
1654 lastFamily
= Family
;
1657 lastWeight
= Weight
;
1659 // read in new font metrics **************************************
1661 // 1. construct filename ******************************************
1662 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1665 // Julian - we'll need to do this a different way now we've removed the
1666 // font directory system. Must find Stefan's original code.
1668 name
= wxTheFontNameDirectory
->GetAFMName(Family
, Weight
, Style
);
1672 // get the directory of the AFM files
1676 strcpy(afmName
,wxGetAFMPath());
1678 // 2. open and process the file **********************************
1680 // a short explanation of the AFM format:
1681 // we have for each character a line, which gives its size
1684 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1686 // that means, we have a character with ascii code 63, and width
1687 // (444/1000 * fontSize) points.
1688 // the other data is ignored for now!
1690 // when the font has changed, we read in the right AFM file and store the
1691 // character widths in an array, which is processed below (see point 3.).
1693 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1696 strcat(afmName
,name
);
1697 strcat(afmName
,".afm");
1698 FILE *afmFile
= fopen(afmName
,"r");
1700 wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1701 wxDebugMsg(" using approximate values\n");
1703 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1704 lastDescender
= -150; // dito.
1707 // init the widths array
1708 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1709 // some variables for holding parts of a line
1710 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1711 char upString
[30], utString
[30], encString
[50];
1714 // read in the file and parse it
1715 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1716 // A.) check for descender definition
1717 if(strncmp(line
,"Descender",9)==0){
1718 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1719 || (strcmp(descString
,"Descender")!=0)) {
1720 wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n",
1724 // JC 1.) check for UnderlinePosition
1725 else if(strncmp(line
,"UnderlinePosition",17)==0){
1726 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1727 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1728 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1732 // JC 2.) check for UnderlineThickness
1733 else if(strncmp(line
,"UnderlineThickness",18)==0){
1734 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1735 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1736 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1740 // JC 3.) check for EncodingScheme
1741 else if(strncmp(line
,"EncodingScheme",14)==0){
1742 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1743 || (strcmp(utString
,"EncodingScheme")!=0)) {
1744 wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1747 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1749 wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1750 afmName
,line
, encString
);
1753 // B.) check for char-width
1754 else if(strncmp(line
,"C ",2)==0){
1755 if(sscanf(line
,"%s%d%s%s%d",
1756 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1757 wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1759 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1760 strcmp(WXString
,"WX")!=0){
1761 wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1763 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1764 if(ascii
>=0 && ascii
<256){
1765 lastWidths
[ascii
] = cWidth
; // store width
1767 /* MATTHEW: this happens a lot; don't print an error */
1768 // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1771 // C.) ignore other entries.
1775 // hack to compute correct values for german 'Umlaute'
1776 // the correct way would be to map the character names
1777 // like 'adieresis' to corresp. positions of ISOEnc and read
1778 // these values from AFM files, too. Maybe later ...
1779 lastWidths
[196] = lastWidths
['A']; // Ä
1780 lastWidths
[228] = lastWidths
['a']; // ä
1781 lastWidths
[214] = lastWidths
['O']; // Ö
1782 lastWidths
[246] = lastWidths
['o']; // ö
1783 lastWidths
[220] = lastWidths
['U']; // Ü
1784 lastWidths
[252] = lastWidths
['u']; // ü
1785 lastWidths
[223] = lastWidths
[251]; // ß
1788 // JC: calculate UnderlineThickness/UnderlinePosition
1789 UnderlinePosition
= UnderlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1790 UnderlineThickness
= UnderlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1792 // 3. now the font metrics are read in, calc size *******************
1793 // this is done by adding the widths of the characters in the
1794 // string. they are given in 1/1000 of the size!
1797 long height
=Size
; // by default
1799 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1800 if(lastWidths
[*p
]== INT_MIN
){
1801 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1803 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1805 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1808 // add descender to height (it is usually a negative value)
1809 if(lastDescender
!=INT_MIN
){
1810 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1813 // return size values
1817 // return other parameters
1819 if(lastDescender
!=INT_MIN
){
1820 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1826 // currently no idea how to calculate this!
1827 // if (externalLeading) *externalLeading = 0;
1828 if (externalLeading
)
1829 *externalLeading
= 0;
1831 // ----- end of contributed code -----
1835 void wxPostScriptDC::DrawSpline( wxList
*points
)
1837 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1840 wxNode
*node
= points
->First();
1841 p
= (wxPoint
*)node
->Data();
1843 x1
= p
->x
; y1
= p
->y
;
1845 node
= node
->Next();
1846 p
= (wxPoint
*)node
->Data();
1848 x3
= a
= (double)(x1
+ c
) / 2;
1849 y3
= b
= (double)(y1
+ d
) / 2;
1851 *(GetStream()) << "newpath " << x1
<< " " << (GetYOrigin() - y1
) << " moveto " << x3
<< " " << (GetYOrigin() - y3
);
1852 *(GetStream()) << " lineto\n";
1853 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1854 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1856 while ((node
= node
->Next()) != NULL
)
1858 q
= (wxPoint
*)node
->Data();
1863 x3
= (double)(x2
+ c
) / 2;
1864 y3
= (double)(y2
+ d
) / 2;
1865 *(GetStream()) << x1
<< " " << (GetYOrigin() - y1
) << " " << x2
<< " " << (GetYOrigin() - y2
) << " ";
1866 *(GetStream()) << x3
<< " " << (GetYOrigin() - y3
) << " DrawSplineSection\n";
1868 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1869 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1872 * At this point, (x2,y2) and (c,d) are the position of the
1873 * next-to-last and last point respectively, in the point list
1875 *(GetStream()) << c
<< " " << (GetYOrigin() - d
) << " lineto stroke\n";
1878 long wxPostScriptDC::GetCharWidth ()
1880 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1881 return (long) (GetCharHeight() * 72.0 / 120.0);
1885 void wxPostScriptDC::SetMapMode (int mode
)
1887 m_mappingMode
= mode
;
1888 SetLogicalOrigin(0, 0);
1889 if(m_mappingMode
== MM_METRIC
)
1891 SetUserScale(72.0f
/ 25.4f
, 72.0f
/ 25.4f
);
1895 SetUserScale(1.0, 1.0);
1901 * Set the logical origin.
1902 * Actually we are setting the printer's origin and since
1903 * postscript transformations are cumulative we need to reset
1904 * the previous origin. We also need to allow for the user scale
1905 * factor (which affects printer coords but not logical)
1907 void wxPostScriptDC::SetLogicalOrigin(long x
, long y
)
1911 long xOffset
= (long) ((m_logicalOriginX
- x
) / m_scaleFactor
);
1912 long yOffset
= (long) ((y
- m_logicalOriginY
) / m_scaleFactor
);
1916 *m_pstream
<< xOffset
<< " " << yOffset
<< " translate\n";
1919 m_logicalOriginX
= x
;
1920 m_logicalOriginY
= y
;
1924 * Obsolete - now performed by SetUserScale() and SetLogicalOrigin()
1927 wxPostScriptDC::SetupCTM()
1932 * Set the user scale.
1933 * NB: Postscript transformations are cumulative and so we
1934 * need to take into account the current scale. Also, this
1935 * affects the logical origin
1937 void wxPostScriptDC::SetUserScale (double x
, double y
)
1939 // reset logical origin
1940 long xOrg
= m_logicalOriginX
;
1941 long yOrg
= m_logicalOriginY
;
1942 SetLogicalOrigin(0, 0);
1944 // set new scale factor
1948 factor
/= m_scaleFactor
;
1952 *m_pstream
<< factor
<< " " << factor
<< " scale\n";
1955 // set logical origin at new scale
1956 SetLogicalOrigin(xOrg
, yOrg
);
1961 m_scaleFactor
= m_userScaleX
;
1964 long wxPostScriptDC::DeviceToLogicalX (int x
) const
1969 long wxPostScriptDC::DeviceToLogicalXRel (int x
) const
1974 long wxPostScriptDC::DeviceToLogicalY (int y
) const
1979 long wxPostScriptDC::DeviceToLogicalYRel (int y
) const
1984 long wxPostScriptDC::LogicalToDeviceX (long x
) const
1989 long wxPostScriptDC::LogicalToDeviceXRel (long x
) const
1994 long wxPostScriptDC::LogicalToDeviceY (long y
) const
1999 long wxPostScriptDC::LogicalToDeviceYRel (long y
) const
2004 void wxPostScriptDC::GetSize(int* width
, int* height
) const
2006 const char *paperType
= wxThePrintSetupData
->GetPaperName();
2008 paperType
= _("A4 210 x 297 mm");
2010 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2012 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2015 *width
= paper
->widthPixels
;
2016 *height
= paper
->heightPixels
;
2025 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
2027 const char *paperType
= wxThePrintSetupData
->GetPaperName();
2029 paperType
= _("A4 210 x 297 mm");
2031 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2033 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2036 *width
= paper
->widthMM
;
2037 *height
= paper
->heightMM
;
2046 void wxPostScriptDC::CalcBoundingBox(long x
, long y
)
2048 long device_x
= (long) (x
- m_logicalOriginX
* m_scaleFactor
);
2049 long device_y
= (long) (y
+ m_logicalOriginY
* m_scaleFactor
);
2051 if (device_x
< m_minX
) m_minX
= device_x
;
2052 if (device_y
< m_minY
) m_minY
= device_y
;
2053 if (device_x
> m_maxX
) m_maxX
= device_x
;
2054 if (device_y
> m_maxY
) m_maxY
= device_y
;
2060 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2062 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2063 const wxPoint
& pos
, const wxSize
& size
, long style
):
2064 wxDialog(parent
, -1, title
, pos
, size
, style
)
2066 wxBeginBusyCursor();
2071 *orientation
= new wxString
[2],
2072 *print_modes
= new wxString
[3];
2074 long wx_printer_translate_x
, wx_printer_translate_y
;
2075 double wx_printer_scale_x
, wx_printer_scale_y
;
2077 orientation
[0] = _("Portrait");
2078 orientation
[1] = _("Landscape");
2080 print_modes
[0] = _("Send to Printer");
2081 print_modes
[1] = _("Print to File");
2082 print_modes
[2] = _("Preview Only");
2086 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2087 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2088 okBut
->SetDefault();
2091 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2092 (void) new wxStaticText( this, -1, _("Printer Command: "),
2094 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2095 wxPoint(100, yPos
), wxSize(100, -1) );
2097 (void) new wxStaticText( this, -1, _("Printer Options: "),
2098 wxPoint(210, yPos
) );
2099 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2100 wxPoint(305, yPos
), wxSize(150, -1) );
2106 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2108 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2110 // @@@ Configuration hook
2111 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
2112 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2114 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
2116 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
2117 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2119 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2121 wxSize(-1,-1), features
,
2122 print_modes
, features
, 0);
2125 radio1
->Enable(0, FALSE
);
2126 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2127 radio1
->Enable(2, FALSE
);
2130 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2131 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2132 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2134 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2137 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2138 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2140 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2141 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2142 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2146 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2147 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
2148 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2150 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2151 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
2152 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2156 delete[] orientation
;
2157 delete[] print_modes
;
2162 int wxPostScriptPrintDialog::ShowModal ()
2164 if ( wxDialog::ShowModal() == wxID_OK
)
2166 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2167 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2168 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2169 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2170 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2171 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2172 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2173 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2175 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
2176 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
2177 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
2178 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
2181 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2182 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2185 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
2188 switch ( radio1
->GetSelection() ) {
2189 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2190 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2191 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2198 // PostScript printer settings
2199 // RETAINED FOR BACKWARD COMPATIBILITY
2200 void wxSetPrinterCommand(const char *cmd
)
2202 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2205 void wxSetPrintPreviewCommand(const char *cmd
)
2207 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2210 void wxSetPrinterOptions(const char *flags
)
2212 wxThePrintSetupData
->SetPrinterOptions(flags
);
2215 void wxSetPrinterFile(const char *f
)
2217 wxThePrintSetupData
->SetPrinterFile(f
);
2220 void wxSetPrinterOrientation(int orient
)
2222 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2225 void wxSetPrinterScaling(double x
, double y
)
2227 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2230 void wxSetPrinterTranslation(long x
, long y
)
2232 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2235 // 1 = Preview, 2 = print to file, 3 = send to printer
2236 void wxSetPrinterMode(int mode
)
2238 wxThePrintSetupData
->SetPrinterMode(mode
);
2241 void wxSetAFMPath(const char *f
)
2243 wxThePrintSetupData
->SetAFMPath(f
);
2246 // Get current values
2247 char *wxGetPrinterCommand()
2249 return wxThePrintSetupData
->GetPrinterCommand();
2252 char *wxGetPrintPreviewCommand()
2254 return wxThePrintSetupData
->GetPrintPreviewCommand();
2257 char *wxGetPrinterOptions()
2259 return wxThePrintSetupData
->GetPrinterOptions();
2262 char *wxGetPrinterFile()
2264 return wxThePrintSetupData
->GetPrinterFile();
2267 int wxGetPrinterOrientation()
2269 return wxThePrintSetupData
->GetPrinterOrientation();
2272 void wxGetPrinterScaling(double* x
, double* y
)
2274 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2277 void wxGetPrinterTranslation(long *x
, long *y
)
2279 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2282 int wxGetPrinterMode()
2284 return wxThePrintSetupData
->GetPrinterMode();
2287 char *wxGetAFMPath()
2289 return wxThePrintSetupData
->GetAFMPath();
2296 wxPrintSetupData::wxPrintSetupData()
2298 printerCommand
= (char *) NULL
;
2299 previewCommand
= (char *) NULL
;
2300 printerFlags
= (char *) NULL
;
2301 printerOrient
= PS_PORTRAIT
;
2302 printerScaleX
= (double)1.0;
2303 printerScaleY
= (double)1.0;
2304 printerTranslateX
= 0;
2305 printerTranslateY
= 0;
2306 // 1 = Preview, 2 = print to file, 3 = send to printer
2308 afmPath
= (char *) NULL
;
2309 paperName
= (char *) NULL
;
2311 printerFile
= (char *) NULL
;
2314 wxPrintSetupData::~wxPrintSetupData()
2317 delete[] printerCommand
;
2319 delete[] previewCommand
;
2321 delete[] printerFlags
;
2327 delete[] printerFile
;
2330 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2332 if (cmd
== printerCommand
)
2336 delete[] printerCommand
;
2338 printerCommand
= copystring(cmd
);
2340 printerCommand
= (char *) NULL
;
2343 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2345 if (cmd
== previewCommand
)
2349 delete[] previewCommand
;
2351 previewCommand
= copystring(cmd
);
2353 previewCommand
= (char *) NULL
;
2356 void wxPrintSetupData::SetPaperName(const char *name
)
2358 if (name
== paperName
)
2364 paperName
= copystring(name
);
2366 paperName
= (char *) NULL
;
2369 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2371 if (printerFlags
== flags
)
2375 delete[] printerFlags
;
2377 printerFlags
= copystring(flags
);
2379 printerFlags
= (char *) NULL
;
2382 void wxPrintSetupData::SetPrinterFile(const char *f
)
2384 if (f
== printerFile
)
2388 delete[] printerFile
;
2390 printerFile
= copystring(f
);
2392 printerFile
= (char *) NULL
;
2395 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2397 printerOrient
= orient
;
2400 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2406 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2408 printerTranslateX
= x
;
2409 printerTranslateY
= y
;
2412 // 1 = Preview, 2 = print to file, 3 = send to printer
2413 void wxPrintSetupData::SetPrinterMode(int mode
)
2418 void wxPrintSetupData::SetAFMPath(const char *f
)
2426 afmPath
= copystring(f
);
2428 afmPath
= (char *) NULL
;
2431 void wxPrintSetupData::SetColour(bool col
)
2436 // Get current values
2437 char *wxPrintSetupData::GetPrinterCommand()
2439 return printerCommand
;
2442 char *wxPrintSetupData::GetPrintPreviewCommand()
2444 return previewCommand
;
2447 char *wxPrintSetupData::GetPrinterOptions()
2449 return printerFlags
;
2452 char *wxPrintSetupData::GetPrinterFile()
2457 char *wxPrintSetupData::GetPaperName()
2462 int wxPrintSetupData::GetPrinterOrientation()
2464 return printerOrient
;
2467 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2473 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2475 *x
= printerTranslateX
;
2476 *y
= printerTranslateY
;
2479 int wxPrintSetupData::GetPrinterMode()
2484 char *wxPrintSetupData::GetAFMPath()
2489 bool wxPrintSetupData::GetColour()
2494 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2496 SetPrinterCommand(data
.GetPrinterCommand());
2497 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2498 SetPrinterOptions(data
.GetPrinterOptions());
2500 data
.GetPrinterTranslation(&x
, &y
);
2501 SetPrinterTranslation(x
, y
);
2504 data
.GetPrinterScaling(&x1
, &y1
);
2505 SetPrinterScaling(x1
, y1
);
2507 SetPrinterOrientation(data
.GetPrinterOrientation());
2508 SetPrinterMode(data
.GetPrinterMode());
2509 SetAFMPath(data
.GetAFMPath());
2510 SetPaperName(data
.GetPaperName());
2511 SetColour(data
.GetColour());
2514 void wxInitializePrintSetupData(bool init
)
2518 wxThePrintSetupData
= new wxPrintSetupData
;
2520 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2521 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2522 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2523 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2525 // Could have a .ini file to read in some defaults
2526 // - and/or use environment variables, e.g. WXWIN
2528 wxThePrintSetupData
->SetPrinterCommand("print");
2529 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2530 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2533 wxThePrintSetupData
->SetPrinterCommand("print");
2534 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2535 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2537 #if !defined(__VMS__) && !defined(__WXMSW__)
2538 wxThePrintSetupData
->SetPrinterCommand("lpr");
2539 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2540 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2545 if (wxThePrintSetupData
)
2546 delete wxThePrintSetupData
;
2547 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2552 * Paper size database for PostScript
2555 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2561 pageName
= copystring(name
);
2564 wxPrintPaperType::~wxPrintPaperType()
2570 * Print paper database for PostScript
2573 #if !USE_SHARED_LIBRARIES
2574 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
2577 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2579 DeleteContents(TRUE
);
2582 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2586 void wxPrintPaperDatabase::CreateDatabase()
2588 // Need correct values for page size in pixels.
2589 // Each unit is one 'point' = 1/72 of an inch.
2590 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2591 // in wxPostScriptDC code, so we can start from top left.
2592 // So access this database and translate by appropriate number
2593 // of points for this paper size. OR IS IT OK ALREADY?
2594 // Can't remember where the PostScript origin is by default.
2595 // Heck, someone will know how to make it hunky-dory...
2598 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2599 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2600 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2601 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2606 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 210*4, 297*4 );
2607 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 297*4, 420*4 );
2608 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 216*4, 279*4 );
2609 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 216*4, 356*4 );
2613 void wxPrintPaperDatabase::ClearDatabase()
2618 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2620 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2623 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2625 wxNode
*node
= Find(name
);
2627 return (wxPrintPaperType
*)node
->Data();
2629 return (wxPrintPaperType
*) NULL
;
2633 * Initialization/cleanup module
2636 bool wxPostScriptModule::OnInit()
2638 wxInitializePrintSetupData();
2639 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2640 wxThePrintPaperDatabase
->CreateDatabase();
2645 void wxPostScriptModule::OnExit()
2647 wxInitializePrintSetupData(FALSE
);
2648 delete wxThePrintPaperDatabase
;
2649 wxThePrintPaperDatabase
= NULL
;