1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPostScriptDC implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "postscrp.h"
14 #pragma implementation
18 // For compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
32 #include "wx/postscrp.h"
34 #include "wx/filedlg.h"
35 #include "wx/msgdlg.h"
37 #include "wx/button.h"
38 #include "wx/radiobox.h"
39 #include "wx/textctrl.h"
40 #include "wx/stattext.h"
45 #include "wx/dcmemory.h"
48 #include "wx/msw/private.h"
67 #include "gdk/gdkx.h" // GDK_DISPLAY
68 #include "gdk/gdkprivate.h" // XImage
70 #include <X11/Xutil.h>
76 #include <X11/Xutil.h>
99 // Declarations local to this file
100 #define YSCALE(y) (m_yOrigin / m_scaleFactor - (y))
102 // Determine the Default Postscript Previewer
103 // available on the platform
104 #if defined(__SUN__) && defined(__XVIEW__)
105 // OpenWindow/NeWS's Postscript Previewer
106 # define PS_VIEWER_PROG "pageview"
107 #elif defined(__VMS__)
108 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
109 #elif defined(__SGI__)
110 // SGI's Display Postscript Previewer
111 //# define PS_VIEWER_PROG "dps"
112 # define PS_VIEWER_PROG "xpsview"
113 #elif defined(__X__) || defined(__WXGTK__)
114 // Front-end to ghostscript
115 # define PS_VIEWER_PROG "ghostview"
117 // Windows ghostscript/ghostview
118 # define PS_VIEWER_PROG NULL
121 wxPrintSetupData
*wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
123 // these should move into wxPostscriptDC:
124 double UnderlinePosition
= 0.0F
;
125 double UnderlineThickness
= 0.0F
;
127 #define _MAXPATHLEN 500
129 /* See "wxspline.inc" and "xfspline.inc" */
130 #if wxUSE_XFIG_SPLINE_CODE
131 static const char *wxPostScriptHeaderSpline
= " \
132 /DrawSplineSection {\n\
139 /xa x1 x2 x1 sub 0.666667 mul add def\n\
140 /ya y1 y2 y1 sub 0.666667 mul add def\n\
141 /xb x3 x2 x3 sub 0.666667 mul add def\n\
142 /yb y3 y2 y3 sub 0.666667 mul add def\n\
144 xa ya xb yb x3 y3 curveto\n\
148 // No extra PS header for this spline implementation.
149 static const char *wxPostScriptHeaderSpline
= (char *) NULL
;
151 #endif /* wxUSE_XFIG_SPLINE_CODE */
154 // VMS has a bug in the ofstream class.
155 // the buffering doesn't work correctly. therefore
156 // we will allocate (temporarily) a very big buffer (1MB), so
157 // that a buffer overflow will not occur.
159 #define VMS_BUFSIZ (1024L*1024L)
160 static char *fileBuffer
= NULL
;
163 #if !USE_SHARED_LIBRARY
164 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
165 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
166 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
167 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
170 wxPostScriptDC::wxPostScriptDC (void)
172 // m_yOrigin = 792; // For EPS output
173 m_yOrigin
= 842; // For A4 output
181 m_pstream
= (ofstream
*) NULL
;
184 // Can only send to file in Windows
185 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
189 m_currentGreen
= 255;
193 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
195 Create(file
, interactive
, parent
);
198 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
200 m_isInteractive
= interactive
;
202 m_yOrigin
= 792; // For EPS output
203 // m_yOrigin = 842; // For A4 output
211 m_pstream
= (ofstream
*) NULL
;
214 // Can only send to file in Windows
215 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
220 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
226 m_currentGreen
= 255;
234 wxPostScriptDC::~wxPostScriptDC (void)
240 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
242 wxPostScriptPrintDialog
dialog (parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
243 m_ok
= (dialog
.ShowModal () == wxID_OK
) ;
248 if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
|| wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
252 wxThePrintSetupData
->SetPrinterFile("preview");
254 // For PS_PRINTER action this depends on a Unix-style print spooler
255 // since the wx_printer_file can be destroyed during a session
256 // @@@ TODO: a Windows-style answer for non-Unix
258 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
260 strcpy (tmp
, "/tmp/preview_");
261 strcat (tmp
, userId
);
262 wxThePrintSetupData
->SetPrinterFile(tmp
);
265 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
266 strcat (tmp2
, ".ps");
267 wxThePrintSetupData
->SetPrinterFile(tmp2
);
270 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
272 char *file
= wxSaveFileSelector (_("PostScript"), "ps");
278 wxThePrintSetupData
->SetPrinterFile(file
);
286 void wxPostScriptDC::SetClippingRegion (long cx
, long cy
, long cw
, long ch
)
294 *m_pstream
<< "gsave\n";
295 *m_pstream
<< "newpath\n";
296 *m_pstream
<< cx
<< " " << YSCALE (cy
) << " moveto\n";
297 *m_pstream
<< (cx
+ cw
) << " " << YSCALE (cy
) << " lineto\n";
298 *m_pstream
<< cx
+ cw
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
299 *m_pstream
<< cx
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
300 *m_pstream
<< "closepath clip newpath\n";
303 void wxPostScriptDC::DestroyClippingRegion (void)
310 *m_pstream
<< "grestore\n";
314 void wxPostScriptDC::Clear (void)
318 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
), int WXUNUSED(style
))
322 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
327 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
331 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
337 *m_pstream
<< "newpath\n";
338 *m_pstream
<< x1
<< " " << YSCALE (y1
) << " moveto\n";
339 *m_pstream
<< x2
<< " " << YSCALE (y2
) << " lineto\n";
340 *m_pstream
<< "stroke\n";
341 CalcBoundingBox (x1
, (long)YSCALE (y1
));
342 CalcBoundingBox (x2
, (long)YSCALE (y2
));
345 #define RAD2DEG 57.29577951308
347 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
354 long radius
= (long) sqrt((double) (dx
*dx
+dy
*dy
));
355 double alpha1
, alpha2
;
357 if (x1
== x2
&& y1
== y2
) {
360 } else if (radius
== 0.0) {
361 alpha1
= alpha2
= 0.0;
363 alpha1
= (x1
- xc
== 0) ?
364 (y1
- yc
< 0) ? 90.0 : -90.0 :
365 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
366 alpha2
= (x2
- xc
== 0) ?
367 (y2
- yc
< 0) ? 90.0 : -90.0 :
368 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
370 while (alpha1
<= 0) alpha1
+= 360;
371 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
372 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
373 while (alpha2
> 360) alpha2
-= 360;
375 if (m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
) {
377 *m_pstream
<< "newpath\n"
378 << xc
<< " " << YSCALE(yc
) << " "
379 << radius
<< " " << radius
<< " "
380 << alpha1
<< " " << alpha2
<< " ellipse\n"
381 << xc
<< " " << YSCALE(yc
) << " lineto\n"
385 if (m_pen
.Ok() && m_pen
.GetStyle() != wxTRANSPARENT
) {
387 *m_pstream
<< "newpath\n"
388 << xc
<< " " << YSCALE(yc
) << " "
389 << radius
<< " " << radius
<< " "
390 << alpha1
<< " " << alpha2
<< " ellipse\n"
393 CalcBoundingBox(x1
, (long)YSCALE(y1
));
394 CalcBoundingBox(x2
, (long)YSCALE(y2
));
397 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
402 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
403 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
408 DrawEllipse(x
,y
,w
,h
);
412 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
418 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
419 w
/2 << " " << (h
/2) << " " <<
420 int(sa
) <<" "<< int(ea
)<<" true ellipticarc\n";
422 CalcBoundingBox (x
, (long)YSCALE (y
));
423 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
425 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
431 (x
+w
/2) << " " << YSCALE (y
+h
/2) << " " <<
432 (w
/2) << " " << (h
/2) << " " <<
433 int(sa
) <<" "<< int(ea
)<<" false ellipticarc\n";
435 CalcBoundingBox (x
, (long)YSCALE (y
));
436 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
440 void wxPostScriptDC::DrawPoint (long x
, long y
)
446 *m_pstream
<< "newpath\n";
447 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
448 *m_pstream
<< (x
+1) << " " << YSCALE (y
) << " lineto\n";
449 *m_pstream
<< "stroke\n";
450 CalcBoundingBox (x
, (long)YSCALE (y
));
453 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
459 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
462 *m_pstream
<< "newpath\n";
464 long xx
= points
[0].x
+ xoffset
;
465 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
466 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
467 CalcBoundingBox (xx
, yy
);
470 for (i
= 1; i
< n
; i
++)
472 xx
= points
[i
].x
+ xoffset
;
473 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
474 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
475 CalcBoundingBox (xx
, yy
);
477 *m_pstream
<< "fill\n";
480 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
483 *m_pstream
<< "newpath\n";
485 long xx
= points
[0].x
+ xoffset
;
486 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
487 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
488 CalcBoundingBox (xx
, yy
);
491 for (i
= 1; i
< n
; i
++)
493 xx
= points
[i
].x
+ xoffset
;
494 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
495 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
496 CalcBoundingBox (xx
, yy
);
500 xx
= points
[0].x
+ xoffset
;
501 yy
= (long) YSCALE (points
[0].y
+ yoffset
);
502 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
505 *m_pstream
<< "stroke\n";
510 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
519 *m_pstream
<< "newpath\n";
521 long xx
= points
[0].x
+ xoffset
;
522 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
523 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
524 CalcBoundingBox (xx
, yy
);
527 for (i
= 1; i
< n
; i
++)
529 xx
= points
[i
].x
+ xoffset
;
530 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
531 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
532 CalcBoundingBox (xx
, yy
);
534 *m_pstream
<< "stroke\n";
538 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
542 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
546 *m_pstream
<< "newpath\n";
547 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
548 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
549 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
550 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
551 *m_pstream
<< "closepath\n";
552 *m_pstream
<< "fill\n";
554 CalcBoundingBox (x
, (long)YSCALE (y
));
555 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
557 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
561 *m_pstream
<< "newpath\n";
562 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
563 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
) << " lineto\n";
564 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ height
) << " lineto\n";
565 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
566 *m_pstream
<< "closepath\n";
567 *m_pstream
<< "stroke\n";
569 CalcBoundingBox (x
, (long)YSCALE (y
));
570 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
574 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
581 // Now, a negative radius is interpreted to mean
582 // 'the proportion of the smallest X or Y dimension'
583 double smallest
= 0.0;
588 radius
= (-radius
* smallest
);
591 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
594 // Draw rectangle anticlockwise
595 *m_pstream
<< "newpath\n";
596 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
598 *m_pstream
<< x
<< " " << YSCALE (y
+ radius
) << " moveto\n";
600 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
601 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
603 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
604 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
606 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
608 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
610 *m_pstream
<< "closepath\n";
612 *m_pstream
<< "fill\n";
614 CalcBoundingBox (x
, (long)YSCALE (y
));
615 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
617 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
620 // Draw rectangle anticlockwise
621 *m_pstream
<< "newpath\n";
622 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
624 *m_pstream
<< x
<< " " << YSCALE (y
+ height
- radius
) << " lineto\n";
626 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
627 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
) << " lineto\n";
629 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
630 *m_pstream
<< (x
+ width
) << " " << YSCALE (y
+ radius
) << " lineto\n";
632 *m_pstream
<< (x
+ width
- radius
) << " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
634 *m_pstream
<< (x
+ radius
) << " " << YSCALE (y
) << " lineto\n";
636 *m_pstream
<< "closepath\n";
638 *m_pstream
<< "stroke\n";
640 CalcBoundingBox (x
, (long)YSCALE (y
));
641 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
645 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
649 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
653 *m_pstream
<< "newpath\n";
654 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
655 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
656 *m_pstream
<< "fill\n";
658 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
659 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
661 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
665 *m_pstream
<< "newpath\n";
666 *m_pstream
<< (x
+ width
/ 2) << " " << YSCALE (y
+ height
/ 2) << " ";
667 *m_pstream
<< (width
/ 2) << " " << (height
/ 2) << " 0 360 ellipse\n";
668 *m_pstream
<< "stroke\n";
670 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
671 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
675 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
677 #if defined(__X__) || defined(__WXGTK__)
679 memDC
.SelectObject(icon
);
680 Blit(x
, y
, icon
.GetWidth(), icon
.GetHeight(), &memDC
, 0, 0);
684 void wxPostScriptDC::SetFont (const wxFont
& the_font
)
689 if (m_font
== the_font
)
699 const char *style
= "";
700 int Style
= m_font
.GetStyle ();
701 int Weight
= m_font
.GetWeight ();
703 switch (m_font
.GetFamily ())
713 // name = "/Times-Roman";
714 name
= "/Times"; // Altered by EDZ
717 name
= "/Zapf-Chancery-MediumItalic";
722 case wxDEFAULT
: // Sans Serif Font
723 name
= "/LucidaSans";
726 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
728 if (m_font
.GetFamily () == wxROMAN
)
733 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
736 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
738 if (m_font
.GetFamily () == wxROMAN
)
743 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
745 if (m_font
.GetFamily () == wxROMAN
)
746 style
= "-BoldItalic";
748 style
= "-BoldOblique";
750 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
752 if (m_font
.GetFamily () == wxROMAN
)
757 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
759 if (m_font
.GetFamily () == wxROMAN
)
760 style
= "-BoldItalic";
762 style
= "-BoldOblique";
769 *m_pstream
<< buf
<< " findfont\n";
770 *m_pstream
<< (m_font
.GetPointSize() * m_scaleFactor
) << " scalefont setfont\n";
773 void wxPostScriptDC::SetPen (const wxPen
& pen
)
778 int oldStyle
= m_pen
.GetStyle();
786 *m_pstream
<< m_pen
.GetWidth () << " setlinewidth\n";
788 // Line style - WRONG: 2nd arg is OFFSET
790 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
791 operator correctly. You should look-up this in the Red Book: the 2nd parame-
792 ter is not number of values in the array of the first one, but an offset
793 into this description of the pattern. I mean a real *offset* not index
794 into array. I.e. If the command is [3 4] 1 setdash is used, then there
795 will be first black line *2* units long, then space 4 units, then the
796 pattern of *3* units black, 4 units space will be repeated.
798 static const char *dotted
= "[2 5] 2";
799 static const char *short_dashed
= "[4 4] 2";
800 static const char *long_dashed
= "[4 8] 2";
801 static const char *dotted_dashed
= "[6 6 2 6] 4";
803 const char *psdash
= (char *) NULL
;
804 switch (m_pen
.GetStyle ())
810 psdash
= short_dashed
;
813 psdash
= long_dashed
;
816 psdash
= dotted_dashed
;
824 if (oldStyle
!= m_pen
.GetStyle())
825 *m_pstream
<< psdash
<< " setdash\n";
828 unsigned char red
= m_pen
.GetColour ().Red ();
829 unsigned char blue
= m_pen
.GetColour ().Blue ();
830 unsigned char green
= m_pen
.GetColour ().Green ();
834 // Anything not white is black
835 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
836 && green
== (unsigned char) 255))
838 red
= (unsigned char) 0;
839 green
= (unsigned char) 0;
840 blue
= (unsigned char) 0;
844 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
846 long redPS
= (long) (((int) red
) / 255.0);
847 long bluePS
= (long) (((int) blue
) / 255.0);
848 long greenPS
= (long) (((int) green
) / 255.0);
850 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
853 m_currentBlue
= blue
;
854 m_currentGreen
= green
;
858 void wxPostScriptDC::SetBrush (const wxBrush
& brush
)
869 unsigned char red
= m_brush
.GetColour ().Red ();
870 unsigned char blue
= m_brush
.GetColour ().Blue ();
871 unsigned char green
= m_brush
.GetColour ().Green ();
875 // Anything not black is white
876 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
877 && green
== (unsigned char) 0))
879 red
= (unsigned char) 255;
880 green
= (unsigned char) 255;
881 blue
= (unsigned char) 255;
885 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
887 long redPS
= (long) (((int) red
) / 255.0);
888 long bluePS
= (long) (((int) blue
) / 255.0);
889 long greenPS
= (long) (((int) green
) / 255.0);
890 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
892 m_currentBlue
= blue
;
893 m_currentGreen
= green
;
897 void wxPostScriptDC::DrawText (const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
))
902 // TODO: SetFont checks for identity so this will always be a NULL operation
906 if (m_textForegroundColour
.Ok ())
908 unsigned char red
= m_textForegroundColour
.Red ();
909 unsigned char blue
= m_textForegroundColour
.Blue ();
910 unsigned char green
= m_textForegroundColour
.Green ();
914 // Anything not white is black
915 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
916 && green
== (unsigned char) 255))
918 red
= (unsigned char) 0;
919 green
= (unsigned char) 0;
920 blue
= (unsigned char) 0;
923 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
925 long redPS
= (long) (((int) red
) / 255.0);
926 long bluePS
= (long) (((int) blue
) / 255.0);
927 long greenPS
= (long) (((int) green
) / 255.0);
928 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
931 m_currentBlue
= blue
;
932 m_currentGreen
= green
;
938 size
= m_font
.GetPointSize ();
940 *m_pstream
<< x
<< " " << YSCALE (y
+ size
) << " moveto\n";
942 // *m_pstream << "(" << text << ")" << " show\n";
944 int len
= strlen ((char *)(const char *)text
);
946 for (i
= 0; i
< len
; i
++)
950 if (ch == ')' || ch == '(' || ch == '\\')
954 int c
= (unsigned char) text
[i
];
955 if ( c
== ')' || c
== '(' || c
== '\\')
957 *m_pstream
<< "\\" << (char) c
;
961 // Cope with character codes > 127
963 sprintf(tmp
, "\\%o", c
);
967 *m_pstream
<< (char) c
;
970 *m_pstream
<< ")" << " show\n";
972 if (m_font
.GetUnderlined())
975 GetTextExtent(text
, &w
, &h
);
976 *m_pstream
<< "gsave " << x
<< " " << YSCALE (y
+ size
- UnderlinePosition
)
978 << UnderlineThickness
<< " setlinewidth "
979 << (x
+ w
) << " " << YSCALE (y
+ size
- UnderlinePosition
)
980 << " lineto stroke grestore\n";
983 CalcBoundingBox (x
, (long)YSCALE (y
+ size
));
984 CalcBoundingBox (x
+ size
* strlen ((char *)(const char *)text
), (long)YSCALE (y
));
988 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
990 m_backgroundBrush
= brush
;
993 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
997 static const char *wxPostScriptHeaderEllipse
= "\
998 /ellipsedict 8 dict def\n\
999 ellipsedict /mtrx matrix put\n\
1001 { ellipsedict begin\n\
1002 /endangle exch def\n\
1003 /startangle exch def\n\
1008 /savematrix mtrx currentmatrix def\n\
1011 0 0 1 startangle endangle arc\n\
1012 savematrix setmatrix\n\
1017 static const char *wxPostScriptHeaderEllipticArc
= "\
1018 /ellipticarcdict 8 dict def\n\
1019 ellipticarcdict /mtrx matrix put\n\
1021 { ellipticarcdict begin\n\
1022 /do_fill exch def\n\
1023 /endangle exch def\n\
1024 /startangle exch def\n\
1029 /savematrix mtrx currentmatrix def\n\
1032 do_fill { 0 0 moveto } if\n\
1033 0 0 1 startangle endangle arc\n\
1034 savematrix setmatrix\n\
1035 do_fill { fill }{ stroke } ifelse\n\
1039 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1041 if (m_filename
== "")
1044 m_filename
= "wxtmp.ps";
1046 m_filename
= wxGetTempFileName("ps");
1048 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1052 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1057 m_pstream
= new ofstream
;
1058 if(fileBuffer
) delete[] fileBuffer
;
1059 fileBuffer
= new char[VMS_BUFSIZ
];
1060 m_pstream
->setbuf(fileBuffer
,VMS_BUFSIZ
);
1061 m_pstream
->open(wxThePrintSetupData
->GetPrinterFile());
1063 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1065 if (!m_pstream
|| !m_pstream
->good())
1067 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1073 SetBrush (*wxBLACK_BRUSH
);
1074 SetPen (*wxBLACK_PEN
);
1082 void wxPostScriptDC::EndDoc (void)
1084 static char wxPostScriptHeaderReencodeISO1
[] =
1085 "\n/reencodeISO {\n"
1086 "dup dup findfont dup length dict begin\n"
1087 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
1088 "/Encoding ISOLatin1Encoding def\n"
1089 "currentdict end definefont\n"
1091 "/ISOLatin1Encoding [\n"
1092 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1093 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1094 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1095 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1096 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
1097 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
1098 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
1099 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
1100 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
1101 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
1102 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
1103 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1104 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1105 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
1106 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
1108 static char wxPostScriptHeaderReencodeISO2
[] =
1109 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
1110 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
1111 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
1112 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
1113 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
1114 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
1115 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
1116 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
1117 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
1118 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
1119 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
1120 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
1121 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
1122 "/yacute/thorn/ydieresis\n"
1130 *m_pstream
<< "grestore\n";
1133 // Will reuse m_pstream for header
1135 // see the definition of fileBuffer for explanation
1136 m_pstream
->close(); // steve, 05.09.94
1137 if(fileBuffer
) delete[] fileBuffer
;
1142 m_pstream
= (ofstream
*) NULL
;
1148 char *header_file
= "header.ps";
1150 char *header_file
= wxGetTempFileName("ps");
1152 m_pstream
= new ofstream (header_file
);
1154 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1155 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1156 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1157 // time_t when; time (&when);
1158 // *m_pstream << "%%CreationDate: " << ctime (&when);
1159 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1161 // User Id information
1163 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1165 *m_pstream
<< "%%For: " << (char *)userID
;
1167 if (wxGetUserName(userName
, sizeof(userName
)))
1168 *m_pstream
<< " (" << (char *)userName
<< ")";
1171 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1173 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1176 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1178 long wx_printer_translate_x
, wx_printer_translate_y
;
1179 double wx_printer_scale_x
, wx_printer_scale_y
;
1180 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1181 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1183 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1185 *m_pstream
<< "%%Orientation: Landscape\n";
1189 *m_pstream
<< "%%Orientation: Portrait\n";
1192 // Compute the bounding box. Note that it is in the default user
1193 // coordinate system, thus we have to convert the values.
1194 long llx
= (long) ((m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1195 long lly
= (long) ((m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1196 long urx
= (long) ((m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1197 long ury
= (long) ((m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1200 // If we're landscape, our sense of "x" and "y" is reversed.
1201 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1204 tmp
= llx
; llx
= lly
; lly
= tmp
;
1205 tmp
= urx
; urx
= ury
; ury
= tmp
;
1207 // We need either the two lines that follow, or we need to subtract
1208 // min_x from real_translate_y, which is commented out below.
1209 llx
= llx
- m_minX
*wx_printer_scale_y
;
1210 urx
= urx
- m_minX
*wx_printer_scale_y
;
1214 // The Adobe specifications call for integers; we round as to make
1215 // the bounding larger.
1216 *m_pstream
<< "%%BoundingBox: "
1217 << floor((double)llx
) << " " << floor((double)lly
) << " "
1218 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1219 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1220 *m_pstream
<< "%%EndComments\n\n";
1222 // To check the correctness of the bounding box, postscript commands
1223 // to draw a box corresponding to the bounding box are generated below.
1224 // But since we typically don't want to print such a box, the postscript
1225 // commands are generated within comments. These lines appear before any
1226 // adjustment of scale, rotation, or translation, and hence are in the
1227 // default user coordinates.
1228 *m_pstream
<< "% newpath\n";
1229 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1230 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1231 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1232 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1236 long real_translate_y
= wx_printer_translate_y
;
1237 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1239 real_translate_y
-= m_maxY
;
1240 // The following line can be used instead of the adjustment to
1241 // llx and urx above.
1242 // real_translate_y -= m_minX;
1243 *m_pstream
<< "90 rotate\n";
1246 /* Probably don't want this now we have it in EndPage, below.
1247 * We should rationalise the scaling code to one place. JACS, October 1995
1248 * Do we take the next 2 lines out or not?
1251 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1252 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1255 *m_pstream
<< "%%BeginProlog\n";
1256 *m_pstream
<< wxPostScriptHeaderEllipse
;
1257 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1258 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1259 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1261 if (wxPostScriptHeaderSpline
)
1262 *m_pstream
<< wxPostScriptHeaderSpline
;
1263 *m_pstream
<< "%%EndProlog\n";
1266 m_pstream
= (ofstream
*) NULL
;
1269 char *tmp_file
= "tmp.ps";
1271 char *tmp_file
= wxGetTempFileName("ps");
1274 // Paste header Before wx_printer_file
1275 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1276 wxRemoveFile (header_file
);
1277 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1278 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1280 #if defined(__X__) || defined(__WXGTK__)
1283 switch (wxThePrintSetupData
->GetPrinterMode()) {
1287 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1288 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1289 argv
[2] = (char *) NULL
;
1290 wxExecute (argv
, TRUE
);
1291 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1299 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1301 // !SM! If we simply assign to argv[1] here, if printer options
1302 // are blank, we get an annoying and confusing message from lpr.
1303 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1305 argv
[argc
++] = opts
;
1307 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1308 argv
[argc
++] = (char *) NULL
;
1309 wxExecute (argv
, TRUE
);
1310 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1321 void wxPostScriptDC::StartPage (void)
1325 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1326 // *m_pstream << "matrix currentmatrix\n";
1328 // Added by Chris Breeze
1330 // Each page starts with an "initgraphics" which resets the
1331 // transformation and so we need to reset the origin
1332 // (and rotate the page for landscape printing)
1333 m_scaleFactor
= 1.0;
1334 m_logicalOriginX
= 0;
1335 m_logicalOriginY
= 0;
1338 long translate_x
, translate_y
;
1339 double scale_x
, scale_y
;
1340 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1341 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1343 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1345 translate_y
-= GetYOrigin();
1346 *m_pstream
<< "90 rotate\n";
1349 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1350 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1353 void wxPostScriptDC::EndPage (void)
1357 *m_pstream
<< "showpage\n";
1359 // Removed by Chris Breeze
1361 *m_pstream
<< "setmatrix\n";
1363 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1365 long wx_printer_translate_x
, wx_printer_translate_y
;
1366 double wx_printer_scale_x
, wx_printer_scale_y
;
1367 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1368 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1370 // Compute the bounding box. Note that it is in the default user
1371 // coordinate system, thus we have to convert the values.
1372 long llx
= (m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1373 long lly
= (m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1374 long urx
= (m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1375 long ury
= (m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1377 // If we're landscape, our sense of "x" and "y" is reversed.
1378 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1381 tmp
= llx
; llx
= lly
; lly
= tmp
;
1382 tmp
= urx
; urx
= ury
; ury
= tmp
;
1384 // We need either the two lines that follow, or we need to subtract
1385 // m_minX from real_translate_y, which is commented out below.
1386 llx
= llx
- m_minX
*wx_printer_scale_y
;
1387 urx
= urx
- m_minX
*wx_printer_scale_y
;
1391 long real_translate_y
= wx_printer_translate_y
;
1392 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1394 real_translate_y
-= m_maxY
;
1395 // The following line can be used instead of the adjustment to
1396 // llx and urx above.
1397 // real_translate_y -= m_minX;
1398 *m_pstream
<< "90 rotate\n";
1401 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1402 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1406 bool wxPostScriptDC::
1407 Blit (long xdest
, long ydest
, long fwidth
, long fheight
,
1408 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(rop
), bool WXUNUSED(useMask
))
1410 long width
, height
, x
, y
;
1412 #if !defined(__X__) && !defined(__WXGTK__)
1416 if (!source
->IsKindOf(CLASSINFO(wxPaintDC
))) return FALSE
;
1418 width
= (long)floor((double)fwidth
);
1419 height
= (long)floor((double)fheight
);
1420 x
= (long)floor((double)xsrc
);
1421 y
= (long)floor((double)ysrc
);
1423 /* PostScript setup: */
1424 *m_pstream
<< "gsave\n";
1425 *m_pstream
<< xdest
<< " " << YSCALE(ydest
+ fheight
) << " translate\n";
1426 *m_pstream
<< fwidth
<< " " << fheight
<< " scale\n";
1427 *m_pstream
<< "/DataString " << width
<< " string def\n";
1428 *m_pstream
<< width
<< " " << height
<< " 8 [ ";
1429 *m_pstream
<< width
<< " 0 0 " << (-height
) << " 0 " << height
;
1430 *m_pstream
<< " ]\n{\n";
1431 *m_pstream
<< " currentfile DataString readhexstring pop\n";
1432 *m_pstream
<< "} bind image\n";
1434 #if defined(__X__) || defined(__WXGTK__)
1436 /* Output data as hex digits: */
1446 cm
= ((GdkColormapPrivate
*)gdk_colormap_get_system())->xcolormap
;
1447 GdkWindow
*gwin
= ((wxClientDC
*)source
)->GetWindow();
1448 image
= XGetImage(d
, ((GdkWindowPrivate
*)gwin
)->xwindow
, x
, y
, width
, height
, AllPlanes
, ZPixmap
);
1453 // TODO. for now, use global display
1454 // d = source->display;
1455 d
= (Display
*) wxGetDisplay();
1457 d
= (Display
*) wxGetDisplay();
1460 cm
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) d
);
1461 // TODO - implement GetPixmap() and uncomment this line
1462 // image = XGetImage(d, source->GetPixmap(), x, y, width, height, AllPlanes, ZPixmap);
1469 #define CM_CACHE_SIZE 256
1470 unsigned long cachesrc
[CM_CACHE_SIZE
];
1471 int cachedest
[CM_CACHE_SIZE
], cache_pos
= 0, all_cache
= FALSE
;
1473 for (j
= 0; j
< height
; j
++) {
1474 for (i
= 0; i
< width
; i
++) {
1476 unsigned long spixel
;
1478 const unsigned short MAX_COLOR
= 0xFFFF;
1480 spixel
= XGetPixel(image
, i
, j
);
1482 for (k
= cache_pos
; k
--; )
1483 if (cachesrc
[k
] == spixel
) {
1484 pixel
= cachedest
[k
];
1488 for (k
= CM_CACHE_SIZE
; k
-- > cache_pos
; )
1489 if (cachesrc
[k
] == spixel
) {
1490 pixel
= cachedest
[k
];
1494 cachesrc
[cache_pos
] = xcol
.pixel
= spixel
;
1495 XQueryColor(d
, cm
, &xcol
);
1499 r
= (long)((double)(xcol
.red
) / MAX_COLOR
);
1500 g
= (long)((double)(xcol
.green
) / MAX_COLOR
);
1501 b
= (long)((double)(xcol
.blue
) / MAX_COLOR
);
1503 pixel
= (int)(255 * sqrt(((r
* r
) + (g
* g
) + (b
* b
)) / 3));
1505 cachedest
[cache_pos
] = pixel
;
1507 if (++cache_pos
>= CM_CACHE_SIZE
) {
1515 h
= (pixel
>> 4) & 0xF;
1521 s
[0] = 'a' + (h
- 10);
1525 s
[1] = 'a' + (l
- 10);
1532 XDestroyImage(image
);
1535 *m_pstream
<< "grestore\n";
1537 CalcBoundingBox(xdest
, (long)YSCALE(ydest
));
1538 CalcBoundingBox(xdest
+ fwidth
, (long)YSCALE(ydest
+ fheight
));
1543 long wxPostScriptDC::GetCharHeight (void)
1546 return m_font
.GetPointSize ();
1551 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1552 long *descent
, long *externalLeading
, wxFont
*theFont
,
1553 bool WXUNUSED(use16
))
1555 wxFont
*fontToUse
= theFont
;
1557 fontToUse
= (wxFont
*) &m_font
;
1561 #if !USE_AFM_FOR_POSTSCRIPT
1562 // Provide a VERY rough estimate (avoid using it)
1563 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1564 // font such as Courier (aka wxMODERN)
1568 height
= fontToUse
->GetPointSize();
1570 *x
= strlen (string
) * height
* 72 / 120;
1571 *y
= (long) (height
* 1.32); // allow for descender
1575 if (externalLeading
)
1576 *externalLeading
= 0;
1578 // +++++ start of contributed code +++++
1580 // ************************************************************
1581 // method for calculating string widths in postscript:
1582 // read in the AFM (adobe font metrics) file for the
1583 // actual font, parse it and extract the character widths
1584 // and also the descender. this may be improved, but for now
1585 // it works well. the AFM file is only read in if the
1586 // font is changed. this may be chached in the future.
1587 // calls to GetTextExtent with the font unchanged are rather
1590 // for each font and style used there is an AFM file necessary.
1591 // currently i have only files for the roman font family.
1592 // i try to get files for the other ones!
1594 // CAVE: the size of the string is currently always calculated
1595 // in 'points' (1/72 of an inch). this should later on be
1596 // changed to depend on the mapping mode.
1597 // CAVE: the path to the AFM files must be set before calling this
1598 // function. this is usually done by a call like the following:
1599 // wxSetAFMPath("d:\\wxw161\\afm\\");
1603 // wxPostScriptDC dc(NULL, TRUE);
1605 // wxSetAFMPath("d:\\wxw161\\afm\\");
1606 // dc.StartDoc("Test");
1609 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1610 // dc.GetTextExtent("Hallo",&w,&h);
1615 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1616 // created: 10.09.94
1617 // updated: 14.05.95
1619 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1620 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1621 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1623 // these static vars are for storing the state between calls
1624 static int lastFamily
= INT_MIN
;
1625 static int lastSize
= INT_MIN
;
1626 static int lastStyle
= INT_MIN
;
1627 static int lastWeight
= INT_MIN
;
1628 static int lastDescender
= INT_MIN
;
1629 static int lastWidths
[256]; // widths of the characters
1631 // get actual parameters
1632 const int Family
= fontToUse
->GetFamily();
1633 const int Size
= fontToUse
->GetPointSize();
1634 const int Style
= fontToUse
->GetStyle();
1635 const int Weight
= fontToUse
->GetWeight();
1637 // if we have another font, read the font-metrics
1638 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1639 // store actual values
1640 lastFamily
= Family
;
1643 lastWeight
= Weight
;
1645 // read in new font metrics **************************************
1647 // 1. construct filename ******************************************
1648 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1651 // Julian - we'll need to do this a different way now we've removed the
1652 // font directory system. Must find Stefan's original code.
1654 name
= wxTheFontNameDirectory
->GetAFMName(Family
, Weight
, Style
);
1658 // get the directory of the AFM files
1662 strcpy(afmName
,wxGetAFMPath());
1664 // 2. open and process the file **********************************
1666 // a short explanation of the AFM format:
1667 // we have for each character a line, which gives its size
1670 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1672 // that means, we have a character with ascii code 63, and width
1673 // (444/1000 * fontSize) points.
1674 // the other data is ignored for now!
1676 // when the font has changed, we read in the right AFM file and store the
1677 // character widths in an array, which is processed below (see point 3.).
1679 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1682 strcat(afmName
,name
);
1683 strcat(afmName
,".afm");
1684 FILE *afmFile
= fopen(afmName
,"r");
1686 wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1687 wxDebugMsg(" using approximate values\n");
1689 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1690 lastDescender
= -150; // dito.
1693 // init the widths array
1694 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1695 // some variables for holding parts of a line
1696 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1697 char upString
[30], utString
[30], encString
[50];
1700 // read in the file and parse it
1701 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1702 // A.) check for descender definition
1703 if(strncmp(line
,"Descender",9)==0){
1704 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1705 || (strcmp(descString
,"Descender")!=0)) {
1706 wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n",
1710 // JC 1.) check for UnderlinePosition
1711 else if(strncmp(line
,"UnderlinePosition",17)==0){
1712 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1713 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1714 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1718 // JC 2.) check for UnderlineThickness
1719 else if(strncmp(line
,"UnderlineThickness",18)==0){
1720 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1721 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1722 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1726 // JC 3.) check for EncodingScheme
1727 else if(strncmp(line
,"EncodingScheme",14)==0){
1728 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1729 || (strcmp(utString
,"EncodingScheme")!=0)) {
1730 wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1733 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1735 wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1736 afmName
,line
, encString
);
1739 // B.) check for char-width
1740 else if(strncmp(line
,"C ",2)==0){
1741 if(sscanf(line
,"%s%d%s%s%d",
1742 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1743 wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1745 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1746 strcmp(WXString
,"WX")!=0){
1747 wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1749 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1750 if(ascii
>=0 && ascii
<256){
1751 lastWidths
[ascii
] = cWidth
; // store width
1753 /* MATTHEW: this happens a lot; don't print an error */
1754 // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1757 // C.) ignore other entries.
1761 // hack to compute correct values for german 'Umlaute'
1762 // the correct way would be to map the character names
1763 // like 'adieresis' to corresp. positions of ISOEnc and read
1764 // these values from AFM files, too. Maybe later ...
1765 lastWidths
[196] = lastWidths
['A']; // Ä
1766 lastWidths
[228] = lastWidths
['a']; // ä
1767 lastWidths
[214] = lastWidths
['O']; // Ö
1768 lastWidths
[246] = lastWidths
['o']; // ö
1769 lastWidths
[220] = lastWidths
['U']; // Ü
1770 lastWidths
[252] = lastWidths
['u']; // ü
1771 lastWidths
[223] = lastWidths
[251]; // ß
1774 // JC: calculate UnderlineThickness/UnderlinePosition
1775 UnderlinePosition
= UnderlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1776 UnderlineThickness
= UnderlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1778 // 3. now the font metrics are read in, calc size *******************
1779 // this is done by adding the widths of the characters in the
1780 // string. they are given in 1/1000 of the size!
1783 long height
=Size
; // by default
1785 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1786 if(lastWidths
[*p
]== INT_MIN
){
1787 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1789 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1791 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1794 // add descender to height (it is usually a negative value)
1795 if(lastDescender
!=INT_MIN
){
1796 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1799 // return size values
1803 // return other parameters
1805 if(lastDescender
!=INT_MIN
){
1806 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1812 // currently no idea how to calculate this!
1813 // if (externalLeading) *externalLeading = 0;
1814 if (externalLeading
)
1815 *externalLeading
= 0;
1817 // ----- end of contributed code -----
1821 void wxPostScriptDC::DrawSpline( wxList
*points
)
1823 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1826 wxNode
*node
= points
->First();
1827 p
= (wxPoint
*)node
->Data();
1829 x1
= p
->x
; y1
= p
->y
;
1831 node
= node
->Next();
1832 p
= (wxPoint
*)node
->Data();
1834 x3
= a
= (double)(x1
+ c
) / 2;
1835 y3
= b
= (double)(y1
+ d
) / 2;
1837 *(GetStream()) << "newpath " << x1
<< " " << (GetYOrigin() - y1
) << " moveto " << x3
<< " " << (GetYOrigin() - y3
);
1838 *(GetStream()) << " lineto\n";
1839 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1840 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1842 while ((node
= node
->Next()) != NULL
)
1844 q
= (wxPoint
*)node
->Data();
1849 x3
= (double)(x2
+ c
) / 2;
1850 y3
= (double)(y2
+ d
) / 2;
1851 *(GetStream()) << x1
<< " " << (GetYOrigin() - y1
) << " " << x2
<< " " << (GetYOrigin() - y2
) << " ";
1852 *(GetStream()) << x3
<< " " << (GetYOrigin() - y3
) << " DrawSplineSection\n";
1854 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1855 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1858 * At this point, (x2,y2) and (c,d) are the position of the
1859 * next-to-last and last point respectively, in the point list
1861 *(GetStream()) << c
<< " " << (GetYOrigin() - d
) << " lineto stroke\n";
1864 long wxPostScriptDC::GetCharWidth (void)
1866 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1867 return (long) (GetCharHeight() * 72.0 / 120.0);
1871 void wxPostScriptDC::SetMapMode (int mode
)
1873 m_mappingMode
= mode
;
1874 SetLogicalOrigin(0, 0);
1875 if(m_mappingMode
== MM_METRIC
)
1877 SetUserScale(72.0f
/ 25.4f
, 72.0f
/ 25.4f
);
1881 SetUserScale(1.0, 1.0);
1887 * Set the logical origin.
1888 * Actually we are setting the printer's origin and since
1889 * postscript transformations are cumulative we need to reset
1890 * the previous origin. We also need to allow for the user scale
1891 * factor (which affects printer coords but not logical)
1893 void wxPostScriptDC::SetLogicalOrigin(long x
, long y
)
1897 long xOffset
= (long) ((m_logicalOriginX
- x
) / m_scaleFactor
);
1898 long yOffset
= (long) ((y
- m_logicalOriginY
) / m_scaleFactor
);
1902 *m_pstream
<< xOffset
<< " " << yOffset
<< " translate\n";
1905 m_logicalOriginX
= x
;
1906 m_logicalOriginY
= y
;
1910 * Obsolete - now performed by SetUserScale() and SetLogicalOrigin()
1913 wxPostScriptDC::SetupCTM()
1918 * Set the user scale.
1919 * NB: Postscript transformations are cumulative and so we
1920 * need to take into account the current scale. Also, this
1921 * affects the logical origin
1923 void wxPostScriptDC::SetUserScale (double x
, double y
)
1925 // reset logical origin
1926 long xOrg
= m_logicalOriginX
;
1927 long yOrg
= m_logicalOriginY
;
1928 SetLogicalOrigin(0, 0);
1930 // set new scale factor
1934 factor
/= m_scaleFactor
;
1938 *m_pstream
<< factor
<< " " << factor
<< " scale\n";
1941 // set logical origin at new scale
1942 SetLogicalOrigin(xOrg
, yOrg
);
1947 m_scaleFactor
= m_userScaleX
;
1950 long wxPostScriptDC::DeviceToLogicalX (int x
) const
1955 long wxPostScriptDC::DeviceToLogicalXRel (int x
) const
1960 long wxPostScriptDC::DeviceToLogicalY (int y
) const
1965 long wxPostScriptDC::DeviceToLogicalYRel (int y
) const
1970 long wxPostScriptDC::LogicalToDeviceX (long x
) const
1975 long wxPostScriptDC::LogicalToDeviceXRel (long x
) const
1980 long wxPostScriptDC::LogicalToDeviceY (long y
) const
1985 long wxPostScriptDC::LogicalToDeviceYRel (long y
) const
1990 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1992 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1994 paperType
= _("A4 210 x 297 mm");
1996 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1998 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2001 *width
= paper
->widthPixels
;
2002 *height
= paper
->heightPixels
;
2011 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
2013 const char *paperType
= wxThePrintSetupData
->GetPaperName();
2015 paperType
= _("A4 210 x 297 mm");
2017 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2019 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
2022 *width
= paper
->widthMM
;
2023 *height
= paper
->heightMM
;
2032 void wxPostScriptDC::CalcBoundingBox(long x
, long y
)
2034 long device_x
= (long) (x
- m_logicalOriginX
* m_scaleFactor
);
2035 long device_y
= (long) (y
+ m_logicalOriginY
* m_scaleFactor
);
2037 if (device_x
< m_minX
) m_minX
= device_x
;
2038 if (device_y
< m_minY
) m_minY
= device_y
;
2039 if (device_x
> m_maxX
) m_maxX
= device_x
;
2040 if (device_y
> m_maxY
) m_maxY
= device_y
;
2043 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2045 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2046 const wxPoint
& pos
, const wxSize
& size
, long style
):
2047 wxDialog(parent
, -1, title
, pos
, size
, style
)
2049 wxBeginBusyCursor();
2052 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2053 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2054 okBut
->SetDefault();
2058 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2059 (void) new wxStaticText( this, -1, _("Printer Command: "),
2061 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(),
2062 wxPoint(100, yPos
), wxSize(100, -1) );
2064 (void) new wxStaticText( this, -1, _("Printer Options: "),
2065 wxPoint(210, yPos
) );
2066 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(),
2067 wxPoint(305, yPos
), wxSize(150, -1) );
2072 wxString orientation
[2];
2073 orientation
[0] = _("Portrait");
2074 orientation
[1] = _("Landscape");
2076 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2078 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2080 // @@@ Configuration hook
2081 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
2082 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2084 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
2086 wxString print_modes
[3];
2087 print_modes
[0] = _("Send to Printer");
2088 print_modes
[1] = _("Print to File");
2089 print_modes
[2] = _("Preview Only");
2091 int features
= (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2092 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, _("PostScript:"),
2093 wxPoint(150, yPos
), wxSize(-1,-1), features
, print_modes
, features
, 0);
2096 radio1
->Enable(0, FALSE
);
2097 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2098 radio1
->Enable(2, FALSE
);
2101 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2103 long wx_printer_translate_x
, wx_printer_translate_y
;
2104 double wx_printer_scale_x
, wx_printer_scale_y
;
2105 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2106 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2108 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2112 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos
));
2113 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2115 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2116 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos
));
2117 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2121 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos
));
2122 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
2123 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2125 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos
));
2126 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
2127 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2134 int wxPostScriptPrintDialog::ShowModal (void)
2136 if ( wxDialog::ShowModal() == wxID_OK
)
2138 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2139 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2140 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2141 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2142 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2143 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2144 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2145 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2147 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
2148 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
2149 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
2150 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
2153 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2154 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2157 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
2160 switch ( radio1
->GetSelection() ) {
2161 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2162 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2163 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2170 // PostScript printer settings
2171 // RETAINED FOR BACKWARD COMPATIBILITY
2172 void wxSetPrinterCommand(const char *cmd
)
2174 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2177 void wxSetPrintPreviewCommand(const char *cmd
)
2179 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2182 void wxSetPrinterOptions(const char *flags
)
2184 wxThePrintSetupData
->SetPrinterOptions(flags
);
2187 void wxSetPrinterFile(const char *f
)
2189 wxThePrintSetupData
->SetPrinterFile(f
);
2192 void wxSetPrinterOrientation(int orient
)
2194 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2197 void wxSetPrinterScaling(double x
, double y
)
2199 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2202 void wxSetPrinterTranslation(long x
, long y
)
2204 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2207 // 1 = Preview, 2 = print to file, 3 = send to printer
2208 void wxSetPrinterMode(int mode
)
2210 wxThePrintSetupData
->SetPrinterMode(mode
);
2213 void wxSetAFMPath(const char *f
)
2215 wxThePrintSetupData
->SetAFMPath(f
);
2218 // Get current values
2219 char *wxGetPrinterCommand(void)
2221 return wxThePrintSetupData
->GetPrinterCommand();
2224 char *wxGetPrintPreviewCommand(void)
2226 return wxThePrintSetupData
->GetPrintPreviewCommand();
2229 char *wxGetPrinterOptions(void)
2231 return wxThePrintSetupData
->GetPrinterOptions();
2234 char *wxGetPrinterFile(void)
2236 return wxThePrintSetupData
->GetPrinterFile();
2239 int wxGetPrinterOrientation(void)
2241 return wxThePrintSetupData
->GetPrinterOrientation();
2244 void wxGetPrinterScaling(double* x
, double* y
)
2246 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2249 void wxGetPrinterTranslation(long *x
, long *y
)
2251 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2254 int wxGetPrinterMode(void)
2256 return wxThePrintSetupData
->GetPrinterMode();
2259 char *wxGetAFMPath(void)
2261 return wxThePrintSetupData
->GetAFMPath();
2268 wxPrintSetupData::wxPrintSetupData(void)
2270 printerCommand
= (char *) NULL
;
2271 previewCommand
= (char *) NULL
;
2272 printerFlags
= (char *) NULL
;
2273 printerOrient
= PS_PORTRAIT
;
2274 printerScaleX
= (double)1.0;
2275 printerScaleY
= (double)1.0;
2276 printerTranslateX
= 0;
2277 printerTranslateY
= 0;
2278 // 1 = Preview, 2 = print to file, 3 = send to printer
2280 afmPath
= (char *) NULL
;
2281 paperName
= (char *) NULL
;
2283 printerFile
= (char *) NULL
;
2286 wxPrintSetupData::~wxPrintSetupData(void)
2289 delete[] printerCommand
;
2291 delete[] previewCommand
;
2293 delete[] printerFlags
;
2299 delete[] printerFile
;
2302 void wxPrintSetupData::SetPrinterCommand(const char *cmd
)
2304 if (cmd
== printerCommand
)
2308 delete[] printerCommand
;
2310 printerCommand
= copystring(cmd
);
2312 printerCommand
= (char *) NULL
;
2315 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd
)
2317 if (cmd
== previewCommand
)
2321 delete[] previewCommand
;
2323 previewCommand
= copystring(cmd
);
2325 previewCommand
= (char *) NULL
;
2328 void wxPrintSetupData::SetPaperName(const char *name
)
2330 if (name
== paperName
)
2336 paperName
= copystring(name
);
2338 paperName
= (char *) NULL
;
2341 void wxPrintSetupData::SetPrinterOptions(const char *flags
)
2343 if (printerFlags
== flags
)
2347 delete[] printerFlags
;
2349 printerFlags
= copystring(flags
);
2351 printerFlags
= (char *) NULL
;
2354 void wxPrintSetupData::SetPrinterFile(const char *f
)
2356 if (f
== printerFile
)
2360 delete[] printerFile
;
2362 printerFile
= copystring(f
);
2364 printerFile
= (char *) NULL
;
2367 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2369 printerOrient
= orient
;
2372 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2378 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2380 printerTranslateX
= x
;
2381 printerTranslateY
= y
;
2384 // 1 = Preview, 2 = print to file, 3 = send to printer
2385 void wxPrintSetupData::SetPrinterMode(int mode
)
2390 void wxPrintSetupData::SetAFMPath(const char *f
)
2398 afmPath
= copystring(f
);
2400 afmPath
= (char *) NULL
;
2403 void wxPrintSetupData::SetColour(bool col
)
2408 // Get current values
2409 char *wxPrintSetupData::GetPrinterCommand(void)
2411 return printerCommand
;
2414 char *wxPrintSetupData::GetPrintPreviewCommand(void)
2416 return previewCommand
;
2419 char *wxPrintSetupData::GetPrinterOptions(void)
2421 return printerFlags
;
2424 char *wxPrintSetupData::GetPrinterFile(void)
2429 char *wxPrintSetupData::GetPaperName(void)
2434 int wxPrintSetupData::GetPrinterOrientation(void)
2436 return printerOrient
;
2439 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2445 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2447 *x
= printerTranslateX
;
2448 *y
= printerTranslateY
;
2451 int wxPrintSetupData::GetPrinterMode(void)
2456 char *wxPrintSetupData::GetAFMPath(void)
2461 bool wxPrintSetupData::GetColour(void)
2466 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2468 SetPrinterCommand(data
.GetPrinterCommand());
2469 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2470 SetPrinterOptions(data
.GetPrinterOptions());
2472 data
.GetPrinterTranslation(&x
, &y
);
2473 SetPrinterTranslation(x
, y
);
2476 data
.GetPrinterScaling(&x1
, &y1
);
2477 SetPrinterScaling(x1
, y1
);
2479 SetPrinterOrientation(data
.GetPrinterOrientation());
2480 SetPrinterMode(data
.GetPrinterMode());
2481 SetAFMPath(data
.GetAFMPath());
2482 SetPaperName(data
.GetPaperName());
2483 SetColour(data
.GetColour());
2486 void wxInitializePrintSetupData(bool init
)
2490 wxThePrintSetupData
= new wxPrintSetupData
;
2492 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2493 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2494 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2495 wxThePrintSetupData
->SetPaperName(_("A4 210 x 297 mm"));
2497 // Could have a .ini file to read in some defaults
2498 // - and/or use environment variables, e.g. WXWIN
2500 wxThePrintSetupData
->SetPrinterCommand("print");
2501 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2502 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2505 wxThePrintSetupData
->SetPrinterCommand("print");
2506 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2507 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2509 #if !defined(__VMS__) && !defined(__WXMSW__)
2510 wxThePrintSetupData
->SetPrinterCommand("lpr");
2511 wxThePrintSetupData
->SetPrinterOptions((char *) NULL
);
2512 wxThePrintSetupData
->SetAFMPath((char *) NULL
);
2517 if (wxThePrintSetupData
)
2518 delete wxThePrintSetupData
;
2519 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2524 * Paper size database for PostScript
2527 wxPrintPaperType::wxPrintPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2533 pageName
= copystring(name
);
2536 wxPrintPaperType::~wxPrintPaperType(void)
2541 wxPrintPaperDatabase::wxPrintPaperDatabase(void):wxList(wxKEY_STRING
)
2543 DeleteContents(TRUE
);
2546 wxPrintPaperDatabase::~wxPrintPaperDatabase(void)
2550 void wxPrintPaperDatabase::CreateDatabase(void)
2552 // Need correct values for page size in pixels.
2553 // Each unit is one 'point' = 1/72 of an inch.
2554 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2555 // in wxPostScriptDC code, so we can start from top left.
2556 // So access this database and translate by appropriate number
2557 // of points for this paper size. OR IS IT OK ALREADY?
2558 // Can't remember where the PostScript origin is by default.
2559 // Heck, someone will know how to make it hunky-dory...
2562 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2563 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2564 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2565 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2568 void wxPrintPaperDatabase::ClearDatabase(void)
2573 void wxPrintPaperDatabase::AddPaperType(const char *name
, int wmm
, int hmm
, int wp
, int hp
)
2575 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2578 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2580 wxNode
*node
= Find(name
);
2582 return (wxPrintPaperType
*)node
->Data();
2584 return (wxPrintPaperType
*) NULL
;
2588 * Initialization/cleanup module
2591 bool wxPostScriptModule::OnInit()
2593 wxInitializePrintSetupData();
2594 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
2595 wxThePrintPaperDatabase
->CreateDatabase();
2600 void wxPostScriptModule::OnExit()
2602 wxInitializePrintSetupData(FALSE
);
2603 delete wxThePrintPaperDatabase
;
2604 wxThePrintPaperDatabase
= NULL
;