]> git.saurik.com Git - wxWidgets.git/blame - src/generic/dcpsg.cpp
Added Set/GetQuickBestSize
[wxWidgets.git] / src / generic / dcpsg.cpp
CommitLineData
ed880dd4 1/////////////////////////////////////////////////////////////////////////////
389076f1 2// Name: src/generic/dcpsg.cpp
bf38cbff 3// Purpose: Generic wxPostScriptDC implementation
ed880dd4
RR
4// Author: Julian Smart, Robert Roebling, Markus Holzhem
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
ed880dd4
RR
10/////////////////////////////////////////////////////////////////////////////
11
9a6be59a
VZ
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
88a7a4e1 18#if wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT
06cfab17 19
88a7a4e1 20#include "wx/generic/dcpsg.h"
ce4169a4 21
88a7a4e1
WS
22#ifndef WX_PRECOMP
23 #include "wx/intl.h"
e4db172a 24 #include "wx/log.h"
670f9935 25 #include "wx/app.h"
de6185e2 26 #include "wx/utils.h"
f38924e8 27 #include "wx/dcmemory.h"
88a7a4e1 28#endif // WX_PRECOMP
06cfab17 29
ef539066 30#include "wx/image.h"
9a05fd8d 31#include "wx/prntbase.h"
8850cbd3 32#include "wx/generic/prntdlgg.h"
7bcb11d3 33#include "wx/paper.h"
d361e74e 34#include "wx/filefn.h"
b713f891 35#include "wx/math.h"
d36d1be9 36#include "wx/stdpaths.h"
57c208c5 37
bf38cbff
JS
38#ifdef __WXMSW__
39
40#ifdef DrawText
41#undef DrawText
42#endif
43
44#ifdef StartDoc
45#undef StartDoc
46#endif
47
48#ifdef GetCharWidth
49#undef GetCharWidth
50#endif
51
52#ifdef FindWindow
53#undef FindWindow
54#endif
55
56#endif
57
ed880dd4
RR
58//-----------------------------------------------------------------------------
59// start and end of document/page
60//-----------------------------------------------------------------------------
61
c31c771b
RR
62static const char *wxPostScriptHeaderConicTo = "\
63/conicto {\n\
64 /to_y exch def\n\
65 /to_x exch def\n\
66 /conic_cntrl_y exch def\n\
67 /conic_cntrl_x exch def\n\
68 currentpoint\n\
69 /p0_y exch def\n\
70 /p0_x exch def\n\
71 /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\
72 /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\
73 /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\
74 /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\
75 p1_x p1_y p2_x p2_y to_x to_y curveto\n\
76} bind def\n\
c31c771b 77";
a47391f3 78
ed880dd4
RR
79static const char *wxPostScriptHeaderEllipse = "\
80/ellipsedict 8 dict def\n\
81ellipsedict /mtrx matrix put\n\
82/ellipse {\n\
9a6be59a
VZ
83 ellipsedict begin\n\
84 /endangle exch def\n\
85 /startangle exch def\n\
86 /yrad exch def\n\
87 /xrad exch def\n\
88 /y exch def\n\
89 /x exch def\n\
90 /savematrix mtrx currentmatrix def\n\
91 x y translate\n\
92 xrad yrad scale\n\
93 0 0 1 startangle endangle arc\n\
94 savematrix setmatrix\n\
95 end\n\
96 } def\n\
ed880dd4
RR
97";
98
99static const char *wxPostScriptHeaderEllipticArc= "\
100/ellipticarcdict 8 dict def\n\
101ellipticarcdict /mtrx matrix put\n\
102/ellipticarc\n\
103{ ellipticarcdict begin\n\
104 /do_fill exch def\n\
105 /endangle exch def\n\
106 /startangle exch def\n\
107 /yrad exch def\n\
108 /xrad exch def \n\
109 /y exch def\n\
110 /x exch def\n\
111 /savematrix mtrx currentmatrix def\n\
112 x y translate\n\
113 xrad yrad scale\n\
114 do_fill { 0 0 moveto } if\n\
115 0 0 1 startangle endangle arc\n\
116 savematrix setmatrix\n\
117 do_fill { fill }{ stroke } ifelse\n\
118 end\n\
119} def\n";
120
121static const char *wxPostScriptHeaderSpline = "\
122/DrawSplineSection {\n\
9a6be59a
VZ
123 /y3 exch def\n\
124 /x3 exch def\n\
125 /y2 exch def\n\
126 /x2 exch def\n\
127 /y1 exch def\n\
128 /x1 exch def\n\
129 /xa x1 x2 x1 sub 0.666667 mul add def\n\
130 /ya y1 y2 y1 sub 0.666667 mul add def\n\
131 /xb x3 x2 x3 sub 0.666667 mul add def\n\
132 /yb y3 y2 y3 sub 0.666667 mul add def\n\
133 x1 y1 lineto\n\
134 xa ya xb yb x3 y3 curveto\n\
135 } def\n\
ed880dd4
RR
136";
137
138static const char *wxPostScriptHeaderColourImage = "\
244e5e34
VZ
139% define 'colorimage' if it isn't defined\n\
140% ('colortogray' and 'mergeprocs' come from xwd2ps\n\
141% via xgrab)\n\
142/colorimage where % do we know about 'colorimage'?\n\
143 { pop } % yes: pop off the 'dict' returned\n\
144 { % no: define one\n\
145 /colortogray { % define an RGB->I function\n\
146 /rgbdata exch store % call input 'rgbdata'\n\
ed880dd4
RR
147 rgbdata length 3 idiv\n\
148 /npixls exch store\n\
149 /rgbindx 0 store\n\
150 0 1 npixls 1 sub {\n\
151 grays exch\n\
244e5e34
VZ
152 rgbdata rgbindx get 20 mul % Red\n\
153 rgbdata rgbindx 1 add get 32 mul % Green\n\
154 rgbdata rgbindx 2 add get 12 mul % Blue\n\
155 add add 64 idiv % I = .5G + .31R + .18B\n\
ed880dd4
RR
156 put\n\
157 /rgbindx rgbindx 3 add store\n\
158 } for\n\
159 grays 0 npixls getinterval\n\
160 } bind def\n\
161\n\
244e5e34
VZ
162 % Utility procedure for colorimage operator.\n\
163 % This procedure takes two procedures off the\n\
164 % stack and merges them into a single procedure.\n\
ed880dd4 165\n\
244e5e34 166 /mergeprocs { % def\n\
ed880dd4
RR
167 dup length\n\
168 3 -1 roll\n\
169 dup\n\
170 length\n\
171 dup\n\
172 5 1 roll\n\
173 3 -1 roll\n\
174 add\n\
175 array cvx\n\
176 dup\n\
177 3 -1 roll\n\
178 0 exch\n\
179 putinterval\n\
180 dup\n\
181 4 2 roll\n\
182 putinterval\n\
183 } bind def\n\
184\n\
244e5e34
VZ
185 /colorimage { % def\n\
186 pop pop % remove 'false 3' operands\n\
ed880dd4
RR
187 {colortogray} mergeprocs\n\
188 image\n\
189 } bind def\n\
244e5e34 190 } ifelse % end of 'false' case\n\
ed880dd4
RR
191";
192
193static char wxPostScriptHeaderReencodeISO1[] =
194 "\n/reencodeISO {\n"
195"dup dup findfont dup length dict begin\n"
196"{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
197"/Encoding ISOLatin1Encoding def\n"
198"currentdict end definefont\n"
199"} def\n"
200"/ISOLatin1Encoding [\n"
201"/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
202"/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
203"/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
204"/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
205"/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
206"/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
207"/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
208"/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
209"/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
210"/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
211"/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
212"/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
213"/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
214"/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
215"/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
216
217static char wxPostScriptHeaderReencodeISO2[] =
218"/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
219"/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
220"/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
221"/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
222"/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
223"/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
224"/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
225"/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
226"/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
227"/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
228"/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
229"/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
230"/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
231"/yacute/thorn/ydieresis\n"
232 "] def\n\n";
233
ed880dd4
RR
234//-------------------------------------------------------------------------------
235// wxPostScriptDC
236//-------------------------------------------------------------------------------
237
eba33006
RR
238IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC)
239
a148cfb6 240float wxPostScriptDC::ms_PSScaleFactor = 1.0;
b64de916
VS
241
242void wxPostScriptDC::SetResolution(int ppi)
243{
244 ms_PSScaleFactor = (float)ppi / 72.0;
245}
246
247int wxPostScriptDC::GetResolution()
248{
249 return (int)(ms_PSScaleFactor * 72.0);
250}
48c31b28 251
eba33006 252//-------------------------------------------------------------------------------
b64de916 253
ed880dd4
RR
254wxPostScriptDC::wxPostScriptDC ()
255{
d7657f75 256 m_pstream = (FILE*) NULL;
afce4c03 257
ed880dd4
RR
258 m_currentRed = 0;
259 m_currentGreen = 0;
260 m_currentBlue = 0;
afce4c03 261
ed880dd4 262 m_pageNumber = 0;
afce4c03 263
ca65c044 264 m_clipping = false;
afce4c03 265
ed880dd4
RR
266 m_underlinePosition = 0.0;
267 m_underlineThickness = 0.0;
268
269 m_signX = 1; // default x-axis left to right
270 m_signY = -1; // default y-axis bottom up -> top down
ed880dd4
RR
271}
272
7bcb11d3
JS
273wxPostScriptDC::wxPostScriptDC (const wxPrintData& printData)
274{
d7657f75 275 m_pstream = (FILE*) NULL;
7bcb11d3
JS
276
277 m_currentRed = 0;
278 m_currentGreen = 0;
279 m_currentBlue = 0;
280
281 m_pageNumber = 0;
282
ca65c044 283 m_clipping = false;
7bcb11d3
JS
284
285 m_underlinePosition = 0.0;
286 m_underlineThickness = 0.0;
287
288 m_signX = 1; // default x-axis left to right
289 m_signY = -1; // default y-axis bottom up -> top down
290
291 m_printData = printData;
75737d05 292
ca65c044 293 m_ok = true;
7bcb11d3
JS
294}
295
ed880dd4
RR
296wxPostScriptDC::~wxPostScriptDC ()
297{
d7657f75
RR
298 if (m_pstream)
299 {
300 fclose( m_pstream );
72cdf4c9 301 m_pstream = (FILE*) NULL;
d7657f75 302 }
ed880dd4
RR
303}
304
4bc67cc5
RR
305bool wxPostScriptDC::Ok() const
306{
ef539066 307 return m_ok;
4bc67cc5 308}
afce4c03 309
72cdf4c9 310void wxPostScriptDC::DoSetClippingRegion (wxCoord x, wxCoord y, wxCoord w, wxCoord h)
ed880dd4 311{
846051ec 312 wxCHECK_RET( m_ok , wxT("invalid postscript dc") );
afce4c03 313
7087444f 314 if (m_clipping) DestroyClippingRegion();
ed880dd4 315
7087444f 316 wxDC::DoSetClippingRegion(x, y, w, h);
afce4c03 317
ca65c044 318 m_clipping = true;
846051ec 319
bdbcded6
JS
320 PsPrintf( wxT("gsave\n newpath\n")
321 wxT("%d %d moveto\n")
322 wxT("%d %d lineto\n")
323 wxT("%d %d lineto\n")
324 wxT("%d %d lineto\n")
325 wxT("closepath clip newpath\n"),
6a7b1d6e
RD
326 LogicalToDeviceX(x), LogicalToDeviceY(y),
327 LogicalToDeviceX(x+w), LogicalToDeviceY(y),
328 LogicalToDeviceX(x+w), LogicalToDeviceY(y+h),
329 LogicalToDeviceX(x), LogicalToDeviceY(y+h) );
ed880dd4
RR
330}
331
ed880dd4
RR
332
333void wxPostScriptDC::DestroyClippingRegion()
334{
846051ec 335 wxCHECK_RET( m_ok , wxT("invalid postscript dc") );
afce4c03 336
ed880dd4
RR
337 if (m_clipping)
338 {
ca65c044 339 m_clipping = false;
244e5e34 340 PsPrint( "grestore\n" );
ed880dd4 341 }
004fd0c8 342
7087444f 343 wxDC::DestroyClippingRegion();
ed880dd4
RR
344}
345
346void wxPostScriptDC::Clear()
347{
f632aa1e
JS
348 // This should fail silently to avoid unnecessary
349 // asserts
350 // wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") );
ed880dd4
RR
351}
352
387ebd3e 353bool wxPostScriptDC::DoFloodFill (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour &WXUNUSED(col), int WXUNUSED(style))
ed880dd4 354{
223d09f6 355 wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
ca65c044 356 return false;
ed880dd4
RR
357}
358
72cdf4c9 359bool wxPostScriptDC::DoGetPixel (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour * WXUNUSED(col)) const
ed880dd4 360{
223d09f6 361 wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
ca65c044 362 return false;
ed880dd4
RR
363}
364
72cdf4c9 365void wxPostScriptDC::DoCrossHair (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
ed880dd4 366{
223d09f6 367 wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") );
ed880dd4
RR
368}
369
72cdf4c9 370void wxPostScriptDC::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
ed880dd4 371{
846051ec 372 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 373
ed880dd4 374 if (m_pen.GetStyle() == wxTRANSPARENT) return;
afce4c03 375
ed880dd4 376 SetPen( m_pen );
afce4c03 377
bdbcded6
JS
378 PsPrintf( wxT("newpath\n")
379 wxT("%d %d moveto\n")
380 wxT("%d %d lineto\n")
381 wxT("stroke\n"),
6a7b1d6e
RD
382 LogicalToDeviceX(x1), LogicalToDeviceY(y1),
383 LogicalToDeviceX(x2), LogicalToDeviceY (y2) );
afce4c03 384
ed880dd4
RR
385 CalcBoundingBox( x1, y1 );
386 CalcBoundingBox( x2, y2 );
387}
388
389#define RAD2DEG 57.29577951308
390
72cdf4c9 391void wxPostScriptDC::DoDrawArc (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc)
ed880dd4 392{
846051ec 393 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 394
72cdf4c9
VZ
395 wxCoord dx = x1 - xc;
396 wxCoord dy = y1 - yc;
397 wxCoord radius = (wxCoord) sqrt( (double)(dx*dx+dy*dy) );
ed880dd4
RR
398 double alpha1, alpha2;
399
afce4c03 400 if (x1 == x2 && y1 == y2)
ed880dd4 401 {
d7657f75
RR
402 alpha1 = 0.0;
403 alpha2 = 360.0;
72cdf4c9 404 }
c77a6796 405 else if ( wxIsNullDouble(radius) )
ed880dd4 406 {
c77a6796
VZ
407 alpha1 =
408 alpha2 = 0.0;
72cdf4c9 409 }
d7657f75 410 else
ed880dd4 411 {
d7657f75
RR
412 alpha1 = (x1 - xc == 0) ?
413 (y1 - yc < 0) ? 90.0 : -90.0 :
414 -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG;
415 alpha2 = (x2 - xc == 0) ?
416 (y2 - yc < 0) ? 90.0 : -90.0 :
417 -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG;
ed880dd4
RR
418 }
419 while (alpha1 <= 0) alpha1 += 360;
420 while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between
421 while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree
422 while (alpha2 > 360) alpha2 -= 360;
423
afce4c03 424 if (m_brush.GetStyle() != wxTRANSPARENT)
ed880dd4 425 {
d7657f75 426 SetBrush( m_brush );
72cdf4c9 427
bdbcded6
JS
428 PsPrintf( wxT("newpath\n")
429 wxT("%d %d %d %d %d %d ellipse\n")
430 wxT("%d %d lineto\n")
431 wxT("closepath\n")
432 wxT("fill\n"),
6a7b1d6e
RD
433 LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2,
434 LogicalToDeviceX(xc), LogicalToDeviceY(yc) );
d7657f75
RR
435
436 CalcBoundingBox( xc-radius, yc-radius );
437 CalcBoundingBox( xc+radius, yc+radius );
ed880dd4 438 }
afce4c03
VZ
439
440 if (m_pen.GetStyle() != wxTRANSPARENT)
ed880dd4 441 {
d7657f75 442 SetPen( m_pen );
72cdf4c9 443
bdbcded6
JS
444 PsPrintf( wxT("newpath\n")
445 wxT("%d %d %d %d %d %d ellipse\n")
446 wxT("%d %d lineto\n")
447 wxT("stroke\n")
448 wxT("fill\n"),
6a7b1d6e
RD
449 LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2,
450 LogicalToDeviceX(xc), LogicalToDeviceY(yc) );
d7657f75
RR
451
452 CalcBoundingBox( xc-radius, yc-radius );
453 CalcBoundingBox( xc+radius, yc+radius );
ed880dd4 454 }
ed880dd4
RR
455}
456
72cdf4c9 457void wxPostScriptDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
ed880dd4 458{
846051ec 459 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 460
c77a6796
VZ
461 if ( sa >= 360 || sa <= -360 )
462 sa -= int(sa/360)*360;
463 if ( ea >= 360 || ea <=- 360 )
464 ea -= int(ea/360)*360;
465 if ( sa < 0 )
466 sa += 360;
467 if ( ea < 0 )
468 ea += 360;
afce4c03 469
c77a6796 470 if ( wxIsSameDouble(sa, ea) )
ed880dd4
RR
471 {
472 DrawEllipse(x,y,w,h);
473 return;
474 }
475
476 if (m_brush.GetStyle () != wxTRANSPARENT)
477 {
478 SetBrush( m_brush );
72cdf4c9 479
bdbcded6
JS
480 PsPrintf( wxT("newpath\n")
481 wxT("%d %d %d %d %d %d true ellipticarc\n"),
244e5e34
VZ
482 LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2),
483 LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2),
484 (wxCoord)sa, (wxCoord)ea );
72cdf4c9 485
ed880dd4
RR
486 CalcBoundingBox( x ,y );
487 CalcBoundingBox( x+w, y+h );
72cdf4c9
VZ
488 }
489
ed880dd4
RR
490 if (m_pen.GetStyle () != wxTRANSPARENT)
491 {
492 SetPen( m_pen );
493
bdbcded6
JS
494 PsPrintf( wxT("newpath\n")
495 wxT("%d %d %d %d %d %d false ellipticarc\n"),
244e5e34
VZ
496 LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2),
497 LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2),
498 (wxCoord)sa, (wxCoord)ea );
72cdf4c9 499
d7657f75 500 CalcBoundingBox( x ,y );
ed880dd4
RR
501 CalcBoundingBox( x+w, y+h );
502 }
503}
504
72cdf4c9 505void wxPostScriptDC::DoDrawPoint (wxCoord x, wxCoord y)
ed880dd4 506{
846051ec 507 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 508
ed880dd4 509 if (m_pen.GetStyle() == wxTRANSPARENT) return;
afce4c03 510
ed880dd4 511 SetPen (m_pen);
afce4c03 512
bdbcded6
JS
513 PsPrintf( wxT("newpath\n")
514 wxT("%d %d moveto\n")
515 wxT("%d %d lineto\n")
516 wxT("stroke\n"),
6a7b1d6e
RD
517 LogicalToDeviceX(x), LogicalToDeviceY(y),
518 LogicalToDeviceX(x+1), LogicalToDeviceY(y) );
afce4c03 519
ed880dd4
RR
520 CalcBoundingBox( x, y );
521}
522
6e76b35d 523void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
ed880dd4 524{
846051ec 525 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 526
ed880dd4 527 if (n <= 0) return;
afce4c03 528
ed880dd4
RR
529 if (m_brush.GetStyle () != wxTRANSPARENT)
530 {
d7657f75
RR
531 SetBrush( m_brush );
532
244e5e34 533 PsPrint( "newpath\n" );
afce4c03 534
6a7b1d6e
RD
535 wxCoord xx = LogicalToDeviceX(points[0].x + xoffset);
536 wxCoord yy = LogicalToDeviceY(points[0].y + yoffset);
72cdf4c9 537
244e5e34 538 PsPrintf( wxT("%d %d moveto\n"), xx, yy );
72cdf4c9 539
d7657f75 540 CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
ed880dd4 541
d7657f75
RR
542 for (int i = 1; i < n; i++)
543 {
6a7b1d6e
RD
544 xx = LogicalToDeviceX(points[i].x + xoffset);
545 yy = LogicalToDeviceY(points[i].y + yoffset);
72cdf4c9 546
244e5e34 547 PsPrintf( wxT("%d %d lineto\n"), xx, yy );
ed880dd4 548
d7657f75
RR
549 CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset);
550 }
72cdf4c9 551
244e5e34 552 PsPrint( (fillStyle == wxODDEVEN_RULE ? "eofill\n" : "fill\n") );
ed880dd4
RR
553 }
554
555 if (m_pen.GetStyle () != wxTRANSPARENT)
556 {
d7657f75 557 SetPen( m_pen );
72cdf4c9 558
244e5e34 559 PsPrint( "newpath\n" );
ed880dd4 560
6a7b1d6e
RD
561 wxCoord xx = LogicalToDeviceX(points[0].x + xoffset);
562 wxCoord yy = LogicalToDeviceY(points[0].y + yoffset);
72cdf4c9 563
244e5e34 564 PsPrintf( wxT("%d %d moveto\n"), xx, yy );
72cdf4c9 565
d7657f75 566 CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
ed880dd4 567
d7657f75
RR
568 for (int i = 1; i < n; i++)
569 {
6a7b1d6e
RD
570 xx = LogicalToDeviceX(points[i].x + xoffset);
571 yy = LogicalToDeviceY(points[i].y + yoffset);
72cdf4c9 572
244e5e34 573 PsPrintf( wxT("%d %d lineto\n"), xx, yy );
72cdf4c9 574
d7657f75
RR
575 CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset);
576 }
ed880dd4 577
244e5e34
VZ
578 PsPrint( "closepath\n" );
579 PsPrint( "stroke\n" );
ed880dd4
RR
580 }
581}
582
793db755 583void wxPostScriptDC::DoDrawPolyPolygon (int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
6e76b35d 584{
244e5e34 585 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
6e76b35d
VZ
586
587 if (n <= 0) return;
588
589 if (m_brush.GetStyle () != wxTRANSPARENT)
590 {
591 SetBrush( m_brush );
592
244e5e34 593 PsPrint( "newpath\n" );
6e76b35d
VZ
594
595 int ofs = 0;
793db755 596 for (int i = 0; i < n; ofs += count[i++])
6e76b35d
VZ
597 {
598 wxCoord xx = LogicalToDeviceX(points[ofs].x + xoffset);
599 wxCoord yy = LogicalToDeviceY(points[ofs].y + yoffset);
600
244e5e34 601 PsPrintf( wxT("%d %d moveto\n"), xx, yy );
6e76b35d
VZ
602
603 CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset );
604
793db755 605 for (int j = 1; j < count[i]; j++)
6e76b35d
VZ
606 {
607 xx = LogicalToDeviceX(points[ofs+j].x + xoffset);
608 yy = LogicalToDeviceY(points[ofs+j].y + yoffset);
609
244e5e34 610 PsPrintf( wxT("%d %d lineto\n"), xx, yy );
6e76b35d
VZ
611
612 CalcBoundingBox( points[ofs+j].x + xoffset, points[ofs+j].y + yoffset);
613 }
614 }
244e5e34 615 PsPrint( (fillStyle == wxODDEVEN_RULE ? "eofill\n" : "fill\n") );
6e76b35d
VZ
616 }
617
618 if (m_pen.GetStyle () != wxTRANSPARENT)
619 {
620 SetPen( m_pen );
621
244e5e34 622 PsPrint( "newpath\n" );
6e76b35d
VZ
623
624 int ofs = 0;
793db755 625 for (int i = 0; i < n; ofs += count[i++])
6e76b35d
VZ
626 {
627 wxCoord xx = LogicalToDeviceX(points[ofs].x + xoffset);
628 wxCoord yy = LogicalToDeviceY(points[ofs].y + yoffset);
629
244e5e34 630 PsPrintf( wxT("%d %d moveto\n"), xx, yy );
6e76b35d
VZ
631
632 CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset );
633
793db755 634 for (int j = 1; j < count[i]; j++)
6e76b35d
VZ
635 {
636 xx = LogicalToDeviceX(points[ofs+j].x + xoffset);
637 yy = LogicalToDeviceY(points[ofs+j].y + yoffset);
638
244e5e34 639 PsPrintf( wxT("%d %d lineto\n"), xx, yy );
6e76b35d
VZ
640
641 CalcBoundingBox( points[ofs+j].x + xoffset, points[ofs+j].y + yoffset);
642 }
643 }
244e5e34
VZ
644 PsPrint( "closepath\n" );
645 PsPrint( "stroke\n" );
6e76b35d
VZ
646 }
647}
648
72cdf4c9 649void wxPostScriptDC::DoDrawLines (int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
ed880dd4 650{
846051ec 651 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 652
d7657f75 653 if (m_pen.GetStyle() == wxTRANSPARENT) return;
72cdf4c9 654
d7657f75 655 if (n <= 0) return;
afce4c03 656
ed880dd4 657 SetPen (m_pen);
afce4c03 658
9a6be59a
VZ
659 int i;
660 for ( i =0; i<n ; i++ )
ed880dd4 661 {
6a7b1d6e 662 CalcBoundingBox( LogicalToDeviceX(points[i].x+xoffset), LogicalToDeviceY(points[i].y+yoffset));
ed880dd4
RR
663 }
664
51b62c24
JS
665 PsPrintf( wxT("newpath\n")
666 wxT("%d %d moveto\n"),
244e5e34
VZ
667 LogicalToDeviceX(points[0].x+xoffset),
668 LogicalToDeviceY(points[0].y+yoffset) );
ca65c044 669
244e5e34 670 for (i = 1; i < n; i++)
846051ec 671 {
244e5e34
VZ
672 PsPrintf( wxT("%d %d lineto\n"),
673 LogicalToDeviceX(points[i].x+xoffset),
674 LogicalToDeviceY(points[i].y+yoffset) );
ed880dd4 675 }
ca65c044 676
244e5e34 677 PsPrint( "stroke\n" );
ed880dd4
RR
678}
679
72cdf4c9 680void wxPostScriptDC::DoDrawRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
ed880dd4 681{
846051ec 682 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 683
ed880dd4
RR
684 if (m_brush.GetStyle () != wxTRANSPARENT)
685 {
686 SetBrush( m_brush );
72cdf4c9 687
bdbcded6
JS
688 PsPrintf( wxT("newpath\n")
689 wxT("%d %d moveto\n")
690 wxT("%d %d lineto\n")
691 wxT("%d %d lineto\n")
692 wxT("%d %d lineto\n")
693 wxT("closepath\n")
694 wxT("fill\n"),
6a7b1d6e
RD
695 LogicalToDeviceX(x), LogicalToDeviceY(y),
696 LogicalToDeviceX(x + width), LogicalToDeviceY(y),
697 LogicalToDeviceX(x + width), LogicalToDeviceY(y + height),
698 LogicalToDeviceX(x), LogicalToDeviceY(y + height) );
ed880dd4
RR
699
700 CalcBoundingBox( x, y );
701 CalcBoundingBox( x + width, y + height );
702 }
afce4c03 703
ed880dd4
RR
704 if (m_pen.GetStyle () != wxTRANSPARENT)
705 {
706 SetPen (m_pen);
707
bdbcded6
JS
708 PsPrintf( wxT("newpath\n")
709 wxT("%d %d moveto\n")
710 wxT("%d %d lineto\n")
711 wxT("%d %d lineto\n")
712 wxT("%d %d lineto\n")
713 wxT("closepath\n")
714 wxT("stroke\n"),
6a7b1d6e
RD
715 LogicalToDeviceX(x), LogicalToDeviceY(y),
716 LogicalToDeviceX(x + width), LogicalToDeviceY(y),
717 LogicalToDeviceX(x + width), LogicalToDeviceY(y + height),
718 LogicalToDeviceX(x), LogicalToDeviceY(y + height) );
72cdf4c9 719
ed880dd4
RR
720 CalcBoundingBox( x, y );
721 CalcBoundingBox( x + width, y + height );
722 }
723}
724
72cdf4c9 725void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
ed880dd4 726{
846051ec 727 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 728
ed880dd4
RR
729 if (radius < 0.0)
730 {
731 // Now, a negative radius is interpreted to mean
732 // 'the proportion of the smallest X or Y dimension'
999836aa 733 double smallest = width < height ? width : height;
ed880dd4
RR
734 radius = (-radius * smallest);
735 }
afce4c03 736
72cdf4c9 737 wxCoord rad = (wxCoord) radius;
ed880dd4
RR
738
739 if (m_brush.GetStyle () != wxTRANSPARENT)
740 {
741 SetBrush( m_brush );
afce4c03 742
d7657f75 743 /* Draw rectangle anticlockwise */
bdbcded6
JS
744 PsPrintf( wxT("newpath\n")
745 wxT("%d %d %d 90 180 arc\n")
a77d6d2f 746 wxT("%d %d lineto\n")
bdbcded6
JS
747 wxT("%d %d %d 180 270 arc\n")
748 wxT("%d %d lineto\n")
749 wxT("%d %d %d 270 0 arc\n")
750 wxT("%d %d lineto\n")
751 wxT("%d %d %d 0 90 arc\n")
752 wxT("%d %d lineto\n")
753 wxT("closepath\n")
754 wxT("fill\n"),
6a7b1d6e 755 LogicalToDeviceX(x + rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
a77d6d2f 756 LogicalToDeviceX(x), LogicalToDeviceY(y + height - rad),
6a7b1d6e
RD
757 LogicalToDeviceX(x + rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
758 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height),
759 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
760 LogicalToDeviceX(x + width), LogicalToDeviceY(y + rad),
761 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
762 LogicalToDeviceX(x + rad), LogicalToDeviceY(y) );
ed880dd4
RR
763
764 CalcBoundingBox( x, y );
765 CalcBoundingBox( x + width, y + height );
766 }
afce4c03 767
ed880dd4
RR
768 if (m_pen.GetStyle () != wxTRANSPARENT)
769 {
770 SetPen (m_pen);
afce4c03 771
d7657f75 772 /* Draw rectangle anticlockwise */
bdbcded6
JS
773 PsPrintf( wxT("newpath\n")
774 wxT("%d %d %d 90 180 arc\n")
a77d6d2f 775 wxT("%d %d lineto\n")
bdbcded6
JS
776 wxT("%d %d %d 180 270 arc\n")
777 wxT("%d %d lineto\n")
778 wxT("%d %d %d 270 0 arc\n")
779 wxT("%d %d lineto\n")
780 wxT("%d %d %d 0 90 arc\n")
781 wxT("%d %d lineto\n")
782 wxT("closepath\n")
783 wxT("stroke\n"),
6a7b1d6e 784 LogicalToDeviceX(x + rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
a77d6d2f 785 LogicalToDeviceX(x), LogicalToDeviceY(y + height - rad),
6a7b1d6e
RD
786 LogicalToDeviceX(x + rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
787 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height),
788 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
789 LogicalToDeviceX(x + width), LogicalToDeviceY(y + rad),
790 LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
791 LogicalToDeviceX(x + rad), LogicalToDeviceY(y) );
ed880dd4
RR
792
793 CalcBoundingBox( x, y );
794 CalcBoundingBox( x + width, y + height );
795 }
796}
797
72cdf4c9 798void wxPostScriptDC::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
ed880dd4 799{
846051ec 800 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 801
ed880dd4
RR
802 if (m_brush.GetStyle () != wxTRANSPARENT)
803 {
804 SetBrush (m_brush);
805
bdbcded6
JS
806 PsPrintf( wxT("newpath\n")
807 wxT("%d %d %d %d 0 360 ellipse\n")
808 wxT("fill\n"),
6a7b1d6e
RD
809 LogicalToDeviceX(x + width / 2), LogicalToDeviceY(y + height / 2),
810 LogicalToDeviceXRel(width / 2), LogicalToDeviceYRel(height / 2) );
ed880dd4
RR
811
812 CalcBoundingBox( x - width, y - height );
813 CalcBoundingBox( x + width, y + height );
814 }
afce4c03 815
d7657f75 816 if (m_pen.GetStyle () != wxTRANSPARENT)
ed880dd4
RR
817 {
818 SetPen (m_pen);
819
bdbcded6
JS
820 PsPrintf( wxT("newpath\n")
821 wxT("%d %d %d %d 0 360 ellipse\n")
822 wxT("stroke\n"),
6a7b1d6e
RD
823 LogicalToDeviceX(x + width / 2), LogicalToDeviceY(y + height / 2),
824 LogicalToDeviceXRel(width / 2), LogicalToDeviceYRel(height / 2) );
ed880dd4
RR
825
826 CalcBoundingBox( x - width, y - height );
827 CalcBoundingBox( x + width, y + height );
828 }
829}
830
72cdf4c9 831void wxPostScriptDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
ed880dd4 832{
ca65c044 833 DrawBitmap( icon, x, y, true );
ed880dd4
RR
834}
835
d7657f75
RR
836/* this has to be char, not wxChar */
837static char hexArray[] = "0123456789ABCDEF";
d7657f75 838
72cdf4c9 839void wxPostScriptDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool WXUNUSED(useMask) )
ed880dd4 840{
846051ec 841 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
ef539066
RR
842
843 if (!bitmap.Ok()) return;
afce4c03 844
368d59f0 845 wxImage image = bitmap.ConvertToImage();
afce4c03 846
ef539066 847 if (!image.Ok()) return;
afce4c03 848
b64de916
VS
849 wxCoord w = image.GetWidth();
850 wxCoord h = image.GetHeight();
851
6a7b1d6e
RD
852 wxCoord ww = LogicalToDeviceXRel(image.GetWidth());
853 wxCoord hh = LogicalToDeviceYRel(image.GetHeight());
afce4c03 854
6a7b1d6e
RD
855 wxCoord xx = LogicalToDeviceX(x);
856 wxCoord yy = LogicalToDeviceY(y + bitmap.GetHeight());
d7657f75 857
bdbcded6
JS
858 PsPrintf( wxT("/origstate save def\n")
859 wxT("20 dict begin\n")
860 wxT("/pix %d string def\n")
861 wxT("/grays %d string def\n")
862 wxT("/npixels 0 def\n")
863 wxT("/rgbindx 0 def\n")
864 wxT("%d %d translate\n")
865 wxT("%d %d scale\n")
866 wxT("%d %d 8\n")
867 wxT("[%d 0 0 %d 0 %d]\n")
868 wxT("{currentfile pix readhexstring pop}\n")
869 wxT("false 3 colorimage\n"),
b64de916 870 w, w, xx, yy, ww, hh, w, h, w, -h, h );
244e5e34
VZ
871
872 unsigned char* data = image.GetData();
873
c56ae042
VZ
874 // size of the buffer = width*rgb(3)*hexa(2)+'\n'
875 wxCharBuffer buffer(w*6 + 1);
244e5e34
VZ
876 int firstDigit, secondDigit;
877
878 //rows
879 for (int j = 0; j < h; j++)
880 {
41f4eb85 881 char* bufferindex = buffer.data();
244e5e34
VZ
882
883 //cols
884 for (int i = 0; i < w*3; i++)
ef539066 885 {
244e5e34
VZ
886 firstDigit = (int)(*data/16.0);
887 secondDigit = (int)(*data - (firstDigit*16.0));
888 *(bufferindex++) = hexArray[firstDigit];
889 *(bufferindex++) = hexArray[secondDigit];
890
891 data++;
d7657f75 892 }
244e5e34
VZ
893 *(bufferindex++) = '\n';
894 *bufferindex = 0;
895 PsPrint( buffer );
ef539066 896 }
244e5e34
VZ
897
898 PsPrint( "end\n" );
899 PsPrint( "origstate restore\n" );
ed880dd4
RR
900}
901
36b3b54a 902void wxPostScriptDC::SetFont( const wxFont& font )
ed880dd4 903{
846051ec 904 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 905
ed880dd4 906 if (!font.Ok()) return;
afce4c03 907
ed880dd4 908 m_font = font;
57c208c5 909
36b3b54a
RR
910 int Style = m_font.GetStyle();
911 int Weight = m_font.GetWeight();
912
733b25e1 913 const char *name;
d7657f75 914 switch (m_font.GetFamily())
36b3b54a
RR
915 {
916 case wxTELETYPE:
917 case wxMODERN:
733b25e1
RR
918 {
919 if (Style == wxITALIC)
920 {
921 if (Weight == wxBOLD)
922 name = "/Courier-BoldOblique";
923 else
924 name = "/Courier-Oblique";
925 }
926 else
927 {
928 if (Weight == wxBOLD)
929 name = "/Courier-Bold";
930 else
931 name = "/Courier";
932 }
36b3b54a 933 break;
733b25e1 934 }
36b3b54a 935 case wxROMAN:
733b25e1
RR
936 {
937 if (Style == wxITALIC)
938 {
939 if (Weight == wxBOLD)
940 name = "/Times-BoldItalic";
941 else
942 name = "/Times-Italic";
943 }
944 else
945 {
946 if (Weight == wxBOLD)
947 name = "/Times-Bold";
948 else
949 name = "/Times-Roman";
950 }
36b3b54a 951 break;
733b25e1 952 }
36b3b54a 953 case wxSCRIPT:
733b25e1
RR
954 {
955 name = "/ZapfChancery-MediumItalic";
36b3b54a 956 break;
733b25e1
RR
957 }
958 case wxSWISS:
36b3b54a 959 default:
733b25e1
RR
960 {
961 if (Style == wxITALIC)
962 {
963 if (Weight == wxBOLD)
964 name = "/Helvetica-BoldOblique";
965 else
966 name = "/Helvetica-Oblique";
967 }
968 else
969 {
970 if (Weight == wxBOLD)
971 name = "/Helvetica-Bold";
972 else
973 name = "/Helvetica";
974 }
975 break;
976 }
36b3b54a 977 }
57c208c5 978
29402f45
JS
979 // We may legitimately call SetFont before BeginDoc
980 if (!m_pstream)
981 return;
ca65c044 982
244e5e34
VZ
983 PsPrint( name );
984 PsPrint( " reencodeISO def\n" );
985 PsPrint( name );
986 PsPrint( " findfont\n" );
ca65c044 987
244e5e34
VZ
988 char buffer[100];
989 sprintf( buffer, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font.GetPointSize() * 1000) / 1000.0F);
990 // this is a hack - we must scale font size (in pts) according to m_scaleY but
991 // LogicalToDeviceYRel works with wxCoord type (int or longint). Se we first convert font size
992 // to 1/1000th of pt and then back.
993 for (int i = 0; i < 100; i++)
994 if (buffer[i] == ',') buffer[i] = '.';
995 PsPrint( buffer );
ed880dd4
RR
996}
997
998void wxPostScriptDC::SetPen( const wxPen& pen )
999{
846051ec 1000 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 1001
ed880dd4 1002 if (!pen.Ok()) return;
afce4c03 1003
ed880dd4
RR
1004 int oldStyle = m_pen.GetStyle();
1005
1006 m_pen = pen;
1007
244e5e34
VZ
1008 char buffer[100];
1009 sprintf( buffer, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen.GetWidth()) / 1000.0f );
1010 for (int i = 0; i < 100; i++)
1011 if (buffer[i] == ',') buffer[i] = '.';
1012 PsPrint( buffer );
f6bcfd97 1013
ed880dd4
RR
1014/*
1015 Line style - WRONG: 2nd arg is OFFSET
afce4c03 1016
ed880dd4
RR
1017 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
1018 operator correctly. You should look-up this in the Red Book: the 2nd parame-
1019 ter is not number of values in the array of the first one, but an offset
1020 into this description of the pattern. I mean a real *offset* not index
1021 into array. I.e. If the command is [3 4] 1 setdash is used, then there
72cdf4c9 1022 will be first black line *2* units wxCoord, then space 4 units, then the
ed880dd4
RR
1023 pattern of *3* units black, 4 units space will be repeated.
1024*/
1025
1026 static const char *dotted = "[2 5] 2";
1027 static const char *short_dashed = "[4 4] 2";
72cdf4c9 1028 static const char *wxCoord_dashed = "[4 8] 2";
ed880dd4
RR
1029 static const char *dotted_dashed = "[6 6 2 6] 4";
1030
999836aa
VZ
1031 const char *psdash;
1032
d7657f75 1033 switch (m_pen.GetStyle())
ed880dd4
RR
1034 {
1035 case wxDOT: psdash = dotted; break;
1036 case wxSHORT_DASH: psdash = short_dashed; break;
244e5e34 1037 case wxLONG_DASH: psdash = wxCoord_dashed; break;
ed880dd4 1038 case wxDOT_DASH: psdash = dotted_dashed; break;
f081c944
RR
1039 case wxUSER_DASH:
1040 {
1041 wxDash *dashes;
1042 int nDashes = m_pen.GetDashes (&dashes);
1043 PsPrint ("[");
1044 for (int i = 0; i < nDashes; ++i)
1045 {
1046 sprintf( buffer, "%d ", dashes [i] );
1047 PsPrint( buffer );
1048 }
1049 PsPrint ("] 0 setdash\n");
88a7a4e1
WS
1050 psdash = 0;
1051 }
f081c944 1052 break;
ed880dd4
RR
1053 case wxSOLID:
1054 case wxTRANSPARENT:
1055 default: psdash = "[] 0"; break;
1056 }
afce4c03 1057
f081c944 1058 if ( psdash && (oldStyle != m_pen.GetStyle()) )
ed880dd4 1059 {
244e5e34
VZ
1060 PsPrint( psdash );
1061 PsPrint( " setdash\n" );
ed880dd4
RR
1062 }
1063
1064 // Line colour
1065 unsigned char red = m_pen.GetColour().Red();
1066 unsigned char blue = m_pen.GetColour().Blue();
1067 unsigned char green = m_pen.GetColour().Green();
1068
1069 if (!m_colour)
1070 {
1071 // Anything not white is black
72cdf4c9
VZ
1072 if (! (red == (unsigned char) 255 &&
1073 blue == (unsigned char) 255 &&
d7657f75
RR
1074 green == (unsigned char) 255) )
1075 {
1076 red = (unsigned char) 0;
1077 green = (unsigned char) 0;
1078 blue = (unsigned char) 0;
72cdf4c9 1079 }
d7657f75 1080 // setgray here ?
ed880dd4
RR
1081 }
1082
1083 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1084 {
d7657f75
RR
1085 double redPS = (double)(red) / 255.0;
1086 double bluePS = (double)(blue) / 255.0;
1087 double greenPS = (double)(green) / 255.0;
ca65c044 1088
f6bcfd97 1089 sprintf( buffer,
846051ec
JS
1090 "%.8f %.8f %.8f setrgbcolor\n",
1091 redPS, greenPS, bluePS );
f6bcfd97 1092 for (int i = 0; i < 100; i++)
3ca6a5f0 1093 if (buffer[i] == ',') buffer[i] = '.';
72cdf4c9 1094
244e5e34 1095 PsPrint( buffer );
ca65c044 1096
d7657f75
RR
1097 m_currentRed = red;
1098 m_currentBlue = blue;
1099 m_currentGreen = green;
ed880dd4
RR
1100 }
1101}
1102
1103void wxPostScriptDC::SetBrush( const wxBrush& brush )
1104{
846051ec 1105 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 1106
ed880dd4 1107 if (!brush.Ok()) return;
afce4c03 1108
ed880dd4
RR
1109 m_brush = brush;
1110
1111 // Brush colour
3c1b65a4
RR
1112 unsigned char red = m_brush.GetColour().Red();
1113 unsigned char blue = m_brush.GetColour().Blue();
1114 unsigned char green = m_brush.GetColour().Green();
ed880dd4
RR
1115
1116 if (!m_colour)
1117 {
d7657f75 1118 // Anything not white is black
72cdf4c9
VZ
1119 if (! (red == (unsigned char) 255 &&
1120 blue == (unsigned char) 255 &&
d7657f75
RR
1121 green == (unsigned char) 255) )
1122 {
1123 red = (unsigned char) 0;
1124 green = (unsigned char) 0;
1125 blue = (unsigned char) 0;
72cdf4c9 1126 }
d7657f75 1127 // setgray here ?
ed880dd4 1128 }
72cdf4c9 1129
ed880dd4
RR
1130 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1131 {
d7657f75
RR
1132 double redPS = (double)(red) / 255.0;
1133 double bluePS = (double)(blue) / 255.0;
1134 double greenPS = (double)(green) / 255.0;
72cdf4c9 1135
f6bcfd97
BP
1136 char buffer[100];
1137 sprintf( buffer,
72cdf4c9
VZ
1138 "%.8f %.8f %.8f setrgbcolor\n",
1139 redPS, greenPS, bluePS );
f6bcfd97 1140 for (int i = 0; i < 100; i++)
3ca6a5f0 1141 if (buffer[i] == ',') buffer[i] = '.';
ca65c044 1142
244e5e34 1143 PsPrint( buffer );
72cdf4c9 1144
d7657f75
RR
1145 m_currentRed = red;
1146 m_currentBlue = blue;
1147 m_currentGreen = green;
ed880dd4
RR
1148 }
1149}
1150
72cdf4c9 1151void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
ed880dd4 1152{
846051ec 1153 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
479cd5de 1154
a148cfb6
RR
1155 if (m_textForegroundColour.Ok())
1156 {
1157 unsigned char red = m_textForegroundColour.Red();
1158 unsigned char blue = m_textForegroundColour.Blue();
1159 unsigned char green = m_textForegroundColour.Green();
1160
1161 if (!m_colour)
1162 {
1163 // Anything not white is black
1164 if (! (red == (unsigned char) 255 &&
1165 blue == (unsigned char) 255 &&
1166 green == (unsigned char) 255))
1167 {
1168 red = (unsigned char) 0;
1169 green = (unsigned char) 0;
1170 blue = (unsigned char) 0;
1171 }
1172 }
1173
1174 // maybe setgray here ?
1175 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1176 {
1177 double redPS = (double)(red) / 255.0;
1178 double bluePS = (double)(blue) / 255.0;
1179 double greenPS = (double)(green) / 255.0;
1180
1181 char buffer[100];
1182 sprintf( buffer,
1183 "%.8f %.8f %.8f setrgbcolor\n",
1184 redPS, greenPS, bluePS );
1185 for (size_t i = 0; i < strlen(buffer); i++)
1186 if (buffer[i] == ',') buffer[i] = '.';
244e5e34 1187 PsPrint( buffer );
a148cfb6
RR
1188
1189 m_currentRed = red;
1190 m_currentBlue = blue;
1191 m_currentGreen = green;
1192 }
1193 }
a47391f3 1194
6c3d9ced 1195 wxCoord text_w, text_h, text_descent;
479cd5de 1196
6c3d9ced 1197 GetTextExtent(text, &text_w, &text_h, &text_descent);
afce4c03 1198
080b749f
VZ
1199 // VZ: this seems to be unnecessary, so taking it out for now, if it
1200 // doesn't create any problems, remove this comment entirely
1201 //SetFont( m_font );
ed880dd4 1202
ed880dd4
RR
1203
1204 int size = m_font.GetPointSize();
1205
6c3d9ced
VS
1206// wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
1207// commented by V. Slavik and replaced by accurate version
1208// - note that there is still rounding error in text_descent!
1209 wxCoord by = y + size - text_descent; // baseline
244e5e34
VZ
1210
1211 PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x), LogicalToDeviceY(by) );
1212 PsPrint( "(" );
ca65c044 1213
244e5e34
VZ
1214 const wxWX2MBbuf textbuf = text.mb_str();
1215 size_t len = strlen(textbuf);
1216 size_t i;
1217 for (i = 0; i < len; i++)
ed880dd4 1218 {
244e5e34
VZ
1219 int c = (unsigned char) textbuf[i];
1220 if (c == ')' || c == '(' || c == '\\')
ed880dd4 1221 {
244e5e34
VZ
1222 /* Cope with special characters */
1223 PsPrint( "\\" );
1224 PsPrint(c);
ed880dd4 1225 }
244e5e34 1226 else if ( c >= 128 )
72cdf4c9 1227 {
244e5e34
VZ
1228 /* Cope with character codes > 127 */
1229 PsPrintf( wxT("\\%o"), c);
1230 }
1231 else
1232 {
1233 PsPrint(c);
1234 }
1235 }
ca65c044 1236
244e5e34 1237 PsPrint( ") show\n" );
ca65c044 1238
244e5e34
VZ
1239 if (m_font.GetUnderlined())
1240 {
1241 wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
1242 char buffer[100];
1243
1244 sprintf( buffer,
72cdf4c9
VZ
1245 "gsave\n"
1246 "%d %d moveto\n"
f6bcfd97 1247 "%f setlinewidth\n"
72cdf4c9
VZ
1248 "%d %d lineto\n"
1249 "stroke\n"
1250 "grestore\n",
6a7b1d6e 1251 LogicalToDeviceX(x), LogicalToDeviceY(uy),
f6bcfd97 1252 m_underlineThickness,
6a7b1d6e 1253 LogicalToDeviceX(x + text_w), LogicalToDeviceY(uy) );
244e5e34
VZ
1254 for (i = 0; i < 100; i++)
1255 if (buffer[i] == ',') buffer[i] = '.';
1256 PsPrint( buffer );
ed880dd4 1257 }
afce4c03 1258
ed880dd4 1259 CalcBoundingBox( x, y );
88a7a4e1 1260 CalcBoundingBox( x + size * text.length() * 2/3 , y );
ed880dd4
RR
1261}
1262
95724b1a
VZ
1263void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle )
1264{
c77a6796 1265 if ( wxIsNullDouble(angle) )
95724b1a
VZ
1266 {
1267 DoDrawText(text, x, y);
1268 return;
1269 }
1270
846051ec 1271 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
95724b1a
VZ
1272
1273 SetFont( m_font );
1274
1275 if (m_textForegroundColour.Ok())
1276 {
1277 unsigned char red = m_textForegroundColour.Red();
1278 unsigned char blue = m_textForegroundColour.Blue();
1279 unsigned char green = m_textForegroundColour.Green();
1280
1281 if (!m_colour)
1282 {
1283 // Anything not white is black
479cd5de
VZ
1284 if (! (red == (unsigned char) 255 &&
1285 blue == (unsigned char) 255 &&
1286 green == (unsigned char) 255))
95724b1a
VZ
1287 {
1288 red = (unsigned char) 0;
1289 green = (unsigned char) 0;
1290 blue = (unsigned char) 0;
1291 }
1292 }
1293
1294 // maybe setgray here ?
1295 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
1296 {
1297 double redPS = (double)(red) / 255.0;
1298 double bluePS = (double)(blue) / 255.0;
1299 double greenPS = (double)(green) / 255.0;
479cd5de 1300
f6bcfd97
BP
1301 char buffer[100];
1302 sprintf( buffer,
1303 "%.8f %.8f %.8f setrgbcolor\n",
1304 redPS, greenPS, bluePS );
1305 for (int i = 0; i < 100; i++)
3ca6a5f0 1306 if (buffer[i] == ',') buffer[i] = '.';
244e5e34 1307 PsPrint( buffer );
479cd5de 1308
95724b1a
VZ
1309 m_currentRed = red;
1310 m_currentBlue = blue;
1311 m_currentGreen = green;
1312 }
1313 }
1314
1315 int size = m_font.GetPointSize();
1316
244e5e34 1317 PsPrintf( wxT("%d %d moveto\n"),
846051ec 1318 LogicalToDeviceX(x), LogicalToDeviceY(y));
ca65c044 1319
244e5e34
VZ
1320 char buffer[100];
1321 sprintf(buffer, "%.8f rotate\n", angle);
1322 size_t i;
1323 for (i = 0; i < 100; i++)
1324 {
1325 if (buffer[i] == ',') buffer[i] = '.';
1326 }
1327 PsPrint( buffer);
ca65c044 1328
244e5e34
VZ
1329 PsPrint( "(" );
1330 const wxWX2MBbuf textbuf = text.mb_str();
1331 size_t len = strlen(textbuf);
1332 for (i = 0; i < len; i++)
1333 {
1334 int c = (unsigned char) textbuf[i];
1335 if (c == ')' || c == '(' || c == '\\')
95724b1a 1336 {
244e5e34
VZ
1337 /* Cope with special characters */
1338 PsPrint( "\\" );
1339 PsPrint(c);
95724b1a 1340 }
244e5e34 1341 else if ( c >= 128 )
479cd5de 1342 {
244e5e34
VZ
1343 /* Cope with character codes > 127 */
1344 PsPrintf( wxT("\\%o"), c);
479cd5de 1345 }
244e5e34 1346 else
846051ec 1347 {
244e5e34 1348 PsPrint(c);
846051ec 1349 }
244e5e34 1350 }
ca65c044 1351
244e5e34 1352 PsPrint( ") show\n" );
ca65c044 1353
244e5e34
VZ
1354 sprintf( buffer, "%.8f rotate\n", -angle );
1355 for (i = 0; i < 100; i++)
1356 {
1357 if (buffer[i] == ',') buffer[i] = '.';
1358 }
1359 PsPrint( buffer );
ca65c044 1360
244e5e34
VZ
1361 if (m_font.GetUnderlined())
1362 {
1363 wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
1364 wxCoord w, h;
244e5e34
VZ
1365 GetTextExtent(text, &w, &h);
1366
1367 sprintf( buffer,
846051ec
JS
1368 "gsave\n"
1369 "%d %d moveto\n"
1370 "%f setlinewidth\n"
1371 "%d %d lineto\n"
1372 "stroke\n"
1373 "grestore\n",
1374 LogicalToDeviceX(x), LogicalToDeviceY(uy),
1375 m_underlineThickness,
1376 LogicalToDeviceX(x + w), LogicalToDeviceY(uy) );
244e5e34
VZ
1377 for (i = 0; i < 100; i++)
1378 {
1379 if (buffer[i] == ',') buffer[i] = '.';
846051ec 1380 }
244e5e34 1381 PsPrint( buffer );
95724b1a 1382 }
ca65c044 1383
95724b1a 1384 CalcBoundingBox( x, y );
88a7a4e1 1385 CalcBoundingBox( x + size * text.length() * 2/3 , y );
95724b1a 1386}
ed880dd4
RR
1387
1388void wxPostScriptDC::SetBackground (const wxBrush& brush)
1389{
1390 m_backgroundBrush = brush;
1391}
1392
1393void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function))
1394{
223d09f6 1395 wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") );
ed880dd4
RR
1396}
1397
389076f1 1398#if wxUSE_SPLINES
64698f9a 1399void wxPostScriptDC::DoDrawSpline( wxList *points )
ed880dd4 1400{
846051ec 1401 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 1402
ed880dd4
RR
1403 SetPen( m_pen );
1404
8a39593e 1405 // a and b are not used
846051ec 1406 //double a, b;
8a39593e 1407 double c, d, x1, y1, x2, y2, x3, y3;
ed880dd4
RR
1408 wxPoint *p, *q;
1409
222ed1d6 1410 wxList::compatibility_iterator node = points->GetFirst();
b1d4dd7a 1411 p = (wxPoint *)node->GetData();
afce4c03 1412 x1 = p->x;
ed880dd4
RR
1413 y1 = p->y;
1414
b1d4dd7a
RL
1415 node = node->GetNext();
1416 p = (wxPoint *)node->GetData();
afce4c03 1417 c = p->x;
ed880dd4 1418 d = p->y;
a47391f3 1419 x3 =
8a39593e 1420 #if 0
a47391f3
JS
1421 a =
1422 #endif
8a39593e 1423 (double)(x1 + c) / 2;
a47391f3 1424 y3 =
8a39593e 1425 #if 0
a47391f3
JS
1426 b =
1427 #endif
8a39593e 1428 (double)(y1 + d) / 2;
ed880dd4 1429
bdbcded6
JS
1430 PsPrintf( wxT("newpath\n")
1431 wxT("%d %d moveto\n")
1432 wxT("%d %d lineto\n"),
6a7b1d6e
RD
1433 LogicalToDeviceX((wxCoord)x1), LogicalToDeviceY((wxCoord)y1),
1434 LogicalToDeviceX((wxCoord)x3), LogicalToDeviceY((wxCoord)y3) );
afce4c03 1435
72cdf4c9
VZ
1436 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1437 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
ed880dd4 1438
244e5e34
VZ
1439 node = node->GetNext();
1440 while (node)
ed880dd4 1441 {
b1d4dd7a 1442 q = (wxPoint *)node->GetData();
ed880dd4 1443
d7657f75
RR
1444 x1 = x3;
1445 y1 = y3;
1446 x2 = c;
1447 y2 = d;
1448 c = q->x;
1449 d = q->y;
ed880dd4
RR
1450 x3 = (double)(x2 + c) / 2;
1451 y3 = (double)(y2 + d) / 2;
72cdf4c9 1452
244e5e34
VZ
1453 PsPrintf( wxT("%d %d %d %d %d %d DrawSplineSection\n"),
1454 LogicalToDeviceX((wxCoord)x1), LogicalToDeviceY((wxCoord)y1),
1455 LogicalToDeviceX((wxCoord)x2), LogicalToDeviceY((wxCoord)y2),
1456 LogicalToDeviceX((wxCoord)x3), LogicalToDeviceY((wxCoord)y3) );
72cdf4c9
VZ
1457
1458 CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
1459 CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
999836aa
VZ
1460
1461 node = node->GetNext();
ed880dd4 1462 }
afce4c03 1463
72cdf4c9
VZ
1464 /*
1465 At this point, (x2,y2) and (c,d) are the position of the
1466 next-to-last and last point respectively, in the point list
1467 */
ed880dd4 1468
51b62c24
JS
1469 PsPrintf( wxT("%d %d lineto\n")
1470 wxT("stroke\n"),
6a7b1d6e 1471 LogicalToDeviceX((wxCoord)c), LogicalToDeviceY((wxCoord)d) );
ed880dd4 1472}
389076f1 1473#endif // wxUSE_SPLINES
ed880dd4 1474
72cdf4c9 1475wxCoord wxPostScriptDC::GetCharWidth() const
ed880dd4
RR
1476{
1477 // Chris Breeze: reasonable approximation using wxMODERN/Courier
72cdf4c9 1478 return (wxCoord) (GetCharHeight() * 72.0 / 120.0);
ed880dd4
RR
1479}
1480
1481
1482void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
1483{
846051ec 1484 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 1485
ed880dd4
RR
1486 m_signX = (xLeftRight ? 1 : -1);
1487 m_signY = (yBottomUp ? 1 : -1);
afce4c03 1488
ed880dd4
RR
1489 ComputeScaleAndOrigin();
1490}
1491
72cdf4c9 1492void wxPostScriptDC::SetDeviceOrigin( wxCoord x, wxCoord y )
ed880dd4 1493{
846051ec 1494 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 1495
4bc67cc5
RR
1496 int h = 0;
1497 int w = 0;
1498 GetSize( &w, &h );
afce4c03 1499
4bc67cc5 1500 wxDC::SetDeviceOrigin( x, h-y );
ed880dd4
RR
1501}
1502
4e4ea166 1503void wxPostScriptDC::DoGetSize(int* width, int* height) const
ed880dd4 1504{
7bcb11d3 1505 wxPaperSize id = m_printData.GetPaperId();
ed880dd4 1506
7bcb11d3 1507 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id);
afce4c03 1508
7bcb11d3 1509 if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
afce4c03 1510
ac2def68
RR
1511 int w = 595;
1512 int h = 842;
ed880dd4
RR
1513 if (paper)
1514 {
ac2def68
RR
1515 w = paper->GetSizeDeviceUnits().x;
1516 h = paper->GetSizeDeviceUnits().y;
ed880dd4 1517 }
72cdf4c9 1518
ac2def68 1519 if (m_printData.GetOrientation() == wxLANDSCAPE)
ed880dd4 1520 {
ac2def68 1521 int tmp = w;
72cdf4c9
VZ
1522 w = h;
1523 h = tmp;
ed880dd4 1524 }
72cdf4c9 1525
b64de916
VS
1526 if (width) *width = (int)(w * ms_PSScaleFactor);
1527 if (height) *height = (int)(h * ms_PSScaleFactor);
ed880dd4
RR
1528}
1529
4e4ea166 1530void wxPostScriptDC::DoGetSizeMM(int *width, int *height) const
ed880dd4 1531{
7bcb11d3
JS
1532 wxPaperSize id = m_printData.GetPaperId();
1533
1534 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id);
afce4c03 1535
7bcb11d3
JS
1536 if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
1537
ac2def68
RR
1538 int w = 210;
1539 int h = 297;
7bcb11d3 1540 if (paper)
ed880dd4 1541 {
ac2def68
RR
1542 w = paper->GetWidth() / 10;
1543 h = paper->GetHeight() / 10;
ed880dd4 1544 }
72cdf4c9 1545
ac2def68 1546 if (m_printData.GetOrientation() == wxLANDSCAPE)
ed880dd4 1547 {
ac2def68 1548 int tmp = w;
72cdf4c9
VZ
1549 w = h;
1550 h = tmp;
ed880dd4 1551 }
72cdf4c9 1552
ac2def68
RR
1553 if (width) *width = w;
1554 if (height) *height = h;
7bcb11d3
JS
1555}
1556
1557// Resolution in pixels per logical inch
1558wxSize wxPostScriptDC::GetPPI(void) const
1559{
48c31b28 1560 return wxSize((int)(72 * ms_PSScaleFactor),
b64de916 1561 (int)(72 * ms_PSScaleFactor));
7bcb11d3 1562}
ed880dd4 1563
7bcb11d3 1564
d7657f75 1565bool wxPostScriptDC::StartDoc( const wxString& message )
7bcb11d3 1566{
ca65c044 1567 wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") );
32b13913 1568
6038ec8e 1569 if (m_printData.GetPrintMode() != wxPRINT_MODE_STREAM )
7bcb11d3 1570 {
ca65c044 1571 if (m_printData.GetFilename() == wxEmptyString)
244e5e34
VZ
1572 {
1573 wxString filename = wxGetTempFileName( wxT("ps") );
1574 m_printData.SetFilename(filename);
1575 }
72cdf4c9 1576
392857fb 1577 m_pstream = wxFopen( m_printData.GetFilename(), wxT("w+") );
7bcb11d3 1578
244e5e34
VZ
1579 if (!m_pstream)
1580 {
1581 wxLogError( _("Cannot open file for PostScript printing!"));
ca65c044
WS
1582 m_ok = false;
1583 return false;
244e5e34 1584 }
ed880dd4 1585 }
afce4c03 1586
ca65c044 1587 m_ok = true;
244e5e34 1588 m_title = message;
ed880dd4 1589
244e5e34
VZ
1590 PsPrint( "%!PS-Adobe-2.0\n" );
1591 PsPrintf( wxT("%%%%Title: %s\n"), m_title.c_str() );
77ffb593 1592 PsPrint( "%%Creator: wxWidgets PostScript renderer\n" );
244e5e34 1593 PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() );
eba33006 1594 if (m_printData.GetOrientation() == wxLANDSCAPE)
244e5e34 1595 PsPrint( "%%Orientation: Landscape\n" );
eba33006 1596 else
244e5e34 1597 PsPrint( "%%Orientation: Portrait\n" );
a47391f3 1598
244e5e34 1599 // PsPrintf( wxT("%%%%Pages: %d\n"), (wxPageNumber - 1) );
a47391f3 1600
244e5e34 1601 const wxChar *paper;
3fc306e9
RR
1602 switch (m_printData.GetPaperId())
1603 {
670f9935
WS
1604 case wxPAPER_LETTER: paper = wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches
1605 case wxPAPER_LEGAL: paper = wxT("Legal"); break; // Legal, 8 1/2 by 14 inches
1606 case wxPAPER_A4: paper = wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters
244e5e34 1607 case wxPAPER_TABLOID: paper = wxT("Tabloid"); break; // Tabloid, 11 by 17 inches
670f9935
WS
1608 case wxPAPER_LEDGER: paper = wxT("Ledger"); break; // Ledger, 17 by 11 inches
1609 case wxPAPER_STATEMENT: paper = wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches
1610 case wxPAPER_EXECUTIVE: paper = wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches
1611 case wxPAPER_A3: paper = wxT("A3"); break; // A3 sheet, 297 by 420 millimeters
1612 case wxPAPER_A5: paper = wxT("A5"); break; // A5 sheet, 148 by 210 millimeters
1613 case wxPAPER_B4: paper = wxT("B4"); break; // B4 sheet, 250 by 354 millimeters
1614 case wxPAPER_B5: paper = wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper
1615 case wxPAPER_FOLIO: paper = wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper
1616 case wxPAPER_QUARTO: paper = wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper
1617 case wxPAPER_10X14: paper = wxT("10x14"); break; // 10-by-14-inch sheet
244e5e34 1618 default: paper = wxT("A4");
3fc306e9 1619 }
244e5e34
VZ
1620 PsPrintf( wxT("%%%%DocumentPaperSizes: %s\n"), paper );
1621 PsPrint( "%%EndComments\n\n" );
1622
1623 PsPrint( "%%BeginProlog\n" );
1624 PsPrint( wxPostScriptHeaderConicTo );
1625 PsPrint( wxPostScriptHeaderEllipse );
1626 PsPrint( wxPostScriptHeaderEllipticArc );
1627 PsPrint( wxPostScriptHeaderColourImage );
244e5e34
VZ
1628 PsPrint( wxPostScriptHeaderReencodeISO1 );
1629 PsPrint( wxPostScriptHeaderReencodeISO2 );
d7657f75 1630 if (wxPostScriptHeaderSpline)
244e5e34
VZ
1631 PsPrint( wxPostScriptHeaderSpline );
1632 PsPrint( "%%EndProlog\n" );
d7657f75 1633
ed880dd4
RR
1634 SetBrush( *wxBLACK_BRUSH );
1635 SetPen( *wxBLACK_PEN );
1636 SetBackground( *wxWHITE_BRUSH );
1637 SetTextForeground( *wxBLACK );
1638
1639 // set origin according to paper size
1640 SetDeviceOrigin( 0,0 );
afce4c03 1641
ed880dd4
RR
1642 wxPageNumber = 1;
1643 m_pageNumber = 1;
ca65c044 1644 return true;
ed880dd4
RR
1645}
1646
1647void wxPostScriptDC::EndDoc ()
1648{
244e5e34 1649 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 1650
ed880dd4
RR
1651 if (m_clipping)
1652 {
ca65c044 1653 m_clipping = false;
244e5e34 1654 PsPrint( "grestore\n" );
ed880dd4
RR
1655 }
1656
244e5e34
VZ
1657 if ( m_pstream ) {
1658 fclose( m_pstream );
1659 m_pstream = (FILE *) NULL;
1660 }
ed880dd4 1661
a47391f3 1662#if 0
ed880dd4 1663 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
72cdf4c9 1664 wxCoord wx_printer_translate_x, wx_printer_translate_y;
ed880dd4 1665 double wx_printer_scale_x, wx_printer_scale_y;
ed880dd4 1666
479cd5de
VZ
1667 wx_printer_translate_x = (wxCoord)m_printData.GetPrinterTranslateX();
1668 wx_printer_translate_y = (wxCoord)m_printData.GetPrinterTranslateY();
7bcb11d3
JS
1669
1670 wx_printer_scale_x = m_printData.GetPrinterScaleX();
1671 wx_printer_scale_y = m_printData.GetPrinterScaleY();
1672
ed880dd4
RR
1673 // Compute the bounding box. Note that it is in the default user
1674 // coordinate system, thus we have to convert the values.
6a7b1d6e
RD
1675 wxCoord minX = (wxCoord) LogicalToDeviceX(m_minX);
1676 wxCoord minY = (wxCoord) LogicalToDeviceY(m_minY);
1677 wxCoord maxX = (wxCoord) LogicalToDeviceX(m_maxX);
1678 wxCoord maxY = (wxCoord) LogicalToDeviceY(m_maxY);
48c31b28 1679
a30f8da8
VS
1680 // LOG2DEV may have changed the minimum to maximum vice versa
1681 if ( minX > maxX ) { wxCoord tmp = minX; minX = maxX; maxX = tmp; }
1682 if ( minY > maxY ) { wxCoord tmp = minY; minY = maxY; maxY = tmp; }
48c31b28 1683
a30f8da8
VS
1684 // account for used scaling (boundingbox is before scaling in ps-file)
1685 double scale_x = m_printData.GetPrinterScaleX() / ms_PSScaleFactor;
1686 double scale_y = m_printData.GetPrinterScaleY() / ms_PSScaleFactor;
48c31b28
VZ
1687
1688 wxCoord llx, lly, urx, ury;
a30f8da8
VS
1689 llx = (wxCoord) ((minX+wx_printer_translate_x)*scale_x);
1690 lly = (wxCoord) ((minY+wx_printer_translate_y)*scale_y);
1691 urx = (wxCoord) ((maxX+wx_printer_translate_x)*scale_x);
1692 ury = (wxCoord) ((maxY+wx_printer_translate_y)*scale_y);
1693 // (end of bounding box computation)
1694
ed880dd4
RR
1695
1696 // If we're landscape, our sense of "x" and "y" is reversed.
7bcb11d3 1697 if (m_printData.GetOrientation() == wxLANDSCAPE)
ed880dd4 1698 {
72cdf4c9 1699 wxCoord tmp;
ed880dd4
RR
1700 tmp = llx; llx = lly; lly = tmp;
1701 tmp = urx; urx = ury; ury = tmp;
1702
1703 // We need either the two lines that follow, or we need to subtract
1704 // min_x from real_translate_y, which is commented out below.
72cdf4c9
VZ
1705 llx = llx - (wxCoord)(m_minX*wx_printer_scale_y);
1706 urx = urx - (wxCoord)(m_minX*wx_printer_scale_y);
ed880dd4
RR
1707 }
1708
1709 // The Adobe specifications call for integers; we round as to make
1710 // the bounding larger.
244e5e34 1711 PsPrintf( wxT("%%%%BoundingBox: %d %d %d %d\n"),
72cdf4c9
VZ
1712 (wxCoord)floor((double)llx), (wxCoord)floor((double)lly),
1713 (wxCoord)ceil((double)urx), (wxCoord)ceil((double)ury) );
ed880dd4
RR
1714
1715 // To check the correctness of the bounding box, postscript commands
1716 // to draw a box corresponding to the bounding box are generated below.
1717 // But since we typically don't want to print such a box, the postscript
1718 // commands are generated within comments. These lines appear before any
1719 // adjustment of scale, rotation, or translation, and hence are in the
1720 // default user coordinates.
244e5e34
VZ
1721 PsPrint( "% newpath\n" );
1722 PsPrintf( wxT("%% %d %d moveto\n"), llx, lly );
1723 PsPrintf( wxT("%% %d %d lineto\n"), urx, lly );
1724 PsPrintf( wxT("%% %d %d lineto\n"), urx, ury );
1725 PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx, ury );
09c9194a 1726#endif
ed880dd4 1727
8850cbd3 1728#ifndef __WXMSW__
32b13913 1729 wxPostScriptPrintNativeData *data =
8850cbd3
RR
1730 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
1731
6038ec8e 1732 if (m_ok && (m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER))
ed880dd4 1733 {
09c9194a 1734 wxString command;
8850cbd3 1735 command += data->GetPrinterCommand();
09c9194a 1736 command += wxT(" ");
8850cbd3 1737 command += data->GetPrinterOptions();
cb27bab1 1738 command += wxT(" ");
09c9194a 1739 command += m_printData.GetFilename();
ed880dd4 1740
ca65c044 1741 wxExecute( command, true );
09c9194a 1742 wxRemoveFile( m_printData.GetFilename() );
ed880dd4
RR
1743 }
1744#endif
1745}
1746
d7657f75 1747void wxPostScriptDC::StartPage()
ed880dd4 1748{
846051ec 1749 wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
afce4c03 1750
244e5e34 1751 PsPrintf( wxT("%%%%Page: %d\n"), wxPageNumber++ );
afce4c03 1752
ac2def68 1753 // What is this one supposed to do? RR.
ed880dd4
RR
1754// *m_pstream << "matrix currentmatrix\n";
1755
1756 // Added by Chris Breeze
1757
9a6be59a
VZ
1758 // Each page starts with an "initgraphics" which resets the
1759 // transformation and so we need to reset the origin
1760 // (and rotate the page for landscape printing)
afce4c03 1761
afce4c03 1762 // Output scaling
72cdf4c9 1763 wxCoord translate_x, translate_y;
afce4c03 1764 double scale_x, scale_y;
afce4c03 1765
32b13913 1766 wxPostScriptPrintNativeData *data =
8850cbd3
RR
1767 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
1768
1769 translate_x = (wxCoord)data->GetPrinterTranslateX();
1770 translate_y = (wxCoord)data->GetPrinterTranslateY();
7bcb11d3 1771
8850cbd3
RR
1772 scale_x = data->GetPrinterScaleX();
1773 scale_y = data->GetPrinterScaleY();
7bcb11d3
JS
1774
1775 if (m_printData.GetOrientation() == wxLANDSCAPE)
afce4c03 1776 {
ac2def68
RR
1777 int h;
1778 GetSize( (int*) NULL, &h );
1779 translate_y -= h;
244e5e34
VZ
1780 PsPrint( "90 rotate\n" );
1781 // I copied this one from a PostScript tutorial, but to no avail. RR.
1782 // PsPrint( "90 rotate llx neg ury nef translate\n" );
afce4c03
VZ
1783 }
1784
244e5e34
VZ
1785 char buffer[100];
1786 sprintf( buffer, "%.8f %.8f scale\n", scale_x / ms_PSScaleFactor,
846051ec 1787 scale_y / ms_PSScaleFactor);
244e5e34
VZ
1788 for (int i = 0; i < 100; i++)
1789 if (buffer[i] == ',') buffer[i] = '.';
1790 PsPrint( buffer );
1791
1792 PsPrintf( wxT("%d %d translate\n"), translate_x, translate_y );
ed880dd4
RR
1793}
1794
1795void wxPostScriptDC::EndPage ()
1796{
846051ec 1797 wxCHECK_RET( m_ok , wxT("invalid postscript dc") );
afce4c03 1798
244e5e34 1799 PsPrint( "showpage\n" );
ed880dd4
RR
1800}
1801
72cdf4c9
VZ
1802bool wxPostScriptDC::DoBlit( wxCoord xdest, wxCoord ydest,
1803 wxCoord fwidth, wxCoord fheight,
afce4c03 1804 wxDC *source,
72cdf4c9 1805 wxCoord xsrc, wxCoord ysrc,
f0a6b1cd 1806 int rop, bool WXUNUSED(useMask), wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask) )
ed880dd4 1807{
ca65c044 1808 wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") );
afce4c03 1809
ca65c044 1810 wxCHECK_MSG( source, false, wxT("invalid source dc") );
afce4c03 1811
342b6a2f 1812 /* blit into a bitmap */
afce4c03 1813 wxBitmap bitmap( (int)fwidth, (int)fheight );
45b776d4
JS
1814 wxMemoryDC memDC;
1815 memDC.SelectObject(bitmap);
342b6a2f 1816 memDC.Blit(0, 0, fwidth, fheight, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */
45b776d4 1817 memDC.SelectObject(wxNullBitmap);
ea6f44b5
RR
1818
1819 /* draw bitmap. scaling and positioning is done there */
ea6f44b5 1820 DrawBitmap( bitmap, xdest, ydest );
afce4c03 1821
ca65c044 1822 return true;
ed880dd4
RR
1823}
1824
72cdf4c9 1825wxCoord wxPostScriptDC::GetCharHeight() const
ed880dd4
RR
1826{
1827 if (m_font.Ok())
b64de916 1828 return m_font.GetPointSize();
ed880dd4
RR
1829 else
1830 return 12;
1831}
1832
72cdf4c9
VZ
1833void wxPostScriptDC::DoGetTextExtent(const wxString& string,
1834 wxCoord *x, wxCoord *y,
1835 wxCoord *descent, wxCoord *externalLeading,
1836 wxFont *theFont ) const
ed880dd4 1837{
36b3b54a 1838 wxFont *fontToUse = theFont;
afce4c03 1839
36b3b54a
RR
1840 if (!fontToUse) fontToUse = (wxFont*) &m_font;
1841
223d09f6 1842 wxCHECK_RET( fontToUse, wxT("GetTextExtent: no font defined") );
87138c52 1843
32b13913 1844 if (string.empty())
3fc306e9
RR
1845 {
1846 if (x) (*x) = 0;
1847 if (y) (*y) = 0;
272995af
JS
1848 if (descent) (*descent) = 0;
1849 if (externalLeading) (*externalLeading) = 0;
3fc306e9
RR
1850 return;
1851 }
a47391f3 1852
3fc306e9
RR
1853 // GTK 2.0
1854
9626e0bf 1855 const wxWX2MBbuf strbuf = string.mb_str();
ed880dd4 1856
f036b31c 1857#if !wxUSE_AFM_FOR_POSTSCRIPT
36b3b54a
RR
1858 /* Provide a VERY rough estimate (avoid using it).
1859 * Produces accurate results for mono-spaced font
1860 * such as Courier (aka wxMODERN) */
afce4c03 1861
9a6be59a
VZ
1862 int height = 12;
1863 if (fontToUse)
1864 {
afce4c03 1865 height = fontToUse->GetPointSize();
9a6be59a 1866 }
72cdf4c9
VZ
1867 if ( x )
1868 *x = strlen (strbuf) * height * 72 / 120;
1869 if ( y )
1870 *y = (wxCoord) (height * 1.32); /* allow for descender */
36b3b54a
RR
1871 if (descent) *descent = 0;
1872 if (externalLeading) *externalLeading = 0;
ed880dd4 1873#else
ed880dd4 1874
afce4c03
VZ
1875 /* method for calculating string widths in postscript:
1876 / read in the AFM (adobe font metrics) file for the
1877 / actual font, parse it and extract the character widths
1878 / and also the descender. this may be improved, but for now
1879 / it works well. the AFM file is only read in if the
1880 / font is changed. this may be chached in the future.
1881 / calls to GetTextExtent with the font unchanged are rather
1882 / efficient!!!
1883 /
1884 / for each font and style used there is an AFM file necessary.
1885 / currently i have only files for the roman font family.
1886 / I try to get files for the other ones!
1887 /
1888 / CAVE: the size of the string is currently always calculated
1889 / in 'points' (1/72 of an inch). this should later on be
1890 / changed to depend on the mapping mode.
1891 / CAVE: the path to the AFM files must be set before calling this
1892 / function. this is usually done by a call like the following:
1893 / wxSetAFMPath("d:\\wxw161\\afm\\");
1894 /
1895 / example:
1896 /
ca65c044 1897 / wxPostScriptDC dc(NULL, true);
afce4c03
VZ
1898 / if (dc.Ok()){
1899 / wxSetAFMPath("d:\\wxw161\\afm\\");
1900 / dc.StartDoc("Test");
1901 / dc.StartPage();
72cdf4c9 1902 / wxCoord w,h;
afce4c03
VZ
1903 / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1904 / dc.GetTextExtent("Hallo",&w,&h);
1905 / dc.EndPage();
1906 / dc.EndDoc();
1907 / }
1908 /
1909 / by steve (stefan.hammes@urz.uni-heidelberg.de)
1910 / created: 10.09.94
1911 / updated: 14.05.95 */
36b3b54a
RR
1912
1913 /* these static vars are for storing the state between calls */
1914 static int lastFamily= INT_MIN;
1915 static int lastSize= INT_MIN;
1916 static int lastStyle= INT_MIN;
1917 static int lastWeight= INT_MIN;
1918 static int lastDescender = INT_MIN;
1919 static int lastWidths[256]; /* widths of the characters */
72cdf4c9 1920
a439ecef
VS
1921 double UnderlinePosition = 0.0;
1922 double UnderlineThickness = 0.0;
36b3b54a 1923
eba33006 1924 // Get actual parameters
733b25e1
RR
1925 int Family = fontToUse->GetFamily();
1926 int Size = fontToUse->GetPointSize();
1927 int Style = fontToUse->GetStyle();
1928 int Weight = fontToUse->GetWeight();
36b3b54a 1929
eba33006 1930 // If we have another font, read the font-metrics
36b3b54a
RR
1931 if (Family!=lastFamily || Size!=lastSize || Style!=lastStyle || Weight!=lastWeight)
1932 {
eba33006 1933 // Store actual values
36b3b54a
RR
1934 lastFamily = Family;
1935 lastSize = Size;
1936 lastStyle = Style;
1937 lastWeight = Weight;
1938
999836aa 1939 const wxChar *name;
36b3b54a
RR
1940
1941 switch (Family)
afce4c03
VZ
1942 {
1943 case wxMODERN:
733b25e1
RR
1944 case wxTELETYPE:
1945 {
2b5f62a0
VZ
1946 if ((Style == wxITALIC) && (Weight == wxBOLD)) name = wxT("CourBoO.afm");
1947 else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = wxT("CourBo.afm");
1948 else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = wxT("CourO.afm");
1949 else name = wxT("Cour.afm");
afce4c03 1950 break;
733b25e1 1951 }
afce4c03 1952 case wxROMAN:
733b25e1 1953 {
2b5f62a0
VZ
1954 if ((Style == wxITALIC) && (Weight == wxBOLD)) name = wxT("TimesBoO.afm");
1955 else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = wxT("TimesBo.afm");
1956 else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = wxT("TimesO.afm");
1957 else name = wxT("TimesRo.afm");
afce4c03 1958 break;
733b25e1
RR
1959 }
1960 case wxSCRIPT:
1961 {
2b5f62a0 1962 name = wxT("Zapf.afm");
999836aa 1963 break;
733b25e1
RR
1964 }
1965 case wxSWISS:
afce4c03 1966 default:
733b25e1 1967 {
2b5f62a0
VZ
1968 if ((Style == wxITALIC) && (Weight == wxBOLD)) name = wxT("HelvBoO.afm");
1969 else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = wxT("HelvBo.afm");
1970 else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = wxT("HelvO.afm");
1971 else name = wxT("Helv.afm");
afce4c03 1972 break;
733b25e1 1973 }
afce4c03 1974 }
36b3b54a 1975
eba33006 1976 FILE *afmFile = NULL;
a47391f3 1977
d36d1be9
VZ
1978 // Get the directory of the AFM files
1979 wxString afmName;
1980
1981 // VZ: I don't know if the cast always works under Unix but it clearly
1982 // never does under Windows where the pointer is
1983 // wxWindowsPrintNativeData and so calling GetFontMetricPath() on
1984 // it just crashes
1985#ifndef __WIN32__
32b13913 1986 wxPostScriptPrintNativeData *data =
398c701f 1987 wxDynamicCast(m_printData.GetNativeData(), wxPostScriptPrintNativeData);
32b13913 1988
398c701f 1989 if (data && !data->GetFontMetricPath().empty())
72cdf4c9 1990 {
8850cbd3 1991 afmName = data->GetFontMetricPath();
eba33006 1992 afmName << wxFILE_SEP_PATH << name;
d361e74e 1993 }
d36d1be9 1994#endif // __WIN32__
72cdf4c9 1995
d36d1be9
VZ
1996 if ( !afmName.empty() )
1997 afmFile = wxFopen(afmName, wxT("r"));
1998
d36d1be9
VZ
1999 if ( !afmFile )
2000 {
2001#if defined(__UNIX__) && !defined(__VMS__)
2c18f21d 2002 afmName = wxGetDataDir();
d36d1be9
VZ
2003#else // !__UNIX__
2004 afmName = wxStandardPaths::Get().GetDataDir();
2005#endif // __UNIX__/!__UNIX__
2006
3e469ea3 2007 afmName << wxFILE_SEP_PATH
733b25e1
RR
2008#if defined(__LINUX__) || defined(__FREEBSD__)
2009 << wxT("gs_afm") << wxFILE_SEP_PATH
2010#else
021e0f21 2011 << wxT("afm") << wxFILE_SEP_PATH
733b25e1
RR
2012#endif
2013 << name;
392857fb 2014 afmFile = wxFopen(afmName,wxT("r"));
3e469ea3 2015 }
479cd5de 2016
eba33006
RR
2017 /* 2. open and process the file
2018 / a short explanation of the AFM format:
2019 / we have for each character a line, which gives its size
2020 / e.g.:
2021 /
2022 / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
2023 /
2024 / that means, we have a character with ascii code 63, and width
2025 / (444/1000 * fontSize) points.
2026 / the other data is ignored for now!
2027 /
2028 / when the font has changed, we read in the right AFM file and store the
2029 / character widths in an array, which is processed below (see point 3.). */
385bcb35 2030 if (afmFile==NULL)
36b3b54a 2031 {
ccbfa8ec 2032 wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName.c_str() );
48c31b28 2033 wxLogDebug( wxT(" using approximate values"));
36b3b54a
RR
2034 for (int i=0; i<256; i++) lastWidths[i] = 500; /* an approximate value */
2035 lastDescender = -150; /* dito. */
ed880dd4 2036 }
afce4c03
VZ
2037 else
2038 {
36b3b54a
RR
2039 /* init the widths array */
2040 for(int i=0; i<256; i++) lastWidths[i] = INT_MIN;
2041 /* some variables for holding parts of a line */
32b13913
WS
2042 char cString[10], semiString[10], WXString[10];
2043 char descString[20];
2044 char upString[30], utString[30];
2045 char encString[50];
36b3b54a
RR
2046 char line[256];
2047 int ascii,cWidth;
2048 /* read in the file and parse it */
2049 while(fgets(line,sizeof(line),afmFile)!=NULL)
afce4c03 2050 {
36b3b54a 2051 /* A.) check for descender definition */
021e0f21 2052 if (strncmp(line,"Descender",9)==0)
afce4c03 2053 {
36b3b54a 2054 if ((sscanf(line,"%s%d",descString,&lastDescender)!=2) ||
021e0f21 2055 (strcmp(descString,"Descender")!=0))
afce4c03 2056 {
ccbfa8ec 2057 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName.c_str(),line );
36b3b54a
RR
2058 }
2059 }
2060 /* JC 1.) check for UnderlinePosition */
021e0f21 2061 else if(strncmp(line,"UnderlinePosition",17)==0)
afce4c03 2062 {
36b3b54a 2063 if ((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) ||
021e0f21 2064 (strcmp(upString,"UnderlinePosition")!=0))
afce4c03 2065 {
ccbfa8ec 2066 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName.c_str(), line );
36b3b54a
RR
2067 }
2068 }
afce4c03 2069 /* JC 2.) check for UnderlineThickness */
021e0f21 2070 else if(strncmp(line,"UnderlineThickness",18)==0)
afce4c03 2071 {
36b3b54a 2072 if ((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) ||
021e0f21 2073 (strcmp(utString,"UnderlineThickness")!=0))
afce4c03 2074 {
ccbfa8ec 2075 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName.c_str(), line );
36b3b54a
RR
2076 }
2077 }
afce4c03 2078 /* JC 3.) check for EncodingScheme */
021e0f21 2079 else if(strncmp(line,"EncodingScheme",14)==0)
afce4c03 2080 {
36b3b54a 2081 if ((sscanf(line,"%s%s",utString,encString)!=2) ||
021e0f21 2082 (strcmp(utString,"EncodingScheme")!=0))
afce4c03 2083 {
ccbfa8ec 2084 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName.c_str(), line );
36b3b54a 2085 }
021e0f21 2086 else if (strncmp(encString, "AdobeStandardEncoding", 21))
36b3b54a 2087 {
ccbfa8ec 2088 wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"),
3e469ea3 2089 afmName.c_str(),line, encString);
36b3b54a
RR
2090 }
2091 }
2092 /* B.) check for char-width */
021e0f21 2093 else if(strncmp(line,"C ",2)==0)
afce4c03 2094 {
36b3b54a 2095 if (sscanf(line,"%s%d%s%s%d",cString,&ascii,semiString,WXString,&cWidth)!=5)
afce4c03 2096 {
ccbfa8ec 2097 wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName.c_str(),line);
36b3b54a 2098 }
021e0f21 2099 if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 || strcmp(WXString,"WX")!=0)
afce4c03 2100 {
ccbfa8ec 2101 wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName.c_str(),line);
36b3b54a
RR
2102 }
2103 /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
2104 if (ascii>=0 && ascii<256)
afce4c03 2105 {
36b3b54a
RR
2106 lastWidths[ascii] = cWidth; /* store width */
2107 }
afce4c03
VZ
2108 else
2109 {
2110 /* MATTHEW: this happens a lot; don't print an error */
48c31b28 2111 /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */
36b3b54a
RR
2112 }
2113 }
2114 /* C.) ignore other entries. */
2115 }
2116 fclose(afmFile);
ed880dd4 2117 }
36b3b54a 2118 /* hack to compute correct values for german 'Umlaute'
afce4c03
VZ
2119 / the correct way would be to map the character names
2120 / like 'adieresis' to corresp. positions of ISOEnc and read
2121 / these values from AFM files, too. Maybe later ... */
b52e49f5
VZ
2122
2123 // NB: casts to int are needed to suppress gcc 3.3 warnings
2124