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
27 #include "wx/dcmemory.h"
33 #include "wx/generic/dcpsg.h"
34 #include "wx/prntbase.h"
35 #include "wx/generic/prntdlgg.h"
37 #include "wx/filefn.h"
39 #include "wx/stdpaths.h"
61 //-----------------------------------------------------------------------------
62 // start and end of document/page
63 //-----------------------------------------------------------------------------
65 static const char *wxPostScriptHeaderConicTo
= "\
69 /conic_cntrl_y exch def\n\
70 /conic_cntrl_x exch def\n\
74 /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\
75 /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\
76 /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\
77 /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\
78 p1_x p1_y p2_x p2_y to_x to_y curveto\n\
82 static const char *wxPostScriptHeaderEllipse
= "\
83 /ellipsedict 8 dict def\n\
84 ellipsedict /mtrx matrix put\n\
88 /startangle exch def\n\
93 /savematrix mtrx currentmatrix def\n\
96 0 0 1 startangle endangle arc\n\
97 savematrix setmatrix\n\
102 static const char *wxPostScriptHeaderEllipticArc
= "\
103 /ellipticarcdict 8 dict def\n\
104 ellipticarcdict /mtrx matrix put\n\
106 { ellipticarcdict begin\n\
108 /endangle exch def\n\
109 /startangle exch def\n\
114 /savematrix mtrx currentmatrix def\n\
117 do_fill { 0 0 moveto } if\n\
118 0 0 1 startangle endangle arc\n\
119 savematrix setmatrix\n\
120 do_fill { fill }{ stroke } ifelse\n\
124 static const char *wxPostScriptHeaderSpline
= "\
125 /DrawSplineSection {\n\
132 /xa x1 x2 x1 sub 0.666667 mul add def\n\
133 /ya y1 y2 y1 sub 0.666667 mul add def\n\
134 /xb x3 x2 x3 sub 0.666667 mul add def\n\
135 /yb y3 y2 y3 sub 0.666667 mul add def\n\
137 xa ya xb yb x3 y3 curveto\n\
141 static const char *wxPostScriptHeaderColourImage
= "\
142 % define 'colorimage' if it isn't defined\n\
143 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
145 /colorimage where % do we know about 'colorimage'?\n\
146 { pop } % yes: pop off the 'dict' returned\n\
147 { % no: define one\n\
148 /colortogray { % define an RGB->I function\n\
149 /rgbdata exch store % call input 'rgbdata'\n\
150 rgbdata length 3 idiv\n\
151 /npixls exch store\n\
153 0 1 npixls 1 sub {\n\
155 rgbdata rgbindx get 20 mul % Red\n\
156 rgbdata rgbindx 1 add get 32 mul % Green\n\
157 rgbdata rgbindx 2 add get 12 mul % Blue\n\
158 add add 64 idiv % I = .5G + .31R + .18B\n\
160 /rgbindx rgbindx 3 add store\n\
162 grays 0 npixls getinterval\n\
165 % Utility procedure for colorimage operator.\n\
166 % This procedure takes two procedures off the\n\
167 % stack and merges them into a single procedure.\n\
169 /mergeprocs { % def\n\
188 /colorimage { % def\n\
189 pop pop % remove 'false 3' operands\n\
190 {colortogray} mergeprocs\n\
193 } ifelse % end of 'false' case\n\
196 static char wxPostScriptHeaderReencodeISO1
[] =
198 "dup dup findfont dup length dict begin\n"
199 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
200 "/Encoding ISOLatin1Encoding def\n"
201 "currentdict end definefont\n"
203 "/ISOLatin1Encoding [\n"
204 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
205 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
206 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
207 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
208 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
209 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
210 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
211 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
212 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
213 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
214 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
215 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
216 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
217 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
218 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
220 static char wxPostScriptHeaderReencodeISO2
[] =
221 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
222 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
223 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
224 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
225 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
226 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
227 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
228 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
229 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
230 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
231 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
232 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
233 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
234 "/yacute/thorn/ydieresis\n"
237 //-------------------------------------------------------------------------------
239 //-------------------------------------------------------------------------------
241 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
243 float wxPostScriptDC::ms_PSScaleFactor
= 1.0;
245 void wxPostScriptDC::SetResolution(int ppi
)
247 ms_PSScaleFactor
= (float)ppi
/ 72.0;
250 int wxPostScriptDC::GetResolution()
252 return (int)(ms_PSScaleFactor
* 72.0);
255 //-------------------------------------------------------------------------------
257 wxPostScriptDC::wxPostScriptDC ()
259 m_pstream
= (FILE*) NULL
;
269 m_underlinePosition
= 0.0;
270 m_underlineThickness
= 0.0;
272 m_signX
= 1; // default x-axis left to right
273 m_signY
= -1; // default y-axis bottom up -> top down
276 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
278 m_pstream
= (FILE*) NULL
;
288 m_underlinePosition
= 0.0;
289 m_underlineThickness
= 0.0;
291 m_signX
= 1; // default x-axis left to right
292 m_signY
= -1; // default y-axis bottom up -> top down
294 m_printData
= printData
;
299 wxPostScriptDC::~wxPostScriptDC ()
304 m_pstream
= (FILE*) NULL
;
308 bool wxPostScriptDC::Ok() const
313 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
315 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
317 if (m_clipping
) DestroyClippingRegion();
319 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
323 PsPrintf( wxT("gsave\n newpath\n")
324 wxT("%d %d moveto\n")
325 wxT("%d %d lineto\n")
326 wxT("%d %d lineto\n")
327 wxT("%d %d lineto\n")
328 wxT("closepath clip newpath\n"),
329 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
330 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
331 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
332 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
336 void wxPostScriptDC::DestroyClippingRegion()
338 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
343 PsPrint( "grestore\n" );
346 wxDC::DestroyClippingRegion();
349 void wxPostScriptDC::Clear()
351 // This should fail silently to avoid unnecessary
353 // wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
356 bool wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
358 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
362 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
364 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
368 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
370 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
373 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
375 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
377 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
381 PsPrintf( wxT("newpath\n")
382 wxT("%d %d moveto\n")
383 wxT("%d %d lineto\n")
385 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
386 LogicalToDeviceX(x2
), LogicalToDeviceY (y2
) );
388 CalcBoundingBox( x1
, y1
);
389 CalcBoundingBox( x2
, y2
);
392 #define RAD2DEG 57.29577951308
394 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
396 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
398 wxCoord dx
= x1
- xc
;
399 wxCoord dy
= y1
- yc
;
400 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
401 double alpha1
, alpha2
;
403 if (x1
== x2
&& y1
== y2
)
408 else if ( wxIsNullDouble(radius
) )
415 alpha1
= (x1
- xc
== 0) ?
416 (y1
- yc
< 0) ? 90.0 : -90.0 :
417 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
418 alpha2
= (x2
- xc
== 0) ?
419 (y2
- yc
< 0) ? 90.0 : -90.0 :
420 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
422 while (alpha1
<= 0) alpha1
+= 360;
423 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
424 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
425 while (alpha2
> 360) alpha2
-= 360;
427 if (m_brush
.GetStyle() != wxTRANSPARENT
)
431 PsPrintf( wxT("newpath\n")
432 wxT("%d %d %d %d %d %d ellipse\n")
433 wxT("%d %d lineto\n")
436 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
437 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
439 CalcBoundingBox( xc
-radius
, yc
-radius
);
440 CalcBoundingBox( xc
+radius
, yc
+radius
);
443 if (m_pen
.GetStyle() != wxTRANSPARENT
)
447 PsPrintf( wxT("newpath\n")
448 wxT("%d %d %d %d %d %d ellipse\n")
449 wxT("%d %d lineto\n")
452 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
453 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
455 CalcBoundingBox( xc
-radius
, yc
-radius
);
456 CalcBoundingBox( xc
+radius
, yc
+radius
);
460 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
462 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
464 if ( sa
>= 360 || sa
<= -360 )
465 sa
-= int(sa
/360)*360;
466 if ( ea
>= 360 || ea
<=- 360 )
467 ea
-= int(ea
/360)*360;
473 if ( wxIsSameDouble(sa
, ea
) )
475 DrawEllipse(x
,y
,w
,h
);
479 if (m_brush
.GetStyle () != wxTRANSPARENT
)
483 PsPrintf( wxT("newpath\n")
484 wxT("%d %d %d %d %d %d true ellipticarc\n"),
485 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
486 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
487 (wxCoord
)sa
, (wxCoord
)ea
);
489 CalcBoundingBox( x
,y
);
490 CalcBoundingBox( x
+w
, y
+h
);
493 if (m_pen
.GetStyle () != wxTRANSPARENT
)
497 PsPrintf( wxT("newpath\n")
498 wxT("%d %d %d %d %d %d false ellipticarc\n"),
499 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
500 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
501 (wxCoord
)sa
, (wxCoord
)ea
);
503 CalcBoundingBox( x
,y
);
504 CalcBoundingBox( x
+w
, y
+h
);
508 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
510 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
512 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
516 PsPrintf( wxT("newpath\n")
517 wxT("%d %d moveto\n")
518 wxT("%d %d lineto\n")
520 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
521 LogicalToDeviceX(x
+1), LogicalToDeviceY(y
) );
523 CalcBoundingBox( x
, y
);
526 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
528 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
532 if (m_brush
.GetStyle () != wxTRANSPARENT
)
536 PsPrint( "newpath\n" );
538 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
539 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
541 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
543 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
545 for (int i
= 1; i
< n
; i
++)
547 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
548 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
550 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
552 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
555 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
558 if (m_pen
.GetStyle () != wxTRANSPARENT
)
562 PsPrint( "newpath\n" );
564 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
565 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
567 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
569 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
571 for (int i
= 1; i
< n
; i
++)
573 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
574 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
576 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
578 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
581 PsPrint( "closepath\n" );
582 PsPrint( "stroke\n" );
586 void wxPostScriptDC::DoDrawPolyPolygon (int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
588 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
592 if (m_brush
.GetStyle () != wxTRANSPARENT
)
596 PsPrint( "newpath\n" );
599 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
601 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
602 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
604 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
606 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
608 for (int j
= 1; j
< count
[i
]; j
++)
610 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
611 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
613 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
615 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
618 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
621 if (m_pen
.GetStyle () != wxTRANSPARENT
)
625 PsPrint( "newpath\n" );
628 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
630 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
631 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
633 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
635 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
637 for (int j
= 1; j
< count
[i
]; j
++)
639 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
640 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
642 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
644 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
647 PsPrint( "closepath\n" );
648 PsPrint( "stroke\n" );
652 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
654 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
656 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
663 for ( i
=0; i
<n
; i
++ )
665 CalcBoundingBox( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
668 PsPrintf( wxT("newpath\n")
669 wxT("%d %d moveto\n"),
670 LogicalToDeviceX(points
[0].x
+xoffset
),
671 LogicalToDeviceY(points
[0].y
+yoffset
) );
673 for (i
= 1; i
< n
; i
++)
675 PsPrintf( wxT("%d %d lineto\n"),
676 LogicalToDeviceX(points
[i
].x
+xoffset
),
677 LogicalToDeviceY(points
[i
].y
+yoffset
) );
680 PsPrint( "stroke\n" );
683 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
685 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
687 if (m_brush
.GetStyle () != wxTRANSPARENT
)
691 PsPrintf( wxT("newpath\n")
692 wxT("%d %d moveto\n")
693 wxT("%d %d lineto\n")
694 wxT("%d %d lineto\n")
695 wxT("%d %d lineto\n")
698 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
699 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
700 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
701 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
703 CalcBoundingBox( x
, y
);
704 CalcBoundingBox( x
+ width
, y
+ height
);
707 if (m_pen
.GetStyle () != wxTRANSPARENT
)
711 PsPrintf( wxT("newpath\n")
712 wxT("%d %d moveto\n")
713 wxT("%d %d lineto\n")
714 wxT("%d %d lineto\n")
715 wxT("%d %d lineto\n")
718 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
719 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
720 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
721 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
723 CalcBoundingBox( x
, y
);
724 CalcBoundingBox( x
+ width
, y
+ height
);
728 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
730 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
734 // Now, a negative radius is interpreted to mean
735 // 'the proportion of the smallest X or Y dimension'
736 double smallest
= width
< height
? width
: height
;
737 radius
= (-radius
* smallest
);
740 wxCoord rad
= (wxCoord
) radius
;
742 if (m_brush
.GetStyle () != wxTRANSPARENT
)
746 /* Draw rectangle anticlockwise */
747 PsPrintf( wxT("newpath\n")
748 wxT("%d %d %d 90 180 arc\n")
749 wxT("%d %d lineto\n")
750 wxT("%d %d %d 180 270 arc\n")
751 wxT("%d %d lineto\n")
752 wxT("%d %d %d 270 0 arc\n")
753 wxT("%d %d lineto\n")
754 wxT("%d %d %d 0 90 arc\n")
755 wxT("%d %d lineto\n")
758 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
759 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
- rad
),
760 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
761 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
762 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
763 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
764 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
765 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
767 CalcBoundingBox( x
, y
);
768 CalcBoundingBox( x
+ width
, y
+ height
);
771 if (m_pen
.GetStyle () != wxTRANSPARENT
)
775 /* Draw rectangle anticlockwise */
776 PsPrintf( wxT("newpath\n")
777 wxT("%d %d %d 90 180 arc\n")
778 wxT("%d %d lineto\n")
779 wxT("%d %d %d 180 270 arc\n")
780 wxT("%d %d lineto\n")
781 wxT("%d %d %d 270 0 arc\n")
782 wxT("%d %d lineto\n")
783 wxT("%d %d %d 0 90 arc\n")
784 wxT("%d %d lineto\n")
787 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
788 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
- rad
),
789 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
790 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
791 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
792 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
793 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
794 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
796 CalcBoundingBox( x
, y
);
797 CalcBoundingBox( x
+ width
, y
+ height
);
801 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
803 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
805 if (m_brush
.GetStyle () != wxTRANSPARENT
)
809 PsPrintf( wxT("newpath\n")
810 wxT("%d %d %d %d 0 360 ellipse\n")
812 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
813 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
815 CalcBoundingBox( x
- width
, y
- height
);
816 CalcBoundingBox( x
+ width
, y
+ height
);
819 if (m_pen
.GetStyle () != wxTRANSPARENT
)
823 PsPrintf( wxT("newpath\n")
824 wxT("%d %d %d %d 0 360 ellipse\n")
826 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
827 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
829 CalcBoundingBox( x
- width
, y
- height
);
830 CalcBoundingBox( x
+ width
, y
+ height
);
834 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
836 DrawBitmap( icon
, x
, y
, true );
839 /* this has to be char, not wxChar */
840 static char hexArray
[] = "0123456789ABCDEF";
842 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
844 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
846 if (!bitmap
.Ok()) return;
848 wxImage image
= bitmap
.ConvertToImage();
850 if (!image
.Ok()) return;
852 wxCoord w
= image
.GetWidth();
853 wxCoord h
= image
.GetHeight();
855 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
856 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
858 wxCoord xx
= LogicalToDeviceX(x
);
859 wxCoord yy
= LogicalToDeviceY(y
+ bitmap
.GetHeight());
861 PsPrintf( wxT("/origstate save def\n")
862 wxT("20 dict begin\n")
863 wxT("/pix %d string def\n")
864 wxT("/grays %d string def\n")
865 wxT("/npixels 0 def\n")
866 wxT("/rgbindx 0 def\n")
867 wxT("%d %d translate\n")
870 wxT("[%d 0 0 %d 0 %d]\n")
871 wxT("{currentfile pix readhexstring pop}\n")
872 wxT("false 3 colorimage\n"),
873 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
875 unsigned char* data
= image
.GetData();
877 /* buffer = line = width*rgb(3)*hexa(2)+'\n'(1)+null(1) */
878 char* buffer
= new char[ w
*6+2 ];
879 int firstDigit
, secondDigit
;
882 for (int j
= 0; j
< h
; j
++)
884 char* bufferindex
= buffer
;
887 for (int i
= 0; i
< w
*3; i
++)
889 firstDigit
= (int)(*data
/16.0);
890 secondDigit
= (int)(*data
- (firstDigit
*16.0));
891 *(bufferindex
++) = hexArray
[firstDigit
];
892 *(bufferindex
++) = hexArray
[secondDigit
];
896 *(bufferindex
++) = '\n';
902 PsPrint( "origstate restore\n" );
905 void wxPostScriptDC::SetFont( const wxFont
& font
)
907 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
909 if (!font
.Ok()) return;
913 int Style
= m_font
.GetStyle();
914 int Weight
= m_font
.GetWeight();
917 switch (m_font
.GetFamily())
922 if (Style
== wxITALIC
)
924 if (Weight
== wxBOLD
)
925 name
= "/Courier-BoldOblique";
927 name
= "/Courier-Oblique";
931 if (Weight
== wxBOLD
)
932 name
= "/Courier-Bold";
940 if (Style
== wxITALIC
)
942 if (Weight
== wxBOLD
)
943 name
= "/Times-BoldItalic";
945 name
= "/Times-Italic";
949 if (Weight
== wxBOLD
)
950 name
= "/Times-Bold";
952 name
= "/Times-Roman";
958 name
= "/ZapfChancery-MediumItalic";
964 if (Style
== wxITALIC
)
966 if (Weight
== wxBOLD
)
967 name
= "/Helvetica-BoldOblique";
969 name
= "/Helvetica-Oblique";
973 if (Weight
== wxBOLD
)
974 name
= "/Helvetica-Bold";
982 // We may legitimately call SetFont before BeginDoc
987 PsPrint( " reencodeISO def\n" );
989 PsPrint( " findfont\n" );
992 sprintf( buffer
, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
993 // this is a hack - we must scale font size (in pts) according to m_scaleY but
994 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
995 // to 1/1000th of pt and then back.
996 for (int i
= 0; i
< 100; i
++)
997 if (buffer
[i
] == ',') buffer
[i
] = '.';
1001 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1003 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1005 if (!pen
.Ok()) return;
1007 int oldStyle
= m_pen
.GetStyle();
1012 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
1013 for (int i
= 0; i
< 100; i
++)
1014 if (buffer
[i
] == ',') buffer
[i
] = '.';
1018 Line style - WRONG: 2nd arg is OFFSET
1020 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1021 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1022 ter is not number of values in the array of the first one, but an offset
1023 into this description of the pattern. I mean a real *offset* not index
1024 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1025 will be first black line *2* units wxCoord, then space 4 units, then the
1026 pattern of *3* units black, 4 units space will be repeated.
1029 static const char *dotted
= "[2 5] 2";
1030 static const char *short_dashed
= "[4 4] 2";
1031 static const char *wxCoord_dashed
= "[4 8] 2";
1032 static const char *dotted_dashed
= "[6 6 2 6] 4";
1036 switch (m_pen
.GetStyle())
1038 case wxDOT
: psdash
= dotted
; break;
1039 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1040 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1041 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1044 default: psdash
= "[] 0"; break;
1047 if ( (oldStyle
!= m_pen
.GetStyle()) )
1050 PsPrint( " setdash\n" );
1054 unsigned char red
= m_pen
.GetColour().Red();
1055 unsigned char blue
= m_pen
.GetColour().Blue();
1056 unsigned char green
= m_pen
.GetColour().Green();
1060 // Anything not white is black
1061 if (! (red
== (unsigned char) 255 &&
1062 blue
== (unsigned char) 255 &&
1063 green
== (unsigned char) 255) )
1065 red
= (unsigned char) 0;
1066 green
= (unsigned char) 0;
1067 blue
= (unsigned char) 0;
1072 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1074 double redPS
= (double)(red
) / 255.0;
1075 double bluePS
= (double)(blue
) / 255.0;
1076 double greenPS
= (double)(green
) / 255.0;
1079 "%.8f %.8f %.8f setrgbcolor\n",
1080 redPS
, greenPS
, bluePS
);
1081 for (int i
= 0; i
< 100; i
++)
1082 if (buffer
[i
] == ',') buffer
[i
] = '.';
1087 m_currentBlue
= blue
;
1088 m_currentGreen
= green
;
1092 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1094 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1096 if (!brush
.Ok()) return;
1101 unsigned char red
= m_brush
.GetColour().Red();
1102 unsigned char blue
= m_brush
.GetColour().Blue();
1103 unsigned char green
= m_brush
.GetColour().Green();
1107 // Anything not white is black
1108 if (! (red
== (unsigned char) 255 &&
1109 blue
== (unsigned char) 255 &&
1110 green
== (unsigned char) 255) )
1112 red
= (unsigned char) 0;
1113 green
= (unsigned char) 0;
1114 blue
= (unsigned char) 0;
1119 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1121 double redPS
= (double)(red
) / 255.0;
1122 double bluePS
= (double)(blue
) / 255.0;
1123 double greenPS
= (double)(green
) / 255.0;
1127 "%.8f %.8f %.8f setrgbcolor\n",
1128 redPS
, greenPS
, bluePS
);
1129 for (int i
= 0; i
< 100; i
++)
1130 if (buffer
[i
] == ',') buffer
[i
] = '.';
1135 m_currentBlue
= blue
;
1136 m_currentGreen
= green
;
1140 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1142 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1144 if (m_textForegroundColour
.Ok())
1146 unsigned char red
= m_textForegroundColour
.Red();
1147 unsigned char blue
= m_textForegroundColour
.Blue();
1148 unsigned char green
= m_textForegroundColour
.Green();
1152 // Anything not white is black
1153 if (! (red
== (unsigned char) 255 &&
1154 blue
== (unsigned char) 255 &&
1155 green
== (unsigned char) 255))
1157 red
= (unsigned char) 0;
1158 green
= (unsigned char) 0;
1159 blue
= (unsigned char) 0;
1163 // maybe setgray here ?
1164 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1166 double redPS
= (double)(red
) / 255.0;
1167 double bluePS
= (double)(blue
) / 255.0;
1168 double greenPS
= (double)(green
) / 255.0;
1172 "%.8f %.8f %.8f setrgbcolor\n",
1173 redPS
, greenPS
, bluePS
);
1174 for (size_t i
= 0; i
< strlen(buffer
); i
++)
1175 if (buffer
[i
] == ',') buffer
[i
] = '.';
1179 m_currentBlue
= blue
;
1180 m_currentGreen
= green
;
1184 wxCoord text_w
, text_h
, text_descent
;
1186 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1188 // VZ: this seems to be unnecessary, so taking it out for now, if it
1189 // doesn't create any problems, remove this comment entirely
1190 //SetFont( m_font );
1193 int size
= m_font
.GetPointSize();
1195 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1196 // commented by V. Slavik and replaced by accurate version
1197 // - note that there is still rounding error in text_descent!
1198 wxCoord by
= y
+ size
- text_descent
; // baseline
1200 PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1203 const wxWX2MBbuf textbuf
= text
.mb_str();
1204 size_t len
= strlen(textbuf
);
1206 for (i
= 0; i
< len
; i
++)
1208 int c
= (unsigned char) textbuf
[i
];
1209 if (c
== ')' || c
== '(' || c
== '\\')
1211 /* Cope with special characters */
1215 else if ( c
>= 128 )
1217 /* Cope with character codes > 127 */
1218 PsPrintf( wxT("\\%o"), c
);
1226 PsPrint( ") show\n" );
1228 if (m_font
.GetUnderlined())
1230 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1240 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1241 m_underlineThickness
,
1242 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1243 for (i
= 0; i
< 100; i
++)
1244 if (buffer
[i
] == ',') buffer
[i
] = '.';
1248 CalcBoundingBox( x
, y
);
1249 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1252 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1254 if ( wxIsNullDouble(angle
) )
1256 DoDrawText(text
, x
, y
);
1260 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1264 if (m_textForegroundColour
.Ok())
1266 unsigned char red
= m_textForegroundColour
.Red();
1267 unsigned char blue
= m_textForegroundColour
.Blue();
1268 unsigned char green
= m_textForegroundColour
.Green();
1272 // Anything not white is black
1273 if (! (red
== (unsigned char) 255 &&
1274 blue
== (unsigned char) 255 &&
1275 green
== (unsigned char) 255))
1277 red
= (unsigned char) 0;
1278 green
= (unsigned char) 0;
1279 blue
= (unsigned char) 0;
1283 // maybe setgray here ?
1284 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1286 double redPS
= (double)(red
) / 255.0;
1287 double bluePS
= (double)(blue
) / 255.0;
1288 double greenPS
= (double)(green
) / 255.0;
1292 "%.8f %.8f %.8f setrgbcolor\n",
1293 redPS
, greenPS
, bluePS
);
1294 for (int i
= 0; i
< 100; i
++)
1295 if (buffer
[i
] == ',') buffer
[i
] = '.';
1299 m_currentBlue
= blue
;
1300 m_currentGreen
= green
;
1304 int size
= m_font
.GetPointSize();
1306 PsPrintf( wxT("%d %d moveto\n"),
1307 LogicalToDeviceX(x
), LogicalToDeviceY(y
));
1310 sprintf(buffer
, "%.8f rotate\n", angle
);
1312 for (i
= 0; i
< 100; i
++)
1314 if (buffer
[i
] == ',') buffer
[i
] = '.';
1319 const wxWX2MBbuf textbuf
= text
.mb_str();
1320 size_t len
= strlen(textbuf
);
1321 for (i
= 0; i
< len
; i
++)
1323 int c
= (unsigned char) textbuf
[i
];
1324 if (c
== ')' || c
== '(' || c
== '\\')
1326 /* Cope with special characters */
1330 else if ( c
>= 128 )
1332 /* Cope with character codes > 127 */
1333 PsPrintf( wxT("\\%o"), c
);
1341 PsPrint( ") show\n" );
1343 sprintf( buffer
, "%.8f rotate\n", -angle
);
1344 for (i
= 0; i
< 100; i
++)
1346 if (buffer
[i
] == ',') buffer
[i
] = '.';
1350 if (m_font
.GetUnderlined())
1352 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1354 GetTextExtent(text
, &w
, &h
);
1363 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1364 m_underlineThickness
,
1365 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1366 for (i
= 0; i
< 100; i
++)
1368 if (buffer
[i
] == ',') buffer
[i
] = '.';
1373 CalcBoundingBox( x
, y
);
1374 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1377 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1379 m_backgroundBrush
= brush
;
1382 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1384 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1388 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1390 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1394 // a and b are not used
1396 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1399 wxList::compatibility_iterator node
= points
->GetFirst();
1400 p
= (wxPoint
*)node
->GetData();
1404 node
= node
->GetNext();
1405 p
= (wxPoint
*)node
->GetData();
1412 (double)(x1
+ c
) / 2;
1417 (double)(y1
+ d
) / 2;
1419 PsPrintf( wxT("newpath\n")
1420 wxT("%d %d moveto\n")
1421 wxT("%d %d lineto\n"),
1422 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1423 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1425 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1426 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1428 node
= node
->GetNext();
1431 q
= (wxPoint
*)node
->GetData();
1439 x3
= (double)(x2
+ c
) / 2;
1440 y3
= (double)(y2
+ d
) / 2;
1442 PsPrintf( wxT("%d %d %d %d %d %d DrawSplineSection\n"),
1443 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1444 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1445 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1447 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1448 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1450 node
= node
->GetNext();
1454 At this point, (x2,y2) and (c,d) are the position of the
1455 next-to-last and last point respectively, in the point list
1458 PsPrintf( wxT("%d %d lineto\n")
1460 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1462 #endif // wxUSE_SPLINES
1464 wxCoord
wxPostScriptDC::GetCharWidth() const
1466 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1467 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1471 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1473 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1475 m_signX
= (xLeftRight
? 1 : -1);
1476 m_signY
= (yBottomUp
? 1 : -1);
1478 ComputeScaleAndOrigin();
1481 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1483 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1489 wxDC::SetDeviceOrigin( x
, h
-y
);
1492 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1494 wxPaperSize id
= m_printData
.GetPaperId();
1496 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1498 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1504 w
= paper
->GetSizeDeviceUnits().x
;
1505 h
= paper
->GetSizeDeviceUnits().y
;
1508 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1515 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1516 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1519 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1521 wxPaperSize id
= m_printData
.GetPaperId();
1523 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1525 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1531 w
= paper
->GetWidth() / 10;
1532 h
= paper
->GetHeight() / 10;
1535 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1542 if (width
) *width
= w
;
1543 if (height
) *height
= h
;
1546 // Resolution in pixels per logical inch
1547 wxSize
wxPostScriptDC::GetPPI(void) const
1549 return wxSize((int)(72 * ms_PSScaleFactor
),
1550 (int)(72 * ms_PSScaleFactor
));
1554 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1556 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
1558 if (m_printData
.GetPrintMode() != wxPRINT_MODE_STREAM
)
1560 if (m_printData
.GetFilename() == wxEmptyString
)
1562 wxString filename
= wxGetTempFileName( wxT("ps") );
1563 m_printData
.SetFilename(filename
);
1566 m_pstream
= wxFopen( m_printData
.GetFilename(), wxT("w+") );
1570 wxLogError( _("Cannot open file for PostScript printing!"));
1579 PsPrint( "%!PS-Adobe-2.0\n" );
1580 PsPrintf( wxT("%%%%Title: %s\n"), m_title
.c_str() );
1581 PsPrint( "%%Creator: wxWidgets PostScript renderer\n" );
1582 PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() );
1583 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1584 PsPrint( "%%Orientation: Landscape\n" );
1586 PsPrint( "%%Orientation: Portrait\n" );
1588 // PsPrintf( wxT("%%%%Pages: %d\n"), (wxPageNumber - 1) );
1590 const wxChar
*paper
;
1591 switch (m_printData
.GetPaperId())
1593 case wxPAPER_LETTER
: paper
= wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches
1594 case wxPAPER_LEGAL
: paper
= wxT("Legal"); break; // Legal, 8 1/2 by 14 inches
1595 case wxPAPER_A4
: paper
= wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters
1596 case wxPAPER_TABLOID
: paper
= wxT("Tabloid"); break; // Tabloid, 11 by 17 inches
1597 case wxPAPER_LEDGER
: paper
= wxT("Ledger"); break; // Ledger, 17 by 11 inches
1598 case wxPAPER_STATEMENT
: paper
= wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches
1599 case wxPAPER_EXECUTIVE
: paper
= wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches
1600 case wxPAPER_A3
: paper
= wxT("A3"); break; // A3 sheet, 297 by 420 millimeters
1601 case wxPAPER_A5
: paper
= wxT("A5"); break; // A5 sheet, 148 by 210 millimeters
1602 case wxPAPER_B4
: paper
= wxT("B4"); break; // B4 sheet, 250 by 354 millimeters
1603 case wxPAPER_B5
: paper
= wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper
1604 case wxPAPER_FOLIO
: paper
= wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper
1605 case wxPAPER_QUARTO
: paper
= wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper
1606 case wxPAPER_10X14
: paper
= wxT("10x14"); break; // 10-by-14-inch sheet
1607 default: paper
= wxT("A4");
1609 PsPrintf( wxT("%%%%DocumentPaperSizes: %s\n"), paper
);
1610 PsPrint( "%%EndComments\n\n" );
1612 PsPrint( "%%BeginProlog\n" );
1613 PsPrint( wxPostScriptHeaderConicTo
);
1614 PsPrint( wxPostScriptHeaderEllipse
);
1615 PsPrint( wxPostScriptHeaderEllipticArc
);
1616 PsPrint( wxPostScriptHeaderColourImage
);
1617 PsPrint( wxPostScriptHeaderReencodeISO1
);
1618 PsPrint( wxPostScriptHeaderReencodeISO2
);
1619 if (wxPostScriptHeaderSpline
)
1620 PsPrint( wxPostScriptHeaderSpline
);
1621 PsPrint( "%%EndProlog\n" );
1623 SetBrush( *wxBLACK_BRUSH
);
1624 SetPen( *wxBLACK_PEN
);
1625 SetBackground( *wxWHITE_BRUSH
);
1626 SetTextForeground( *wxBLACK
);
1628 // set origin according to paper size
1629 SetDeviceOrigin( 0,0 );
1636 void wxPostScriptDC::EndDoc ()
1638 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1643 PsPrint( "grestore\n" );
1647 fclose( m_pstream
);
1648 m_pstream
= (FILE *) NULL
;
1652 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1653 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1654 double wx_printer_scale_x
, wx_printer_scale_y
;
1656 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1657 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1659 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1660 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1662 // Compute the bounding box. Note that it is in the default user
1663 // coordinate system, thus we have to convert the values.
1664 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1665 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1666 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1667 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1669 // LOG2DEV may have changed the minimum to maximum vice versa
1670 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1671 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1673 // account for used scaling (boundingbox is before scaling in ps-file)
1674 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1675 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1677 wxCoord llx
, lly
, urx
, ury
;
1678 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1679 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1680 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1681 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1682 // (end of bounding box computation)
1685 // If we're landscape, our sense of "x" and "y" is reversed.
1686 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1689 tmp
= llx
; llx
= lly
; lly
= tmp
;
1690 tmp
= urx
; urx
= ury
; ury
= tmp
;
1692 // We need either the two lines that follow, or we need to subtract
1693 // min_x from real_translate_y, which is commented out below.
1694 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1695 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1698 // The Adobe specifications call for integers; we round as to make
1699 // the bounding larger.
1700 PsPrintf( wxT("%%%%BoundingBox: %d %d %d %d\n"),
1701 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1702 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1704 // To check the correctness of the bounding box, postscript commands
1705 // to draw a box corresponding to the bounding box are generated below.
1706 // But since we typically don't want to print such a box, the postscript
1707 // commands are generated within comments. These lines appear before any
1708 // adjustment of scale, rotation, or translation, and hence are in the
1709 // default user coordinates.
1710 PsPrint( "% newpath\n" );
1711 PsPrintf( wxT("%% %d %d moveto\n"), llx
, lly
);
1712 PsPrintf( wxT("%% %d %d lineto\n"), urx
, lly
);
1713 PsPrintf( wxT("%% %d %d lineto\n"), urx
, ury
);
1714 PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx
, ury
);
1718 wxPostScriptPrintNativeData
*data
=
1719 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1721 if (m_ok
&& (m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
1724 command
+= data
->GetPrinterCommand();
1725 command
+= wxT(" ");
1726 command
+= data
->GetPrinterOptions();
1727 command
+= wxT(" ");
1728 command
+= m_printData
.GetFilename();
1730 wxExecute( command
, true );
1731 wxRemoveFile( m_printData
.GetFilename() );
1736 void wxPostScriptDC::StartPage()
1738 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1740 PsPrintf( wxT("%%%%Page: %d\n"), wxPageNumber
++ );
1742 // What is this one supposed to do? RR.
1743 // *m_pstream << "matrix currentmatrix\n";
1745 // Added by Chris Breeze
1747 // Each page starts with an "initgraphics" which resets the
1748 // transformation and so we need to reset the origin
1749 // (and rotate the page for landscape printing)
1752 wxCoord translate_x
, translate_y
;
1753 double scale_x
, scale_y
;
1755 wxPostScriptPrintNativeData
*data
=
1756 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1758 translate_x
= (wxCoord
)data
->GetPrinterTranslateX();
1759 translate_y
= (wxCoord
)data
->GetPrinterTranslateY();
1761 scale_x
= data
->GetPrinterScaleX();
1762 scale_y
= data
->GetPrinterScaleY();
1764 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1767 GetSize( (int*) NULL
, &h
);
1769 PsPrint( "90 rotate\n" );
1770 // I copied this one from a PostScript tutorial, but to no avail. RR.
1771 // PsPrint( "90 rotate llx neg ury nef translate\n" );
1775 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1776 scale_y
/ ms_PSScaleFactor
);
1777 for (int i
= 0; i
< 100; i
++)
1778 if (buffer
[i
] == ',') buffer
[i
] = '.';
1781 PsPrintf( wxT("%d %d translate\n"), translate_x
, translate_y
);
1784 void wxPostScriptDC::EndPage ()
1786 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1788 PsPrint( "showpage\n" );
1791 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1792 wxCoord fwidth
, wxCoord fheight
,
1794 wxCoord xsrc
, wxCoord ysrc
,
1795 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
1797 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
1799 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1801 /* blit into a bitmap */
1802 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1804 memDC
.SelectObject(bitmap
);
1805 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1806 memDC
.SelectObject(wxNullBitmap
);
1808 /* draw bitmap. scaling and positioning is done there */
1809 DrawBitmap( bitmap
, xdest
, ydest
);
1814 wxCoord
wxPostScriptDC::GetCharHeight() const
1817 return m_font
.GetPointSize();
1822 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1823 wxCoord
*x
, wxCoord
*y
,
1824 wxCoord
*descent
, wxCoord
*externalLeading
,
1825 wxFont
*theFont
) const
1827 wxFont
*fontToUse
= theFont
;
1829 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1831 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1837 if (descent
) (*descent
) = 0;
1838 if (externalLeading
) (*externalLeading
) = 0;
1844 const wxWX2MBbuf strbuf
= string
.mb_str();
1846 #if !wxUSE_AFM_FOR_POSTSCRIPT
1847 /* Provide a VERY rough estimate (avoid using it).
1848 * Produces accurate results for mono-spaced font
1849 * such as Courier (aka wxMODERN) */
1854 height
= fontToUse
->GetPointSize();
1857 *x
= strlen (strbuf
) * height
* 72 / 120;
1859 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
1860 if (descent
) *descent
= 0;
1861 if (externalLeading
) *externalLeading
= 0;
1864 /* method for calculating string widths in postscript:
1865 / read in the AFM (adobe font metrics) file for the
1866 / actual font, parse it and extract the character widths
1867 / and also the descender. this may be improved, but for now
1868 / it works well. the AFM file is only read in if the
1869 / font is changed. this may be chached in the future.
1870 / calls to GetTextExtent with the font unchanged are rather
1873 / for each font and style used there is an AFM file necessary.
1874 / currently i have only files for the roman font family.
1875 / I try to get files for the other ones!
1877 / CAVE: the size of the string is currently always calculated
1878 / in 'points' (1/72 of an inch). this should later on be
1879 / changed to depend on the mapping mode.
1880 / CAVE: the path to the AFM files must be set before calling this
1881 / function. this is usually done by a call like the following:
1882 / wxSetAFMPath("d:\\wxw161\\afm\\");
1886 / wxPostScriptDC dc(NULL, true);
1888 / wxSetAFMPath("d:\\wxw161\\afm\\");
1889 / dc.StartDoc("Test");
1892 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1893 / dc.GetTextExtent("Hallo",&w,&h);
1898 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1900 / updated: 14.05.95 */
1902 /* these static vars are for storing the state between calls */
1903 static int lastFamily
= INT_MIN
;
1904 static int lastSize
= INT_MIN
;
1905 static int lastStyle
= INT_MIN
;
1906 static int lastWeight
= INT_MIN
;
1907 static int lastDescender
= INT_MIN
;
1908 static int lastWidths
[256]; /* widths of the characters */
1910 double UnderlinePosition
= 0.0;
1911 double UnderlineThickness
= 0.0;
1913 // Get actual parameters
1914 int Family
= fontToUse
->GetFamily();
1915 int Size
= fontToUse
->GetPointSize();
1916 int Style
= fontToUse
->GetStyle();
1917 int Weight
= fontToUse
->GetWeight();
1919 // If we have another font, read the font-metrics
1920 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1922 // Store actual values
1923 lastFamily
= Family
;
1926 lastWeight
= Weight
;
1935 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBoO.afm");
1936 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBo.afm");
1937 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("CourO.afm");
1938 else name
= wxT("Cour.afm");
1943 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBoO.afm");
1944 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBo.afm");
1945 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("TimesO.afm");
1946 else name
= wxT("TimesRo.afm");
1951 name
= wxT("Zapf.afm");
1957 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBoO.afm");
1958 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBo.afm");
1959 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("HelvO.afm");
1960 else name
= wxT("Helv.afm");
1965 FILE *afmFile
= NULL
;
1967 // Get the directory of the AFM files
1970 // VZ: I don't know if the cast always works under Unix but it clearly
1971 // never does under Windows where the pointer is
1972 // wxWindowsPrintNativeData and so calling GetFontMetricPath() on
1975 wxPostScriptPrintNativeData
*data
=
1976 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1978 if (!data
->GetFontMetricPath().empty())
1980 afmName
= data
->GetFontMetricPath();
1981 afmName
<< wxFILE_SEP_PATH
<< name
;
1985 if ( !afmName
.empty() )
1986 afmFile
= wxFopen(afmName
, wxT("r"));
1990 #if defined(__UNIX__) && !defined(__VMS__)
1991 afmName
= wxGetDataDir();
1993 afmName
= wxStandardPaths::Get().GetDataDir();
1994 #endif // __UNIX__/!__UNIX__
1996 afmName
<< wxFILE_SEP_PATH
1997 #if defined(__LINUX__) || defined(__FREEBSD__)
1998 << wxT("gs_afm") << wxFILE_SEP_PATH
2000 << wxT("afm") << wxFILE_SEP_PATH
2003 afmFile
= wxFopen(afmName
,wxT("r"));
2006 /* 2. open and process the file
2007 / a short explanation of the AFM format:
2008 / we have for each character a line, which gives its size
2011 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2013 / that means, we have a character with ascii code 63, and width
2014 / (444/1000 * fontSize) points.
2015 / the other data is ignored for now!
2017 / when the font has changed, we read in the right AFM file and store the
2018 / character widths in an array, which is processed below (see point 3.). */
2021 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2022 wxLogDebug( wxT(" using approximate values"));
2023 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2024 lastDescender
= -150; /* dito. */
2028 /* init the widths array */
2029 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2030 /* some variables for holding parts of a line */
2031 char cString
[10], semiString
[10], WXString
[10];
2032 char descString
[20];
2033 char upString
[30], utString
[30];
2037 /* read in the file and parse it */
2038 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2040 /* A.) check for descender definition */
2041 if (strncmp(line
,"Descender",9)==0)
2043 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2044 (strcmp(descString
,"Descender")!=0))
2046 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2049 /* JC 1.) check for UnderlinePosition */
2050 else if(strncmp(line
,"UnderlinePosition",17)==0)
2052 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2053 (strcmp(upString
,"UnderlinePosition")!=0))
2055 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2058 /* JC 2.) check for UnderlineThickness */
2059 else if(strncmp(line
,"UnderlineThickness",18)==0)
2061 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2062 (strcmp(utString
,"UnderlineThickness")!=0))
2064 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2067 /* JC 3.) check for EncodingScheme */
2068 else if(strncmp(line
,"EncodingScheme",14)==0)
2070 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2071 (strcmp(utString
,"EncodingScheme")!=0))
2073 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2075 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2077 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2078 afmName
.c_str(),line
, encString
);
2081 /* B.) check for char-width */
2082 else if(strncmp(line
,"C ",2)==0)
2084 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2086 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2088 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2090 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2092 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2093 if (ascii
>=0 && ascii
<256)
2095 lastWidths
[ascii
] = cWidth
; /* store width */
2099 /* MATTHEW: this happens a lot; don't print an error */
2100 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2103 /* C.) ignore other entries. */
2107 /* hack to compute correct values for german 'Umlaute'
2108 / the correct way would be to map the character names
2109 / like 'adieresis' to corresp. positions of ISOEnc and read
2110 / these values from AFM files, too. Maybe later ... */
2112 // NB: casts to int are needed to suppress gcc 3.3 warnings
2113 lastWidths
[196] = lastWidths
[(int)'A']; // Ä
2114 lastWidths
[228] = lastWidths
[(int)'a']; // ä
2115 lastWidths
[214] = lastWidths
[(int)'O']; // Ö
2116 lastWidths
[246] = lastWidths
[(int)'o']; // ö
2117 lastWidths
[220] = lastWidths
[(int)'U']; // Ü
2118 lastWidths
[252] = lastWidths
[(int)'u']; // ü
2119 lastWidths
[223] = lastWidths
[(int)251]; // ß
2121 /* JC: calculate UnderlineThickness/UnderlinePosition */
2123 // VS: dirty, but is there any better solution?
2125 pt
= (double*) &m_underlinePosition
;
2126 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2127 pt
= (double*) &m_underlineThickness
;
2128 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2133 /* 3. now the font metrics are read in, calc size this
2134 / is done by adding the widths of the characters in the
2135 / string. they are given in 1/1000 of the size! */
2138 wxCoord height
=Size
; /* by default */
2140 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2142 if(lastWidths
[*p
]== INT_MIN
)
2144 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2145 sum
+= lastWidths
[(unsigned char)' ']; /* assume space */
2149 sum
+= lastWidths
[*p
];
2153 double widthSum
= sum
;
2155 widthSum
/= 1000.0F
;
2157 /* add descender to height (it is usually a negative value) */
2158 //if (lastDescender != INT_MIN)
2160 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2162 // - commented by V. Slavik - height already contains descender in it
2163 // (judging from few experiments)
2165 /* return size values */
2167 *x
= (wxCoord
)widthSum
;
2171 /* return other parameters */
2174 if(lastDescender
!=INT_MIN
)
2176 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2184 /* currently no idea how to calculate this! */
2185 if (externalLeading
) *externalLeading
= 0;
2190 // print postscript datas via required method (file, stream)
2191 void wxPostScriptDC::PsPrintf( const wxChar
* fmt
, ... )
2194 va_start(argptr
, fmt
);
2196 PsPrint( wxString::FormatV( fmt
, argptr
).c_str() );
2199 void wxPostScriptDC::PsPrint( const char* psdata
)
2201 wxPostScriptPrintNativeData
*data
=
2202 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2204 switch (m_printData
.GetPrintMode())
2207 // append to output stream
2208 case wxPRINT_MODE_STREAM
:
2210 wxOutputStream
* outputstream
= data
->GetOutputStream();
2211 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2212 outputstream
->Write( psdata
, strlen( psdata
) );
2215 #endif // wxUSE_STREAMS
2217 // save data into file
2219 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2220 fwrite( psdata
, 1, strlen( psdata
), m_pstream
);
2224 void wxPostScriptDC::PsPrint( int ch
)
2226 wxPostScriptPrintNativeData
*data
=
2227 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2229 switch (m_printData
.GetPrintMode())
2232 // append to output stream
2233 case wxPRINT_MODE_STREAM
:
2235 wxOutputStream
* outputstream
= data
->GetOutputStream();
2236 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2237 outputstream
->PutC( (char)ch
);
2240 #endif // wxUSE_STREAMS
2242 // save data into file
2244 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2245 fputc( ch
, m_pstream
);
2253 // wxUSE_PRINTING_ARCHITECTURE