1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dcpsg.h"
16 #include "wx/wxprec.h"
25 #if wxUSE_PRINTING_ARCHITECTURE
31 #include "wx/window.h"
32 #include "wx/dcmemory.h"
35 #include "wx/filedlg.h"
37 #include "wx/msgdlg.h"
40 #include "wx/generic/dcpsg.h"
41 #include "wx/printdlg.h"
42 #include "wx/button.h"
43 #include "wx/stattext.h"
44 #include "wx/radiobox.h"
45 #include "wx/textctrl.h"
46 #include "wx/prntbase.h"
48 #include "wx/filefn.h"
72 //-----------------------------------------------------------------------------
73 // start and end of document/page
74 //-----------------------------------------------------------------------------
76 static const char *wxPostScriptHeaderConicTo
= "\
80 /conic_cntrl_y exch def\n\
81 /conic_cntrl_x exch def\n\
85 /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\
86 /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\
87 /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\
88 /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\
89 p1_x p1_y p2_x p2_y to_x to_y curveto\n\
93 static const char *wxPostScriptHeaderEllipse
= "\
94 /ellipsedict 8 dict def\n\
95 ellipsedict /mtrx matrix put\n\
99 /startangle exch def\n\
104 /savematrix mtrx currentmatrix def\n\
107 0 0 1 startangle endangle arc\n\
108 savematrix setmatrix\n\
113 static const char *wxPostScriptHeaderEllipticArc
= "\
114 /ellipticarcdict 8 dict def\n\
115 ellipticarcdict /mtrx matrix put\n\
117 { ellipticarcdict begin\n\
119 /endangle exch def\n\
120 /startangle exch def\n\
125 /savematrix mtrx currentmatrix def\n\
128 do_fill { 0 0 moveto } if\n\
129 0 0 1 startangle endangle arc\n\
130 savematrix setmatrix\n\
131 do_fill { fill }{ stroke } ifelse\n\
135 static const char *wxPostScriptHeaderSpline
= "\
136 /DrawSplineSection {\n\
143 /xa x1 x2 x1 sub 0.666667 mul add def\n\
144 /ya y1 y2 y1 sub 0.666667 mul add def\n\
145 /xb x3 x2 x3 sub 0.666667 mul add def\n\
146 /yb y3 y2 y3 sub 0.666667 mul add def\n\
148 xa ya xb yb x3 y3 curveto\n\
152 static const char *wxPostScriptHeaderColourImage
= "\
153 %% define 'colorimage' if it isn't defined\n\
154 %% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
156 /colorimage where %% do we know about 'colorimage'?\n\
157 { pop } %% yes: pop off the 'dict' returned\n\
158 { %% no: define one\n\
159 /colortogray { %% define an RGB->I function\n\
160 /rgbdata exch store %% call input 'rgbdata'\n\
161 rgbdata length 3 idiv\n\
162 /npixls exch store\n\
164 0 1 npixls 1 sub {\n\
166 rgbdata rgbindx get 20 mul %% Red\n\
167 rgbdata rgbindx 1 add get 32 mul %% Green\n\
168 rgbdata rgbindx 2 add get 12 mul %% Blue\n\
169 add add 64 idiv %% I = .5G + .31R + .18B\n\
171 /rgbindx rgbindx 3 add store\n\
173 grays 0 npixls getinterval\n\
176 %% Utility procedure for colorimage operator.\n\
177 %% This procedure takes two procedures off the\n\
178 %% stack and merges them into a single procedure.\n\
180 /mergeprocs { %% def\n\
199 /colorimage { %% def\n\
200 pop pop %% remove 'false 3' operands\n\
201 {colortogray} mergeprocs\n\
204 } ifelse %% end of 'false' case\n\
208 static char wxPostScriptHeaderReencodeISO1
[] =
210 "dup dup findfont dup length dict begin\n"
211 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
212 "/Encoding ISOLatin1Encoding def\n"
213 "currentdict end definefont\n"
215 "/ISOLatin1Encoding [\n"
216 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
217 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
218 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
219 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
220 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
221 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
222 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
223 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
224 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
225 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
226 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
227 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
228 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
229 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
230 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
232 static char wxPostScriptHeaderReencodeISO2
[] =
233 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
234 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
235 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
236 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
237 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
238 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
239 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
240 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
241 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
242 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
243 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
244 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
245 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
246 "/yacute/thorn/ydieresis\n"
250 //-------------------------------------------------------------------------------
252 //-------------------------------------------------------------------------------
254 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
256 float wxPostScriptDC::ms_PSScaleFactor
= 10.0;
258 void wxPostScriptDC::SetResolution(int ppi
)
260 ms_PSScaleFactor
= (float)ppi
/ 72.0;
263 int wxPostScriptDC::GetResolution()
265 return (int)(ms_PSScaleFactor
* 72.0);
268 //-------------------------------------------------------------------------------
270 wxPostScriptDC::wxPostScriptDC ()
272 m_pstream
= (FILE*) NULL
;
282 m_underlinePosition
= 0.0;
283 m_underlineThickness
= 0.0;
285 m_signX
= 1; // default x-axis left to right
286 m_signY
= -1; // default y-axis bottom up -> top down
289 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
291 m_pstream
= (FILE*) NULL
;
301 m_underlinePosition
= 0.0;
302 m_underlineThickness
= 0.0;
304 m_signX
= 1; // default x-axis left to right
305 m_signY
= -1; // default y-axis bottom up -> top down
307 m_printData
= printData
;
312 wxPostScriptDC::~wxPostScriptDC ()
317 m_pstream
= (FILE*) NULL
;
321 bool wxPostScriptDC::Ok() const
326 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
328 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
330 if (m_clipping
) DestroyClippingRegion();
332 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
341 "closepath clip newpath\n",
342 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
343 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
344 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
345 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
349 void wxPostScriptDC::DestroyClippingRegion()
351 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
356 fprintf( m_pstream
, "grestore\n" );
359 wxDC::DestroyClippingRegion();
362 void wxPostScriptDC::Clear()
364 wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
367 bool wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
369 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
373 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
375 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
379 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
381 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
384 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
386 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
388 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
397 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
398 LogicalToDeviceX(x2
), LogicalToDeviceY (y2
) );
400 CalcBoundingBox( x1
, y1
);
401 CalcBoundingBox( x2
, y2
);
404 #define RAD2DEG 57.29577951308
406 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
408 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
410 wxCoord dx
= x1
- xc
;
411 wxCoord dy
= y1
- yc
;
412 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
413 double alpha1
, alpha2
;
415 if (x1
== x2
&& y1
== y2
)
420 else if (radius
== 0.0)
422 alpha1
= alpha2
= 0.0;
426 alpha1
= (x1
- xc
== 0) ?
427 (y1
- yc
< 0) ? 90.0 : -90.0 :
428 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
429 alpha2
= (x2
- xc
== 0) ?
430 (y2
- yc
< 0) ? 90.0 : -90.0 :
431 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
433 while (alpha1
<= 0) alpha1
+= 360;
434 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
435 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
436 while (alpha2
> 360) alpha2
-= 360;
438 if (m_brush
.GetStyle() != wxTRANSPARENT
)
444 "%d %d %d %d %d %d ellipse\n"
448 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
449 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
451 CalcBoundingBox( xc
-radius
, yc
-radius
);
452 CalcBoundingBox( xc
+radius
, yc
+radius
);
455 if (m_pen
.GetStyle() != wxTRANSPARENT
)
461 "%d %d %d %d %d %d ellipse\n"
465 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
466 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
468 CalcBoundingBox( xc
-radius
, yc
-radius
);
469 CalcBoundingBox( xc
+radius
, yc
+radius
);
473 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
475 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
477 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
478 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
484 DrawEllipse(x
,y
,w
,h
);
488 if (m_brush
.GetStyle () != wxTRANSPARENT
)
494 "%d %d %d %d %d %d true ellipticarc\n",
495 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
497 CalcBoundingBox( x
,y
);
498 CalcBoundingBox( x
+w
, y
+h
);
501 if (m_pen
.GetStyle () != wxTRANSPARENT
)
507 "%d %d %d %d %d %d false ellipticarc\n",
508 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
510 CalcBoundingBox( x
,y
);
511 CalcBoundingBox( x
+w
, y
+h
);
515 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
517 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
519 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
528 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
529 LogicalToDeviceX(x
+1), LogicalToDeviceY(y
) );
531 CalcBoundingBox( x
, y
);
534 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
))
536 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
540 if (m_brush
.GetStyle () != wxTRANSPARENT
)
544 fprintf( m_pstream
, "newpath\n" );
546 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
547 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
549 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
551 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
553 for (int i
= 1; i
< n
; i
++)
555 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
556 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
558 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
560 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
563 fprintf( m_pstream
, "fill\n" );
566 if (m_pen
.GetStyle () != wxTRANSPARENT
)
570 fprintf( m_pstream
, "newpath\n" );
572 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
573 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
575 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
577 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
579 for (int i
= 1; i
< n
; i
++)
581 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
582 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
584 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
586 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
589 fprintf( m_pstream
, "closepath\n" );
590 fprintf( m_pstream
, "stroke\n" );
594 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
596 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
598 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
605 for ( i
=0; i
<n
; i
++ )
607 CalcBoundingBox( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
613 LogicalToDeviceX(points
[0].x
+xoffset
), LogicalToDeviceY(points
[0].y
+yoffset
) );
615 for (i
= 1; i
< n
; i
++)
619 LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
) );
622 fprintf( m_pstream
, "stroke\n" );
625 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
627 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
629 if (m_brush
.GetStyle () != wxTRANSPARENT
)
641 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
642 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
643 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
644 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
646 CalcBoundingBox( x
, y
);
647 CalcBoundingBox( x
+ width
, y
+ height
);
650 if (m_pen
.GetStyle () != wxTRANSPARENT
)
662 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
663 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
664 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
665 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
667 CalcBoundingBox( x
, y
);
668 CalcBoundingBox( x
+ width
, y
+ height
);
672 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
674 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
678 // Now, a negative radius is interpreted to mean
679 // 'the proportion of the smallest X or Y dimension'
680 double smallest
= 0.0;
685 radius
= (-radius
* smallest
);
688 wxCoord rad
= (wxCoord
) radius
;
690 if (m_brush
.GetStyle () != wxTRANSPARENT
)
694 /* Draw rectangle anticlockwise */
697 "%d %d %d 90 180 arc\n"
699 "%d %d %d 180 270 arc\n"
701 "%d %d %d 270 0 arc\n"
703 "%d %d %d 0 90 arc\n"
707 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
708 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
709 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
710 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
711 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
712 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
713 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
714 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
716 CalcBoundingBox( x
, y
);
717 CalcBoundingBox( x
+ width
, y
+ height
);
720 if (m_pen
.GetStyle () != wxTRANSPARENT
)
724 /* Draw rectangle anticlockwise */
727 "%d %d %d 90 180 arc\n"
729 "%d %d %d 180 270 arc\n"
731 "%d %d %d 270 0 arc\n"
733 "%d %d %d 0 90 arc\n"
737 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
738 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
739 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
740 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
741 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
742 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
743 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
744 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
746 CalcBoundingBox( x
, y
);
747 CalcBoundingBox( x
+ width
, y
+ height
);
751 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
753 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
755 if (m_brush
.GetStyle () != wxTRANSPARENT
)
761 "%d %d %d %d 0 360 ellipse\n"
763 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
764 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
766 CalcBoundingBox( x
- width
, y
- height
);
767 CalcBoundingBox( x
+ width
, y
+ height
);
770 if (m_pen
.GetStyle () != wxTRANSPARENT
)
776 "%d %d %d %d 0 360 ellipse\n"
778 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
779 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
781 CalcBoundingBox( x
- width
, y
- height
);
782 CalcBoundingBox( x
+ width
, y
+ height
);
786 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
788 DrawBitmap( icon
, x
, y
, TRUE
);
791 /* this has to be char, not wxChar */
792 static char hexArray
[] = "0123456789ABCDEF";
793 static void LocalDecToHex( int dec
, char *buf
)
795 int firstDigit
= (int)(dec
/16.0);
796 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
797 buf
[0] = hexArray
[firstDigit
];
798 buf
[1] = hexArray
[secondDigit
];
802 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
804 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
806 if (!bitmap
.Ok()) return;
808 wxImage image
= bitmap
.ConvertToImage();
810 if (!image
.Ok()) return;
812 wxCoord w
= image
.GetWidth();
813 wxCoord h
= image
.GetHeight();
815 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
816 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
818 wxCoord xx
= LogicalToDeviceX(x
);
819 wxCoord yy
= LogicalToDeviceY(y
+ bitmap
.GetHeight());
822 "/origstate save def\n"
824 "/pix %d string def\n"
825 "/grays %d string def\n"
832 "{currentfile pix readhexstring pop}\n"
833 "false 3 colorimage\n",
834 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
837 for (int j
= 0; j
< h
; j
++)
839 for (int i
= 0; i
< w
; i
++)
842 LocalDecToHex( image
.GetRed(i
,j
), buffer
);
843 fprintf( m_pstream
, buffer
);
844 LocalDecToHex( image
.GetGreen(i
,j
), buffer
);
845 fprintf( m_pstream
, buffer
);
846 LocalDecToHex( image
.GetBlue(i
,j
), buffer
);
847 fprintf( m_pstream
, buffer
);
849 fprintf( m_pstream
, "\n" );
852 fprintf( m_pstream
, "end\n" );
853 fprintf( m_pstream
, "origstate restore\n" );
856 void wxPostScriptDC::SetFont( const wxFont
& font
)
858 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
860 if (!font
.Ok()) return;
865 int Style
= m_font
.GetStyle();
866 int Weight
= m_font
.GetWeight();
869 switch (m_font
.GetFamily())
874 if (Style
== wxITALIC
)
876 if (Weight
== wxBOLD
)
877 name
= "/Courier-BoldOblique";
879 name
= "/Courier-Oblique";
883 if (Weight
== wxBOLD
)
884 name
= "/Courier-Bold";
892 if (Style
== wxITALIC
)
894 if (Weight
== wxBOLD
)
895 name
= "/Times-BoldItalic";
897 name
= "/Times-Italic";
901 if (Weight
== wxBOLD
)
902 name
= "/Times-Bold";
904 name
= "/Times-Roman";
910 name
= "/ZapfChancery-MediumItalic";
918 if (Style
== wxITALIC
)
920 if (Weight
== wxBOLD
)
921 name
= "/Helvetica-BoldOblique";
923 name
= "/Helvetica-Oblique";
927 if (Weight
== wxBOLD
)
928 name
= "/Helvetica-Bold";
936 fprintf( m_pstream
, name
);
937 fprintf( m_pstream
, " reencodeISO def\n" );
938 fprintf( m_pstream
, name
);
939 fprintf( m_pstream
, " findfont\n" );
942 sprintf( buffer
, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
943 // this is a hack - we must scale font size (in pts) according to m_scaleY but
944 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
945 // to 1/1000th of pt and then back.
946 for (int i
= 0; i
< 100; i
++)
947 if (buffer
[i
] == ',') buffer
[i
] = '.';
948 fprintf( m_pstream
, buffer
);
952 void wxPostScriptDC::SetPen( const wxPen
& pen
)
954 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
956 if (!pen
.Ok()) return;
958 int oldStyle
= m_pen
.GetStyle();
965 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
967 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
969 for (int i
= 0; i
< 100; i
++)
970 if (buffer
[i
] == ',') buffer
[i
] = '.';
971 fprintf( m_pstream
, buffer
);
975 Line style - WRONG: 2nd arg is OFFSET
977 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
978 operator correctly. You should look-up this in the Red Book: the 2nd parame-
979 ter is not number of values in the array of the first one, but an offset
980 into this description of the pattern. I mean a real *offset* not index
981 into array. I.e. If the command is [3 4] 1 setdash is used, then there
982 will be first black line *2* units wxCoord, then space 4 units, then the
983 pattern of *3* units black, 4 units space will be repeated.
986 static const char *dotted
= "[2 5] 2";
987 static const char *short_dashed
= "[4 4] 2";
988 static const char *wxCoord_dashed
= "[4 8] 2";
989 static const char *dotted_dashed
= "[6 6 2 6] 4";
991 const char *psdash
= (char *) NULL
;
992 switch (m_pen
.GetStyle())
994 case wxDOT
: psdash
= dotted
; break;
995 case wxSHORT_DASH
: psdash
= short_dashed
; break;
996 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
997 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1000 default: psdash
= "[] 0"; break;
1003 if (oldStyle
!= m_pen
.GetStyle())
1005 fprintf( m_pstream
, psdash
);
1006 fprintf( m_pstream
," setdash\n" );
1010 unsigned char red
= m_pen
.GetColour().Red();
1011 unsigned char blue
= m_pen
.GetColour().Blue();
1012 unsigned char green
= m_pen
.GetColour().Green();
1016 // Anything not white is black
1017 if (! (red
== (unsigned char) 255 &&
1018 blue
== (unsigned char) 255 &&
1019 green
== (unsigned char) 255) )
1021 red
= (unsigned char) 0;
1022 green
= (unsigned char) 0;
1023 blue
= (unsigned char) 0;
1028 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1030 double redPS
= (double)(red
) / 255.0;
1031 double bluePS
= (double)(blue
) / 255.0;
1032 double greenPS
= (double)(green
) / 255.0;
1036 "%.8f %.8f %.8f setrgbcolor\n",
1037 redPS
, greenPS
, bluePS
);
1038 for (int i
= 0; i
< 100; i
++)
1039 if (buffer
[i
] == ',') buffer
[i
] = '.';
1040 fprintf( m_pstream
, buffer
);
1043 m_currentBlue
= blue
;
1044 m_currentGreen
= green
;
1048 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1050 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1052 if (!brush
.Ok()) return;
1057 unsigned char red
= m_brush
.GetColour().Red();
1058 unsigned char blue
= m_brush
.GetColour().Blue();
1059 unsigned char green
= m_brush
.GetColour().Green();
1063 // Anything not white is black
1064 if (! (red
== (unsigned char) 255 &&
1065 blue
== (unsigned char) 255 &&
1066 green
== (unsigned char) 255) )
1068 red
= (unsigned char) 0;
1069 green
= (unsigned char) 0;
1070 blue
= (unsigned char) 0;
1075 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1077 double redPS
= (double)(red
) / 255.0;
1078 double bluePS
= (double)(blue
) / 255.0;
1079 double greenPS
= (double)(green
) / 255.0;
1083 "%.8f %.8f %.8f setrgbcolor\n",
1084 redPS
, greenPS
, bluePS
);
1085 for (int i
= 0; i
< 100; i
++)
1086 if (buffer
[i
] == ',') buffer
[i
] = '.';
1087 fprintf( m_pstream
, buffer
);
1090 m_currentBlue
= blue
;
1091 m_currentGreen
= green
;
1097 #define PANGO_ENABLE_ENGINE
1099 #include "wx/gtk/private.h"
1100 #include "wx/fontutil.h"
1101 #include "gtk/gtk.h"
1102 #include <pango/pangoft2.h>
1103 #include <freetype/ftglyph.h>
1105 #ifndef FT_Outline_Decompose
1106 FT_EXPORT( FT_Error
) FT_Outline_Decompose(
1107 FT_Outline
* outline
,
1108 const FT_Outline_Funcs
* interface
,
1112 typedef struct _OutlineInfo OutlineInfo
;
1113 struct _OutlineInfo
{
1117 static int paps_move_to( FT_Vector
* to
,
1120 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1121 fprintf(outline_info
->file
, "%d %d moveto\n",
1127 static int paps_line_to( FT_Vector
* to
,
1130 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1131 fprintf(outline_info
->file
, "%d %d lineto\n",
1137 static int paps_conic_to( FT_Vector
* control
,
1141 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1142 fprintf(outline_info
->file
, "%d %d %d %d conicto\n",
1150 static int paps_cubic_to( FT_Vector
* control1
,
1151 FT_Vector
* control2
,
1155 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1156 fprintf(outline_info
->file
,
1157 "%d %d %d %d %d %d curveto\n",
1167 void draw_bezier_outline(FILE *file
,
1169 FT_UInt glyph_index
,
1175 FT_Int load_flags
= FT_LOAD_NO_BITMAP
;
1178 FT_Outline_Funcs outlinefunc
=
1186 OutlineInfo outline_info
;
1187 outline_info
.file
= file
;
1189 fprintf(file
, "gsave\n");
1190 fprintf(file
, "%d %d translate\n", pos_x
, pos_y
);
1191 // FT2 scales outlines to 26.6 pixels so the code below
1192 // should read 26600 instead of the 60000.
1193 fprintf(file
, "%d 60000 div %d 60000 div scale\n", scale_x
, scale_y
);
1194 fprintf(file
, "0 0 0 setrgbcolor\n");
1196 FT_Load_Glyph(face
, glyph_index
, load_flags
);
1197 FT_Get_Glyph (face
->glyph
, &glyph
);
1198 FT_Outline_Decompose (&(((FT_OutlineGlyph
)glyph
)->outline
),
1199 &outlinefunc
, &outline_info
);
1200 fprintf(file
, "closepath fill grestore \n");
1202 FT_Done_Glyph (glyph
);
1207 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1209 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1212 int dpi
= GetResolution();
1214 PangoContext
*context
= pango_ft2_get_context ( dpi
, dpi
);
1216 pango_context_set_language (context
, pango_language_from_string ("en_US"));
1217 pango_context_set_base_dir (context
, PANGO_DIRECTION_LTR
);
1219 pango_context_set_font_description (context
, m_font
.GetNativeFontInfo()->description
);
1221 PangoLayout
*layout
= pango_layout_new (context
);
1223 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( text
);
1225 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) );
1227 pango_layout_set_text( layout
, (const char*) buffer
, strlen(buffer
) );
1229 PangoRectangle rect
;
1230 pango_layout_get_extents(layout
, NULL
, &rect
);
1232 int xx
= x
* PANGO_SCALE
;
1233 int yy
= y
* PANGO_SCALE
+ (rect
.height
*2/3);
1235 int scale_x
= LogicalToDeviceXRel( 1000 );
1236 int scale_y
= LogicalToDeviceYRel( 1000 );
1238 // Loop over lines in layout
1239 int num_lines
= pango_layout_get_line_count( layout
);
1240 for (int i
= 0; i
< num_lines
; i
++)
1242 PangoLayoutLine
*line
= pango_layout_get_line( layout
, i
);
1244 // Loop over runs in line
1245 GSList
*runs_list
= line
->runs
;
1248 PangoLayoutRun
*run
= (PangoLayoutRun
*) runs_list
->data
;
1249 PangoItem
*item
= run
->item
;
1250 PangoGlyphString
*glyphs
= run
->glyphs
;
1251 PangoAnalysis
*analysis
= &item
->analysis
;
1252 PangoFont
*font
= analysis
->font
;
1253 FT_Face ft_face
= pango_ft2_font_get_face(font
);
1255 int num_glyphs
= glyphs
->num_glyphs
;
1256 for (int glyph_idx
= 0; glyph_idx
< num_glyphs
; glyph_idx
++)
1258 PangoGlyphGeometry geometry
= glyphs
->glyphs
[glyph_idx
].geometry
;
1259 int pos_x
= xx
+ geometry
.x_offset
;
1260 int pos_y
= yy
- geometry
.y_offset
;
1261 xx
+= geometry
.width
;
1263 draw_bezier_outline( m_pstream
, ft_face
,
1264 (FT_UInt
)(glyphs
->glyphs
[glyph_idx
].glyph
),
1265 LogicalToDeviceX( pos_x
/ PANGO_SCALE
),
1266 LogicalToDeviceY( pos_y
/ PANGO_SCALE
),
1269 runs_list
= runs_list
->next
;
1273 g_object_unref( G_OBJECT( layout
) );
1275 wxCoord text_w
, text_h
, text_descent
;
1277 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1279 // VZ: this seems to be unnecessary, so taking it out for now, if it
1280 // doesn't create any problems, remove this comment entirely
1281 //SetFont( m_font );
1283 if (m_textForegroundColour
.Ok())
1285 unsigned char red
= m_textForegroundColour
.Red();
1286 unsigned char blue
= m_textForegroundColour
.Blue();
1287 unsigned char green
= m_textForegroundColour
.Green();
1291 // Anything not white is black
1292 if (! (red
== (unsigned char) 255 &&
1293 blue
== (unsigned char) 255 &&
1294 green
== (unsigned char) 255))
1296 red
= (unsigned char) 0;
1297 green
= (unsigned char) 0;
1298 blue
= (unsigned char) 0;
1302 // maybe setgray here ?
1303 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1305 double redPS
= (double)(red
) / 255.0;
1306 double bluePS
= (double)(blue
) / 255.0;
1307 double greenPS
= (double)(green
) / 255.0;
1311 "%.8f %.8f %.8f setrgbcolor\n",
1312 redPS
, greenPS
, bluePS
);
1313 for (int i
= 0; i
< 100; i
++)
1314 if (buffer
[i
] == ',') buffer
[i
] = '.';
1315 fprintf( m_pstream
, buffer
);
1318 m_currentBlue
= blue
;
1319 m_currentGreen
= green
;
1323 int size
= m_font
.GetPointSize();
1325 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1326 // commented by V. Slavik and replaced by accurate version
1327 // - note that there is still rounding error in text_descent!
1328 wxCoord by
= y
+ size
- text_descent
; // baseline
1329 fprintf( m_pstream
, "%d %d moveto\n", LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1331 fprintf( m_pstream
, "(" );
1332 const wxWX2MBbuf textbuf
= text
.mb_str();
1333 size_t len
= strlen(textbuf
);
1335 for (i
= 0; i
< len
; i
++)
1337 int c
= (unsigned char) textbuf
[i
];
1338 if (c
== ')' || c
== '(' || c
== '\\')
1340 /* Cope with special characters */
1341 fprintf( m_pstream
, "\\" );
1342 fputc(c
, m_pstream
);
1344 else if ( c
>= 128 )
1346 /* Cope with character codes > 127 */
1347 fprintf(m_pstream
, "\\%o", c
);
1351 fputc(c
, m_pstream
);
1355 fprintf( m_pstream
, ") show\n" );
1357 if (m_font
.GetUnderlined())
1359 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1369 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1370 m_underlineThickness
,
1371 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1372 for (i
= 0; i
< 100; i
++)
1373 if (buffer
[i
] == ',') buffer
[i
] = '.';
1374 fprintf( m_pstream
, buffer
);
1377 CalcBoundingBox( x
, y
);
1378 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1382 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1386 DoDrawText(text
, x
, y
);
1390 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1394 if (m_textForegroundColour
.Ok())
1396 unsigned char red
= m_textForegroundColour
.Red();
1397 unsigned char blue
= m_textForegroundColour
.Blue();
1398 unsigned char green
= m_textForegroundColour
.Green();
1402 // Anything not white is black
1403 if (! (red
== (unsigned char) 255 &&
1404 blue
== (unsigned char) 255 &&
1405 green
== (unsigned char) 255))
1407 red
= (unsigned char) 0;
1408 green
= (unsigned char) 0;
1409 blue
= (unsigned char) 0;
1413 // maybe setgray here ?
1414 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1416 double redPS
= (double)(red
) / 255.0;
1417 double bluePS
= (double)(blue
) / 255.0;
1418 double greenPS
= (double)(green
) / 255.0;
1422 "%.8f %.8f %.8f setrgbcolor\n",
1423 redPS
, greenPS
, bluePS
);
1424 for (int i
= 0; i
< 100; i
++)
1425 if (buffer
[i
] == ',') buffer
[i
] = '.';
1426 fprintf( m_pstream
, buffer
);
1429 m_currentBlue
= blue
;
1430 m_currentGreen
= green
;
1434 int size
= m_font
.GetPointSize();
1436 long by
= y
+ (long)floor( double(size
) * 2.0 / 3.0 ); // approximate baseline
1438 // FIXME only correct for 90 degrees
1439 fprintf(m_pstream
, "%d %d moveto\n",
1440 LogicalToDeviceX((wxCoord
)(x
+ size
)), LogicalToDeviceY((wxCoord
)by
) );
1443 sprintf(buffer
, "%.8f rotate\n", angle
);
1445 for (i
= 0; i
< 100; i
++)
1446 if (buffer
[i
] == ',') buffer
[i
] = '.';
1447 fprintf(m_pstream
, buffer
);
1449 fprintf( m_pstream
, "(" );
1450 const wxWX2MBbuf textbuf
= text
.mb_str();
1451 size_t len
= strlen(textbuf
);
1452 for (i
= 0; i
< len
; i
++)
1454 int c
= (unsigned char) textbuf
[i
];
1455 if (c
== ')' || c
== '(' || c
== '\\')
1457 /* Cope with special characters */
1458 fprintf( m_pstream
, "\\" );
1459 fputc(c
, m_pstream
);
1461 else if ( c
>= 128 )
1463 /* Cope with character codes > 127 */
1464 fprintf(m_pstream
, "\\%o", c
);
1468 fputc(c
, m_pstream
);
1472 fprintf( m_pstream
, ") show\n" );
1474 sprintf( buffer
, "%.8f rotate\n", -angle
);
1475 for (i
= 0; i
< 100; i
++)
1476 if (buffer
[i
] == ',') buffer
[i
] = '.';
1477 fprintf( m_pstream
, buffer
);
1479 if (m_font
.GetUnderlined())
1481 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1484 GetTextExtent(text
, &w
, &h
);
1493 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1494 m_underlineThickness
,
1495 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1496 for (i
= 0; i
< 100; i
++)
1497 if (buffer
[i
] == ',') buffer
[i
] = '.';
1498 fprintf( m_pstream
, buffer
);
1501 CalcBoundingBox( x
, y
);
1502 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1505 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1507 m_backgroundBrush
= brush
;
1510 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1512 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1515 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1517 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1521 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1524 wxNode
*node
= points
->First();
1525 p
= (wxPoint
*)node
->Data();
1529 node
= node
->Next();
1530 p
= (wxPoint
*)node
->Data();
1533 x3
= a
= (double)(x1
+ c
) / 2;
1534 y3
= b
= (double)(y1
+ d
) / 2;
1540 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1541 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1543 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1544 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1546 while ((node
= node
->Next()) != NULL
)
1548 q
= (wxPoint
*)node
->Data();
1556 x3
= (double)(x2
+ c
) / 2;
1557 y3
= (double)(y2
+ d
) / 2;
1560 "%d %d %d %d %d %d DrawSplineSection\n",
1561 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1562 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1563 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1565 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1566 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1570 At this point, (x2,y2) and (c,d) are the position of the
1571 next-to-last and last point respectively, in the point list
1577 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1580 wxCoord
wxPostScriptDC::GetCharWidth() const
1582 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1583 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1587 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1589 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1591 m_signX
= (xLeftRight
? 1 : -1);
1592 m_signY
= (yBottomUp
? 1 : -1);
1594 // FIXME there is no such function in MSW nor in OS2/PM
1595 #if !defined(__WXMSW__) && !defined(__WXPM__)
1596 ComputeScaleAndOrigin();
1600 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1602 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1608 wxDC::SetDeviceOrigin( x
, h
-y
);
1611 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1613 wxPaperSize id
= m_printData
.GetPaperId();
1615 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1617 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1623 w
= paper
->GetSizeDeviceUnits().x
;
1624 h
= paper
->GetSizeDeviceUnits().y
;
1627 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1634 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1635 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1638 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1640 wxPaperSize id
= m_printData
.GetPaperId();
1642 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1644 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1650 w
= paper
->GetWidth() / 10;
1651 h
= paper
->GetHeight() / 10;
1654 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1661 if (width
) *width
= w
;
1662 if (height
) *height
= h
;
1665 // Resolution in pixels per logical inch
1666 wxSize
wxPostScriptDC::GetPPI(void) const
1668 return wxSize((int)(72 * ms_PSScaleFactor
),
1669 (int)(72 * ms_PSScaleFactor
));
1673 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1675 wxCHECK_MSG( m_ok
, FALSE
, wxT("invalid postscript dc") );
1677 if (m_printData
.GetFilename() == "")
1679 wxString filename
= wxGetTempFileName("ps");
1680 m_printData
.SetFilename(filename
);
1683 m_pstream
= wxFopen( m_printData
.GetFilename().c_str(), wxT("w+") ); // FIXME: use fn_str() here under Unicode?
1687 wxLogError( _("Cannot open file for PostScript printing!"));
1694 fprintf( m_pstream
, "%%!PS-Adobe-2.0\n" );
1695 fprintf( m_pstream
, "%%%%Title: %s\n", (const char *) m_title
.ToAscii() );
1696 fprintf( m_pstream
, "%%%%Creator: wxWindows PostScript renderer\n" );
1697 fprintf( m_pstream
, "%%%%CreationDate: %s\n", (const char *) wxNow().ToAscii() );
1698 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1699 fprintf( m_pstream
, "%%%%Orientation: Landscape\n" );
1701 fprintf( m_pstream
, "%%%%Orientation: Portrait\n" );
1703 // fprintf( m_pstream, "%%%%Pages: %d\n", (wxPageNumber - 1) );
1706 switch (m_printData
.GetPaperId())
1708 case wxPAPER_LETTER
: paper
= "Letter"; break; // Letter: paper ""; 8 1/2 by 11 inches
1709 case wxPAPER_LEGAL
: paper
= "Legal"; break; // Legal, 8 1/2 by 14 inches
1710 case wxPAPER_A4
: paper
= "A4"; break; // A4 Sheet, 210 by 297 millimeters
1711 case wxPAPER_TABLOID
: paper
= "Tabloid"; break; // Tabloid, 11 by 17 inches
1712 case wxPAPER_LEDGER
: paper
= "Ledger"; break; // Ledger, 17 by 11 inches
1713 case wxPAPER_STATEMENT
: paper
= "Statement"; break; // Statement, 5 1/2 by 8 1/2 inches
1714 case wxPAPER_EXECUTIVE
: paper
= "Executive"; break; // Executive, 7 1/4 by 10 1/2 inches
1715 case wxPAPER_A3
: paper
= "A3"; break; // A3 sheet, 297 by 420 millimeters
1716 case wxPAPER_A5
: paper
= "A5"; break; // A5 sheet, 148 by 210 millimeters
1717 case wxPAPER_B4
: paper
= "B4"; break; // B4 sheet, 250 by 354 millimeters
1718 case wxPAPER_B5
: paper
= "B5"; break; // B5 sheet, 182-by-257-millimeter paper
1719 case wxPAPER_FOLIO
: paper
= "Folio"; break; // Folio, 8-1/2-by-13-inch paper
1720 case wxPAPER_QUARTO
: paper
= "Quaro"; break; // Quarto, 215-by-275-millimeter paper
1721 case wxPAPER_10X14
: paper
= "10x14"; break; // 10-by-14-inch sheet
1722 default: paper
= "A4";
1724 fprintf( m_pstream
, "%%%%DocumentPaperSizes: %s\n", paper
);
1725 fprintf( m_pstream
, "%%%%EndComments\n\n" );
1727 fprintf( m_pstream
, "%%%%BeginProlog\n" );
1728 fprintf( m_pstream
, wxPostScriptHeaderConicTo
);
1729 fprintf( m_pstream
, wxPostScriptHeaderEllipse
);
1730 fprintf( m_pstream
, wxPostScriptHeaderEllipticArc
);
1731 fprintf( m_pstream
, wxPostScriptHeaderColourImage
);
1733 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO1
);
1734 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO2
);
1736 if (wxPostScriptHeaderSpline
)
1737 fprintf( m_pstream
, wxPostScriptHeaderSpline
);
1738 fprintf( m_pstream
, "%%%%EndProlog\n" );
1740 SetBrush( *wxBLACK_BRUSH
);
1741 SetPen( *wxBLACK_PEN
);
1742 SetBackground( *wxWHITE_BRUSH
);
1743 SetTextForeground( *wxBLACK
);
1745 // set origin according to paper size
1746 SetDeviceOrigin( 0,0 );
1754 void wxPostScriptDC::EndDoc ()
1756 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1761 fprintf( m_pstream
, "grestore\n" );
1764 fclose( m_pstream
);
1765 m_pstream
= (FILE *) NULL
;
1768 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1769 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1770 double wx_printer_scale_x
, wx_printer_scale_y
;
1772 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1773 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1775 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1776 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1778 // Compute the bounding box. Note that it is in the default user
1779 // coordinate system, thus we have to convert the values.
1780 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1781 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1782 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1783 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1785 // LOG2DEV may have changed the minimum to maximum vice versa
1786 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1787 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1789 // account for used scaling (boundingbox is before scaling in ps-file)
1790 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1791 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1793 wxCoord llx
, lly
, urx
, ury
;
1794 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1795 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1796 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1797 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1798 // (end of bounding box computation)
1801 // If we're landscape, our sense of "x" and "y" is reversed.
1802 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1805 tmp
= llx
; llx
= lly
; lly
= tmp
;
1806 tmp
= urx
; urx
= ury
; ury
= tmp
;
1808 // We need either the two lines that follow, or we need to subtract
1809 // min_x from real_translate_y, which is commented out below.
1810 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1811 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1814 // The Adobe specifications call for integers; we round as to make
1815 // the bounding larger.
1817 "%%%%BoundingBox: %d %d %d %d\n",
1818 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1819 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1821 // To check the correctness of the bounding box, postscript commands
1822 // to draw a box corresponding to the bounding box are generated below.
1823 // But since we typically don't want to print such a box, the postscript
1824 // commands are generated within comments. These lines appear before any
1825 // adjustment of scale, rotation, or translation, and hence are in the
1826 // default user coordinates.
1827 fprintf( m_pstream
, "%% newpath\n" );
1828 fprintf( m_pstream
, "%% %d %d moveto\n", llx
, lly
);
1829 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, lly
);
1830 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, ury
);
1831 fprintf( m_pstream
, "%% %d %d lineto closepath stroke\n", llx
, ury
);
1834 #if defined(__X__) || defined(__WXGTK__)
1835 if (m_ok
&& (m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
1838 command
+= m_printData
.GetPrinterCommand();
1839 command
+= wxT(" ");
1840 command
+= m_printData
.GetFilename();
1842 wxExecute( command
, TRUE
);
1843 wxRemoveFile( m_printData
.GetFilename() );
1848 void wxPostScriptDC::StartPage()
1850 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1852 fprintf( m_pstream
, "%%%%Page: %d\n", wxPageNumber
++ );
1854 // What is this one supposed to do? RR.
1855 // *m_pstream << "matrix currentmatrix\n";
1857 // Added by Chris Breeze
1859 // Each page starts with an "initgraphics" which resets the
1860 // transformation and so we need to reset the origin
1861 // (and rotate the page for landscape printing)
1864 wxCoord translate_x
, translate_y
;
1865 double scale_x
, scale_y
;
1867 translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1868 translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1870 scale_x
= m_printData
.GetPrinterScaleX();
1871 scale_y
= m_printData
.GetPrinterScaleY();
1873 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1876 GetSize( (int*) NULL
, &h
);
1878 fprintf( m_pstream
, "90 rotate\n" );
1880 // I copied this one from a PostScript tutorial, but to no avail. RR.
1881 // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" );
1885 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1886 scale_y
/ ms_PSScaleFactor
);
1887 for (int i
= 0; i
< 100; i
++)
1888 if (buffer
[i
] == ',') buffer
[i
] = '.';
1889 fprintf( m_pstream
, buffer
);
1891 fprintf( m_pstream
, "%d %d translate\n", translate_x
, translate_y
);
1894 void wxPostScriptDC::EndPage ()
1896 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1898 fprintf( m_pstream
, "showpage\n" );
1901 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1902 wxCoord fwidth
, wxCoord fheight
,
1904 wxCoord xsrc
, wxCoord ysrc
,
1905 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
1907 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, wxT("invalid postscript dc") );
1909 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1911 /* blit into a bitmap */
1912 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1914 memDC
.SelectObject(bitmap
);
1915 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1916 memDC
.SelectObject(wxNullBitmap
);
1918 /* draw bitmap. scaling and positioning is done there */
1919 DrawBitmap( bitmap
, xdest
, ydest
);
1924 wxCoord
wxPostScriptDC::GetCharHeight() const
1927 return m_font
.GetPointSize();
1932 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1933 wxCoord
*x
, wxCoord
*y
,
1934 wxCoord
*descent
, wxCoord
*externalLeading
,
1935 wxFont
*theFont
) const
1937 wxFont
*fontToUse
= theFont
;
1939 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1941 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1943 if (string
.IsEmpty())
1951 int dpi
= GetResolution();
1952 PangoContext
*context
= pango_ft2_get_context ( dpi
, dpi
);
1954 pango_context_set_language (context
, pango_language_from_string ("en_US"));
1955 pango_context_set_base_dir (context
, PANGO_DIRECTION_LTR
);
1957 PangoLayout
*layout
= pango_layout_new (context
);
1959 PangoFontDescription
*desc
= fontToUse
->GetNativeFontInfo()->description
;
1960 pango_layout_set_font_description(layout
, desc
);
1962 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1963 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1965 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1966 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1967 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1969 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1971 PangoRectangle rect
;
1972 pango_layout_line_get_extents(line
, NULL
, &rect
);
1974 if (x
) (*x
) = (wxCoord
) ( m_scaleX
* rect
.width
/ PANGO_SCALE
);
1975 if (y
) (*y
) = (wxCoord
) ( m_scaleY
* rect
.height
/ PANGO_SCALE
);
1978 // Do something about metrics here
1981 if (externalLeading
) (*externalLeading
) = 0; // ??
1983 g_object_unref( G_OBJECT( layout
) );
1987 const wxWX2MBbuf strbuf
= string
.mb_str();
1989 #if !wxUSE_AFM_FOR_POSTSCRIPT
1990 /* Provide a VERY rough estimate (avoid using it).
1991 * Produces accurate results for mono-spaced font
1992 * such as Courier (aka wxMODERN) */
1997 height
= fontToUse
->GetPointSize();
2000 *x
= strlen (strbuf
) * height
* 72 / 120;
2002 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
2003 if (descent
) *descent
= 0;
2004 if (externalLeading
) *externalLeading
= 0;
2007 /* method for calculating string widths in postscript:
2008 / read in the AFM (adobe font metrics) file for the
2009 / actual font, parse it and extract the character widths
2010 / and also the descender. this may be improved, but for now
2011 / it works well. the AFM file is only read in if the
2012 / font is changed. this may be chached in the future.
2013 / calls to GetTextExtent with the font unchanged are rather
2016 / for each font and style used there is an AFM file necessary.
2017 / currently i have only files for the roman font family.
2018 / I try to get files for the other ones!
2020 / CAVE: the size of the string is currently always calculated
2021 / in 'points' (1/72 of an inch). this should later on be
2022 / changed to depend on the mapping mode.
2023 / CAVE: the path to the AFM files must be set before calling this
2024 / function. this is usually done by a call like the following:
2025 / wxSetAFMPath("d:\\wxw161\\afm\\");
2029 / wxPostScriptDC dc(NULL, TRUE);
2031 / wxSetAFMPath("d:\\wxw161\\afm\\");
2032 / dc.StartDoc("Test");
2035 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
2036 / dc.GetTextExtent("Hallo",&w,&h);
2041 / by steve (stefan.hammes@urz.uni-heidelberg.de)
2043 / updated: 14.05.95 */
2045 /* these static vars are for storing the state between calls */
2046 static int lastFamily
= INT_MIN
;
2047 static int lastSize
= INT_MIN
;
2048 static int lastStyle
= INT_MIN
;
2049 static int lastWeight
= INT_MIN
;
2050 static int lastDescender
= INT_MIN
;
2051 static int lastWidths
[256]; /* widths of the characters */
2053 double UnderlinePosition
= 0.0;
2054 double UnderlineThickness
= 0.0;
2056 // Get actual parameters
2057 int Family
= fontToUse
->GetFamily();
2058 int Size
= fontToUse
->GetPointSize();
2059 int Style
= fontToUse
->GetStyle();
2060 int Weight
= fontToUse
->GetWeight();
2062 // If we have another font, read the font-metrics
2063 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
2065 // Store actual values
2066 lastFamily
= Family
;
2069 lastWeight
= Weight
;
2071 const char *name
= NULL
;
2078 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO.afm";
2079 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo.afm";
2080 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "CourO.afm";
2081 else name
= "Cour.afm";
2086 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO.afm";
2087 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo.afm";
2088 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO.afm";
2089 else name
= "TimesRo.afm";
2101 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO.afm";
2102 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo.afm";
2103 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "HelvO.afm";
2104 else name
= "Helv.afm";
2109 FILE *afmFile
= NULL
;
2111 // Get the directory of the AFM files
2113 if (!m_printData
.GetFontMetricPath().IsEmpty())
2115 afmName
= m_printData
.GetFontMetricPath();
2116 afmName
<< wxFILE_SEP_PATH
<< name
;
2117 afmFile
= wxFopen(afmName
,wxT("r"));
2120 #if defined(__UNIX__) && !defined(__VMS__)
2123 afmName
= wxGetDataDir();
2124 afmName
<< wxFILE_SEP_PATH
2125 #if defined(__LINUX__) || defined(__FREEBSD__)
2126 << wxT("gs_afm") << wxFILE_SEP_PATH
2128 << wxT("afm") << wxFILE_SEP_PATH
2131 afmFile
= wxFopen(afmName
,wxT("r"));
2135 /* 2. open and process the file
2136 / a short explanation of the AFM format:
2137 / we have for each character a line, which gives its size
2140 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2142 / that means, we have a character with ascii code 63, and width
2143 / (444/1000 * fontSize) points.
2144 / the other data is ignored for now!
2146 / when the font has changed, we read in the right AFM file and store the
2147 / character widths in an array, which is processed below (see point 3.). */
2150 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2151 wxLogDebug( wxT(" using approximate values"));
2152 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2153 lastDescender
= -150; /* dito. */
2157 /* init the widths array */
2158 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2159 /* some variables for holding parts of a line */
2160 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2161 char upString
[30], utString
[30], encString
[50];
2164 /* read in the file and parse it */
2165 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2167 /* A.) check for descender definition */
2168 if (strncmp(line
,"Descender",9)==0)
2170 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2171 (strcmp(descString
,"Descender")!=0))
2173 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2176 /* JC 1.) check for UnderlinePosition */
2177 else if(strncmp(line
,"UnderlinePosition",17)==0)
2179 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2180 (strcmp(upString
,"UnderlinePosition")!=0))
2182 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2185 /* JC 2.) check for UnderlineThickness */
2186 else if(strncmp(line
,"UnderlineThickness",18)==0)
2188 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2189 (strcmp(utString
,"UnderlineThickness")!=0))
2191 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2194 /* JC 3.) check for EncodingScheme */
2195 else if(strncmp(line
,"EncodingScheme",14)==0)
2197 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2198 (strcmp(utString
,"EncodingScheme")!=0))
2200 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2202 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2204 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2205 afmName
.c_str(),line
, encString
);
2208 /* B.) check for char-width */
2209 else if(strncmp(line
,"C ",2)==0)
2211 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2213 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2215 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2217 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2219 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2220 if (ascii
>=0 && ascii
<256)
2222 lastWidths
[ascii
] = cWidth
; /* store width */
2226 /* MATTHEW: this happens a lot; don't print an error */
2227 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2230 /* C.) ignore other entries. */
2234 /* hack to compute correct values for german 'Umlaute'
2235 / the correct way would be to map the character names
2236 / like 'adieresis' to corresp. positions of ISOEnc and read
2237 / these values from AFM files, too. Maybe later ... */
2238 lastWidths
[196] = lastWidths
['A']; // Ä
2239 lastWidths
[228] = lastWidths
['a']; // ä
2240 lastWidths
[214] = lastWidths
['O']; // Ö
2241 lastWidths
[246] = lastWidths
['o']; // ö
2242 lastWidths
[220] = lastWidths
['U']; // Ü
2243 lastWidths
[252] = lastWidths
['u']; // ü
2244 lastWidths
[223] = lastWidths
[251]; // ß
2246 /* JC: calculate UnderlineThickness/UnderlinePosition */
2248 // VS: dirty, but is there any better solution?
2250 pt
= (double*) &m_underlinePosition
;
2251 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2252 pt
= (double*) &m_underlineThickness
;
2253 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2258 /* 3. now the font metrics are read in, calc size this
2259 / is done by adding the widths of the characters in the
2260 / string. they are given in 1/1000 of the size! */
2263 wxCoord height
=Size
; /* by default */
2265 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2267 if(lastWidths
[*p
]== INT_MIN
)
2269 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2270 sum
+= lastWidths
[' ']; /* assume space */
2274 sum
+= lastWidths
[*p
];
2278 double widthSum
= sum
;
2280 widthSum
/= 1000.0F
;
2282 /* add descender to height (it is usually a negative value) */
2283 //if (lastDescender != INT_MIN)
2285 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2287 // - commented by V. Slavik - height already contains descender in it
2288 // (judging from few experiments)
2290 /* return size values */
2292 *x
= (wxCoord
)widthSum
;
2296 /* return other parameters */
2299 if(lastDescender
!=INT_MIN
)
2301 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2309 /* currently no idea how to calculate this! */
2310 if (externalLeading
) *externalLeading
= 0;
2322 // wxUSE_PRINTING_ARCHITECTURE