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>
94 // Declarations local to this file
95 #define YSCALE(y) (m_yOrigin / m_scaleFactor - (y))
97 // Determine the Default Postscript Previewer
98 // available on the platform
99 #if defined(__SUN__) && defined(__XVIEW__)
100 // OpenWindow/NeWS's Postscript Previewer
101 # define PS_VIEWER_PROG "pageview"
102 #elif defined(__VMS__)
103 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
104 #elif defined(__SGI__)
105 // SGI's Display Postscript Previewer
106 //# define PS_VIEWER_PROG "dps"
107 # define PS_VIEWER_PROG "xpsview"
108 #elif defined(__X__) || defined(__WXGTK__)
109 // Front-end to ghostscript
110 # define PS_VIEWER_PROG "ghostview"
112 // Windows ghostscript/ghostview
113 # define PS_VIEWER_PROG NULL
116 wxPrintSetupData
*wxThePrintSetupData
= NULL
;
118 // these should move into wxPostscriptDC:
119 double UnderlinePosition
= 0.0F
;
120 double UnderlineThickness
= 0.0F
;
122 #define _MAXPATHLEN 500
124 /* See "wxspline.inc" and "xfspline.inc" */
125 #if USE_XFIG_SPLINE_CODE
126 static const char *wxPostScriptHeaderSpline
= " \
127 /DrawSplineSection {\n\
134 /xa x1 x2 x1 sub 0.666667 mul add def\n\
135 /ya y1 y2 y1 sub 0.666667 mul add def\n\
136 /xb x3 x2 x3 sub 0.666667 mul add def\n\
137 /yb y3 y2 y3 sub 0.666667 mul add def\n\
139 xa ya xb yb x3 y3 curveto\n\
143 // No extra PS header for this spline implementation.
144 static const char *wxPostScriptHeaderSpline
= NULL
;
146 #endif /* USE_XFIG_SPLINE_CODE */
149 // VMS has a bug in the ofstream class.
150 // the buffering doesn't work correctly. therefore
151 // we will allocate (temporarily) a very big buffer (1MB), so
152 // that a buffer overflow will not occur.
154 #define VMS_BUFSIZ (1024L*1024L)
155 static char *fileBuffer
= NULL
;
158 #if !USE_SHARED_LIBRARY
159 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
160 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData
, wxObject
)
161 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType
, wxObject
)
162 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase
, wxList
)
165 wxPostScriptDC::wxPostScriptDC (void)
167 // m_yOrigin = 792; // For EPS output
168 m_yOrigin
= 842; // For A4 output
179 // Can only send to file in Windows
180 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
184 m_currentGreen
= 255;
188 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
190 Create(file
, interactive
, parent
);
193 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
195 m_isInteractive
= interactive
;
197 m_yOrigin
= 792; // For EPS output
198 // m_yOrigin = 842; // For A4 output
209 // Can only send to file in Windows
210 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
215 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
221 m_currentGreen
= 255;
229 wxPostScriptDC::~wxPostScriptDC (void)
235 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
237 wxPostScriptPrintDialog
dialog (parent
, "Printer Settings", wxPoint(150, 150), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
238 m_ok
= (dialog
.ShowModal () == wxID_OK
) ;
243 if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
|| wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
247 wxThePrintSetupData
->SetPrinterFile("preview");
249 // For PS_PRINTER action this depends on a Unix-style print spooler
250 // since the wx_printer_file can be destroyed during a session
251 // @@@ TODO: a Windows-style answer for non-Unix
253 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
255 strcpy (tmp
, "/tmp/preview_");
256 strcat (tmp
, userId
);
257 wxThePrintSetupData
->SetPrinterFile(tmp
);
260 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
261 strcat (tmp2
, ".ps");
262 wxThePrintSetupData
->SetPrinterFile(tmp2
);
265 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
267 char *file
= wxSaveFileSelector ("PostScript", "ps");
273 wxThePrintSetupData
->SetPrinterFile(file
);
281 void wxPostScriptDC::SetClippingRegion (long cx
, long cy
, long cw
, long ch
)
289 *m_pstream
<< "gsave\n";
290 *m_pstream
<< "newpath\n";
291 *m_pstream
<< cx
<< " " << YSCALE (cy
) << " moveto\n";
292 *m_pstream
<< cx
+ cw
<< " " << YSCALE (cy
) << " lineto\n";
293 *m_pstream
<< cx
+ cw
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
294 *m_pstream
<< cx
<< " " << YSCALE (cy
+ ch
) << " lineto\n";
295 *m_pstream
<< "closepath clip newpath\n";
298 void wxPostScriptDC::DestroyClippingRegion (void)
305 *m_pstream
<< "grestore\n";
309 void wxPostScriptDC::Clear (void)
313 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
), int WXUNUSED(style
))
317 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
322 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
326 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
332 *m_pstream
<< "newpath\n";
333 *m_pstream
<< x1
<< " " << YSCALE (y1
) << " moveto\n";
334 *m_pstream
<< x2
<< " " << YSCALE (y2
) << " lineto\n";
335 *m_pstream
<< "stroke\n";
336 CalcBoundingBox (x1
, (long)YSCALE (y1
));
337 CalcBoundingBox (x2
, (long)YSCALE (y2
));
340 #define RAD2DEG 57.29577951308
342 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
349 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
350 double alpha1
, alpha2
;
352 if (x1
== x2
&& y1
== y2
) {
355 } else if (radius
== 0.0) {
356 alpha1
= alpha2
= 0.0;
358 alpha1
= (x1
- xc
== 0) ?
359 (y1
- yc
< 0) ? 90.0 : -90.0 :
360 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
361 alpha2
= (x2
- xc
== 0) ?
362 (y2
- yc
< 0) ? 90.0 : -90.0 :
363 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
365 while (alpha1
<= 0) alpha1
+= 360;
366 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
367 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
368 while (alpha2
> 360) alpha2
-= 360;
370 if (m_brush
.Ok() && m_brush
.GetStyle() != wxTRANSPARENT
) {
372 *m_pstream
<< "newpath\n"
373 << xc
<< " " << YSCALE(yc
) << " "
374 << radius
<< " " << radius
<< " "
375 << alpha1
<< " " << alpha2
<< " ellipse\n"
376 << xc
<< " " << YSCALE(yc
) << " lineto\n"
380 if (m_pen
.Ok() && m_pen
.GetStyle() != wxTRANSPARENT
) {
382 *m_pstream
<< "newpath\n"
383 << xc
<< " " << YSCALE(yc
) << " "
384 << radius
<< " " << radius
<< " "
385 << alpha1
<< " " << alpha2
<< " ellipse\n"
388 CalcBoundingBox(x1
, (long)YSCALE(y1
));
389 CalcBoundingBox(x2
, (long)YSCALE(y2
));
392 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
397 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
398 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
403 DrawEllipse(x
,y
,w
,h
);
407 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
413 x
+w
/2 << " " << YSCALE (y
+h
/2) << " " <<
414 w
/2 << " " << h
/2 << " " <<
415 int(sa
) <<" "<< int(ea
)<<" true ellipticarc\n";
417 CalcBoundingBox (x
, (long)YSCALE (y
));
418 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
420 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
426 x
+w
/2 << " " << YSCALE (y
+h
/2) << " " <<
427 w
/2 << " " << h
/2 << " " <<
428 int(sa
) <<" "<< int(ea
)<<" false ellipticarc\n";
430 CalcBoundingBox (x
, (long)YSCALE (y
));
431 CalcBoundingBox (x
+w
,(long)YSCALE(y
+h
));
435 void wxPostScriptDC::DrawPoint (long x
, long y
)
441 *m_pstream
<< "newpath\n";
442 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
443 *m_pstream
<< (x
+1) << " " << YSCALE (y
) << " lineto\n";
444 *m_pstream
<< "stroke\n";
445 CalcBoundingBox (x
, (long)YSCALE (y
));
448 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
454 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
457 *m_pstream
<< "newpath\n";
459 long xx
= points
[0].x
+ xoffset
;
460 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
461 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
462 CalcBoundingBox (xx
, yy
);
465 for (i
= 1; i
< n
; i
++)
467 xx
= points
[i
].x
+ xoffset
;
468 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
469 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
470 CalcBoundingBox (xx
, yy
);
472 *m_pstream
<< "fill\n";
475 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
478 *m_pstream
<< "newpath\n";
480 long xx
= points
[0].x
+ xoffset
;
481 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
482 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
483 CalcBoundingBox (xx
, yy
);
486 for (i
= 1; i
< n
; i
++)
488 xx
= points
[i
].x
+ xoffset
;
489 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
490 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
491 CalcBoundingBox (xx
, yy
);
495 xx
= points
[0].x
+ xoffset
;
496 yy
= (long) YSCALE (points
[0].y
+ yoffset
);
497 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
500 *m_pstream
<< "stroke\n";
505 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
514 *m_pstream
<< "newpath\n";
516 long xx
= points
[0].x
+ xoffset
;
517 long yy
= (long) YSCALE (points
[0].y
+ yoffset
);
518 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
519 CalcBoundingBox (xx
, yy
);
522 for (i
= 1; i
< n
; i
++)
524 xx
= points
[i
].x
+ xoffset
;
525 yy
= (long) YSCALE (points
[i
].y
+ yoffset
);
526 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
527 CalcBoundingBox (xx
, yy
);
529 *m_pstream
<< "stroke\n";
533 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
537 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
541 *m_pstream
<< "newpath\n";
542 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
543 *m_pstream
<< x
+ width
<< " " << YSCALE (y
) << " lineto\n";
544 *m_pstream
<< x
+ width
<< " " << YSCALE (y
+ height
) << " lineto\n";
545 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
546 *m_pstream
<< "closepath\n";
547 *m_pstream
<< "fill\n";
549 CalcBoundingBox (x
, (long)YSCALE (y
));
550 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
552 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
556 *m_pstream
<< "newpath\n";
557 *m_pstream
<< x
<< " " << YSCALE (y
) << " moveto\n";
558 *m_pstream
<< x
+ width
<< " " << YSCALE (y
) << " lineto\n";
559 *m_pstream
<< x
+ width
<< " " << YSCALE (y
+ height
) << " lineto\n";
560 *m_pstream
<< x
<< " " << YSCALE (y
+ height
) << " lineto\n";
561 *m_pstream
<< "closepath\n";
562 *m_pstream
<< "stroke\n";
564 CalcBoundingBox (x
, (long)YSCALE (y
));
565 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
569 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
576 // Now, a negative radius is interpreted to mean
577 // 'the proportion of the smallest X or Y dimension'
578 double smallest
= 0.0;
583 radius
= (-radius
* smallest
);
586 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
589 // Draw rectangle anticlockwise
590 *m_pstream
<< "newpath\n";
591 *m_pstream
<< x
+ radius
<< " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
593 *m_pstream
<< x
<< " " << YSCALE (y
+ radius
) << " moveto\n";
595 *m_pstream
<< x
+ radius
<< " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
596 *m_pstream
<< x
+ width
- radius
<< " " << YSCALE (y
+ height
) << " lineto\n";
598 *m_pstream
<< x
+ width
- radius
<< " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
599 *m_pstream
<< x
+ width
<< " " << YSCALE (y
+ radius
) << " lineto\n";
601 *m_pstream
<< x
+ width
- radius
<< " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
603 *m_pstream
<< x
+ radius
<< " " << YSCALE (y
) << " lineto\n";
605 *m_pstream
<< "closepath\n";
607 *m_pstream
<< "fill\n";
609 CalcBoundingBox (x
, (long)YSCALE (y
));
610 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
612 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
615 // Draw rectangle anticlockwise
616 *m_pstream
<< "newpath\n";
617 *m_pstream
<< x
+ radius
<< " " << YSCALE (y
+ radius
) << " " << radius
<< " 90 180 arc\n";
619 *m_pstream
<< x
<< " " << YSCALE (y
+ height
- radius
) << " lineto\n";
621 *m_pstream
<< x
+ radius
<< " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 180 270 arc\n";
622 *m_pstream
<< x
+ width
- radius
<< " " << YSCALE (y
+ height
) << " lineto\n";
624 *m_pstream
<< x
+ width
- radius
<< " " << YSCALE (y
+ height
- radius
) << " " << radius
<< " 270 0 arc\n";
625 *m_pstream
<< x
+ width
<< " " << YSCALE (y
+ radius
) << " lineto\n";
627 *m_pstream
<< x
+ width
- radius
<< " " << YSCALE (y
+ radius
) << " " << radius
<< " 0 90 arc\n";
629 *m_pstream
<< x
+ radius
<< " " << YSCALE (y
) << " lineto\n";
631 *m_pstream
<< "closepath\n";
633 *m_pstream
<< "stroke\n";
635 CalcBoundingBox (x
, (long)YSCALE (y
));
636 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
640 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
644 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
648 *m_pstream
<< "newpath\n";
649 *m_pstream
<< x
+ width
/ 2 << " " << YSCALE (y
+ height
/ 2) << " ";
650 *m_pstream
<< width
/ 2 << " " << height
/ 2 << " 0 360 ellipse\n";
651 *m_pstream
<< "fill\n";
653 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
654 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
656 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
660 *m_pstream
<< "newpath\n";
661 *m_pstream
<< x
+ width
/ 2 << " " << YSCALE (y
+ height
/ 2) << " ";
662 *m_pstream
<< width
/ 2 << " " << height
/ 2 << " 0 360 ellipse\n";
663 *m_pstream
<< "stroke\n";
665 CalcBoundingBox (x
- width
, (long)YSCALE (y
- height
));
666 CalcBoundingBox (x
+ width
, (long)YSCALE (y
+ height
));
670 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
672 #if defined(__X__) || defined(__WXGTK__)
674 memDC
.SelectObject(icon
);
675 Blit(x
, y
, icon
.GetWidth(), icon
.GetHeight(), &memDC
, 0, 0);
679 void wxPostScriptDC::SetFont (const wxFont
& the_font
)
684 if (m_font
== the_font
)
694 const char *style
= "";
695 int Style
= m_font
.GetStyle ();
696 int Weight
= m_font
.GetWeight ();
698 switch (m_font
.GetFamily ())
708 // name = "/Times-Roman";
709 name
= "/Times"; // Altered by EDZ
712 name
= "/Zapf-Chancery-MediumItalic";
717 case wxDEFAULT
: // Sans Serif Font
718 name
= "/LucidaSans";
721 if (Style
== wxNORMAL
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
723 if (m_font
.GetFamily () == wxROMAN
)
728 else if (Style
== wxNORMAL
&& Weight
== wxBOLD
)
731 else if (Style
== wxITALIC
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
733 if (m_font
.GetFamily () == wxROMAN
)
738 else if (Style
== wxITALIC
&& Weight
== wxBOLD
)
740 if (m_font
.GetFamily () == wxROMAN
)
741 style
= "-BoldItalic";
743 style
= "-BoldOblique";
745 else if (Style
== wxSLANT
&& (Weight
== wxNORMAL
|| Weight
== wxLIGHT
))
747 if (m_font
.GetFamily () == wxROMAN
)
752 else if (Style
== wxSLANT
&& Weight
== wxBOLD
)
754 if (m_font
.GetFamily () == wxROMAN
)
755 style
= "-BoldItalic";
757 style
= "-BoldOblique";
764 *m_pstream
<< buf
<< " findfont\n";
765 *m_pstream
<< m_font
.GetPointSize() * m_scaleFactor
<< " scalefont setfont\n";
768 void wxPostScriptDC::SetPen (const wxPen
& pen
)
773 int oldStyle
= m_pen
.GetStyle();
781 *m_pstream
<< m_pen
.GetWidth () << " setlinewidth\n";
783 // Line style - WRONG: 2nd arg is OFFSET
785 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
786 operator correctly. You should look-up this in the Red Book: the 2nd parame-
787 ter is not number of values in the array of the first one, but an offset
788 into this description of the pattern. I mean a real *offset* not index
789 into array. I.e. If the command is [3 4] 1 setdash is used, then there
790 will be first black line *2* units long, then space 4 units, then the
791 pattern of *3* units black, 4 units space will be repeated.
793 static const char *dotted
= "[2 5] 2";
794 static const char *short_dashed
= "[4 4] 2";
795 static const char *long_dashed
= "[4 8] 2";
796 static const char *dotted_dashed
= "[6 6 2 6] 4";
798 const char *psdash
= NULL
;
799 switch (m_pen
.GetStyle ())
805 psdash
= short_dashed
;
808 psdash
= long_dashed
;
811 psdash
= dotted_dashed
;
819 if (oldStyle
!= m_pen
.GetStyle())
820 *m_pstream
<< psdash
<< " setdash\n";
823 unsigned char red
= m_pen
.GetColour ().Red ();
824 unsigned char blue
= m_pen
.GetColour ().Blue ();
825 unsigned char green
= m_pen
.GetColour ().Green ();
829 // Anything not white is black
830 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
831 && green
== (unsigned char) 255))
833 red
= (unsigned char) 0;
834 green
= (unsigned char) 0;
835 blue
= (unsigned char) 0;
839 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
841 long redPS
= (long) (((int) red
) / 255.0);
842 long bluePS
= (long) (((int) blue
) / 255.0);
843 long greenPS
= (long) (((int) green
) / 255.0);
845 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
848 m_currentBlue
= blue
;
849 m_currentGreen
= green
;
853 void wxPostScriptDC::SetBrush (const wxBrush
& brush
)
864 unsigned char red
= m_brush
.GetColour ().Red ();
865 unsigned char blue
= m_brush
.GetColour ().Blue ();
866 unsigned char green
= m_brush
.GetColour ().Green ();
870 // Anything not black is white
871 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
872 && green
== (unsigned char) 0))
874 red
= (unsigned char) 255;
875 green
= (unsigned char) 255;
876 blue
= (unsigned char) 255;
880 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
882 long redPS
= (long) (((int) red
) / 255.0);
883 long bluePS
= (long) (((int) blue
) / 255.0);
884 long greenPS
= (long) (((int) green
) / 255.0);
885 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
887 m_currentBlue
= blue
;
888 m_currentGreen
= green
;
892 void wxPostScriptDC::DrawText (const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
))
897 // TODO: SetFont checks for identity so this will always be a NULL operation
901 if (m_textForegroundColour
.Ok ())
903 unsigned char red
= m_textForegroundColour
.Red ();
904 unsigned char blue
= m_textForegroundColour
.Blue ();
905 unsigned char green
= m_textForegroundColour
.Green ();
909 // Anything not white is black
910 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
911 && green
== (unsigned char) 255))
913 red
= (unsigned char) 0;
914 green
= (unsigned char) 0;
915 blue
= (unsigned char) 0;
918 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
920 long redPS
= (long) (((int) red
) / 255.0);
921 long bluePS
= (long) (((int) blue
) / 255.0);
922 long greenPS
= (long) (((int) green
) / 255.0);
923 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
926 m_currentBlue
= blue
;
927 m_currentGreen
= green
;
933 size
= m_font
.GetPointSize ();
935 *m_pstream
<< x
<< " " << YSCALE (y
+ size
) << " moveto\n";
937 // *m_pstream << "(" << text << ")" << " show\n";
939 int len
= strlen ((char *)(const char *)text
);
941 for (i
= 0; i
< len
; i
++)
945 if (ch == ')' || ch == '(' || ch == '\\')
949 int c
= (unsigned char) text
[i
];
950 if ( c
== ')' || c
== '(' || c
== '\\')
952 *m_pstream
<< "\\" << (char) c
;
956 // Cope with character codes > 127
958 sprintf(tmp
, "\\%o", c
);
962 *m_pstream
<< (char) c
;
965 *m_pstream
<< ")" << " show\n";
967 if (m_font
.GetUnderlined())
970 GetTextExtent(text
, &w
, &h
);
971 *m_pstream
<< "gsave " << x
<< " " << YSCALE (y
+ size
- UnderlinePosition
)
973 << UnderlineThickness
<< " setlinewidth "
974 << x
+ w
<< " " << YSCALE (y
+ size
- UnderlinePosition
)
975 << " lineto stroke grestore\n";
978 CalcBoundingBox (x
, (long)YSCALE (y
+ size
));
979 CalcBoundingBox (x
+ size
* strlen ((char *)(const char *)text
), (long)YSCALE (y
));
983 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
985 m_backgroundBrush
= brush
;
988 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
992 static const char *wxPostScriptHeaderEllipse
= "\
993 /ellipsedict 8 dict def\n\
994 ellipsedict /mtrx matrix put\n\
996 { ellipsedict begin\n\
997 /endangle exch def\n\
998 /startangle exch def\n\
1003 /savematrix mtrx currentmatrix def\n\
1006 0 0 1 startangle endangle arc\n\
1007 savematrix setmatrix\n\
1012 static const char *wxPostScriptHeaderEllipticArc
= "\
1013 /ellipticarcdict 8 dict def\n\
1014 ellipticarcdict /mtrx matrix put\n\
1016 { ellipticarcdict begin\n\
1017 /do_fill exch def\n\
1018 /endangle exch def\n\
1019 /startangle exch def\n\
1024 /savematrix mtrx currentmatrix def\n\
1027 do_fill { 0 0 moveto } if\n\
1028 0 0 1 startangle endangle arc\n\
1029 savematrix setmatrix\n\
1030 do_fill { fill }{ stroke } ifelse\n\
1034 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1036 if (m_filename
== "")
1039 m_filename
= "wxtmp.ps";
1041 m_filename
= wxGetTempFileName("ps");
1043 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1047 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1052 m_pstream
= new ofstream
;
1053 if(fileBuffer
) delete[] fileBuffer
;
1054 fileBuffer
= new char[VMS_BUFSIZ
];
1055 m_pstream
->setbuf(fileBuffer
,VMS_BUFSIZ
);
1056 m_pstream
->open(wxThePrintSetupData
->GetPrinterFile());
1058 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1060 if (!m_pstream
|| !m_pstream
->good())
1062 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1068 SetBrush (*wxBLACK_BRUSH
);
1069 SetPen (*wxBLACK_PEN
);
1077 void wxPostScriptDC::EndDoc (void)
1079 static char wxPostScriptHeaderReencodeISO1
[] =
1080 "\n/reencodeISO {\n"
1081 "dup dup findfont dup length dict begin\n"
1082 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
1083 "/Encoding ISOLatin1Encoding def\n"
1084 "currentdict end definefont\n"
1086 "/ISOLatin1Encoding [\n"
1087 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1088 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1089 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1090 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1091 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
1092 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
1093 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
1094 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
1095 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
1096 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
1097 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
1098 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1099 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1100 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
1101 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
1103 static char wxPostScriptHeaderReencodeISO2
[] =
1104 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
1105 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
1106 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
1107 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
1108 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
1109 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
1110 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
1111 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
1112 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
1113 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
1114 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
1115 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
1116 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
1117 "/yacute/thorn/ydieresis\n"
1125 *m_pstream
<< "grestore\n";
1128 // Will reuse m_pstream for header
1130 // see the definition of fileBuffer for explanation
1131 m_pstream
->close(); // steve, 05.09.94
1132 if(fileBuffer
) delete[] fileBuffer
;
1143 char *header_file
= "header.ps";
1145 char *header_file
= wxGetTempFileName("ps");
1147 m_pstream
= new ofstream (header_file
);
1149 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1150 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1151 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1152 // time_t when; time (&when);
1153 // *m_pstream << "%%CreationDate: " << ctime (&when);
1154 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1156 // User Id information
1158 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1160 *m_pstream
<< "%%For: " << (char *)userID
;
1162 if (wxGetUserName(userName
, sizeof(userName
)))
1163 *m_pstream
<< " (" << (char *)userName
<< ")";
1166 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1168 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1171 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1173 long wx_printer_translate_x
, wx_printer_translate_y
;
1174 double wx_printer_scale_x
, wx_printer_scale_y
;
1175 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1176 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1178 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1180 *m_pstream
<< "%%Orientation: Landscape\n";
1184 *m_pstream
<< "%%Orientation: Portrait\n";
1187 // Compute the bounding box. Note that it is in the default user
1188 // coordinate system, thus we have to convert the values.
1189 long llx
= (long) ((m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1190 long lly
= (long) ((m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1191 long urx
= (long) ((m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
);
1192 long ury
= (long) ((m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
);
1195 // If we're landscape, our sense of "x" and "y" is reversed.
1196 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1199 tmp
= llx
; llx
= lly
; lly
= tmp
;
1200 tmp
= urx
; urx
= ury
; ury
= tmp
;
1202 // We need either the two lines that follow, or we need to subtract
1203 // min_x from real_translate_y, which is commented out below.
1204 llx
= llx
- m_minX
*wx_printer_scale_y
;
1205 urx
= urx
- m_minX
*wx_printer_scale_y
;
1209 // The Adobe specifications call for integers; we round as to make
1210 // the bounding larger.
1211 *m_pstream
<< "%%BoundingBox: "
1212 << floor(llx
) << " " << floor(lly
) << " "
1213 << ceil(urx
) << " " << ceil(ury
) << "\n";
1214 *m_pstream
<< "%%Pages: " << wxPageNumber
- 1 << "\n";
1215 *m_pstream
<< "%%EndComments\n\n";
1217 // To check the correctness of the bounding box, postscript commands
1218 // to draw a box corresponding to the bounding box are generated below.
1219 // But since we typically don't want to print such a box, the postscript
1220 // commands are generated within comments. These lines appear before any
1221 // adjustment of scale, rotation, or translation, and hence are in the
1222 // default user coordinates.
1223 *m_pstream
<< "% newpath\n";
1224 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1225 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1226 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1227 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1231 long real_translate_y
= wx_printer_translate_y
;
1232 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1234 real_translate_y
-= m_maxY
;
1235 // The following line can be used instead of the adjustment to
1236 // llx and urx above.
1237 // real_translate_y -= m_minX;
1238 *m_pstream
<< "90 rotate\n";
1241 /* Probably don't want this now we have it in EndPage, below.
1242 * We should rationalise the scaling code to one place. JACS, October 1995
1243 * Do we take the next 2 lines out or not?
1246 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1247 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1250 *m_pstream
<< "%%BeginProlog\n";
1251 *m_pstream
<< wxPostScriptHeaderEllipse
;
1252 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1253 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1254 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1256 if (wxPostScriptHeaderSpline
)
1257 *m_pstream
<< wxPostScriptHeaderSpline
;
1258 *m_pstream
<< "%%EndProlog\n";
1264 char *tmp_file
= "tmp.ps";
1266 char *tmp_file
= wxGetTempFileName("ps");
1269 // Paste header Before wx_printer_file
1270 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1271 wxRemoveFile (header_file
);
1272 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1273 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1275 #if defined(__X__) || defined(__WXGTK__)
1278 switch (wxThePrintSetupData
->GetPrinterMode()) {
1282 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1283 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1285 wxExecute (argv
, TRUE
);
1286 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1294 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1296 // !SM! If we simply assign to argv[1] here, if printer options
1297 // are blank, we get an annoying and confusing message from lpr.
1298 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1300 argv
[argc
++] = opts
;
1302 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1303 argv
[argc
++] = NULL
;
1304 wxExecute (argv
, TRUE
);
1305 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1316 void wxPostScriptDC::StartPage (void)
1320 *m_pstream
<< "%%Page: " << wxPageNumber
++ << "\n";
1321 // *m_pstream << "matrix currentmatrix\n";
1323 // Added by Chris Breeze
1325 // Each page starts with an "initgraphics" which resets the
1326 // transformation and so we need to reset the origin
1327 // (and rotate the page for landscape printing)
1328 m_scaleFactor
= 1.0;
1329 m_logicalOriginX
= 0;
1330 m_logicalOriginY
= 0;
1333 long translate_x
, translate_y
;
1334 double scale_x
, scale_y
;
1335 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1336 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1338 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1340 translate_y
-= GetYOrigin();
1341 *m_pstream
<< "90 rotate\n";
1344 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1345 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1348 void wxPostScriptDC::EndPage (void)
1352 *m_pstream
<< "showpage\n";
1354 // Removed by Chris Breeze
1356 *m_pstream
<< "setmatrix\n";
1358 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1360 long wx_printer_translate_x
, wx_printer_translate_y
;
1361 double wx_printer_scale_x
, wx_printer_scale_y
;
1362 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1363 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1365 // Compute the bounding box. Note that it is in the default user
1366 // coordinate system, thus we have to convert the values.
1367 long llx
= (m_minX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1368 long lly
= (m_minY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1369 long urx
= (m_maxX
+wx_printer_translate_x
)*wx_printer_scale_x
;
1370 long ury
= (m_maxY
+wx_printer_translate_y
)*wx_printer_scale_y
;
1372 // If we're landscape, our sense of "x" and "y" is reversed.
1373 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1376 tmp
= llx
; llx
= lly
; lly
= tmp
;
1377 tmp
= urx
; urx
= ury
; ury
= tmp
;
1379 // We need either the two lines that follow, or we need to subtract
1380 // m_minX from real_translate_y, which is commented out below.
1381 llx
= llx
- m_minX
*wx_printer_scale_y
;
1382 urx
= urx
- m_minX
*wx_printer_scale_y
;
1386 long real_translate_y
= wx_printer_translate_y
;
1387 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1389 real_translate_y
-= m_maxY
;
1390 // The following line can be used instead of the adjustment to
1391 // llx and urx above.
1392 // real_translate_y -= m_minX;
1393 *m_pstream
<< "90 rotate\n";
1396 *m_pstream
<< wx_printer_scale_x
<< " " << wx_printer_scale_y
<< " scale\n";
1397 *m_pstream
<< wx_printer_translate_x
<< " " << real_translate_y
<< " translate\n";
1401 /* MATTHEW: Implement Blit: */
1402 /* MATTHEW: [4] Re-wrote to use colormap */
1403 bool wxPostScriptDC::
1404 Blit (long xdest
, long ydest
, long fwidth
, long fheight
,
1405 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(rop
), bool WXUNUSED(useMask
))
1407 long width
, height
, x
, y
;
1409 #if !defined(__X__) && !defined(__WXGTK__)
1413 if (!source
->IsKindOf(CLASSINFO(wxPaintDC
))) return FALSE
;
1415 width
= (long)floor(fwidth
);
1416 height
= (long)floor(fheight
);
1417 x
= (long)floor(xsrc
);
1418 y
= (long)floor(ysrc
);
1420 /* PostScript setup: */
1421 *m_pstream
<< "gsave\n";
1422 *m_pstream
<< xdest
<< " " << YSCALE(ydest
+ fheight
) << " translate\n";
1423 *m_pstream
<< fwidth
<< " " << fheight
<< " scale\n";
1424 *m_pstream
<< "/DataString " << width
<< " string def\n";
1425 *m_pstream
<< width
<< " " << height
<< " 8 [ ";
1426 *m_pstream
<< width
<< " 0 0 " << (-height
) << " 0 " << height
;
1427 *m_pstream
<< " ]\n{\n";
1428 *m_pstream
<< " currentfile DataString readhexstring pop\n";
1429 *m_pstream
<< "} bind image\n";
1431 #if defined(__X__) || defined(__WXGTK__)
1433 /* Output data as hex digits: */
1443 cm
= ((GdkColormapPrivate
*)gdk_colormap_get_system())->xcolormap
;
1444 GdkWindow
*gwin
= ((wxClientDC
*)source
)->GetWindow();
1445 image
= XGetImage(d
, ((GdkWindowPrivate
*)gwin
)->xwindow
, x
, y
, width
, height
, AllPlanes
, ZPixmap
);
1450 d
= source
->display
;
1455 cm
= wxGetMainColormap(d
);
1456 image
= XGetImage(d
, source
->pixmap
, x
, y
, width
, height
, AllPlanes
, ZPixmap
);
1463 #define CM_CACHE_SIZE 256
1464 unsigned long cachesrc
[CM_CACHE_SIZE
];
1465 int cachedest
[CM_CACHE_SIZE
], cache_pos
= 0, all_cache
= FALSE
;
1467 for (j
= 0; j
< height
; j
++) {
1468 for (i
= 0; i
< width
; i
++) {
1470 unsigned long spixel
;
1472 const unsigned short MAX_COLOR
= 0xFFFF;
1474 spixel
= XGetPixel(image
, i
, j
);
1476 for (k
= cache_pos
; k
--; )
1477 if (cachesrc
[k
] == spixel
) {
1478 pixel
= cachedest
[k
];
1482 for (k
= CM_CACHE_SIZE
; k
-- > cache_pos
; )
1483 if (cachesrc
[k
] == spixel
) {
1484 pixel
= cachedest
[k
];
1488 cachesrc
[cache_pos
] = xcol
.pixel
= spixel
;
1489 XQueryColor(d
, cm
, &xcol
);
1493 r
= (long)((double)(xcol
.red
) / MAX_COLOR
);
1494 g
= (long)((double)(xcol
.green
) / MAX_COLOR
);
1495 b
= (long)((double)(xcol
.blue
) / MAX_COLOR
);
1497 pixel
= (int)(255 * sqrt(((r
* r
) + (g
* g
) + (b
* b
)) / 3));
1499 cachedest
[cache_pos
] = pixel
;
1501 if (++cache_pos
>= CM_CACHE_SIZE
) {
1509 h
= (pixel
>> 4) & 0xF;
1515 s
[0] = 'a' + (h
- 10);
1519 s
[1] = 'a' + (l
- 10);
1526 XDestroyImage(image
);
1529 *m_pstream
<< "grestore\n";
1531 CalcBoundingBox(xdest
, (long)YSCALE(ydest
));
1532 CalcBoundingBox(xdest
+ fwidth
, (long)YSCALE(ydest
+ fheight
));
1537 long wxPostScriptDC::GetCharHeight (void)
1540 return m_font
.GetPointSize ();
1545 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1546 long *descent
, long *externalLeading
, wxFont
*theFont
,
1547 bool WXUNUSED(use16
))
1549 wxFont
*fontToUse
= theFont
;
1551 fontToUse
= (wxFont
*) &m_font
;
1555 #if !USE_AFM_FOR_POSTSCRIPT
1556 // Provide a VERY rough estimate (avoid using it)
1557 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1558 // font such as Courier (aka wxMODERN)
1562 height
= fontToUse
->GetPointSize();
1564 *x
= strlen (string
) * height
* 72 / 120;
1565 *y
= (long) (height
* 1.32); // allow for descender
1569 if (externalLeading
)
1570 *externalLeading
= 0;
1572 // +++++ start of contributed code +++++
1574 // ************************************************************
1575 // method for calculating string widths in postscript:
1576 // read in the AFM (adobe font metrics) file for the
1577 // actual font, parse it and extract the character widths
1578 // and also the descender. this may be improved, but for now
1579 // it works well. the AFM file is only read in if the
1580 // font is changed. this may be chached in the future.
1581 // calls to GetTextExtent with the font unchanged are rather
1584 // for each font and style used there is an AFM file necessary.
1585 // currently i have only files for the roman font family.
1586 // i try to get files for the other ones!
1588 // CAVE: the size of the string is currently always calculated
1589 // in 'points' (1/72 of an inch). this should later on be
1590 // changed to depend on the mapping mode.
1591 // CAVE: the path to the AFM files must be set before calling this
1592 // function. this is usually done by a call like the following:
1593 // wxSetAFMPath("d:\\wxw161\\afm\\");
1597 // wxPostScriptDC dc(NULL, TRUE);
1599 // wxSetAFMPath("d:\\wxw161\\afm\\");
1600 // dc.StartDoc("Test");
1603 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1604 // dc.GetTextExtent("Hallo",&w,&h);
1609 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1610 // created: 10.09.94
1611 // updated: 14.05.95
1613 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1614 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1615 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1617 // these static vars are for storing the state between calls
1618 static int lastFamily
= INT_MIN
;
1619 static int lastSize
= INT_MIN
;
1620 static int lastStyle
= INT_MIN
;
1621 static int lastWeight
= INT_MIN
;
1622 static int lastDescender
= INT_MIN
;
1623 static int lastWidths
[256]; // widths of the characters
1625 // get actual parameters
1626 const int Family
= fontToUse
->GetFamily();
1627 const int Size
= fontToUse
->GetPointSize();
1628 const int Style
= fontToUse
->GetStyle();
1629 const int Weight
= fontToUse
->GetWeight();
1631 // if we have another font, read the font-metrics
1632 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1633 // store actual values
1634 lastFamily
= Family
;
1637 lastWeight
= Weight
;
1639 // read in new font metrics **************************************
1641 // 1. construct filename ******************************************
1642 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1645 // Julian - we'll need to do this a different way now we've removed the
1646 // font directory system. Must find Stefan's original code.
1648 name
= wxTheFontNameDirectory
.GetAFMName(Family
, Weight
, Style
);
1652 // get the directory of the AFM files
1656 strcpy(afmName
,wxGetAFMPath());
1658 // 2. open and process the file **********************************
1660 // a short explanation of the AFM format:
1661 // we have for each character a line, which gives its size
1664 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1666 // that means, we have a character with ascii code 63, and width
1667 // (444/1000 * fontSize) points.
1668 // the other data is ignored for now!
1670 // when the font has changed, we read in the right AFM file and store the
1671 // character widths in an array, which is processed below (see point 3.).
1673 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1676 strcat(afmName
,name
);
1677 strcat(afmName
,".afm");
1678 FILE *afmFile
= fopen(afmName
,"r");
1680 wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1681 wxDebugMsg(" using approximate values\n");
1683 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1684 lastDescender
= -150; // dito.
1687 // init the widths array
1688 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1689 // some variables for holding parts of a line
1690 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1691 char upString
[30], utString
[30], encString
[50];
1694 // read in the file and parse it
1695 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1696 // A.) check for descender definition
1697 if(strncmp(line
,"Descender",9)==0){
1698 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1699 || (strcmp(descString
,"Descender")!=0)) {
1700 wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n",
1704 // JC 1.) check for UnderlinePosition
1705 else if(strncmp(line
,"UnderlinePosition",17)==0){
1706 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1707 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1708 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1712 // JC 2.) check for UnderlineThickness
1713 else if(strncmp(line
,"UnderlineThickness",18)==0){
1714 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1715 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1716 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1720 // JC 3.) check for EncodingScheme
1721 else if(strncmp(line
,"EncodingScheme",14)==0){
1722 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1723 || (strcmp(utString
,"EncodingScheme")!=0)) {
1724 wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1727 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1729 wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1730 afmName
,line
, encString
);
1733 // B.) check for char-width
1734 else if(strncmp(line
,"C ",2)==0){
1735 if(sscanf(line
,"%s%d%s%s%d",
1736 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1737 wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1739 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1740 strcmp(WXString
,"WX")!=0){
1741 wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1743 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1744 if(ascii
>=0 && ascii
<256){
1745 lastWidths
[ascii
] = cWidth
; // store width
1747 /* MATTHEW: this happens a lot; don't print an error */
1748 // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1751 // C.) ignore other entries.
1755 // hack to compute correct values for german 'Umlaute'
1756 // the correct way would be to map the character names
1757 // like 'adieresis' to corresp. positions of ISOEnc and read
1758 // these values from AFM files, too. Maybe later ...
1759 lastWidths
[196] = lastWidths
['A']; // Ä
1760 lastWidths
[228] = lastWidths
['a']; // ä
1761 lastWidths
[214] = lastWidths
['O']; // Ö
1762 lastWidths
[246] = lastWidths
['o']; // ö
1763 lastWidths
[220] = lastWidths
['U']; // Ü
1764 lastWidths
[252] = lastWidths
['u']; // ü
1765 lastWidths
[223] = lastWidths
[251]; // ß
1768 // JC: calculate UnderlineThickness/UnderlinePosition
1769 UnderlinePosition
= UnderlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1770 UnderlineThickness
= UnderlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1772 // 3. now the font metrics are read in, calc size *******************
1773 // this is done by adding the widths of the characters in the
1774 // string. they are given in 1/1000 of the size!
1777 long height
=Size
; // by default
1779 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1780 if(lastWidths
[*p
]== INT_MIN
){
1781 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1783 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1785 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1788 // add descender to height (it is usually a negative value)
1789 if(lastDescender
!=INT_MIN
){
1790 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1793 // return size values
1797 // return other parameters
1799 if(lastDescender
!=INT_MIN
){
1800 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1806 // currently no idea how to calculate this!
1807 // if (externalLeading) *externalLeading = 0;
1808 if (externalLeading
)
1809 *externalLeading
= 0;
1811 // ----- end of contributed code -----
1815 void wxPostScriptDC::DrawOpenSpline( wxList
*points
)
1817 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1820 wxNode
*node
= points
->First();
1821 p
= (wxPoint
*)node
->Data();
1823 x1
= p
->x
; y1
= p
->y
;
1825 node
= node
->Next();
1826 p
= (wxPoint
*)node
->Data();
1828 x3
= a
= (double)(x1
+ c
) / 2;
1829 y3
= b
= (double)(y1
+ d
) / 2;
1831 *(GetStream()) << "newpath " << x1
<< " " << GetYOrigin() - y1
<< " moveto " << x3
<< " " << GetYOrigin() - y3
;
1832 *(GetStream()) << " lineto\n";
1833 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1834 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1836 while ((node
= node
->Next()) != NULL
)
1838 q
= (wxPoint
*)node
->Data();
1843 x3
= (double)(x2
+ c
) / 2;
1844 y3
= (double)(y2
+ d
) / 2;
1845 *(GetStream()) << x1
<< " " << GetYOrigin() - y1
<< " " << x2
<< " " << GetYOrigin() - y2
<< " ";
1846 *(GetStream()) << x3
<< " " << GetYOrigin() - y3
<< " DrawSplineSection\n";
1848 CalcBoundingBox( (long)x1
, (long)(GetYOrigin() - y1
));
1849 CalcBoundingBox( (long)x3
, (long)(GetYOrigin() - y3
));
1852 * At this point, (x2,y2) and (c,d) are the position of the
1853 * next-to-last and last point respectively, in the point list
1855 *(GetStream()) << c
<< " " << GetYOrigin() - d
<< " lineto stroke\n";
1858 long wxPostScriptDC::GetCharWidth (void)
1860 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1861 return (long) (GetCharHeight() * 72.0 / 120.0);
1865 void wxPostScriptDC::SetMapMode (int mode
)
1867 m_mappingMode
= mode
;
1868 SetLogicalOrigin(0, 0);
1869 if(m_mappingMode
== MM_METRIC
)
1871 SetUserScale(72.0f
/ 25.4f
, 72.0f
/ 25.4f
);
1875 SetUserScale(1.0, 1.0);
1881 * Set the logical origin.
1882 * Actually we are setting the printer's origin and since
1883 * postscript transformations are cumulative we need to reset
1884 * the previous origin. We also need to allow for the user scale
1885 * factor (which affects printer coords but not logical)
1887 void wxPostScriptDC::SetLogicalOrigin(long x
, long y
)
1891 long xOffset
= (long) ((m_logicalOriginX
- x
) / m_scaleFactor
);
1892 long yOffset
= (long) ((y
- m_logicalOriginY
) / m_scaleFactor
);
1896 *m_pstream
<< xOffset
<< " " << yOffset
<< " translate\n";
1899 m_logicalOriginX
= x
;
1900 m_logicalOriginY
= y
;
1904 * Obsolete - now performed by SetUserScale() and SetLogicalOrigin()
1907 wxPostScriptDC::SetupCTM()
1912 * Set the user scale.
1913 * NB: Postscript transformations are cumulative and so we
1914 * need to take into account the current scale. Also, this
1915 * affects the logical origin
1917 void wxPostScriptDC::SetUserScale (double x
, double y
)
1919 // reset logical origin
1920 long xOrg
= m_logicalOriginX
;
1921 long yOrg
= m_logicalOriginY
;
1922 SetLogicalOrigin(0, 0);
1924 // set new scale factor
1928 factor
/= m_scaleFactor
;
1932 *m_pstream
<< factor
<< " " << factor
<< " scale\n";
1935 // set logical origin at new scale
1936 SetLogicalOrigin(xOrg
, yOrg
);
1941 m_scaleFactor
= m_userScaleX
;
1944 long wxPostScriptDC::DeviceToLogicalX (int x
) const
1949 long wxPostScriptDC::DeviceToLogicalXRel (int x
) const
1954 long wxPostScriptDC::DeviceToLogicalY (int y
) const
1959 long wxPostScriptDC::DeviceToLogicalYRel (int y
) const
1964 long wxPostScriptDC::LogicalToDeviceX (long x
) const
1969 long wxPostScriptDC::LogicalToDeviceXRel (long x
) const
1974 long wxPostScriptDC::LogicalToDeviceY (long y
) const
1979 long wxPostScriptDC::LogicalToDeviceYRel (long y
) const
1984 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1986 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1988 paperType
= "A4 210 x 297 mm";
1990 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1992 paper
= wxThePrintPaperDatabase
->FindPaperType("A4 210 x 297 mm");
1995 *width
= paper
->widthPixels
;
1996 *height
= paper
->heightPixels
;
2005 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
2007 const char *paperType
= wxThePrintSetupData
->GetPaperName();
2009 paperType
= "A4 210 x 297 mm";
2011 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
2013 paper
= wxThePrintPaperDatabase
->FindPaperType("A4 210 x 297 mm");
2016 *width
= paper
->widthMM
;
2017 *height
= paper
->heightMM
;
2026 void wxPostScriptDC::CalcBoundingBox(long x
, long y
)
2028 long device_x
= (long) (x
- m_logicalOriginX
* m_scaleFactor
);
2029 long device_y
= (long) (y
+ m_logicalOriginY
* m_scaleFactor
);
2031 if (device_x
< m_minX
) m_minX
= device_x
;
2032 if (device_y
< m_minY
) m_minY
= device_y
;
2033 if (device_x
> m_maxX
) m_maxX
= device_x
;
2034 if (device_y
> m_maxY
) m_maxY
= device_y
;
2037 IMPLEMENT_CLASS(wxPostScriptPrintDialog
, wxDialog
)
2039 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow
*parent
, const wxString
& title
,
2040 const wxPoint
& pos
, const wxSize
& size
, long style
):
2041 wxDialog(parent
, -1, title
, pos
, size
, style
)
2043 wxBeginBusyCursor();
2046 wxButton
*okBut
= new wxButton (this, wxID_OK
, _("OK"), wxPoint(5, 5));
2047 (void) new wxButton (this, wxID_CANCEL
, _("Cancel"), wxPoint(40, 5));
2048 okBut
->SetDefault();
2052 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2053 (void) new wxStaticText(this, -1, _("Printer Command: "), wxPoint(5, yPos
));
2054 wxTextCtrl
*text_prt
= new wxTextCtrl(this, wxID_PRINTER_COMMAND
, wxThePrintSetupData
->GetPrinterCommand(), wxPoint(100, yPos
), wxSize(100, -1));
2056 (void) new wxStaticText(this, -1, "Printer Options: ", wxPoint(210, yPos
));
2057 wxTextCtrl
*text0
= new wxTextCtrl(this, wxID_PRINTER_OPTIONS
, wxThePrintSetupData
->GetPrinterOptions(), wxPoint(305, yPos
), wxSize(150, -1));
2062 wxString orientation
[2];
2063 orientation
[0] = "Portrait";
2064 orientation
[1] = "Landscape";
2066 wxRadioBox
*radio0
= new wxRadioBox(this, wxID_PRINTER_ORIENTATION
, "Orientation: ", wxPoint(5, yPos
), wxSize(-1,-1),
2068 radio0
->SetSelection((int)wxThePrintSetupData
->GetPrinterOrientation() - 1);
2070 // @@@ Configuration hook
2071 if (wxThePrintSetupData
->GetPrintPreviewCommand() == NULL
)
2072 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2074 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData
->previewCommand
);
2076 wxString print_modes
[3];
2077 print_modes
[0] = "Send to Printer";
2078 print_modes
[1] = "Print to File";
2079 print_modes
[2] = "Preview Only";
2081 int features
= (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand()) ? 3 : 2;
2082 wxRadioBox
*radio1
= new wxRadioBox(this, wxID_PRINTER_MODES
, "PostScript:",
2083 wxPoint(150, yPos
), wxSize(-1,-1), features
, print_modes
, features
, 0);
2086 radio1
->Enable(0, FALSE
);
2087 if (wxThePrintSetupData
->GetPrintPreviewCommand() && *wxThePrintSetupData
->GetPrintPreviewCommand())
2088 radio1
->Enable(2, FALSE
);
2091 radio1
->SetSelection((int)wxThePrintSetupData
->GetPrinterMode());
2093 long wx_printer_translate_x
, wx_printer_translate_y
;
2094 double wx_printer_scale_x
, wx_printer_scale_y
;
2095 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
2096 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
2098 sprintf (buf
, "%.2f", wx_printer_scale_x
);
2102 (void) new wxStaticText(this, -1, "X Scaling", wxPoint(5, yPos
));
2103 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2105 sprintf (buf
, "%.2f", wx_printer_scale_y
);
2106 (void) new wxStaticText(this, -1, "Y Scaling", wxPoint(220, yPos
));
2107 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2111 (void) new wxStaticText(this, -1, "X Translation", wxPoint(5, yPos
));
2112 sprintf (buf
, "%.2ld", wx_printer_translate_x
);
2113 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS
, buf
, wxPoint(100, yPos
), wxSize(100, -1));
2115 (void) new wxStaticText(this, -1, "Y Translation", wxPoint(220, yPos
));
2116 sprintf (buf
, "%.2ld", wx_printer_translate_y
);
2117 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS
, buf
, wxPoint(320, yPos
), wxSize(100, -1));
2124 int wxPostScriptPrintDialog::ShowModal (void)
2126 if ( wxDialog::ShowModal() == wxID_OK
)
2128 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2129 wxTextCtrl
*text1
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_SCALE
);
2130 wxTextCtrl
*text2
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_SCALE
);
2131 wxTextCtrl
*text3
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_X_TRANS
);
2132 wxTextCtrl
*text4
= (wxTextCtrl
*)FindWindow(wxID_PRINTER_Y_TRANS
);
2133 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2134 wxRadioBox
*radio0
= (wxRadioBox
*)FindWindow(wxID_PRINTER_ORIENTATION
);
2135 wxRadioBox
*radio1
= (wxRadioBox
*)FindWindow(wxID_PRINTER_MODES
);
2137 StringToDouble (WXSTRINGCAST text1
->GetValue (), &wxThePrintSetupData
->printerScaleX
);
2138 StringToDouble (WXSTRINGCAST text2
->GetValue (), &wxThePrintSetupData
->printerScaleY
);
2139 StringToLong (WXSTRINGCAST text3
->GetValue (), &wxThePrintSetupData
->printerTranslateX
);
2140 StringToLong (WXSTRINGCAST text4
->GetValue (), &wxThePrintSetupData
->printerTranslateY
);
2143 wxThePrintSetupData
->SetPrinterOptions(WXSTRINGCAST text0
->GetValue ());
2144 wxThePrintSetupData
->SetPrinterCommand(WXSTRINGCAST text_prt
->GetValue ());
2147 wxThePrintSetupData
->SetPrinterOrientation((radio0
->GetSelection() == 1 ? PS_LANDSCAPE
: PS_PORTRAIT
));
2150 switch ( radio1
->GetSelection() ) {
2151 case 0: wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
); break;
2152 case 1: wxThePrintSetupData
->SetPrinterMode(PS_FILE
); break;
2153 case 2: wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
); break;
2160 // PostScript printer settings
2161 // RETAINED FOR BACKWARD COMPATIBILITY
2162 void wxSetPrinterCommand(char *cmd
)
2164 wxThePrintSetupData
->SetPrinterCommand(cmd
);
2167 void wxSetPrintPreviewCommand(char *cmd
)
2169 wxThePrintSetupData
->SetPrintPreviewCommand(cmd
);
2172 void wxSetPrinterOptions(char *flags
)
2174 wxThePrintSetupData
->SetPrinterOptions(flags
);
2177 void wxSetPrinterFile(char *f
)
2179 wxThePrintSetupData
->SetPrinterFile(f
);
2182 void wxSetPrinterOrientation(int orient
)
2184 wxThePrintSetupData
->SetPrinterOrientation(orient
);
2187 void wxSetPrinterScaling(double x
, double y
)
2189 wxThePrintSetupData
->SetPrinterScaling(x
, y
);
2192 void wxSetPrinterTranslation(long x
, long y
)
2194 wxThePrintSetupData
->SetPrinterTranslation(x
, y
);
2197 // 1 = Preview, 2 = print to file, 3 = send to printer
2198 void wxSetPrinterMode(int mode
)
2200 wxThePrintSetupData
->SetPrinterMode(mode
);
2203 void wxSetAFMPath(char *f
)
2205 wxThePrintSetupData
->SetAFMPath(f
);
2208 // Get current values
2209 char *wxGetPrinterCommand(void)
2211 return wxThePrintSetupData
->GetPrinterCommand();
2214 char *wxGetPrintPreviewCommand(void)
2216 return wxThePrintSetupData
->GetPrintPreviewCommand();
2219 char *wxGetPrinterOptions(void)
2221 return wxThePrintSetupData
->GetPrinterOptions();
2224 char *wxGetPrinterFile(void)
2226 return wxThePrintSetupData
->GetPrinterFile();
2229 int wxGetPrinterOrientation(void)
2231 return wxThePrintSetupData
->GetPrinterOrientation();
2234 void wxGetPrinterScaling(double* x
, double* y
)
2236 wxThePrintSetupData
->GetPrinterScaling(x
, y
);
2239 void wxGetPrinterTranslation(long *x
, long *y
)
2241 wxThePrintSetupData
->GetPrinterTranslation(x
, y
);
2244 int wxGetPrinterMode(void)
2246 return wxThePrintSetupData
->GetPrinterMode();
2249 char *wxGetAFMPath(void)
2251 return wxThePrintSetupData
->GetAFMPath();
2258 wxPrintSetupData::wxPrintSetupData(void)
2260 printerCommand
= NULL
;
2261 previewCommand
= NULL
;
2262 printerFlags
= NULL
;
2263 printerOrient
= PS_PORTRAIT
;
2264 printerScaleX
= (double)1.0;
2265 printerScaleY
= (double)1.0;
2266 printerTranslateX
= 0;
2267 printerTranslateY
= 0;
2268 // 1 = Preview, 2 = print to file, 3 = send to printer
2276 wxPrintSetupData::~wxPrintSetupData(void)
2279 delete[] printerCommand
;
2281 delete[] previewCommand
;
2283 delete[] printerFlags
;
2289 delete[] printerFile
;
2292 void wxPrintSetupData::SetPrinterCommand(char *cmd
)
2294 if (cmd
== printerCommand
)
2298 delete[] printerCommand
;
2300 printerCommand
= copystring(cmd
);
2302 printerCommand
= NULL
;
2305 void wxPrintSetupData::SetPrintPreviewCommand(char *cmd
)
2307 if (cmd
== previewCommand
)
2311 delete[] previewCommand
;
2313 previewCommand
= copystring(cmd
);
2315 previewCommand
= NULL
;
2318 void wxPrintSetupData::SetPaperName(char *name
)
2320 if (name
== paperName
)
2326 paperName
= copystring(name
);
2331 void wxPrintSetupData::SetPrinterOptions(char *flags
)
2333 if (printerFlags
== flags
)
2337 delete[] printerFlags
;
2339 printerFlags
= copystring(flags
);
2341 printerFlags
= NULL
;
2344 void wxPrintSetupData::SetPrinterFile(char *f
)
2346 if (f
== printerFile
)
2350 delete[] printerFile
;
2352 printerFile
= copystring(f
);
2357 void wxPrintSetupData::SetPrinterOrientation(int orient
)
2359 printerOrient
= orient
;
2362 void wxPrintSetupData::SetPrinterScaling(double x
, double y
)
2368 void wxPrintSetupData::SetPrinterTranslation(long x
, long y
)
2370 printerTranslateX
= x
;
2371 printerTranslateY
= y
;
2374 // 1 = Preview, 2 = print to file, 3 = send to printer
2375 void wxPrintSetupData::SetPrinterMode(int mode
)
2380 void wxPrintSetupData::SetAFMPath(char *f
)
2388 afmPath
= copystring(f
);
2393 void wxPrintSetupData::SetColour(bool col
)
2398 // Get current values
2399 char *wxPrintSetupData::GetPrinterCommand(void)
2401 return printerCommand
;
2404 char *wxPrintSetupData::GetPrintPreviewCommand(void)
2406 return previewCommand
;
2409 char *wxPrintSetupData::GetPrinterOptions(void)
2411 return printerFlags
;
2414 char *wxPrintSetupData::GetPrinterFile(void)
2419 char *wxPrintSetupData::GetPaperName(void)
2424 int wxPrintSetupData::GetPrinterOrientation(void)
2426 return printerOrient
;
2429 void wxPrintSetupData::GetPrinterScaling(double *x
, double *y
)
2435 void wxPrintSetupData::GetPrinterTranslation(long *x
, long *y
)
2437 *x
= printerTranslateX
;
2438 *y
= printerTranslateY
;
2441 int wxPrintSetupData::GetPrinterMode(void)
2446 char *wxPrintSetupData::GetAFMPath(void)
2451 bool wxPrintSetupData::GetColour(void)
2456 void wxPrintSetupData::operator=(wxPrintSetupData
& data
)
2458 SetPrinterCommand(data
.GetPrinterCommand());
2459 SetPrintPreviewCommand(data
.GetPrintPreviewCommand());
2460 SetPrinterOptions(data
.GetPrinterOptions());
2462 data
.GetPrinterTranslation(&x
, &y
);
2463 SetPrinterTranslation(x
, y
);
2466 data
.GetPrinterScaling(&x1
, &y1
);
2467 SetPrinterScaling(x1
, y1
);
2469 SetPrinterOrientation(data
.GetPrinterOrientation());
2470 SetPrinterMode(data
.GetPrinterMode());
2471 SetAFMPath(data
.GetAFMPath());
2472 SetPaperName(data
.GetPaperName());
2473 SetColour(data
.GetColour());
2476 void wxInitializePrintSetupData(bool init
)
2480 wxThePrintSetupData
= new wxPrintSetupData
;
2482 wxThePrintSetupData
->SetPrintPreviewCommand(PS_VIEWER_PROG
);
2483 wxThePrintSetupData
->SetPrinterOrientation(PS_PORTRAIT
);
2484 wxThePrintSetupData
->SetPrinterMode(PS_PREVIEW
);
2485 wxThePrintSetupData
->SetPaperName("A4 210 x 297 mm");
2487 // Could have a .ini file to read in some defaults
2488 // - and/or use environment variables, e.g. WXWIN
2490 wxThePrintSetupData
->SetPrinterCommand("print");
2491 wxThePrintSetupData
->SetPrinterOptions("/nonotify/queue=psqueue");
2492 wxThePrintSetupData
->SetAFMPath("sys$ps_font_metrics:");
2495 wxThePrintSetupData
->SetPrinterCommand("print");
2496 wxThePrintSetupData
->SetAFMPath("c:\\windows\\system\\");
2497 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2499 #if !defined(__VMS__) && !defined(__WXMSW__)
2500 wxThePrintSetupData
->SetPrinterCommand("lpr");
2501 wxThePrintSetupData
->SetPrinterOptions(NULL
);
2502 wxThePrintSetupData
->SetAFMPath(NULL
);
2507 if (wxThePrintSetupData
)
2508 delete wxThePrintSetupData
;
2509 wxThePrintSetupData
= NULL
;
2514 * Paper size database for PostScript
2517 wxPrintPaperType::wxPrintPaperType(char *name
, int wmm
, int hmm
, int wp
, int hp
)
2523 pageName
= copystring(name
);
2526 wxPrintPaperType::~wxPrintPaperType(void)
2531 wxPrintPaperDatabase::wxPrintPaperDatabase(void):wxList(wxKEY_STRING
)
2533 DeleteContents(TRUE
);
2536 wxPrintPaperDatabase::~wxPrintPaperDatabase(void)
2540 void wxPrintPaperDatabase::CreateDatabase(void)
2542 // Need correct values for page size in pixels.
2543 // Each unit is one 'point' = 1/72 of an inch.
2544 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2545 // in wxPostScriptDC code, so we can start from top left.
2546 // So access this database and translate by appropriate number
2547 // of points for this paper size. OR IS IT OK ALREADY?
2548 // Can't remember where the PostScript origin is by default.
2549 // Heck, someone will know how to make it hunky-dory...
2552 AddPaperType("A4 210 x 297 mm", 210, 297, 595, 842);
2553 AddPaperType("A3 297 x 420 mm", 297, 420, 842, 1191);
2554 AddPaperType("Letter 8 1/2 x 11 in", 216, 279, 612, 791);
2555 AddPaperType("Legal 8 1/2 x 14 in", 216, 356, 612, 1009);
2558 void wxPrintPaperDatabase::ClearDatabase(void)
2563 void wxPrintPaperDatabase::AddPaperType(char *name
, int wmm
, int hmm
, int wp
, int hp
)
2565 Append(name
, new wxPrintPaperType(name
, wmm
, hmm
, wp
, hp
));
2568 wxPrintPaperType
*wxPrintPaperDatabase::FindPaperType(const char *name
)
2570 wxNode
*node
= Find(name
);
2572 return (wxPrintPaperType
*)node
->Data();