1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/dcpsg.cpp
3 // Purpose: Generic wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
21 #if wxUSE_PRINTING_ARCHITECTURE
25 #include "wx/dcmemory.h"
31 #include "wx/generic/dcpsg.h"
32 #include "wx/prntbase.h"
33 #include "wx/generic/prntdlgg.h"
35 #include "wx/filefn.h"
37 #include "wx/stdpaths.h"
59 //-----------------------------------------------------------------------------
60 // start and end of document/page
61 //-----------------------------------------------------------------------------
63 static const char *wxPostScriptHeaderConicTo
= "\
67 /conic_cntrl_y exch def\n\
68 /conic_cntrl_x exch def\n\
72 /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\
73 /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\
74 /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\
75 /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\
76 p1_x p1_y p2_x p2_y to_x to_y curveto\n\
80 static const char *wxPostScriptHeaderEllipse
= "\
81 /ellipsedict 8 dict def\n\
82 ellipsedict /mtrx matrix put\n\
86 /startangle exch def\n\
91 /savematrix mtrx currentmatrix def\n\
94 0 0 1 startangle endangle arc\n\
95 savematrix setmatrix\n\
100 static const char *wxPostScriptHeaderEllipticArc
= "\
101 /ellipticarcdict 8 dict def\n\
102 ellipticarcdict /mtrx matrix put\n\
104 { ellipticarcdict begin\n\
106 /endangle exch def\n\
107 /startangle exch def\n\
112 /savematrix mtrx currentmatrix def\n\
115 do_fill { 0 0 moveto } if\n\
116 0 0 1 startangle endangle arc\n\
117 savematrix setmatrix\n\
118 do_fill { fill }{ stroke } ifelse\n\
122 static const char *wxPostScriptHeaderSpline
= "\
123 /DrawSplineSection {\n\
130 /xa x1 x2 x1 sub 0.666667 mul add def\n\
131 /ya y1 y2 y1 sub 0.666667 mul add def\n\
132 /xb x3 x2 x3 sub 0.666667 mul add def\n\
133 /yb y3 y2 y3 sub 0.666667 mul add def\n\
135 xa ya xb yb x3 y3 curveto\n\
139 static const char *wxPostScriptHeaderColourImage
= "\
140 % define 'colorimage' if it isn't defined\n\
141 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
143 /colorimage where % do we know about 'colorimage'?\n\
144 { pop } % yes: pop off the 'dict' returned\n\
145 { % no: define one\n\
146 /colortogray { % define an RGB->I function\n\
147 /rgbdata exch store % call input 'rgbdata'\n\
148 rgbdata length 3 idiv\n\
149 /npixls exch store\n\
151 0 1 npixls 1 sub {\n\
153 rgbdata rgbindx get 20 mul % Red\n\
154 rgbdata rgbindx 1 add get 32 mul % Green\n\
155 rgbdata rgbindx 2 add get 12 mul % Blue\n\
156 add add 64 idiv % I = .5G + .31R + .18B\n\
158 /rgbindx rgbindx 3 add store\n\
160 grays 0 npixls getinterval\n\
163 % Utility procedure for colorimage operator.\n\
164 % This procedure takes two procedures off the\n\
165 % stack and merges them into a single procedure.\n\
167 /mergeprocs { % def\n\
186 /colorimage { % def\n\
187 pop pop % remove 'false 3' operands\n\
188 {colortogray} mergeprocs\n\
191 } ifelse % end of 'false' case\n\
194 static char wxPostScriptHeaderReencodeISO1
[] =
196 "dup dup findfont dup length dict begin\n"
197 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
198 "/Encoding ISOLatin1Encoding def\n"
199 "currentdict end definefont\n"
201 "/ISOLatin1Encoding [\n"
202 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
203 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
204 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
205 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
206 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
207 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
208 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
209 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
210 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
211 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
212 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
213 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
214 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
215 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
216 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
218 static char wxPostScriptHeaderReencodeISO2
[] =
219 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
220 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
221 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
222 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
223 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
224 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
225 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
226 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
227 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
228 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
229 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
230 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
231 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
232 "/yacute/thorn/ydieresis\n"
235 //-------------------------------------------------------------------------------
237 //-------------------------------------------------------------------------------
239 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
241 float wxPostScriptDC::ms_PSScaleFactor
= 1.0;
243 void wxPostScriptDC::SetResolution(int ppi
)
245 ms_PSScaleFactor
= (float)ppi
/ 72.0;
248 int wxPostScriptDC::GetResolution()
250 return (int)(ms_PSScaleFactor
* 72.0);
253 //-------------------------------------------------------------------------------
255 wxPostScriptDC::wxPostScriptDC ()
257 m_pstream
= (FILE*) NULL
;
267 m_underlinePosition
= 0.0;
268 m_underlineThickness
= 0.0;
270 m_signX
= 1; // default x-axis left to right
271 m_signY
= -1; // default y-axis bottom up -> top down
274 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
276 m_pstream
= (FILE*) NULL
;
286 m_underlinePosition
= 0.0;
287 m_underlineThickness
= 0.0;
289 m_signX
= 1; // default x-axis left to right
290 m_signY
= -1; // default y-axis bottom up -> top down
292 m_printData
= printData
;
297 wxPostScriptDC::~wxPostScriptDC ()
302 m_pstream
= (FILE*) NULL
;
306 bool wxPostScriptDC::Ok() const
311 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
313 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
315 if (m_clipping
) DestroyClippingRegion();
317 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
321 PsPrintf( wxT("gsave\n newpath\n")
322 wxT("%d %d moveto\n")
323 wxT("%d %d lineto\n")
324 wxT("%d %d lineto\n")
325 wxT("%d %d lineto\n")
326 wxT("closepath clip newpath\n"),
327 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
328 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
329 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
330 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
334 void wxPostScriptDC::DestroyClippingRegion()
336 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
341 PsPrint( "grestore\n" );
344 wxDC::DestroyClippingRegion();
347 void wxPostScriptDC::Clear()
349 // This should fail silently to avoid unnecessary
351 // wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
354 bool wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
356 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
360 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
362 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
366 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
368 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
371 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
373 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
375 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
379 PsPrintf( wxT("newpath\n")
380 wxT("%d %d moveto\n")
381 wxT("%d %d lineto\n")
383 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
384 LogicalToDeviceX(x2
), LogicalToDeviceY (y2
) );
386 CalcBoundingBox( x1
, y1
);
387 CalcBoundingBox( x2
, y2
);
390 #define RAD2DEG 57.29577951308
392 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
394 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
396 wxCoord dx
= x1
- xc
;
397 wxCoord dy
= y1
- yc
;
398 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
399 double alpha1
, alpha2
;
401 if (x1
== x2
&& y1
== y2
)
406 else if ( wxIsNullDouble(radius
) )
413 alpha1
= (x1
- xc
== 0) ?
414 (y1
- yc
< 0) ? 90.0 : -90.0 :
415 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
416 alpha2
= (x2
- xc
== 0) ?
417 (y2
- yc
< 0) ? 90.0 : -90.0 :
418 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
420 while (alpha1
<= 0) alpha1
+= 360;
421 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
422 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
423 while (alpha2
> 360) alpha2
-= 360;
425 if (m_brush
.GetStyle() != wxTRANSPARENT
)
429 PsPrintf( wxT("newpath\n")
430 wxT("%d %d %d %d %d %d ellipse\n")
431 wxT("%d %d lineto\n")
434 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
435 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
437 CalcBoundingBox( xc
-radius
, yc
-radius
);
438 CalcBoundingBox( xc
+radius
, yc
+radius
);
441 if (m_pen
.GetStyle() != wxTRANSPARENT
)
445 PsPrintf( wxT("newpath\n")
446 wxT("%d %d %d %d %d %d ellipse\n")
447 wxT("%d %d lineto\n")
450 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
451 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
453 CalcBoundingBox( xc
-radius
, yc
-radius
);
454 CalcBoundingBox( xc
+radius
, yc
+radius
);
458 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
460 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
462 if ( sa
>= 360 || sa
<= -360 )
463 sa
-= int(sa
/360)*360;
464 if ( ea
>= 360 || ea
<=- 360 )
465 ea
-= int(ea
/360)*360;
471 if ( wxIsSameDouble(sa
, ea
) )
473 DrawEllipse(x
,y
,w
,h
);
477 if (m_brush
.GetStyle () != wxTRANSPARENT
)
481 PsPrintf( wxT("newpath\n")
482 wxT("%d %d %d %d %d %d true ellipticarc\n"),
483 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
484 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
485 (wxCoord
)sa
, (wxCoord
)ea
);
487 CalcBoundingBox( x
,y
);
488 CalcBoundingBox( x
+w
, y
+h
);
491 if (m_pen
.GetStyle () != wxTRANSPARENT
)
495 PsPrintf( wxT("newpath\n")
496 wxT("%d %d %d %d %d %d false ellipticarc\n"),
497 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
498 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
499 (wxCoord
)sa
, (wxCoord
)ea
);
501 CalcBoundingBox( x
,y
);
502 CalcBoundingBox( x
+w
, y
+h
);
506 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
508 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
510 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
514 PsPrintf( wxT("newpath\n")
515 wxT("%d %d moveto\n")
516 wxT("%d %d lineto\n")
518 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
519 LogicalToDeviceX(x
+1), LogicalToDeviceY(y
) );
521 CalcBoundingBox( x
, y
);
524 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
526 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
530 if (m_brush
.GetStyle () != wxTRANSPARENT
)
534 PsPrint( "newpath\n" );
536 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
537 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
539 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
541 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
543 for (int i
= 1; i
< n
; i
++)
545 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
546 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
548 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
550 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
553 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
556 if (m_pen
.GetStyle () != wxTRANSPARENT
)
560 PsPrint( "newpath\n" );
562 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
563 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
565 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
567 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
569 for (int i
= 1; i
< n
; i
++)
571 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
572 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
574 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
576 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
579 PsPrint( "closepath\n" );
580 PsPrint( "stroke\n" );
584 void wxPostScriptDC::DoDrawPolyPolygon (int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
586 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
590 if (m_brush
.GetStyle () != wxTRANSPARENT
)
594 PsPrint( "newpath\n" );
597 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
599 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
600 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
602 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
604 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
606 for (int j
= 1; j
< count
[i
]; j
++)
608 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
609 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
611 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
613 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
616 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
619 if (m_pen
.GetStyle () != wxTRANSPARENT
)
623 PsPrint( "newpath\n" );
626 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
628 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
629 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
631 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
633 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
635 for (int j
= 1; j
< count
[i
]; j
++)
637 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
638 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
640 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
642 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
645 PsPrint( "closepath\n" );
646 PsPrint( "stroke\n" );
650 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
652 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
654 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
661 for ( i
=0; i
<n
; i
++ )
663 CalcBoundingBox( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
666 PsPrintf( wxT("newpath\n")
667 wxT("%d %d moveto\n"),
668 LogicalToDeviceX(points
[0].x
+xoffset
),
669 LogicalToDeviceY(points
[0].y
+yoffset
) );
671 for (i
= 1; i
< n
; i
++)
673 PsPrintf( wxT("%d %d lineto\n"),
674 LogicalToDeviceX(points
[i
].x
+xoffset
),
675 LogicalToDeviceY(points
[i
].y
+yoffset
) );
678 PsPrint( "stroke\n" );
681 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
683 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
685 if (m_brush
.GetStyle () != wxTRANSPARENT
)
689 PsPrintf( wxT("newpath\n")
690 wxT("%d %d moveto\n")
691 wxT("%d %d lineto\n")
692 wxT("%d %d lineto\n")
693 wxT("%d %d lineto\n")
696 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
697 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
698 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
699 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
701 CalcBoundingBox( x
, y
);
702 CalcBoundingBox( x
+ width
, y
+ height
);
705 if (m_pen
.GetStyle () != wxTRANSPARENT
)
709 PsPrintf( wxT("newpath\n")
710 wxT("%d %d moveto\n")
711 wxT("%d %d lineto\n")
712 wxT("%d %d lineto\n")
713 wxT("%d %d lineto\n")
716 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
717 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
718 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
719 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
721 CalcBoundingBox( x
, y
);
722 CalcBoundingBox( x
+ width
, y
+ height
);
726 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
728 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
732 // Now, a negative radius is interpreted to mean
733 // 'the proportion of the smallest X or Y dimension'
734 double smallest
= width
< height
? width
: height
;
735 radius
= (-radius
* smallest
);
738 wxCoord rad
= (wxCoord
) radius
;
740 if (m_brush
.GetStyle () != wxTRANSPARENT
)
744 /* Draw rectangle anticlockwise */
745 PsPrintf( wxT("newpath\n")
746 wxT("%d %d %d 90 180 arc\n")
747 wxT("%d %d lineto\n")
748 wxT("%d %d %d 180 270 arc\n")
749 wxT("%d %d lineto\n")
750 wxT("%d %d %d 270 0 arc\n")
751 wxT("%d %d lineto\n")
752 wxT("%d %d %d 0 90 arc\n")
753 wxT("%d %d lineto\n")
756 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
757 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
- rad
),
758 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
759 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
760 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
761 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
762 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
763 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
765 CalcBoundingBox( x
, y
);
766 CalcBoundingBox( x
+ width
, y
+ height
);
769 if (m_pen
.GetStyle () != wxTRANSPARENT
)
773 /* Draw rectangle anticlockwise */
774 PsPrintf( wxT("newpath\n")
775 wxT("%d %d %d 90 180 arc\n")
776 wxT("%d %d lineto\n")
777 wxT("%d %d %d 180 270 arc\n")
778 wxT("%d %d lineto\n")
779 wxT("%d %d %d 270 0 arc\n")
780 wxT("%d %d lineto\n")
781 wxT("%d %d %d 0 90 arc\n")
782 wxT("%d %d lineto\n")
785 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
786 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
- rad
),
787 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
788 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
789 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
790 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
791 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
792 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
794 CalcBoundingBox( x
, y
);
795 CalcBoundingBox( x
+ width
, y
+ height
);
799 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
801 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
803 if (m_brush
.GetStyle () != wxTRANSPARENT
)
807 PsPrintf( wxT("newpath\n")
808 wxT("%d %d %d %d 0 360 ellipse\n")
810 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
811 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
813 CalcBoundingBox( x
- width
, y
- height
);
814 CalcBoundingBox( x
+ width
, y
+ height
);
817 if (m_pen
.GetStyle () != wxTRANSPARENT
)
821 PsPrintf( wxT("newpath\n")
822 wxT("%d %d %d %d 0 360 ellipse\n")
824 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
825 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
827 CalcBoundingBox( x
- width
, y
- height
);
828 CalcBoundingBox( x
+ width
, y
+ height
);
832 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
834 DrawBitmap( icon
, x
, y
, true );
837 /* this has to be char, not wxChar */
838 static char hexArray
[] = "0123456789ABCDEF";
840 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
842 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
844 if (!bitmap
.Ok()) return;
846 wxImage image
= bitmap
.ConvertToImage();
848 if (!image
.Ok()) return;
850 wxCoord w
= image
.GetWidth();
851 wxCoord h
= image
.GetHeight();
853 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
854 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
856 wxCoord xx
= LogicalToDeviceX(x
);
857 wxCoord yy
= LogicalToDeviceY(y
+ bitmap
.GetHeight());
859 PsPrintf( wxT("/origstate save def\n")
860 wxT("20 dict begin\n")
861 wxT("/pix %d string def\n")
862 wxT("/grays %d string def\n")
863 wxT("/npixels 0 def\n")
864 wxT("/rgbindx 0 def\n")
865 wxT("%d %d translate\n")
868 wxT("[%d 0 0 %d 0 %d]\n")
869 wxT("{currentfile pix readhexstring pop}\n")
870 wxT("false 3 colorimage\n"),
871 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
873 unsigned char* data
= image
.GetData();
875 /* buffer = line = width*rgb(3)*hexa(2)+'\n'(1)+null(1) */
876 char* buffer
= new char[ w
*6+2 ];
877 int firstDigit
, secondDigit
;
880 for (int j
= 0; j
< h
; j
++)
882 char* bufferindex
= buffer
;
885 for (int i
= 0; i
< w
*3; i
++)
887 firstDigit
= (int)(*data
/16.0);
888 secondDigit
= (int)(*data
- (firstDigit
*16.0));
889 *(bufferindex
++) = hexArray
[firstDigit
];
890 *(bufferindex
++) = hexArray
[secondDigit
];
894 *(bufferindex
++) = '\n';
900 PsPrint( "origstate restore\n" );
903 void wxPostScriptDC::SetFont( const wxFont
& font
)
905 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
907 if (!font
.Ok()) return;
911 int Style
= m_font
.GetStyle();
912 int Weight
= m_font
.GetWeight();
915 switch (m_font
.GetFamily())
920 if (Style
== wxITALIC
)
922 if (Weight
== wxBOLD
)
923 name
= "/Courier-BoldOblique";
925 name
= "/Courier-Oblique";
929 if (Weight
== wxBOLD
)
930 name
= "/Courier-Bold";
938 if (Style
== wxITALIC
)
940 if (Weight
== wxBOLD
)
941 name
= "/Times-BoldItalic";
943 name
= "/Times-Italic";
947 if (Weight
== wxBOLD
)
948 name
= "/Times-Bold";
950 name
= "/Times-Roman";
956 name
= "/ZapfChancery-MediumItalic";
962 if (Style
== wxITALIC
)
964 if (Weight
== wxBOLD
)
965 name
= "/Helvetica-BoldOblique";
967 name
= "/Helvetica-Oblique";
971 if (Weight
== wxBOLD
)
972 name
= "/Helvetica-Bold";
980 // We may legitimately call SetFont before BeginDoc
985 PsPrint( " reencodeISO def\n" );
987 PsPrint( " findfont\n" );
990 sprintf( buffer
, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
991 // this is a hack - we must scale font size (in pts) according to m_scaleY but
992 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
993 // to 1/1000th of pt and then back.
994 for (int i
= 0; i
< 100; i
++)
995 if (buffer
[i
] == ',') buffer
[i
] = '.';
999 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1001 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1003 if (!pen
.Ok()) return;
1005 int oldStyle
= m_pen
.GetStyle();
1010 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
1011 for (int i
= 0; i
< 100; i
++)
1012 if (buffer
[i
] == ',') buffer
[i
] = '.';
1016 Line style - WRONG: 2nd arg is OFFSET
1018 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1019 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1020 ter is not number of values in the array of the first one, but an offset
1021 into this description of the pattern. I mean a real *offset* not index
1022 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1023 will be first black line *2* units wxCoord, then space 4 units, then the
1024 pattern of *3* units black, 4 units space will be repeated.
1027 static const char *dotted
= "[2 5] 2";
1028 static const char *short_dashed
= "[4 4] 2";
1029 static const char *wxCoord_dashed
= "[4 8] 2";
1030 static const char *dotted_dashed
= "[6 6 2 6] 4";
1034 switch (m_pen
.GetStyle())
1036 case wxDOT
: psdash
= dotted
; break;
1037 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1038 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1039 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1042 default: psdash
= "[] 0"; break;
1045 if ( (oldStyle
!= m_pen
.GetStyle()) )
1048 PsPrint( " setdash\n" );
1052 unsigned char red
= m_pen
.GetColour().Red();
1053 unsigned char blue
= m_pen
.GetColour().Blue();
1054 unsigned char green
= m_pen
.GetColour().Green();
1058 // Anything not white is black
1059 if (! (red
== (unsigned char) 255 &&
1060 blue
== (unsigned char) 255 &&
1061 green
== (unsigned char) 255) )
1063 red
= (unsigned char) 0;
1064 green
= (unsigned char) 0;
1065 blue
= (unsigned char) 0;
1070 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1072 double redPS
= (double)(red
) / 255.0;
1073 double bluePS
= (double)(blue
) / 255.0;
1074 double greenPS
= (double)(green
) / 255.0;
1077 "%.8f %.8f %.8f setrgbcolor\n",
1078 redPS
, greenPS
, bluePS
);
1079 for (int i
= 0; i
< 100; i
++)
1080 if (buffer
[i
] == ',') buffer
[i
] = '.';
1085 m_currentBlue
= blue
;
1086 m_currentGreen
= green
;
1090 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1092 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1094 if (!brush
.Ok()) return;
1099 unsigned char red
= m_brush
.GetColour().Red();
1100 unsigned char blue
= m_brush
.GetColour().Blue();
1101 unsigned char green
= m_brush
.GetColour().Green();
1105 // Anything not white is black
1106 if (! (red
== (unsigned char) 255 &&
1107 blue
== (unsigned char) 255 &&
1108 green
== (unsigned char) 255) )
1110 red
= (unsigned char) 0;
1111 green
= (unsigned char) 0;
1112 blue
= (unsigned char) 0;
1117 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1119 double redPS
= (double)(red
) / 255.0;
1120 double bluePS
= (double)(blue
) / 255.0;
1121 double greenPS
= (double)(green
) / 255.0;
1125 "%.8f %.8f %.8f setrgbcolor\n",
1126 redPS
, greenPS
, bluePS
);
1127 for (int i
= 0; i
< 100; i
++)
1128 if (buffer
[i
] == ',') buffer
[i
] = '.';
1133 m_currentBlue
= blue
;
1134 m_currentGreen
= green
;
1138 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1140 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1142 if (m_textForegroundColour
.Ok())
1144 unsigned char red
= m_textForegroundColour
.Red();
1145 unsigned char blue
= m_textForegroundColour
.Blue();
1146 unsigned char green
= m_textForegroundColour
.Green();
1150 // Anything not white is black
1151 if (! (red
== (unsigned char) 255 &&
1152 blue
== (unsigned char) 255 &&
1153 green
== (unsigned char) 255))
1155 red
= (unsigned char) 0;
1156 green
= (unsigned char) 0;
1157 blue
= (unsigned char) 0;
1161 // maybe setgray here ?
1162 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1164 double redPS
= (double)(red
) / 255.0;
1165 double bluePS
= (double)(blue
) / 255.0;
1166 double greenPS
= (double)(green
) / 255.0;
1170 "%.8f %.8f %.8f setrgbcolor\n",
1171 redPS
, greenPS
, bluePS
);
1172 for (size_t i
= 0; i
< strlen(buffer
); i
++)
1173 if (buffer
[i
] == ',') buffer
[i
] = '.';
1177 m_currentBlue
= blue
;
1178 m_currentGreen
= green
;
1182 wxCoord text_w
, text_h
, text_descent
;
1184 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1186 // VZ: this seems to be unnecessary, so taking it out for now, if it
1187 // doesn't create any problems, remove this comment entirely
1188 //SetFont( m_font );
1191 int size
= m_font
.GetPointSize();
1193 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1194 // commented by V. Slavik and replaced by accurate version
1195 // - note that there is still rounding error in text_descent!
1196 wxCoord by
= y
+ size
- text_descent
; // baseline
1198 PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1201 const wxWX2MBbuf textbuf
= text
.mb_str();
1202 size_t len
= strlen(textbuf
);
1204 for (i
= 0; i
< len
; i
++)
1206 int c
= (unsigned char) textbuf
[i
];
1207 if (c
== ')' || c
== '(' || c
== '\\')
1209 /* Cope with special characters */
1213 else if ( c
>= 128 )
1215 /* Cope with character codes > 127 */
1216 PsPrintf( wxT("\\%o"), c
);
1224 PsPrint( ") show\n" );
1226 if (m_font
.GetUnderlined())
1228 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1238 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1239 m_underlineThickness
,
1240 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1241 for (i
= 0; i
< 100; i
++)
1242 if (buffer
[i
] == ',') buffer
[i
] = '.';
1246 CalcBoundingBox( x
, y
);
1247 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1250 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1252 if ( wxIsNullDouble(angle
) )
1254 DoDrawText(text
, x
, y
);
1258 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1262 if (m_textForegroundColour
.Ok())
1264 unsigned char red
= m_textForegroundColour
.Red();
1265 unsigned char blue
= m_textForegroundColour
.Blue();
1266 unsigned char green
= m_textForegroundColour
.Green();
1270 // Anything not white is black
1271 if (! (red
== (unsigned char) 255 &&
1272 blue
== (unsigned char) 255 &&
1273 green
== (unsigned char) 255))
1275 red
= (unsigned char) 0;
1276 green
= (unsigned char) 0;
1277 blue
= (unsigned char) 0;
1281 // maybe setgray here ?
1282 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1284 double redPS
= (double)(red
) / 255.0;
1285 double bluePS
= (double)(blue
) / 255.0;
1286 double greenPS
= (double)(green
) / 255.0;
1290 "%.8f %.8f %.8f setrgbcolor\n",
1291 redPS
, greenPS
, bluePS
);
1292 for (int i
= 0; i
< 100; i
++)
1293 if (buffer
[i
] == ',') buffer
[i
] = '.';
1297 m_currentBlue
= blue
;
1298 m_currentGreen
= green
;
1302 int size
= m_font
.GetPointSize();
1304 PsPrintf( wxT("%d %d moveto\n"),
1305 LogicalToDeviceX(x
), LogicalToDeviceY(y
));
1308 sprintf(buffer
, "%.8f rotate\n", angle
);
1310 for (i
= 0; i
< 100; i
++)
1312 if (buffer
[i
] == ',') buffer
[i
] = '.';
1317 const wxWX2MBbuf textbuf
= text
.mb_str();
1318 size_t len
= strlen(textbuf
);
1319 for (i
= 0; i
< len
; i
++)
1321 int c
= (unsigned char) textbuf
[i
];
1322 if (c
== ')' || c
== '(' || c
== '\\')
1324 /* Cope with special characters */
1328 else if ( c
>= 128 )
1330 /* Cope with character codes > 127 */
1331 PsPrintf( wxT("\\%o"), c
);
1339 PsPrint( ") show\n" );
1341 sprintf( buffer
, "%.8f rotate\n", -angle
);
1342 for (i
= 0; i
< 100; i
++)
1344 if (buffer
[i
] == ',') buffer
[i
] = '.';
1348 if (m_font
.GetUnderlined())
1350 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1352 GetTextExtent(text
, &w
, &h
);
1361 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1362 m_underlineThickness
,
1363 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1364 for (i
= 0; i
< 100; i
++)
1366 if (buffer
[i
] == ',') buffer
[i
] = '.';
1371 CalcBoundingBox( x
, y
);
1372 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1375 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1377 m_backgroundBrush
= brush
;
1380 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1382 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1386 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1388 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1392 // a and b are not used
1394 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1397 wxList::compatibility_iterator node
= points
->GetFirst();
1398 p
= (wxPoint
*)node
->GetData();
1402 node
= node
->GetNext();
1403 p
= (wxPoint
*)node
->GetData();
1410 (double)(x1
+ c
) / 2;
1415 (double)(y1
+ d
) / 2;
1417 PsPrintf( wxT("newpath\n")
1418 wxT("%d %d moveto\n")
1419 wxT("%d %d lineto\n"),
1420 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1421 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1423 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1424 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1426 node
= node
->GetNext();
1429 q
= (wxPoint
*)node
->GetData();
1437 x3
= (double)(x2
+ c
) / 2;
1438 y3
= (double)(y2
+ d
) / 2;
1440 PsPrintf( wxT("%d %d %d %d %d %d DrawSplineSection\n"),
1441 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1442 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1443 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1445 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1446 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1448 node
= node
->GetNext();
1452 At this point, (x2,y2) and (c,d) are the position of the
1453 next-to-last and last point respectively, in the point list
1456 PsPrintf( wxT("%d %d lineto\n")
1458 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1460 #endif // wxUSE_SPLINES
1462 wxCoord
wxPostScriptDC::GetCharWidth() const
1464 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1465 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1469 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1471 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1473 m_signX
= (xLeftRight
? 1 : -1);
1474 m_signY
= (yBottomUp
? 1 : -1);
1476 ComputeScaleAndOrigin();
1479 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1481 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1487 wxDC::SetDeviceOrigin( x
, h
-y
);
1490 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1492 wxPaperSize id
= m_printData
.GetPaperId();
1494 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1496 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1502 w
= paper
->GetSizeDeviceUnits().x
;
1503 h
= paper
->GetSizeDeviceUnits().y
;
1506 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1513 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1514 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1517 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1519 wxPaperSize id
= m_printData
.GetPaperId();
1521 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1523 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1529 w
= paper
->GetWidth() / 10;
1530 h
= paper
->GetHeight() / 10;
1533 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1540 if (width
) *width
= w
;
1541 if (height
) *height
= h
;
1544 // Resolution in pixels per logical inch
1545 wxSize
wxPostScriptDC::GetPPI(void) const
1547 return wxSize((int)(72 * ms_PSScaleFactor
),
1548 (int)(72 * ms_PSScaleFactor
));
1552 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1554 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
1556 if (m_printData
.GetPrintMode() != wxPRINT_MODE_STREAM
)
1558 if (m_printData
.GetFilename() == wxEmptyString
)
1560 wxString filename
= wxGetTempFileName( wxT("ps") );
1561 m_printData
.SetFilename(filename
);
1564 m_pstream
= wxFopen( m_printData
.GetFilename(), wxT("w+") );
1568 wxLogError( _("Cannot open file for PostScript printing!"));
1577 PsPrint( "%!PS-Adobe-2.0\n" );
1578 PsPrintf( wxT("%%%%Title: %s\n"), m_title
.c_str() );
1579 PsPrint( "%%Creator: wxWidgets PostScript renderer\n" );
1580 PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() );
1581 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1582 PsPrint( "%%Orientation: Landscape\n" );
1584 PsPrint( "%%Orientation: Portrait\n" );
1586 // PsPrintf( wxT("%%%%Pages: %d\n"), (wxPageNumber - 1) );
1588 const wxChar
*paper
;
1589 switch (m_printData
.GetPaperId())
1591 case wxPAPER_LETTER
: paper
= wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches
1592 case wxPAPER_LEGAL
: paper
= wxT("Legal"); break; // Legal, 8 1/2 by 14 inches
1593 case wxPAPER_A4
: paper
= wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters
1594 case wxPAPER_TABLOID
: paper
= wxT("Tabloid"); break; // Tabloid, 11 by 17 inches
1595 case wxPAPER_LEDGER
: paper
= wxT("Ledger"); break; // Ledger, 17 by 11 inches
1596 case wxPAPER_STATEMENT
: paper
= wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches
1597 case wxPAPER_EXECUTIVE
: paper
= wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches
1598 case wxPAPER_A3
: paper
= wxT("A3"); break; // A3 sheet, 297 by 420 millimeters
1599 case wxPAPER_A5
: paper
= wxT("A5"); break; // A5 sheet, 148 by 210 millimeters
1600 case wxPAPER_B4
: paper
= wxT("B4"); break; // B4 sheet, 250 by 354 millimeters
1601 case wxPAPER_B5
: paper
= wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper
1602 case wxPAPER_FOLIO
: paper
= wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper
1603 case wxPAPER_QUARTO
: paper
= wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper
1604 case wxPAPER_10X14
: paper
= wxT("10x14"); break; // 10-by-14-inch sheet
1605 default: paper
= wxT("A4");
1607 PsPrintf( wxT("%%%%DocumentPaperSizes: %s\n"), paper
);
1608 PsPrint( "%%EndComments\n\n" );
1610 PsPrint( "%%BeginProlog\n" );
1611 PsPrint( wxPostScriptHeaderConicTo
);
1612 PsPrint( wxPostScriptHeaderEllipse
);
1613 PsPrint( wxPostScriptHeaderEllipticArc
);
1614 PsPrint( wxPostScriptHeaderColourImage
);
1615 PsPrint( wxPostScriptHeaderReencodeISO1
);
1616 PsPrint( wxPostScriptHeaderReencodeISO2
);
1617 if (wxPostScriptHeaderSpline
)
1618 PsPrint( wxPostScriptHeaderSpline
);
1619 PsPrint( "%%EndProlog\n" );
1621 SetBrush( *wxBLACK_BRUSH
);
1622 SetPen( *wxBLACK_PEN
);
1623 SetBackground( *wxWHITE_BRUSH
);
1624 SetTextForeground( *wxBLACK
);
1626 // set origin according to paper size
1627 SetDeviceOrigin( 0,0 );
1634 void wxPostScriptDC::EndDoc ()
1636 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1641 PsPrint( "grestore\n" );
1645 fclose( m_pstream
);
1646 m_pstream
= (FILE *) NULL
;
1650 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1651 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1652 double wx_printer_scale_x
, wx_printer_scale_y
;
1654 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1655 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1657 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1658 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1660 // Compute the bounding box. Note that it is in the default user
1661 // coordinate system, thus we have to convert the values.
1662 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1663 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1664 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1665 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1667 // LOG2DEV may have changed the minimum to maximum vice versa
1668 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1669 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1671 // account for used scaling (boundingbox is before scaling in ps-file)
1672 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1673 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1675 wxCoord llx
, lly
, urx
, ury
;
1676 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1677 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1678 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1679 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1680 // (end of bounding box computation)
1683 // If we're landscape, our sense of "x" and "y" is reversed.
1684 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1687 tmp
= llx
; llx
= lly
; lly
= tmp
;
1688 tmp
= urx
; urx
= ury
; ury
= tmp
;
1690 // We need either the two lines that follow, or we need to subtract
1691 // min_x from real_translate_y, which is commented out below.
1692 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1693 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1696 // The Adobe specifications call for integers; we round as to make
1697 // the bounding larger.
1698 PsPrintf( wxT("%%%%BoundingBox: %d %d %d %d\n"),
1699 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1700 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1702 // To check the correctness of the bounding box, postscript commands
1703 // to draw a box corresponding to the bounding box are generated below.
1704 // But since we typically don't want to print such a box, the postscript
1705 // commands are generated within comments. These lines appear before any
1706 // adjustment of scale, rotation, or translation, and hence are in the
1707 // default user coordinates.
1708 PsPrint( "% newpath\n" );
1709 PsPrintf( wxT("%% %d %d moveto\n"), llx
, lly
);
1710 PsPrintf( wxT("%% %d %d lineto\n"), urx
, lly
);
1711 PsPrintf( wxT("%% %d %d lineto\n"), urx
, ury
);
1712 PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx
, ury
);
1716 wxPostScriptPrintNativeData
*data
=
1717 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1719 if (m_ok
&& (m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
1722 command
+= data
->GetPrinterCommand();
1723 command
+= wxT(" ");
1724 command
+= data
->GetPrinterOptions();
1725 command
+= wxT(" ");
1726 command
+= m_printData
.GetFilename();
1728 wxExecute( command
, true );
1729 wxRemoveFile( m_printData
.GetFilename() );
1734 void wxPostScriptDC::StartPage()
1736 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1738 PsPrintf( wxT("%%%%Page: %d\n"), wxPageNumber
++ );
1740 // What is this one supposed to do? RR.
1741 // *m_pstream << "matrix currentmatrix\n";
1743 // Added by Chris Breeze
1745 // Each page starts with an "initgraphics" which resets the
1746 // transformation and so we need to reset the origin
1747 // (and rotate the page for landscape printing)
1750 wxCoord translate_x
, translate_y
;
1751 double scale_x
, scale_y
;
1753 wxPostScriptPrintNativeData
*data
=
1754 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1756 translate_x
= (wxCoord
)data
->GetPrinterTranslateX();
1757 translate_y
= (wxCoord
)data
->GetPrinterTranslateY();
1759 scale_x
= data
->GetPrinterScaleX();
1760 scale_y
= data
->GetPrinterScaleY();
1762 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1765 GetSize( (int*) NULL
, &h
);
1767 PsPrint( "90 rotate\n" );
1768 // I copied this one from a PostScript tutorial, but to no avail. RR.
1769 // PsPrint( "90 rotate llx neg ury nef translate\n" );
1773 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1774 scale_y
/ ms_PSScaleFactor
);
1775 for (int i
= 0; i
< 100; i
++)
1776 if (buffer
[i
] == ',') buffer
[i
] = '.';
1779 PsPrintf( wxT("%d %d translate\n"), translate_x
, translate_y
);
1782 void wxPostScriptDC::EndPage ()
1784 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1786 PsPrint( "showpage\n" );
1789 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1790 wxCoord fwidth
, wxCoord fheight
,
1792 wxCoord xsrc
, wxCoord ysrc
,
1793 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
1795 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
1797 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1799 /* blit into a bitmap */
1800 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1802 memDC
.SelectObject(bitmap
);
1803 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1804 memDC
.SelectObject(wxNullBitmap
);
1806 /* draw bitmap. scaling and positioning is done there */
1807 DrawBitmap( bitmap
, xdest
, ydest
);
1812 wxCoord
wxPostScriptDC::GetCharHeight() const
1815 return m_font
.GetPointSize();
1820 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1821 wxCoord
*x
, wxCoord
*y
,
1822 wxCoord
*descent
, wxCoord
*externalLeading
,
1823 wxFont
*theFont
) const
1825 wxFont
*fontToUse
= theFont
;
1827 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1829 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1835 if (descent
) (*descent
) = 0;
1836 if (externalLeading
) (*externalLeading
) = 0;
1842 const wxWX2MBbuf strbuf
= string
.mb_str();
1844 #if !wxUSE_AFM_FOR_POSTSCRIPT
1845 /* Provide a VERY rough estimate (avoid using it).
1846 * Produces accurate results for mono-spaced font
1847 * such as Courier (aka wxMODERN) */
1852 height
= fontToUse
->GetPointSize();
1855 *x
= strlen (strbuf
) * height
* 72 / 120;
1857 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
1858 if (descent
) *descent
= 0;
1859 if (externalLeading
) *externalLeading
= 0;
1862 /* method for calculating string widths in postscript:
1863 / read in the AFM (adobe font metrics) file for the
1864 / actual font, parse it and extract the character widths
1865 / and also the descender. this may be improved, but for now
1866 / it works well. the AFM file is only read in if the
1867 / font is changed. this may be chached in the future.
1868 / calls to GetTextExtent with the font unchanged are rather
1871 / for each font and style used there is an AFM file necessary.
1872 / currently i have only files for the roman font family.
1873 / I try to get files for the other ones!
1875 / CAVE: the size of the string is currently always calculated
1876 / in 'points' (1/72 of an inch). this should later on be
1877 / changed to depend on the mapping mode.
1878 / CAVE: the path to the AFM files must be set before calling this
1879 / function. this is usually done by a call like the following:
1880 / wxSetAFMPath("d:\\wxw161\\afm\\");
1884 / wxPostScriptDC dc(NULL, true);
1886 / wxSetAFMPath("d:\\wxw161\\afm\\");
1887 / dc.StartDoc("Test");
1890 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1891 / dc.GetTextExtent("Hallo",&w,&h);
1896 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1898 / updated: 14.05.95 */
1900 /* these static vars are for storing the state between calls */
1901 static int lastFamily
= INT_MIN
;
1902 static int lastSize
= INT_MIN
;
1903 static int lastStyle
= INT_MIN
;
1904 static int lastWeight
= INT_MIN
;
1905 static int lastDescender
= INT_MIN
;
1906 static int lastWidths
[256]; /* widths of the characters */
1908 double UnderlinePosition
= 0.0;
1909 double UnderlineThickness
= 0.0;
1911 // Get actual parameters
1912 int Family
= fontToUse
->GetFamily();
1913 int Size
= fontToUse
->GetPointSize();
1914 int Style
= fontToUse
->GetStyle();
1915 int Weight
= fontToUse
->GetWeight();
1917 // If we have another font, read the font-metrics
1918 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1920 // Store actual values
1921 lastFamily
= Family
;
1924 lastWeight
= Weight
;
1933 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBoO.afm");
1934 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBo.afm");
1935 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("CourO.afm");
1936 else name
= wxT("Cour.afm");
1941 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBoO.afm");
1942 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBo.afm");
1943 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("TimesO.afm");
1944 else name
= wxT("TimesRo.afm");
1949 name
= wxT("Zapf.afm");
1955 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBoO.afm");
1956 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBo.afm");
1957 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("HelvO.afm");
1958 else name
= wxT("Helv.afm");
1963 FILE *afmFile
= NULL
;
1965 // Get the directory of the AFM files
1968 // VZ: I don't know if the cast always works under Unix but it clearly
1969 // never does under Windows where the pointer is
1970 // wxWindowsPrintNativeData and so calling GetFontMetricPath() on
1973 wxPostScriptPrintNativeData
*data
=
1974 wxDynamicCast(m_printData
.GetNativeData(), wxPostScriptPrintNativeData
);
1976 if (data
&& !data
->GetFontMetricPath().empty())
1978 afmName
= data
->GetFontMetricPath();
1979 afmName
<< wxFILE_SEP_PATH
<< name
;
1983 if ( !afmName
.empty() )
1984 afmFile
= wxFopen(afmName
, wxT("r"));
1988 #if defined(__UNIX__) && !defined(__VMS__)
1989 afmName
= wxGetDataDir();
1991 afmName
= wxStandardPaths::Get().GetDataDir();
1992 #endif // __UNIX__/!__UNIX__
1994 afmName
<< wxFILE_SEP_PATH
1995 #if defined(__LINUX__) || defined(__FREEBSD__)
1996 << wxT("gs_afm") << wxFILE_SEP_PATH
1998 << wxT("afm") << wxFILE_SEP_PATH
2001 afmFile
= wxFopen(afmName
,wxT("r"));
2004 /* 2. open and process the file
2005 / a short explanation of the AFM format:
2006 / we have for each character a line, which gives its size
2009 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2011 / that means, we have a character with ascii code 63, and width
2012 / (444/1000 * fontSize) points.
2013 / the other data is ignored for now!
2015 / when the font has changed, we read in the right AFM file and store the
2016 / character widths in an array, which is processed below (see point 3.). */
2019 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2020 wxLogDebug( wxT(" using approximate values"));
2021 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2022 lastDescender
= -150; /* dito. */
2026 /* init the widths array */
2027 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2028 /* some variables for holding parts of a line */
2029 char cString
[10], semiString
[10], WXString
[10];
2030 char descString
[20];
2031 char upString
[30], utString
[30];
2035 /* read in the file and parse it */
2036 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2038 /* A.) check for descender definition */
2039 if (strncmp(line
,"Descender",9)==0)
2041 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2042 (strcmp(descString
,"Descender")!=0))
2044 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2047 /* JC 1.) check for UnderlinePosition */
2048 else if(strncmp(line
,"UnderlinePosition",17)==0)
2050 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2051 (strcmp(upString
,"UnderlinePosition")!=0))
2053 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2056 /* JC 2.) check for UnderlineThickness */
2057 else if(strncmp(line
,"UnderlineThickness",18)==0)
2059 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2060 (strcmp(utString
,"UnderlineThickness")!=0))
2062 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2065 /* JC 3.) check for EncodingScheme */
2066 else if(strncmp(line
,"EncodingScheme",14)==0)
2068 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2069 (strcmp(utString
,"EncodingScheme")!=0))
2071 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2073 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2075 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2076 afmName
.c_str(),line
, encString
);
2079 /* B.) check for char-width */
2080 else if(strncmp(line
,"C ",2)==0)
2082 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2084 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2086 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2088 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2090 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2091 if (ascii
>=0 && ascii
<256)
2093 lastWidths
[ascii
] = cWidth
; /* store width */
2097 /* MATTHEW: this happens a lot; don't print an error */
2098 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2101 /* C.) ignore other entries. */
2105 /* hack to compute correct values for german 'Umlaute'
2106 / the correct way would be to map the character names
2107 / like 'adieresis' to corresp. positions of ISOEnc and read
2108 / these values from AFM files, too. Maybe later ... */
2110 // NB: casts to int are needed to suppress gcc 3.3 warnings
2111 lastWidths
[196] = lastWidths
[(int)'A']; // Ä
2112 lastWidths
[228] = lastWidths
[(int)'a']; // ä
2113 lastWidths
[214] = lastWidths
[(int)'O']; // Ö
2114 lastWidths
[246] = lastWidths
[(int)'o']; // ö
2115 lastWidths
[220] = lastWidths
[(int)'U']; // Ü
2116 lastWidths
[252] = lastWidths
[(int)'u']; // ü
2117 lastWidths
[223] = lastWidths
[(int)251]; // ß
2119 /* JC: calculate UnderlineThickness/UnderlinePosition */
2121 // VS: dirty, but is there any better solution?
2123 pt
= (double*) &m_underlinePosition
;
2124 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2125 pt
= (double*) &m_underlineThickness
;
2126 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2131 /* 3. now the font metrics are read in, calc size this
2132 / is done by adding the widths of the characters in the
2133 / string. they are given in 1/1000 of the size! */
2136 wxCoord height
=Size
; /* by default */
2138 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2140 if(lastWidths
[*p
]== INT_MIN
)
2142 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2143 sum
+= lastWidths
[(unsigned char)' ']; /* assume space */
2147 sum
+= lastWidths
[*p
];
2151 double widthSum
= sum
;
2153 widthSum
/= 1000.0F
;
2155 /* add descender to height (it is usually a negative value) */
2156 //if (lastDescender != INT_MIN)
2158 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2160 // - commented by V. Slavik - height already contains descender in it
2161 // (judging from few experiments)
2163 /* return size values */
2165 *x
= (wxCoord
)widthSum
;
2169 /* return other parameters */
2172 if(lastDescender
!=INT_MIN
)
2174 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2182 /* currently no idea how to calculate this! */
2183 if (externalLeading
) *externalLeading
= 0;
2188 // print postscript datas via required method (file, stream)
2189 void wxPostScriptDC::PsPrintf( const wxChar
* fmt
, ... )
2192 va_start(argptr
, fmt
);
2194 PsPrint( wxString::FormatV( fmt
, argptr
).c_str() );
2197 void wxPostScriptDC::PsPrint( const char* psdata
)
2199 wxPostScriptPrintNativeData
*data
=
2200 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2202 switch (m_printData
.GetPrintMode())
2205 // append to output stream
2206 case wxPRINT_MODE_STREAM
:
2208 wxOutputStream
* outputstream
= data
->GetOutputStream();
2209 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2210 outputstream
->Write( psdata
, strlen( psdata
) );
2213 #endif // wxUSE_STREAMS
2215 // save data into file
2217 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2218 fwrite( psdata
, 1, strlen( psdata
), m_pstream
);
2222 void wxPostScriptDC::PsPrint( int ch
)
2224 wxPostScriptPrintNativeData
*data
=
2225 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2227 switch (m_printData
.GetPrintMode())
2230 // append to output stream
2231 case wxPRINT_MODE_STREAM
:
2233 wxOutputStream
* outputstream
= data
->GetOutputStream();
2234 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2235 outputstream
->PutC( (char)ch
);
2238 #endif // wxUSE_STREAMS
2240 // save data into file
2242 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2243 fputc( ch
, m_pstream
);
2251 // wxUSE_PRINTING_ARCHITECTURE