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