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"
18 #if wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT
20 #include "wx/generic/dcpsg.h"
28 #include "wx/dcmemory.h"
31 #include "wx/prntbase.h"
32 #include "wx/generic/prntdlgg.h"
34 #include "wx/filefn.h"
36 #include "wx/stdpaths.h"
58 //-----------------------------------------------------------------------------
59 // start and end of document/page
60 //-----------------------------------------------------------------------------
62 static const char *wxPostScriptHeaderConicTo
= "\
66 /conic_cntrl_y exch def\n\
67 /conic_cntrl_x exch def\n\
71 /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\
72 /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\
73 /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\
74 /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\
75 p1_x p1_y p2_x p2_y to_x to_y curveto\n\
79 static const char *wxPostScriptHeaderEllipse
= "\
80 /ellipsedict 8 dict def\n\
81 ellipsedict /mtrx matrix put\n\
85 /startangle exch def\n\
90 /savematrix mtrx currentmatrix def\n\
93 0 0 1 startangle endangle arc\n\
94 savematrix setmatrix\n\
99 static const char *wxPostScriptHeaderEllipticArc
= "\
100 /ellipticarcdict 8 dict def\n\
101 ellipticarcdict /mtrx matrix put\n\
103 { ellipticarcdict begin\n\
105 /endangle exch def\n\
106 /startangle exch def\n\
111 /savematrix mtrx currentmatrix def\n\
114 do_fill { 0 0 moveto } if\n\
115 0 0 1 startangle endangle arc\n\
116 savematrix setmatrix\n\
117 do_fill { fill }{ stroke } ifelse\n\
121 static const char *wxPostScriptHeaderSpline
= "\
122 /DrawSplineSection {\n\
129 /xa x1 x2 x1 sub 0.666667 mul add def\n\
130 /ya y1 y2 y1 sub 0.666667 mul add def\n\
131 /xb x3 x2 x3 sub 0.666667 mul add def\n\
132 /yb y3 y2 y3 sub 0.666667 mul add def\n\
134 xa ya xb yb x3 y3 curveto\n\
138 static const char *wxPostScriptHeaderColourImage
= "\
139 % define 'colorimage' if it isn't defined\n\
140 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
142 /colorimage where % do we know about 'colorimage'?\n\
143 { pop } % yes: pop off the 'dict' returned\n\
144 { % no: define one\n\
145 /colortogray { % define an RGB->I function\n\
146 /rgbdata exch store % call input 'rgbdata'\n\
147 rgbdata length 3 idiv\n\
148 /npixls exch store\n\
150 0 1 npixls 1 sub {\n\
152 rgbdata rgbindx get 20 mul % Red\n\
153 rgbdata rgbindx 1 add get 32 mul % Green\n\
154 rgbdata rgbindx 2 add get 12 mul % Blue\n\
155 add add 64 idiv % I = .5G + .31R + .18B\n\
157 /rgbindx rgbindx 3 add store\n\
159 grays 0 npixls getinterval\n\
162 % Utility procedure for colorimage operator.\n\
163 % This procedure takes two procedures off the\n\
164 % stack and merges them into a single procedure.\n\
166 /mergeprocs { % def\n\
185 /colorimage { % def\n\
186 pop pop % remove 'false 3' operands\n\
187 {colortogray} mergeprocs\n\
190 } ifelse % end of 'false' case\n\
193 static char wxPostScriptHeaderReencodeISO1
[] =
195 "dup dup findfont dup length dict begin\n"
196 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
197 "/Encoding ISOLatin1Encoding def\n"
198 "currentdict end definefont\n"
200 "/ISOLatin1Encoding [\n"
201 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\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 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
206 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
207 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
208 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
209 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
210 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
211 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
212 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
213 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
214 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
215 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
217 static char wxPostScriptHeaderReencodeISO2
[] =
218 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
219 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
220 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
221 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
222 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
223 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
224 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
225 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
226 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
227 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
228 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
229 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
230 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
231 "/yacute/thorn/ydieresis\n"
234 //-------------------------------------------------------------------------------
236 //-------------------------------------------------------------------------------
238 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
240 float wxPostScriptDC::ms_PSScaleFactor
= 1.0;
242 void wxPostScriptDC::SetResolution(int ppi
)
244 ms_PSScaleFactor
= (float)ppi
/ 72.0;
247 int wxPostScriptDC::GetResolution()
249 return (int)(ms_PSScaleFactor
* 72.0);
252 //-------------------------------------------------------------------------------
254 wxPostScriptDC::wxPostScriptDC ()
256 m_pstream
= (FILE*) NULL
;
266 m_underlinePosition
= 0.0;
267 m_underlineThickness
= 0.0;
269 m_signX
= 1; // default x-axis left to right
270 m_signY
= -1; // default y-axis bottom up -> top down
273 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
275 m_pstream
= (FILE*) NULL
;
285 m_underlinePosition
= 0.0;
286 m_underlineThickness
= 0.0;
288 m_signX
= 1; // default x-axis left to right
289 m_signY
= -1; // default y-axis bottom up -> top down
291 m_printData
= printData
;
296 wxPostScriptDC::~wxPostScriptDC ()
301 m_pstream
= (FILE*) NULL
;
305 bool wxPostScriptDC::Ok() const
310 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
312 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
314 if (m_clipping
) DestroyClippingRegion();
316 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
320 PsPrintf( wxT("gsave\n newpath\n")
321 wxT("%d %d moveto\n")
322 wxT("%d %d lineto\n")
323 wxT("%d %d lineto\n")
324 wxT("%d %d lineto\n")
325 wxT("closepath clip newpath\n"),
326 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
327 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
328 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
329 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
333 void wxPostScriptDC::DestroyClippingRegion()
335 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
340 PsPrint( "grestore\n" );
343 wxDC::DestroyClippingRegion();
346 void wxPostScriptDC::Clear()
348 // This should fail silently to avoid unnecessary
350 // wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
353 bool wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
355 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
359 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
361 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
365 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
367 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
370 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
372 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
374 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
378 PsPrintf( wxT("newpath\n")
379 wxT("%d %d moveto\n")
380 wxT("%d %d lineto\n")
382 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
383 LogicalToDeviceX(x2
), LogicalToDeviceY (y2
) );
385 CalcBoundingBox( x1
, y1
);
386 CalcBoundingBox( x2
, y2
);
389 #define RAD2DEG 57.29577951308
391 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
393 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
395 wxCoord dx
= x1
- xc
;
396 wxCoord dy
= y1
- yc
;
397 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
398 double alpha1
, alpha2
;
400 if (x1
== x2
&& y1
== y2
)
405 else if ( wxIsNullDouble(radius
) )
412 alpha1
= (x1
- xc
== 0) ?
413 (y1
- yc
< 0) ? 90.0 : -90.0 :
414 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
415 alpha2
= (x2
- xc
== 0) ?
416 (y2
- yc
< 0) ? 90.0 : -90.0 :
417 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
419 while (alpha1
<= 0) alpha1
+= 360;
420 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
421 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
422 while (alpha2
> 360) alpha2
-= 360;
424 if (m_brush
.GetStyle() != wxTRANSPARENT
)
428 PsPrintf( wxT("newpath\n")
429 wxT("%d %d %d %d %d %d ellipse\n")
430 wxT("%d %d lineto\n")
433 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
434 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
436 CalcBoundingBox( xc
-radius
, yc
-radius
);
437 CalcBoundingBox( xc
+radius
, yc
+radius
);
440 if (m_pen
.GetStyle() != wxTRANSPARENT
)
444 PsPrintf( wxT("newpath\n")
445 wxT("%d %d %d %d %d %d ellipse\n")
446 wxT("%d %d lineto\n")
449 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
450 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
452 CalcBoundingBox( xc
-radius
, yc
-radius
);
453 CalcBoundingBox( xc
+radius
, yc
+radius
);
457 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
459 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
461 if ( sa
>= 360 || sa
<= -360 )
462 sa
-= int(sa
/360)*360;
463 if ( ea
>= 360 || ea
<=- 360 )
464 ea
-= int(ea
/360)*360;
470 if ( wxIsSameDouble(sa
, ea
) )
472 DrawEllipse(x
,y
,w
,h
);
476 if (m_brush
.GetStyle () != wxTRANSPARENT
)
480 PsPrintf( wxT("newpath\n")
481 wxT("%d %d %d %d %d %d true ellipticarc\n"),
482 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
483 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
484 (wxCoord
)sa
, (wxCoord
)ea
);
486 CalcBoundingBox( x
,y
);
487 CalcBoundingBox( x
+w
, y
+h
);
490 if (m_pen
.GetStyle () != wxTRANSPARENT
)
494 PsPrintf( wxT("newpath\n")
495 wxT("%d %d %d %d %d %d false ellipticarc\n"),
496 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
497 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
498 (wxCoord
)sa
, (wxCoord
)ea
);
500 CalcBoundingBox( x
,y
);
501 CalcBoundingBox( x
+w
, y
+h
);
505 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
507 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
509 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
513 PsPrintf( wxT("newpath\n")
514 wxT("%d %d moveto\n")
515 wxT("%d %d lineto\n")
517 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
518 LogicalToDeviceX(x
+1), LogicalToDeviceY(y
) );
520 CalcBoundingBox( x
, y
);
523 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
525 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
529 if (m_brush
.GetStyle () != wxTRANSPARENT
)
533 PsPrint( "newpath\n" );
535 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
536 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
538 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
540 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
542 for (int i
= 1; i
< n
; i
++)
544 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
545 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
547 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
549 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
552 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
555 if (m_pen
.GetStyle () != wxTRANSPARENT
)
559 PsPrint( "newpath\n" );
561 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
562 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
564 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
566 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
568 for (int i
= 1; i
< n
; i
++)
570 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
571 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
573 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
575 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
578 PsPrint( "closepath\n" );
579 PsPrint( "stroke\n" );
583 void wxPostScriptDC::DoDrawPolyPolygon (int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
585 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
589 if (m_brush
.GetStyle () != wxTRANSPARENT
)
593 PsPrint( "newpath\n" );
596 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
598 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
599 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
601 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
603 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
605 for (int j
= 1; j
< count
[i
]; j
++)
607 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
608 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
610 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
612 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
615 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
618 if (m_pen
.GetStyle () != wxTRANSPARENT
)
622 PsPrint( "newpath\n" );
625 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
627 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
628 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
630 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
632 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
634 for (int j
= 1; j
< count
[i
]; j
++)
636 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
637 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
639 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
641 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
644 PsPrint( "closepath\n" );
645 PsPrint( "stroke\n" );
649 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
651 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
653 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
660 for ( i
=0; i
<n
; i
++ )
662 CalcBoundingBox( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
665 PsPrintf( wxT("newpath\n")
666 wxT("%d %d moveto\n"),
667 LogicalToDeviceX(points
[0].x
+xoffset
),
668 LogicalToDeviceY(points
[0].y
+yoffset
) );
670 for (i
= 1; i
< n
; i
++)
672 PsPrintf( wxT("%d %d lineto\n"),
673 LogicalToDeviceX(points
[i
].x
+xoffset
),
674 LogicalToDeviceY(points
[i
].y
+yoffset
) );
677 PsPrint( "stroke\n" );
680 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
682 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
684 if (m_brush
.GetStyle () != wxTRANSPARENT
)
688 PsPrintf( wxT("newpath\n")
689 wxT("%d %d moveto\n")
690 wxT("%d %d lineto\n")
691 wxT("%d %d lineto\n")
692 wxT("%d %d lineto\n")
695 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
696 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
697 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
698 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
700 CalcBoundingBox( x
, y
);
701 CalcBoundingBox( x
+ width
, y
+ height
);
704 if (m_pen
.GetStyle () != wxTRANSPARENT
)
708 PsPrintf( wxT("newpath\n")
709 wxT("%d %d moveto\n")
710 wxT("%d %d lineto\n")
711 wxT("%d %d lineto\n")
712 wxT("%d %d lineto\n")
715 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
716 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
717 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
718 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
720 CalcBoundingBox( x
, y
);
721 CalcBoundingBox( x
+ width
, y
+ height
);
725 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
727 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
731 // Now, a negative radius is interpreted to mean
732 // 'the proportion of the smallest X or Y dimension'
733 double smallest
= width
< height
? width
: height
;
734 radius
= (-radius
* smallest
);
737 wxCoord rad
= (wxCoord
) radius
;
739 if (m_brush
.GetStyle () != wxTRANSPARENT
)
743 /* Draw rectangle anticlockwise */
744 PsPrintf( wxT("newpath\n")
745 wxT("%d %d %d 90 180 arc\n")
746 wxT("%d %d lineto\n")
747 wxT("%d %d %d 180 270 arc\n")
748 wxT("%d %d lineto\n")
749 wxT("%d %d %d 270 0 arc\n")
750 wxT("%d %d lineto\n")
751 wxT("%d %d %d 0 90 arc\n")
752 wxT("%d %d lineto\n")
755 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
756 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
- rad
),
757 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
758 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
759 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
760 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
761 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
762 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
764 CalcBoundingBox( x
, y
);
765 CalcBoundingBox( x
+ width
, y
+ height
);
768 if (m_pen
.GetStyle () != wxTRANSPARENT
)
772 /* Draw rectangle anticlockwise */
773 PsPrintf( wxT("newpath\n")
774 wxT("%d %d %d 90 180 arc\n")
775 wxT("%d %d lineto\n")
776 wxT("%d %d %d 180 270 arc\n")
777 wxT("%d %d lineto\n")
778 wxT("%d %d %d 270 0 arc\n")
779 wxT("%d %d lineto\n")
780 wxT("%d %d %d 0 90 arc\n")
781 wxT("%d %d lineto\n")
784 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
785 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
- rad
),
786 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
787 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
788 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
789 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
790 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
791 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
793 CalcBoundingBox( x
, y
);
794 CalcBoundingBox( x
+ width
, y
+ height
);
798 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
800 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
802 if (m_brush
.GetStyle () != wxTRANSPARENT
)
806 PsPrintf( wxT("newpath\n")
807 wxT("%d %d %d %d 0 360 ellipse\n")
809 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
810 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
812 CalcBoundingBox( x
- width
, y
- height
);
813 CalcBoundingBox( x
+ width
, y
+ height
);
816 if (m_pen
.GetStyle () != wxTRANSPARENT
)
820 PsPrintf( wxT("newpath\n")
821 wxT("%d %d %d %d 0 360 ellipse\n")
823 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
824 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
826 CalcBoundingBox( x
- width
, y
- height
);
827 CalcBoundingBox( x
+ width
, y
+ height
);
831 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
833 DrawBitmap( icon
, x
, y
, true );
836 /* this has to be char, not wxChar */
837 static char hexArray
[] = "0123456789ABCDEF";
839 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
841 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
843 if (!bitmap
.Ok()) return;
845 wxImage image
= bitmap
.ConvertToImage();
847 if (!image
.Ok()) return;
849 wxCoord w
= image
.GetWidth();
850 wxCoord h
= image
.GetHeight();
852 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
853 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
855 wxCoord xx
= LogicalToDeviceX(x
);
856 wxCoord yy
= LogicalToDeviceY(y
+ bitmap
.GetHeight());
858 PsPrintf( wxT("/origstate save def\n")
859 wxT("20 dict begin\n")
860 wxT("/pix %d string def\n")
861 wxT("/grays %d string def\n")
862 wxT("/npixels 0 def\n")
863 wxT("/rgbindx 0 def\n")
864 wxT("%d %d translate\n")
867 wxT("[%d 0 0 %d 0 %d]\n")
868 wxT("{currentfile pix readhexstring pop}\n")
869 wxT("false 3 colorimage\n"),
870 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
872 unsigned char* data
= image
.GetData();
874 // size of the buffer = width*rgb(3)*hexa(2)+'\n'
875 wxCharBuffer
buffer(w
*6 + 1);
876 int firstDigit
, secondDigit
;
879 for (int j
= 0; j
< h
; j
++)
881 char* bufferindex
= buffer
.data();
884 for (int i
= 0; i
< w
*3; i
++)
886 firstDigit
= (int)(*data
/16.0);
887 secondDigit
= (int)(*data
- (firstDigit
*16.0));
888 *(bufferindex
++) = hexArray
[firstDigit
];
889 *(bufferindex
++) = hexArray
[secondDigit
];
893 *(bufferindex
++) = '\n';
899 PsPrint( "origstate restore\n" );
902 void wxPostScriptDC::SetFont( const wxFont
& font
)
904 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
906 if (!font
.Ok()) return;
910 int Style
= m_font
.GetStyle();
911 int Weight
= m_font
.GetWeight();
914 switch (m_font
.GetFamily())
919 if (Style
== wxITALIC
)
921 if (Weight
== wxBOLD
)
922 name
= "/Courier-BoldOblique";
924 name
= "/Courier-Oblique";
928 if (Weight
== wxBOLD
)
929 name
= "/Courier-Bold";
937 if (Style
== wxITALIC
)
939 if (Weight
== wxBOLD
)
940 name
= "/Times-BoldItalic";
942 name
= "/Times-Italic";
946 if (Weight
== wxBOLD
)
947 name
= "/Times-Bold";
949 name
= "/Times-Roman";
955 name
= "/ZapfChancery-MediumItalic";
961 if (Style
== wxITALIC
)
963 if (Weight
== wxBOLD
)
964 name
= "/Helvetica-BoldOblique";
966 name
= "/Helvetica-Oblique";
970 if (Weight
== wxBOLD
)
971 name
= "/Helvetica-Bold";
979 // We may legitimately call SetFont before BeginDoc
984 PsPrint( " reencodeISO def\n" );
986 PsPrint( " findfont\n" );
989 sprintf( buffer
, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
990 // this is a hack - we must scale font size (in pts) according to m_scaleY but
991 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
992 // to 1/1000th of pt and then back.
993 for (int i
= 0; i
< 100; i
++)
994 if (buffer
[i
] == ',') buffer
[i
] = '.';
998 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1000 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1002 if (!pen
.Ok()) return;
1004 int oldStyle
= m_pen
.GetStyle();
1009 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
1010 for (int i
= 0; i
< 100; i
++)
1011 if (buffer
[i
] == ',') buffer
[i
] = '.';
1015 Line style - WRONG: 2nd arg is OFFSET
1017 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1018 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1019 ter is not number of values in the array of the first one, but an offset
1020 into this description of the pattern. I mean a real *offset* not index
1021 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1022 will be first black line *2* units wxCoord, then space 4 units, then the
1023 pattern of *3* units black, 4 units space will be repeated.
1026 static const char *dotted
= "[2 5] 2";
1027 static const char *short_dashed
= "[4 4] 2";
1028 static const char *wxCoord_dashed
= "[4 8] 2";
1029 static const char *dotted_dashed
= "[6 6 2 6] 4";
1033 switch (m_pen
.GetStyle())
1035 case wxDOT
: psdash
= dotted
; break;
1036 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1037 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1038 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1042 int nDashes
= m_pen
.GetDashes (&dashes
);
1044 for (int i
= 0; i
< nDashes
; ++i
)
1046 sprintf( buffer
, "%d ", dashes
[i
] );
1049 PsPrint ("] 0 setdash\n");
1055 default: psdash
= "[] 0"; break;
1058 if ( psdash
&& (oldStyle
!= m_pen
.GetStyle()) )
1061 PsPrint( " setdash\n" );
1065 unsigned char red
= m_pen
.GetColour().Red();
1066 unsigned char blue
= m_pen
.GetColour().Blue();
1067 unsigned char green
= m_pen
.GetColour().Green();
1071 // Anything not white is black
1072 if (! (red
== (unsigned char) 255 &&
1073 blue
== (unsigned char) 255 &&
1074 green
== (unsigned char) 255) )
1076 red
= (unsigned char) 0;
1077 green
= (unsigned char) 0;
1078 blue
= (unsigned char) 0;
1083 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1085 double redPS
= (double)(red
) / 255.0;
1086 double bluePS
= (double)(blue
) / 255.0;
1087 double greenPS
= (double)(green
) / 255.0;
1090 "%.8f %.8f %.8f setrgbcolor\n",
1091 redPS
, greenPS
, bluePS
);
1092 for (int i
= 0; i
< 100; i
++)
1093 if (buffer
[i
] == ',') buffer
[i
] = '.';
1098 m_currentBlue
= blue
;
1099 m_currentGreen
= green
;
1103 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1105 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1107 if (!brush
.Ok()) return;
1112 unsigned char red
= m_brush
.GetColour().Red();
1113 unsigned char blue
= m_brush
.GetColour().Blue();
1114 unsigned char green
= m_brush
.GetColour().Green();
1118 // Anything not white is black
1119 if (! (red
== (unsigned char) 255 &&
1120 blue
== (unsigned char) 255 &&
1121 green
== (unsigned char) 255) )
1123 red
= (unsigned char) 0;
1124 green
= (unsigned char) 0;
1125 blue
= (unsigned char) 0;
1130 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1132 double redPS
= (double)(red
) / 255.0;
1133 double bluePS
= (double)(blue
) / 255.0;
1134 double greenPS
= (double)(green
) / 255.0;
1138 "%.8f %.8f %.8f setrgbcolor\n",
1139 redPS
, greenPS
, bluePS
);
1140 for (int i
= 0; i
< 100; i
++)
1141 if (buffer
[i
] == ',') buffer
[i
] = '.';
1146 m_currentBlue
= blue
;
1147 m_currentGreen
= green
;
1151 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1153 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1155 if (m_textForegroundColour
.Ok())
1157 unsigned char red
= m_textForegroundColour
.Red();
1158 unsigned char blue
= m_textForegroundColour
.Blue();
1159 unsigned char green
= m_textForegroundColour
.Green();
1163 // Anything not white is black
1164 if (! (red
== (unsigned char) 255 &&
1165 blue
== (unsigned char) 255 &&
1166 green
== (unsigned char) 255))
1168 red
= (unsigned char) 0;
1169 green
= (unsigned char) 0;
1170 blue
= (unsigned char) 0;
1174 // maybe setgray here ?
1175 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1177 double redPS
= (double)(red
) / 255.0;
1178 double bluePS
= (double)(blue
) / 255.0;
1179 double greenPS
= (double)(green
) / 255.0;
1183 "%.8f %.8f %.8f setrgbcolor\n",
1184 redPS
, greenPS
, bluePS
);
1185 for (size_t i
= 0; i
< strlen(buffer
); i
++)
1186 if (buffer
[i
] == ',') buffer
[i
] = '.';
1190 m_currentBlue
= blue
;
1191 m_currentGreen
= green
;
1195 wxCoord text_w
, text_h
, text_descent
;
1197 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1199 // VZ: this seems to be unnecessary, so taking it out for now, if it
1200 // doesn't create any problems, remove this comment entirely
1201 //SetFont( m_font );
1204 int size
= m_font
.GetPointSize();
1206 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1207 // commented by V. Slavik and replaced by accurate version
1208 // - note that there is still rounding error in text_descent!
1209 wxCoord by
= y
+ size
- text_descent
; // baseline
1211 PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1214 const wxWX2MBbuf textbuf
= text
.mb_str();
1215 size_t len
= strlen(textbuf
);
1217 for (i
= 0; i
< len
; i
++)
1219 int c
= (unsigned char) textbuf
[i
];
1220 if (c
== ')' || c
== '(' || c
== '\\')
1222 /* Cope with special characters */
1226 else if ( c
>= 128 )
1228 /* Cope with character codes > 127 */
1229 PsPrintf( wxT("\\%o"), c
);
1237 PsPrint( ") show\n" );
1239 if (m_font
.GetUnderlined())
1241 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1251 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1252 m_underlineThickness
,
1253 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1254 for (i
= 0; i
< 100; i
++)
1255 if (buffer
[i
] == ',') buffer
[i
] = '.';
1259 CalcBoundingBox( x
, y
);
1260 CalcBoundingBox( x
+ size
* text
.length() * 2/3 , y
);
1263 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1265 if ( wxIsNullDouble(angle
) )
1267 DoDrawText(text
, x
, y
);
1271 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1275 if (m_textForegroundColour
.Ok())
1277 unsigned char red
= m_textForegroundColour
.Red();
1278 unsigned char blue
= m_textForegroundColour
.Blue();
1279 unsigned char green
= m_textForegroundColour
.Green();
1283 // Anything not white is black
1284 if (! (red
== (unsigned char) 255 &&
1285 blue
== (unsigned char) 255 &&
1286 green
== (unsigned char) 255))
1288 red
= (unsigned char) 0;
1289 green
= (unsigned char) 0;
1290 blue
= (unsigned char) 0;
1294 // maybe setgray here ?
1295 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1297 double redPS
= (double)(red
) / 255.0;
1298 double bluePS
= (double)(blue
) / 255.0;
1299 double greenPS
= (double)(green
) / 255.0;
1303 "%.8f %.8f %.8f setrgbcolor\n",
1304 redPS
, greenPS
, bluePS
);
1305 for (int i
= 0; i
< 100; i
++)
1306 if (buffer
[i
] == ',') buffer
[i
] = '.';
1310 m_currentBlue
= blue
;
1311 m_currentGreen
= green
;
1315 int size
= m_font
.GetPointSize();
1317 PsPrintf( wxT("%d %d moveto\n"),
1318 LogicalToDeviceX(x
), LogicalToDeviceY(y
));
1321 sprintf(buffer
, "%.8f rotate\n", angle
);
1323 for (i
= 0; i
< 100; i
++)
1325 if (buffer
[i
] == ',') buffer
[i
] = '.';
1330 const wxWX2MBbuf textbuf
= text
.mb_str();
1331 size_t len
= strlen(textbuf
);
1332 for (i
= 0; i
< len
; i
++)
1334 int c
= (unsigned char) textbuf
[i
];
1335 if (c
== ')' || c
== '(' || c
== '\\')
1337 /* Cope with special characters */
1341 else if ( c
>= 128 )
1343 /* Cope with character codes > 127 */
1344 PsPrintf( wxT("\\%o"), c
);
1352 PsPrint( ") show\n" );
1354 sprintf( buffer
, "%.8f rotate\n", -angle
);
1355 for (i
= 0; i
< 100; i
++)
1357 if (buffer
[i
] == ',') buffer
[i
] = '.';
1361 if (m_font
.GetUnderlined())
1363 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1365 GetTextExtent(text
, &w
, &h
);
1374 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1375 m_underlineThickness
,
1376 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1377 for (i
= 0; i
< 100; i
++)
1379 if (buffer
[i
] == ',') buffer
[i
] = '.';
1384 CalcBoundingBox( x
, y
);
1385 CalcBoundingBox( x
+ size
* text
.length() * 2/3 , y
);
1388 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1390 m_backgroundBrush
= brush
;
1393 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1395 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1399 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1401 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1405 // a and b are not used
1407 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1410 wxList::compatibility_iterator node
= points
->GetFirst();
1411 p
= (wxPoint
*)node
->GetData();
1415 node
= node
->GetNext();
1416 p
= (wxPoint
*)node
->GetData();
1423 (double)(x1
+ c
) / 2;
1428 (double)(y1
+ d
) / 2;
1430 PsPrintf( wxT("newpath\n")
1431 wxT("%d %d moveto\n")
1432 wxT("%d %d lineto\n"),
1433 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1434 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1436 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1437 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1439 node
= node
->GetNext();
1442 q
= (wxPoint
*)node
->GetData();
1450 x3
= (double)(x2
+ c
) / 2;
1451 y3
= (double)(y2
+ d
) / 2;
1453 PsPrintf( wxT("%d %d %d %d %d %d DrawSplineSection\n"),
1454 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1455 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1456 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1458 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1459 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1461 node
= node
->GetNext();
1465 At this point, (x2,y2) and (c,d) are the position of the
1466 next-to-last and last point respectively, in the point list
1469 PsPrintf( wxT("%d %d lineto\n")
1471 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1473 #endif // wxUSE_SPLINES
1475 wxCoord
wxPostScriptDC::GetCharWidth() const
1477 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1478 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1482 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1484 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1486 m_signX
= (xLeftRight
? 1 : -1);
1487 m_signY
= (yBottomUp
? 1 : -1);
1489 ComputeScaleAndOrigin();
1492 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1494 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1500 wxDC::SetDeviceOrigin( x
, h
-y
);
1503 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1505 wxPaperSize id
= m_printData
.GetPaperId();
1507 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1509 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1515 w
= paper
->GetSizeDeviceUnits().x
;
1516 h
= paper
->GetSizeDeviceUnits().y
;
1519 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1526 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1527 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1530 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1532 wxPaperSize id
= m_printData
.GetPaperId();
1534 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1536 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1542 w
= paper
->GetWidth() / 10;
1543 h
= paper
->GetHeight() / 10;
1546 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1553 if (width
) *width
= w
;
1554 if (height
) *height
= h
;
1557 // Resolution in pixels per logical inch
1558 wxSize
wxPostScriptDC::GetPPI(void) const
1560 return wxSize((int)(72 * ms_PSScaleFactor
),
1561 (int)(72 * ms_PSScaleFactor
));
1565 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1567 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
1569 if (m_printData
.GetPrintMode() != wxPRINT_MODE_STREAM
)
1571 if (m_printData
.GetFilename() == wxEmptyString
)
1573 wxString filename
= wxGetTempFileName( wxT("ps") );
1574 m_printData
.SetFilename(filename
);
1577 m_pstream
= wxFopen( m_printData
.GetFilename(), wxT("w+") );
1581 wxLogError( _("Cannot open file for PostScript printing!"));
1590 PsPrint( "%!PS-Adobe-2.0\n" );
1591 PsPrintf( wxT("%%%%Title: %s\n"), m_title
.c_str() );
1592 PsPrint( "%%Creator: wxWidgets PostScript renderer\n" );
1593 PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() );
1594 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1595 PsPrint( "%%Orientation: Landscape\n" );
1597 PsPrint( "%%Orientation: Portrait\n" );
1599 // PsPrintf( wxT("%%%%Pages: %d\n"), (wxPageNumber - 1) );
1601 const wxChar
*paper
;
1602 switch (m_printData
.GetPaperId())
1604 case wxPAPER_LETTER
: paper
= wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches
1605 case wxPAPER_LEGAL
: paper
= wxT("Legal"); break; // Legal, 8 1/2 by 14 inches
1606 case wxPAPER_A4
: paper
= wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters
1607 case wxPAPER_TABLOID
: paper
= wxT("Tabloid"); break; // Tabloid, 11 by 17 inches
1608 case wxPAPER_LEDGER
: paper
= wxT("Ledger"); break; // Ledger, 17 by 11 inches
1609 case wxPAPER_STATEMENT
: paper
= wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches
1610 case wxPAPER_EXECUTIVE
: paper
= wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches
1611 case wxPAPER_A3
: paper
= wxT("A3"); break; // A3 sheet, 297 by 420 millimeters
1612 case wxPAPER_A5
: paper
= wxT("A5"); break; // A5 sheet, 148 by 210 millimeters
1613 case wxPAPER_B4
: paper
= wxT("B4"); break; // B4 sheet, 250 by 354 millimeters
1614 case wxPAPER_B5
: paper
= wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper
1615 case wxPAPER_FOLIO
: paper
= wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper
1616 case wxPAPER_QUARTO
: paper
= wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper
1617 case wxPAPER_10X14
: paper
= wxT("10x14"); break; // 10-by-14-inch sheet
1618 default: paper
= wxT("A4");
1620 PsPrintf( wxT("%%%%DocumentPaperSizes: %s\n"), paper
);
1621 PsPrint( "%%EndComments\n\n" );
1623 PsPrint( "%%BeginProlog\n" );
1624 PsPrint( wxPostScriptHeaderConicTo
);
1625 PsPrint( wxPostScriptHeaderEllipse
);
1626 PsPrint( wxPostScriptHeaderEllipticArc
);
1627 PsPrint( wxPostScriptHeaderColourImage
);
1628 PsPrint( wxPostScriptHeaderReencodeISO1
);
1629 PsPrint( wxPostScriptHeaderReencodeISO2
);
1630 if (wxPostScriptHeaderSpline
)
1631 PsPrint( wxPostScriptHeaderSpline
);
1632 PsPrint( "%%EndProlog\n" );
1634 SetBrush( *wxBLACK_BRUSH
);
1635 SetPen( *wxBLACK_PEN
);
1636 SetBackground( *wxWHITE_BRUSH
);
1637 SetTextForeground( *wxBLACK
);
1639 // set origin according to paper size
1640 SetDeviceOrigin( 0,0 );
1647 void wxPostScriptDC::EndDoc ()
1649 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1654 PsPrint( "grestore\n" );
1658 fclose( m_pstream
);
1659 m_pstream
= (FILE *) NULL
;
1663 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1664 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1665 double wx_printer_scale_x
, wx_printer_scale_y
;
1667 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1668 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1670 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1671 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1673 // Compute the bounding box. Note that it is in the default user
1674 // coordinate system, thus we have to convert the values.
1675 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1676 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1677 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1678 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1680 // LOG2DEV may have changed the minimum to maximum vice versa
1681 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1682 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1684 // account for used scaling (boundingbox is before scaling in ps-file)
1685 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1686 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1688 wxCoord llx
, lly
, urx
, ury
;
1689 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1690 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1691 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1692 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1693 // (end of bounding box computation)
1696 // If we're landscape, our sense of "x" and "y" is reversed.
1697 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1700 tmp
= llx
; llx
= lly
; lly
= tmp
;
1701 tmp
= urx
; urx
= ury
; ury
= tmp
;
1703 // We need either the two lines that follow, or we need to subtract
1704 // min_x from real_translate_y, which is commented out below.
1705 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1706 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1709 // The Adobe specifications call for integers; we round as to make
1710 // the bounding larger.
1711 PsPrintf( wxT("%%%%BoundingBox: %d %d %d %d\n"),
1712 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1713 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1715 // To check the correctness of the bounding box, postscript commands
1716 // to draw a box corresponding to the bounding box are generated below.
1717 // But since we typically don't want to print such a box, the postscript
1718 // commands are generated within comments. These lines appear before any
1719 // adjustment of scale, rotation, or translation, and hence are in the
1720 // default user coordinates.
1721 PsPrint( "% newpath\n" );
1722 PsPrintf( wxT("%% %d %d moveto\n"), llx
, lly
);
1723 PsPrintf( wxT("%% %d %d lineto\n"), urx
, lly
);
1724 PsPrintf( wxT("%% %d %d lineto\n"), urx
, ury
);
1725 PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx
, ury
);
1729 wxPostScriptPrintNativeData
*data
=
1730 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1732 if (m_ok
&& (m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
1735 command
+= data
->GetPrinterCommand();
1736 command
+= wxT(" ");
1737 command
+= data
->GetPrinterOptions();
1738 command
+= wxT(" ");
1739 command
+= m_printData
.GetFilename();
1741 wxExecute( command
, true );
1742 wxRemoveFile( m_printData
.GetFilename() );
1747 void wxPostScriptDC::StartPage()
1749 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1751 PsPrintf( wxT("%%%%Page: %d\n"), wxPageNumber
++ );
1753 // What is this one supposed to do? RR.
1754 // *m_pstream << "matrix currentmatrix\n";
1756 // Added by Chris Breeze
1758 // Each page starts with an "initgraphics" which resets the
1759 // transformation and so we need to reset the origin
1760 // (and rotate the page for landscape printing)
1763 wxCoord translate_x
, translate_y
;
1764 double scale_x
, scale_y
;
1766 wxPostScriptPrintNativeData
*data
=
1767 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1769 translate_x
= (wxCoord
)data
->GetPrinterTranslateX();
1770 translate_y
= (wxCoord
)data
->GetPrinterTranslateY();
1772 scale_x
= data
->GetPrinterScaleX();
1773 scale_y
= data
->GetPrinterScaleY();
1775 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1778 GetSize( (int*) NULL
, &h
);
1780 PsPrint( "90 rotate\n" );
1781 // I copied this one from a PostScript tutorial, but to no avail. RR.
1782 // PsPrint( "90 rotate llx neg ury nef translate\n" );
1786 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1787 scale_y
/ ms_PSScaleFactor
);
1788 for (int i
= 0; i
< 100; i
++)
1789 if (buffer
[i
] == ',') buffer
[i
] = '.';
1792 PsPrintf( wxT("%d %d translate\n"), translate_x
, translate_y
);
1795 void wxPostScriptDC::EndPage ()
1797 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1799 PsPrint( "showpage\n" );
1802 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1803 wxCoord fwidth
, wxCoord fheight
,
1805 wxCoord xsrc
, wxCoord ysrc
,
1806 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
1808 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
1810 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1812 /* blit into a bitmap */
1813 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1815 memDC
.SelectObject(bitmap
);
1816 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1817 memDC
.SelectObject(wxNullBitmap
);
1819 /* draw bitmap. scaling and positioning is done there */
1820 DrawBitmap( bitmap
, xdest
, ydest
);
1825 wxCoord
wxPostScriptDC::GetCharHeight() const
1828 return m_font
.GetPointSize();
1833 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1834 wxCoord
*x
, wxCoord
*y
,
1835 wxCoord
*descent
, wxCoord
*externalLeading
,
1836 wxFont
*theFont
) const
1838 wxFont
*fontToUse
= theFont
;
1840 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1842 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1848 if (descent
) (*descent
) = 0;
1849 if (externalLeading
) (*externalLeading
) = 0;
1855 const wxWX2MBbuf strbuf
= string
.mb_str();
1857 #if !wxUSE_AFM_FOR_POSTSCRIPT
1858 /* Provide a VERY rough estimate (avoid using it).
1859 * Produces accurate results for mono-spaced font
1860 * such as Courier (aka wxMODERN) */
1865 height
= fontToUse
->GetPointSize();
1868 *x
= strlen (strbuf
) * height
* 72 / 120;
1870 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
1871 if (descent
) *descent
= 0;
1872 if (externalLeading
) *externalLeading
= 0;
1875 /* method for calculating string widths in postscript:
1876 / read in the AFM (adobe font metrics) file for the
1877 / actual font, parse it and extract the character widths
1878 / and also the descender. this may be improved, but for now
1879 / it works well. the AFM file is only read in if the
1880 / font is changed. this may be chached in the future.
1881 / calls to GetTextExtent with the font unchanged are rather
1884 / for each font and style used there is an AFM file necessary.
1885 / currently i have only files for the roman font family.
1886 / I try to get files for the other ones!
1888 / CAVE: the size of the string is currently always calculated
1889 / in 'points' (1/72 of an inch). this should later on be
1890 / changed to depend on the mapping mode.
1891 / CAVE: the path to the AFM files must be set before calling this
1892 / function. this is usually done by a call like the following:
1893 / wxSetAFMPath("d:\\wxw161\\afm\\");
1897 / wxPostScriptDC dc(NULL, true);
1899 / wxSetAFMPath("d:\\wxw161\\afm\\");
1900 / dc.StartDoc("Test");
1903 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1904 / dc.GetTextExtent("Hallo",&w,&h);
1909 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1911 / updated: 14.05.95 */
1913 /* these static vars are for storing the state between calls */
1914 static int lastFamily
= INT_MIN
;
1915 static int lastSize
= INT_MIN
;
1916 static int lastStyle
= INT_MIN
;
1917 static int lastWeight
= INT_MIN
;
1918 static int lastDescender
= INT_MIN
;
1919 static int lastWidths
[256]; /* widths of the characters */
1921 double UnderlinePosition
= 0.0;
1922 double UnderlineThickness
= 0.0;
1924 // Get actual parameters
1925 int Family
= fontToUse
->GetFamily();
1926 int Size
= fontToUse
->GetPointSize();
1927 int Style
= fontToUse
->GetStyle();
1928 int Weight
= fontToUse
->GetWeight();
1930 // If we have another font, read the font-metrics
1931 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
1933 // Store actual values
1934 lastFamily
= Family
;
1937 lastWeight
= Weight
;
1946 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBoO.afm");
1947 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBo.afm");
1948 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("CourO.afm");
1949 else name
= wxT("Cour.afm");
1954 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBoO.afm");
1955 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBo.afm");
1956 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("TimesO.afm");
1957 else name
= wxT("TimesRo.afm");
1962 name
= wxT("Zapf.afm");
1968 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBoO.afm");
1969 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBo.afm");
1970 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("HelvO.afm");
1971 else name
= wxT("Helv.afm");
1976 FILE *afmFile
= NULL
;
1978 // Get the directory of the AFM files
1981 // VZ: I don't know if the cast always works under Unix but it clearly
1982 // never does under Windows where the pointer is
1983 // wxWindowsPrintNativeData and so calling GetFontMetricPath() on
1986 wxPostScriptPrintNativeData
*data
=
1987 wxDynamicCast(m_printData
.GetNativeData(), wxPostScriptPrintNativeData
);
1989 if (data
&& !data
->GetFontMetricPath().empty())
1991 afmName
= data
->GetFontMetricPath();
1992 afmName
<< wxFILE_SEP_PATH
<< name
;
1996 if ( !afmName
.empty() )
1997 afmFile
= wxFopen(afmName
, wxT("r"));
2001 #if defined(__UNIX__) && !defined(__VMS__)
2002 afmName
= wxGetDataDir();
2004 afmName
= wxStandardPaths::Get().GetDataDir();
2005 #endif // __UNIX__/!__UNIX__
2007 afmName
<< wxFILE_SEP_PATH
2008 #if defined(__LINUX__) || defined(__FREEBSD__)
2009 << wxT("gs_afm") << wxFILE_SEP_PATH
2011 << wxT("afm") << wxFILE_SEP_PATH
2014 afmFile
= wxFopen(afmName
,wxT("r"));
2017 /* 2. open and process the file
2018 / a short explanation of the AFM format:
2019 / we have for each character a line, which gives its size
2022 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2024 / that means, we have a character with ascii code 63, and width
2025 / (444/1000 * fontSize) points.
2026 / the other data is ignored for now!
2028 / when the font has changed, we read in the right AFM file and store the
2029 / character widths in an array, which is processed below (see point 3.). */
2032 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2033 wxLogDebug( wxT(" using approximate values"));
2034 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2035 lastDescender
= -150; /* dito. */
2039 /* init the widths array */
2040 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2041 /* some variables for holding parts of a line */
2042 char cString
[10], semiString
[10], WXString
[10];
2043 char descString
[20];
2044 char upString
[30], utString
[30];
2048 /* read in the file and parse it */
2049 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2051 /* A.) check for descender definition */
2052 if (strncmp(line
,"Descender",9)==0)
2054 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2055 (strcmp(descString
,"Descender")!=0))
2057 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2060 /* JC 1.) check for UnderlinePosition */
2061 else if(strncmp(line
,"UnderlinePosition",17)==0)
2063 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2064 (strcmp(upString
,"UnderlinePosition")!=0))
2066 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2069 /* JC 2.) check for UnderlineThickness */
2070 else if(strncmp(line
,"UnderlineThickness",18)==0)
2072 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2073 (strcmp(utString
,"UnderlineThickness")!=0))
2075 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2078 /* JC 3.) check for EncodingScheme */
2079 else if(strncmp(line
,"EncodingScheme",14)==0)
2081 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2082 (strcmp(utString
,"EncodingScheme")!=0))
2084 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2086 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2088 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2089 afmName
.c_str(),line
, encString
);
2092 /* B.) check for char-width */
2093 else if(strncmp(line
,"C ",2)==0)
2095 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2097 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2099 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2101 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2103 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2104 if (ascii
>=0 && ascii
<256)
2106 lastWidths
[ascii
] = cWidth
; /* store width */
2110 /* MATTHEW: this happens a lot; don't print an error */
2111 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2114 /* C.) ignore other entries. */
2118 /* hack to compute correct values for german 'Umlaute'
2119 / the correct way would be to map the character names
2120 / like 'adieresis' to corresp. positions of ISOEnc and read
2121 / these values from AFM files, too. Maybe later ... */
2123 // NB: casts to int are needed to suppress gcc 3.3 warnings
2124 lastWidths
[196] = lastWidths
[(int)'A']; // Ä
2125 lastWidths
[228] = lastWidths
[(int)'a']; // ä
2126 lastWidths
[214] = lastWidths
[(int)'O']; // Ö
2127 lastWidths
[246] = lastWidths
[(int)'o']; // ö
2128 lastWidths
[220] = lastWidths
[(int)'U']; // Ü
2129 lastWidths
[252] = lastWidths
[(int)'u']; // ü
2130 lastWidths
[223] = lastWidths
[(int)251]; // ß
2132 /* JC: calculate UnderlineThickness/UnderlinePosition */
2134 // VS: dirty, but is there any better solution?
2136 pt
= (double*) &m_underlinePosition
;
2137 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2138 pt
= (double*) &m_underlineThickness
;
2139 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2144 /* 3. now the font metrics are read in, calc size this
2145 / is done by adding the widths of the characters in the
2146 / string. they are given in 1/1000 of the size! */
2149 wxCoord height
=Size
; /* by default */
2151 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2153 if(lastWidths
[*p
]== INT_MIN
)
2155 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2156 sum
+= lastWidths
[(unsigned char)' ']; /* assume space */
2160 sum
+= lastWidths
[*p
];
2164 double widthSum
= sum
;
2166 widthSum
/= 1000.0F
;
2168 /* add descender to height (it is usually a negative value) */
2169 //if (lastDescender != INT_MIN)
2171 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2173 // - commented by V. Slavik - height already contains descender in it
2174 // (judging from few experiments)
2176 /* return size values */
2178 *x
= (wxCoord
)widthSum
;
2182 /* return other parameters */
2185 if(lastDescender
!=INT_MIN
)
2187 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2195 /* currently no idea how to calculate this! */
2196 if (externalLeading
) *externalLeading
= 0;
2201 // print postscript datas via required method (file, stream)
2202 void wxPostScriptDC::PsPrintf( const wxChar
* fmt
, ... )
2205 va_start(argptr
, fmt
);
2207 PsPrint( wxString::FormatV( fmt
, argptr
).c_str() );
2210 void wxPostScriptDC::PsPrint( const char* psdata
)
2212 wxPostScriptPrintNativeData
*data
=
2213 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2215 switch (m_printData
.GetPrintMode())
2218 // append to output stream
2219 case wxPRINT_MODE_STREAM
:
2221 wxOutputStream
* outputstream
= data
->GetOutputStream();
2222 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2223 outputstream
->Write( psdata
, strlen( psdata
) );
2226 #endif // wxUSE_STREAMS
2228 // save data into file
2230 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2231 fwrite( psdata
, 1, strlen( psdata
), m_pstream
);
2235 void wxPostScriptDC::PsPrint( int ch
)
2237 wxPostScriptPrintNativeData
*data
=
2238 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2240 switch (m_printData
.GetPrintMode())
2243 // append to output stream
2244 case wxPRINT_MODE_STREAM
:
2246 wxOutputStream
* outputstream
= data
->GetOutputStream();
2247 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2248 outputstream
->PutC( (char)ch
);
2251 #endif // wxUSE_STREAMS
2253 // save data into file
2255 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2256 fputc( ch
, m_pstream
);
2260 #endif // wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT