1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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"
39 #include "wx/generic/prntdlgg.h"
41 #include "wx/filefn.h"
42 #if WXWIN_COMPATIBILITY_2_2
43 #include "wx/window.h"
44 #include "wx/printdlg.h"
69 //-----------------------------------------------------------------------------
70 // start and end of document/page
71 //-----------------------------------------------------------------------------
73 static const char *wxPostScriptHeaderConicTo
= "\
77 /conic_cntrl_y exch def\n\
78 /conic_cntrl_x exch def\n\
82 /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\
83 /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\
84 /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\
85 /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\
86 p1_x p1_y p2_x p2_y to_x to_y curveto\n\
90 static const char *wxPostScriptHeaderEllipse
= "\
91 /ellipsedict 8 dict def\n\
92 ellipsedict /mtrx matrix put\n\
96 /startangle exch def\n\
101 /savematrix mtrx currentmatrix def\n\
104 0 0 1 startangle endangle arc\n\
105 savematrix setmatrix\n\
110 static const char *wxPostScriptHeaderEllipticArc
= "\
111 /ellipticarcdict 8 dict def\n\
112 ellipticarcdict /mtrx matrix put\n\
114 { ellipticarcdict begin\n\
116 /endangle exch def\n\
117 /startangle exch def\n\
122 /savematrix mtrx currentmatrix def\n\
125 do_fill { 0 0 moveto } if\n\
126 0 0 1 startangle endangle arc\n\
127 savematrix setmatrix\n\
128 do_fill { fill }{ stroke } ifelse\n\
132 static const char *wxPostScriptHeaderSpline
= "\
133 /DrawSplineSection {\n\
140 /xa x1 x2 x1 sub 0.666667 mul add def\n\
141 /ya y1 y2 y1 sub 0.666667 mul add def\n\
142 /xb x3 x2 x3 sub 0.666667 mul add def\n\
143 /yb y3 y2 y3 sub 0.666667 mul add def\n\
145 xa ya xb yb x3 y3 curveto\n\
149 static const char *wxPostScriptHeaderColourImage
= "\
150 % define 'colorimage' if it isn't defined\n\
151 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
153 /colorimage where % do we know about 'colorimage'?\n\
154 { pop } % yes: pop off the 'dict' returned\n\
155 { % no: define one\n\
156 /colortogray { % define an RGB->I function\n\
157 /rgbdata exch store % call input 'rgbdata'\n\
158 rgbdata length 3 idiv\n\
159 /npixls exch store\n\
161 0 1 npixls 1 sub {\n\
163 rgbdata rgbindx get 20 mul % Red\n\
164 rgbdata rgbindx 1 add get 32 mul % Green\n\
165 rgbdata rgbindx 2 add get 12 mul % Blue\n\
166 add add 64 idiv % I = .5G + .31R + .18B\n\
168 /rgbindx rgbindx 3 add store\n\
170 grays 0 npixls getinterval\n\
173 % Utility procedure for colorimage operator.\n\
174 % This procedure takes two procedures off the\n\
175 % stack and merges them into a single procedure.\n\
177 /mergeprocs { % def\n\
196 /colorimage { % def\n\
197 pop pop % remove 'false 3' operands\n\
198 {colortogray} mergeprocs\n\
201 } ifelse % end of 'false' case\n\
206 static char wxPostScriptHeaderReencodeISO1
[] =
208 "dup dup findfont dup length dict begin\n"
209 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
210 "/Encoding ISOLatin1Encoding def\n"
211 "currentdict end definefont\n"
213 "/ISOLatin1Encoding [\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 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
218 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
219 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
220 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
221 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
222 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
223 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
224 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
225 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
226 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
227 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
228 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
230 static char wxPostScriptHeaderReencodeISO2
[] =
231 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
232 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
233 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
234 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
235 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
236 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
237 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
238 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
239 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
240 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
241 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
242 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
243 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
244 "/yacute/thorn/ydieresis\n"
248 //-------------------------------------------------------------------------------
250 //-------------------------------------------------------------------------------
252 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
254 float wxPostScriptDC::ms_PSScaleFactor
= 1.0;
256 void wxPostScriptDC::SetResolution(int ppi
)
258 ms_PSScaleFactor
= (float)ppi
/ 72.0;
261 int wxPostScriptDC::GetResolution()
263 return (int)(ms_PSScaleFactor
* 72.0);
266 //-------------------------------------------------------------------------------
268 wxPostScriptDC::wxPostScriptDC ()
270 m_pstream
= (FILE*) NULL
;
280 m_underlinePosition
= 0.0;
281 m_underlineThickness
= 0.0;
283 m_signX
= 1; // default x-axis left to right
284 m_signY
= -1; // default y-axis bottom up -> top down
287 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
289 m_pstream
= (FILE*) NULL
;
299 m_underlinePosition
= 0.0;
300 m_underlineThickness
= 0.0;
302 m_signX
= 1; // default x-axis left to right
303 m_signY
= -1; // default y-axis bottom up -> top down
305 m_printData
= printData
;
310 wxPostScriptDC::~wxPostScriptDC ()
315 m_pstream
= (FILE*) NULL
;
319 #if WXWIN_COMPATIBILITY_2_2
320 bool wxPostScriptDC::Create( const wxString
&output
, bool interactive
, wxWindow
*parent
)
323 data
.SetFilename( output
);
324 data
.SetPrintMode( wxPRINT_MODE_FILE
);
328 wxPrintDialogData
ddata( data
);
329 wxPrintDialog
dialog( parent
, &data
);
330 dialog
.GetPrintDialogData().SetSetupDialog(true);
331 if (dialog
.ShowModal() != wxID_OK
)
336 data
= dialog
.GetPrintDialogData().GetPrintData();
344 bool wxPostScriptDC::Ok() const
349 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
351 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
353 if (m_clipping
) DestroyClippingRegion();
355 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
359 PsPrintf( wxT("gsave\n newpath\n")
360 wxT("%d %d moveto\n")
361 wxT("%d %d lineto\n")
362 wxT("%d %d lineto\n")
363 wxT("%d %d lineto\n")
364 wxT("closepath clip newpath\n"),
365 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
366 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
367 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
368 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
372 void wxPostScriptDC::DestroyClippingRegion()
374 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
379 PsPrint( "grestore\n" );
382 wxDC::DestroyClippingRegion();
385 void wxPostScriptDC::Clear()
387 // This should fail silently to avoid unnecessary
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
, wxT("invalid postscript dc") );
413 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
417 PsPrintf( wxT("newpath\n")
418 wxT("%d %d moveto\n")
419 wxT("%d %d lineto\n")
421 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
422 LogicalToDeviceX(x2
), LogicalToDeviceY (y2
) );
424 CalcBoundingBox( x1
, y1
);
425 CalcBoundingBox( x2
, y2
);
428 #define RAD2DEG 57.29577951308
430 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
432 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
434 wxCoord dx
= x1
- xc
;
435 wxCoord dy
= y1
- yc
;
436 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
437 double alpha1
, alpha2
;
439 if (x1
== x2
&& y1
== y2
)
444 else if (radius
== 0.0)
446 alpha1
= alpha2
= 0.0;
450 alpha1
= (x1
- xc
== 0) ?
451 (y1
- yc
< 0) ? 90.0 : -90.0 :
452 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
453 alpha2
= (x2
- xc
== 0) ?
454 (y2
- yc
< 0) ? 90.0 : -90.0 :
455 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
457 while (alpha1
<= 0) alpha1
+= 360;
458 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
459 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
460 while (alpha2
> 360) alpha2
-= 360;
462 if (m_brush
.GetStyle() != wxTRANSPARENT
)
466 PsPrintf( wxT("newpath\n")
467 wxT("%d %d %d %d %d %d ellipse\n")
468 wxT("%d %d lineto\n")
471 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
472 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
474 CalcBoundingBox( xc
-radius
, yc
-radius
);
475 CalcBoundingBox( xc
+radius
, yc
+radius
);
478 if (m_pen
.GetStyle() != wxTRANSPARENT
)
482 PsPrintf( wxT("newpath\n")
483 wxT("%d %d %d %d %d %d ellipse\n")
484 wxT("%d %d lineto\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
, 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
)
514 PsPrintf( wxT("newpath\n")
515 wxT("%d %d %d %d %d %d true ellipticarc\n"),
516 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
517 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
518 (wxCoord
)sa
, (wxCoord
)ea
);
520 CalcBoundingBox( x
,y
);
521 CalcBoundingBox( x
+w
, y
+h
);
524 if (m_pen
.GetStyle () != wxTRANSPARENT
)
528 PsPrintf( wxT("newpath\n")
529 wxT("%d %d %d %d %d %d false ellipticarc\n"),
530 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
531 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
532 (wxCoord
)sa
, (wxCoord
)ea
);
534 CalcBoundingBox( x
,y
);
535 CalcBoundingBox( x
+w
, y
+h
);
539 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
541 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
543 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
547 PsPrintf( wxT("newpath\n")
548 wxT("%d %d moveto\n")
549 wxT("%d %d lineto\n")
551 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
552 LogicalToDeviceX(x
+1), LogicalToDeviceY(y
) );
554 CalcBoundingBox( x
, y
);
557 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
559 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
563 if (m_brush
.GetStyle () != wxTRANSPARENT
)
567 PsPrint( "newpath\n" );
569 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
570 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
572 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
574 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
576 for (int i
= 1; i
< n
; i
++)
578 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
579 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
581 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
583 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
586 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
589 if (m_pen
.GetStyle () != wxTRANSPARENT
)
593 PsPrint( "newpath\n" );
595 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
596 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
598 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
600 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
602 for (int i
= 1; i
< n
; i
++)
604 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
605 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
607 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
609 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
612 PsPrint( "closepath\n" );
613 PsPrint( "stroke\n" );
617 void wxPostScriptDC::DoDrawPolyPolygon (int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
619 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
623 if (m_brush
.GetStyle () != wxTRANSPARENT
)
627 PsPrint( "newpath\n" );
630 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
632 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
633 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
635 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
637 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
639 for (int j
= 1; j
< count
[i
]; j
++)
641 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
642 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
644 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
646 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
649 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
652 if (m_pen
.GetStyle () != wxTRANSPARENT
)
656 PsPrint( "newpath\n" );
659 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
661 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
662 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
664 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
666 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
668 for (int j
= 1; j
< count
[i
]; j
++)
670 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
671 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
673 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
675 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
678 PsPrint( "closepath\n" );
679 PsPrint( "stroke\n" );
683 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
685 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
687 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
694 for ( i
=0; i
<n
; i
++ )
696 CalcBoundingBox( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
699 PsPrintf( wxT("newpath\n")
700 wxT("%d %d moveto\n"),
701 LogicalToDeviceX(points
[0].x
+xoffset
),
702 LogicalToDeviceY(points
[0].y
+yoffset
) );
704 for (i
= 1; i
< n
; i
++)
706 PsPrintf( wxT("%d %d lineto\n"),
707 LogicalToDeviceX(points
[i
].x
+xoffset
),
708 LogicalToDeviceY(points
[i
].y
+yoffset
) );
711 PsPrint( "stroke\n" );
714 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
716 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
718 if (m_brush
.GetStyle () != wxTRANSPARENT
)
722 PsPrintf( wxT("newpath\n")
723 wxT("%d %d moveto\n")
724 wxT("%d %d lineto\n")
725 wxT("%d %d lineto\n")
726 wxT("%d %d lineto\n")
729 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
730 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
731 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
732 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
734 CalcBoundingBox( x
, y
);
735 CalcBoundingBox( x
+ width
, y
+ height
);
738 if (m_pen
.GetStyle () != wxTRANSPARENT
)
742 PsPrintf( wxT("newpath\n")
743 wxT("%d %d moveto\n")
744 wxT("%d %d lineto\n")
745 wxT("%d %d lineto\n")
746 wxT("%d %d lineto\n")
749 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
750 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
751 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
752 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
754 CalcBoundingBox( x
, y
);
755 CalcBoundingBox( x
+ width
, y
+ height
);
759 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
761 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
765 // Now, a negative radius is interpreted to mean
766 // 'the proportion of the smallest X or Y dimension'
767 double smallest
= width
< height
? width
: height
;
768 radius
= (-radius
* smallest
);
771 wxCoord rad
= (wxCoord
) radius
;
773 if (m_brush
.GetStyle () != wxTRANSPARENT
)
777 /* Draw rectangle anticlockwise */
778 PsPrintf( wxT("newpath\n")
779 wxT("%d %d %d 90 180 arc\n")
780 wxT("%d %d moveto\n")
781 wxT("%d %d %d 180 270 arc\n")
782 wxT("%d %d lineto\n")
783 wxT("%d %d %d 270 0 arc\n")
784 wxT("%d %d lineto\n")
785 wxT("%d %d %d 0 90 arc\n")
786 wxT("%d %d lineto\n")
789 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
790 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
791 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
792 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
793 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
794 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
795 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
796 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
798 CalcBoundingBox( x
, y
);
799 CalcBoundingBox( x
+ width
, y
+ height
);
802 if (m_pen
.GetStyle () != wxTRANSPARENT
)
806 /* Draw rectangle anticlockwise */
807 PsPrintf( wxT("newpath\n")
808 wxT("%d %d %d 90 180 arc\n")
809 wxT("%d %d moveto\n")
810 wxT("%d %d %d 180 270 arc\n")
811 wxT("%d %d lineto\n")
812 wxT("%d %d %d 270 0 arc\n")
813 wxT("%d %d lineto\n")
814 wxT("%d %d %d 0 90 arc\n")
815 wxT("%d %d lineto\n")
818 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
819 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
820 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
821 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
822 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
823 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
824 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
825 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
827 CalcBoundingBox( x
, y
);
828 CalcBoundingBox( x
+ width
, y
+ height
);
832 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
834 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
836 if (m_brush
.GetStyle () != wxTRANSPARENT
)
840 PsPrintf( wxT("newpath\n")
841 wxT("%d %d %d %d 0 360 ellipse\n")
843 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
844 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
846 CalcBoundingBox( x
- width
, y
- height
);
847 CalcBoundingBox( x
+ width
, y
+ height
);
850 if (m_pen
.GetStyle () != wxTRANSPARENT
)
854 PsPrintf( wxT("newpath\n")
855 wxT("%d %d %d %d 0 360 ellipse\n")
857 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
858 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
860 CalcBoundingBox( x
- width
, y
- height
);
861 CalcBoundingBox( x
+ width
, y
+ height
);
865 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
867 DrawBitmap( icon
, x
, y
, true );
870 /* this has to be char, not wxChar */
871 static char hexArray
[] = "0123456789ABCDEF";
873 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
875 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
877 if (!bitmap
.Ok()) return;
879 wxImage image
= bitmap
.ConvertToImage();
881 if (!image
.Ok()) return;
883 wxCoord w
= image
.GetWidth();
884 wxCoord h
= image
.GetHeight();
886 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
887 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
889 wxCoord xx
= LogicalToDeviceX(x
);
890 wxCoord yy
= LogicalToDeviceY(y
+ bitmap
.GetHeight());
892 PsPrintf( wxT("/origstate save def\n")
893 wxT("20 dict begin\n")
894 wxT("/pix %d string def\n")
895 wxT("/grays %d string def\n")
896 wxT("/npixels 0 def\n")
897 wxT("/rgbindx 0 def\n")
898 wxT("%d %d translate\n")
901 wxT("[%d 0 0 %d 0 %d]\n")
902 wxT("{currentfile pix readhexstring pop}\n")
903 wxT("false 3 colorimage\n"),
904 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
906 unsigned char* data
= image
.GetData();
908 /* buffer = line = width*rgb(3)*hexa(2)+'\n'(1)+null(1) */
909 char* buffer
= new char[ w
*6+2 ];
910 int firstDigit
, secondDigit
;
913 for (int j
= 0; j
< h
; j
++)
915 char* bufferindex
= buffer
;
918 for (int i
= 0; i
< w
*3; i
++)
920 firstDigit
= (int)(*data
/16.0);
921 secondDigit
= (int)(*data
- (firstDigit
*16.0));
922 *(bufferindex
++) = hexArray
[firstDigit
];
923 *(bufferindex
++) = hexArray
[secondDigit
];
927 *(bufferindex
++) = '\n';
933 PsPrint( "origstate restore\n" );
936 void wxPostScriptDC::SetFont( const wxFont
& font
)
938 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
940 if (!font
.Ok()) return;
946 int Style
= m_font
.GetStyle();
947 int Weight
= m_font
.GetWeight();
950 switch (m_font
.GetFamily())
955 if (Style
== wxITALIC
)
957 if (Weight
== wxBOLD
)
958 name
= "/Courier-BoldOblique";
960 name
= "/Courier-Oblique";
964 if (Weight
== wxBOLD
)
965 name
= "/Courier-Bold";
973 if (Style
== wxITALIC
)
975 if (Weight
== wxBOLD
)
976 name
= "/Times-BoldItalic";
978 name
= "/Times-Italic";
982 if (Weight
== wxBOLD
)
983 name
= "/Times-Bold";
985 name
= "/Times-Roman";
991 name
= "/ZapfChancery-MediumItalic";
997 if (Style
== wxITALIC
)
999 if (Weight
== wxBOLD
)
1000 name
= "/Helvetica-BoldOblique";
1002 name
= "/Helvetica-Oblique";
1006 if (Weight
== wxBOLD
)
1007 name
= "/Helvetica-Bold";
1009 name
= "/Helvetica";
1015 // We may legitimately call SetFont before BeginDoc
1020 PsPrint( " reencodeISO def\n" );
1022 PsPrint( " findfont\n" );
1025 sprintf( buffer
, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
1026 // this is a hack - we must scale font size (in pts) according to m_scaleY but
1027 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
1028 // to 1/1000th of pt and then back.
1029 for (int i
= 0; i
< 100; i
++)
1030 if (buffer
[i
] == ',') buffer
[i
] = '.';
1032 #endif // !wxUSE_PANGO
1035 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1037 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1039 if (!pen
.Ok()) return;
1041 int oldStyle
= m_pen
.GetStyle();
1046 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
1047 for (int i
= 0; i
< 100; i
++)
1048 if (buffer
[i
] == ',') buffer
[i
] = '.';
1052 Line style - WRONG: 2nd arg is OFFSET
1054 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1055 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1056 ter is not number of values in the array of the first one, but an offset
1057 into this description of the pattern. I mean a real *offset* not index
1058 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1059 will be first black line *2* units wxCoord, then space 4 units, then the
1060 pattern of *3* units black, 4 units space will be repeated.
1063 static const char *dotted
= "[2 5] 2";
1064 static const char *short_dashed
= "[4 4] 2";
1065 static const char *wxCoord_dashed
= "[4 8] 2";
1066 static const char *dotted_dashed
= "[6 6 2 6] 4";
1070 switch (m_pen
.GetStyle())
1072 case wxDOT
: psdash
= dotted
; break;
1073 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1074 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1075 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1078 default: psdash
= "[] 0"; break;
1081 if ( (oldStyle
!= m_pen
.GetStyle()) )
1084 PsPrint( " setdash\n" );
1088 unsigned char red
= m_pen
.GetColour().Red();
1089 unsigned char blue
= m_pen
.GetColour().Blue();
1090 unsigned char green
= m_pen
.GetColour().Green();
1094 // Anything not white is black
1095 if (! (red
== (unsigned char) 255 &&
1096 blue
== (unsigned char) 255 &&
1097 green
== (unsigned char) 255) )
1099 red
= (unsigned char) 0;
1100 green
= (unsigned char) 0;
1101 blue
= (unsigned char) 0;
1106 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1108 double redPS
= (double)(red
) / 255.0;
1109 double bluePS
= (double)(blue
) / 255.0;
1110 double greenPS
= (double)(green
) / 255.0;
1114 "%.8f %.8f %.8f setrgbcolor\n",
1115 redPS
, greenPS
, bluePS
);
1116 for (int i
= 0; i
< 100; i
++)
1117 if (buffer
[i
] == ',') buffer
[i
] = '.';
1122 m_currentBlue
= blue
;
1123 m_currentGreen
= green
;
1127 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1129 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1131 if (!brush
.Ok()) return;
1136 unsigned char red
= m_brush
.GetColour().Red();
1137 unsigned char blue
= m_brush
.GetColour().Blue();
1138 unsigned char green
= m_brush
.GetColour().Green();
1142 // Anything not white is black
1143 if (! (red
== (unsigned char) 255 &&
1144 blue
== (unsigned char) 255 &&
1145 green
== (unsigned char) 255) )
1147 red
= (unsigned char) 0;
1148 green
= (unsigned char) 0;
1149 blue
= (unsigned char) 0;
1154 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1156 double redPS
= (double)(red
) / 255.0;
1157 double bluePS
= (double)(blue
) / 255.0;
1158 double greenPS
= (double)(green
) / 255.0;
1162 "%.8f %.8f %.8f setrgbcolor\n",
1163 redPS
, greenPS
, bluePS
);
1164 for (int i
= 0; i
< 100; i
++)
1165 if (buffer
[i
] == ',') buffer
[i
] = '.';
1170 m_currentBlue
= blue
;
1171 m_currentGreen
= green
;
1177 #define PANGO_ENABLE_ENGINE
1180 #include "wx/gtk/private.h"
1181 #include "gtk/gtk.h"
1183 #include "wx/x11/private.h"
1186 #include <ft2build.h>
1187 #include FT_FREETYPE_H
1189 #include "wx/fontutil.h"
1190 #include <pango/pangoft2.h>
1191 #include <freetype/ftglyph.h>
1193 #ifndef FT_Outline_Decompose
1194 FT_EXPORT( FT_Error
) FT_Outline_Decompose(
1195 FT_Outline
* outline
,
1196 const FT_Outline_Funcs
* interface
,
1200 typedef struct _OutlineInfo OutlineInfo
;
1201 struct _OutlineInfo
{
1202 wxPostScriptDC
* caller
;
1205 static int paps_move_to( FT_Vector
* to
, void *user_data
)
1207 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1208 outline_info
->caller
->PsPrintf( wxT("%d %d moveto\n"), (int)to
->x
, (int)to
->y
);
1212 static int paps_line_to( FT_Vector
* to
, void *user_data
)
1214 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1215 outline_info
->caller
->PsPrintf( wxT("%d %d lineto\n"), (int)to
->x
, (int)to
->y
);
1219 static int paps_conic_to( FT_Vector
* control
, FT_Vector
* to
, void *user_data
)
1221 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1222 outline_info
->caller
->PsPrintf( wxT("%d %d %d %d conicto\n"),
1231 paps_cubic_to( FT_Vector
* control1
, FT_Vector
* control2
,
1232 FT_Vector
* to
, void *user_data
)
1234 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1235 outline_info
->caller
->PsPrintf(wxT("%d %d %d %d %d %d curveto\n"),
1245 void draw_bezier_outline(wxPostScriptDC
* caller
,
1247 FT_UInt glyph_index
,
1253 FT_Int load_flags
= FT_LOAD_NO_BITMAP
;
1256 FT_Outline_Funcs outlinefunc
=
1264 OutlineInfo outline_info
;
1265 outline_info
.caller
= caller
;
1267 caller
->PsPrint("gsave\n");
1268 caller
->PsPrintf( wxT("%d %d translate\n"), pos_x
, pos_y
);
1270 // We have to replace the "," from the German
1271 // locale with the Englich "." for PostScript
1273 sprintf(buf
, "%.8f %.8f scale\n", scale_x
, scale_y
);
1274 for (size_t i
= 0; i
< strlen(buf
); i
++)
1275 if (buf
[i
] == ',') buf
[i
] = '.';
1276 caller
->PsPrint(buf
);
1278 FT_Load_Glyph(face
, glyph_index
, load_flags
);
1279 FT_Get_Glyph (face
->glyph
, &glyph
);
1280 FT_Outline_Decompose (&(((FT_OutlineGlyph
)glyph
)->outline
),
1281 &outlinefunc
, &outline_info
);
1282 caller
->PsPrint("closepath fill grestore\n");
1284 FT_Done_Glyph (glyph
);
1291 static void InitializePangoContext(PangoContext
*context
)
1294 pango_context_set_base_dir(context
,
1295 gtk_widget_get_default_direction() == GTK_TEXT_DIR_LTR
?
1296 PANGO_DIRECTION_LTR
: PANGO_DIRECTION_RTL
);
1297 pango_context_set_language(context
, gtk_get_default_language());
1299 // FIXME: assuming LTR is incorrect!
1300 pango_context_set_base_dir(context
, PANGO_DIRECTION_LTR
);
1301 wxString lang
= wxGetLocale()->GetCanonicalName();
1302 pango_context_set_language(context
,
1303 pango_language_from_string(lang
.ToAscii()));
1308 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1310 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1312 if (m_textForegroundColour
.Ok())
1314 unsigned char red
= m_textForegroundColour
.Red();
1315 unsigned char blue
= m_textForegroundColour
.Blue();
1316 unsigned char green
= m_textForegroundColour
.Green();
1320 // Anything not white is black
1321 if (! (red
== (unsigned char) 255 &&
1322 blue
== (unsigned char) 255 &&
1323 green
== (unsigned char) 255))
1325 red
= (unsigned char) 0;
1326 green
= (unsigned char) 0;
1327 blue
= (unsigned char) 0;
1331 // maybe setgray here ?
1332 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1334 double redPS
= (double)(red
) / 255.0;
1335 double bluePS
= (double)(blue
) / 255.0;
1336 double greenPS
= (double)(green
) / 255.0;
1340 "%.8f %.8f %.8f setrgbcolor\n",
1341 redPS
, greenPS
, bluePS
);
1342 for (size_t i
= 0; i
< strlen(buffer
); i
++)
1343 if (buffer
[i
] == ',') buffer
[i
] = '.';
1347 m_currentBlue
= blue
;
1348 m_currentGreen
= green
;
1354 int pango_dpi
= 600;
1355 PangoContext
*context
= pango_ft2_get_context ( pango_dpi
, pango_dpi
);
1357 InitializePangoContext(context
);
1359 double scale
= (double)pango_dpi
/ (double)ps_dpi
;
1360 scale
/= m_userScaleY
;
1362 pango_context_set_font_description (context
, m_font
.GetNativeFontInfo()->description
);
1364 PangoLayout
*layout
= pango_layout_new (context
);
1366 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( text
);
1368 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) );
1370 pango_layout_set_text( layout
, (const char*) buffer
, strlen(buffer
) );
1372 PsPrintf( wxT("%%%% %s\n"), text
.c_str() );
1374 PangoRectangle rect
;
1375 pango_layout_get_extents(layout
, NULL
, &rect
);
1377 int xx
= LogicalToDeviceX( x
);
1378 int yy
= LogicalToDeviceY( y
);
1380 int xxx
= xx
* PANGO_SCALE
;
1381 int yyy
= yy
* PANGO_SCALE
- (int)(rect
.height
* 0.66 / scale
); // Move down by estimated baseline. HACK.
1383 #define ps_kludge_factor 2.8
1385 // Loop over lines in layout
1386 int num_lines
= pango_layout_get_line_count( layout
);
1387 for (int i
= 0; i
< num_lines
; i
++)
1389 PangoLayoutLine
*line
= pango_layout_get_line( layout
, i
);
1391 // width of glyphs already printed
1394 // Loop over runs in line
1395 GSList
*runs_list
= line
->runs
;
1398 PangoLayoutRun
*run
= (PangoLayoutRun
*) runs_list
->data
;
1399 PangoItem
*item
= run
->item
;
1400 PangoGlyphString
*glyphs
= run
->glyphs
;
1401 PangoAnalysis
*analysis
= &item
->analysis
;
1402 PangoFont
*font
= analysis
->font
;
1403 FT_Face ft_face
= pango_ft2_font_get_face(font
);
1405 int num_glyphs
= glyphs
->num_glyphs
;
1406 for (int glyph_idx
= 0; glyph_idx
< num_glyphs
; glyph_idx
++)
1408 PangoGlyphGeometry geometry
= glyphs
->glyphs
[glyph_idx
].geometry
;
1409 int pos_x
= xxx
+ (int)((double)(all_width
+geometry
.x_offset
) / scale
);
1410 int pos_y
= yyy
+ (int)((double)geometry
.y_offset
/ scale
);
1411 all_width
+= geometry
.width
;
1413 draw_bezier_outline( this, ft_face
,
1414 (FT_UInt
)(glyphs
->glyphs
[glyph_idx
].glyph
),
1415 pos_x
/ PANGO_SCALE
,
1416 pos_y
/ PANGO_SCALE
,
1417 1.0/(ps_kludge_factor
* scale
* 26.6),
1418 1.0/(ps_kludge_factor
* scale
* 26.6) );
1420 runs_list
= runs_list
->next
;
1424 g_object_unref( G_OBJECT( layout
) );
1425 g_object_unref( G_OBJECT( context
) );
1426 #else // !wxUSE_PANGO
1427 wxCoord text_w
, text_h
, text_descent
;
1429 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1431 // VZ: this seems to be unnecessary, so taking it out for now, if it
1432 // doesn't create any problems, remove this comment entirely
1433 //SetFont( m_font );
1436 int size
= m_font
.GetPointSize();
1438 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1439 // commented by V. Slavik and replaced by accurate version
1440 // - note that there is still rounding error in text_descent!
1441 wxCoord by
= y
+ size
- text_descent
; // baseline
1443 PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1446 const wxWX2MBbuf textbuf
= text
.mb_str();
1447 size_t len
= strlen(textbuf
);
1449 for (i
= 0; i
< len
; i
++)
1451 int c
= (unsigned char) textbuf
[i
];
1452 if (c
== ')' || c
== '(' || c
== '\\')
1454 /* Cope with special characters */
1458 else if ( c
>= 128 )
1460 /* Cope with character codes > 127 */
1461 PsPrintf( wxT("\\%o"), c
);
1469 PsPrint( ") show\n" );
1471 if (m_font
.GetUnderlined())
1473 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1483 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1484 m_underlineThickness
,
1485 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1486 for (i
= 0; i
< 100; i
++)
1487 if (buffer
[i
] == ',') buffer
[i
] = '.';
1491 CalcBoundingBox( x
, y
);
1492 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1493 #endif // wxUSE_PANGO/!wxUSE_PANGO
1496 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1500 DoDrawText(text
, x
, y
);
1504 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1508 if (m_textForegroundColour
.Ok())
1510 unsigned char red
= m_textForegroundColour
.Red();
1511 unsigned char blue
= m_textForegroundColour
.Blue();
1512 unsigned char green
= m_textForegroundColour
.Green();
1516 // Anything not white is black
1517 if (! (red
== (unsigned char) 255 &&
1518 blue
== (unsigned char) 255 &&
1519 green
== (unsigned char) 255))
1521 red
= (unsigned char) 0;
1522 green
= (unsigned char) 0;
1523 blue
= (unsigned char) 0;
1527 // maybe setgray here ?
1528 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1530 double redPS
= (double)(red
) / 255.0;
1531 double bluePS
= (double)(blue
) / 255.0;
1532 double greenPS
= (double)(green
) / 255.0;
1536 "%.8f %.8f %.8f setrgbcolor\n",
1537 redPS
, greenPS
, bluePS
);
1538 for (int i
= 0; i
< 100; i
++)
1539 if (buffer
[i
] == ',') buffer
[i
] = '.';
1543 m_currentBlue
= blue
;
1544 m_currentGreen
= green
;
1548 int size
= m_font
.GetPointSize();
1550 PsPrintf( wxT("%d %d moveto\n"),
1551 LogicalToDeviceX(x
), LogicalToDeviceY(y
));
1554 sprintf(buffer
, "%.8f rotate\n", angle
);
1556 for (i
= 0; i
< 100; i
++)
1558 if (buffer
[i
] == ',') buffer
[i
] = '.';
1563 const wxWX2MBbuf textbuf
= text
.mb_str();
1564 size_t len
= strlen(textbuf
);
1565 for (i
= 0; i
< len
; i
++)
1567 int c
= (unsigned char) textbuf
[i
];
1568 if (c
== ')' || c
== '(' || c
== '\\')
1570 /* Cope with special characters */
1574 else if ( c
>= 128 )
1576 /* Cope with character codes > 127 */
1577 PsPrintf( wxT("\\%o"), c
);
1585 PsPrint( ") show\n" );
1587 sprintf( buffer
, "%.8f rotate\n", -angle
);
1588 for (i
= 0; i
< 100; i
++)
1590 if (buffer
[i
] == ',') buffer
[i
] = '.';
1594 if (m_font
.GetUnderlined())
1596 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1599 GetTextExtent(text
, &w
, &h
);
1608 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1609 m_underlineThickness
,
1610 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1611 for (i
= 0; i
< 100; i
++)
1613 if (buffer
[i
] == ',') buffer
[i
] = '.';
1618 CalcBoundingBox( x
, y
);
1619 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1622 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1624 m_backgroundBrush
= brush
;
1627 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1629 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1632 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1634 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1638 // a and b are not used
1640 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1643 wxList::compatibility_iterator node
= points
->GetFirst();
1644 p
= (wxPoint
*)node
->GetData();
1648 node
= node
->GetNext();
1649 p
= (wxPoint
*)node
->GetData();
1656 (double)(x1
+ c
) / 2;
1661 (double)(y1
+ d
) / 2;
1663 PsPrintf( wxT("newpath\n")
1664 wxT("%d %d moveto\n")
1665 wxT("%d %d lineto\n"),
1666 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1667 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1669 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1670 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1672 node
= node
->GetNext();
1675 q
= (wxPoint
*)node
->GetData();
1683 x3
= (double)(x2
+ c
) / 2;
1684 y3
= (double)(y2
+ d
) / 2;
1686 PsPrintf( wxT("%d %d %d %d %d %d DrawSplineSection\n"),
1687 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1688 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1689 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1691 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1692 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1694 node
= node
->GetNext();
1698 At this point, (x2,y2) and (c,d) are the position of the
1699 next-to-last and last point respectively, in the point list
1702 PsPrintf( wxT("%d %d lineto\n")
1704 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1707 wxCoord
wxPostScriptDC::GetCharWidth() const
1709 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1710 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1714 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1716 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1718 m_signX
= (xLeftRight
? 1 : -1);
1719 m_signY
= (yBottomUp
? 1 : -1);
1721 // FIXME there is no such function in MSW nor in OS2/PM
1722 #if !defined(__WXMSW__) && !defined(__WXPM__)
1723 ComputeScaleAndOrigin();
1727 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1729 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1735 wxDC::SetDeviceOrigin( x
, h
-y
);
1738 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1740 wxPaperSize id
= m_printData
.GetPaperId();
1742 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1744 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1750 w
= paper
->GetSizeDeviceUnits().x
;
1751 h
= paper
->GetSizeDeviceUnits().y
;
1754 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1761 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1762 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1765 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1767 wxPaperSize id
= m_printData
.GetPaperId();
1769 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1771 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1777 w
= paper
->GetWidth() / 10;
1778 h
= paper
->GetHeight() / 10;
1781 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1788 if (width
) *width
= w
;
1789 if (height
) *height
= h
;
1792 // Resolution in pixels per logical inch
1793 wxSize
wxPostScriptDC::GetPPI(void) const
1795 return wxSize((int)(72 * ms_PSScaleFactor
),
1796 (int)(72 * ms_PSScaleFactor
));
1800 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1802 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
1804 wxPostScriptPrintNativeData
*data
=
1805 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1807 if (data
->GetPrintMode() != wxPRINT_MODE_STREAM
)
1809 if (m_printData
.GetFilename() == wxEmptyString
)
1811 wxString filename
= wxGetTempFileName( wxT("ps") );
1812 m_printData
.SetFilename(filename
);
1815 // FIXME: use fn_str() here under Unicode?
1816 m_pstream
= wxFopen( m_printData
.GetFilename().c_str(), wxT("w+") );
1820 wxLogError( _("Cannot open file for PostScript printing!"));
1829 PsPrint( "%!PS-Adobe-2.0\n" );
1830 PsPrintf( wxT("%%%%Title: %s\n"), m_title
.c_str() );
1831 PsPrint( "%%Creator: wxWidgets PostScript renderer\n" );
1832 PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() );
1833 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1834 PsPrint( "%%Orientation: Landscape\n" );
1836 PsPrint( "%%Orientation: Portrait\n" );
1838 // PsPrintf( wxT("%%%%Pages: %d\n"), (wxPageNumber - 1) );
1840 const wxChar
*paper
;
1841 switch (m_printData
.GetPaperId())
1843 case wxPAPER_LETTER
: paper
= wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches
1844 case wxPAPER_LEGAL
: paper
= wxT("Legal"); break; // Legal, 8 1/2 by 14 inches
1845 case wxPAPER_A4
: paper
= wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters
1846 case wxPAPER_TABLOID
: paper
= wxT("Tabloid"); break; // Tabloid, 11 by 17 inches
1847 case wxPAPER_LEDGER
: paper
= wxT("Ledger"); break; // Ledger, 17 by 11 inches
1848 case wxPAPER_STATEMENT
: paper
= wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches
1849 case wxPAPER_EXECUTIVE
: paper
= wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches
1850 case wxPAPER_A3
: paper
= wxT("A3"); break; // A3 sheet, 297 by 420 millimeters
1851 case wxPAPER_A5
: paper
= wxT("A5"); break; // A5 sheet, 148 by 210 millimeters
1852 case wxPAPER_B4
: paper
= wxT("B4"); break; // B4 sheet, 250 by 354 millimeters
1853 case wxPAPER_B5
: paper
= wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper
1854 case wxPAPER_FOLIO
: paper
= wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper
1855 case wxPAPER_QUARTO
: paper
= wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper
1856 case wxPAPER_10X14
: paper
= wxT("10x14"); break; // 10-by-14-inch sheet
1857 default: paper
= wxT("A4");
1859 PsPrintf( wxT("%%%%DocumentPaperSizes: %s\n"), paper
);
1860 PsPrint( "%%EndComments\n\n" );
1862 PsPrint( "%%BeginProlog\n" );
1863 PsPrint( wxPostScriptHeaderConicTo
);
1864 PsPrint( wxPostScriptHeaderEllipse
);
1865 PsPrint( wxPostScriptHeaderEllipticArc
);
1866 PsPrint( wxPostScriptHeaderColourImage
);
1869 PsPrint( wxPostScriptHeaderReencodeISO1
);
1870 PsPrint( wxPostScriptHeaderReencodeISO2
);
1872 if (wxPostScriptHeaderSpline
)
1873 PsPrint( wxPostScriptHeaderSpline
);
1874 PsPrint( "%%EndProlog\n" );
1876 SetBrush( *wxBLACK_BRUSH
);
1877 SetPen( *wxBLACK_PEN
);
1878 SetBackground( *wxWHITE_BRUSH
);
1879 SetTextForeground( *wxBLACK
);
1881 // set origin according to paper size
1882 SetDeviceOrigin( 0,0 );
1889 void wxPostScriptDC::EndDoc ()
1891 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1896 PsPrint( "grestore\n" );
1900 fclose( m_pstream
);
1901 m_pstream
= (FILE *) NULL
;
1905 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1906 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1907 double wx_printer_scale_x
, wx_printer_scale_y
;
1909 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1910 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1912 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1913 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1915 // Compute the bounding box. Note that it is in the default user
1916 // coordinate system, thus we have to convert the values.
1917 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1918 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1919 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1920 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1922 // LOG2DEV may have changed the minimum to maximum vice versa
1923 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1924 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1926 // account for used scaling (boundingbox is before scaling in ps-file)
1927 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1928 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1930 wxCoord llx
, lly
, urx
, ury
;
1931 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1932 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1933 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1934 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1935 // (end of bounding box computation)
1938 // If we're landscape, our sense of "x" and "y" is reversed.
1939 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1942 tmp
= llx
; llx
= lly
; lly
= tmp
;
1943 tmp
= urx
; urx
= ury
; ury
= tmp
;
1945 // We need either the two lines that follow, or we need to subtract
1946 // min_x from real_translate_y, which is commented out below.
1947 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1948 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1951 // The Adobe specifications call for integers; we round as to make
1952 // the bounding larger.
1953 PsPrintf( wxT("%%%%BoundingBox: %d %d %d %d\n"),
1954 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1955 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1957 // To check the correctness of the bounding box, postscript commands
1958 // to draw a box corresponding to the bounding box are generated below.
1959 // But since we typically don't want to print such a box, the postscript
1960 // commands are generated within comments. These lines appear before any
1961 // adjustment of scale, rotation, or translation, and hence are in the
1962 // default user coordinates.
1963 PsPrint( "% newpath\n" );
1964 PsPrintf( wxT("%% %d %d moveto\n"), llx
, lly
);
1965 PsPrintf( wxT("%% %d %d lineto\n"), urx
, lly
);
1966 PsPrintf( wxT("%% %d %d lineto\n"), urx
, ury
);
1967 PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx
, ury
);
1971 wxPostScriptPrintNativeData
*data
=
1972 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
1974 if (m_ok
&& (data
->GetPrintMode() == wxPRINT_MODE_PRINTER
))
1977 command
+= data
->GetPrinterCommand();
1978 command
+= wxT(" ");
1979 command
+= data
->GetPrinterOptions();
1980 command
+= wxT(" ");
1981 command
+= m_printData
.GetFilename();
1983 wxExecute( command
, true );
1984 wxRemoveFile( m_printData
.GetFilename() );
1989 void wxPostScriptDC::StartPage()
1991 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1993 PsPrintf( wxT("%%%%Page: %d\n"), wxPageNumber
++ );
1995 // What is this one supposed to do? RR.
1996 // *m_pstream << "matrix currentmatrix\n";
1998 // Added by Chris Breeze
2000 // Each page starts with an "initgraphics" which resets the
2001 // transformation and so we need to reset the origin
2002 // (and rotate the page for landscape printing)
2005 wxCoord translate_x
, translate_y
;
2006 double scale_x
, scale_y
;
2008 wxPostScriptPrintNativeData
*data
=
2009 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2011 translate_x
= (wxCoord
)data
->GetPrinterTranslateX();
2012 translate_y
= (wxCoord
)data
->GetPrinterTranslateY();
2014 scale_x
= data
->GetPrinterScaleX();
2015 scale_y
= data
->GetPrinterScaleY();
2017 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
2020 GetSize( (int*) NULL
, &h
);
2022 PsPrint( "90 rotate\n" );
2023 // I copied this one from a PostScript tutorial, but to no avail. RR.
2024 // PsPrint( "90 rotate llx neg ury nef translate\n" );
2028 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
2029 scale_y
/ ms_PSScaleFactor
);
2030 for (int i
= 0; i
< 100; i
++)
2031 if (buffer
[i
] == ',') buffer
[i
] = '.';
2034 PsPrintf( wxT("%d %d translate\n"), translate_x
, translate_y
);
2037 void wxPostScriptDC::EndPage ()
2039 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
2041 PsPrint( "showpage\n" );
2044 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
2045 wxCoord fwidth
, wxCoord fheight
,
2047 wxCoord xsrc
, wxCoord ysrc
,
2048 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
2050 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
2052 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
2054 /* blit into a bitmap */
2055 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
2057 memDC
.SelectObject(bitmap
);
2058 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
2059 memDC
.SelectObject(wxNullBitmap
);
2061 /* draw bitmap. scaling and positioning is done there */
2062 DrawBitmap( bitmap
, xdest
, ydest
);
2067 wxCoord
wxPostScriptDC::GetCharHeight() const
2070 return m_font
.GetPointSize();
2075 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
2076 wxCoord
*x
, wxCoord
*y
,
2077 wxCoord
*descent
, wxCoord
*externalLeading
,
2078 wxFont
*theFont
) const
2080 wxFont
*fontToUse
= theFont
;
2082 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
2084 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
2086 if (string
.IsEmpty())
2090 if (descent
) (*descent
) = 0;
2091 if (externalLeading
) (*externalLeading
) = 0;
2096 int wx_dpi
= GetResolution();
2097 int pango_dpi
= 600;
2098 PangoContext
*context
= pango_ft2_get_context ( pango_dpi
, pango_dpi
);
2100 InitializePangoContext(context
);
2102 double scale
= pango_dpi
/ wx_dpi
;
2103 scale
/= m_userScaleY
;
2105 PangoLayout
*layout
= pango_layout_new (context
);
2107 PangoFontDescription
*desc
= fontToUse
->GetNativeFontInfo()->description
;
2108 pango_layout_set_font_description(layout
, desc
);
2110 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
2112 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
2113 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
2115 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
2117 PangoRectangle rect
;
2118 pango_layout_get_extents(layout
, NULL
, &rect
);
2120 if (x
) (*x
) = (wxCoord
) ( PANGO_PIXELS(rect
.width
) / scale
);
2121 if (y
) (*y
) = (wxCoord
) ( PANGO_PIXELS(rect
.height
) / scale
);
2124 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
2125 int baseline
= pango_layout_iter_get_baseline(iter
);
2126 pango_layout_iter_free(iter
);
2127 *descent
= wxCoord(*y
- PANGO_PIXELS(baseline
) / scale
);
2129 if (externalLeading
) (*externalLeading
) = 0; // ??
2131 g_object_unref( G_OBJECT( layout
) );
2135 const wxWX2MBbuf strbuf
= string
.mb_str();
2137 #if !wxUSE_AFM_FOR_POSTSCRIPT
2138 /* Provide a VERY rough estimate (avoid using it).
2139 * Produces accurate results for mono-spaced font
2140 * such as Courier (aka wxMODERN) */
2145 height
= fontToUse
->GetPointSize();
2148 *x
= strlen (strbuf
) * height
* 72 / 120;
2150 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
2151 if (descent
) *descent
= 0;
2152 if (externalLeading
) *externalLeading
= 0;
2155 /* method for calculating string widths in postscript:
2156 / read in the AFM (adobe font metrics) file for the
2157 / actual font, parse it and extract the character widths
2158 / and also the descender. this may be improved, but for now
2159 / it works well. the AFM file is only read in if the
2160 / font is changed. this may be chached in the future.
2161 / calls to GetTextExtent with the font unchanged are rather
2164 / for each font and style used there is an AFM file necessary.
2165 / currently i have only files for the roman font family.
2166 / I try to get files for the other ones!
2168 / CAVE: the size of the string is currently always calculated
2169 / in 'points' (1/72 of an inch). this should later on be
2170 / changed to depend on the mapping mode.
2171 / CAVE: the path to the AFM files must be set before calling this
2172 / function. this is usually done by a call like the following:
2173 / wxSetAFMPath("d:\\wxw161\\afm\\");
2177 / wxPostScriptDC dc(NULL, true);
2179 / wxSetAFMPath("d:\\wxw161\\afm\\");
2180 / dc.StartDoc("Test");
2183 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
2184 / dc.GetTextExtent("Hallo",&w,&h);
2189 / by steve (stefan.hammes@urz.uni-heidelberg.de)
2191 / updated: 14.05.95 */
2193 /* these static vars are for storing the state between calls */
2194 static int lastFamily
= INT_MIN
;
2195 static int lastSize
= INT_MIN
;
2196 static int lastStyle
= INT_MIN
;
2197 static int lastWeight
= INT_MIN
;
2198 static int lastDescender
= INT_MIN
;
2199 static int lastWidths
[256]; /* widths of the characters */
2201 double UnderlinePosition
= 0.0;
2202 double UnderlineThickness
= 0.0;
2204 // Get actual parameters
2205 int Family
= fontToUse
->GetFamily();
2206 int Size
= fontToUse
->GetPointSize();
2207 int Style
= fontToUse
->GetStyle();
2208 int Weight
= fontToUse
->GetWeight();
2210 // If we have another font, read the font-metrics
2211 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
2213 // Store actual values
2214 lastFamily
= Family
;
2217 lastWeight
= Weight
;
2226 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBoO.afm");
2227 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBo.afm");
2228 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("CourO.afm");
2229 else name
= wxT("Cour.afm");
2234 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBoO.afm");
2235 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBo.afm");
2236 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("TimesO.afm");
2237 else name
= wxT("TimesRo.afm");
2242 name
= wxT("Zapf.afm");
2248 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBoO.afm");
2249 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBo.afm");
2250 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("HelvO.afm");
2251 else name
= wxT("Helv.afm");
2256 FILE *afmFile
= NULL
;
2258 wxPostScriptPrintNativeData
*data
=
2259 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2261 // Get the directory of the AFM files
2263 if (!data
->GetFontMetricPath().IsEmpty())
2265 afmName
= data
->GetFontMetricPath();
2266 afmName
<< wxFILE_SEP_PATH
<< name
;
2267 afmFile
= wxFopen(afmName
,wxT("r"));
2270 #if defined(__UNIX__) && !defined(__VMS__)
2273 afmName
= wxGetDataDir();
2274 afmName
<< wxFILE_SEP_PATH
2275 #if defined(__LINUX__) || defined(__FREEBSD__)
2276 << wxT("gs_afm") << wxFILE_SEP_PATH
2278 << wxT("afm") << wxFILE_SEP_PATH
2281 afmFile
= wxFopen(afmName
,wxT("r"));
2285 /* 2. open and process the file
2286 / a short explanation of the AFM format:
2287 / we have for each character a line, which gives its size
2290 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2292 / that means, we have a character with ascii code 63, and width
2293 / (444/1000 * fontSize) points.
2294 / the other data is ignored for now!
2296 / when the font has changed, we read in the right AFM file and store the
2297 / character widths in an array, which is processed below (see point 3.). */
2300 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2301 wxLogDebug( wxT(" using approximate values"));
2302 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2303 lastDescender
= -150; /* dito. */
2307 /* init the widths array */
2308 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2309 /* some variables for holding parts of a line */
2310 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2311 char upString
[30], utString
[30], encString
[50];
2314 /* read in the file and parse it */
2315 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2317 /* A.) check for descender definition */
2318 if (strncmp(line
,"Descender",9)==0)
2320 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2321 (strcmp(descString
,"Descender")!=0))
2323 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2326 /* JC 1.) check for UnderlinePosition */
2327 else if(strncmp(line
,"UnderlinePosition",17)==0)
2329 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2330 (strcmp(upString
,"UnderlinePosition")!=0))
2332 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2335 /* JC 2.) check for UnderlineThickness */
2336 else if(strncmp(line
,"UnderlineThickness",18)==0)
2338 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2339 (strcmp(utString
,"UnderlineThickness")!=0))
2341 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2344 /* JC 3.) check for EncodingScheme */
2345 else if(strncmp(line
,"EncodingScheme",14)==0)
2347 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2348 (strcmp(utString
,"EncodingScheme")!=0))
2350 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2352 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2354 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2355 afmName
.c_str(),line
, encString
);
2358 /* B.) check for char-width */
2359 else if(strncmp(line
,"C ",2)==0)
2361 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2363 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2365 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2367 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2369 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2370 if (ascii
>=0 && ascii
<256)
2372 lastWidths
[ascii
] = cWidth
; /* store width */
2376 /* MATTHEW: this happens a lot; don't print an error */
2377 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2380 /* C.) ignore other entries. */
2384 /* hack to compute correct values for german 'Umlaute'
2385 / the correct way would be to map the character names
2386 / like 'adieresis' to corresp. positions of ISOEnc and read
2387 / these values from AFM files, too. Maybe later ... */
2389 // NB: casts to int are needed to suppress gcc 3.3 warnings
2390 lastWidths
[196] = lastWidths
[(int)'A']; // Ä
2391 lastWidths
[228] = lastWidths
[(int)'a']; // ä
2392 lastWidths
[214] = lastWidths
[(int)'O']; // Ö
2393 lastWidths
[246] = lastWidths
[(int)'o']; // ö
2394 lastWidths
[220] = lastWidths
[(int)'U']; // Ü
2395 lastWidths
[252] = lastWidths
[(int)'u']; // ü
2396 lastWidths
[223] = lastWidths
[(int)251]; // ß
2398 /* JC: calculate UnderlineThickness/UnderlinePosition */
2400 // VS: dirty, but is there any better solution?
2402 pt
= (double*) &m_underlinePosition
;
2403 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2404 pt
= (double*) &m_underlineThickness
;
2405 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2410 /* 3. now the font metrics are read in, calc size this
2411 / is done by adding the widths of the characters in the
2412 / string. they are given in 1/1000 of the size! */
2415 wxCoord height
=Size
; /* by default */
2417 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2419 if(lastWidths
[*p
]== INT_MIN
)
2421 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2422 sum
+= lastWidths
[(unsigned char)' ']; /* assume space */
2426 sum
+= lastWidths
[*p
];
2430 double widthSum
= sum
;
2432 widthSum
/= 1000.0F
;
2434 /* add descender to height (it is usually a negative value) */
2435 //if (lastDescender != INT_MIN)
2437 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2439 // - commented by V. Slavik - height already contains descender in it
2440 // (judging from few experiments)
2442 /* return size values */
2444 *x
= (wxCoord
)widthSum
;
2448 /* return other parameters */
2451 if(lastDescender
!=INT_MIN
)
2453 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2461 /* currently no idea how to calculate this! */
2462 if (externalLeading
) *externalLeading
= 0;
2470 // print postscript datas via required method (file, stream)
2471 void wxPostScriptDC::PsPrintf( const wxChar
* fmt
, ... )
2474 va_start(argptr
, fmt
);
2476 PsPrint( wxString::FormatV( fmt
, argptr
).c_str() );
2479 void wxPostScriptDC::PsPrint( const char* psdata
)
2481 wxPostScriptPrintNativeData
*data
=
2482 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2484 switch(data
->GetPrintMode())
2487 // append to output stream
2488 case wxPRINT_MODE_STREAM
:
2490 wxOutputStream
* outputstream
= data
->GetOutputStream();
2491 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2492 outputstream
->Write( psdata
, strlen( psdata
) );
2495 #endif // wxUSE_STREAMS
2497 // save data into file
2499 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2500 fwrite( psdata
, 1, strlen( psdata
), m_pstream
);
2504 void wxPostScriptDC::PsPrint( int ch
)
2506 wxPostScriptPrintNativeData
*data
=
2507 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
2509 switch (data
->GetPrintMode())
2512 // append to output stream
2513 case wxPRINT_MODE_STREAM
:
2515 wxOutputStream
* outputstream
= data
->GetOutputStream();
2516 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2517 outputstream
->PutC( ch
);
2520 #endif // wxUSE_STREAMS
2522 // save data into file
2524 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2525 fputc( ch
, m_pstream
);
2529 #if WXWIN_COMPATIBILITY_2_2
2530 WXDLLEXPORT wxPrintSetupData
*wxThePrintSetupData
= 0;
2532 void wxInitializePrintSetupData(bool init
)
2536 // gets initialized in the constructor
2537 wxThePrintSetupData
= new wxPrintSetupData
;
2541 delete wxThePrintSetupData
;
2543 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2547 // A module to allow initialization/cleanup of PostScript-related
2548 // things without calling these functions from app.cpp.
2550 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2552 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2554 wxPostScriptModule() {}
2559 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2561 bool wxPostScriptModule::OnInit()
2563 wxInitializePrintSetupData();
2568 void wxPostScriptModule::OnExit()
2570 wxInitializePrintSetupData(false);
2573 // WXWIN_COMPATIBILITY_2_2
2579 // wxUSE_PRINTING_ARCHITECTURE