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"
40 #include "wx/filefn.h"
41 #if WXWIN_COMPATIBILITY_2_2
42 #include "wx/window.h"
43 #include "wx/printdlg.h"
68 //-----------------------------------------------------------------------------
69 // start and end of document/page
70 //-----------------------------------------------------------------------------
72 static const char *wxPostScriptHeaderConicTo
= "\
76 /conic_cntrl_y exch def\n\
77 /conic_cntrl_x exch def\n\
81 /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\
82 /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\
83 /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\
84 /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\
85 p1_x p1_y p2_x p2_y to_x to_y curveto\n\
89 static const char *wxPostScriptHeaderEllipse
= "\
90 /ellipsedict 8 dict def\n\
91 ellipsedict /mtrx matrix put\n\
95 /startangle exch def\n\
100 /savematrix mtrx currentmatrix def\n\
103 0 0 1 startangle endangle arc\n\
104 savematrix setmatrix\n\
109 static const char *wxPostScriptHeaderEllipticArc
= "\
110 /ellipticarcdict 8 dict def\n\
111 ellipticarcdict /mtrx matrix put\n\
113 { ellipticarcdict begin\n\
115 /endangle exch def\n\
116 /startangle exch def\n\
121 /savematrix mtrx currentmatrix def\n\
124 do_fill { 0 0 moveto } if\n\
125 0 0 1 startangle endangle arc\n\
126 savematrix setmatrix\n\
127 do_fill { fill }{ stroke } ifelse\n\
131 static const char *wxPostScriptHeaderSpline
= "\
132 /DrawSplineSection {\n\
139 /xa x1 x2 x1 sub 0.666667 mul add def\n\
140 /ya y1 y2 y1 sub 0.666667 mul add def\n\
141 /xb x3 x2 x3 sub 0.666667 mul add def\n\
142 /yb y3 y2 y3 sub 0.666667 mul add def\n\
144 xa ya xb yb x3 y3 curveto\n\
148 static const char *wxPostScriptHeaderColourImage
= "\
149 % define 'colorimage' if it isn't defined\n\
150 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
152 /colorimage where % do we know about 'colorimage'?\n\
153 { pop } % yes: pop off the 'dict' returned\n\
154 { % no: define one\n\
155 /colortogray { % define an RGB->I function\n\
156 /rgbdata exch store % call input 'rgbdata'\n\
157 rgbdata length 3 idiv\n\
158 /npixls exch store\n\
160 0 1 npixls 1 sub {\n\
162 rgbdata rgbindx get 20 mul % Red\n\
163 rgbdata rgbindx 1 add get 32 mul % Green\n\
164 rgbdata rgbindx 2 add get 12 mul % Blue\n\
165 add add 64 idiv % I = .5G + .31R + .18B\n\
167 /rgbindx rgbindx 3 add store\n\
169 grays 0 npixls getinterval\n\
172 % Utility procedure for colorimage operator.\n\
173 % This procedure takes two procedures off the\n\
174 % stack and merges them into a single procedure.\n\
176 /mergeprocs { % def\n\
195 /colorimage { % def\n\
196 pop pop % remove 'false 3' operands\n\
197 {colortogray} mergeprocs\n\
200 } ifelse % end of 'false' case\n\
205 static char wxPostScriptHeaderReencodeISO1
[] =
207 "dup dup findfont dup length dict begin\n"
208 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
209 "/Encoding ISOLatin1Encoding def\n"
210 "currentdict end definefont\n"
212 "/ISOLatin1Encoding [\n"
213 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
214 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
215 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
216 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
217 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
218 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
219 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
220 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
221 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
222 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
223 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
224 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
225 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
226 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
227 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
229 static char wxPostScriptHeaderReencodeISO2
[] =
230 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
231 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
232 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
233 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
234 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
235 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
236 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
237 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
238 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
239 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
240 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
241 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
242 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
243 "/yacute/thorn/ydieresis\n"
247 //-------------------------------------------------------------------------------
249 //-------------------------------------------------------------------------------
251 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC
, wxDC
)
253 float wxPostScriptDC::ms_PSScaleFactor
= 1.0;
255 void wxPostScriptDC::SetResolution(int ppi
)
257 ms_PSScaleFactor
= (float)ppi
/ 72.0;
260 int wxPostScriptDC::GetResolution()
262 return (int)(ms_PSScaleFactor
* 72.0);
265 //-------------------------------------------------------------------------------
267 wxPostScriptDC::wxPostScriptDC ()
269 m_pstream
= (FILE*) NULL
;
279 m_underlinePosition
= 0.0;
280 m_underlineThickness
= 0.0;
282 m_signX
= 1; // default x-axis left to right
283 m_signY
= -1; // default y-axis bottom up -> top down
286 wxPostScriptDC::wxPostScriptDC (const wxPrintData
& printData
)
288 m_pstream
= (FILE*) NULL
;
298 m_underlinePosition
= 0.0;
299 m_underlineThickness
= 0.0;
301 m_signX
= 1; // default x-axis left to right
302 m_signY
= -1; // default y-axis bottom up -> top down
304 m_printData
= printData
;
309 wxPostScriptDC::~wxPostScriptDC ()
314 m_pstream
= (FILE*) NULL
;
318 #if WXWIN_COMPATIBILITY_2_2
319 bool wxPostScriptDC::Create( const wxString
&output
, bool interactive
, wxWindow
*parent
)
322 data
.SetFilename( output
);
323 data
.SetPrintMode( wxPRINT_MODE_FILE
);
327 wxPrintDialogData
ddata( data
);
328 wxPrintDialog
dialog( parent
, &data
);
329 dialog
.GetPrintDialogData().SetSetupDialog(true);
330 if (dialog
.ShowModal() != wxID_OK
)
335 data
= dialog
.GetPrintDialogData().GetPrintData();
343 bool wxPostScriptDC::Ok() const
348 void wxPostScriptDC::DoSetClippingRegion (wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
350 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
352 if (m_clipping
) DestroyClippingRegion();
354 wxDC::DoSetClippingRegion(x
, y
, w
, h
);
358 PsPrintf( wxT("gsave\n newpath\n")
359 wxT("%d %d moveto\n")
360 wxT("%d %d lineto\n")
361 wxT("%d %d lineto\n")
362 wxT("%d %d lineto\n")
363 wxT("closepath clip newpath\n"),
364 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
365 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
),
366 LogicalToDeviceX(x
+w
), LogicalToDeviceY(y
+h
),
367 LogicalToDeviceX(x
), LogicalToDeviceY(y
+h
) );
371 void wxPostScriptDC::DestroyClippingRegion()
373 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
378 PsPrint( "grestore\n" );
381 wxDC::DestroyClippingRegion();
384 void wxPostScriptDC::Clear()
386 // This should fail silently to avoid unnecessary
388 // wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
391 bool wxPostScriptDC::DoFloodFill (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
393 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
397 bool wxPostScriptDC::DoGetPixel (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
399 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
403 void wxPostScriptDC::DoCrossHair (wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
))
405 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
408 void wxPostScriptDC::DoDrawLine (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
410 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
412 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
416 PsPrintf( wxT("newpath\n")
417 wxT("%d %d moveto\n")
418 wxT("%d %d lineto\n")
420 LogicalToDeviceX(x1
), LogicalToDeviceY(y1
),
421 LogicalToDeviceX(x2
), LogicalToDeviceY (y2
) );
423 CalcBoundingBox( x1
, y1
);
424 CalcBoundingBox( x2
, y2
);
427 #define RAD2DEG 57.29577951308
429 void wxPostScriptDC::DoDrawArc (wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
431 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
433 wxCoord dx
= x1
- xc
;
434 wxCoord dy
= y1
- yc
;
435 wxCoord radius
= (wxCoord
) sqrt( (double)(dx
*dx
+dy
*dy
) );
436 double alpha1
, alpha2
;
438 if (x1
== x2
&& y1
== y2
)
443 else if (radius
== 0.0)
445 alpha1
= alpha2
= 0.0;
449 alpha1
= (x1
- xc
== 0) ?
450 (y1
- yc
< 0) ? 90.0 : -90.0 :
451 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
452 alpha2
= (x2
- xc
== 0) ?
453 (y2
- yc
< 0) ? 90.0 : -90.0 :
454 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
456 while (alpha1
<= 0) alpha1
+= 360;
457 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
458 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
459 while (alpha2
> 360) alpha2
-= 360;
461 if (m_brush
.GetStyle() != wxTRANSPARENT
)
465 PsPrintf( wxT("newpath\n")
466 wxT("%d %d %d %d %d %d ellipse\n")
467 wxT("%d %d lineto\n")
470 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
471 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
473 CalcBoundingBox( xc
-radius
, yc
-radius
);
474 CalcBoundingBox( xc
+radius
, yc
+radius
);
477 if (m_pen
.GetStyle() != wxTRANSPARENT
)
481 PsPrintf( wxT("newpath\n")
482 wxT("%d %d %d %d %d %d ellipse\n")
483 wxT("%d %d lineto\n")
486 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
), LogicalToDeviceXRel(radius
), LogicalToDeviceYRel(radius
), (wxCoord
)alpha1
, (wxCoord
) alpha2
,
487 LogicalToDeviceX(xc
), LogicalToDeviceY(yc
) );
489 CalcBoundingBox( xc
-radius
, yc
-radius
);
490 CalcBoundingBox( xc
+radius
, yc
+radius
);
494 void wxPostScriptDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
496 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
498 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
499 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
505 DrawEllipse(x
,y
,w
,h
);
509 if (m_brush
.GetStyle () != wxTRANSPARENT
)
513 PsPrintf( wxT("newpath\n")
514 wxT("%d %d %d %d %d %d true ellipticarc\n"),
515 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
516 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
517 (wxCoord
)sa
, (wxCoord
)ea
);
519 CalcBoundingBox( x
,y
);
520 CalcBoundingBox( x
+w
, y
+h
);
523 if (m_pen
.GetStyle () != wxTRANSPARENT
)
527 PsPrintf( wxT("newpath\n")
528 wxT("%d %d %d %d %d %d false ellipticarc\n"),
529 LogicalToDeviceX(x
+w
/2), LogicalToDeviceY(y
+h
/2),
530 LogicalToDeviceXRel(w
/2), LogicalToDeviceYRel(h
/2),
531 (wxCoord
)sa
, (wxCoord
)ea
);
533 CalcBoundingBox( x
,y
);
534 CalcBoundingBox( x
+w
, y
+h
);
538 void wxPostScriptDC::DoDrawPoint (wxCoord x
, wxCoord y
)
540 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
542 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
546 PsPrintf( wxT("newpath\n")
547 wxT("%d %d moveto\n")
548 wxT("%d %d lineto\n")
550 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
551 LogicalToDeviceX(x
+1), LogicalToDeviceY(y
) );
553 CalcBoundingBox( x
, y
);
556 void wxPostScriptDC::DoDrawPolygon (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
558 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
562 if (m_brush
.GetStyle () != wxTRANSPARENT
)
566 PsPrint( "newpath\n" );
568 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
569 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
571 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
573 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
575 for (int i
= 1; i
< n
; i
++)
577 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
578 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
580 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
582 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
585 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
588 if (m_pen
.GetStyle () != wxTRANSPARENT
)
592 PsPrint( "newpath\n" );
594 wxCoord xx
= LogicalToDeviceX(points
[0].x
+ xoffset
);
595 wxCoord yy
= LogicalToDeviceY(points
[0].y
+ yoffset
);
597 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
599 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
601 for (int i
= 1; i
< n
; i
++)
603 xx
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
604 yy
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
606 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
608 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
611 PsPrint( "closepath\n" );
612 PsPrint( "stroke\n" );
616 void wxPostScriptDC::DoDrawPolyPolygon (int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
618 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
622 if (m_brush
.GetStyle () != wxTRANSPARENT
)
626 PsPrint( "newpath\n" );
629 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
631 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
632 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
634 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
636 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
638 for (int j
= 1; j
< count
[i
]; j
++)
640 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
641 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
643 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
645 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
648 PsPrint( (fillStyle
== wxODDEVEN_RULE
? "eofill\n" : "fill\n") );
651 if (m_pen
.GetStyle () != wxTRANSPARENT
)
655 PsPrint( "newpath\n" );
658 for (int i
= 0; i
< n
; ofs
+= count
[i
++])
660 wxCoord xx
= LogicalToDeviceX(points
[ofs
].x
+ xoffset
);
661 wxCoord yy
= LogicalToDeviceY(points
[ofs
].y
+ yoffset
);
663 PsPrintf( wxT("%d %d moveto\n"), xx
, yy
);
665 CalcBoundingBox( points
[ofs
].x
+ xoffset
, points
[ofs
].y
+ yoffset
);
667 for (int j
= 1; j
< count
[i
]; j
++)
669 xx
= LogicalToDeviceX(points
[ofs
+j
].x
+ xoffset
);
670 yy
= LogicalToDeviceY(points
[ofs
+j
].y
+ yoffset
);
672 PsPrintf( wxT("%d %d lineto\n"), xx
, yy
);
674 CalcBoundingBox( points
[ofs
+j
].x
+ xoffset
, points
[ofs
+j
].y
+ yoffset
);
677 PsPrint( "closepath\n" );
678 PsPrint( "stroke\n" );
682 void wxPostScriptDC::DoDrawLines (int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
684 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
686 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
693 for ( i
=0; i
<n
; i
++ )
695 CalcBoundingBox( LogicalToDeviceX(points
[i
].x
+xoffset
), LogicalToDeviceY(points
[i
].y
+yoffset
));
698 PsPrintf( wxT("newpath\n")
699 wxT("%d %d moveto\n"),
700 LogicalToDeviceX(points
[0].x
+xoffset
),
701 LogicalToDeviceY(points
[0].y
+yoffset
) );
703 for (i
= 1; i
< n
; i
++)
705 PsPrintf( wxT("%d %d lineto\n"),
706 LogicalToDeviceX(points
[i
].x
+xoffset
),
707 LogicalToDeviceY(points
[i
].y
+yoffset
) );
710 PsPrint( "stroke\n" );
713 void wxPostScriptDC::DoDrawRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
715 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
717 if (m_brush
.GetStyle () != wxTRANSPARENT
)
721 PsPrintf( wxT("newpath\n")
722 wxT("%d %d moveto\n")
723 wxT("%d %d lineto\n")
724 wxT("%d %d lineto\n")
725 wxT("%d %d lineto\n")
728 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
729 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
730 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
731 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
733 CalcBoundingBox( x
, y
);
734 CalcBoundingBox( x
+ width
, y
+ height
);
737 if (m_pen
.GetStyle () != wxTRANSPARENT
)
741 PsPrintf( wxT("newpath\n")
742 wxT("%d %d moveto\n")
743 wxT("%d %d lineto\n")
744 wxT("%d %d lineto\n")
745 wxT("%d %d lineto\n")
748 LogicalToDeviceX(x
), LogicalToDeviceY(y
),
749 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
),
750 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ height
),
751 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ height
) );
753 CalcBoundingBox( x
, y
);
754 CalcBoundingBox( x
+ width
, y
+ height
);
758 void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
760 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
764 // Now, a negative radius is interpreted to mean
765 // 'the proportion of the smallest X or Y dimension'
766 double smallest
= width
< height
? width
: height
;
767 radius
= (-radius
* smallest
);
770 wxCoord rad
= (wxCoord
) radius
;
772 if (m_brush
.GetStyle () != wxTRANSPARENT
)
776 /* Draw rectangle anticlockwise */
777 PsPrintf( wxT("newpath\n")
778 wxT("%d %d %d 90 180 arc\n")
779 wxT("%d %d moveto\n")
780 wxT("%d %d %d 180 270 arc\n")
781 wxT("%d %d lineto\n")
782 wxT("%d %d %d 270 0 arc\n")
783 wxT("%d %d lineto\n")
784 wxT("%d %d %d 0 90 arc\n")
785 wxT("%d %d lineto\n")
788 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
789 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
790 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
791 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
792 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
793 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
794 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
795 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
797 CalcBoundingBox( x
, y
);
798 CalcBoundingBox( x
+ width
, y
+ height
);
801 if (m_pen
.GetStyle () != wxTRANSPARENT
)
805 /* Draw rectangle anticlockwise */
806 PsPrintf( wxT("newpath\n")
807 wxT("%d %d %d 90 180 arc\n")
808 wxT("%d %d moveto\n")
809 wxT("%d %d %d 180 270 arc\n")
810 wxT("%d %d lineto\n")
811 wxT("%d %d %d 270 0 arc\n")
812 wxT("%d %d lineto\n")
813 wxT("%d %d %d 0 90 arc\n")
814 wxT("%d %d lineto\n")
817 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
818 LogicalToDeviceX(x
), LogicalToDeviceY(y
+ rad
),
819 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
820 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
),
821 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ height
- rad
), LogicalToDeviceXRel(rad
),
822 LogicalToDeviceX(x
+ width
), LogicalToDeviceY(y
+ rad
),
823 LogicalToDeviceX(x
+ width
- rad
), LogicalToDeviceY(y
+ rad
), LogicalToDeviceXRel(rad
),
824 LogicalToDeviceX(x
+ rad
), LogicalToDeviceY(y
) );
826 CalcBoundingBox( x
, y
);
827 CalcBoundingBox( x
+ width
, y
+ height
);
831 void wxPostScriptDC::DoDrawEllipse (wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
833 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
835 if (m_brush
.GetStyle () != wxTRANSPARENT
)
839 PsPrintf( wxT("newpath\n")
840 wxT("%d %d %d %d 0 360 ellipse\n")
842 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
843 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
845 CalcBoundingBox( x
- width
, y
- height
);
846 CalcBoundingBox( x
+ width
, y
+ height
);
849 if (m_pen
.GetStyle () != wxTRANSPARENT
)
853 PsPrintf( wxT("newpath\n")
854 wxT("%d %d %d %d 0 360 ellipse\n")
856 LogicalToDeviceX(x
+ width
/ 2), LogicalToDeviceY(y
+ height
/ 2),
857 LogicalToDeviceXRel(width
/ 2), LogicalToDeviceYRel(height
/ 2) );
859 CalcBoundingBox( x
- width
, y
- height
);
860 CalcBoundingBox( x
+ width
, y
+ height
);
864 void wxPostScriptDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
866 DrawBitmap( icon
, x
, y
, true );
869 /* this has to be char, not wxChar */
870 static char hexArray
[] = "0123456789ABCDEF";
872 void wxPostScriptDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
874 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
876 if (!bitmap
.Ok()) return;
878 wxImage image
= bitmap
.ConvertToImage();
880 if (!image
.Ok()) return;
882 wxCoord w
= image
.GetWidth();
883 wxCoord h
= image
.GetHeight();
885 wxCoord ww
= LogicalToDeviceXRel(image
.GetWidth());
886 wxCoord hh
= LogicalToDeviceYRel(image
.GetHeight());
888 wxCoord xx
= LogicalToDeviceX(x
);
889 wxCoord yy
= LogicalToDeviceY(y
+ bitmap
.GetHeight());
891 PsPrintf( wxT("/origstate save def\n")
892 wxT("20 dict begin\n")
893 wxT("/pix %d string def\n")
894 wxT("/grays %d string def\n")
895 wxT("/npixels 0 def\n")
896 wxT("/rgbindx 0 def\n")
897 wxT("%d %d translate\n")
900 wxT("[%d 0 0 %d 0 %d]\n")
901 wxT("{currentfile pix readhexstring pop}\n")
902 wxT("false 3 colorimage\n"),
903 w
, w
, xx
, yy
, ww
, hh
, w
, h
, w
, -h
, h
);
905 unsigned char* data
= image
.GetData();
907 /* buffer = line = width*rgb(3)*hexa(2)+'\n'(1)+null(1) */
908 char* buffer
= new char[ w
*6+2 ];
909 int firstDigit
, secondDigit
;
912 for (int j
= 0; j
< h
; j
++)
914 char* bufferindex
= buffer
;
917 for (int i
= 0; i
< w
*3; i
++)
919 firstDigit
= (int)(*data
/16.0);
920 secondDigit
= (int)(*data
- (firstDigit
*16.0));
921 *(bufferindex
++) = hexArray
[firstDigit
];
922 *(bufferindex
++) = hexArray
[secondDigit
];
926 *(bufferindex
++) = '\n';
932 PsPrint( "origstate restore\n" );
935 void wxPostScriptDC::SetFont( const wxFont
& font
)
937 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
939 if (!font
.Ok()) return;
945 int Style
= m_font
.GetStyle();
946 int Weight
= m_font
.GetWeight();
949 switch (m_font
.GetFamily())
954 if (Style
== wxITALIC
)
956 if (Weight
== wxBOLD
)
957 name
= "/Courier-BoldOblique";
959 name
= "/Courier-Oblique";
963 if (Weight
== wxBOLD
)
964 name
= "/Courier-Bold";
972 if (Style
== wxITALIC
)
974 if (Weight
== wxBOLD
)
975 name
= "/Times-BoldItalic";
977 name
= "/Times-Italic";
981 if (Weight
== wxBOLD
)
982 name
= "/Times-Bold";
984 name
= "/Times-Roman";
990 name
= "/ZapfChancery-MediumItalic";
996 if (Style
== wxITALIC
)
998 if (Weight
== wxBOLD
)
999 name
= "/Helvetica-BoldOblique";
1001 name
= "/Helvetica-Oblique";
1005 if (Weight
== wxBOLD
)
1006 name
= "/Helvetica-Bold";
1008 name
= "/Helvetica";
1014 // We may legitimately call SetFont before BeginDoc
1019 PsPrint( " reencodeISO def\n" );
1021 PsPrint( " findfont\n" );
1024 sprintf( buffer
, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font
.GetPointSize() * 1000) / 1000.0F
);
1025 // this is a hack - we must scale font size (in pts) according to m_scaleY but
1026 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
1027 // to 1/1000th of pt and then back.
1028 for (int i
= 0; i
< 100; i
++)
1029 if (buffer
[i
] == ',') buffer
[i
] = '.';
1031 #endif // !wxUSE_PANGO
1034 void wxPostScriptDC::SetPen( const wxPen
& pen
)
1036 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1038 if (!pen
.Ok()) return;
1040 int oldStyle
= m_pen
.GetStyle();
1045 sprintf( buffer
, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen
.GetWidth()) / 1000.0f
);
1046 for (int i
= 0; i
< 100; i
++)
1047 if (buffer
[i
] == ',') buffer
[i
] = '.';
1051 Line style - WRONG: 2nd arg is OFFSET
1053 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1054 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1055 ter is not number of values in the array of the first one, but an offset
1056 into this description of the pattern. I mean a real *offset* not index
1057 into array. I.e. If the command is [3 4] 1 setdash is used, then there
1058 will be first black line *2* units wxCoord, then space 4 units, then the
1059 pattern of *3* units black, 4 units space will be repeated.
1062 static const char *dotted
= "[2 5] 2";
1063 static const char *short_dashed
= "[4 4] 2";
1064 static const char *wxCoord_dashed
= "[4 8] 2";
1065 static const char *dotted_dashed
= "[6 6 2 6] 4";
1069 switch (m_pen
.GetStyle())
1071 case wxDOT
: psdash
= dotted
; break;
1072 case wxSHORT_DASH
: psdash
= short_dashed
; break;
1073 case wxLONG_DASH
: psdash
= wxCoord_dashed
; break;
1074 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
1077 default: psdash
= "[] 0"; break;
1080 if ( (oldStyle
!= m_pen
.GetStyle()) )
1083 PsPrint( " setdash\n" );
1087 unsigned char red
= m_pen
.GetColour().Red();
1088 unsigned char blue
= m_pen
.GetColour().Blue();
1089 unsigned char green
= m_pen
.GetColour().Green();
1093 // Anything not white is black
1094 if (! (red
== (unsigned char) 255 &&
1095 blue
== (unsigned char) 255 &&
1096 green
== (unsigned char) 255) )
1098 red
= (unsigned char) 0;
1099 green
= (unsigned char) 0;
1100 blue
= (unsigned char) 0;
1105 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1107 double redPS
= (double)(red
) / 255.0;
1108 double bluePS
= (double)(blue
) / 255.0;
1109 double greenPS
= (double)(green
) / 255.0;
1113 "%.8f %.8f %.8f setrgbcolor\n",
1114 redPS
, greenPS
, bluePS
);
1115 for (int i
= 0; i
< 100; i
++)
1116 if (buffer
[i
] == ',') buffer
[i
] = '.';
1121 m_currentBlue
= blue
;
1122 m_currentGreen
= green
;
1126 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
1128 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1130 if (!brush
.Ok()) return;
1135 unsigned char red
= m_brush
.GetColour().Red();
1136 unsigned char blue
= m_brush
.GetColour().Blue();
1137 unsigned char green
= m_brush
.GetColour().Green();
1141 // Anything not white is black
1142 if (! (red
== (unsigned char) 255 &&
1143 blue
== (unsigned char) 255 &&
1144 green
== (unsigned char) 255) )
1146 red
= (unsigned char) 0;
1147 green
= (unsigned char) 0;
1148 blue
= (unsigned char) 0;
1153 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1155 double redPS
= (double)(red
) / 255.0;
1156 double bluePS
= (double)(blue
) / 255.0;
1157 double greenPS
= (double)(green
) / 255.0;
1161 "%.8f %.8f %.8f setrgbcolor\n",
1162 redPS
, greenPS
, bluePS
);
1163 for (int i
= 0; i
< 100; i
++)
1164 if (buffer
[i
] == ',') buffer
[i
] = '.';
1169 m_currentBlue
= blue
;
1170 m_currentGreen
= green
;
1176 #define PANGO_ENABLE_ENGINE
1179 #include "wx/gtk/private.h"
1180 #include "gtk/gtk.h"
1182 #include "wx/x11/private.h"
1185 #include <ft2build.h>
1186 #include FT_FREETYPE_H
1188 #include "wx/fontutil.h"
1189 #include <pango/pangoft2.h>
1190 #include <freetype/ftglyph.h>
1192 #ifndef FT_Outline_Decompose
1193 FT_EXPORT( FT_Error
) FT_Outline_Decompose(
1194 FT_Outline
* outline
,
1195 const FT_Outline_Funcs
* interface
,
1199 typedef struct _OutlineInfo OutlineInfo
;
1200 struct _OutlineInfo
{
1201 wxPostScriptDC
* caller
;
1204 static int paps_move_to( FT_Vector
* to
, void *user_data
)
1206 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1207 outline_info
->caller
->PsPrintf( wxT("%d %d moveto\n"), (int)to
->x
, (int)to
->y
);
1211 static int paps_line_to( FT_Vector
* to
, void *user_data
)
1213 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1214 outline_info
->caller
->PsPrintf( wxT("%d %d lineto\n"), (int)to
->x
, (int)to
->y
);
1218 static int paps_conic_to( FT_Vector
* control
, FT_Vector
* to
, void *user_data
)
1220 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1221 outline_info
->caller
->PsPrintf( wxT("%d %d %d %d conicto\n"),
1230 paps_cubic_to( FT_Vector
* control1
, FT_Vector
* control2
,
1231 FT_Vector
* to
, void *user_data
)
1233 OutlineInfo
*outline_info
= (OutlineInfo
*)user_data
;
1234 outline_info
->caller
->PsPrintf(wxT("%d %d %d %d %d %d curveto\n"),
1244 void draw_bezier_outline(wxPostScriptDC
* caller
,
1246 FT_UInt glyph_index
,
1252 FT_Int load_flags
= FT_LOAD_NO_BITMAP
;
1255 FT_Outline_Funcs outlinefunc
=
1263 OutlineInfo outline_info
;
1264 outline_info
.caller
= caller
;
1266 caller
->PsPrint("gsave\n");
1267 caller
->PsPrintf( wxT("%d %d translate\n"), pos_x
, pos_y
);
1269 // We have to replace the "," from the German
1270 // locale with the Englich "." for PostScript
1272 sprintf(buf
, "%.8f %.8f scale\n", scale_x
, scale_y
);
1273 for (size_t i
= 0; i
< strlen(buf
); i
++)
1274 if (buf
[i
] == ',') buf
[i
] = '.';
1275 caller
->PsPrint(buf
);
1277 FT_Load_Glyph(face
, glyph_index
, load_flags
);
1278 FT_Get_Glyph (face
->glyph
, &glyph
);
1279 FT_Outline_Decompose (&(((FT_OutlineGlyph
)glyph
)->outline
),
1280 &outlinefunc
, &outline_info
);
1281 caller
->PsPrint("closepath fill grestore\n");
1283 FT_Done_Glyph (glyph
);
1290 static void InitializePangoContext(PangoContext
*context
)
1293 pango_context_set_base_dir(context
,
1294 gtk_widget_get_default_direction() == GTK_TEXT_DIR_LTR
?
1295 PANGO_DIRECTION_LTR
: PANGO_DIRECTION_RTL
);
1296 pango_context_set_language(context
, gtk_get_default_language());
1298 // FIXME: assuming LTR is incorrect!
1299 pango_context_set_base_dir(context
, PANGO_DIRECTION_LTR
);
1300 wxString lang
= wxGetLocale()->GetCanonicalName();
1301 pango_context_set_language(context
,
1302 pango_language_from_string(lang
.ToAscii()));
1307 void wxPostScriptDC::DoDrawText( const wxString
& text
, wxCoord x
, wxCoord y
)
1309 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1311 if (m_textForegroundColour
.Ok())
1313 unsigned char red
= m_textForegroundColour
.Red();
1314 unsigned char blue
= m_textForegroundColour
.Blue();
1315 unsigned char green
= m_textForegroundColour
.Green();
1319 // Anything not white is black
1320 if (! (red
== (unsigned char) 255 &&
1321 blue
== (unsigned char) 255 &&
1322 green
== (unsigned char) 255))
1324 red
= (unsigned char) 0;
1325 green
= (unsigned char) 0;
1326 blue
= (unsigned char) 0;
1330 // maybe setgray here ?
1331 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1333 double redPS
= (double)(red
) / 255.0;
1334 double bluePS
= (double)(blue
) / 255.0;
1335 double greenPS
= (double)(green
) / 255.0;
1339 "%.8f %.8f %.8f setrgbcolor\n",
1340 redPS
, greenPS
, bluePS
);
1341 for (size_t i
= 0; i
< strlen(buffer
); i
++)
1342 if (buffer
[i
] == ',') buffer
[i
] = '.';
1346 m_currentBlue
= blue
;
1347 m_currentGreen
= green
;
1353 int pango_dpi
= 600;
1354 PangoContext
*context
= pango_ft2_get_context ( pango_dpi
, pango_dpi
);
1356 InitializePangoContext(context
);
1358 double scale
= (double)pango_dpi
/ (double)ps_dpi
;
1359 scale
/= m_userScaleY
;
1361 pango_context_set_font_description (context
, m_font
.GetNativeFontInfo()->description
);
1363 PangoLayout
*layout
= pango_layout_new (context
);
1365 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( text
);
1367 wxCharBuffer buffer
= wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) );
1369 pango_layout_set_text( layout
, (const char*) buffer
, strlen(buffer
) );
1371 PsPrintf( wxT("%%%% %s\n"), text
.c_str() );
1373 PangoRectangle rect
;
1374 pango_layout_get_extents(layout
, NULL
, &rect
);
1376 int xx
= LogicalToDeviceX( x
);
1377 int yy
= LogicalToDeviceY( y
);
1379 int xxx
= xx
* PANGO_SCALE
;
1380 int yyy
= yy
* PANGO_SCALE
- (int)(rect
.height
* 0.66 / scale
); // Move down by estimated baseline. HACK.
1382 #define ps_kludge_factor 2.8
1384 // Loop over lines in layout
1385 int num_lines
= pango_layout_get_line_count( layout
);
1386 for (int i
= 0; i
< num_lines
; i
++)
1388 PangoLayoutLine
*line
= pango_layout_get_line( layout
, i
);
1390 // width of glyphs already printed
1393 // Loop over runs in line
1394 GSList
*runs_list
= line
->runs
;
1397 PangoLayoutRun
*run
= (PangoLayoutRun
*) runs_list
->data
;
1398 PangoItem
*item
= run
->item
;
1399 PangoGlyphString
*glyphs
= run
->glyphs
;
1400 PangoAnalysis
*analysis
= &item
->analysis
;
1401 PangoFont
*font
= analysis
->font
;
1402 FT_Face ft_face
= pango_ft2_font_get_face(font
);
1404 int num_glyphs
= glyphs
->num_glyphs
;
1405 for (int glyph_idx
= 0; glyph_idx
< num_glyphs
; glyph_idx
++)
1407 PangoGlyphGeometry geometry
= glyphs
->glyphs
[glyph_idx
].geometry
;
1408 int pos_x
= xxx
+ (int)((double)(all_width
+geometry
.x_offset
) / scale
);
1409 int pos_y
= yyy
+ (int)((double)geometry
.y_offset
/ scale
);
1410 all_width
+= geometry
.width
;
1412 draw_bezier_outline( this, ft_face
,
1413 (FT_UInt
)(glyphs
->glyphs
[glyph_idx
].glyph
),
1414 pos_x
/ PANGO_SCALE
,
1415 pos_y
/ PANGO_SCALE
,
1416 1.0/(ps_kludge_factor
* scale
* 26.6),
1417 1.0/(ps_kludge_factor
* scale
* 26.6) );
1419 runs_list
= runs_list
->next
;
1423 g_object_unref( G_OBJECT( layout
) );
1424 g_object_unref( G_OBJECT( context
) );
1425 #else // !wxUSE_PANGO
1426 wxCoord text_w
, text_h
, text_descent
;
1428 GetTextExtent(text
, &text_w
, &text_h
, &text_descent
);
1430 // VZ: this seems to be unnecessary, so taking it out for now, if it
1431 // doesn't create any problems, remove this comment entirely
1432 //SetFont( m_font );
1435 int size
= m_font
.GetPointSize();
1437 // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1438 // commented by V. Slavik and replaced by accurate version
1439 // - note that there is still rounding error in text_descent!
1440 wxCoord by
= y
+ size
- text_descent
; // baseline
1442 PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x
), LogicalToDeviceY(by
) );
1445 const wxWX2MBbuf textbuf
= text
.mb_str();
1446 size_t len
= strlen(textbuf
);
1448 for (i
= 0; i
< len
; i
++)
1450 int c
= (unsigned char) textbuf
[i
];
1451 if (c
== ')' || c
== '(' || c
== '\\')
1453 /* Cope with special characters */
1457 else if ( c
>= 128 )
1459 /* Cope with character codes > 127 */
1460 PsPrintf( wxT("\\%o"), c
);
1468 PsPrint( ") show\n" );
1470 if (m_font
.GetUnderlined())
1472 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1482 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1483 m_underlineThickness
,
1484 LogicalToDeviceX(x
+ text_w
), LogicalToDeviceY(uy
) );
1485 for (i
= 0; i
< 100; i
++)
1486 if (buffer
[i
] == ',') buffer
[i
] = '.';
1490 CalcBoundingBox( x
, y
);
1491 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1492 #endif // wxUSE_PANGO/!wxUSE_PANGO
1495 void wxPostScriptDC::DoDrawRotatedText( const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1499 DoDrawText(text
, x
, y
);
1503 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1507 if (m_textForegroundColour
.Ok())
1509 unsigned char red
= m_textForegroundColour
.Red();
1510 unsigned char blue
= m_textForegroundColour
.Blue();
1511 unsigned char green
= m_textForegroundColour
.Green();
1515 // Anything not white is black
1516 if (! (red
== (unsigned char) 255 &&
1517 blue
== (unsigned char) 255 &&
1518 green
== (unsigned char) 255))
1520 red
= (unsigned char) 0;
1521 green
= (unsigned char) 0;
1522 blue
= (unsigned char) 0;
1526 // maybe setgray here ?
1527 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1529 double redPS
= (double)(red
) / 255.0;
1530 double bluePS
= (double)(blue
) / 255.0;
1531 double greenPS
= (double)(green
) / 255.0;
1535 "%.8f %.8f %.8f setrgbcolor\n",
1536 redPS
, greenPS
, bluePS
);
1537 for (int i
= 0; i
< 100; i
++)
1538 if (buffer
[i
] == ',') buffer
[i
] = '.';
1542 m_currentBlue
= blue
;
1543 m_currentGreen
= green
;
1547 int size
= m_font
.GetPointSize();
1549 PsPrintf( wxT("%d %d moveto\n"),
1550 LogicalToDeviceX(x
), LogicalToDeviceY(y
));
1553 sprintf(buffer
, "%.8f rotate\n", angle
);
1555 for (i
= 0; i
< 100; i
++)
1557 if (buffer
[i
] == ',') buffer
[i
] = '.';
1562 const wxWX2MBbuf textbuf
= text
.mb_str();
1563 size_t len
= strlen(textbuf
);
1564 for (i
= 0; i
< len
; i
++)
1566 int c
= (unsigned char) textbuf
[i
];
1567 if (c
== ')' || c
== '(' || c
== '\\')
1569 /* Cope with special characters */
1573 else if ( c
>= 128 )
1575 /* Cope with character codes > 127 */
1576 PsPrintf( wxT("\\%o"), c
);
1584 PsPrint( ") show\n" );
1586 sprintf( buffer
, "%.8f rotate\n", -angle
);
1587 for (i
= 0; i
< 100; i
++)
1589 if (buffer
[i
] == ',') buffer
[i
] = '.';
1593 if (m_font
.GetUnderlined())
1595 wxCoord uy
= (wxCoord
)(y
+ size
- m_underlinePosition
);
1598 GetTextExtent(text
, &w
, &h
);
1607 LogicalToDeviceX(x
), LogicalToDeviceY(uy
),
1608 m_underlineThickness
,
1609 LogicalToDeviceX(x
+ w
), LogicalToDeviceY(uy
) );
1610 for (i
= 0; i
< 100; i
++)
1612 if (buffer
[i
] == ',') buffer
[i
] = '.';
1617 CalcBoundingBox( x
, y
);
1618 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
1621 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
1623 m_backgroundBrush
= brush
;
1626 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
1628 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
1631 void wxPostScriptDC::DoDrawSpline( wxList
*points
)
1633 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1637 // a and b are not used
1639 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1642 wxList::compatibility_iterator node
= points
->GetFirst();
1643 p
= (wxPoint
*)node
->GetData();
1647 node
= node
->GetNext();
1648 p
= (wxPoint
*)node
->GetData();
1655 (double)(x1
+ c
) / 2;
1660 (double)(y1
+ d
) / 2;
1662 PsPrintf( wxT("newpath\n")
1663 wxT("%d %d moveto\n")
1664 wxT("%d %d lineto\n"),
1665 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1666 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1668 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1669 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1671 node
= node
->GetNext();
1674 q
= (wxPoint
*)node
->GetData();
1682 x3
= (double)(x2
+ c
) / 2;
1683 y3
= (double)(y2
+ d
) / 2;
1685 PsPrintf( wxT("%d %d %d %d %d %d DrawSplineSection\n"),
1686 LogicalToDeviceX((wxCoord
)x1
), LogicalToDeviceY((wxCoord
)y1
),
1687 LogicalToDeviceX((wxCoord
)x2
), LogicalToDeviceY((wxCoord
)y2
),
1688 LogicalToDeviceX((wxCoord
)x3
), LogicalToDeviceY((wxCoord
)y3
) );
1690 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1691 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1693 node
= node
->GetNext();
1697 At this point, (x2,y2) and (c,d) are the position of the
1698 next-to-last and last point respectively, in the point list
1701 PsPrintf( wxT("%d %d lineto\n")
1703 LogicalToDeviceX((wxCoord
)c
), LogicalToDeviceY((wxCoord
)d
) );
1706 wxCoord
wxPostScriptDC::GetCharWidth() const
1708 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1709 return (wxCoord
) (GetCharHeight() * 72.0 / 120.0);
1713 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1715 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1717 m_signX
= (xLeftRight
? 1 : -1);
1718 m_signY
= (yBottomUp
? 1 : -1);
1720 // FIXME there is no such function in MSW nor in OS2/PM
1721 #if !defined(__WXMSW__) && !defined(__WXPM__)
1722 ComputeScaleAndOrigin();
1726 void wxPostScriptDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1728 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1734 wxDC::SetDeviceOrigin( x
, h
-y
);
1737 void wxPostScriptDC::DoGetSize(int* width
, int* height
) const
1739 wxPaperSize id
= m_printData
.GetPaperId();
1741 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1743 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1749 w
= paper
->GetSizeDeviceUnits().x
;
1750 h
= paper
->GetSizeDeviceUnits().y
;
1753 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1760 if (width
) *width
= (int)(w
* ms_PSScaleFactor
);
1761 if (height
) *height
= (int)(h
* ms_PSScaleFactor
);
1764 void wxPostScriptDC::DoGetSizeMM(int *width
, int *height
) const
1766 wxPaperSize id
= m_printData
.GetPaperId();
1768 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(id
);
1770 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1776 w
= paper
->GetWidth() / 10;
1777 h
= paper
->GetHeight() / 10;
1780 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1787 if (width
) *width
= w
;
1788 if (height
) *height
= h
;
1791 // Resolution in pixels per logical inch
1792 wxSize
wxPostScriptDC::GetPPI(void) const
1794 return wxSize((int)(72 * ms_PSScaleFactor
),
1795 (int)(72 * ms_PSScaleFactor
));
1799 bool wxPostScriptDC::StartDoc( const wxString
& message
)
1801 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
1803 if ( m_printData
.GetPrintMode() != wxPRINT_MODE_STREAM
)
1805 if (m_printData
.GetFilename() == wxEmptyString
)
1807 wxString filename
= wxGetTempFileName( wxT("ps") );
1808 m_printData
.SetFilename(filename
);
1811 // FIXME: use fn_str() here under Unicode?
1812 m_pstream
= wxFopen( m_printData
.GetFilename().c_str(), wxT("w+") );
1816 wxLogError( _("Cannot open file for PostScript printing!"));
1825 PsPrint( "%!PS-Adobe-2.0\n" );
1826 PsPrintf( wxT("%%%%Title: %s\n"), m_title
.c_str() );
1827 PsPrint( "%%Creator: wxWidgets PostScript renderer\n" );
1828 PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() );
1829 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1830 PsPrint( "%%Orientation: Landscape\n" );
1832 PsPrint( "%%Orientation: Portrait\n" );
1834 // PsPrintf( wxT("%%%%Pages: %d\n"), (wxPageNumber - 1) );
1836 const wxChar
*paper
;
1837 switch (m_printData
.GetPaperId())
1839 case wxPAPER_LETTER
: paper
= wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches
1840 case wxPAPER_LEGAL
: paper
= wxT("Legal"); break; // Legal, 8 1/2 by 14 inches
1841 case wxPAPER_A4
: paper
= wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters
1842 case wxPAPER_TABLOID
: paper
= wxT("Tabloid"); break; // Tabloid, 11 by 17 inches
1843 case wxPAPER_LEDGER
: paper
= wxT("Ledger"); break; // Ledger, 17 by 11 inches
1844 case wxPAPER_STATEMENT
: paper
= wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches
1845 case wxPAPER_EXECUTIVE
: paper
= wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches
1846 case wxPAPER_A3
: paper
= wxT("A3"); break; // A3 sheet, 297 by 420 millimeters
1847 case wxPAPER_A5
: paper
= wxT("A5"); break; // A5 sheet, 148 by 210 millimeters
1848 case wxPAPER_B4
: paper
= wxT("B4"); break; // B4 sheet, 250 by 354 millimeters
1849 case wxPAPER_B5
: paper
= wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper
1850 case wxPAPER_FOLIO
: paper
= wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper
1851 case wxPAPER_QUARTO
: paper
= wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper
1852 case wxPAPER_10X14
: paper
= wxT("10x14"); break; // 10-by-14-inch sheet
1853 default: paper
= wxT("A4");
1855 PsPrintf( wxT("%%%%DocumentPaperSizes: %s\n"), paper
);
1856 PsPrint( "%%EndComments\n\n" );
1858 PsPrint( "%%BeginProlog\n" );
1859 PsPrint( wxPostScriptHeaderConicTo
);
1860 PsPrint( wxPostScriptHeaderEllipse
);
1861 PsPrint( wxPostScriptHeaderEllipticArc
);
1862 PsPrint( wxPostScriptHeaderColourImage
);
1865 PsPrint( wxPostScriptHeaderReencodeISO1
);
1866 PsPrint( wxPostScriptHeaderReencodeISO2
);
1868 if (wxPostScriptHeaderSpline
)
1869 PsPrint( wxPostScriptHeaderSpline
);
1870 PsPrint( "%%EndProlog\n" );
1872 SetBrush( *wxBLACK_BRUSH
);
1873 SetPen( *wxBLACK_PEN
);
1874 SetBackground( *wxWHITE_BRUSH
);
1875 SetTextForeground( *wxBLACK
);
1877 // set origin according to paper size
1878 SetDeviceOrigin( 0,0 );
1885 void wxPostScriptDC::EndDoc ()
1887 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1892 PsPrint( "grestore\n" );
1896 fclose( m_pstream
);
1897 m_pstream
= (FILE *) NULL
;
1901 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1902 wxCoord wx_printer_translate_x
, wx_printer_translate_y
;
1903 double wx_printer_scale_x
, wx_printer_scale_y
;
1905 wx_printer_translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
1906 wx_printer_translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
1908 wx_printer_scale_x
= m_printData
.GetPrinterScaleX();
1909 wx_printer_scale_y
= m_printData
.GetPrinterScaleY();
1911 // Compute the bounding box. Note that it is in the default user
1912 // coordinate system, thus we have to convert the values.
1913 wxCoord minX
= (wxCoord
) LogicalToDeviceX(m_minX
);
1914 wxCoord minY
= (wxCoord
) LogicalToDeviceY(m_minY
);
1915 wxCoord maxX
= (wxCoord
) LogicalToDeviceX(m_maxX
);
1916 wxCoord maxY
= (wxCoord
) LogicalToDeviceY(m_maxY
);
1918 // LOG2DEV may have changed the minimum to maximum vice versa
1919 if ( minX
> maxX
) { wxCoord tmp
= minX
; minX
= maxX
; maxX
= tmp
; }
1920 if ( minY
> maxY
) { wxCoord tmp
= minY
; minY
= maxY
; maxY
= tmp
; }
1922 // account for used scaling (boundingbox is before scaling in ps-file)
1923 double scale_x
= m_printData
.GetPrinterScaleX() / ms_PSScaleFactor
;
1924 double scale_y
= m_printData
.GetPrinterScaleY() / ms_PSScaleFactor
;
1926 wxCoord llx
, lly
, urx
, ury
;
1927 llx
= (wxCoord
) ((minX
+wx_printer_translate_x
)*scale_x
);
1928 lly
= (wxCoord
) ((minY
+wx_printer_translate_y
)*scale_y
);
1929 urx
= (wxCoord
) ((maxX
+wx_printer_translate_x
)*scale_x
);
1930 ury
= (wxCoord
) ((maxY
+wx_printer_translate_y
)*scale_y
);
1931 // (end of bounding box computation)
1934 // If we're landscape, our sense of "x" and "y" is reversed.
1935 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
1938 tmp
= llx
; llx
= lly
; lly
= tmp
;
1939 tmp
= urx
; urx
= ury
; ury
= tmp
;
1941 // We need either the two lines that follow, or we need to subtract
1942 // min_x from real_translate_y, which is commented out below.
1943 llx
= llx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1944 urx
= urx
- (wxCoord
)(m_minX
*wx_printer_scale_y
);
1947 // The Adobe specifications call for integers; we round as to make
1948 // the bounding larger.
1949 PsPrintf( wxT("%%%%BoundingBox: %d %d %d %d\n"),
1950 (wxCoord
)floor((double)llx
), (wxCoord
)floor((double)lly
),
1951 (wxCoord
)ceil((double)urx
), (wxCoord
)ceil((double)ury
) );
1953 // To check the correctness of the bounding box, postscript commands
1954 // to draw a box corresponding to the bounding box are generated below.
1955 // But since we typically don't want to print such a box, the postscript
1956 // commands are generated within comments. These lines appear before any
1957 // adjustment of scale, rotation, or translation, and hence are in the
1958 // default user coordinates.
1959 PsPrint( "% newpath\n" );
1960 PsPrintf( wxT("%% %d %d moveto\n"), llx
, lly
);
1961 PsPrintf( wxT("%% %d %d lineto\n"), urx
, lly
);
1962 PsPrintf( wxT("%% %d %d lineto\n"), urx
, ury
);
1963 PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx
, ury
);
1966 #if defined(__X__) || defined(__WXGTK__)
1967 if (m_ok
&& (m_printData
.GetPrintMode() == wxPRINT_MODE_PRINTER
))
1970 command
+= m_printData
.GetPrinterCommand();
1971 command
+= wxT(" ");
1972 command
+= m_printData
.GetPrinterOptions();
1973 command
+= wxT(" ");
1974 command
+= m_printData
.GetFilename();
1976 wxExecute( command
, true );
1977 wxRemoveFile( m_printData
.GetFilename() );
1982 void wxPostScriptDC::StartPage()
1984 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
1986 PsPrintf( wxT("%%%%Page: %d\n"), wxPageNumber
++ );
1988 // What is this one supposed to do? RR.
1989 // *m_pstream << "matrix currentmatrix\n";
1991 // Added by Chris Breeze
1993 // Each page starts with an "initgraphics" which resets the
1994 // transformation and so we need to reset the origin
1995 // (and rotate the page for landscape printing)
1998 wxCoord translate_x
, translate_y
;
1999 double scale_x
, scale_y
;
2001 translate_x
= (wxCoord
)m_printData
.GetPrinterTranslateX();
2002 translate_y
= (wxCoord
)m_printData
.GetPrinterTranslateY();
2004 scale_x
= m_printData
.GetPrinterScaleX();
2005 scale_y
= m_printData
.GetPrinterScaleY();
2007 if (m_printData
.GetOrientation() == wxLANDSCAPE
)
2010 GetSize( (int*) NULL
, &h
);
2012 PsPrint( "90 rotate\n" );
2013 // I copied this one from a PostScript tutorial, but to no avail. RR.
2014 // PsPrint( "90 rotate llx neg ury nef translate\n" );
2018 sprintf( buffer
, "%.8f %.8f scale\n", scale_x
/ ms_PSScaleFactor
,
2019 scale_y
/ ms_PSScaleFactor
);
2020 for (int i
= 0; i
< 100; i
++)
2021 if (buffer
[i
] == ',') buffer
[i
] = '.';
2024 PsPrintf( wxT("%d %d translate\n"), translate_x
, translate_y
);
2027 void wxPostScriptDC::EndPage ()
2029 wxCHECK_RET( m_ok
, wxT("invalid postscript dc") );
2031 PsPrint( "showpage\n" );
2034 bool wxPostScriptDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
2035 wxCoord fwidth
, wxCoord fheight
,
2037 wxCoord xsrc
, wxCoord ysrc
,
2038 int rop
, bool WXUNUSED(useMask
), wxCoord
WXUNUSED(xsrcMask
), wxCoord
WXUNUSED(ysrcMask
) )
2040 wxCHECK_MSG( m_ok
, false, wxT("invalid postscript dc") );
2042 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
2044 /* blit into a bitmap */
2045 wxBitmap
bitmap( (int)fwidth
, (int)fheight
);
2047 memDC
.SelectObject(bitmap
);
2048 memDC
.Blit(0, 0, fwidth
, fheight
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
2049 memDC
.SelectObject(wxNullBitmap
);
2051 /* draw bitmap. scaling and positioning is done there */
2052 DrawBitmap( bitmap
, xdest
, ydest
);
2057 wxCoord
wxPostScriptDC::GetCharHeight() const
2060 return m_font
.GetPointSize();
2065 void wxPostScriptDC::DoGetTextExtent(const wxString
& string
,
2066 wxCoord
*x
, wxCoord
*y
,
2067 wxCoord
*descent
, wxCoord
*externalLeading
,
2068 wxFont
*theFont
) const
2070 wxFont
*fontToUse
= theFont
;
2072 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
2074 wxCHECK_RET( fontToUse
, wxT("GetTextExtent: no font defined") );
2076 if (string
.IsEmpty())
2080 if (descent
) (*descent
) = 0;
2081 if (externalLeading
) (*externalLeading
) = 0;
2086 int wx_dpi
= GetResolution();
2087 int pango_dpi
= 600;
2088 PangoContext
*context
= pango_ft2_get_context ( pango_dpi
, pango_dpi
);
2090 InitializePangoContext(context
);
2092 double scale
= pango_dpi
/ wx_dpi
;
2093 scale
/= m_userScaleY
;
2095 PangoLayout
*layout
= pango_layout_new (context
);
2097 PangoFontDescription
*desc
= fontToUse
->GetNativeFontInfo()->description
;
2098 pango_layout_set_font_description(layout
, desc
);
2100 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
2102 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
2103 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
2105 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
2107 PangoRectangle rect
;
2108 pango_layout_get_extents(layout
, NULL
, &rect
);
2110 if (x
) (*x
) = (wxCoord
) ( PANGO_PIXELS(rect
.width
) / scale
);
2111 if (y
) (*y
) = (wxCoord
) ( PANGO_PIXELS(rect
.height
) / scale
);
2114 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
2115 int baseline
= pango_layout_iter_get_baseline(iter
);
2116 pango_layout_iter_free(iter
);
2117 *descent
= wxCoord(*y
- PANGO_PIXELS(baseline
) / scale
);
2119 if (externalLeading
) (*externalLeading
) = 0; // ??
2121 g_object_unref( G_OBJECT( layout
) );
2125 const wxWX2MBbuf strbuf
= string
.mb_str();
2127 #if !wxUSE_AFM_FOR_POSTSCRIPT
2128 /* Provide a VERY rough estimate (avoid using it).
2129 * Produces accurate results for mono-spaced font
2130 * such as Courier (aka wxMODERN) */
2135 height
= fontToUse
->GetPointSize();
2138 *x
= strlen (strbuf
) * height
* 72 / 120;
2140 *y
= (wxCoord
) (height
* 1.32); /* allow for descender */
2141 if (descent
) *descent
= 0;
2142 if (externalLeading
) *externalLeading
= 0;
2145 /* method for calculating string widths in postscript:
2146 / read in the AFM (adobe font metrics) file for the
2147 / actual font, parse it and extract the character widths
2148 / and also the descender. this may be improved, but for now
2149 / it works well. the AFM file is only read in if the
2150 / font is changed. this may be chached in the future.
2151 / calls to GetTextExtent with the font unchanged are rather
2154 / for each font and style used there is an AFM file necessary.
2155 / currently i have only files for the roman font family.
2156 / I try to get files for the other ones!
2158 / CAVE: the size of the string is currently always calculated
2159 / in 'points' (1/72 of an inch). this should later on be
2160 / changed to depend on the mapping mode.
2161 / CAVE: the path to the AFM files must be set before calling this
2162 / function. this is usually done by a call like the following:
2163 / wxSetAFMPath("d:\\wxw161\\afm\\");
2167 / wxPostScriptDC dc(NULL, true);
2169 / wxSetAFMPath("d:\\wxw161\\afm\\");
2170 / dc.StartDoc("Test");
2173 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
2174 / dc.GetTextExtent("Hallo",&w,&h);
2179 / by steve (stefan.hammes@urz.uni-heidelberg.de)
2181 / updated: 14.05.95 */
2183 /* these static vars are for storing the state between calls */
2184 static int lastFamily
= INT_MIN
;
2185 static int lastSize
= INT_MIN
;
2186 static int lastStyle
= INT_MIN
;
2187 static int lastWeight
= INT_MIN
;
2188 static int lastDescender
= INT_MIN
;
2189 static int lastWidths
[256]; /* widths of the characters */
2191 double UnderlinePosition
= 0.0;
2192 double UnderlineThickness
= 0.0;
2194 // Get actual parameters
2195 int Family
= fontToUse
->GetFamily();
2196 int Size
= fontToUse
->GetPointSize();
2197 int Style
= fontToUse
->GetStyle();
2198 int Weight
= fontToUse
->GetWeight();
2200 // If we have another font, read the font-metrics
2201 if (Family
!=lastFamily
|| Size
!=lastSize
|| Style
!=lastStyle
|| Weight
!=lastWeight
)
2203 // Store actual values
2204 lastFamily
= Family
;
2207 lastWeight
= Weight
;
2216 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBoO.afm");
2217 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("CourBo.afm");
2218 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("CourO.afm");
2219 else name
= wxT("Cour.afm");
2224 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBoO.afm");
2225 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("TimesBo.afm");
2226 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("TimesO.afm");
2227 else name
= wxT("TimesRo.afm");
2232 name
= wxT("Zapf.afm");
2238 if ((Style
== wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBoO.afm");
2239 else if ((Style
!= wxITALIC
) && (Weight
== wxBOLD
)) name
= wxT("HelvBo.afm");
2240 else if ((Style
== wxITALIC
) && (Weight
!= wxBOLD
)) name
= wxT("HelvO.afm");
2241 else name
= wxT("Helv.afm");
2246 FILE *afmFile
= NULL
;
2248 // Get the directory of the AFM files
2250 if (!m_printData
.GetFontMetricPath().IsEmpty())
2252 afmName
= m_printData
.GetFontMetricPath();
2253 afmName
<< wxFILE_SEP_PATH
<< name
;
2254 afmFile
= wxFopen(afmName
,wxT("r"));
2257 #if defined(__UNIX__) && !defined(__VMS__)
2260 afmName
= wxGetDataDir();
2261 afmName
<< wxFILE_SEP_PATH
2262 #if defined(__LINUX__) || defined(__FREEBSD__)
2263 << wxT("gs_afm") << wxFILE_SEP_PATH
2265 << wxT("afm") << wxFILE_SEP_PATH
2268 afmFile
= wxFopen(afmName
,wxT("r"));
2272 /* 2. open and process the file
2273 / a short explanation of the AFM format:
2274 / we have for each character a line, which gives its size
2277 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2279 / that means, we have a character with ascii code 63, and width
2280 / (444/1000 * fontSize) points.
2281 / the other data is ignored for now!
2283 / when the font has changed, we read in the right AFM file and store the
2284 / character widths in an array, which is processed below (see point 3.). */
2287 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName
.c_str() );
2288 wxLogDebug( wxT(" using approximate values"));
2289 for (int i
=0; i
<256; i
++) lastWidths
[i
] = 500; /* an approximate value */
2290 lastDescender
= -150; /* dito. */
2294 /* init the widths array */
2295 for(int i
=0; i
<256; i
++) lastWidths
[i
] = INT_MIN
;
2296 /* some variables for holding parts of a line */
2297 char cString
[10],semiString
[10],WXString
[10],descString
[20];
2298 char upString
[30], utString
[30], encString
[50];
2301 /* read in the file and parse it */
2302 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
)
2304 /* A.) check for descender definition */
2305 if (strncmp(line
,"Descender",9)==0)
2307 if ((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2) ||
2308 (strcmp(descString
,"Descender")!=0))
2310 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName
.c_str(),line
);
2313 /* JC 1.) check for UnderlinePosition */
2314 else if(strncmp(line
,"UnderlinePosition",17)==0)
2316 if ((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2) ||
2317 (strcmp(upString
,"UnderlinePosition")!=0))
2319 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName
.c_str(), line
);
2322 /* JC 2.) check for UnderlineThickness */
2323 else if(strncmp(line
,"UnderlineThickness",18)==0)
2325 if ((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2) ||
2326 (strcmp(utString
,"UnderlineThickness")!=0))
2328 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName
.c_str(), line
);
2331 /* JC 3.) check for EncodingScheme */
2332 else if(strncmp(line
,"EncodingScheme",14)==0)
2334 if ((sscanf(line
,"%s%s",utString
,encString
)!=2) ||
2335 (strcmp(utString
,"EncodingScheme")!=0))
2337 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName
.c_str(), line
);
2339 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
2341 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
2342 afmName
.c_str(),line
, encString
);
2345 /* B.) check for char-width */
2346 else if(strncmp(line
,"C ",2)==0)
2348 if (sscanf(line
,"%s%d%s%s%d",cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5)
2350 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName
.c_str(),line
);
2352 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 || strcmp(WXString
,"WX")!=0)
2354 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName
.c_str(),line
);
2356 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2357 if (ascii
>=0 && ascii
<256)
2359 lastWidths
[ascii
] = cWidth
; /* store width */
2363 /* MATTHEW: this happens a lot; don't print an error */
2364 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
2367 /* C.) ignore other entries. */
2371 /* hack to compute correct values for german 'Umlaute'
2372 / the correct way would be to map the character names
2373 / like 'adieresis' to corresp. positions of ISOEnc and read
2374 / these values from AFM files, too. Maybe later ... */
2376 // NB: casts to int are needed to suppress gcc 3.3 warnings
2377 lastWidths
[196] = lastWidths
[(int)'A']; // Ä
2378 lastWidths
[228] = lastWidths
[(int)'a']; // ä
2379 lastWidths
[214] = lastWidths
[(int)'O']; // Ö
2380 lastWidths
[246] = lastWidths
[(int)'o']; // ö
2381 lastWidths
[220] = lastWidths
[(int)'U']; // Ü
2382 lastWidths
[252] = lastWidths
[(int)'u']; // ü
2383 lastWidths
[223] = lastWidths
[(int)251]; // ß
2385 /* JC: calculate UnderlineThickness/UnderlinePosition */
2387 // VS: dirty, but is there any better solution?
2389 pt
= (double*) &m_underlinePosition
;
2390 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlinePosition
* fontToUse
->GetPointSize())) / 1000.0f
;
2391 pt
= (double*) &m_underlineThickness
;
2392 *pt
= LogicalToDeviceYRel((wxCoord
)(UnderlineThickness
* fontToUse
->GetPointSize())) / 1000.0f
;
2397 /* 3. now the font metrics are read in, calc size this
2398 / is done by adding the widths of the characters in the
2399 / string. they are given in 1/1000 of the size! */
2402 wxCoord height
=Size
; /* by default */
2404 for(p
=(unsigned char *)wxMBSTRINGCAST strbuf
; *p
; p
++)
2406 if(lastWidths
[*p
]== INT_MIN
)
2408 wxLogDebug(wxT("GetTextExtent: undefined width for character '%c' (%d)"), *p
,*p
);
2409 sum
+= lastWidths
[(unsigned char)' ']; /* assume space */
2413 sum
+= lastWidths
[*p
];
2417 double widthSum
= sum
;
2419 widthSum
/= 1000.0F
;
2421 /* add descender to height (it is usually a negative value) */
2422 //if (lastDescender != INT_MIN)
2424 // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
2426 // - commented by V. Slavik - height already contains descender in it
2427 // (judging from few experiments)
2429 /* return size values */
2431 *x
= (wxCoord
)widthSum
;
2435 /* return other parameters */
2438 if(lastDescender
!=INT_MIN
)
2440 *descent
= (wxCoord
)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
2448 /* currently no idea how to calculate this! */
2449 if (externalLeading
) *externalLeading
= 0;
2457 // print postscript datas via required method (file, stream)
2458 void wxPostScriptDC::PsPrintf( const wxChar
* fmt
, ... )
2461 va_start(argptr
, fmt
);
2463 PsPrint( wxString::FormatV( fmt
, argptr
).c_str() );
2466 void wxPostScriptDC::PsPrint( const char* psdata
)
2468 switch( m_printData
.GetPrintMode() )
2471 // append to output stream
2472 case wxPRINT_MODE_STREAM
:
2474 wxOutputStream
* outputstream
= m_printData
.GetOutputStream();
2475 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2476 outputstream
->Write( psdata
, strlen( psdata
) );
2479 #endif // wxUSE_STREAMS
2481 // save data into file
2483 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2484 fwrite( psdata
, 1, strlen( psdata
), m_pstream
);
2488 void wxPostScriptDC::PsPrint( int ch
)
2490 switch( m_printData
.GetPrintMode() )
2493 // append to output stream
2494 case wxPRINT_MODE_STREAM
:
2496 wxOutputStream
* outputstream
= m_printData
.GetOutputStream();
2497 wxCHECK_RET( outputstream
, wxT("invalid outputstream") );
2498 outputstream
->PutC( ch
);
2501 #endif // wxUSE_STREAMS
2503 // save data into file
2505 wxCHECK_RET( m_pstream
, wxT("invalid postscript dc") );
2506 fputc( ch
, m_pstream
);
2510 #if WXWIN_COMPATIBILITY_2_2
2511 WXDLLEXPORT wxPrintSetupData
*wxThePrintSetupData
= 0;
2513 void wxInitializePrintSetupData(bool init
)
2517 // gets initialized in the constructor
2518 wxThePrintSetupData
= new wxPrintSetupData
;
2522 delete wxThePrintSetupData
;
2524 wxThePrintSetupData
= (wxPrintSetupData
*) NULL
;
2528 // A module to allow initialization/cleanup of PostScript-related
2529 // things without calling these functions from app.cpp.
2531 class WXDLLEXPORT wxPostScriptModule
: public wxModule
2533 DECLARE_DYNAMIC_CLASS(wxPostScriptModule
)
2535 wxPostScriptModule() {}
2540 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule
, wxModule
)
2542 bool wxPostScriptModule::OnInit()
2544 wxInitializePrintSetupData();
2549 void wxPostScriptModule::OnExit()
2551 wxInitializePrintSetupData(false);
2554 // WXWIN_COMPATIBILITY_2_2
2560 // wxUSE_PRINTING_ARCHITECTURE