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::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
311 void wxPostScriptDC::DestroyClippingRegion ()
318 *m_pstream
<< "grestore\n";
322 void wxPostScriptDC::Clear ()
326 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
330 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
335 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
339 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
345 *m_pstream
<< "newpath\n";
346 *m_pstream
<< x1
<< " " << YSCALE (y1
) << " moveto\n";
347 *m_pstream
<< x2
<< " " << YSCALE (y2
) << " lineto\n";
348 *m_pstream
<< "stroke\n";
349 CalcBoundingBox (x1
, (long)YSCALE (y1
));
350 CalcBoundingBox (x2
, (long)YSCALE (y2
));
353 #define RAD2DEG 57.29577951308
355 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
362 long radius
= (long) sqrt((double) (dx
*dx
+dy
*dy
));
363 double alpha1
, alpha2
;
365 if (x1
== x2
&& y1
== y2
) {
368 } else if (radius
== 0.0) {
369 alpha1
= alpha2
= 0.0;
371 alpha1
= (x1
- xc
== 0) ?
372 (y1
- yc
< 0) ? 90.0 : -90.0 :
373 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
374 alpha2
= (x2
- xc
== 0) ?
375 (y2
- yc
< 0) ? 90.0 : -90.0 :
376 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
378 while (alpha1
<= 0) alpha1
+= 360;
379 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
380 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
381 while (alpha2
> 360) alpha2
-= 360;
383 if (m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
) {
385 *m_pstream
<< "newpath\n"
386 << xc
<< " " << YSCALE(yc
) << " "
387 << radius
<< " " << radius
<< " "
388 << alpha1
<< " " << alpha2
<< " ellipse\n"
389 << xc
<< " " << YSCALE(yc
) << " lineto\n"
393 if (m_pen
.Ok() && m_pen
.GetStyle() != wxTRANSPARENT
) {
395 *m_pstream
<< "newpath\n"
396 << xc
<< " " << YSCALE(yc
) << " "
397 << radius
<< " " << radius
<< " "
398 << alpha1
<< " " << alpha2
<< " ellipse\n"
401 CalcBoundingBox(x1
, (long)YSCALE(y1
));
402 CalcBoundingBox(x2
, (long)YSCALE(y2
));
405 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
410 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
411 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
416 DrawEllipse(x
,y
,w
,h
);
420 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
426 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
427 w
/2 << " " << (h
/2) << " " <<
428 int(sa
) <<" "<< int(ea
)<<" true ellipticarc\n";
430 CalcBoundingBox (x
, (long)YSCALE (y
));
431 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
433 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
439 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
440 (w
/2) << " " << (h
/2) << " " <<
441 int(sa
) <<" "<< int(ea
)<<" false ellipticarc\n";
443 CalcBoundingBox (x
, (long)YSCALE (y
));
444 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
448 void wxPostScriptDC::DrawPoint (long x
, long y
)
454 *m_pstream
<< "newpath\n";
455 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
456 *m_pstream
<< (x
+1) << " " << YSCALE (y
) << " lineto\n";
457 *m_pstream
<< "stroke\n";
458 CalcBoundingBox (x
, (long)YSCALE (y
));
461 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
467 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
470 *m_pstream
<< "newpath\n";
472 long xx
= points
[0].x
+ xoffset
;
473 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
474 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
475 CalcBoundingBox (xx
, yy
);
478 for (i
= 1; i
< n
; i
++)
480 xx
= points
[i
].x
+ xoffset
;
481 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
482 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
483 CalcBoundingBox (xx
, yy
);
485 *m_pstream
<< "fill\n";
488 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
491 *m_pstream
<< "newpath\n";
493 long xx
= points
[0].x
+ xoffset
;
494 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
495 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
496 CalcBoundingBox (xx
, yy
);
499 for (i
= 1; i
< n
; i
++)
501 xx
= points
[i
].x
+ xoffset
;
502 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
503 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
504 CalcBoundingBox (xx
, yy
);
508 xx
= points
[0].x
+ xoffset
;
509 yy
= (long) YSCALE (points
[0].y
+ yoffset
);
510 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
513 *m_pstream
<< "stroke\n";
518 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
527 *m_pstream
<< "newpath\n";
529 long xx
= points
[0].x
+ xoffset
;
530 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
531 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
532 CalcBoundingBox (xx
, yy
);
535 for (i
= 1; i
< n
; i
++)
537 xx
= points
[i
].x
+ xoffset
;
538 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
539 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
540 CalcBoundingBox (xx
, yy
);
542 *m_pstream
<< "stroke\n";
546 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
550 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
554 *m_pstream
<< "newpath\n";
555 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
556 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
557 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
558 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
559 *m_pstream
<< "closepath\n";
560 *m_pstream
<< "fill\n";
562 CalcBoundingBox (x
, (long)YSCALE (y
));
563 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
565 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
569 *m_pstream
<< "newpath\n";
570 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
571 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
572 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
573 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
574 *m_pstream
<< "closepath\n";
575 *m_pstream
<< "stroke\n";
577 CalcBoundingBox (x
, (long)YSCALE (y
));
578 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
582 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
589 // Now, a negative radius is interpreted to mean
590 // 'the proportion of the smallest X or Y dimension'
591 double smallest
= 0.0;
596 radius
= (-radius
* smallest
);
599 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
602 // Draw rectangle anticlockwise
603 *m_pstream
<< "newpath\n";
604 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
606 *m_pstream
<< x
<< " " << YSCALE (y
+ radius
) << " moveto\n";
608 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
609 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
611 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
612 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
614 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
616 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
618 *m_pstream
<< "closepath\n";
620 *m_pstream
<< "fill\n";
622 CalcBoundingBox (x
, (long)YSCALE (y
));
623 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
625 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
628 // Draw rectangle anticlockwise
629 *m_pstream
<< "newpath\n";
630 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
632 *m_pstream
<< x
<< " " << YSCALE (y
+ height
- radius
) << " lineto\n";
634 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
635 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
637 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
638 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
640 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
642 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
644 *m_pstream
<< "closepath\n";
646 *m_pstream
<< "stroke\n";
648 CalcBoundingBox (x
, (long)YSCALE (y
));
649 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
653 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
657 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
661 *m_pstream
<< "newpath\n";
662 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
663 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
664 *m_pstream
<< "fill\n";
666 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
667 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
669 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
673 *m_pstream
<< "newpath\n";
674 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
675 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
676 *m_pstream
<< "stroke\n";
678 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
679 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
683 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
685 #if defined(__X__) || defined(__WXGTK__)
687 memDC
.SelectObject(icon
);
688 Blit(x
, y
, icon
.GetWidth(), icon
.GetHeight(), &memDC
, 0, 0);
692 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool useMask
)
696 void wxPostScriptDC::SetFont (const wxFont
& the_font
)
701 if (m_font
== the_font
)
711 const char *style
= "";
712 int Style
= m_font
.GetStyle ();
713 int Weight
= m_font
.GetWeight ();
715 switch (m_font
.GetFamily ())
725 // name = "/Times-Roman";
726 name
= "/Times"; // Altered by EDZ
729 name
= "/Zapf-Chancery-MediumItalic";
734 case wxDEFAULT
: // Sans Serif Font
735 name
= "/LucidaSans";
738 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
740 if (m_font
.GetFamily () == wxROMAN
)
745 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
748 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
750 if (m_font
.GetFamily () == wxROMAN
)
755 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
757 if (m_font
.GetFamily () == wxROMAN
)
758 style
= "-BoldItalic";
760 style
= "-BoldOblique";
762 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
764 if (m_font
.GetFamily () == wxROMAN
)
769 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
771 if (m_font
.GetFamily () == wxROMAN
)
772 style
= "-BoldItalic";
774 style
= "-BoldOblique";
781 *m_pstream
<< buf
<< " findfont\n";
782 *m_pstream
<< (m_font
.GetPointSize() * m_scaleFactor
) << " scalefont setfont\n";
785 void wxPostScriptDC::SetPen (const wxPen
& pen
)
790 int oldStyle
= m_pen
.GetStyle();
798 *m_pstream
<< m_pen
.GetWidth () << " setlinewidth\n";
800 // Line style - WRONG: 2nd arg is OFFSET
802 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
803 operator correctly. You should look-up this in the Red Book: the 2nd parame-
804 ter is not number of values in the array of the first one, but an offset
805 into this description of the pattern. I mean a real *offset* not index
806 into array. I.e. If the command is [3 4] 1 setdash is used, then there
807 will be first black line *2* units long, then space 4 units, then the
808 pattern of *3* units black, 4 units space will be repeated.
810 static const char *dotted
= "[2 5] 2";
811 static const char *short_dashed
= "[4 4] 2";
812 static const char *long_dashed
= "[4 8] 2";
813 static const char *dotted_dashed
= "[6 6 2 6] 4";
815 const char *psdash
= (char *) NULL
;
816 switch (m_pen
.GetStyle ())
822 psdash
= short_dashed
;
825 psdash
= long_dashed
;
828 psdash
= dotted_dashed
;
836 if (oldStyle
!= m_pen
.GetStyle())
837 *m_pstream
<< psdash
<< " setdash\n";
840 unsigned char red
= m_pen
.GetColour ().Red ();
841 unsigned char blue
= m_pen
.GetColour ().Blue ();
842 unsigned char green
= m_pen
.GetColour ().Green ();
846 // Anything not white is black
847 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
848 && green
== (unsigned char) 255))
850 red
= (unsigned char) 0;
851 green
= (unsigned char) 0;
852 blue
= (unsigned char) 0;
856 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
858 long redPS
= (long) (((int) red
) / 255.0);
859 long bluePS
= (long) (((int) blue
) / 255.0);
860 long greenPS
= (long) (((int) green
) / 255.0);
862 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
865 m_currentBlue
= blue
;
866 m_currentGreen
= green
;
870 void wxPostScriptDC::SetBrush (const wxBrush
& brush
)
881 unsigned char red
= m_brush
.GetColour ().Red ();
882 unsigned char blue
= m_brush
.GetColour ().Blue ();
883 unsigned char green
= m_brush
.GetColour ().Green ();
887 // Anything not black is white
888 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
889 && green
== (unsigned char) 0))
891 red
= (unsigned char) 255;
892 green
= (unsigned char) 255;
893 blue
= (unsigned char) 255;
897 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
899 long redPS
= (long) (((int) red
) / 255.0);
900 long bluePS
= (long) (((int) blue
) / 255.0);
901 long greenPS
= (long) (((int) green
) / 255.0);
902 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
904 m_currentBlue
= blue
;
905 m_currentGreen
= green
;
909 void wxPostScriptDC::DrawText (const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
))
914 // TODO: SetFont checks for identity so this will always be a NULL operation
918 if (m_textForegroundColour
.Ok ())
920 unsigned char red
= m_textForegroundColour
.Red ();
921 unsigned char blue
= m_textForegroundColour
.Blue ();
922 unsigned char green
= m_textForegroundColour
.Green ();
926 // Anything not white is black
927 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
928 && green
== (unsigned char) 255))
930 red
= (unsigned char) 0;
931 green
= (unsigned char) 0;
932 blue
= (unsigned char) 0;
935 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
937 long redPS
= (long) (((int) red
) / 255.0);
938 long bluePS
= (long) (((int) blue
) / 255.0);
939 long greenPS
= (long) (((int) green
) / 255.0);
940 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
943 m_currentBlue
= blue
;
944 m_currentGreen
= green
;
950 size
= m_font
.GetPointSize ();
952 *m_pstream
<< x
<< " " << YSCALE (y
+ size
) << " moveto\n";
954 // *m_pstream << "(" << text << ")" << " show\n";
956 int len
= strlen ((char *)(const char *)text
);
958 for (i
= 0; i
< len
; i
++)
962 if (ch == ')' || ch == '(' || ch == '\\')
966 int c
= (unsigned char) text
[i
];
967 if ( c
== ')' || c
== '(' || c
== '\\')
969 *m_pstream
<< "\\" << (char) c
;
973 // Cope with character codes > 127
975 sprintf(tmp
, "\\%o", c
);
979 *m_pstream
<< (char) c
;
982 *m_pstream
<< ")" << " show\n";
984 if (m_font
.GetUnderlined())
987 GetTextExtent(text
, &w
, &h
);
988 *m_pstream
<< "gsave " << x
<< " " << YSCALE (y
+ size
- UnderlinePosition
)
990 << UnderlineThickness
<< " setlinewidth "
991 << (x
+ w
) << " " << YSCALE (y
+ size
- UnderlinePosition
)
992 << " lineto stroke grestore\n";
995 CalcBoundingBox (x
, (long)YSCALE (y
+ size
));
996 CalcBoundingBox (x
+ size
* strlen ((char *)(const char *)text
), (long)YSCALE (y
));
1000 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1002 m_backgroundBrush
= brush
;
1005 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1009 static const char *wxPostScriptHeaderEllipse
= "\
1010 /ellipsedict 8 dict def\n\
1011 ellipsedict /mtrx matrix put\n\
1013 { ellipsedict begin\n\
1014 /endangle exch def\n\
1015 /startangle exch def\n\
1020 /savematrix mtrx currentmatrix def\n\
1023 0 0 1 startangle endangle arc\n\
1024 savematrix setmatrix\n\
1029 static const char *wxPostScriptHeaderEllipticArc
= "\
1030 /ellipticarcdict 8 dict def\n\
1031 ellipticarcdict /mtrx matrix put\n\
1033 { ellipticarcdict begin\n\
1034 /do_fill exch def\n\
1035 /endangle exch def\n\
1036 /startangle exch def\n\
1041 /savematrix mtrx currentmatrix def\n\
1044 do_fill { 0 0 moveto } if\n\
1045 0 0 1 startangle endangle arc\n\
1046 savematrix setmatrix\n\
1047 do_fill { fill }{ stroke } ifelse\n\
1051 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1053 if (m_filename
== "")
1056 m_filename
= "wxtmp.ps";
1058 m_filename
= wxGetTempFileName("ps");
1060 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1064 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1069 m_pstream
= new ofstream
;
1070 if(fileBuffer
) delete[] fileBuffer
;
1071 fileBuffer
= new char[VMS_BUFSIZ
];
1072 m_pstream
->setbuf(fileBuffer
,VMS_BUFSIZ
);
1073 m_pstream
->open(wxThePrintSetupData
->GetPrinterFile());
1075 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1077 if (!m_pstream
|| !m_pstream
->good())
1079 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1085 SetBrush (*wxBLACK_BRUSH
);
1086 SetPen (*wxBLACK_PEN
);
1094 void wxPostScriptDC::EndDoc ()
1096 static char wxPostScriptHeaderReencodeISO1
[] =
1097 "\n/reencodeISO {\n"
1098 "dup dup findfont dup length dict begin\n"
1099 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
1100 "/Encoding ISOLatin1Encoding def\n"
1101 "currentdict end definefont\n"
1103 "/ISOLatin1Encoding [\n"
1104 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1105 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1106 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1107 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1108 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
1109 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
1110 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
1111 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
1112 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
1113 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
1114 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
1115 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1116 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1117 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
1118 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
1120 static char wxPostScriptHeaderReencodeISO2
[] =
1121 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
1122 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
1123 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
1124 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
1125 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
1126 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
1127 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
1128 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
1129 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
1130 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
1131 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
1132 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
1133 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
1134 "/yacute/thorn/ydieresis\n"
1142 *m_pstream
<< "grestore\n";
1145 // Will reuse m_pstream for header
1147 // see the definition of fileBuffer for explanation
1148 m_pstream
->close(); // steve, 05.09.94
1149 if(fileBuffer
) delete[] fileBuffer
;
1154 m_pstream
= (ofstream
*) NULL
;
1160 char *header_file
= "header.ps";
1162 char *header_file
= wxGetTempFileName("ps");
1164 m_pstream
= new ofstream (header_file
);
1166 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1167 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1168 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1169 // time_t when; time (&when);
1170 // *m_pstream << "%%CreationDate: " << ctime (&when);
1171 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1173 // User Id information
1175 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1177 *m_pstream
<< "%%For: " << (char *)userID
;
1179 if (wxGetUserName(userName
, sizeof(userName
)))
1180 *m_pstream
<< " (" << (char *)userName
<< ")";
1183 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1185 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1188 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1190 long wx_printer_translate_x
, wx_printer_translate_y
;
1191 double wx_printer_scale_x
, wx_printer_scale_y
;
1192 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1193 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1195 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1197 *m_pstream
<< "%%Orientation: Landscape\n";
1201 *m_pstream
<< "%%Orientation: Portrait\n";
1204 // Compute the bounding box. Note that it is in the default user
1205 // coordinate system, thus we have to convert the values.
1206 long llx
= (long) ((m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1207 long lly
= (long) ((m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1208 long urx
= (long) ((m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1209 long ury
= (long) ((m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1212 // If we're landscape, our sense of "x" and "y" is reversed.
1213 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1216 tmp
= llx
; llx
= lly
; lly
= tmp
;
1217 tmp
= urx
; urx
= ury
; ury
= tmp
;
1219 // We need either the two lines that follow, or we need to subtract
1220 // min_x from real_translate_y, which is commented out below.
1221 llx
= llx
- m_minX
*wx_printer_scale_y
;
1222 urx
= urx
- m_minX
*wx_printer_scale_y
;
1226 // The Adobe specifications call for integers; we round as to make
1227 // the bounding larger.
1228 *m_pstream
<< "%%BoundingBox: "
1229 << floor((double)llx
) << " " << floor((double)lly
) << " "
1230 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1231 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1232 *m_pstream
<< "%%EndComments\n\n";
1234 // To check the correctness of the bounding box, postscript commands
1235 // to draw a box corresponding to the bounding box are generated below.
1236 // But since we typically don't want to print such a box, the postscript
1237 // commands are generated within comments. These lines appear before any
1238 // adjustment of scale, rotation, or translation, and hence are in the
1239 // default user coordinates.
1240 *m_pstream
<< "% newpath\n";
1241 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1242 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1243 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1244 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1248 long real_translate_y
= wx_printer_translate_y
;
1249 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1251 real_translate_y
-= m_maxY
;
1252 // The following line can be used instead of the adjustment to
1253 // llx and urx above.
1254 // real_translate_y -= m_minX;
1255 *m_pstream
<< "90 rotate\n";
1258 /* Probably don't want this now we have it in EndPage, below.
1259 * We should rationalise the scaling code to one place. JACS, October 1995
1260 * Do we take the next 2 lines out or not?
1263 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1264 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1267 *m_pstream
<< "%%BeginProlog\n";
1268 *m_pstream
<< wxPostScriptHeaderEllipse
;
1269 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1270 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1271 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1273 if (wxPostScriptHeaderSpline
)
1274 *m_pstream
<< wxPostScriptHeaderSpline
;
1275 *m_pstream
<< "%%EndProlog\n";
1278 m_pstream
= (ofstream
*) NULL
;
1281 char *tmp_file
= "tmp.ps";
1283 char *tmp_file
= wxGetTempFileName("ps");
1286 // Paste header Before wx_printer_file
1287 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1288 wxRemoveFile (header_file
);
1289 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1290 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1292 #if defined(__X__) || defined(__WXGTK__)
1295 switch (wxThePrintSetupData
->GetPrinterMode()) {
1299 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1300 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1301 argv
[2] = (char *) NULL
;
1302 wxExecute (argv
, TRUE
);
1303 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1311 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1313 // !SM! If we simply assign to argv[1] here, if printer options
1314 // are blank, we get an annoying and confusing message from lpr.
1315 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1317 argv
[argc
++] = opts
;
1319 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1320 argv
[argc
++] = (char *) NULL
;
1321 wxExecute (argv
, TRUE
);
1322 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1333 void wxPostScriptDC::StartPage ()
1337 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1338 // *m_pstream << "matrix currentmatrix\n";
1340 // Added by Chris Breeze
1342 // Each page starts with an "initgraphics" which resets the
1343 // transformation and so we need to reset the origin
1344 // (and rotate the page for landscape printing)
1345 m_scaleFactor
= 1.0;
1346 m_logicalOriginX
= 0;
1347 m_logicalOriginY
= 0;
1350 long translate_x
, translate_y
;
1351 double scale_x
, scale_y
;
1352 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1353 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1355 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1357 translate_y
-= GetYOrigin();
1358 *m_pstream
<< "90 rotate\n";
1361 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1362 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1365 void wxPostScriptDC::EndPage ()
1369 *m_pstream
<< "showpage\n";
1371 // Removed by Chris Breeze
1373 *m_pstream
<< "setmatrix\n";
1375 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1377 long wx_printer_translate_x
, wx_printer_translate_y
;
1378 double wx_printer_scale_x
, wx_printer_scale_y
;
1379 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1380 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1382 // Compute the bounding box. Note that it is in the default user
1383 // coordinate system, thus we have to convert the values.
1384 long llx
= (m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1385 long lly
= (m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1386 long urx
= (m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1387 long ury
= (m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1389 // If we're landscape, our sense of "x" and "y" is reversed.
1390 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1393 tmp
= llx
; llx
= lly
; lly
= tmp
;
1394 tmp
= urx
; urx
= ury
; ury
= tmp
;
1396 // We need either the two lines that follow, or we need to subtract
1397 // m_minX from real_translate_y, which is commented out below.
1398 llx
= llx
- m_minX
*wx_printer_scale_y
;
1399 urx
= urx
- m_minX
*wx_printer_scale_y
;
1403 long real_translate_y
= wx_printer_translate_y
;
1404 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1406 real_translate_y
-= m_maxY
;
1407 // The following line can be used instead of the adjustment to
1408 // llx and urx above.
1409 // real_translate_y -= m_minX;
1410 *m_pstream
<< "90 rotate\n";
1413 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1414 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1418 bool wxPostScriptDC::
1419 Blit (long xdest
, long ydest
, long fwidth
, long fheight
,
1420 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(rop
), bool WXUNUSED(useMask
))
1422 long width
, height
, x
, y
;
1424 #if !defined(__X__) && !defined(__WXGTK__)
1428 if (!source
->IsKindOf(CLASSINFO(wxPaintDC
))) return FALSE
;
1430 width
= (long)floor((double)fwidth
);
1431 height
= (long)floor((double)fheight
);
1432 x
= (long)floor((double)xsrc
);
1433 y
= (long)floor((double)ysrc
);
1435 /* PostScript setup: */
1436 *m_pstream
<< "gsave\n";
1437 *m_pstream
<< xdest
<< " " << YSCALE(ydest
+ fheight
) << " translate\n";
1438 *m_pstream
<< fwidth
<< " " << fheight
<< " scale\n";
1439 *m_pstream
<< "/DataString " << width
<< " string def\n";
1440 *m_pstream
<< width
<< " " << height
<< " 8 [ ";
1441 *m_pstream
<< width
<< " 0 0 " << (-height
) << " 0 " << height
;
1442 *m_pstream
<< " ]\n{\n";
1443 *m_pstream
<< " currentfile DataString readhexstring pop\n";
1444 *m_pstream
<< "} bind image\n";
1446 #if defined(__X__) || defined(__WXGTK__)
1448 /* Output data as hex digits: */
1458 cm
= ((GdkColormapPrivate
*)gdk_colormap_get_system())->xcolormap
;
1459 GdkWindow
*gwin
= ((wxClientDC
*)source
)->GetWindow();
1460 image
= XGetImage(d
, ((GdkWindowPrivate
*)gwin
)->xwindow
, x
, y
, width
, height
, AllPlanes
, ZPixmap
);
1465 // TODO. for now, use global display
1466 // d = source->display;
1467 d
= (Display
*) wxGetDisplay();
1469 d
= (Display
*) wxGetDisplay();
1472 cm
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) d
);
1473 // TODO - implement GetPixmap() and uncomment this line
1474 // image = XGetImage(d, source->GetPixmap(), x, y, width, height, AllPlanes, ZPixmap);
1481 #define CM_CACHE_SIZE 256
1482 unsigned long cachesrc
[CM_CACHE_SIZE
];
1483 int cachedest
[CM_CACHE_SIZE
], cache_pos
= 0, all_cache
= FALSE
;
1485 for (j
= 0; j
< height
; j
++) {
1486 for (i
= 0; i
< width
; i
++) {
1488 unsigned long spixel
;
1490 const unsigned short MAX_COLOR
= 0xFFFF;
1492 spixel
= XGetPixel(image
, i
, j
);
1494 for (k
= cache_pos
; k
--; )
1495 if (cachesrc
[k
] == spixel
) {
1496 pixel
= cachedest
[k
];
1500 for (k
= CM_CACHE_SIZE
; k
-- > cache_pos
; )
1501 if (cachesrc
[k
] == spixel
) {
1502 pixel
= cachedest
[k
];
1506 cachesrc
[cache_pos
] = xcol
.pixel
= spixel
;
1507 XQueryColor(d
, cm
, &xcol
);
1511 r
= (long)((double)(xcol
.red
) / MAX_COLOR
);
1512 g
= (long)((double)(xcol
.green
) / MAX_COLOR
);
1513 b
= (long)((double)(xcol
.blue
) / MAX_COLOR
);
1515 pixel
= (int)(255 * sqrt(((r
* r
) + (g
* g
) + (b
* b
)) / 3));
1517 cachedest
[cache_pos
] = pixel
;
1519 if (++cache_pos
>= CM_CACHE_SIZE
) {
1527 h
= (pixel
>> 4) & 0xF;
1533 s
[0] = 'a' + (h
- 10);
1537 s
[1] = 'a' + (l
- 10);
1544 XDestroyImage(image
);
1547 *m_pstream
<< "grestore\n";
1549 CalcBoundingBox(xdest
, (long)YSCALE(ydest
));
1550 CalcBoundingBox(xdest
+ fwidth
, (long)YSCALE(ydest
+ fheight
));
1555 long wxPostScriptDC::GetCharHeight ()
1558 return m_font
.GetPointSize ();
1563 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1564 long *descent
, long *externalLeading
, wxFont
*theFont
,
1565 bool WXUNUSED(use16
))
1567 wxFont
*fontToUse
= theFont
;
1569 fontToUse
= (wxFont
*) &m_font
;
1573 #if !USE_AFM_FOR_POSTSCRIPT
1574 // Provide a VERY rough estimate (avoid using it)
1575 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1576 // font such as Courier (aka wxMODERN)
1580 height
= fontToUse
->GetPointSize();
1582 *x
= strlen (string
) * height
* 72 / 120;
1583 *y
= (long) (height
* 1.32); // allow for descender
1587 if (externalLeading
)
1588 *externalLeading
= 0;
1590 // +++++ start of contributed code +++++
1592 // ************************************************************
1593 // method for calculating string widths in postscript:
1594 // read in the AFM (adobe font metrics) file for the
1595 // actual font, parse it and extract the character widths
1596 // and also the descender. this may be improved, but for now
1597 // it works well. the AFM file is only read in if the
1598 // font is changed. this may be chached in the future.
1599 // calls to GetTextExtent with the font unchanged are rather
1602 // for each font and style used there is an AFM file necessary.
1603 // currently i have only files for the roman font family.
1604 // i try to get files for the other ones!
1606 // CAVE: the size of the string is currently always calculated
1607 // in 'points' (1/72 of an inch). this should later on be
1608 // changed to depend on the mapping mode.
1609 // CAVE: the path to the AFM files must be set before calling this
1610 // function. this is usually done by a call like the following:
1611 // wxSetAFMPath("d:\\wxw161\\afm\\");
1615 // wxPostScriptDC dc(NULL, TRUE);
1617 // wxSetAFMPath("d:\\wxw161\\afm\\");
1618 // dc.StartDoc("Test");
1621 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1622 // dc.GetTextExtent("Hallo",&w,&h);
1627 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1628 // created: 10.09.94
1629 // updated: 14.05.95
1631 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1632 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1633 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1635 // these static vars are for storing the state between calls
1636 static int lastFamily
= INT_MIN
;
1637 static int lastSize
= INT_MIN
;
1638 static int lastStyle
= INT_MIN
;
1639 static int lastWeight
= INT_MIN
;
1640 static int lastDescender
= INT_MIN
;
1641 static int lastWidths
[256]; // widths of the characters
1643 // get actual parameters
1644 const int Family
= fontToUse
->GetFamily();
1645 const int Size
= fontToUse
->GetPointSize();
1646 const int Style
= fontToUse
->GetStyle();
1647 const int Weight
= fontToUse
->GetWeight();
1649 // if we have another font, read the font-metrics
1650 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1651 // store actual values
1652 lastFamily
= Family
;
1655 lastWeight
= Weight
;
1657 // read in new font metrics **************************************
1659 // 1. construct filename ******************************************
1660 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1663 // Julian - we'll need to do this a different way now we've removed the
1664 // font directory system. Must find Stefan's original code.
1666 name
= wxTheFontNameDirectory
->GetAFMName(Family
, Weight
, Style
);
1670 // get the directory of the AFM files
1674 strcpy(afmName
,wxGetAFMPath());
1676 // 2. open and process the file **********************************
1678 // a short explanation of the AFM format:
1679 // we have for each character a line, which gives its size
1682 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1684 // that means, we have a character with ascii code 63, and width
1685 // (444/1000 * fontSize) points.
1686 // the other data is ignored for now!
1688 // when the font has changed, we read in the right AFM file and store the
1689 // character widths in an array, which is processed below (see point 3.).
1691 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1694 strcat(afmName
,name
);
1695 strcat(afmName
,".afm");
1696 FILE *afmFile
= fopen(afmName
,"r");
1698 wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1699 wxDebugMsg(" using approximate values\n");
1701 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1702 lastDescender
= -150; // dito.
1705 // init the widths array
1706 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1707 // some variables for holding parts of a line
1708 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1709 char upString
[30], utString
[30], encString
[50];
1712 // read in the file and parse it
1713 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1714 // A.) check for descender definition
1715 if(strncmp(line
,"Descender",9)==0){
1716 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1717 || (strcmp(descString
,"Descender")!=0)) {
1718 wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n",
1722 // JC 1.) check for UnderlinePosition
1723 else if(strncmp(line
,"UnderlinePosition",17)==0){
1724 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1725 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1726 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1730 // JC 2.) check for UnderlineThickness
1731 else if(strncmp(line
,"UnderlineThickness",18)==0){
1732 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1733 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1734 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1738 // JC 3.) check for EncodingScheme
1739 else if(strncmp(line
,"EncodingScheme",14)==0){
1740 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1741 || (strcmp(utString
,"EncodingScheme")!=0)) {
1742 wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1745 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1747 wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1748 afmName
,line
, encString
);
1751 // B.) check for char-width
1752 else if(strncmp(line
,"C ",2)==0){
1753 if(sscanf(line
,"%s%d%s%s%d",
1754 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1755 wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1757 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1758 strcmp(WXString
,"WX")!=0){
1759 wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1761 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1762 if(ascii
>=0 && ascii
<256){
1763 lastWidths
[ascii
] = cWidth
; // store width
1765 /* MATTHEW: this happens a lot; don't print an error */
1766 // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1769 // C.) ignore other entries.
1773 // hack to compute correct values for german 'Umlaute'
1774 // the correct way would be to map the character names
1775 // like 'adieresis' to corresp. positions of ISOEnc and read
1776 // these values from AFM files, too. Maybe later ...
1777 lastWidths
[196] = lastWidths
['A']; // Ä
1778 lastWidths
[228] = lastWidths
['a']; // ä
1779 lastWidths
[214] = lastWidths
['O']; // Ö
1780 lastWidths
[246] = lastWidths
['o']; // ö
1781 lastWidths
[220] = lastWidths
['U']; // Ü
1782 lastWidths
[252] = lastWidths
['u']; // ü
1783 lastWidths
[223] = lastWidths
[251]; // ß
1786 // JC: calculate UnderlineThickness/UnderlinePosition
1787 UnderlinePosition
= UnderlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1788 UnderlineThickness
= UnderlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1790 // 3. now the font metrics are read in, calc size *******************
1791 // this is done by adding the widths of the characters in the
1792 // string. they are given in 1/1000 of the size!
1795 long height
=Size
; // by default
1797 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1798 if(lastWidths
[*p
]== INT_MIN
){
1799 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1801 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1803 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1806 // add descender to height (it is usually a negative value)
1807 if(lastDescender
!=INT_MIN
){
1808 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1811 // return size values
1815 // return other parameters
1817 if(lastDescender
!=INT_MIN
){
1818 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1824 // currently no idea how to calculate this!
1825 // if (externalLeading) *externalLeading = 0;
1826 if (externalLeading
)
1827 *externalLeading
= 0;
1829 // ----- end of contributed code -----
1833 void wxPostScriptDC::DrawSpline( wxList
*points
)
1835 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1838 wxNode
*node
= points
->First();
1839 p
= (wxPoint
*)node
->Data();
1841 x1
= p
->x
; y1
= p
->y
;
1843 node
= node
->Next();
1844 p
= (wxPoint
*)node
->Data();
1846 x3
= a
= (double)(x1
+ c
) / 2;
1847 y3
= b
= (double)(y1
+ d
) / 2;
1849 *(GetStream()) << "newpath " << x1
<< " " << (GetYOrigin() - y1
) << " moveto " << x3
<< " " << (GetYOrigin() - y3
);
1850 *(GetStream()) << " lineto\n";
1851 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1852 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1854 while ((node
= node
->Next()) != NULL
)
1856 q
= (wxPoint
*)node
->Data();
1861 x3
= (double)(x2
+ c
) / 2;
1862 y3
= (double)(y2
+ d
) / 2;
1863 *(GetStream()) << x1
<< " " << (GetYOrigin() - y1
) << " " << x2
<< " " << (GetYOrigin() - y2
) << " ";
1864 *(GetStream()) << x3
<< " " << (GetYOrigin() - y3
) << " DrawSplineSection\n";
1866 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1867 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1870 * At this point, (x2,y2) and (c,d) are the position of the
1871 * next-to-last and last point respectively, in the point list
1873 *(GetStream()) << c
<< " " << (GetYOrigin() - d
) << " lineto stroke\n";
1876 long wxPostScriptDC::GetCharWidth ()
1878 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1879 return (long) (GetCharHeight() * 72.0 / 120.0);
1883 void wxPostScriptDC::SetMapMode (int mode
)
1885 m_mappingMode
= mode
;
1886 SetLogicalOrigin(0, 0);
1887 if(m_mappingMode
== MM_METRIC
)
1889 SetUserScale(72.0f
/ 25.4f
, 72.0f
/ 25.4f
);
1893 SetUserScale(1.0, 1.0);
1899 * Set the logical origin.
1900 * Actually we are setting the printer's origin and since
1901 * postscript transformations are cumulative we need to reset
1902 * the previous origin. We also need to allow for the user scale
1903 * factor (which affects printer coords but not logical)
1905 void wxPostScriptDC::SetLogicalOrigin(long x
, long y
)
1909 long xOffset
= (long) ((m_logicalOriginX
- x
) / m_scaleFactor
);
1910 long yOffset
= (long) ((y
- m_logicalOriginY
) / m_scaleFactor
);
1914 *m_pstream
<< xOffset
<< " " << yOffset
<< " translate\n";
1917 m_logicalOriginX
= x
;
1918 m_logicalOriginY
= y
;
1922 * Obsolete - now performed by SetUserScale() and SetLogicalOrigin()
1925 wxPostScriptDC::SetupCTM()
1930 * Set the user scale.
1931 * NB: Postscript transformations are cumulative and so we
1932 * need to take into account the current scale. Also, this
1933 * affects the logical origin
1935 void wxPostScriptDC::SetUserScale (double x
, double y
)
1937 // reset logical origin
1938 long xOrg
= m_logicalOriginX
;
1939 long yOrg
= m_logicalOriginY
;
1940 SetLogicalOrigin(0, 0);
1942 // set new scale factor
1946 factor
/= m_scaleFactor
;
1950 *m_pstream
<< factor
<< " " << factor
<< " scale\n";
1953 // set logical origin at new scale
1954 SetLogicalOrigin(xOrg
, yOrg
);
1959 m_scaleFactor
= m_userScaleX
;
1962 long wxPostScriptDC::DeviceToLogicalX (int x
) const
1967 long wxPostScriptDC::DeviceToLogicalXRel (int x
) const
1972 long wxPostScriptDC::DeviceToLogicalY (int y
) const
1977 long wxPostScriptDC::DeviceToLogicalYRel (int y
) const
1982 long wxPostScriptDC::LogicalToDeviceX (long x
) const
1987 long wxPostScriptDC::LogicalToDeviceXRel (long x
) const
1992 long wxPostScriptDC::LogicalToDeviceY (long y
) const
1997 long wxPostScriptDC::LogicalToDeviceYRel (long y
) const
2002 void wxPostScriptDC::GetSize(int* width
, int* height
) const
2004 const char *paperType
= wxThePrintSetupData
->GetPaperName();
2006 paperType
= _("A4 210 x 297 mm");
2008 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2010 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2013 *width
= paper
->widthPixels
;
2014 *height
= paper
->heightPixels
;
2023 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
2025 const char *paperType
= wxThePrintSetupData
->GetPaperName();
2027 paperType
= _("A4 210 x 297 mm");
2029 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2031 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2034 *width
= paper
->widthMM
;
2035 *height
= paper
->heightMM
;
2044 void wxPostScriptDC::CalcBoundingBox(long x
, long y
)
2046 long device_x
= (long) (x
- m_logicalOriginX
* m_scaleFactor
);
2047 long device_y
= (long) (y
+ m_logicalOriginY
* m_scaleFactor
);
2049 if (device_x
< m_minX
) m_minX
= device_x
;
2050 if (device_y
< m_minY
) m_minY
= device_y
;
2051 if (device_x
> m_maxX
) m_maxX
= device_x
;
2052 if (device_y
> m_maxY
) m_maxY
= device_y
;
2055 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2057 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2058 const wxPoint
& pos
, const wxSize
& size
, long style
):
2059 wxDialog(parent
, -1, title
, pos
, size
, style
)
2061 wxBeginBusyCursor();
2066 *orientation
= new wxString
[2],
2067 *print_modes
= new wxString
[3];
2069 long wx_printer_translate_x
, wx_printer_translate_y
;
2070 double wx_printer_scale_x
, wx_printer_scale_y
;
2072 orientation
[0] = _("Portrait");
2073 orientation
[1] = _("Landscape");
2075 print_modes
[0] = _("Send to Printer");
2076 print_modes
[1] = _("Print to File");
2077 print_modes
[2] = _("Preview Only");
2081 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2082 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2083 okBut
->SetDefault();
2086 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2087 (void) new wxStaticText( this, -1, _("Printer Command: "),
2089 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2090 wxPoint(100, yPos
), wxSize(100, -1) );
2092 (void) new wxStaticText( this, -1, _("Printer Options: "),
2093 wxPoint(210, yPos
) );
2094 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2095 wxPoint(305, yPos
), wxSize(150, -1) );
2101 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2103 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2105 // @@@ Configuration hook
2106 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
2107 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2109 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
2111 features
= (wxThePrintSetupData
->GetPrintPreviewCommand() &&
2112 *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2114 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2116 wxSize(-1,-1), features
,
2117 print_modes
, features
, 0);
2120 radio1
->Enable(0, FALSE
);
2121 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2122 radio1
->Enable(2, FALSE
);
2125 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2126 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2127 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2129 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2132 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2133 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2135 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2136 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2137 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2141 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2142 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
2143 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2145 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2146 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
2147 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2151 delete[] orientation
;
2152 delete[] print_modes
;
2157 int wxPostScriptPrintDialog::ShowModal ()
2159 if ( wxDialog::ShowModal() == wxID_OK
)
2161 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2162 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2163 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2164 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2165 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2166 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2167 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2168 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2170 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
2171 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
2172 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
2173 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
2176 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2177 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2180 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
2183 switch ( radio1
->GetSelection() ) {
2184 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2185 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2186 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2193 // PostScript printer settings
2194 // RETAINED FOR BACKWARD COMPATIBILITY
2195 void wxSetPrinterCommand(const char *cmd
)
2197 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2200 void wxSetPrintPreviewCommand(const char *cmd
)
2202 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2205 void wxSetPrinterOptions(const char *flags
)
2207 wxThePrintSetupData
->SetPrinterOptions(flags
);
2210 void wxSetPrinterFile(const char *f
)
2212 wxThePrintSetupData
->SetPrinterFile(f
);
2215 void wxSetPrinterOrientation(int orient
)
2217 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2220 void wxSetPrinterScaling(double x
, double y
)
2222 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2225 void wxSetPrinterTranslation(long x
, long y
)
2227 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2230 // 1 = Preview, 2 = print to file, 3 = send to printer
2231 void wxSetPrinterMode(int mode
)
2233 wxThePrintSetupData
->SetPrinterMode(mode
);
2236 void wxSetAFMPath(const char *f
)
2238 wxThePrintSetupData
->SetAFMPath(f
);
2241 // Get current values
2242 char *wxGetPrinterCommand()
2244 return wxThePrintSetupData
->GetPrinterCommand();
2247 char *wxGetPrintPreviewCommand()
2249 return wxThePrintSetupData
->GetPrintPreviewCommand();
2252 char *wxGetPrinterOptions()
2254 return wxThePrintSetupData
->GetPrinterOptions();
2257 char *wxGetPrinterFile()
2259 return wxThePrintSetupData
->GetPrinterFile();
2262 int wxGetPrinterOrientation()
2264 return wxThePrintSetupData
->GetPrinterOrientation();
2267 void wxGetPrinterScaling(double* x
, double* y
)
2269 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2272 void wxGetPrinterTranslation(long *x
, long *y
)
2274 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2277 int wxGetPrinterMode()
2279 return wxThePrintSetupData
->GetPrinterMode();
2282 char *wxGetAFMPath()
2284 return wxThePrintSetupData
->GetAFMPath();
2291 wxPrintSetupData::wxPrintSetupData()
2293 printerCommand
= (char *) NULL
;
2294 previewCommand
= (char *) NULL
;
2295 printerFlags
= (char *) NULL
;
2296 printerOrient
= PS_PORTRAIT
;
2297 printerScaleX
= (double)1.0;
2298 printerScaleY
= (double)1.0;
2299 printerTranslateX
= 0;
2300 printerTranslateY
= 0;
2301 // 1 = Preview, 2 = print to file, 3 = send to printer
2303 afmPath
= (char *) NULL
;
2304 paperName
= (char *) NULL
;
2306 printerFile
= (char *) NULL
;
2309 wxPrintSetupData::~wxPrintSetupData()
2312 delete[] printerCommand
;
2314 delete[] previewCommand
;
2316 delete[] printerFlags
;
2322 delete[] printerFile
;
2325 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2327 if (cmd
== printerCommand
)
2331 delete[] printerCommand
;
2333 printerCommand
= copystring(cmd
);
2335 printerCommand
= (char *) NULL
;
2338 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2340 if (cmd
== previewCommand
)
2344 delete[] previewCommand
;
2346 previewCommand
= copystring(cmd
);
2348 previewCommand
= (char *) NULL
;
2351 void wxPrintSetupData::SetPaperName(const char *name
)
2353 if (name
== paperName
)
2359 paperName
= copystring(name
);
2361 paperName
= (char *) NULL
;
2364 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2366 if (printerFlags
== flags
)
2370 delete[] printerFlags
;
2372 printerFlags
= copystring(flags
);
2374 printerFlags
= (char *) NULL
;
2377 void wxPrintSetupData::SetPrinterFile(const char *f
)
2379 if (f
== printerFile
)
2383 delete[] printerFile
;
2385 printerFile
= copystring(f
);
2387 printerFile
= (char *) NULL
;
2390 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2392 printerOrient
= orient
;
2395 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2401 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2403 printerTranslateX
= x
;
2404 printerTranslateY
= y
;
2407 // 1 = Preview, 2 = print to file, 3 = send to printer
2408 void wxPrintSetupData::SetPrinterMode(int mode
)
2413 void wxPrintSetupData::SetAFMPath(const char *f
)
2421 afmPath
= copystring(f
);
2423 afmPath
= (char *) NULL
;
2426 void wxPrintSetupData::SetColour(bool col
)
2431 // Get current values
2432 char *wxPrintSetupData::GetPrinterCommand()
2434 return printerCommand
;
2437 char *wxPrintSetupData::GetPrintPreviewCommand()
2439 return previewCommand
;
2442 char *wxPrintSetupData::GetPrinterOptions()
2444 return printerFlags
;
2447 char *wxPrintSetupData::GetPrinterFile()
2452 char *wxPrintSetupData::GetPaperName()
2457 int wxPrintSetupData::GetPrinterOrientation()
2459 return printerOrient
;
2462 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2468 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2470 *x
= printerTranslateX
;
2471 *y
= printerTranslateY
;
2474 int wxPrintSetupData::GetPrinterMode()
2479 char *wxPrintSetupData::GetAFMPath()
2484 bool wxPrintSetupData::GetColour()
2489 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2491 SetPrinterCommand(data
.GetPrinterCommand());
2492 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2493 SetPrinterOptions(data
.GetPrinterOptions());
2495 data
.GetPrinterTranslation(&x
, &y
);
2496 SetPrinterTranslation(x
, y
);
2499 data
.GetPrinterScaling(&x1
, &y1
);
2500 SetPrinterScaling(x1
, y1
);
2502 SetPrinterOrientation(data
.GetPrinterOrientation());
2503 SetPrinterMode(data
.GetPrinterMode());
2504 SetAFMPath(data
.GetAFMPath());
2505 SetPaperName(data
.GetPaperName());
2506 SetColour(data
.GetColour());
2509 void wxInitializePrintSetupData(bool init
)
2513 wxThePrintSetupData
= new wxPrintSetupData
;
2515 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2516 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2517 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2518 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2520 // Could have a .ini file to read in some defaults
2521 // - and/or use environment variables, e.g. WXWIN
2523 wxThePrintSetupData
->SetPrinterCommand("print");
2524 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2525 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2528 wxThePrintSetupData
->SetPrinterCommand("print");
2529 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2530 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2532 #if !defined(__VMS__) && !defined(__WXMSW__)
2533 wxThePrintSetupData
->SetPrinterCommand("lpr");
2534 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2535 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2540 if (wxThePrintSetupData
)
2541 delete wxThePrintSetupData
;
2542 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2547 * Paper size database for PostScript
2550 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2556 pageName
= copystring(name
);
2559 wxPrintPaperType::~wxPrintPaperType()
2565 * Print paper database for PostScript
2568 #if !USE_SHARED_LIBRARIES
2569 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
2572 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING
)
2574 DeleteContents(TRUE
);
2577 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2581 void wxPrintPaperDatabase::CreateDatabase()
2583 // Need correct values for page size in pixels.
2584 // Each unit is one 'point' = 1/72 of an inch.
2585 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2586 // in wxPostScriptDC code, so we can start from top left.
2587 // So access this database and translate by appropriate number
2588 // of points for this paper size. OR IS IT OK ALREADY?
2589 // Can't remember where the PostScript origin is by default.
2590 // Heck, someone will know how to make it hunky-dory...
2593 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2594 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2595 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2596 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2601 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 210*4, 297*4 );
2602 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 297*4, 420*4 );
2603 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 216*4, 279*4 );
2604 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 216*4, 356*4 );
2608 void wxPrintPaperDatabase::ClearDatabase()
2613 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2615 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2618 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2620 wxNode
*node
= Find(name
);
2622 return (wxPrintPaperType
*)node
->Data();
2624 return (wxPrintPaperType
*) NULL
;
2628 * Initialization/cleanup module
2631 bool wxPostScriptModule::OnInit()
2633 wxInitializePrintSetupData();
2634 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2635 wxThePrintPaperDatabase
->CreateDatabase();
2640 void wxPostScriptModule::OnExit()
2642 wxInitializePrintSetupData(FALSE
);
2643 delete wxThePrintPaperDatabase
;
2644 wxThePrintPaperDatabase
= NULL
;