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"
26 #include "wx/dcmemory.h"
32 #include "wx/prntbase.h"
33 #include "wx/generic/prntdlgg.h"
35 #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 //-------------------------------------------------------------------------------
241 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
243 wxPostScriptDC::wxPostScriptDC()
245 m_pimpl
= new wxPostScriptImplDC( this );
248 wxPostScriptDC::wxPostScriptDC(const wxPrintData
& printData
)
250 m_pimpl
= new wxPostScriptImplDC( this, printData
);
257 static const double RAD2DEG
= 180.0 / M_PI
;
259 // we don't want to use only 72 dpi from PS print
260 static const int DPI
= 600;
261 static const double PS2DEV
= 600.0 / 72.0;
262 static const double DEV2PS
= 72.0 / 600.0;
264 #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS)
265 #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS)
266 #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS)
267 #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS)
271 IMPLEMENT_ABSTRACT_CLASS(wxPostScriptImplDC
, wxImplDC
)
273 IMPLEMENT_ABSTRACT_CLASS(wxPostScriptDC
, wxDC
)
276 //-------------------------------------------------------------------------------
279 wxPostScriptImplDC::wxPostScriptImplDC( wxPostScriptDC
*owner
) :
284 m_pageHeight
= 842 * PS2DEV
;
289 wxPostScriptImplDC::wxPostScriptImplDC( wxPostScriptDC
*owner
, const wxPrintData
& data
) :
294 // this calculates m_pageHeight required for
295 // taking the inverted Y axis into account
296 SetPrintData( data
);
304 wxPostScriptImplDC::wxPostScriptImplDC( wxPrinterDC
*owner
) :
307 wxPostScriptDC::wxPostScriptDC()
312 m_pageHeight
= 842 * PS2DEV
;
318 wxPostScriptImplDC::wxPostScriptImplDC( wxPrinterDC
*owner
, const wxPrintData
& data
) :
321 wxPostScriptDC::wxPostScriptDC( const wxPrintData
& data
)
326 // this calculates m_pageHeight required for
327 // taking the inverted Y axis into account
328 SetPrintData( data
);
333 void wxPostScriptImplDC::Init()
335 m_pstream
= (FILE*) NULL
;
345 m_underlinePosition
= 0.0;
346 m_underlineThickness
= 0.0;
350 wxPostScriptImplDC::~wxPostScriptImplDC ()
355 m_pstream
= (FILE*) NULL
;
359 bool wxPostScriptImplDC::IsOk() const
364 wxRect
wxPostScriptImplDC::GetPaperRect()
369 return wxRect(0,0,w
,h
);
372 int wxPostScriptImplDC::GetResolution()
377 void wxPostScriptImplDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
379 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
382 DestroyClippingRegion();
390 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
396 buffer
.Printf( "gsave\n"
402 "closepath clip newpath\n",
403 XLOG2DEV(x
), YLOG2DEV(y
),
404 XLOG2DEV(x
+w
), YLOG2DEV(y
),
405 XLOG2DEV(x
+w
), YLOG2DEV(y
+h
),
406 XLOG2DEV(x
), YLOG2DEV(y
+h
) );
407 buffer
.Replace( ",", "." );
412 void wxPostScriptImplDC::DestroyClippingRegion()
414 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
419 PsPrint( "grestore\n" );
423 wxImplDC::DestroyClippingRegion();
425 wxDC::DestroyClippingRegion();
429 void wxPostScriptImplDC::Clear()
431 // This should fail silently to avoid unnecessary
433 // wxFAIL_MSG( wxT("wxPostScriptImplDC::Clear not implemented.") );
436 bool wxPostScriptImplDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
438 wxFAIL_MSG( wxT("wxPostScriptImplDC::FloodFill not implemented.") );
442 bool wxPostScriptImplDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
444 wxFAIL_MSG( wxT("wxPostScriptImplDC::GetPixel not implemented.") );
448 void wxPostScriptImplDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
450 wxFAIL_MSG( wxT("wxPostScriptImplDC::CrossHair not implemented.") );
453 void wxPostScriptImplDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
455 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
457 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
462 buffer
.Printf( "newpath\n"
466 XLOG2DEV(x1
), YLOG2DEV(y1
),
467 XLOG2DEV(x2
), YLOG2DEV(y2
) );
468 buffer
.Replace( ",", "." );
471 CalcBoundingBox( x1
, y1
);
472 CalcBoundingBox( x2
, y2
);
475 void wxPostScriptImplDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
477 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
479 wxCoord dx
= x1
- xc
;
480 wxCoord dy
= y1
- yc
;
481 double radius
= sqrt( (double)(dx
*dx
+dy
*dy
) );
482 double alpha1
, alpha2
;
484 if (x1
== x2
&& y1
== y2
)
489 else if ( wxIsNullDouble(radius
) )
496 alpha1
= (x1
- xc
== 0) ?
497 (y1
- yc
< 0) ? 90.0 : -90.0 :
498 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
499 alpha2
= (x2
- xc
== 0) ?
500 (y2
- yc
< 0) ? 90.0 : -90.0 :
501 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
503 while (alpha1
<= 0) alpha1
+= 360;
504 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
505 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
506 while (alpha2
> 360) alpha2
-= 360;
508 int i_radius
= wxRound( radius
);
510 if (m_brush
.GetStyle() != wxTRANSPARENT
)
515 buffer
.Printf( "newpath\n"
516 "%f %f %f %f %f %f ellipse\n"
520 XLOG2DEV(xc
), YLOG2DEV(yc
),
521 XLOG2DEVREL(i_radius
), YLOG2DEVREL(i_radius
),
523 XLOG2DEV(xc
), YLOG2DEV(yc
) );
524 buffer
.Replace( ",", "." );
527 CalcBoundingBox( xc
-i_radius
, yc
-i_radius
);
528 CalcBoundingBox( xc
+i_radius
, yc
+i_radius
);
531 if (m_pen
.GetStyle() != wxTRANSPARENT
)
536 buffer
.Printf( "newpath\n"
537 "%f %f %f %f %f %f ellipse\n"
541 XLOG2DEV(xc
), YLOG2DEV(yc
),
542 XLOG2DEVREL(i_radius
), YLOG2DEVREL(i_radius
),
544 XLOG2DEV(xc
), YLOG2DEV(yc
) );
545 buffer
.Replace( ",", "." );
548 CalcBoundingBox( xc
-i_radius
, yc
-i_radius
);
549 CalcBoundingBox( xc
+i_radius
, yc
+i_radius
);
553 void wxPostScriptImplDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
555 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
557 if ( sa
>= 360 || sa
<= -360 )
558 sa
-= int(sa
/360)*360;
559 if ( ea
>= 360 || ea
<=- 360 )
560 ea
-= int(ea
/360)*360;
566 if ( wxIsSameDouble(sa
, ea
) )
568 DoDrawEllipse(x
,y
,w
,h
);
572 if (m_brush
.GetStyle () != wxTRANSPARENT
)
577 buffer
.Printf( "newpath\n"
578 "%f %f %f %f %f %f true ellipticarc\n",
579 XLOG2DEV(x
+w
/2), YLOG2DEV(y
+h
/2),
580 XLOG2DEVREL(w
/2), YLOG2DEVREL(h
/2),
582 buffer
.Replace( ",", "." );
585 CalcBoundingBox( x
,y
);
586 CalcBoundingBox( x
+w
, y
+h
);
589 if (m_pen
.GetStyle () != wxTRANSPARENT
)
594 buffer
.Printf( "newpath\n"
595 "%f %f %f %f %f %f false ellipticarc\n",
596 XLOG2DEV(x
+w
/2), YLOG2DEV(y
+h
/2),
597 XLOG2DEVREL(w
/2), YLOG2DEVREL(h
/2),
599 buffer
.Replace( ",", "." );
602 CalcBoundingBox( x
,y
);
603 CalcBoundingBox( x
+w
, y
+h
);
607 void wxPostScriptImplDC::DoDrawPoint (wxCoord x
, wxCoord y
)
609 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
611 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
616 buffer
.Printf( "newpath\n"
620 XLOG2DEV(x
), YLOG2DEV(y
),
621 XLOG2DEV(x
+1), YLOG2DEV(y
) );
622 buffer
.Replace( ",", "." );
625 CalcBoundingBox( x
, y
);
628 void wxPostScriptImplDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
630 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
634 if (m_brush
.GetStyle () != wxTRANSPARENT
)
638 PsPrint( "newpath\n" );
640 double xx
= XLOG2DEV(points
[0].x
+ xoffset
);
641 double yy
= YLOG2DEV(points
[0].y
+ yoffset
);
644 buffer
.Printf( "%f %f moveto\n", xx
, yy
);
645 buffer
.Replace( ",", "." );
648 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
650 for (int i
= 1; i
< n
; i
++)
652 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
653 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
655 buffer
.Printf( "%f %f lineto\n", xx
, yy
);
656 buffer
.Replace( ",", "." );
659 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
662 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
665 if (m_pen
.GetStyle () != wxTRANSPARENT
)
669 PsPrint( "newpath\n" );
671 double xx
= XLOG2DEV(points
[0].x
+ xoffset
);
672 double yy
= YLOG2DEV(points
[0].y
+ yoffset
);
675 buffer
.Printf( "%f %f moveto\n", xx
, yy
);
676 buffer
.Replace( ",", "." );
679 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
681 for (int i
= 1; i
< n
; i
++)
683 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
684 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
686 buffer
.Printf( "%f %f lineto\n", xx
, yy
);
687 buffer
.Replace( ",", "." );
690 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
693 PsPrint( "closepath\n" );
694 PsPrint( "stroke\n" );
698 void wxPostScriptImplDC::DoDrawPolyPolygon (int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
700 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
704 if (m_brush
.GetStyle () != wxTRANSPARENT
)
708 PsPrint( "newpath\n" );
711 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
713 double xx
= XLOG2DEV(points
[ofs
].x
+ xoffset
);
714 double yy
= YLOG2DEV(points
[ofs
].y
+ yoffset
);
717 buffer
.Printf( "%f %f moveto\n", xx
, yy
);
718 buffer
.Replace( ",", "." );
721 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
723 for (int j
= 1; j
< count
[i
]; j
++)
725 xx
= XLOG2DEV(points
[ofs
+j
].x
+ xoffset
);
726 yy
= YLOG2DEV(points
[ofs
+j
].y
+ yoffset
);
728 buffer
.Printf( "%f %f lineto\n", xx
, yy
);
729 buffer
.Replace( ",", "." );
732 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
735 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
738 if (m_pen
.GetStyle () != wxTRANSPARENT
)
742 PsPrint( "newpath\n" );
745 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
747 double xx
= XLOG2DEV(points
[ofs
].x
+ xoffset
);
748 double yy
= YLOG2DEV(points
[ofs
].y
+ yoffset
);
751 buffer
.Printf( "%f %f moveto\n", xx
, yy
);
752 buffer
.Replace( ",", "." );
755 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
757 for (int j
= 1; j
< count
[i
]; j
++)
759 xx
= XLOG2DEV(points
[ofs
+j
].x
+ xoffset
);
760 yy
= YLOG2DEV(points
[ofs
+j
].y
+ yoffset
);
762 buffer
.Printf( "%f %f lineto\n", xx
, yy
);
763 buffer
.Replace( ",", "." );
766 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
769 PsPrint( "closepath\n" );
770 PsPrint( "stroke\n" );
774 void wxPostScriptImplDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
776 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
778 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
785 for ( i
=0; i
<n
; i
++ )
786 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
789 buffer
.Printf( "newpath\n"
791 XLOG2DEV(points
[0].x
+xoffset
),
792 YLOG2DEV(points
[0].y
+yoffset
) );
793 buffer
.Replace( ",", "." );
796 for (i
= 1; i
< n
; i
++)
798 buffer
.Printf( "%f %f lineto\n",
799 XLOG2DEV(points
[i
].x
+xoffset
),
800 YLOG2DEV(points
[i
].y
+yoffset
) );
801 buffer
.Replace( ",", "." );
805 PsPrint( "stroke\n" );
808 void wxPostScriptImplDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
810 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
815 if (m_brush
.GetStyle () != wxTRANSPARENT
)
820 buffer
.Printf( "newpath\n"
827 XLOG2DEV(x
), YLOG2DEV(y
),
828 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
829 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
830 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
831 buffer
.Replace( ",", "." );
834 CalcBoundingBox( x
, y
);
835 CalcBoundingBox( x
+ width
, y
+ height
);
838 if (m_pen
.GetStyle () != wxTRANSPARENT
)
843 buffer
.Printf( "newpath\n"
850 XLOG2DEV(x
), YLOG2DEV(y
),
851 XLOG2DEV(x
+ width
), YLOG2DEV(y
),
852 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
),
853 XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
854 buffer
.Replace( ",", "." );
857 CalcBoundingBox( x
, y
);
858 CalcBoundingBox( x
+ width
, y
+ height
);
862 void wxPostScriptImplDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
864 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
871 // Now, a negative radius is interpreted to mean
872 // 'the proportion of the smallest X or Y dimension'
873 double smallest
= width
< height
? width
: height
;
874 radius
= (-radius
* smallest
);
877 wxCoord rad
= (wxCoord
) radius
;
879 if (m_brush
.GetStyle () != wxTRANSPARENT
)
883 /* Draw rectangle anticlockwise */
885 buffer
.Printf( "newpath\n"
886 "%f %f %f 90 180 arc\n"
888 "%f %f %f 180 270 arc\n"
890 "%f %f %f 270 0 arc\n"
892 "%f %f %f 0 90 arc\n"
896 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
897 XLOG2DEV(x
), YLOG2DEV(y
+ height
- rad
),
898 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
899 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
900 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
901 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
902 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
903 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
904 buffer
.Replace( ",", "." );
907 CalcBoundingBox( x
, y
);
908 CalcBoundingBox( x
+ width
, y
+ height
);
911 if (m_pen
.GetStyle () != wxTRANSPARENT
)
915 /* Draw rectangle anticlockwise */
917 buffer
.Printf( "newpath\n"
918 "%f %f %f 90 180 arc\n"
920 "%f %f %f 180 270 arc\n"
922 "%f %f %f 270 0 arc\n"
924 "%f %f %f 0 90 arc\n"
928 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
929 XLOG2DEV(x
), YLOG2DEV(y
+ height
- rad
),
930 XLOG2DEV(x
+ rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
931 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
),
932 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ height
- rad
), XLOG2DEVREL(rad
),
933 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ rad
),
934 XLOG2DEV(x
+ width
- rad
), YLOG2DEV(y
+ rad
), XLOG2DEVREL(rad
),
935 XLOG2DEV(x
+ rad
), YLOG2DEV(y
) );
936 buffer
.Replace( ",", "." );
939 CalcBoundingBox( x
, y
);
940 CalcBoundingBox( x
+ width
, y
+ height
);
944 void wxPostScriptImplDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
946 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
951 if (m_brush
.GetStyle () != wxTRANSPARENT
)
956 buffer
.Printf( "newpath\n"
957 "%f %f %f %f 0 360 ellipse\n"
959 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
960 XLOG2DEVREL(width
/ 2), YLOG2DEVREL(height
/ 2) );
961 buffer
.Replace( ",", "." );
964 CalcBoundingBox( x
- width
, y
- height
);
965 CalcBoundingBox( x
+ width
, y
+ height
);
968 if (m_pen
.GetStyle () != wxTRANSPARENT
)
973 buffer
.Printf( "newpath\n"
974 "%f %f %f %f 0 360 ellipse\n"
976 XLOG2DEV(x
+ width
/ 2), YLOG2DEV(y
+ height
/ 2),
977 XLOG2DEVREL(width
/ 2), YLOG2DEVREL(height
/ 2) );
978 buffer
.Replace( ",", "." );
981 CalcBoundingBox( x
- width
, y
- height
);
982 CalcBoundingBox( x
+ width
, y
+ height
);
986 void wxPostScriptImplDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
988 DoDrawBitmap( icon
, x
, y
, true );
991 /* this has to be char, not wxChar */
992 static char hexArray
[] = "0123456789ABCDEF";
994 void wxPostScriptImplDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
996 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
998 if (!bitmap
.Ok()) return;
1000 wxImage image
= bitmap
.ConvertToImage();
1002 if (!image
.Ok()) return;
1004 wxCoord w
= image
.GetWidth();
1005 wxCoord h
= image
.GetHeight();
1007 double ww
= XLOG2DEVREL(image
.GetWidth());
1008 double hh
= YLOG2DEVREL(image
.GetHeight());
1010 double xx
= XLOG2DEV(x
);
1011 double yy
= YLOG2DEV(y
+ bitmap
.GetHeight());
1014 buffer
.Printf( "/origstate save def\n"
1016 "/pix %d string def\n"
1017 "/grays %d string def\n"
1023 "[%d 0 0 %d 0 %d]\n"
1024 "{currentfile pix readhexstring pop}\n"
1025 "false 3 colorimage\n",
1026 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
1027 buffer
.Replace( ",", "." );
1030 unsigned char* data
= image
.GetData();
1032 // size of the buffer = width*rgb(3)*hexa(2)+'\n'
1033 wxCharBuffer
charbuffer(w
*6 + 1);
1034 int firstDigit
, secondDigit
;
1037 for (int j
= 0; j
< h
; j
++)
1039 char* bufferindex
= charbuffer
.data();
1042 for (int i
= 0; i
< w
*3; i
++)
1044 firstDigit
= (int)(*data
/16.0);
1045 secondDigit
= (int)(*data
- (firstDigit
*16.0));
1046 *(bufferindex
++) = hexArray
[firstDigit
];
1047 *(bufferindex
++) = hexArray
[secondDigit
];
1051 *(bufferindex
++) = '\n';
1055 fwrite( charbuffer
, 1, strlen( charbuffer
), m_pstream
);
1057 PsPrint( charbuffer
);
1061 PsPrint( "origstate restore\n" );
1064 void wxPostScriptImplDC::SetFont( const wxFont
& font
)
1066 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1068 if (!font
.Ok()) return;
1072 int Style
= m_font
.GetStyle();
1073 int Weight
= m_font
.GetWeight();
1076 switch (m_font
.GetFamily())
1081 if (Style
== wxITALIC
)
1083 if (Weight
== wxBOLD
)
1084 name
= "/Courier-BoldOblique";
1086 name
= "/Courier-Oblique";
1090 if (Weight
== wxBOLD
)
1091 name
= "/Courier-Bold";
1099 if (Style
== wxITALIC
)
1101 if (Weight
== wxBOLD
)
1102 name
= "/Times-BoldItalic";
1104 name
= "/Times-Italic";
1108 if (Weight
== wxBOLD
)
1109 name
= "/Times-Bold";
1111 name
= "/Times-Roman";
1117 name
= "/ZapfChancery-MediumItalic";
1123 if (Style
== wxITALIC
)
1125 if (Weight
== wxBOLD
)
1126 name
= "/Helvetica-BoldOblique";
1128 name
= "/Helvetica-Oblique";
1132 if (Weight
== wxBOLD
)
1133 name
= "/Helvetica-Bold";
1135 name
= "/Helvetica";
1141 // We may legitimately call SetFont before BeginDoc
1146 PsPrint( " reencodeISO def\n" );
1148 PsPrint( " findfont\n" );
1151 double size
= (double) m_font
.GetPointSize();
1153 buffer
.Printf( "%f scalefont setfont\n", size
* DEV2PS
* m_scaleX
);
1154 buffer
.Replace( ",", "." );
1158 void wxPostScriptImplDC::SetPen( const wxPen
& pen
)
1160 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1162 if (!pen
.Ok()) return;
1164 int oldStyle
= m_pen
.GetStyle();
1170 if (m_pen
.GetWidth() <= 0)
1173 width
= (double) m_pen
.GetWidth();
1176 buffer
.Printf( "%f setlinewidth\n", width
* DEV2PS
* m_scaleX
);
1177 buffer
.Replace( ",", "." );
1181 Line style - WRONG: 2nd arg is OFFSET
1183 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1184 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1185 ter is not number of values in the array of the first one, but an offset
1186 into this description of the pattern. I mean a real *offset* not index
1187 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1188 will be first black line *2* units wxCoord, then space 4 units, then the
1189 pattern of *3* units black, 4 units space will be repeated.
1192 static const char *dotted
= "[2 5] 2";
1193 static const char *short_dashed
= "[4 4] 2";
1194 static const char *wxCoord_dashed
= "[4 8] 2";
1195 static const char *dotted_dashed
= "[6 6 2 6] 4";
1199 switch (m_pen
.GetStyle())
1201 case wxDOT
: psdash
= dotted
; break;
1202 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1203 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1204 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1208 int nDashes
= m_pen
.GetDashes (&dashes
);
1210 for (int i
= 0; i
< nDashes
; ++i
)
1212 buffer
.Printf( "%d ", dashes
[i
] );
1215 PsPrint ("] 0 setdash\n");
1221 default: psdash
= "[] 0"; break;
1224 if ( psdash
&& (oldStyle
!= m_pen
.GetStyle()) )
1227 PsPrint( " setdash\n" );
1231 unsigned char red
= m_pen
.GetColour().Red();
1232 unsigned char blue
= m_pen
.GetColour().Blue();
1233 unsigned char green
= m_pen
.GetColour().Green();
1237 // Anything not white is black
1238 if (! (red
== (unsigned char) 255 &&
1239 blue
== (unsigned char) 255 &&
1240 green
== (unsigned char) 255) )
1242 red
= (unsigned char) 0;
1243 green
= (unsigned char) 0;
1244 blue
= (unsigned char) 0;
1249 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1251 double redPS
= (double)(red
) / 255.0;
1252 double bluePS
= (double)(blue
) / 255.0;
1253 double greenPS
= (double)(green
) / 255.0;
1256 buffer
.Printf( "%f %f %f setrgbcolor\n", redPS
, greenPS
, bluePS
);
1257 buffer
.Replace( ",", "." );
1261 m_currentBlue
= blue
;
1262 m_currentGreen
= green
;
1266 void wxPostScriptImplDC::SetBrush( const wxBrush
& brush
)
1268 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1270 if (!brush
.Ok()) return;
1275 unsigned char red
= m_brush
.GetColour().Red();
1276 unsigned char blue
= m_brush
.GetColour().Blue();
1277 unsigned char green
= m_brush
.GetColour().Green();
1281 // Anything not white is black
1282 if (! (red
== (unsigned char) 255 &&
1283 blue
== (unsigned char) 255 &&
1284 green
== (unsigned char) 255) )
1286 red
= (unsigned char) 0;
1287 green
= (unsigned char) 0;
1288 blue
= (unsigned char) 0;
1293 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1295 double redPS
= (double)(red
) / 255.0;
1296 double bluePS
= (double)(blue
) / 255.0;
1297 double greenPS
= (double)(green
) / 255.0;
1300 buffer
.Printf( "%f %f %f setrgbcolor\n", redPS
, greenPS
, bluePS
);
1301 buffer
.Replace( ",", "." );
1305 m_currentBlue
= blue
;
1306 m_currentGreen
= green
;
1310 void wxPostScriptImplDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1312 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1314 const wxWX2MBbuf textbuf
= text
.mb_str();
1318 if (m_textForegroundColour
.Ok())
1320 unsigned char red
= m_textForegroundColour
.Red();
1321 unsigned char blue
= m_textForegroundColour
.Blue();
1322 unsigned char green
= m_textForegroundColour
.Green();
1326 // Anything not white is black
1327 if (! (red
== (unsigned char) 255 &&
1328 blue
== (unsigned char) 255 &&
1329 green
== (unsigned char) 255))
1331 red
= (unsigned char) 0;
1332 green
= (unsigned char) 0;
1333 blue
= (unsigned char) 0;
1337 // maybe setgray here ?
1338 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1340 double redPS
= (double)(red
) / 255.0;
1341 double bluePS
= (double)(blue
) / 255.0;
1342 double greenPS
= (double)(green
) / 255.0;
1345 buffer
.Printf( "%f %f %f setrgbcolor\n", redPS
, greenPS
, bluePS
);
1346 buffer
.Replace( ",", "." );
1350 m_currentBlue
= blue
;
1351 m_currentGreen
= green
;
1355 wxCoord text_w
, text_h
, text_descent
;
1357 GetOwner()->GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1359 int size
= m_font
.GetPointSize();
1361 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1362 // commented by V. Slavik and replaced by accurate version
1363 // - note that there is still rounding error in text_descent!
1364 wxCoord by
= y
+ size
- text_descent
; // baseline
1367 buffer
.Printf( "%f %f moveto\n", XLOG2DEV(x
), YLOG2DEV(by
) );
1368 buffer
.Replace( ",", "." );
1372 size_t len
= strlen(textbuf
);
1374 for (i
= 0; i
< len
; i
++)
1376 int c
= (unsigned char) textbuf
[i
];
1377 if (c
== ')' || c
== '(' || c
== '\\')
1379 /* Cope with special characters */
1381 PsPrint( (char) c
);
1383 else if ( c
>= 128 )
1385 /* Cope with character codes > 127 */
1386 buffer
.Printf( "\\%o", c
);
1391 PsPrint( (char) c
);
1395 PsPrint( ") show\n" );
1397 if (m_font
.GetUnderlined())
1399 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1401 buffer
.Printf( "gsave\n"
1407 XLOG2DEV(x
), YLOG2DEV(uy
),
1408 m_underlineThickness
,
1409 XLOG2DEV(x
+ text_w
), YLOG2DEV(uy
) );
1410 buffer
.Replace( ",", "." );
1414 CalcBoundingBox( x
, y
);
1415 CalcBoundingBox( x
+ size
* text
.length() * 2/3 , y
);
1418 void wxPostScriptImplDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1420 if ( wxIsNullDouble(angle
) )
1422 DoDrawText(text
, x
, y
);
1426 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1430 if (m_textForegroundColour
.Ok())
1432 unsigned char red
= m_textForegroundColour
.Red();
1433 unsigned char blue
= m_textForegroundColour
.Blue();
1434 unsigned char green
= m_textForegroundColour
.Green();
1438 // Anything not white is black
1439 if (! (red
== (unsigned char) 255 &&
1440 blue
== (unsigned char) 255 &&
1441 green
== (unsigned char) 255))
1443 red
= (unsigned char) 0;
1444 green
= (unsigned char) 0;
1445 blue
= (unsigned char) 0;
1449 // maybe setgray here ?
1450 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1452 double redPS
= (double)(red
) / 255.0;
1453 double bluePS
= (double)(blue
) / 255.0;
1454 double greenPS
= (double)(green
) / 255.0;
1457 buffer
.Printf( "%f %f %f setrgbcolor\n", redPS
, greenPS
, bluePS
);
1458 buffer
.Replace( ",", "." );
1462 m_currentBlue
= blue
;
1463 m_currentGreen
= green
;
1467 int size
= m_font
.GetPointSize();
1470 buffer
.Printf( "%f %f moveto\n", XLOG2DEV(x
), YLOG2DEV(y
));
1471 buffer
.Replace( ",", "." );
1474 buffer
.Printf( "%f rotate\n", angle
);
1475 buffer
.Replace( ",", "." );
1479 const wxWX2MBbuf textbuf
= text
.mb_str();
1480 size_t len
= strlen(textbuf
);
1482 for (i
= 0; i
< len
; i
++)
1484 int c
= (unsigned char) textbuf
[i
];
1485 if (c
== ')' || c
== '(' || c
== '\\')
1487 /* Cope with special characters */
1489 PsPrint( (char) c
);
1491 else if ( c
>= 128 )
1493 /* Cope with character codes > 127 */
1494 buffer
.Printf( "\\%o", c
);
1499 PsPrint( (char) c
);
1503 PsPrint( ") show\n" );
1505 buffer
.Printf( "%f rotate\n", -angle
);
1506 buffer
.Replace( ",", "." );
1509 if (m_font
.GetUnderlined())
1511 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1513 GetOwner()->GetTextExtent(text
, &w
, &h
);
1522 XLOG2DEV(x
), YLOG2DEV(uy
),
1523 m_underlineThickness
,
1524 XLOG2DEV(x
+ w
), YLOG2DEV(uy
) );
1525 buffer
.Replace( ",", "." );
1529 CalcBoundingBox( x
, y
);
1530 CalcBoundingBox( x
+ size
* text
.length() * 2/3 , y
);
1533 void wxPostScriptImplDC::SetBackground (const wxBrush
& brush
)
1535 m_backgroundBrush
= brush
;
1538 void wxPostScriptImplDC::SetLogicalFunction (int WXUNUSED(function
))
1540 wxFAIL_MSG( wxT("wxPostScriptImplDC::SetLogicalFunction not implemented.") );
1544 void wxPostScriptImplDC::DoDrawSpline( const wxPointList
*points
)
1546 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1550 // a and b are not used
1552 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1555 wxPointList::compatibility_iterator node
= points
->GetFirst();
1556 p
= node
->GetData();
1560 node
= node
->GetNext();
1561 p
= node
->GetData();
1568 (double)(x1
+ c
) / 2;
1573 (double)(y1
+ d
) / 2;
1576 buffer
.Printf( "newpath\n"
1579 XLOG2DEV(wxRound(x1
)), YLOG2DEV(wxRound(y1
)),
1580 XLOG2DEV(wxRound(x3
)), YLOG2DEV(wxRound(y3
)) );
1581 buffer
.Replace( ",", "." );
1584 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1585 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1587 node
= node
->GetNext();
1590 q
= node
->GetData();
1598 x3
= (double)(x2
+ c
) / 2;
1599 y3
= (double)(y2
+ d
) / 2;
1601 buffer
.Printf( "%f %f %f %f %f %f DrawSplineSection\n",
1602 XLOG2DEV(wxRound(x1
)), YLOG2DEV(wxRound(y1
)),
1603 XLOG2DEV(wxRound(x2
)), YLOG2DEV(wxRound(y2
)),
1604 XLOG2DEV(wxRound(x3
)), YLOG2DEV(wxRound(y3
)) );
1605 buffer
.Replace( ",", "." );
1608 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1609 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1611 node
= node
->GetNext();
1615 At this point, (x2,y2) and (c,d) are the position of the
1616 next-to-last and last point respectively, in the point list
1619 buffer
.Printf( "%f %f lineto\nstroke\n", XLOG2DEV(wxRound(c
)), YLOG2DEV(wxRound(d
)) );
1620 buffer
.Replace( ",", "." );
1623 #endif // wxUSE_SPLINES
1625 wxCoord
wxPostScriptImplDC::GetCharWidth() const
1627 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1628 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1631 void wxPostScriptImplDC::SetPrintData(const wxPrintData
& data
)
1635 wxPaperSize id
= m_printData
.GetPaperId();
1636 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1637 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1642 w
= paper
->GetSizeDeviceUnits().x
;
1643 h
= paper
->GetSizeDeviceUnits().y
;
1646 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1647 m_pageHeight
= w
* PS2DEV
;
1649 m_pageHeight
= h
* PS2DEV
;
1654 void wxPostScriptImplDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1656 wxDCBase::SetAxisOrientation(xLeftRight
,yBottomUp
);
1659 void wxPostScriptImplDC::SetMapMode(int mode
)
1661 wxDCBase::SetMapMode(mode
);
1664 void wxPostScriptImplDC::SetUserScale(double x
, double y
)
1666 wxDCBase::SetUserScale(x
,y
);
1669 void wxPostScriptImplDC::SetLogicalScale(double x
, double y
)
1671 wxDCBase::SetLogicalScale(x
,y
);
1674 void wxPostScriptImplDC::SetLogicalOrigin(wxCoord x
, wxCoord y
)
1676 wxDCBase::SetLogicalOrigin(x
,y
);
1679 void wxPostScriptImplDC::SetDeviceOrigin(wxCoord x
, wxCoord y
)
1681 wxDCBase::SetDeviceOrigin(x
,y
);
1685 void wxPostScriptImplDC::ComputeScaleAndOrigin()
1687 const wxRealPoint
origScale(m_scaleX
, m_scaleY
);
1690 wxImplDC::ComputeScaleAndOrigin();
1692 wxDC::ComputeScaleAndOrigin();
1695 // If scale has changed call SetPen to recalulate the line width
1696 // and SetFont to recalculate font size
1697 if ( wxRealPoint(m_scaleX
, m_scaleY
) != origScale
&& m_pen
.IsOk() )
1704 void wxPostScriptImplDC::DoGetSize(int* width
, int* height
) const
1706 wxPaperSize id
= m_printData
.GetPaperId();
1708 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1710 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1716 w
= paper
->GetSizeDeviceUnits().x
;
1717 h
= paper
->GetSizeDeviceUnits().y
;
1720 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1728 *width
= wxRound( w
* PS2DEV
);
1731 *height
= wxRound( h
* PS2DEV
);
1734 void wxPostScriptImplDC::DoGetSizeMM(int *width
, int *height
) const
1736 wxPaperSize id
= m_printData
.GetPaperId();
1738 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1740 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1746 w
= paper
->GetWidth() / 10;
1747 h
= paper
->GetHeight() / 10;
1750 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1757 if (width
) *width
= w
;
1758 if (height
) *height
= h
;
1761 // Resolution in pixels per logical inch
1762 wxSize
wxPostScriptImplDC::GetPPI(void) const
1764 return wxSize( DPI
, DPI
);
1768 bool wxPostScriptImplDC::StartDoc( const wxString
& message
)
1770 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
1772 if (m_printData
.GetPrintMode() != wxPRINT_MODE_STREAM
)
1774 if (m_printData
.GetFilename() == wxEmptyString
)
1776 wxString filename
= wxGetTempFileName( wxT("ps") );
1777 m_printData
.SetFilename(filename
);
1780 m_pstream
= wxFopen( m_printData
.GetFilename(), wxT("w+") );
1784 wxLogError( _("Cannot open file for PostScript printing!"));
1795 PsPrint( "%!PS-Adobe-2.0\n" );
1797 buffer
.Printf( "%%%%Title: %s\n", m_title
);
1799 PsPrint( "%%Creator: wxWidgets PostScript renderer\n" );
1801 buffer
.Printf( "%%%%CreationDate: %s\n", wxNow() );
1804 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1805 PsPrint( "%%Orientation: Landscape\n" );
1807 PsPrint( "%%Orientation: Portrait\n" );
1809 const wxChar
*paper
;
1810 switch (m_printData
.GetPaperId())
1812 case wxPAPER_LETTER
: paper
= wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches
1813 case wxPAPER_LEGAL
: paper
= wxT("Legal"); break; // Legal, 8 1/2 by 14 inches
1814 case wxPAPER_A4
: paper
= wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters
1815 case wxPAPER_TABLOID
: paper
= wxT("Tabloid"); break; // Tabloid, 11 by 17 inches
1816 case wxPAPER_LEDGER
: paper
= wxT("Ledger"); break; // Ledger, 17 by 11 inches
1817 case wxPAPER_STATEMENT
: paper
= wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches
1818 case wxPAPER_EXECUTIVE
: paper
= wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches
1819 case wxPAPER_A3
: paper
= wxT("A3"); break; // A3 sheet, 297 by 420 millimeters
1820 case wxPAPER_A5
: paper
= wxT("A5"); break; // A5 sheet, 148 by 210 millimeters
1821 case wxPAPER_B4
: paper
= wxT("B4"); break; // B4 sheet, 250 by 354 millimeters
1822 case wxPAPER_B5
: paper
= wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper
1823 case wxPAPER_FOLIO
: paper
= wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper
1824 case wxPAPER_QUARTO
: paper
= wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper
1825 case wxPAPER_10X14
: paper
= wxT("10x14"); break; // 10-by-14-inch sheet
1826 default: paper
= wxT("A4");
1829 buffer
.Printf( "%%%%DocumentPaperSizes: %s\n", paper
);
1832 PsPrint( "%%EndComments\n\n" );
1834 PsPrint( "%%BeginProlog\n" );
1835 PsPrint( wxPostScriptHeaderConicTo
);
1836 PsPrint( wxPostScriptHeaderEllipse
);
1837 PsPrint( wxPostScriptHeaderEllipticArc
);
1838 PsPrint( wxPostScriptHeaderColourImage
);
1839 PsPrint( wxPostScriptHeaderReencodeISO1
);
1840 PsPrint( wxPostScriptHeaderReencodeISO2
);
1841 if (wxPostScriptHeaderSpline
)
1842 PsPrint( wxPostScriptHeaderSpline
);
1843 PsPrint( "%%EndProlog\n" );
1845 SetBrush( *wxBLACK_BRUSH
);
1846 SetPen( *wxBLACK_PEN
);
1847 SetBackground( *wxWHITE_BRUSH
);
1848 SetTextForeground( *wxBLACK
);
1850 // set origin according to paper size
1851 SetDeviceOrigin( 0,0 );
1857 void wxPostScriptImplDC::EndDoc ()
1859 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1864 PsPrint( "grestore\n" );
1868 fclose( m_pstream
);
1869 m_pstream
= (FILE *) NULL
;
1873 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1874 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1875 double wx_printer_scale_x
, wx_printer_scale_y
;
1877 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1878 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1880 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1881 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1883 // Compute the bounding box. Note that it is in the default user
1884 // coordinate system, thus we have to convert the values.
1885 wxCoord minX
= (wxCoord
) XLOG2DEV(m_minX
);
1886 wxCoord minY
= (wxCoord
) YLOG2DEV(m_minY
);
1887 wxCoord maxX
= (wxCoord
) XLOG2DEV(m_maxX
);
1888 wxCoord maxY
= (wxCoord
) YLOG2DEV(m_maxY
);
1890 // LOG2DEV may have changed the minimum to maximum vice versa
1891 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1892 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1894 // account for used scaling (boundingbox is before scaling in ps-file)
1895 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1896 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1898 wxCoord llx
, lly
, urx
, ury
;
1899 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1900 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1901 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1902 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1903 // (end of bounding box computation)
1906 // If we're landscape, our sense of "x" and "y" is reversed.
1907 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1910 tmp
= llx
; llx
= lly
; lly
= tmp
;
1911 tmp
= urx
; urx
= ury
; ury
= tmp
;
1913 // We need either the two lines that follow, or we need to subtract
1914 // min_x from real_translate_y, which is commented out below.
1915 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1916 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1919 // The Adobe specifications call for integers; we round as to make
1920 // the bounding larger.
1921 PsPrintf( wxT("%%%%BoundingBox: %d %d %d %d\n"),
1922 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1923 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1925 // To check the correctness of the bounding box, postscript commands
1926 // to draw a box corresponding to the bounding box are generated below.
1927 // But since we typically don't want to print such a box, the postscript
1928 // commands are generated within comments. These lines appear before any
1929 // adjustment of scale, rotation, or translation, and hence are in the
1930 // default user coordinates.
1931 PsPrint( "% newpath\n" );
1932 PsPrintf( wxT("%% %d %d moveto\n"), llx
, lly
);
1933 PsPrintf( wxT("%% %d %d lineto\n"), urx
, lly
);
1934 PsPrintf( wxT("%% %d %d lineto\n"), urx
, ury
);
1935 PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx
, ury
);
1939 wxPostScriptPrintNativeData
*data
=
1940 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1942 if (m_ok
&& (m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
1945 command
+= data
->GetPrinterCommand();
1946 command
+= wxT(" ");
1947 command
+= data
->GetPrinterOptions();
1948 command
+= wxT(" ");
1949 command
+= m_printData
.GetFilename();
1951 wxExecute( command
, true );
1952 wxRemoveFile( m_printData
.GetFilename() );
1957 void wxPostScriptImplDC::StartPage()
1959 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1962 buffer
.Printf( wxT("%%%%Page: %d\n"), m_pageNumber
++ );
1966 wxPostScriptPrintNativeData
*data
=
1967 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1969 wxCoord translate_x
= (wxCoord
)data
->GetPrinterTranslateX();
1970 wxCoord translate_y
= (wxCoord
)data
->GetPrinterTranslateY();
1972 buffer
.Printf( "%d %d translate\n", translate_x
, translate_y
);
1975 double scale_x
= data
->GetPrinterScaleX();
1976 double scale_y
= data
->GetPrinterScaleY();
1978 buffer
.Printf( "%f %f scale\n", scale_x
, scale_y
);
1979 buffer
.Replace( ",", "." );
1984 // Each page starts with an "initgraphics" which resets the
1985 // transformation and so we need to rotate the page for
1986 // landscape printing)
1988 // I copied this one from a PostScript tutorial, but to no avail. RR.
1989 // PsPrint( "90 rotate llx neg ury nef translate\n" );
1991 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1992 PsPrint( "90 rotate\n" );
1995 void wxPostScriptImplDC::EndPage ()
1997 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1999 PsPrint( "showpage\n" );
2002 bool wxPostScriptImplDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
2003 wxCoord fwidth
, wxCoord fheight
,
2005 wxCoord xsrc
, wxCoord ysrc
,
2006 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
2008 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
2010 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
2012 // blit into a bitmap
2013 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
2015 memDC
.SelectObject(bitmap
);
2016 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
2017 memDC
.SelectObject(wxNullBitmap
);
2019 //draw bitmap. scaling and positioning is done there
2020 GetOwner()->DrawBitmap( bitmap
, xdest
, ydest
);
2025 wxCoord
wxPostScriptImplDC::GetCharHeight() const
2028 return m_font
.GetPointSize();
2033 void wxPostScriptImplDC::PsPrint( const wxString
& str
)
2035 const wxCharBuffer
psdata(str
.utf8_str());
2037 wxPostScriptPrintNativeData
*data
=
2038 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2040 switch (m_printData
.GetPrintMode())
2043 // append to output stream
2044 case wxPRINT_MODE_STREAM
:
2046 wxOutputStream
* outputstream
= data
->GetOutputStream();
2047 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2048 outputstream
->Write( psdata
, strlen( psdata
) );
2051 #endif // wxUSE_STREAMS
2053 // save data into file
2055 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2056 fwrite( psdata
, 1, strlen( psdata
), m_pstream
);
2060 void wxPostScriptImplDC::DoGetTextExtent(const wxString
& string
,
2061 wxCoord
*x
, wxCoord
*y
,
2062 wxCoord
*descent
, wxCoord
*externalLeading
,
2063 const wxFont
*theFont
) const
2065 const wxFont
*fontToUse
= theFont
;
2067 if (!fontToUse
) fontToUse
= &m_font
;
2069 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
2075 if (descent
) (*descent
) = 0;
2076 if (externalLeading
) (*externalLeading
) = 0;
2082 const wxWX2MBbuf strbuf
= string
.mb_str();
2084 // conversion failed (non e.g. ISO characters)
2088 #if !wxUSE_AFM_FOR_POSTSCRIPT
2089 /* Provide a VERY rough estimate (avoid using it).
2090 * Produces accurate results for mono-spaced font
2091 * such as Courier (aka wxMODERN) */
2096 height
= fontToUse
->GetPointSize();
2099 *x
= strlen (strbuf
) * height
* 72 / 120;
2101 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
2102 if (descent
) *descent
= 0;
2103 if (externalLeading
) *externalLeading
= 0;
2106 /* method for calculating string widths in postscript:
2107 / read in the AFM (adobe font metrics) file for the
2108 / actual font, parse it and extract the character widths
2109 / and also the descender. this may be improved, but for now
2110 / it works well. the AFM file is only read in if the
2111 / font is changed. this may be chached in the future.
2112 / calls to GetTextExtent with the font unchanged are rather
2115 / for each font and style used there is an AFM file necessary.
2116 / currently i have only files for the roman font family.
2117 / I try to get files for the other ones!
2119 / CAVE: the size of the string is currently always calculated
2120 / in 'points' (1/72 of an inch). this should later on be
2121 / changed to depend on the mapping mode.
2122 / CAVE: the path to the AFM files must be set before calling this
2123 / fun3B3Bction. this is usually done by a call like the following:
2124 / wxSetAFMPath("d:\\wxw161\\afm\\");
2128 / wxPostScriptDC dc(NULL, true);
2130 / wxSetAFMPath("d:\\wxw161\\afm\\");
2131 / dc.StartDoc("Test");
2134 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
2135 / dc.GetTextExtent("Hallo",&w,&h);
2140 / by steve (stefan.hammes@urz.uni-heidelberg.de)
2142 / updated: 14.05.95 */
2144 /* these static vars are for storing the state between calls */
2145 static int lastFamily
= INT_MIN
;
2146 static int lastSize
= INT_MIN
;
2147 static int lastStyle
= INT_MIN
;
2148 static int lastWeight
= INT_MIN
;
2149 static int lastDescender
= INT_MIN
;
2150 static int lastWidths
[256]; /* widths of the characters */
2152 double UnderlinePosition
= 0.0;
2153 double UnderlineThickness
= 0.0;
2155 // Get actual parameters
2156 int Family
= fontToUse
->GetFamily();
2157 int Size
= fontToUse
->GetPointSize();
2158 int Style
= fontToUse
->GetStyle();
2159 int Weight
= fontToUse
->GetWeight();
2161 // If we have another font, read the font-metrics
2162 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
2164 // Store actual values
2165 lastFamily
= Family
;
2168 lastWeight
= Weight
;
2177 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBoO.afm");
2178 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBo.afm");
2179 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("CourO.afm");
2180 else name
= wxT("Cour.afm");
2185 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBoO.afm");
2186 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBo.afm");
2187 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("TimesO.afm");
2188 else name
= wxT("TimesRo.afm");
2193 name
= wxT("Zapf.afm");
2199 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBoO.afm");
2200 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBo.afm");
2201 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("HelvO.afm");
2202 else name
= wxT("Helv.afm");
2207 FILE *afmFile
= NULL
;
2209 // Get the directory of the AFM files
2212 // VZ: I don't know if the cast always works under Unix but it clearly
2213 // never does under Windows where the pointer is
2214 // wxWindowsPrintNativeData and so calling GetFontMetricPath() on
2217 wxPostScriptPrintNativeData
*data
=
2218 wxDynamicCast(m_printData
.GetNativeData(), wxPostScriptPrintNativeData
);
2220 if (data
&& !data
->GetFontMetricPath().empty())
2222 afmName
= data
->GetFontMetricPath();
2223 afmName
<< wxFILE_SEP_PATH
<< name
;
2227 if ( !afmName
.empty() )
2228 afmFile
= wxFopen(afmName
, wxT("r"));
2232 #if defined(__UNIX__) && !defined(__VMS__)
2233 afmName
= wxGetDataDir();
2235 afmName
= wxStandardPaths::Get().GetDataDir();
2236 #endif // __UNIX__/!__UNIX__
2238 afmName
<< wxFILE_SEP_PATH
2239 #if defined(__LINUX__) || defined(__FREEBSD__)
2240 << wxT("gs_afm") << wxFILE_SEP_PATH
2242 << wxT("afm") << wxFILE_SEP_PATH
2245 afmFile
= wxFopen(afmName
,wxT("r"));
2248 /* 2. open and process the file
2249 / a short explanation of the AFM format:
2250 / we have for each character a line, which gives its size
2253 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2255 / that means, we have a character with ascii code 63, and width
2256 / (444/1000 * fontSize) points.
2257 / the other data is ignored for now!
2259 / when the font has changed, we read in the right AFM file and store the
2260 / character widths in an array, which is processed below (see point 3.). */
2263 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2264 wxLogDebug( wxT(" using approximate values"));
2265 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2266 lastDescender
= -150; /* dito. */
2270 /* init the widths array */
2271 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2272 /* some variables for holding parts of a line */
2273 char cString
[10], semiString
[10], WXString
[10];
2274 char descString
[20];
2275 char upString
[30], utString
[30];
2279 /* read in the file and parse it */
2280 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2282 /* A.) check for descender definition */
2283 if (strncmp(line
,"Descender",9)==0)
2285 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2286 (strcmp(descString
,"Descender")!=0))
2288 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2291 /* JC 1.) check for UnderlinePosition */
2292 else if(strncmp(line
,"UnderlinePosition",17)==0)
2294 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2295 (strcmp(upString
,"UnderlinePosition")!=0))
2297 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2300 /* JC 2.) check for UnderlineThickness */
2301 else if(strncmp(line
,"UnderlineThickness",18)==0)
2303 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2304 (strcmp(utString
,"UnderlineThickness")!=0))
2306 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2309 /* JC 3.) check for EncodingScheme */
2310 else if(strncmp(line
,"EncodingScheme",14)==0)
2312 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2313 (strcmp(utString
,"EncodingScheme")!=0))
2315 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2317 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2319 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2320 afmName
.c_str(),line
, encString
);
2323 /* B.) check for char-width */
2324 else if(strncmp(line
,"C ",2)==0)
2326 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2328 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2330 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2332 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2334 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2335 if (ascii
>=0 && ascii
<256)
2337 lastWidths
[ascii
] = cWidth
; /* store width */
2341 /* MATTHEW: this happens a lot; don't print an error */
2342 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2345 /* C.) ignore other entries. */
2349 /* hack to compute correct values for german 'Umlaute'
2350 / the correct way would be to map the character names
2351 / like 'adieresis' to corresp. positions of ISOEnc and read
2352 / these values from AFM files, too. Maybe later ... */
2354 // NB: casts to int are needed to suppress gcc 3.3 warnings
2355 lastWidths
[196] = lastWidths
[(int)'A']; // Ä
2356 lastWidths
[228] = lastWidths
[(int)'a']; // ä
2357 lastWidths
[214] = lastWidths
[(int)'O']; // Ö
2358 lastWidths
[246] = lastWidths
[(int)'o']; // ö
2359 lastWidths
[220] = lastWidths
[(int)'U']; // Ü
2360 lastWidths
[252] = lastWidths
[(int)'u']; // ü
2361 lastWidths
[223] = lastWidths
[(int)251]; // ß
2363 /* JC: calculate UnderlineThickness/UnderlinePosition */
2365 // VS: dirty, but is there any better solution?
2367 pt
= (double*) &m_underlinePosition
;
2368 *pt
= YLOG2DEVREL((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2369 pt
= (double*) &m_underlineThickness
;
2370 *pt
= YLOG2DEVREL((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2375 /* 3. now the font metrics are read in, calc size this
2376 / is done by adding the widths of the characters in the
2377 / string. they are given in 1/1000 of the size! */
2380 wxCoord height
=Size
; /* by default */
2382 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2384 if(lastWidths
[*p
]== INT_MIN
)
2386 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2387 sum
+= lastWidths
[(unsigned char)' ']; /* assume space */
2391 sum
+= lastWidths
[*p
];
2395 double widthSum
= sum
;
2397 widthSum
/= 1000.0F
;
2399 /* add descender to height (it is usually a negative value) */
2400 //if (lastDescender != INT_MIN)
2402 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2404 // - commented by V. Slavik - height already contains descender in it
2405 // (judging from few experiments)
2407 /* return size values */
2409 *x
= (wxCoord
)widthSum
;
2413 /* return other parameters */
2416 if(lastDescender
!=INT_MIN
)
2418 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2426 /* currently no idea how to calculate this! */
2427 if (externalLeading
) *externalLeading
= 0;
2433 #endif // wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT