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