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 #if WXWIN_COMPATIBILITY_2_2
322 bool wxPostScriptDC::Create( const wxString
&output
, bool interactive
, wxWindow
*parent
)
325 data
.SetFilename( output
);
326 data
.SetPrintMode( wxPRINT_MODE_FILE
);
330 wxPrintDialogData
ddata( data
);
331 wxPrintDialog
dialog( parent
, &data
);
332 dialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
333 if (dialog
.ShowModal() != wxID_OK
)
338 data
= dialog
.GetPrintDialogData().GetPrintData();
346 bool wxPostScriptDC::Ok() const
351 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
353 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
355 if (m_clipping
) DestroyClippingRegion();
357 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
366 "closepath clip newpath\n",
367 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
368 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
369 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
370 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
374 void wxPostScriptDC::DestroyClippingRegion()
376 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
381 fprintf( m_pstream
, "grestore\n" );
384 wxDC::DestroyClippingRegion();
387 void wxPostScriptDC::Clear()
389 wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
392 bool wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
394 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
398 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
400 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
404 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
406 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
409 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
411 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
413 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
422 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
423 LogicalToDeviceX(x2
), LogicalToDeviceY (y2
) );
425 CalcBoundingBox( x1
, y1
);
426 CalcBoundingBox( x2
, y2
);
429 #define RAD2DEG 57.29577951308
431 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
433 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
435 wxCoord dx
= x1
- xc
;
436 wxCoord dy
= y1
- yc
;
437 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
438 double alpha1
, alpha2
;
440 if (x1
== x2
&& y1
== y2
)
445 else if (radius
== 0.0)
447 alpha1
= alpha2
= 0.0;
451 alpha1
= (x1
- xc
== 0) ?
452 (y1
- yc
< 0) ? 90.0 : -90.0 :
453 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
454 alpha2
= (x2
- xc
== 0) ?
455 (y2
- yc
< 0) ? 90.0 : -90.0 :
456 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
458 while (alpha1
<= 0) alpha1
+= 360;
459 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
460 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
461 while (alpha2
> 360) alpha2
-= 360;
463 if (m_brush
.GetStyle() != wxTRANSPARENT
)
469 "%d %d %d %d %d %d ellipse\n"
473 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
474 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
476 CalcBoundingBox( xc
-radius
, yc
-radius
);
477 CalcBoundingBox( xc
+radius
, yc
+radius
);
480 if (m_pen
.GetStyle() != wxTRANSPARENT
)
486 "%d %d %d %d %d %d ellipse\n"
490 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
491 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
493 CalcBoundingBox( xc
-radius
, yc
-radius
);
494 CalcBoundingBox( xc
+radius
, yc
+radius
);
498 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
500 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
502 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
503 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
509 DrawEllipse(x
,y
,w
,h
);
513 if (m_brush
.GetStyle () != wxTRANSPARENT
)
519 "%d %d %d %d %d %d true ellipticarc\n",
520 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
522 CalcBoundingBox( x
,y
);
523 CalcBoundingBox( x
+w
, y
+h
);
526 if (m_pen
.GetStyle () != wxTRANSPARENT
)
532 "%d %d %d %d %d %d false ellipticarc\n",
533 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2), LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2), (wxCoord
)sa
, (wxCoord
)ea
);
535 CalcBoundingBox( x
,y
);
536 CalcBoundingBox( x
+w
, y
+h
);
540 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
542 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
544 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
553 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
554 LogicalToDeviceX(x
+1), LogicalToDeviceY(y
) );
556 CalcBoundingBox( x
, y
);
559 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int WXUNUSED(fillStyle
))
561 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
565 if (m_brush
.GetStyle () != wxTRANSPARENT
)
569 fprintf( m_pstream
, "newpath\n" );
571 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
572 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
574 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
576 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
578 for (int i
= 1; i
< n
; i
++)
580 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
581 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
583 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
585 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
588 fprintf( m_pstream
, "fill\n" );
591 if (m_pen
.GetStyle () != wxTRANSPARENT
)
595 fprintf( m_pstream
, "newpath\n" );
597 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
598 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
600 fprintf( m_pstream
, "%d %d moveto\n", xx
, yy
);
602 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
604 for (int i
= 1; i
< n
; i
++)
606 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
607 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
609 fprintf( m_pstream
, "%d %d lineto\n", xx
, yy
);
611 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
614 fprintf( m_pstream
, "closepath\n" );
615 fprintf( m_pstream
, "stroke\n" );
619 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
621 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
623 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
630 for ( i
=0; i
<n
; i
++ )
632 CalcBoundingBox( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
638 LogicalToDeviceX(points
[0].x
+xoffset
), LogicalToDeviceY(points
[0].y
+yoffset
) );
640 for (i
= 1; i
< n
; i
++)
644 LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
) );
647 fprintf( m_pstream
, "stroke\n" );
650 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
652 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
654 if (m_brush
.GetStyle () != wxTRANSPARENT
)
666 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
667 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
668 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
669 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
671 CalcBoundingBox( x
, y
);
672 CalcBoundingBox( x
+ width
, y
+ height
);
675 if (m_pen
.GetStyle () != wxTRANSPARENT
)
687 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
688 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
689 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
690 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
692 CalcBoundingBox( x
, y
);
693 CalcBoundingBox( x
+ width
, y
+ height
);
697 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
699 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
703 // Now, a negative radius is interpreted to mean
704 // 'the proportion of the smallest X or Y dimension'
705 double smallest
= 0.0;
710 radius
= (-radius
* smallest
);
713 wxCoord rad
= (wxCoord
) radius
;
715 if (m_brush
.GetStyle () != wxTRANSPARENT
)
719 /* Draw rectangle anticlockwise */
722 "%d %d %d 90 180 arc\n"
724 "%d %d %d 180 270 arc\n"
726 "%d %d %d 270 0 arc\n"
728 "%d %d %d 0 90 arc\n"
732 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
733 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
734 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
735 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
736 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
737 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
738 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
739 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
741 CalcBoundingBox( x
, y
);
742 CalcBoundingBox( x
+ width
, y
+ height
);
745 if (m_pen
.GetStyle () != wxTRANSPARENT
)
749 /* Draw rectangle anticlockwise */
752 "%d %d %d 90 180 arc\n"
754 "%d %d %d 180 270 arc\n"
756 "%d %d %d 270 0 arc\n"
758 "%d %d %d 0 90 arc\n"
762 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
763 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
764 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
765 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
766 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
767 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
768 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
769 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
771 CalcBoundingBox( x
, y
);
772 CalcBoundingBox( x
+ width
, y
+ height
);
776 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
778 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
780 if (m_brush
.GetStyle () != wxTRANSPARENT
)
786 "%d %d %d %d 0 360 ellipse\n"
788 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
789 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
791 CalcBoundingBox( x
- width
, y
- height
);
792 CalcBoundingBox( x
+ width
, y
+ height
);
795 if (m_pen
.GetStyle () != wxTRANSPARENT
)
801 "%d %d %d %d 0 360 ellipse\n"
803 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
804 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
806 CalcBoundingBox( x
- width
, y
- height
);
807 CalcBoundingBox( x
+ width
, y
+ height
);
811 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
813 DrawBitmap( icon
, x
, y
, TRUE
);
816 /* this has to be char, not wxChar */
817 static char hexArray
[] = "0123456789ABCDEF";
818 static void LocalDecToHex( int dec
, char *buf
)
820 int firstDigit
= (int)(dec
/16.0);
821 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
822 buf
[0] = hexArray
[firstDigit
];
823 buf
[1] = hexArray
[secondDigit
];
827 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
829 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
831 if (!bitmap
.Ok()) return;
833 wxImage image
= bitmap
.ConvertToImage();
835 if (!image
.Ok()) return;
837 wxCoord w
= image
.GetWidth();
838 wxCoord h
= image
.GetHeight();
840 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
841 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
843 wxCoord xx
= LogicalToDeviceX(x
);
844 wxCoord yy
= LogicalToDeviceY(y
+ bitmap
.GetHeight());
847 "/origstate save def\n"
849 "/pix %d string def\n"
850 "/grays %d string def\n"
857 "{currentfile pix readhexstring pop}\n"
858 "false 3 colorimage\n",
859 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
862 for (int j
= 0; j
< h
; j
++)
864 for (int i
= 0; i
< w
; i
++)
867 LocalDecToHex( image
.GetRed(i
,j
), buffer
);
868 fprintf( m_pstream
, buffer
);
869 LocalDecToHex( image
.GetGreen(i
,j
), buffer
);
870 fprintf( m_pstream
, buffer
);
871 LocalDecToHex( image
.GetBlue(i
,j
), buffer
);
872 fprintf( m_pstream
, buffer
);
874 fprintf( m_pstream
, "\n" );
877 fprintf( m_pstream
, "end\n" );
878 fprintf( m_pstream
, "origstate restore\n" );
881 void wxPostScriptDC::SetFont( const wxFont
& font
)
883 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
885 if (!font
.Ok()) return;
890 int Style
= m_font
.GetStyle();
891 int Weight
= m_font
.GetWeight();
894 switch (m_font
.GetFamily())
899 if (Style
== wxITALIC
)
901 if (Weight
== wxBOLD
)
902 name
= "/Courier-BoldOblique";
904 name
= "/Courier-Oblique";
908 if (Weight
== wxBOLD
)
909 name
= "/Courier-Bold";
917 if (Style
== wxITALIC
)
919 if (Weight
== wxBOLD
)
920 name
= "/Times-BoldItalic";
922 name
= "/Times-Italic";
926 if (Weight
== wxBOLD
)
927 name
= "/Times-Bold";
929 name
= "/Times-Roman";
935 name
= "/ZapfChancery-MediumItalic";
943 if (Style
== wxITALIC
)
945 if (Weight
== wxBOLD
)
946 name
= "/Helvetica-BoldOblique";
948 name
= "/Helvetica-Oblique";
952 if (Weight
== wxBOLD
)
953 name
= "/Helvetica-Bold";
961 fprintf( m_pstream
, name
);
962 fprintf( m_pstream
, " reencodeISO def\n" );
963 fprintf( m_pstream
, name
);
964 fprintf( m_pstream
, " findfont\n" );
967 sprintf( buffer
, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
968 // this is a hack - we must scale font size (in pts) according to m_scaleY but
969 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
970 // to 1/1000th of pt and then back.
971 for (int i
= 0; i
< 100; i
++)
972 if (buffer
[i
] == ',') buffer
[i
] = '.';
973 fprintf( m_pstream
, buffer
);
977 void wxPostScriptDC::SetPen( const wxPen
& pen
)
979 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
981 if (!pen
.Ok()) return;
983 int oldStyle
= m_pen
.GetStyle();
990 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
992 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
994 for (int i
= 0; i
< 100; i
++)
995 if (buffer
[i
] == ',') buffer
[i
] = '.';
996 fprintf( m_pstream
, buffer
);
1000 Line style - WRONG: 2nd arg is OFFSET
1002 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1003 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1004 ter is not number of values in the array of the first one, but an offset
1005 into this description of the pattern. I mean a real *offset* not index
1006 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1007 will be first black line *2* units wxCoord, then space 4 units, then the
1008 pattern of *3* units black, 4 units space will be repeated.
1011 static const char *dotted
= "[2 5] 2";
1012 static const char *short_dashed
= "[4 4] 2";
1013 static const char *wxCoord_dashed
= "[4 8] 2";
1014 static const char *dotted_dashed
= "[6 6 2 6] 4";
1016 const char *psdash
= (char *) NULL
;
1017 switch (m_pen
.GetStyle())
1019 case wxDOT
: psdash
= dotted
; break;
1020 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1021 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1022 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1025 default: psdash
= "[] 0"; break;
1028 if (oldStyle
!= m_pen
.GetStyle())
1030 fprintf( m_pstream
, psdash
);
1031 fprintf( m_pstream
," setdash\n" );
1035 unsigned char red
= m_pen
.GetColour().Red();
1036 unsigned char blue
= m_pen
.GetColour().Blue();
1037 unsigned char green
= m_pen
.GetColour().Green();
1041 // Anything not white is black
1042 if (! (red
== (unsigned char) 255 &&
1043 blue
== (unsigned char) 255 &&
1044 green
== (unsigned char) 255) )
1046 red
= (unsigned char) 0;
1047 green
= (unsigned char) 0;
1048 blue
= (unsigned char) 0;
1053 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1055 double redPS
= (double)(red
) / 255.0;
1056 double bluePS
= (double)(blue
) / 255.0;
1057 double greenPS
= (double)(green
) / 255.0;
1061 "%.8f %.8f %.8f setrgbcolor\n",
1062 redPS
, greenPS
, bluePS
);
1063 for (int i
= 0; i
< 100; i
++)
1064 if (buffer
[i
] == ',') buffer
[i
] = '.';
1065 fprintf( m_pstream
, buffer
);
1068 m_currentBlue
= blue
;
1069 m_currentGreen
= green
;
1073 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1075 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1077 if (!brush
.Ok()) return;
1082 unsigned char red
= m_brush
.GetColour().Red();
1083 unsigned char blue
= m_brush
.GetColour().Blue();
1084 unsigned char green
= m_brush
.GetColour().Green();
1088 // Anything not white is black
1089 if (! (red
== (unsigned char) 255 &&
1090 blue
== (unsigned char) 255 &&
1091 green
== (unsigned char) 255) )
1093 red
= (unsigned char) 0;
1094 green
= (unsigned char) 0;
1095 blue
= (unsigned char) 0;
1100 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1102 double redPS
= (double)(red
) / 255.0;
1103 double bluePS
= (double)(blue
) / 255.0;
1104 double greenPS
= (double)(green
) / 255.0;
1108 "%.8f %.8f %.8f setrgbcolor\n",
1109 redPS
, greenPS
, bluePS
);
1110 for (int i
= 0; i
< 100; i
++)
1111 if (buffer
[i
] == ',') buffer
[i
] = '.';
1112 fprintf( m_pstream
, buffer
);
1115 m_currentBlue
= blue
;
1116 m_currentGreen
= green
;
1122 #define PANGO_ENABLE_ENGINE
1124 #include "wx/gtk/private.h"
1125 #include "wx/fontutil.h"
1126 #include "gtk/gtk.h"
1127 #include <pango/pangoft2.h>
1128 #include <freetype/ftglyph.h>
1130 #ifndef FT_Outline_Decompose
1131 FT_EXPORT( FT_Error
) FT_Outline_Decompose(
1132 FT_Outline
* outline
,
1133 const FT_Outline_Funcs
* interface
,
1137 typedef struct _OutlineInfo OutlineInfo
;
1138 struct _OutlineInfo
{
1142 static int paps_move_to( FT_Vector
* to
,
1145 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1146 fprintf(outline_info
->file
, "%d %d moveto\n",
1152 static int paps_line_to( FT_Vector
* to
,
1155 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1156 fprintf(outline_info
->file
, "%d %d lineto\n",
1162 static int paps_conic_to( FT_Vector
* control
,
1166 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1167 fprintf(outline_info
->file
, "%d %d %d %d conicto\n",
1175 static int paps_cubic_to( FT_Vector
* control1
,
1176 FT_Vector
* control2
,
1180 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1181 fprintf(outline_info
->file
,
1182 "%d %d %d %d %d %d curveto\n",
1192 void draw_bezier_outline(FILE *file
,
1194 FT_UInt glyph_index
,
1200 FT_Int load_flags
= FT_LOAD_NO_BITMAP
;
1203 FT_Outline_Funcs outlinefunc
=
1211 OutlineInfo outline_info
;
1212 outline_info
.file
= file
;
1214 fprintf(file
, "gsave\n");
1215 fprintf(file
, "%d %d translate\n", pos_x
, pos_y
);
1216 // FT2 scales outlines to 26.6 pixels so the code below
1217 // should read 26600 instead of the 60000.
1218 fprintf(file
, "%d 60000 div %d 60000 div scale\n", scale_x
, scale_y
);
1219 fprintf(file
, "0 0 0 setrgbcolor\n");
1221 FT_Load_Glyph(face
, glyph_index
, load_flags
);
1222 FT_Get_Glyph (face
->glyph
, &glyph
);
1223 FT_Outline_Decompose (&(((FT_OutlineGlyph
)glyph
)->outline
),
1224 &outlinefunc
, &outline_info
);
1225 fprintf(file
, "closepath fill grestore \n");
1227 FT_Done_Glyph (glyph
);
1232 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1234 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1237 int dpi
= GetResolution();
1239 PangoContext
*context
= pango_ft2_get_context ( dpi
, dpi
);
1241 pango_context_set_language (context
, pango_language_from_string ("en_US"));
1242 pango_context_set_base_dir (context
, PANGO_DIRECTION_LTR
);
1244 pango_context_set_font_description (context
, m_font
.GetNativeFontInfo()->description
);
1246 PangoLayout
*layout
= pango_layout_new (context
);
1248 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( text
);
1250 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) );
1252 pango_layout_set_text( layout
, (const char*) buffer
, strlen(buffer
) );
1254 PangoRectangle rect
;
1255 pango_layout_get_extents(layout
, NULL
, &rect
);
1257 int xx
= x
* PANGO_SCALE
;
1258 int yy
= y
* PANGO_SCALE
+ (rect
.height
*2/3);
1260 int scale_x
= LogicalToDeviceXRel( 1000 );
1261 int scale_y
= LogicalToDeviceYRel( 1000 );
1263 // Loop over lines in layout
1264 int num_lines
= pango_layout_get_line_count( layout
);
1265 for (int i
= 0; i
< num_lines
; i
++)
1267 PangoLayoutLine
*line
= pango_layout_get_line( layout
, i
);
1269 // Loop over runs in line
1270 GSList
*runs_list
= line
->runs
;
1273 PangoLayoutRun
*run
= (PangoLayoutRun
*) runs_list
->data
;
1274 PangoItem
*item
= run
->item
;
1275 PangoGlyphString
*glyphs
= run
->glyphs
;
1276 PangoAnalysis
*analysis
= &item
->analysis
;
1277 PangoFont
*font
= analysis
->font
;
1278 FT_Face ft_face
= pango_ft2_font_get_face(font
);
1280 int num_glyphs
= glyphs
->num_glyphs
;
1281 for (int glyph_idx
= 0; glyph_idx
< num_glyphs
; glyph_idx
++)
1283 PangoGlyphGeometry geometry
= glyphs
->glyphs
[glyph_idx
].geometry
;
1284 int pos_x
= xx
+ geometry
.x_offset
;
1285 int pos_y
= yy
- geometry
.y_offset
;
1286 xx
+= geometry
.width
;
1288 draw_bezier_outline( m_pstream
, ft_face
,
1289 (FT_UInt
)(glyphs
->glyphs
[glyph_idx
].glyph
),
1290 LogicalToDeviceX( pos_x
/ PANGO_SCALE
),
1291 LogicalToDeviceY( pos_y
/ PANGO_SCALE
),
1294 runs_list
= runs_list
->next
;
1298 g_object_unref( G_OBJECT( layout
) );
1300 wxCoord text_w
, text_h
, text_descent
;
1302 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1304 // VZ: this seems to be unnecessary, so taking it out for now, if it
1305 // doesn't create any problems, remove this comment entirely
1306 //SetFont( m_font );
1308 if (m_textForegroundColour
.Ok())
1310 unsigned char red
= m_textForegroundColour
.Red();
1311 unsigned char blue
= m_textForegroundColour
.Blue();
1312 unsigned char green
= m_textForegroundColour
.Green();
1316 // Anything not white is black
1317 if (! (red
== (unsigned char) 255 &&
1318 blue
== (unsigned char) 255 &&
1319 green
== (unsigned char) 255))
1321 red
= (unsigned char) 0;
1322 green
= (unsigned char) 0;
1323 blue
= (unsigned char) 0;
1327 // maybe setgray here ?
1328 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1330 double redPS
= (double)(red
) / 255.0;
1331 double bluePS
= (double)(blue
) / 255.0;
1332 double greenPS
= (double)(green
) / 255.0;
1336 "%.8f %.8f %.8f setrgbcolor\n",
1337 redPS
, greenPS
, bluePS
);
1338 for (int i
= 0; i
< 100; i
++)
1339 if (buffer
[i
] == ',') buffer
[i
] = '.';
1340 fprintf( m_pstream
, buffer
);
1343 m_currentBlue
= blue
;
1344 m_currentGreen
= green
;
1348 int size
= m_font
.GetPointSize();
1350 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1351 // commented by V. Slavik and replaced by accurate version
1352 // - note that there is still rounding error in text_descent!
1353 wxCoord by
= y
+ size
- text_descent
; // baseline
1354 fprintf( m_pstream
, "%d %d moveto\n", LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1356 fprintf( m_pstream
, "(" );
1357 const wxWX2MBbuf textbuf
= text
.mb_str();
1358 size_t len
= strlen(textbuf
);
1360 for (i
= 0; i
< len
; i
++)
1362 int c
= (unsigned char) textbuf
[i
];
1363 if (c
== ')' || c
== '(' || c
== '\\')
1365 /* Cope with special characters */
1366 fprintf( m_pstream
, "\\" );
1367 fputc(c
, m_pstream
);
1369 else if ( c
>= 128 )
1371 /* Cope with character codes > 127 */
1372 fprintf(m_pstream
, "\\%o", c
);
1376 fputc(c
, m_pstream
);
1380 fprintf( m_pstream
, ") show\n" );
1382 if (m_font
.GetUnderlined())
1384 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1394 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1395 m_underlineThickness
,
1396 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1397 for (i
= 0; i
< 100; i
++)
1398 if (buffer
[i
] == ',') buffer
[i
] = '.';
1399 fprintf( m_pstream
, buffer
);
1402 CalcBoundingBox( x
, y
);
1403 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1407 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1411 DoDrawText(text
, x
, y
);
1415 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1419 if (m_textForegroundColour
.Ok())
1421 unsigned char red
= m_textForegroundColour
.Red();
1422 unsigned char blue
= m_textForegroundColour
.Blue();
1423 unsigned char green
= m_textForegroundColour
.Green();
1427 // Anything not white is black
1428 if (! (red
== (unsigned char) 255 &&
1429 blue
== (unsigned char) 255 &&
1430 green
== (unsigned char) 255))
1432 red
= (unsigned char) 0;
1433 green
= (unsigned char) 0;
1434 blue
= (unsigned char) 0;
1438 // maybe setgray here ?
1439 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1441 double redPS
= (double)(red
) / 255.0;
1442 double bluePS
= (double)(blue
) / 255.0;
1443 double greenPS
= (double)(green
) / 255.0;
1447 "%.8f %.8f %.8f setrgbcolor\n",
1448 redPS
, greenPS
, bluePS
);
1449 for (int i
= 0; i
< 100; i
++)
1450 if (buffer
[i
] == ',') buffer
[i
] = '.';
1451 fprintf( m_pstream
, buffer
);
1454 m_currentBlue
= blue
;
1455 m_currentGreen
= green
;
1459 int size
= m_font
.GetPointSize();
1461 long by
= y
+ (long)floor( double(size
) * 2.0 / 3.0 ); // approximate baseline
1463 // FIXME only correct for 90 degrees
1464 fprintf(m_pstream
, "%d %d moveto\n",
1465 LogicalToDeviceX((wxCoord
)(x
+ size
)), LogicalToDeviceY((wxCoord
)by
) );
1468 sprintf(buffer
, "%.8f rotate\n", angle
);
1470 for (i
= 0; i
< 100; i
++)
1471 if (buffer
[i
] == ',') buffer
[i
] = '.';
1472 fprintf(m_pstream
, buffer
);
1474 fprintf( m_pstream
, "(" );
1475 const wxWX2MBbuf textbuf
= text
.mb_str();
1476 size_t len
= strlen(textbuf
);
1477 for (i
= 0; i
< len
; i
++)
1479 int c
= (unsigned char) textbuf
[i
];
1480 if (c
== ')' || c
== '(' || c
== '\\')
1482 /* Cope with special characters */
1483 fprintf( m_pstream
, "\\" );
1484 fputc(c
, m_pstream
);
1486 else if ( c
>= 128 )
1488 /* Cope with character codes > 127 */
1489 fprintf(m_pstream
, "\\%o", c
);
1493 fputc(c
, m_pstream
);
1497 fprintf( m_pstream
, ") show\n" );
1499 sprintf( buffer
, "%.8f rotate\n", -angle
);
1500 for (i
= 0; i
< 100; i
++)
1501 if (buffer
[i
] == ',') buffer
[i
] = '.';
1502 fprintf( m_pstream
, buffer
);
1504 if (m_font
.GetUnderlined())
1506 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1509 GetTextExtent(text
, &w
, &h
);
1518 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1519 m_underlineThickness
,
1520 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1521 for (i
= 0; i
< 100; i
++)
1522 if (buffer
[i
] == ',') buffer
[i
] = '.';
1523 fprintf( m_pstream
, buffer
);
1526 CalcBoundingBox( x
, y
);
1527 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1530 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1532 m_backgroundBrush
= brush
;
1535 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1537 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1540 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1542 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1546 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1549 wxNode
*node
= points
->First();
1550 p
= (wxPoint
*)node
->Data();
1554 node
= node
->Next();
1555 p
= (wxPoint
*)node
->Data();
1558 x3
= a
= (double)(x1
+ c
) / 2;
1559 y3
= b
= (double)(y1
+ d
) / 2;
1565 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1566 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1568 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1569 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1571 while ((node
= node
->Next()) != NULL
)
1573 q
= (wxPoint
*)node
->Data();
1581 x3
= (double)(x2
+ c
) / 2;
1582 y3
= (double)(y2
+ d
) / 2;
1585 "%d %d %d %d %d %d DrawSplineSection\n",
1586 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1587 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1588 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1590 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1591 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1595 At this point, (x2,y2) and (c,d) are the position of the
1596 next-to-last and last point respectively, in the point list
1602 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1605 wxCoord
wxPostScriptDC::GetCharWidth() const
1607 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1608 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1612 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1614 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1616 m_signX
= (xLeftRight
? 1 : -1);
1617 m_signY
= (yBottomUp
? 1 : -1);
1619 // FIXME there is no such function in MSW nor in OS2/PM
1620 #if !defined(__WXMSW__) && !defined(__WXPM__)
1621 ComputeScaleAndOrigin();
1625 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1627 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1633 wxDC::SetDeviceOrigin( x
, h
-y
);
1636 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1638 wxPaperSize id
= m_printData
.GetPaperId();
1640 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1642 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1648 w
= paper
->GetSizeDeviceUnits().x
;
1649 h
= paper
->GetSizeDeviceUnits().y
;
1652 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1659 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1660 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1663 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1665 wxPaperSize id
= m_printData
.GetPaperId();
1667 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1669 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1675 w
= paper
->GetWidth() / 10;
1676 h
= paper
->GetHeight() / 10;
1679 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1686 if (width
) *width
= w
;
1687 if (height
) *height
= h
;
1690 // Resolution in pixels per logical inch
1691 wxSize
wxPostScriptDC::GetPPI(void) const
1693 return wxSize((int)(72 * ms_PSScaleFactor
),
1694 (int)(72 * ms_PSScaleFactor
));
1698 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1700 wxCHECK_MSG( m_ok
, FALSE
, wxT("invalid postscript dc") );
1702 if (m_printData
.GetFilename() == "")
1704 wxString filename
= wxGetTempFileName("ps");
1705 m_printData
.SetFilename(filename
);
1708 m_pstream
= wxFopen( m_printData
.GetFilename().c_str(), wxT("w+") ); // FIXME: use fn_str() here under Unicode?
1712 wxLogError( _("Cannot open file for PostScript printing!"));
1719 fprintf( m_pstream
, "%%!PS-Adobe-2.0\n" );
1720 fprintf( m_pstream
, "%%%%Title: %s\n", (const char *) m_title
.ToAscii() );
1721 fprintf( m_pstream
, "%%%%Creator: wxWindows PostScript renderer\n" );
1722 fprintf( m_pstream
, "%%%%CreationDate: %s\n", (const char *) wxNow().ToAscii() );
1723 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1724 fprintf( m_pstream
, "%%%%Orientation: Landscape\n" );
1726 fprintf( m_pstream
, "%%%%Orientation: Portrait\n" );
1728 // fprintf( m_pstream, "%%%%Pages: %d\n", (wxPageNumber - 1) );
1731 switch (m_printData
.GetPaperId())
1733 case wxPAPER_LETTER
: paper
= "Letter"; break; // Letter: paper ""; 8 1/2 by 11 inches
1734 case wxPAPER_LEGAL
: paper
= "Legal"; break; // Legal, 8 1/2 by 14 inches
1735 case wxPAPER_A4
: paper
= "A4"; break; // A4 Sheet, 210 by 297 millimeters
1736 case wxPAPER_TABLOID
: paper
= "Tabloid"; break; // Tabloid, 11 by 17 inches
1737 case wxPAPER_LEDGER
: paper
= "Ledger"; break; // Ledger, 17 by 11 inches
1738 case wxPAPER_STATEMENT
: paper
= "Statement"; break; // Statement, 5 1/2 by 8 1/2 inches
1739 case wxPAPER_EXECUTIVE
: paper
= "Executive"; break; // Executive, 7 1/4 by 10 1/2 inches
1740 case wxPAPER_A3
: paper
= "A3"; break; // A3 sheet, 297 by 420 millimeters
1741 case wxPAPER_A5
: paper
= "A5"; break; // A5 sheet, 148 by 210 millimeters
1742 case wxPAPER_B4
: paper
= "B4"; break; // B4 sheet, 250 by 354 millimeters
1743 case wxPAPER_B5
: paper
= "B5"; break; // B5 sheet, 182-by-257-millimeter paper
1744 case wxPAPER_FOLIO
: paper
= "Folio"; break; // Folio, 8-1/2-by-13-inch paper
1745 case wxPAPER_QUARTO
: paper
= "Quaro"; break; // Quarto, 215-by-275-millimeter paper
1746 case wxPAPER_10X14
: paper
= "10x14"; break; // 10-by-14-inch sheet
1747 default: paper
= "A4";
1749 fprintf( m_pstream
, "%%%%DocumentPaperSizes: %s\n", paper
);
1750 fprintf( m_pstream
, "%%%%EndComments\n\n" );
1752 fprintf( m_pstream
, "%%%%BeginProlog\n" );
1753 fprintf( m_pstream
, wxPostScriptHeaderConicTo
);
1754 fprintf( m_pstream
, wxPostScriptHeaderEllipse
);
1755 fprintf( m_pstream
, wxPostScriptHeaderEllipticArc
);
1756 fprintf( m_pstream
, wxPostScriptHeaderColourImage
);
1758 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO1
);
1759 fprintf( m_pstream
, wxPostScriptHeaderReencodeISO2
);
1761 if (wxPostScriptHeaderSpline
)
1762 fprintf( m_pstream
, wxPostScriptHeaderSpline
);
1763 fprintf( m_pstream
, "%%%%EndProlog\n" );
1765 SetBrush( *wxBLACK_BRUSH
);
1766 SetPen( *wxBLACK_PEN
);
1767 SetBackground( *wxWHITE_BRUSH
);
1768 SetTextForeground( *wxBLACK
);
1770 // set origin according to paper size
1771 SetDeviceOrigin( 0,0 );
1779 void wxPostScriptDC::EndDoc ()
1781 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1786 fprintf( m_pstream
, "grestore\n" );
1789 fclose( m_pstream
);
1790 m_pstream
= (FILE *) NULL
;
1793 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1794 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1795 double wx_printer_scale_x
, wx_printer_scale_y
;
1797 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1798 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1800 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1801 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1803 // Compute the bounding box. Note that it is in the default user
1804 // coordinate system, thus we have to convert the values.
1805 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1806 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1807 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1808 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1810 // LOG2DEV may have changed the minimum to maximum vice versa
1811 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1812 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1814 // account for used scaling (boundingbox is before scaling in ps-file)
1815 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1816 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1818 wxCoord llx
, lly
, urx
, ury
;
1819 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1820 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1821 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1822 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1823 // (end of bounding box computation)
1826 // If we're landscape, our sense of "x" and "y" is reversed.
1827 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1830 tmp
= llx
; llx
= lly
; lly
= tmp
;
1831 tmp
= urx
; urx
= ury
; ury
= tmp
;
1833 // We need either the two lines that follow, or we need to subtract
1834 // min_x from real_translate_y, which is commented out below.
1835 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1836 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1839 // The Adobe specifications call for integers; we round as to make
1840 // the bounding larger.
1842 "%%%%BoundingBox: %d %d %d %d\n",
1843 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1844 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1846 // To check the correctness of the bounding box, postscript commands
1847 // to draw a box corresponding to the bounding box are generated below.
1848 // But since we typically don't want to print such a box, the postscript
1849 // commands are generated within comments. These lines appear before any
1850 // adjustment of scale, rotation, or translation, and hence are in the
1851 // default user coordinates.
1852 fprintf( m_pstream
, "%% newpath\n" );
1853 fprintf( m_pstream
, "%% %d %d moveto\n", llx
, lly
);
1854 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, lly
);
1855 fprintf( m_pstream
, "%% %d %d lineto\n", urx
, ury
);
1856 fprintf( m_pstream
, "%% %d %d lineto closepath stroke\n", llx
, ury
);
1859 #if defined(__X__) || defined(__WXGTK__)
1860 if (m_ok
&& (m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
1863 command
+= m_printData
.GetPrinterCommand();
1864 command
+= wxT(" ");
1865 command
+= m_printData
.GetFilename();
1867 wxExecute( command
, TRUE
);
1868 wxRemoveFile( m_printData
.GetFilename() );
1873 void wxPostScriptDC::StartPage()
1875 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1877 fprintf( m_pstream
, "%%%%Page: %d\n", wxPageNumber
++ );
1879 // What is this one supposed to do? RR.
1880 // *m_pstream << "matrix currentmatrix\n";
1882 // Added by Chris Breeze
1884 // Each page starts with an "initgraphics" which resets the
1885 // transformation and so we need to reset the origin
1886 // (and rotate the page for landscape printing)
1889 wxCoord translate_x
, translate_y
;
1890 double scale_x
, scale_y
;
1892 translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1893 translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1895 scale_x
= m_printData
.GetPrinterScaleX();
1896 scale_y
= m_printData
.GetPrinterScaleY();
1898 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1901 GetSize( (int*) NULL
, &h
);
1903 fprintf( m_pstream
, "90 rotate\n" );
1905 // I copied this one from a PostScript tutorial, but to no avail. RR.
1906 // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" );
1910 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
1911 scale_y
/ ms_PSScaleFactor
);
1912 for (int i
= 0; i
< 100; i
++)
1913 if (buffer
[i
] == ',') buffer
[i
] = '.';
1914 fprintf( m_pstream
, buffer
);
1916 fprintf( m_pstream
, "%d %d translate\n", translate_x
, translate_y
);
1919 void wxPostScriptDC::EndPage ()
1921 wxCHECK_RET( m_ok
&& m_pstream
, wxT("invalid postscript dc") );
1923 fprintf( m_pstream
, "showpage\n" );
1926 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
1927 wxCoord fwidth
, wxCoord fheight
,
1929 wxCoord xsrc
, wxCoord ysrc
,
1930 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
1932 wxCHECK_MSG( m_ok
&& m_pstream
, FALSE
, wxT("invalid postscript dc") );
1934 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1936 /* blit into a bitmap */
1937 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
1939 memDC
.SelectObject(bitmap
);
1940 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1941 memDC
.SelectObject(wxNullBitmap
);
1943 /* draw bitmap. scaling and positioning is done there */
1944 DrawBitmap( bitmap
, xdest
, ydest
);
1949 wxCoord
wxPostScriptDC::GetCharHeight() const
1952 return m_font
.GetPointSize();
1957 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
1958 wxCoord
*x
, wxCoord
*y
,
1959 wxCoord
*descent
, wxCoord
*externalLeading
,
1960 wxFont
*theFont
) const
1962 wxFont
*fontToUse
= theFont
;
1964 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1966 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
1968 if (string
.IsEmpty())
1976 int dpi
= GetResolution();
1977 PangoContext
*context
= pango_ft2_get_context ( dpi
, dpi
);
1979 pango_context_set_language (context
, pango_language_from_string ("en_US"));
1980 pango_context_set_base_dir (context
, PANGO_DIRECTION_LTR
);
1982 PangoLayout
*layout
= pango_layout_new (context
);
1984 PangoFontDescription
*desc
= fontToUse
->GetNativeFontInfo()->description
;
1985 pango_layout_set_font_description(layout
, desc
);
1987 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1988 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1990 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1991 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1992 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1994 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1996 PangoRectangle rect
;
1997 pango_layout_line_get_extents(line
, NULL
, &rect
);
1999 if (x
) (*x
) = (wxCoord
) ( m_scaleX
* rect
.width
/ PANGO_SCALE
);
2000 if (y
) (*y
) = (wxCoord
) ( m_scaleY
* rect
.height
/ PANGO_SCALE
);
2003 // Do something about metrics here
2006 if (externalLeading
) (*externalLeading
) = 0; // ??
2008 g_object_unref( G_OBJECT( layout
) );
2012 const wxWX2MBbuf strbuf
= string
.mb_str();
2014 #if !wxUSE_AFM_FOR_POSTSCRIPT
2015 /* Provide a VERY rough estimate (avoid using it).
2016 * Produces accurate results for mono-spaced font
2017 * such as Courier (aka wxMODERN) */
2022 height
= fontToUse
->GetPointSize();
2025 *x
= strlen (strbuf
) * height
* 72 / 120;
2027 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
2028 if (descent
) *descent
= 0;
2029 if (externalLeading
) *externalLeading
= 0;
2032 /* method for calculating string widths in postscript:
2033 / read in the AFM (adobe font metrics) file for the
2034 / actual font, parse it and extract the character widths
2035 / and also the descender. this may be improved, but for now
2036 / it works well. the AFM file is only read in if the
2037 / font is changed. this may be chached in the future.
2038 / calls to GetTextExtent with the font unchanged are rather
2041 / for each font and style used there is an AFM file necessary.
2042 / currently i have only files for the roman font family.
2043 / I try to get files for the other ones!
2045 / CAVE: the size of the string is currently always calculated
2046 / in 'points' (1/72 of an inch). this should later on be
2047 / changed to depend on the mapping mode.
2048 / CAVE: the path to the AFM files must be set before calling this
2049 / function. this is usually done by a call like the following:
2050 / wxSetAFMPath("d:\\wxw161\\afm\\");
2054 / wxPostScriptDC dc(NULL, TRUE);
2056 / wxSetAFMPath("d:\\wxw161\\afm\\");
2057 / dc.StartDoc("Test");
2060 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
2061 / dc.GetTextExtent("Hallo",&w,&h);
2066 / by steve (stefan.hammes@urz.uni-heidelberg.de)
2068 / updated: 14.05.95 */
2070 /* these static vars are for storing the state between calls */
2071 static int lastFamily
= INT_MIN
;
2072 static int lastSize
= INT_MIN
;
2073 static int lastStyle
= INT_MIN
;
2074 static int lastWeight
= INT_MIN
;
2075 static int lastDescender
= INT_MIN
;
2076 static int lastWidths
[256]; /* widths of the characters */
2078 double UnderlinePosition
= 0.0;
2079 double UnderlineThickness
= 0.0;
2081 // Get actual parameters
2082 int Family
= fontToUse
->GetFamily();
2083 int Size
= fontToUse
->GetPointSize();
2084 int Style
= fontToUse
->GetStyle();
2085 int Weight
= fontToUse
->GetWeight();
2087 // If we have another font, read the font-metrics
2088 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
2090 // Store actual values
2091 lastFamily
= Family
;
2094 lastWeight
= Weight
;
2096 const char *name
= NULL
;
2103 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBoO.afm";
2104 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "CourBo.afm";
2105 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "CourO.afm";
2106 else name
= "Cour.afm";
2111 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBoO.afm";
2112 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "TimesBo.afm";
2113 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "TimesO.afm";
2114 else name
= "TimesRo.afm";
2126 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBoO.afm";
2127 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= "HelvBo.afm";
2128 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= "HelvO.afm";
2129 else name
= "Helv.afm";
2134 FILE *afmFile
= NULL
;
2136 // Get the directory of the AFM files
2138 if (!m_printData
.GetFontMetricPath().IsEmpty())
2140 afmName
= m_printData
.GetFontMetricPath();
2141 afmName
<< wxFILE_SEP_PATH
<< name
;
2142 afmFile
= wxFopen(afmName
,wxT("r"));
2145 #if defined(__UNIX__) && !defined(__VMS__)
2148 afmName
= wxGetDataDir();
2149 afmName
<< wxFILE_SEP_PATH
2150 #if defined(__LINUX__) || defined(__FREEBSD__)
2151 << wxT("gs_afm") << wxFILE_SEP_PATH
2153 << wxT("afm") << wxFILE_SEP_PATH
2156 afmFile
= wxFopen(afmName
,wxT("r"));
2160 /* 2. open and process the file
2161 / a short explanation of the AFM format:
2162 / we have for each character a line, which gives its size
2165 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2167 / that means, we have a character with ascii code 63, and width
2168 / (444/1000 * fontSize) points.
2169 / the other data is ignored for now!
2171 / when the font has changed, we read in the right AFM file and store the
2172 / character widths in an array, which is processed below (see point 3.). */
2175 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2176 wxLogDebug( wxT(" using approximate values"));
2177 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2178 lastDescender
= -150; /* dito. */
2182 /* init the widths array */
2183 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2184 /* some variables for holding parts of a line */
2185 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2186 char upString
[30], utString
[30], encString
[50];
2189 /* read in the file and parse it */
2190 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2192 /* A.) check for descender definition */
2193 if (strncmp(line
,"Descender",9)==0)
2195 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2196 (strcmp(descString
,"Descender")!=0))
2198 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2201 /* JC 1.) check for UnderlinePosition */
2202 else if(strncmp(line
,"UnderlinePosition",17)==0)
2204 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2205 (strcmp(upString
,"UnderlinePosition")!=0))
2207 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2210 /* JC 2.) check for UnderlineThickness */
2211 else if(strncmp(line
,"UnderlineThickness",18)==0)
2213 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2214 (strcmp(utString
,"UnderlineThickness")!=0))
2216 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2219 /* JC 3.) check for EncodingScheme */
2220 else if(strncmp(line
,"EncodingScheme",14)==0)
2222 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2223 (strcmp(utString
,"EncodingScheme")!=0))
2225 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2227 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2229 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2230 afmName
.c_str(),line
, encString
);
2233 /* B.) check for char-width */
2234 else if(strncmp(line
,"C ",2)==0)
2236 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2238 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2240 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2242 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2244 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2245 if (ascii
>=0 && ascii
<256)
2247 lastWidths
[ascii
] = cWidth
; /* store width */
2251 /* MATTHEW: this happens a lot; don't print an error */
2252 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2255 /* C.) ignore other entries. */
2259 /* hack to compute correct values for german 'Umlaute'
2260 / the correct way would be to map the character names
2261 / like 'adieresis' to corresp. positions of ISOEnc and read
2262 / these values from AFM files, too. Maybe later ... */
2263 lastWidths
[196] = lastWidths
['A']; // Ä
2264 lastWidths
[228] = lastWidths
['a']; // ä
2265 lastWidths
[214] = lastWidths
['O']; // Ö
2266 lastWidths
[246] = lastWidths
['o']; // ö
2267 lastWidths
[220] = lastWidths
['U']; // Ü
2268 lastWidths
[252] = lastWidths
['u']; // ü
2269 lastWidths
[223] = lastWidths
[251]; // ß
2271 /* JC: calculate UnderlineThickness/UnderlinePosition */
2273 // VS: dirty, but is there any better solution?
2275 pt
= (double*) &m_underlinePosition
;
2276 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2277 pt
= (double*) &m_underlineThickness
;
2278 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2283 /* 3. now the font metrics are read in, calc size this
2284 / is done by adding the widths of the characters in the
2285 / string. they are given in 1/1000 of the size! */
2288 wxCoord height
=Size
; /* by default */
2290 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2292 if(lastWidths
[*p
]== INT_MIN
)
2294 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2295 sum
+= lastWidths
[' ']; /* assume space */
2299 sum
+= lastWidths
[*p
];
2303 double widthSum
= sum
;
2305 widthSum
/= 1000.0F
;
2307 /* add descender to height (it is usually a negative value) */
2308 //if (lastDescender != INT_MIN)
2310 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2312 // - commented by V. Slavik - height already contains descender in it
2313 // (judging from few experiments)
2315 /* return size values */
2317 *x
= (wxCoord
)widthSum
;
2321 /* return other parameters */
2324 if(lastDescender
!=INT_MIN
)
2326 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2334 /* currently no idea how to calculate this! */
2335 if (externalLeading
) *externalLeading
= 0;
2343 #if WXWIN_COMPATIBILITY_2_2
2344 WXDLLEXPORT wxPrintSetupData
*wxThePrintSetupData
= 0;
2346 void wxInitializePrintSetupData(bool init
)
2350 // gets initialized in the constructor
2351 wxThePrintSetupData
= new wxPrintSetupData
;
2355 delete wxThePrintSetupData
;
2357 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2361 // A module to allow initialization/cleanup of PostScript-related
2362 // things without calling these functions from app.cpp.
2364 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2366 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2368 wxPostScriptModule() {}
2373 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2375 bool wxPostScriptModule::OnInit()
2377 wxInitializePrintSetupData();
2382 void wxPostScriptModule::OnExit()
2384 wxInitializePrintSetupData(FALSE
);
2387 // WXWIN_COMPATIBILITY_2_2
2393 // wxUSE_PRINTING_ARCHITECTURE