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