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