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/dcmemory.h"
37 #include "wx/generic/dcpsg.h"
38 #include "wx/prntbase.h"
40 #include "wx/filefn.h"
41 #if WXWIN_COMPATIBILITY_2_2
42 #include "wx/window.h"
43 #include "wx/printdlg.h"
68 //-----------------------------------------------------------------------------
69 // start and end of document/page
70 //-----------------------------------------------------------------------------
72 static const char *wxPostScriptHeaderConicTo
= "\
76 /conic_cntrl_y exch def\n\
77 /conic_cntrl_x exch def\n\
81 /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\
82 /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\
83 /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\
84 /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\
85 p1_x p1_y p2_x p2_y to_x to_y curveto\n\
89 static const char *wxPostScriptHeaderEllipse
= "\
90 /ellipsedict 8 dict def\n\
91 ellipsedict /mtrx matrix put\n\
95 /startangle exch def\n\
100 /savematrix mtrx currentmatrix def\n\
103 0 0 1 startangle endangle arc\n\
104 savematrix setmatrix\n\
109 static const char *wxPostScriptHeaderEllipticArc
= "\
110 /ellipticarcdict 8 dict def\n\
111 ellipticarcdict /mtrx matrix put\n\
113 { ellipticarcdict begin\n\
115 /endangle exch def\n\
116 /startangle exch def\n\
121 /savematrix mtrx currentmatrix def\n\
124 do_fill { 0 0 moveto } if\n\
125 0 0 1 startangle endangle arc\n\
126 savematrix setmatrix\n\
127 do_fill { fill }{ stroke } ifelse\n\
131 static const char *wxPostScriptHeaderSpline
= "\
132 /DrawSplineSection {\n\
139 /xa x1 x2 x1 sub 0.666667 mul add def\n\
140 /ya y1 y2 y1 sub 0.666667 mul add def\n\
141 /xb x3 x2 x3 sub 0.666667 mul add def\n\
142 /yb y3 y2 y3 sub 0.666667 mul add def\n\
144 xa ya xb yb x3 y3 curveto\n\
148 static const char *wxPostScriptHeaderColourImage
= "\
149 %% define 'colorimage' if it isn't defined\n\
150 %% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
152 /colorimage where %% do we know about 'colorimage'?\n\
153 { pop } %% yes: pop off the 'dict' returned\n\
154 { %% no: define one\n\
155 /colortogray { %% define an RGB->I function\n\
156 /rgbdata exch store %% call input 'rgbdata'\n\
157 rgbdata length 3 idiv\n\
158 /npixls exch store\n\
160 0 1 npixls 1 sub {\n\
162 rgbdata rgbindx get 20 mul %% Red\n\
163 rgbdata rgbindx 1 add get 32 mul %% Green\n\
164 rgbdata rgbindx 2 add get 12 mul %% Blue\n\
165 add add 64 idiv %% I = .5G + .31R + .18B\n\
167 /rgbindx rgbindx 3 add store\n\
169 grays 0 npixls getinterval\n\
172 %% Utility procedure for colorimage operator.\n\
173 %% This procedure takes two procedures off the\n\
174 %% stack and merges them into a single procedure.\n\
176 /mergeprocs { %% def\n\
195 /colorimage { %% def\n\
196 pop pop %% remove 'false 3' operands\n\
197 {colortogray} mergeprocs\n\
200 } ifelse %% end of 'false' case\n\
205 static char wxPostScriptHeaderReencodeISO1
[] =
207 "dup dup findfont dup length dict begin\n"
208 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
209 "/Encoding ISOLatin1Encoding def\n"
210 "currentdict end definefont\n"
212 "/ISOLatin1Encoding [\n"
213 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
214 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
215 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
216 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
217 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
218 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
219 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
220 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
221 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
222 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
223 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
224 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
225 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
226 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
227 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
229 static char wxPostScriptHeaderReencodeISO2
[] =
230 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
231 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
232 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
233 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
234 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
235 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
236 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
237 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
238 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
239 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
240 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
241 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
242 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
243 "/yacute/thorn/ydieresis\n"
247 //-------------------------------------------------------------------------------
249 //-------------------------------------------------------------------------------
251 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
253 float wxPostScriptDC::ms_PSScaleFactor
= 10.0;
255 void wxPostScriptDC::SetResolution(int ppi
)
257 ms_PSScaleFactor
= (float)ppi
/ 72.0;
260 int wxPostScriptDC::GetResolution()
262 return (int)(ms_PSScaleFactor
* 72.0);
265 //-------------------------------------------------------------------------------
267 wxPostScriptDC::wxPostScriptDC ()
269 m_pstream
= (FILE*) NULL
;
279 m_underlinePosition
= 0.0;
280 m_underlineThickness
= 0.0;
282 m_signX
= 1; // default x-axis left to right
283 m_signY
= -1; // default y-axis bottom up -> top down
286 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
288 m_pstream
= (FILE*) NULL
;
298 m_underlinePosition
= 0.0;
299 m_underlineThickness
= 0.0;
301 m_signX
= 1; // default x-axis left to right
302 m_signY
= -1; // default y-axis bottom up -> top down
304 m_printData
= printData
;
309 wxPostScriptDC::~wxPostScriptDC ()
314 m_pstream
= (FILE*) NULL
;
318 #if WXWIN_COMPATIBILITY_2_2
319 bool wxPostScriptDC::Create( const wxString
&output
, bool interactive
, wxWindow
*parent
)
322 data
.SetFilename( output
);
323 data
.SetPrintMode( wxPRINT_MODE_FILE
);
327 wxPrintDialogData
ddata( data
);
328 wxPrintDialog
dialog( parent
, &data
);
329 dialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
330 if (dialog
.ShowModal() != wxID_OK
)
335 data
= dialog
.GetPrintDialogData().GetPrintData();
343 bool wxPostScriptDC::Ok() const
348 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
350 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
352 if (m_clipping
) DestroyClippingRegion();
354 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
363 "closepath clip newpath\n",
364 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
365 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
366 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
367 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
371 void wxPostScriptDC::DestroyClippingRegion()
373 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
378 fprintf( m_pstream
, "grestore\n" );
381 wxDC::DestroyClippingRegion();
384 void wxPostScriptDC::Clear()
386 wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
389 bool wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
391 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
395 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
397 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
401 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
403 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
406 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
408 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
410 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
419 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
420 LogicalToDeviceX(x2
), LogicalToDeviceY (y2
) );
422 CalcBoundingBox( x1
, y1
);
423 CalcBoundingBox( x2
, y2
);
426 #define RAD2DEG 57.29577951308
428 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
430 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
432 wxCoord dx
= x1
- xc
;
433 wxCoord dy
= y1
- yc
;
434 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
435 double alpha1
, alpha2
;
437 if (x1
== x2
&& y1
== y2
)
442 else if (radius
== 0.0)
444 alpha1
= alpha2
= 0.0;
448 alpha1
= (x1
- xc
== 0) ?
449 (y1
- yc
< 0) ? 90.0 : -90.0 :
450 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
451 alpha2
= (x2
- xc
== 0) ?
452 (y2
- yc
< 0) ? 90.0 : -90.0 :
453 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
455 while (alpha1
<= 0) alpha1
+= 360;
456 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
457 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
458 while (alpha2
> 360) alpha2
-= 360;
460 if (m_brush
.GetStyle() != wxTRANSPARENT
)
466 "%d %d %d %d %d %d ellipse\n"
470 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
471 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
473 CalcBoundingBox( xc
-radius
, yc
-radius
);
474 CalcBoundingBox( xc
+radius
, yc
+radius
);
477 if (m_pen
.GetStyle() != wxTRANSPARENT
)
483 "%d %d %d %d %d %d ellipse\n"
487 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
488 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
490 CalcBoundingBox( xc
-radius
, yc
-radius
);
491 CalcBoundingBox( xc
+radius
, yc
+radius
);
495 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
497 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
499 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
500 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
506 DrawEllipse(x
,y
,w
,h
);
510 if (m_brush
.GetStyle () != wxTRANSPARENT
)
516 "%d %d %d %d %d %d true ellipticarc\n",
517 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
519 CalcBoundingBox( x
,y
);
520 CalcBoundingBox( x
+w
, y
+h
);
523 if (m_pen
.GetStyle () != wxTRANSPARENT
)
529 "%d %d %d %d %d %d false ellipticarc\n",
530 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
532 CalcBoundingBox( x
,y
);
533 CalcBoundingBox( x
+w
, y
+h
);
537 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
539 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
541 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
550 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
551 LogicalToDeviceX(x
+1), LogicalToDeviceY(y
) );
553 CalcBoundingBox( x
, y
);
556 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
))
558 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
562 if (m_brush
.GetStyle () != wxTRANSPARENT
)
566 fprintf( m_pstream
, "newpath\n" );
568 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
569 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
571 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
573 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
575 for (int i
= 1; i
< n
; i
++)
577 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
578 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
580 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
582 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
585 fprintf( m_pstream
, "fill\n" );
588 if (m_pen
.GetStyle () != wxTRANSPARENT
)
592 fprintf( m_pstream
, "newpath\n" );
594 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
595 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
597 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
599 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
601 for (int i
= 1; i
< n
; i
++)
603 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
604 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
606 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
608 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
611 fprintf( m_pstream
, "closepath\n" );
612 fprintf( m_pstream
, "stroke\n" );
616 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
618 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
620 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
627 for ( i
=0; i
<n
; i
++ )
629 CalcBoundingBox( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
635 LogicalToDeviceX(points
[0].x
+xoffset
), LogicalToDeviceY(points
[0].y
+yoffset
) );
637 for (i
= 1; i
< n
; i
++)
641 LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
) );
644 fprintf( m_pstream
, "stroke\n" );
647 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
649 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
651 if (m_brush
.GetStyle () != wxTRANSPARENT
)
663 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
664 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
665 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
666 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
668 CalcBoundingBox( x
, y
);
669 CalcBoundingBox( x
+ width
, y
+ height
);
672 if (m_pen
.GetStyle () != wxTRANSPARENT
)
684 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
685 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
686 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
687 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
689 CalcBoundingBox( x
, y
);
690 CalcBoundingBox( x
+ width
, y
+ height
);
694 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
696 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
700 // Now, a negative radius is interpreted to mean
701 // 'the proportion of the smallest X or Y dimension'
702 double smallest
= 0.0;
707 radius
= (-radius
* smallest
);
710 wxCoord rad
= (wxCoord
) radius
;
712 if (m_brush
.GetStyle () != wxTRANSPARENT
)
716 /* Draw rectangle anticlockwise */
719 "%d %d %d 90 180 arc\n"
721 "%d %d %d 180 270 arc\n"
723 "%d %d %d 270 0 arc\n"
725 "%d %d %d 0 90 arc\n"
729 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
730 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
731 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
732 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
733 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
734 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
735 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
736 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
738 CalcBoundingBox( x
, y
);
739 CalcBoundingBox( x
+ width
, y
+ height
);
742 if (m_pen
.GetStyle () != wxTRANSPARENT
)
746 /* Draw rectangle anticlockwise */
749 "%d %d %d 90 180 arc\n"
751 "%d %d %d 180 270 arc\n"
753 "%d %d %d 270 0 arc\n"
755 "%d %d %d 0 90 arc\n"
759 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
760 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
761 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
762 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
763 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
764 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
765 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
766 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
768 CalcBoundingBox( x
, y
);
769 CalcBoundingBox( x
+ width
, y
+ height
);
773 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
775 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
777 if (m_brush
.GetStyle () != wxTRANSPARENT
)
783 "%d %d %d %d 0 360 ellipse\n"
785 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
786 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
788 CalcBoundingBox( x
- width
, y
- height
);
789 CalcBoundingBox( x
+ width
, y
+ height
);
792 if (m_pen
.GetStyle () != wxTRANSPARENT
)
798 "%d %d %d %d 0 360 ellipse\n"
800 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
801 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
803 CalcBoundingBox( x
- width
, y
- height
);
804 CalcBoundingBox( x
+ width
, y
+ height
);
808 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
810 DrawBitmap( icon
, x
, y
, TRUE
);
813 /* this has to be char, not wxChar */
814 static char hexArray
[] = "0123456789ABCDEF";
815 static void LocalDecToHex( int dec
, char *buf
)
817 int firstDigit
= (int)(dec
/16.0);
818 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
819 buf
[0] = hexArray
[firstDigit
];
820 buf
[1] = hexArray
[secondDigit
];
824 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
826 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
828 if (!bitmap
.Ok()) return;
830 wxImage image
= bitmap
.ConvertToImage();
832 if (!image
.Ok()) return;
834 wxCoord w
= image
.GetWidth();
835 wxCoord h
= image
.GetHeight();
837 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
838 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
840 wxCoord xx
= LogicalToDeviceX(x
);
841 wxCoord yy
= LogicalToDeviceY(y
+ bitmap
.GetHeight());
844 "/origstate save def\n"
846 "/pix %d string def\n"
847 "/grays %d string def\n"
854 "{currentfile pix readhexstring pop}\n"
855 "false 3 colorimage\n",
856 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
859 for (int j
= 0; j
< h
; j
++)
861 for (int i
= 0; i
< w
; i
++)
864 LocalDecToHex( image
.GetRed(i
,j
), buffer
);
865 fprintf( m_pstream
, buffer
);
866 LocalDecToHex( image
.GetGreen(i
,j
), buffer
);
867 fprintf( m_pstream
, buffer
);
868 LocalDecToHex( image
.GetBlue(i
,j
), buffer
);
869 fprintf( m_pstream
, buffer
);
871 fprintf( m_pstream
, "\n" );
874 fprintf( m_pstream
, "end\n" );
875 fprintf( m_pstream
, "origstate restore\n" );
878 void wxPostScriptDC::SetFont( const wxFont
& font
)
880 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
882 if (!font
.Ok()) return;
888 int Style
= m_font
.GetStyle();
889 int Weight
= m_font
.GetWeight();
892 switch (m_font
.GetFamily())
897 if (Style
== wxITALIC
)
899 if (Weight
== wxBOLD
)
900 name
= "/Courier-BoldOblique";
902 name
= "/Courier-Oblique";
906 if (Weight
== wxBOLD
)
907 name
= "/Courier-Bold";
915 if (Style
== wxITALIC
)
917 if (Weight
== wxBOLD
)
918 name
= "/Times-BoldItalic";
920 name
= "/Times-Italic";
924 if (Weight
== wxBOLD
)
925 name
= "/Times-Bold";
927 name
= "/Times-Roman";
933 name
= "/ZapfChancery-MediumItalic";
941 if (Style
== wxITALIC
)
943 if (Weight
== wxBOLD
)
944 name
= "/Helvetica-BoldOblique";
946 name
= "/Helvetica-Oblique";
950 if (Weight
== wxBOLD
)
951 name
= "/Helvetica-Bold";
959 fprintf( m_pstream
, name
);
960 fprintf( m_pstream
, " reencodeISO def\n" );
961 fprintf( m_pstream
, name
);
962 fprintf( m_pstream
, " findfont\n" );
965 sprintf( buffer
, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
966 // this is a hack - we must scale font size (in pts) according to m_scaleY but
967 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
968 // to 1/1000th of pt and then back.
969 for (int i
= 0; i
< 100; i
++)
970 if (buffer
[i
] == ',') buffer
[i
] = '.';
971 fprintf( m_pstream
, buffer
);
975 void wxPostScriptDC::SetPen( const wxPen
& pen
)
977 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
979 if (!pen
.Ok()) return;
981 int oldStyle
= m_pen
.GetStyle();
988 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
990 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
992 for (int i
= 0; i
< 100; i
++)
993 if (buffer
[i
] == ',') buffer
[i
] = '.';
994 fprintf( m_pstream
, buffer
);
998 Line style - WRONG: 2nd arg is OFFSET
1000 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1001 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1002 ter is not number of values in the array of the first one, but an offset
1003 into this description of the pattern. I mean a real *offset* not index
1004 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1005 will be first black line *2* units wxCoord, then space 4 units, then the
1006 pattern of *3* units black, 4 units space will be repeated.
1009 static const char *dotted
= "[2 5] 2";
1010 static const char *short_dashed
= "[4 4] 2";
1011 static const char *wxCoord_dashed
= "[4 8] 2";
1012 static const char *dotted_dashed
= "[6 6 2 6] 4";
1014 const char *psdash
= (char *) NULL
;
1015 switch (m_pen
.GetStyle())
1017 case wxDOT
: psdash
= dotted
; break;
1018 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1019 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1020 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1023 default: psdash
= "[] 0"; break;
1026 if (oldStyle
!= m_pen
.GetStyle())
1028 fprintf( m_pstream
, psdash
);
1029 fprintf( m_pstream
," setdash\n" );
1033 unsigned char red
= m_pen
.GetColour().Red();
1034 unsigned char blue
= m_pen
.GetColour().Blue();
1035 unsigned char green
= m_pen
.GetColour().Green();
1039 // Anything not white is black
1040 if (! (red
== (unsigned char) 255 &&
1041 blue
== (unsigned char) 255 &&
1042 green
== (unsigned char) 255) )
1044 red
= (unsigned char) 0;
1045 green
= (unsigned char) 0;
1046 blue
= (unsigned char) 0;
1051 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1053 double redPS
= (double)(red
) / 255.0;
1054 double bluePS
= (double)(blue
) / 255.0;
1055 double greenPS
= (double)(green
) / 255.0;
1059 "%.8f %.8f %.8f setrgbcolor\n",
1060 redPS
, greenPS
, bluePS
);
1061 for (int i
= 0; i
< 100; i
++)
1062 if (buffer
[i
] == ',') buffer
[i
] = '.';
1063 fprintf( m_pstream
, buffer
);
1066 m_currentBlue
= blue
;
1067 m_currentGreen
= green
;
1071 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1073 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1075 if (!brush
.Ok()) return;
1080 unsigned char red
= m_brush
.GetColour().Red();
1081 unsigned char blue
= m_brush
.GetColour().Blue();
1082 unsigned char green
= m_brush
.GetColour().Green();
1086 // Anything not white is black
1087 if (! (red
== (unsigned char) 255 &&
1088 blue
== (unsigned char) 255 &&
1089 green
== (unsigned char) 255) )
1091 red
= (unsigned char) 0;
1092 green
= (unsigned char) 0;
1093 blue
= (unsigned char) 0;
1098 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1100 double redPS
= (double)(red
) / 255.0;
1101 double bluePS
= (double)(blue
) / 255.0;
1102 double greenPS
= (double)(green
) / 255.0;
1106 "%.8f %.8f %.8f setrgbcolor\n",
1107 redPS
, greenPS
, bluePS
);
1108 for (int i
= 0; i
< 100; i
++)
1109 if (buffer
[i
] == ',') buffer
[i
] = '.';
1110 fprintf( m_pstream
, buffer
);
1113 m_currentBlue
= blue
;
1114 m_currentGreen
= green
;
1120 #define PANGO_ENABLE_ENGINE
1123 #include "wx/gtk/private.h"
1124 #include "gtk/gtk.h"
1126 #include "wx/x11/private.h"
1129 #include "wx/fontutil.h"
1130 #include <pango/pangoft2.h>
1131 #include <freetype/ftglyph.h>
1133 #ifndef FT_Outline_Decompose
1134 FT_EXPORT( FT_Error
) FT_Outline_Decompose(
1135 FT_Outline
* outline
,
1136 const FT_Outline_Funcs
* interface
,
1140 typedef struct _OutlineInfo OutlineInfo
;
1141 struct _OutlineInfo
{
1145 static int paps_move_to( FT_Vector
* to
,
1148 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1149 fprintf(outline_info
->file
, "%d %d moveto\n",
1155 static int paps_line_to( FT_Vector
* to
,
1158 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1159 fprintf(outline_info
->file
, "%d %d lineto\n",
1165 static int paps_conic_to( FT_Vector
* control
,
1169 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1170 fprintf(outline_info
->file
, "%d %d %d %d conicto\n",
1178 static int paps_cubic_to( FT_Vector
* control1
,
1179 FT_Vector
* control2
,
1183 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1184 fprintf(outline_info
->file
,
1185 "%d %d %d %d %d %d curveto\n",
1195 void draw_bezier_outline(FILE *file
,
1197 FT_UInt glyph_index
,
1203 FT_Int load_flags
= FT_LOAD_NO_BITMAP
;
1206 FT_Outline_Funcs outlinefunc
=
1214 OutlineInfo outline_info
;
1215 outline_info
.file
= file
;
1217 fprintf(file
, "gsave\n");
1218 fprintf(file
, "%d %d translate\n", pos_x
, pos_y
);
1219 // FT2 scales outlines to 26.6 pixels so the code below
1220 // should read 26600 instead of the 60000.
1221 fprintf(file
, "%d 60000 div %d 60000 div scale\n", scale_x
, scale_y
);
1222 fprintf(file
, "0 0 0 setrgbcolor\n");
1224 FT_Load_Glyph(face
, glyph_index
, load_flags
);
1225 FT_Get_Glyph (face
->glyph
, &glyph
);
1226 FT_Outline_Decompose (&(((FT_OutlineGlyph
)glyph
)->outline
),
1227 &outlinefunc
, &outline_info
);
1228 fprintf(file
, "closepath fill grestore \n");
1230 FT_Done_Glyph (glyph
);
1235 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1237 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1240 int dpi
= GetResolution();
1242 PangoContext
*context
= pango_ft2_get_context ( dpi
, dpi
);
1244 pango_context_set_language (context
, pango_language_from_string ("en_US"));
1245 pango_context_set_base_dir (context
, PANGO_DIRECTION_LTR
);
1247 pango_context_set_font_description (context
, m_font
.GetNativeFontInfo()->description
);
1249 PangoLayout
*layout
= pango_layout_new (context
);
1251 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( text
);
1253 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) );
1255 pango_layout_set_text( layout
, (const char*) buffer
, strlen(buffer
) );
1257 PangoRectangle rect
;
1258 pango_layout_get_extents(layout
, NULL
, &rect
);
1260 int xx
= x
* PANGO_SCALE
;
1261 int yy
= y
* PANGO_SCALE
+ (rect
.height
*2/3);
1263 int scale_x
= LogicalToDeviceXRel( 1000 );
1264 int scale_y
= LogicalToDeviceYRel( 1000 );
1266 // Loop over lines in layout
1267 int num_lines
= pango_layout_get_line_count( layout
);
1268 for (int i
= 0; i
< num_lines
; i
++)
1270 PangoLayoutLine
*line
= pango_layout_get_line( layout
, i
);
1272 // Loop over runs in line
1273 GSList
*runs_list
= line
->runs
;
1276 PangoLayoutRun
*run
= (PangoLayoutRun
*) runs_list
->data
;
1277 PangoItem
*item
= run
->item
;
1278 PangoGlyphString
*glyphs
= run
->glyphs
;
1279 PangoAnalysis
*analysis
= &item
->analysis
;
1280 PangoFont
*font
= analysis
->font
;
1281 FT_Face ft_face
= pango_ft2_font_get_face(font
);
1283 int num_glyphs
= glyphs
->num_glyphs
;
1284 for (int glyph_idx
= 0; glyph_idx
< num_glyphs
; glyph_idx
++)
1286 PangoGlyphGeometry geometry
= glyphs
->glyphs
[glyph_idx
].geometry
;
1287 int pos_x
= xx
+ geometry
.x_offset
;
1288 int pos_y
= yy
- geometry
.y_offset
;
1289 xx
+= geometry
.width
;
1291 draw_bezier_outline( m_pstream
, ft_face
,
1292 (FT_UInt
)(glyphs
->glyphs
[glyph_idx
].glyph
),
1293 LogicalToDeviceX( pos_x
/ PANGO_SCALE
),
1294 LogicalToDeviceY( pos_y
/ PANGO_SCALE
),
1297 runs_list
= runs_list
->next
;
1301 g_object_unref( G_OBJECT( layout
) );
1303 wxCoord text_w
, text_h
, text_descent
;
1305 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1307 // VZ: this seems to be unnecessary, so taking it out for now, if it
1308 // doesn't create any problems, remove this comment entirely
1309 //SetFont( m_font );
1311 if (m_textForegroundColour
.Ok())
1313 unsigned char red
= m_textForegroundColour
.Red();
1314 unsigned char blue
= m_textForegroundColour
.Blue();
1315 unsigned char green
= m_textForegroundColour
.Green();
1319 // Anything not white is black
1320 if (! (red
== (unsigned char) 255 &&
1321 blue
== (unsigned char) 255 &&
1322 green
== (unsigned char) 255))
1324 red
= (unsigned char) 0;
1325 green
= (unsigned char) 0;
1326 blue
= (unsigned char) 0;
1330 // maybe setgray here ?
1331 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1333 double redPS
= (double)(red
) / 255.0;
1334 double bluePS
= (double)(blue
) / 255.0;
1335 double greenPS
= (double)(green
) / 255.0;
1339 "%.8f %.8f %.8f setrgbcolor\n",
1340 redPS
, greenPS
, bluePS
);
1341 for (int i
= 0; i
< 100; i
++)
1342 if (buffer
[i
] == ',') buffer
[i
] = '.';
1343 fprintf( m_pstream
, buffer
);
1346 m_currentBlue
= blue
;
1347 m_currentGreen
= green
;
1351 int size
= m_font
.GetPointSize();
1353 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1354 // commented by V. Slavik and replaced by accurate version
1355 // - note that there is still rounding error in text_descent!
1356 wxCoord by
= y
+ size
- text_descent
; // baseline
1357 fprintf( m_pstream
, "%d %d moveto\n", LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1359 fprintf( m_pstream
, "(" );
1360 const wxWX2MBbuf textbuf
= text
.mb_str();
1361 size_t len
= strlen(textbuf
);
1363 for (i
= 0; i
< len
; i
++)
1365 int c
= (unsigned char) textbuf
[i
];
1366 if (c
== ')' || c
== '(' || c
== '\\')
1368 /* Cope with special characters */
1369 fprintf( m_pstream
, "\\" );
1370 fputc(c
, m_pstream
);
1372 else if ( c
>= 128 )
1374 /* Cope with character codes > 127 */
1375 fprintf(m_pstream
, "\\%o", c
);
1379 fputc(c
, m_pstream
);
1383 fprintf( m_pstream
, ") show\n" );
1385 if (m_font
.GetUnderlined())
1387 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1397 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1398 m_underlineThickness
,
1399 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1400 for (i
= 0; i
< 100; i
++)
1401 if (buffer
[i
] == ',') buffer
[i
] = '.';
1402 fprintf( m_pstream
, buffer
);
1405 CalcBoundingBox( x
, y
);
1406 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1410 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1414 DoDrawText(text
, x
, y
);
1418 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1422 if (m_textForegroundColour
.Ok())
1424 unsigned char red
= m_textForegroundColour
.Red();
1425 unsigned char blue
= m_textForegroundColour
.Blue();
1426 unsigned char green
= m_textForegroundColour
.Green();
1430 // Anything not white is black
1431 if (! (red
== (unsigned char) 255 &&
1432 blue
== (unsigned char) 255 &&
1433 green
== (unsigned char) 255))
1435 red
= (unsigned char) 0;
1436 green
= (unsigned char) 0;
1437 blue
= (unsigned char) 0;
1441 // maybe setgray here ?
1442 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1444 double redPS
= (double)(red
) / 255.0;
1445 double bluePS
= (double)(blue
) / 255.0;
1446 double greenPS
= (double)(green
) / 255.0;
1450 "%.8f %.8f %.8f setrgbcolor\n",
1451 redPS
, greenPS
, bluePS
);
1452 for (int i
= 0; i
< 100; i
++)
1453 if (buffer
[i
] == ',') buffer
[i
] = '.';
1454 fprintf( m_pstream
, buffer
);
1457 m_currentBlue
= blue
;
1458 m_currentGreen
= green
;
1462 int size
= m_font
.GetPointSize();
1464 long by
= y
+ (long)floor( double(size
) * 2.0 / 3.0 ); // approximate baseline
1466 // FIXME only correct for 90 degrees
1467 fprintf(m_pstream
, "%d %d moveto\n",
1468 LogicalToDeviceX((wxCoord
)(x
+ size
)), LogicalToDeviceY((wxCoord
)by
) );
1471 sprintf(buffer
, "%.8f rotate\n", angle
);
1473 for (i
= 0; i
< 100; i
++)
1474 if (buffer
[i
] == ',') buffer
[i
] = '.';
1475 fprintf(m_pstream
, buffer
);
1477 fprintf( m_pstream
, "(" );
1478 const wxWX2MBbuf textbuf
= text
.mb_str();
1479 size_t len
= strlen(textbuf
);
1480 for (i
= 0; i
< len
; i
++)
1482 int c
= (unsigned char) textbuf
[i
];
1483 if (c
== ')' || c
== '(' || c
== '\\')
1485 /* Cope with special characters */
1486 fprintf( m_pstream
, "\\" );
1487 fputc(c
, m_pstream
);
1489 else if ( c
>= 128 )
1491 /* Cope with character codes > 127 */
1492 fprintf(m_pstream
, "\\%o", c
);
1496 fputc(c
, m_pstream
);
1500 fprintf( m_pstream
, ") show\n" );
1502 sprintf( buffer
, "%.8f rotate\n", -angle
);
1503 for (i
= 0; i
< 100; i
++)
1504 if (buffer
[i
] == ',') buffer
[i
] = '.';
1505 fprintf( m_pstream
, buffer
);
1507 if (m_font
.GetUnderlined())
1509 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1512 GetTextExtent(text
, &w
, &h
);
1521 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1522 m_underlineThickness
,
1523 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1524 for (i
= 0; i
< 100; i
++)
1525 if (buffer
[i
] == ',') buffer
[i
] = '.';
1526 fprintf( m_pstream
, buffer
);
1529 CalcBoundingBox( x
, y
);
1530 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1533 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1535 m_backgroundBrush
= brush
;
1538 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1540 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1543 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1545 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1549 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1552 wxNode
*node
= points
->GetFirst();
1553 p
= (wxPoint
*)node
->GetData();
1557 node
= node
->GetNext();
1558 p
= (wxPoint
*)node
->GetData();
1561 x3
= a
= (double)(x1
+ c
) / 2;
1562 y3
= b
= (double)(y1
+ d
) / 2;
1568 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1569 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1571 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1572 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1574 while ((node
= node
->GetNext()) != NULL
)
1576 q
= (wxPoint
*)node
->GetData();
1584 x3
= (double)(x2
+ c
) / 2;
1585 y3
= (double)(y2
+ d
) / 2;
1588 "%d %d %d %d %d %d DrawSplineSection\n",
1589 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1590 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1591 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1593 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1594 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1598 At this point, (x2,y2) and (c,d) are the position of the
1599 next-to-last and last point respectively, in the point list
1605 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1608 wxCoord
wxPostScriptDC::GetCharWidth() const
1610 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1611 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1615 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1617 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1619 m_signX
= (xLeftRight
? 1 : -1);
1620 m_signY
= (yBottomUp
? 1 : -1);
1622 // FIXME there is no such function in MSW nor in OS2/PM
1623 #if !defined(__WXMSW__) && !defined(__WXPM__)
1624 ComputeScaleAndOrigin();
1628 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1630 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1636 wxDC::SetDeviceOrigin( x
, h
-y
);
1639 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1641 wxPaperSize id
= m_printData
.GetPaperId();
1643 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1645 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1651 w
= paper
->GetSizeDeviceUnits().x
;
1652 h
= paper
->GetSizeDeviceUnits().y
;
1655 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1662 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1663 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1666 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1668 wxPaperSize id
= m_printData
.GetPaperId();
1670 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1672 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1678 w
= paper
->GetWidth() / 10;
1679 h
= paper
->GetHeight() / 10;
1682 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1689 if (width
) *width
= w
;
1690 if (height
) *height
= h
;
1693 // Resolution in pixels per logical inch
1694 wxSize
wxPostScriptDC::GetPPI(void) const
1696 return wxSize((int)(72 * ms_PSScaleFactor
),
1697 (int)(72 * ms_PSScaleFactor
));
1701 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1703 wxCHECK_MSG( m_ok
, FALSE
, wxT("invalid postscript dc") );
1705 if (m_printData
.GetFilename() == wxT(""))
1707 wxString filename
= wxGetTempFileName( wxT("ps") );
1708 m_printData
.SetFilename(filename
);
1711 m_pstream
= wxFopen( m_printData
.GetFilename().c_str(), wxT("w+") ); // FIXME: use fn_str() here under Unicode?
1715 wxLogError( _("Cannot open file for PostScript printing!"));
1722 fprintf( m_pstream
, "%%!PS-Adobe-2.0\n" );
1723 fprintf( m_pstream
, "%%%%Title: %s\n", (const char *) m_title
.ToAscii() );
1724 fprintf( m_pstream
, "%%%%Creator: wxWindows PostScript renderer\n" );
1725 fprintf( m_pstream
, "%%%%CreationDate: %s\n", (const char *) wxNow().ToAscii() );
1726 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1727 fprintf( m_pstream
, "%%%%Orientation: Landscape\n" );
1729 fprintf( m_pstream
, "%%%%Orientation: Portrait\n" );
1731 // fprintf( m_pstream, "%%%%Pages: %d\n", (wxPageNumber - 1) );
1734 switch (m_printData
.GetPaperId())
1736 case wxPAPER_LETTER
: paper
= "Letter"; break; // Letter: paper ""; 8 1/2 by 11 inches
1737 case wxPAPER_LEGAL
: paper
= "Legal"; break; // Legal, 8 1/2 by 14 inches
1738 case wxPAPER_A4
: paper
= "A4"; break; // A4 Sheet, 210 by 297 millimeters
1739 case wxPAPER_TABLOID
: paper
= "Tabloid"; break; // Tabloid, 11 by 17 inches
1740 case wxPAPER_LEDGER
: paper
= "Ledger"; break; // Ledger, 17 by 11 inches
1741 case wxPAPER_STATEMENT
: paper
= "Statement"; break; // Statement, 5 1/2 by 8 1/2 inches
1742 case wxPAPER_EXECUTIVE
: paper
= "Executive"; break; // Executive, 7 1/4 by 10 1/2 inches
1743 case wxPAPER_A3
: paper
= "A3"; break; // A3 sheet, 297 by 420 millimeters
1744 case wxPAPER_A5
: paper
= "A5"; break; // A5 sheet, 148 by 210 millimeters
1745 case wxPAPER_B4
: paper
= "B4"; break; // B4 sheet, 250 by 354 millimeters
1746 case wxPAPER_B5
: paper
= "B5"; break; // B5 sheet, 182-by-257-millimeter paper
1747 case wxPAPER_FOLIO
: paper
= "Folio"; break; // Folio, 8-1/2-by-13-inch paper
1748 case wxPAPER_QUARTO
: paper
= "Quaro"; break; // Quarto, 215-by-275-millimeter paper
1749 case wxPAPER_10X14
: paper
= "10x14"; break; // 10-by-14-inch sheet
1750 default: paper
= "A4";
1752 fprintf( m_pstream
, "%%%%DocumentPaperSizes: %s\n", paper
);
1753 fprintf( m_pstream
, "%%%%EndComments\n\n" );
1755 fprintf( m_pstream
, "%%%%BeginProlog\n" );
1756 fprintf( m_pstream
, wxPostScriptHeaderConicTo
);
1757 fprintf( m_pstream
, wxPostScriptHeaderEllipse
);
1758 fprintf( m_pstream
, wxPostScriptHeaderEllipticArc
);
1759 fprintf( m_pstream
, wxPostScriptHeaderColourImage
);
1762 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO1
);
1763 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO2
);
1765 if (wxPostScriptHeaderSpline
)
1766 fprintf( m_pstream
, wxPostScriptHeaderSpline
);
1767 fprintf( m_pstream
, "%%%%EndProlog\n" );
1769 SetBrush( *wxBLACK_BRUSH
);
1770 SetPen( *wxBLACK_PEN
);
1771 SetBackground( *wxWHITE_BRUSH
);
1772 SetTextForeground( *wxBLACK
);
1774 // set origin according to paper size
1775 SetDeviceOrigin( 0,0 );
1783 void wxPostScriptDC::EndDoc ()
1785 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1790 fprintf( m_pstream
, "grestore\n" );
1793 fclose( m_pstream
);
1794 m_pstream
= (FILE *) NULL
;
1797 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1798 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1799 double wx_printer_scale_x
, wx_printer_scale_y
;
1801 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1802 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1804 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1805 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1807 // Compute the bounding box. Note that it is in the default user
1808 // coordinate system, thus we have to convert the values.
1809 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1810 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1811 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1812 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1814 // LOG2DEV may have changed the minimum to maximum vice versa
1815 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1816 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1818 // account for used scaling (boundingbox is before scaling in ps-file)
1819 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1820 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1822 wxCoord llx
, lly
, urx
, ury
;
1823 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1824 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1825 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1826 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1827 // (end of bounding box computation)
1830 // If we're landscape, our sense of "x" and "y" is reversed.
1831 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1834 tmp
= llx
; llx
= lly
; lly
= tmp
;
1835 tmp
= urx
; urx
= ury
; ury
= tmp
;
1837 // We need either the two lines that follow, or we need to subtract
1838 // min_x from real_translate_y, which is commented out below.
1839 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1840 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1843 // The Adobe specifications call for integers; we round as to make
1844 // the bounding larger.
1846 "%%%%BoundingBox: %d %d %d %d\n",
1847 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1848 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1850 // To check the correctness of the bounding box, postscript commands
1851 // to draw a box corresponding to the bounding box are generated below.
1852 // But since we typically don't want to print such a box, the postscript
1853 // commands are generated within comments. These lines appear before any
1854 // adjustment of scale, rotation, or translation, and hence are in the
1855 // default user coordinates.
1856 fprintf( m_pstream
, "%% newpath\n" );
1857 fprintf( m_pstream
, "%% %d %d moveto\n", llx
, lly
);
1858 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, lly
);
1859 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, ury
);
1860 fprintf( m_pstream
, "%% %d %d lineto closepath stroke\n", llx
, ury
);
1863 #if defined(__X__) || defined(__WXGTK__)
1864 if (m_ok
&& (m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
1867 command
+= m_printData
.GetPrinterCommand();
1868 command
+= wxT(" ");
1869 command
+= m_printData
.GetFilename();
1871 wxExecute( command
, TRUE
);
1872 wxRemoveFile( m_printData
.GetFilename() );
1877 void wxPostScriptDC::StartPage()
1879 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1881 fprintf( m_pstream
, "%%%%Page: %d\n", wxPageNumber
++ );
1883 // What is this one supposed to do? RR.
1884 // *m_pstream << "matrix currentmatrix\n";
1886 // Added by Chris Breeze
1888 // Each page starts with an "initgraphics" which resets the
1889 // transformation and so we need to reset the origin
1890 // (and rotate the page for landscape printing)
1893 wxCoord translate_x
, translate_y
;
1894 double scale_x
, scale_y
;
1896 translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1897 translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1899 scale_x
= m_printData
.GetPrinterScaleX();
1900 scale_y
= m_printData
.GetPrinterScaleY();
1902 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1905 GetSize( (int*) NULL
, &h
);
1907 fprintf( m_pstream
, "90 rotate\n" );
1909 // I copied this one from a PostScript tutorial, but to no avail. RR.
1910 // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" );
1914 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1915 scale_y
/ ms_PSScaleFactor
);
1916 for (int i
= 0; i
< 100; i
++)
1917 if (buffer
[i
] == ',') buffer
[i
] = '.';
1918 fprintf( m_pstream
, buffer
);
1920 fprintf( m_pstream
, "%d %d translate\n", translate_x
, translate_y
);
1923 void wxPostScriptDC::EndPage ()
1925 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1927 fprintf( m_pstream
, "showpage\n" );
1930 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1931 wxCoord fwidth
, wxCoord fheight
,
1933 wxCoord xsrc
, wxCoord ysrc
,
1934 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
1936 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, wxT("invalid postscript dc") );
1938 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1940 /* blit into a bitmap */
1941 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1943 memDC
.SelectObject(bitmap
);
1944 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1945 memDC
.SelectObject(wxNullBitmap
);
1947 /* draw bitmap. scaling and positioning is done there */
1948 DrawBitmap( bitmap
, xdest
, ydest
);
1953 wxCoord
wxPostScriptDC::GetCharHeight() const
1956 return m_font
.GetPointSize();
1961 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1962 wxCoord
*x
, wxCoord
*y
,
1963 wxCoord
*descent
, wxCoord
*externalLeading
,
1964 wxFont
*theFont
) const
1966 wxFont
*fontToUse
= theFont
;
1968 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1970 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1972 if (string
.IsEmpty())
1980 int dpi
= GetResolution();
1981 PangoContext
*context
= pango_ft2_get_context ( dpi
, dpi
);
1983 pango_context_set_language (context
, pango_language_from_string ("en_US"));
1984 pango_context_set_base_dir (context
, PANGO_DIRECTION_LTR
);
1986 PangoLayout
*layout
= pango_layout_new (context
);
1988 PangoFontDescription
*desc
= fontToUse
->GetNativeFontInfo()->description
;
1989 pango_layout_set_font_description(layout
, desc
);
1991 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1992 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1994 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1995 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1996 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1998 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
2000 PangoRectangle rect
;
2001 pango_layout_line_get_extents(line
, NULL
, &rect
);
2003 if (x
) (*x
) = (wxCoord
) ( m_scaleX
* rect
.width
/ PANGO_SCALE
);
2004 if (y
) (*y
) = (wxCoord
) ( m_scaleY
* rect
.height
/ PANGO_SCALE
);
2007 // Do something about metrics here
2010 if (externalLeading
) (*externalLeading
) = 0; // ??
2012 g_object_unref( G_OBJECT( layout
) );
2016 const wxWX2MBbuf strbuf
= string
.mb_str();
2018 #if !wxUSE_AFM_FOR_POSTSCRIPT
2019 /* Provide a VERY rough estimate (avoid using it).
2020 * Produces accurate results for mono-spaced font
2021 * such as Courier (aka wxMODERN) */
2026 height
= fontToUse
->GetPointSize();
2029 *x
= strlen (strbuf
) * height
* 72 / 120;
2031 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
2032 if (descent
) *descent
= 0;
2033 if (externalLeading
) *externalLeading
= 0;
2036 /* method for calculating string widths in postscript:
2037 / read in the AFM (adobe font metrics) file for the
2038 / actual font, parse it and extract the character widths
2039 / and also the descender. this may be improved, but for now
2040 / it works well. the AFM file is only read in if the
2041 / font is changed. this may be chached in the future.
2042 / calls to GetTextExtent with the font unchanged are rather
2045 / for each font and style used there is an AFM file necessary.
2046 / currently i have only files for the roman font family.
2047 / I try to get files for the other ones!
2049 / CAVE: the size of the string is currently always calculated
2050 / in 'points' (1/72 of an inch). this should later on be
2051 / changed to depend on the mapping mode.
2052 / CAVE: the path to the AFM files must be set before calling this
2053 / function. this is usually done by a call like the following:
2054 / wxSetAFMPath("d:\\wxw161\\afm\\");
2058 / wxPostScriptDC dc(NULL, TRUE);
2060 / wxSetAFMPath("d:\\wxw161\\afm\\");
2061 / dc.StartDoc("Test");
2064 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
2065 / dc.GetTextExtent("Hallo",&w,&h);
2070 / by steve (stefan.hammes@urz.uni-heidelberg.de)
2072 / updated: 14.05.95 */
2074 /* these static vars are for storing the state between calls */
2075 static int lastFamily
= INT_MIN
;
2076 static int lastSize
= INT_MIN
;
2077 static int lastStyle
= INT_MIN
;
2078 static int lastWeight
= INT_MIN
;
2079 static int lastDescender
= INT_MIN
;
2080 static int lastWidths
[256]; /* widths of the characters */
2082 double UnderlinePosition
= 0.0;
2083 double UnderlineThickness
= 0.0;
2085 // Get actual parameters
2086 int Family
= fontToUse
->GetFamily();
2087 int Size
= fontToUse
->GetPointSize();
2088 int Style
= fontToUse
->GetStyle();
2089 int Weight
= fontToUse
->GetWeight();
2091 // If we have another font, read the font-metrics
2092 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
2094 // Store actual values
2095 lastFamily
= Family
;
2098 lastWeight
= Weight
;
2100 const wxChar
*name
= NULL
;
2107 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBoO.afm");
2108 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBo.afm");
2109 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("CourO.afm");
2110 else name
= wxT("Cour.afm");
2115 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBoO.afm");
2116 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBo.afm");
2117 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("TimesO.afm");
2118 else name
= wxT("TimesRo.afm");
2123 name
= wxT("Zapf.afm");
2130 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBoO.afm");
2131 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBo.afm");
2132 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("HelvO.afm");
2133 else name
= wxT("Helv.afm");
2138 FILE *afmFile
= NULL
;
2140 // Get the directory of the AFM files
2142 if (!m_printData
.GetFontMetricPath().IsEmpty())
2144 afmName
= m_printData
.GetFontMetricPath();
2145 afmName
<< wxFILE_SEP_PATH
<< name
;
2146 afmFile
= wxFopen(afmName
,wxT("r"));
2149 #if defined(__UNIX__) && !defined(__VMS__)
2152 afmName
= wxGetDataDir();
2153 afmName
<< wxFILE_SEP_PATH
2154 #if defined(__LINUX__) || defined(__FREEBSD__)
2155 << wxT("gs_afm") << wxFILE_SEP_PATH
2157 << wxT("afm") << wxFILE_SEP_PATH
2160 afmFile
= wxFopen(afmName
,wxT("r"));
2164 /* 2. open and process the file
2165 / a short explanation of the AFM format:
2166 / we have for each character a line, which gives its size
2169 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2171 / that means, we have a character with ascii code 63, and width
2172 / (444/1000 * fontSize) points.
2173 / the other data is ignored for now!
2175 / when the font has changed, we read in the right AFM file and store the
2176 / character widths in an array, which is processed below (see point 3.). */
2179 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2180 wxLogDebug( wxT(" using approximate values"));
2181 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2182 lastDescender
= -150; /* dito. */
2186 /* init the widths array */
2187 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2188 /* some variables for holding parts of a line */
2189 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2190 char upString
[30], utString
[30], encString
[50];
2193 /* read in the file and parse it */
2194 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2196 /* A.) check for descender definition */
2197 if (strncmp(line
,"Descender",9)==0)
2199 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2200 (strcmp(descString
,"Descender")!=0))
2202 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2205 /* JC 1.) check for UnderlinePosition */
2206 else if(strncmp(line
,"UnderlinePosition",17)==0)
2208 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2209 (strcmp(upString
,"UnderlinePosition")!=0))
2211 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2214 /* JC 2.) check for UnderlineThickness */
2215 else if(strncmp(line
,"UnderlineThickness",18)==0)
2217 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2218 (strcmp(utString
,"UnderlineThickness")!=0))
2220 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2223 /* JC 3.) check for EncodingScheme */
2224 else if(strncmp(line
,"EncodingScheme",14)==0)
2226 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2227 (strcmp(utString
,"EncodingScheme")!=0))
2229 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2231 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2233 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2234 afmName
.c_str(),line
, encString
);
2237 /* B.) check for char-width */
2238 else if(strncmp(line
,"C ",2)==0)
2240 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2242 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2244 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2246 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2248 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2249 if (ascii
>=0 && ascii
<256)
2251 lastWidths
[ascii
] = cWidth
; /* store width */
2255 /* MATTHEW: this happens a lot; don't print an error */
2256 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2259 /* C.) ignore other entries. */
2263 /* hack to compute correct values for german 'Umlaute'
2264 / the correct way would be to map the character names
2265 / like 'adieresis' to corresp. positions of ISOEnc and read
2266 / these values from AFM files, too. Maybe later ... */
2267 lastWidths
[196] = lastWidths
['A']; // Ä
2268 lastWidths
[228] = lastWidths
['a']; // ä
2269 lastWidths
[214] = lastWidths
['O']; // Ö
2270 lastWidths
[246] = lastWidths
['o']; // ö
2271 lastWidths
[220] = lastWidths
['U']; // Ü
2272 lastWidths
[252] = lastWidths
['u']; // ü
2273 lastWidths
[223] = lastWidths
[251]; // ß
2275 /* JC: calculate UnderlineThickness/UnderlinePosition */
2277 // VS: dirty, but is there any better solution?
2279 pt
= (double*) &m_underlinePosition
;
2280 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2281 pt
= (double*) &m_underlineThickness
;
2282 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2287 /* 3. now the font metrics are read in, calc size this
2288 / is done by adding the widths of the characters in the
2289 / string. they are given in 1/1000 of the size! */
2292 wxCoord height
=Size
; /* by default */
2294 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2296 if(lastWidths
[*p
]== INT_MIN
)
2298 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2299 sum
+= lastWidths
[' ']; /* assume space */
2303 sum
+= lastWidths
[*p
];
2307 double widthSum
= sum
;
2309 widthSum
/= 1000.0F
;
2311 /* add descender to height (it is usually a negative value) */
2312 //if (lastDescender != INT_MIN)
2314 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2316 // - commented by V. Slavik - height already contains descender in it
2317 // (judging from few experiments)
2319 /* return size values */
2321 *x
= (wxCoord
)widthSum
;
2325 /* return other parameters */
2328 if(lastDescender
!=INT_MIN
)
2330 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2338 /* currently no idea how to calculate this! */
2339 if (externalLeading
) *externalLeading
= 0;
2347 #if WXWIN_COMPATIBILITY_2_2
2348 WXDLLEXPORT wxPrintSetupData
*wxThePrintSetupData
= 0;
2350 void wxInitializePrintSetupData(bool init
)
2354 // gets initialized in the constructor
2355 wxThePrintSetupData
= new wxPrintSetupData
;
2359 delete wxThePrintSetupData
;
2361 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2365 // A module to allow initialization/cleanup of PostScript-related
2366 // things without calling these functions from app.cpp.
2368 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2370 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2372 wxPostScriptModule() {}
2377 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2379 bool wxPostScriptModule::OnInit()
2381 wxInitializePrintSetupData();
2386 void wxPostScriptModule::OnExit()
2388 wxInitializePrintSetupData(FALSE
);
2391 // WXWIN_COMPATIBILITY_2_2
2397 // wxUSE_PRINTING_ARCHITECTURE