]>
Commit | Line | Data |
---|---|---|
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__ | |
1aedb1dd | 13 | #pragma implementation "dcpsg.h" |
ed880dd4 RR |
14 | #endif |
15 | ||
9a6be59a VZ |
16 | #include "wx/wxprec.h" |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | #ifndef WX_PRECOMP | |
9a6be59a | 23 | #endif // WX_PRECOMP |
06cfab17 | 24 | |
ce4169a4 RR |
25 | #if wxUSE_PRINTING_ARCHITECTURE |
26 | ||
06cfab17 RR |
27 | #if wxUSE_POSTSCRIPT |
28 | ||
401eb3de RR |
29 | #include "wx/setup.h" |
30 | ||
e6f1ad22 | 31 | #include "wx/window.h" |
f04371f0 | 32 | #include "wx/dcmemory.h" |
ed880dd4 | 33 | #include "wx/utils.h" |
f04371f0 | 34 | #include "wx/intl.h" |
ed880dd4 | 35 | #include "wx/filedlg.h" |
ed880dd4 | 36 | #include "wx/app.h" |
f04371f0 | 37 | #include "wx/msgdlg.h" |
ef539066 | 38 | #include "wx/image.h" |
3069ac4e | 39 | #include "wx/log.h" |
bf38cbff | 40 | #include "wx/generic/dcpsg.h" |
b403ab00 | 41 | #include "wx/printdlg.h" |
bf38cbff JS |
42 | #include "wx/button.h" |
43 | #include "wx/stattext.h" | |
44 | #include "wx/radiobox.h" | |
45 | #include "wx/textctrl.h" | |
9a05fd8d | 46 | #include "wx/prntbase.h" |
7bcb11d3 | 47 | #include "wx/paper.h" |
d361e74e | 48 | #include "wx/filefn.h" |
ed880dd4 | 49 | |
57c208c5 JS |
50 | #include <math.h> |
51 | ||
bf38cbff JS |
52 | #ifdef __WXMSW__ |
53 | ||
54 | #ifdef DrawText | |
55 | #undef DrawText | |
56 | #endif | |
57 | ||
58 | #ifdef StartDoc | |
59 | #undef StartDoc | |
60 | #endif | |
61 | ||
62 | #ifdef GetCharWidth | |
63 | #undef GetCharWidth | |
64 | #endif | |
65 | ||
66 | #ifdef FindWindow | |
67 | #undef FindWindow | |
68 | #endif | |
69 | ||
70 | #endif | |
71 | ||
ed880dd4 RR |
72 | //----------------------------------------------------------------------------- |
73 | // start and end of document/page | |
74 | //----------------------------------------------------------------------------- | |
75 | ||
76 | static const char *wxPostScriptHeaderEllipse = "\ | |
77 | /ellipsedict 8 dict def\n\ | |
78 | ellipsedict /mtrx matrix put\n\ | |
79 | /ellipse {\n\ | |
9a6be59a VZ |
80 | ellipsedict begin\n\ |
81 | /endangle exch def\n\ | |
82 | /startangle exch def\n\ | |
83 | /yrad exch def\n\ | |
84 | /xrad exch def\n\ | |
85 | /y exch def\n\ | |
86 | /x exch def\n\ | |
87 | /savematrix mtrx currentmatrix def\n\ | |
88 | x y translate\n\ | |
89 | xrad yrad scale\n\ | |
90 | 0 0 1 startangle endangle arc\n\ | |
91 | savematrix setmatrix\n\ | |
92 | end\n\ | |
93 | } def\n\ | |
ed880dd4 RR |
94 | "; |
95 | ||
96 | static const char *wxPostScriptHeaderEllipticArc= "\ | |
97 | /ellipticarcdict 8 dict def\n\ | |
98 | ellipticarcdict /mtrx matrix put\n\ | |
99 | /ellipticarc\n\ | |
100 | { ellipticarcdict begin\n\ | |
101 | /do_fill exch def\n\ | |
102 | /endangle exch def\n\ | |
103 | /startangle exch def\n\ | |
104 | /yrad exch def\n\ | |
105 | /xrad exch def \n\ | |
106 | /y exch def\n\ | |
107 | /x exch def\n\ | |
108 | /savematrix mtrx currentmatrix def\n\ | |
109 | x y translate\n\ | |
110 | xrad yrad scale\n\ | |
111 | do_fill { 0 0 moveto } if\n\ | |
112 | 0 0 1 startangle endangle arc\n\ | |
113 | savematrix setmatrix\n\ | |
114 | do_fill { fill }{ stroke } ifelse\n\ | |
115 | end\n\ | |
116 | } def\n"; | |
117 | ||
118 | static const char *wxPostScriptHeaderSpline = "\ | |
119 | /DrawSplineSection {\n\ | |
9a6be59a VZ |
120 | /y3 exch def\n\ |
121 | /x3 exch def\n\ | |
122 | /y2 exch def\n\ | |
123 | /x2 exch def\n\ | |
124 | /y1 exch def\n\ | |
125 | /x1 exch def\n\ | |
126 | /xa x1 x2 x1 sub 0.666667 mul add def\n\ | |
127 | /ya y1 y2 y1 sub 0.666667 mul add def\n\ | |
128 | /xb x3 x2 x3 sub 0.666667 mul add def\n\ | |
129 | /yb y3 y2 y3 sub 0.666667 mul add def\n\ | |
130 | x1 y1 lineto\n\ | |
131 | xa ya xb yb x3 y3 curveto\n\ | |
132 | } def\n\ | |
ed880dd4 RR |
133 | "; |
134 | ||
135 | static const char *wxPostScriptHeaderColourImage = "\ | |
d7657f75 RR |
136 | %% define 'colorimage' if it isn't defined\n\ |
137 | %% ('colortogray' and 'mergeprocs' come from xwd2ps\n\ | |
138 | %% via xgrab)\n\ | |
139 | /colorimage where %% do we know about 'colorimage'?\n\ | |
140 | { pop } %% yes: pop off the 'dict' returned\n\ | |
141 | { %% no: define one\n\ | |
142 | /colortogray { %% define an RGB->I function\n\ | |
143 | /rgbdata exch store %% call input 'rgbdata'\n\ | |
ed880dd4 RR |
144 | rgbdata length 3 idiv\n\ |
145 | /npixls exch store\n\ | |
146 | /rgbindx 0 store\n\ | |
147 | 0 1 npixls 1 sub {\n\ | |
148 | grays exch\n\ | |
d7657f75 RR |
149 | rgbdata rgbindx get 20 mul %% Red\n\ |
150 | rgbdata rgbindx 1 add get 32 mul %% Green\n\ | |
151 | rgbdata rgbindx 2 add get 12 mul %% Blue\n\ | |
152 | add add 64 idiv %% I = .5G + .31R + .18B\n\ | |
ed880dd4 RR |
153 | put\n\ |
154 | /rgbindx rgbindx 3 add store\n\ | |
155 | } for\n\ | |
156 | grays 0 npixls getinterval\n\ | |
157 | } bind def\n\ | |
158 | \n\ | |
d7657f75 RR |
159 | %% Utility procedure for colorimage operator.\n\ |
160 | %% This procedure takes two procedures off the\n\ | |
161 | %% stack and merges them into a single procedure.\n\ | |
ed880dd4 | 162 | \n\ |
d7657f75 | 163 | /mergeprocs { %% def\n\ |
ed880dd4 RR |
164 | dup length\n\ |
165 | 3 -1 roll\n\ | |
166 | dup\n\ | |
167 | length\n\ | |
168 | dup\n\ | |
169 | 5 1 roll\n\ | |
170 | 3 -1 roll\n\ | |
171 | add\n\ | |
172 | array cvx\n\ | |
173 | dup\n\ | |
174 | 3 -1 roll\n\ | |
175 | 0 exch\n\ | |
176 | putinterval\n\ | |
177 | dup\n\ | |
178 | 4 2 roll\n\ | |
179 | putinterval\n\ | |
180 | } bind def\n\ | |
181 | \n\ | |
d7657f75 RR |
182 | /colorimage { %% def\n\ |
183 | pop pop %% remove 'false 3' operands\n\ | |
ed880dd4 RR |
184 | {colortogray} mergeprocs\n\ |
185 | image\n\ | |
186 | } bind def\n\ | |
d7657f75 | 187 | } ifelse %% end of 'false' case\n\ |
ed880dd4 RR |
188 | "; |
189 | ||
190 | static char wxPostScriptHeaderReencodeISO1[] = | |
191 | "\n/reencodeISO {\n" | |
192 | "dup dup findfont dup length dict begin\n" | |
193 | "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n" | |
194 | "/Encoding ISOLatin1Encoding def\n" | |
195 | "currentdict end definefont\n" | |
196 | "} def\n" | |
197 | "/ISOLatin1Encoding [\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 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
202 | "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n" | |
203 | "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n" | |
204 | "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n" | |
205 | "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n" | |
206 | "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n" | |
207 | "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n" | |
208 | "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n" | |
209 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
210 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
211 | "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n" | |
212 | "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n"; | |
213 | ||
214 | static char wxPostScriptHeaderReencodeISO2[] = | |
215 | "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n" | |
216 | "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n" | |
217 | "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n" | |
218 | "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n" | |
219 | "/guillemotright/onequarter/onehalf/threequarters/questiondown\n" | |
220 | "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n" | |
221 | "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n" | |
222 | "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n" | |
223 | "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n" | |
224 | "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n" | |
225 | "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n" | |
226 | "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n" | |
227 | "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n" | |
228 | "/yacute/thorn/ydieresis\n" | |
229 | "] def\n\n"; | |
230 | ||
ed880dd4 RR |
231 | //------------------------------------------------------------------------------- |
232 | // wxPostScriptDC | |
233 | //------------------------------------------------------------------------------- | |
234 | ||
b64de916 VS |
235 | float wxPostScriptDC::ms_PSScaleFactor = 10.0; |
236 | ||
237 | void wxPostScriptDC::SetResolution(int ppi) | |
238 | { | |
239 | ms_PSScaleFactor = (float)ppi / 72.0; | |
240 | } | |
241 | ||
242 | int wxPostScriptDC::GetResolution() | |
243 | { | |
244 | return (int)(ms_PSScaleFactor * 72.0); | |
245 | } | |
48c31b28 | 246 | |
b64de916 VS |
247 | |
248 | ||
ed880dd4 RR |
249 | wxPostScriptDC::wxPostScriptDC () |
250 | { | |
d7657f75 | 251 | m_pstream = (FILE*) NULL; |
afce4c03 | 252 | |
ed880dd4 RR |
253 | m_currentRed = 0; |
254 | m_currentGreen = 0; | |
255 | m_currentBlue = 0; | |
afce4c03 | 256 | |
ed880dd4 | 257 | m_pageNumber = 0; |
afce4c03 | 258 | |
ed880dd4 | 259 | m_clipping = FALSE; |
afce4c03 | 260 | |
ed880dd4 RR |
261 | m_underlinePosition = 0.0; |
262 | m_underlineThickness = 0.0; | |
263 | ||
264 | m_signX = 1; // default x-axis left to right | |
265 | m_signY = -1; // default y-axis bottom up -> top down | |
7bcb11d3 JS |
266 | |
267 | // Compatibility only | |
e6f1ad22 | 268 | // HH: Doesn't seem to work for wxMSW... |
c6eaa6fb | 269 | #if !defined(__WXMSW__) |
7bcb11d3 | 270 | m_printData = * wxThePrintSetupData; |
e6f1ad22 | 271 | #endif |
ed880dd4 RR |
272 | } |
273 | ||
274 | wxPostScriptDC::wxPostScriptDC (const wxString& file, bool interactive, wxWindow *parent) | |
275 | { | |
d7657f75 | 276 | m_pstream = (FILE*) NULL; |
afce4c03 | 277 | |
ed880dd4 RR |
278 | m_currentRed = 0; |
279 | m_currentGreen = 0; | |
280 | m_currentBlue = 0; | |
afce4c03 | 281 | |
ed880dd4 | 282 | m_pageNumber = 0; |
afce4c03 | 283 | |
ed880dd4 | 284 | m_clipping = FALSE; |
afce4c03 | 285 | |
ed880dd4 RR |
286 | m_underlinePosition = 0.0; |
287 | m_underlineThickness = 0.0; | |
288 | ||
289 | m_signX = 1; // default x-axis left to right | |
290 | m_signY = -1; // default y-axis bottom up -> top down | |
291 | ||
292 | Create(file, interactive, parent); | |
293 | } | |
294 | ||
295 | bool wxPostScriptDC::Create(const wxString& file, bool interactive, wxWindow *parent) | |
296 | { | |
297 | m_isInteractive = interactive; | |
298 | ||
299 | m_title = ""; | |
7bcb11d3 | 300 | m_printData.SetFilename(file); |
ed880dd4 RR |
301 | |
302 | #ifdef __WXMSW__ | |
303 | // Can only send to file in Windows | |
7bcb11d3 | 304 | m_printData.SetPrintMode(wxPRINT_MODE_FILE); |
ed880dd4 RR |
305 | #endif |
306 | ||
307 | if (m_isInteractive) | |
308 | { | |
309 | if ((m_ok = PrinterDialog (parent) ) == FALSE) return FALSE; | |
310 | } | |
311 | else | |
312 | { | |
313 | m_ok = TRUE; | |
314 | } | |
afce4c03 | 315 | |
ed880dd4 RR |
316 | return m_ok; |
317 | } | |
318 | ||
7bcb11d3 JS |
319 | wxPostScriptDC::wxPostScriptDC (const wxPrintData& printData) |
320 | { | |
d7657f75 | 321 | m_pstream = (FILE*) NULL; |
7bcb11d3 JS |
322 | |
323 | m_currentRed = 0; | |
324 | m_currentGreen = 0; | |
325 | m_currentBlue = 0; | |
326 | ||
327 | m_pageNumber = 0; | |
328 | ||
329 | m_clipping = FALSE; | |
330 | ||
331 | m_underlinePosition = 0.0; | |
332 | m_underlineThickness = 0.0; | |
333 | ||
334 | m_signX = 1; // default x-axis left to right | |
335 | m_signY = -1; // default y-axis bottom up -> top down | |
336 | ||
337 | m_printData = printData; | |
75737d05 JS |
338 | |
339 | m_ok = TRUE; | |
7bcb11d3 JS |
340 | } |
341 | ||
ed880dd4 RR |
342 | wxPostScriptDC::~wxPostScriptDC () |
343 | { | |
d7657f75 RR |
344 | if (m_pstream) |
345 | { | |
346 | fclose( m_pstream ); | |
72cdf4c9 | 347 | m_pstream = (FILE*) NULL; |
d7657f75 | 348 | } |
ed880dd4 RR |
349 | } |
350 | ||
4bc67cc5 RR |
351 | bool wxPostScriptDC::Ok() const |
352 | { | |
ef539066 | 353 | return m_ok; |
4bc67cc5 | 354 | } |
afce4c03 | 355 | |
7bcb11d3 | 356 | // This dialog is deprecated now: use wxGenericPrintDialog or the printing framework |
ed880dd4 RR |
357 | bool wxPostScriptDC::PrinterDialog(wxWindow *parent) |
358 | { | |
afce4c03 | 359 | wxPostScriptPrintDialog dialog( parent, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), |
ed880dd4 RR |
360 | wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL ); |
361 | m_ok = (dialog.ShowModal () == wxID_OK); | |
362 | ||
363 | if (!m_ok) return FALSE; | |
364 | ||
7bcb11d3 JS |
365 | if ((m_printData.GetFilename() == "") && |
366 | (m_printData.GetPrintMode() == wxPRINT_MODE_PREVIEW || | |
367 | m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER)) | |
ed880dd4 RR |
368 | { |
369 | // steve, 05.09.94 | |
370 | #ifdef __VMS__ | |
7bcb11d3 | 371 | m_printData.SetFilename("preview"); |
ed880dd4 RR |
372 | #else |
373 | // For PS_PRINTER action this depends on a Unix-style print spooler | |
374 | // since the wx_printer_file can be destroyed during a session | |
375 | // @@@ TODO: a Windows-style answer for non-Unix | |
87138c52 | 376 | wxChar userId[256]; |
ed880dd4 | 377 | wxGetUserId (userId, sizeof (userId) / sizeof (char)); |
87138c52 | 378 | wxChar tmp[256]; |
223d09f6 | 379 | wxStrcpy (tmp, wxT("/tmp/preview_")); |
87138c52 | 380 | wxStrcat (tmp, userId); |
7bcb11d3 | 381 | m_printData.SetFilename(tmp); |
ed880dd4 | 382 | #endif |
87138c52 OK |
383 | wxChar tmp2[256]; |
384 | wxStrcpy(tmp2, m_printData.GetFilename()); | |
223d09f6 | 385 | wxStrcat (tmp2, wxT(".ps")); |
7bcb11d3 | 386 | m_printData.SetFilename(tmp2); |
ed880dd4 | 387 | } |
223d09f6 | 388 | else if ((m_printData.GetFilename() == wxT("")) && (m_printData.GetPrintMode() == wxPRINT_MODE_FILE)) |
ed880dd4 | 389 | { |
223d09f6 | 390 | wxString file = wxSaveFileSelector (_("PostScript"), wxT("ps")); |
ba681060 | 391 | if ( file.IsEmpty() ) |
ed880dd4 RR |
392 | { |
393 | m_ok = FALSE; | |
394 | return FALSE; | |
395 | } | |
ba681060 | 396 | |
7bcb11d3 | 397 | m_printData.SetFilename(file); |
ed880dd4 RR |
398 | m_ok = TRUE; |
399 | } | |
400 | ||
4bc67cc5 | 401 | return m_ok; |
ed880dd4 RR |
402 | } |
403 | ||
72cdf4c9 | 404 | void wxPostScriptDC::DoSetClippingRegion (wxCoord x, wxCoord y, wxCoord w, wxCoord h) |
ed880dd4 | 405 | { |
223d09f6 | 406 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); |
afce4c03 | 407 | |
7087444f | 408 | if (m_clipping) DestroyClippingRegion(); |
ed880dd4 | 409 | |
7087444f | 410 | wxDC::DoSetClippingRegion(x, y, w, h); |
afce4c03 | 411 | |
ed880dd4 | 412 | m_clipping = TRUE; |
72cdf4c9 | 413 | fprintf( m_pstream, |
d7657f75 | 414 | "gsave\n newpath\n" |
72cdf4c9 VZ |
415 | "%d %d moveto\n" |
416 | "%d %d lineto\n" | |
417 | "%d %d lineto\n" | |
418 | "%d %d lineto\n" | |
419 | "closepath clip newpath\n", | |
6a7b1d6e RD |
420 | LogicalToDeviceX(x), LogicalToDeviceY(y), |
421 | LogicalToDeviceX(x+w), LogicalToDeviceY(y), | |
422 | LogicalToDeviceX(x+w), LogicalToDeviceY(y+h), | |
423 | LogicalToDeviceX(x), LogicalToDeviceY(y+h) ); | |
ed880dd4 RR |
424 | } |
425 | ||
ed880dd4 RR |
426 | |
427 | void wxPostScriptDC::DestroyClippingRegion() | |
428 | { | |
223d09f6 | 429 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); |
afce4c03 | 430 | |
ed880dd4 RR |
431 | if (m_clipping) |
432 | { | |
433 | m_clipping = FALSE; | |
72cdf4c9 | 434 | fprintf( m_pstream, "grestore\n" ); |
ed880dd4 | 435 | } |
004fd0c8 | 436 | |
7087444f | 437 | wxDC::DestroyClippingRegion(); |
ed880dd4 RR |
438 | } |
439 | ||
440 | void wxPostScriptDC::Clear() | |
441 | { | |
223d09f6 | 442 | wxFAIL_MSG( wxT("wxPostScriptDC::Clear not implemented.") ); |
ed880dd4 RR |
443 | } |
444 | ||
387ebd3e | 445 | bool wxPostScriptDC::DoFloodFill (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour &WXUNUSED(col), int WXUNUSED(style)) |
ed880dd4 | 446 | { |
223d09f6 | 447 | wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") ); |
387ebd3e | 448 | return FALSE; |
ed880dd4 RR |
449 | } |
450 | ||
72cdf4c9 | 451 | bool 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 | 457 | void wxPostScriptDC::DoCrossHair (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) |
ed880dd4 | 458 | { |
223d09f6 | 459 | wxFAIL_MSG( wxT("wxPostScriptDC::CrossHair not implemented.") ); |
ed880dd4 RR |
460 | } |
461 | ||
72cdf4c9 | 462 | void 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", | |
6a7b1d6e RD |
475 | LogicalToDeviceX(x1), LogicalToDeviceY(y1), |
476 | LogicalToDeviceX(x2), LogicalToDeviceY (y2) ); | |
afce4c03 | 477 | |
ed880dd4 RR |
478 | CalcBoundingBox( x1, y1 ); |
479 | CalcBoundingBox( x2, y2 ); | |
480 | } | |
481 | ||
482 | #define RAD2DEG 57.29577951308 | |
483 | ||
72cdf4c9 | 484 | void 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", | |
6a7b1d6e RD |
526 | LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2, |
527 | LogicalToDeviceX(xc), LogicalToDeviceY(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", | |
6a7b1d6e RD |
543 | LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2, |
544 | LogicalToDeviceX(xc), LogicalToDeviceY(yc) ); | |
d7657f75 RR |
545 | |
546 | CalcBoundingBox( xc-radius, yc-radius ); | |
547 | CalcBoundingBox( xc+radius, yc+radius ); | |
ed880dd4 | 548 | } |
ed880dd4 RR |
549 | } |
550 | ||
72cdf4c9 | 551 | void 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", | |
6a7b1d6e | 573 | LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2), LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2), (wxCoord)sa, (wxCoord)ea ); |
72cdf4c9 | 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", | |
6a7b1d6e | 586 | LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2), LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2), (wxCoord)sa, (wxCoord)ea ); |
72cdf4c9 | 587 | |
d7657f75 | 588 | CalcBoundingBox( x ,y ); |
ed880dd4 RR |
589 | CalcBoundingBox( x+w, y+h ); |
590 | } | |
591 | } | |
592 | ||
72cdf4c9 | 593 | void 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", | |
6a7b1d6e RD |
606 | LogicalToDeviceX(x), LogicalToDeviceY(y), |
607 | LogicalToDeviceX(x+1), LogicalToDeviceY(y) ); | |
afce4c03 | 608 | |
ed880dd4 RR |
609 | CalcBoundingBox( x, y ); |
610 | } | |
611 | ||
72cdf4c9 | 612 | void 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 | |
6a7b1d6e RD |
624 | wxCoord xx = LogicalToDeviceX(points[0].x + xoffset); |
625 | wxCoord yy = LogicalToDeviceY(points[0].y + yoffset); | |
72cdf4c9 VZ |
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 | { | |
6a7b1d6e RD |
633 | xx = LogicalToDeviceX(points[i].x + xoffset); |
634 | yy = LogicalToDeviceY(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 | |
6a7b1d6e RD |
650 | wxCoord xx = LogicalToDeviceX(points[0].x + xoffset); |
651 | wxCoord yy = LogicalToDeviceY(points[0].y + yoffset); | |
72cdf4c9 VZ |
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 | { | |
6a7b1d6e RD |
659 | xx = LogicalToDeviceX(points[i].x + xoffset); |
660 | yy = LogicalToDeviceY(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 | 672 | void 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 | { |
6a7b1d6e | 685 | CalcBoundingBox( LogicalToDeviceX(points[i].x+xoffset), LogicalToDeviceY(points[i].y+yoffset)); |
ed880dd4 RR |
686 | } |
687 | ||
d7657f75 RR |
688 | fprintf( m_pstream, |
689 | "newpath\n" | |
72cdf4c9 | 690 | "%d %d moveto\n", |
6a7b1d6e | 691 | LogicalToDeviceX(points[0].x+xoffset), LogicalToDeviceY(points[0].y+yoffset) ); |
afce4c03 VZ |
692 | |
693 | for (i = 1; i < n; i++) | |
ed880dd4 | 694 | { |
d7657f75 | 695 | fprintf( m_pstream, |
72cdf4c9 | 696 | "%d %d lineto\n", |
6a7b1d6e | 697 | LogicalToDeviceX(points[i].x+xoffset), LogicalToDeviceY(points[i].y+yoffset) ); |
ed880dd4 | 698 | } |
afce4c03 | 699 | |
d7657f75 | 700 | fprintf( m_pstream, "stroke\n" ); |
ed880dd4 RR |
701 | } |
702 | ||
72cdf4c9 | 703 | void 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", | |
6a7b1d6e RD |
719 | LogicalToDeviceX(x), LogicalToDeviceY(y), |
720 | LogicalToDeviceX(x + width), LogicalToDeviceY(y), | |
721 | LogicalToDeviceX(x + width), LogicalToDeviceY(y + height), | |
722 | LogicalToDeviceX(x), LogicalToDeviceY(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", | |
6a7b1d6e RD |
740 | LogicalToDeviceX(x), LogicalToDeviceY(y), |
741 | LogicalToDeviceX(x + width), LogicalToDeviceY(y), | |
742 | LogicalToDeviceX(x + width), LogicalToDeviceY(y + height), | |
743 | LogicalToDeviceX(x), LogicalToDeviceY(y + height) ); | |
72cdf4c9 | 744 | |
ed880dd4 RR |
745 | CalcBoundingBox( x, y ); |
746 | CalcBoundingBox( x + width, y + height ); | |
747 | } | |
748 | } | |
749 | ||
72cdf4c9 | 750 | void 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", | |
6a7b1d6e RD |
785 | LogicalToDeviceX(x + rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad), |
786 | LogicalToDeviceX(x), LogicalToDeviceY(y + rad), | |
787 | LogicalToDeviceX(x + rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad), | |
788 | LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height), | |
789 | LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad), | |
790 | LogicalToDeviceX(x + width), LogicalToDeviceY(y + rad), | |
791 | LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad), | |
792 | LogicalToDeviceX(x + rad), LogicalToDeviceY(y) ); | |
ed880dd4 RR |
793 | |
794 | CalcBoundingBox( x, y ); | |
795 | CalcBoundingBox( x + width, y + height ); | |
796 | } | |
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", | |
6a7b1d6e RD |
815 | LogicalToDeviceX(x + rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad), |
816 | LogicalToDeviceX(x), LogicalToDeviceY(y + rad), | |
817 | LogicalToDeviceX(x + rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad), | |
818 | LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height), | |
819 | LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad), | |
820 | LogicalToDeviceX(x + width), LogicalToDeviceY(y + rad), | |
821 | LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad), | |
822 | LogicalToDeviceX(x + rad), LogicalToDeviceY(y) ); | |
ed880dd4 RR |
823 | |
824 | CalcBoundingBox( x, y ); | |
825 | CalcBoundingBox( x + width, y + height ); | |
826 | } | |
827 | } | |
828 | ||
72cdf4c9 | 829 | void 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", | |
6a7b1d6e RD |
841 | LogicalToDeviceX(x + width / 2), LogicalToDeviceY(y + height / 2), |
842 | LogicalToDeviceXRel(width / 2), LogicalToDeviceYRel(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", | |
6a7b1d6e RD |
856 | LogicalToDeviceX(x + width / 2), LogicalToDeviceY(y + height / 2), |
857 | LogicalToDeviceXRel(width / 2), LogicalToDeviceYRel(height / 2) ); | |
ed880dd4 RR |
858 | |
859 | CalcBoundingBox( x - width, y - height ); | |
860 | CalcBoundingBox( x + width, y + height ); | |
861 | } | |
862 | } | |
863 | ||
72cdf4c9 | 864 | void 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 */ |
870 | static char hexArray[] = "0123456789ABCDEF"; | |
871 | static 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 | 880 | void 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 | |
368d59f0 | 886 | wxImage image = bitmap.ConvertToImage(); |
afce4c03 | 887 | |
ef539066 | 888 | if (!image.Ok()) return; |
afce4c03 | 889 | |
b64de916 VS |
890 | wxCoord w = image.GetWidth(); |
891 | wxCoord h = image.GetHeight(); | |
892 | ||
6a7b1d6e RD |
893 | wxCoord ww = LogicalToDeviceXRel(image.GetWidth()); |
894 | wxCoord hh = LogicalToDeviceYRel(image.GetHeight()); | |
afce4c03 | 895 | |
6a7b1d6e RD |
896 | wxCoord xx = LogicalToDeviceX(x); |
897 | wxCoord yy = LogicalToDeviceY(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 | 934 | void 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]; |
6a7b1d6e | 1019 | sprintf( buffer, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font.GetPointSize() * 1000) / 1000.0F); |
ce7f10f2 | 1020 | // this is a hack - we must scale font size (in pts) according to m_scaleY but |
6a7b1d6e | 1021 | // LogicalToDeviceYRel 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 | ||
1028 | void 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__ | |
6a7b1d6e | 1041 | sprintf( buffer, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen.GetWidth()) / 1000.0f ); |
f6bcfd97 | 1042 | #else |
6a7b1d6e | 1043 | sprintf( buffer, "%f setlinewidth\n", LogicalToDeviceXRel(1000 * m_pen.GetWidth()) / 1000.0f ); |
f6bcfd97 BP |
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 | ||
1124 | void 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 | ||
46eed000 RR |
1171 | #ifdef __WXGTK20__ |
1172 | ||
1173 | #include "wx/gtk/private.h" | |
1174 | #include "wx/fontutil.h" | |
1175 | #include "gtk/gtk.h" | |
1176 | #include <pango/pangoft2.h> | |
1177 | ||
1178 | #endif | |
1179 | ||
72cdf4c9 | 1180 | void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) |
ed880dd4 | 1181 | { |
223d09f6 | 1182 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); |
479cd5de | 1183 | |
4e8e547c | 1184 | #ifdef __WXGTK20__ |
46eed000 | 1185 | |
4e8e547c | 1186 | PangoContext *context = pango_ft2_get_context (300, 300); |
46eed000 RR |
1187 | |
1188 | // What are these for? | |
1189 | pango_context_set_language (context, pango_language_from_string ("en_US")); | |
1190 | pango_context_set_base_dir (context, PANGO_DIRECTION_LTR ); | |
1191 | ||
1192 | // Set the font | |
1193 | pango_context_set_font_description (context, m_font.GetNativeFontInfo()->description ); | |
1194 | ||
1195 | // Create layout | |
1196 | PangoLayout *layout = layout = pango_layout_new (context); | |
1197 | #if wxUSE_UNICODE | |
1198 | wxCharBuffer buffer = wxConvUTF8.cWC2MB( text ); | |
1199 | #else | |
1200 | wxCharBuffer buffer = wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ); | |
1201 | #endif | |
1202 | pango_layout_set_text( layout, (const char*) buffer, strlen(buffer) ); | |
1203 | ||
1204 | // Find out extent for the bitmap | |
1205 | int height = 0; | |
1206 | int width = 0; | |
1207 | PangoRectangle logical_rect; | |
1208 | pango_layout_get_extents (layout, NULL, &logical_rect); | |
1209 | height = PANGO_PIXELS (logical_rect.height); | |
1210 | width = PANGO_PIXELS (logical_rect.width); | |
4e8e547c RR |
1211 | |
1212 | // printf( "h %d w %d lh %d lw %d\n", height, width, logical_rect.height, logical_rect.width ); | |
46eed000 RR |
1213 | |
1214 | // Allocate FreeType 2 bitmap | |
1215 | int byte_width = (width + 7)/8 * 8; | |
1216 | FT_Bitmap bitmap; | |
1217 | guchar *buf = (guchar*) g_malloc (byte_width * height); | |
1218 | memset (buf, 0x00, byte_width * height); | |
1219 | bitmap.rows = height; | |
1220 | bitmap.width = byte_width; | |
1221 | bitmap.pitch = byte_width; | |
1222 | bitmap.buffer = buf; | |
1223 | bitmap.num_grays = 256; | |
1224 | bitmap.pixel_mode = ft_pixel_mode_grays; | |
1225 | ||
1226 | // Render bitmap | |
1227 | pango_ft2_render_layout (&bitmap, layout, 0, 0); | |
1228 | ||
1229 | // Invert bitmap to get black text on white background | |
1230 | for (int pix_idx = 0; pix_idx < width * height; pix_idx++) | |
1231 | buf[pix_idx] = 255-buf[pix_idx]; | |
1232 | ||
1233 | // Write PS output | |
1234 | wxCoord xx = LogicalToDeviceX(x); | |
1235 | wxCoord yy = LogicalToDeviceY(y /*+ bitmap.GetHeight()*/ ); | |
1236 | ||
1237 | fprintf(m_pstream, "gsave\n"); | |
1238 | fprintf(m_pstream, "%d %d translate\n", xx, yy); | |
1239 | fprintf(m_pstream, "/img_width %d def\n", bitmap.width); | |
1240 | fprintf(m_pstream, "/img_height %d def\n", bitmap.rows); | |
1241 | fprintf(m_pstream, "/picstr img_width 8 idiv string def\n"); | |
1242 | ||
1243 | fprintf(m_pstream, | |
4e8e547c RR |
1244 | " img_width 72 15 div mul\n" |
1245 | " img_height 72 15 div mul scale\n" | |
46eed000 RR |
1246 | " 0 setgray\n" |
1247 | " img_width img_height\n" | |
1248 | " true\n" | |
1249 | " [img_width 0 0 img_height neg 0 img_height 0.67 mul]\n" | |
1250 | " { currentfile\n" | |
1251 | " picstr readhexstring pop }\n" | |
1252 | " imagemask" | |
1253 | ); | |
1254 | ||
1255 | ||
1256 | for (int b_idx= 0; b_idx < bitmap.width/8 * bitmap.rows; b_idx++) | |
1257 | { | |
1258 | guchar packed_b = 0; | |
1259 | int bit_idx; | |
1260 | ||
1261 | if (b_idx % (bitmap.width/8) == 0) | |
1262 | fprintf(m_pstream, "\n"); | |
1263 | ||
1264 | for (bit_idx = 0; bit_idx < 8; bit_idx++) | |
1265 | { | |
4e8e547c | 1266 | guchar this_bit = bitmap.buffer[b_idx * 8+bit_idx]<128; |
46eed000 RR |
1267 | packed_b = (packed_b << 1) + this_bit; |
1268 | } | |
1269 | ||
1270 | ||
1271 | fprintf(m_pstream, "%02x", packed_b); | |
1272 | } | |
1273 | ||
1274 | fprintf(m_pstream, "\ngrestore\n" ); | |
1275 | ||
1276 | ||
1277 | // Free memory | |
1278 | g_free( buf ); | |
1279 | ||
1280 | #else | |
6c3d9ced | 1281 | wxCoord text_w, text_h, text_descent; |
479cd5de | 1282 | |
6c3d9ced | 1283 | GetTextExtent(text, &text_w, &text_h, &text_descent); |
afce4c03 | 1284 | |
080b749f VZ |
1285 | // VZ: this seems to be unnecessary, so taking it out for now, if it |
1286 | // doesn't create any problems, remove this comment entirely | |
1287 | //SetFont( m_font ); | |
ed880dd4 | 1288 | |
d7657f75 | 1289 | if (m_textForegroundColour.Ok()) |
ed880dd4 | 1290 | { |
d7657f75 RR |
1291 | unsigned char red = m_textForegroundColour.Red(); |
1292 | unsigned char blue = m_textForegroundColour.Blue(); | |
1293 | unsigned char green = m_textForegroundColour.Green(); | |
ed880dd4 RR |
1294 | |
1295 | if (!m_colour) | |
9a6be59a | 1296 | { |
d7657f75 | 1297 | // Anything not white is black |
72cdf4c9 VZ |
1298 | if (! (red == (unsigned char) 255 && |
1299 | blue == (unsigned char) 255 && | |
1300 | green == (unsigned char) 255)) | |
d7657f75 RR |
1301 | { |
1302 | red = (unsigned char) 0; | |
1303 | green = (unsigned char) 0; | |
1304 | blue = (unsigned char) 0; | |
1305 | } | |
9a6be59a | 1306 | } |
afce4c03 | 1307 | |
d7657f75 | 1308 | // maybe setgray here ? |
ed880dd4 RR |
1309 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) |
1310 | { | |
d7657f75 RR |
1311 | double redPS = (double)(red) / 255.0; |
1312 | double bluePS = (double)(blue) / 255.0; | |
1313 | double greenPS = (double)(green) / 255.0; | |
72cdf4c9 | 1314 | |
f6bcfd97 BP |
1315 | char buffer[100]; |
1316 | sprintf( buffer, | |
1317 | "%.8f %.8f %.8f setrgbcolor\n", | |
1318 | redPS, greenPS, bluePS ); | |
1319 | for (int i = 0; i < 100; i++) | |
3ca6a5f0 | 1320 | if (buffer[i] == ',') buffer[i] = '.'; |
f6bcfd97 | 1321 | fprintf( m_pstream, buffer ); |
72cdf4c9 | 1322 | |
ed880dd4 RR |
1323 | m_currentRed = red; |
1324 | m_currentBlue = blue; | |
1325 | m_currentGreen = green; | |
1326 | } | |
1327 | } | |
1328 | ||
1329 | int size = m_font.GetPointSize(); | |
1330 | ||
6c3d9ced VS |
1331 | // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline |
1332 | // commented by V. Slavik and replaced by accurate version | |
1333 | // - note that there is still rounding error in text_descent! | |
1334 | wxCoord by = y + size - text_descent; // baseline | |
6a7b1d6e | 1335 | fprintf( m_pstream, "%d %d moveto\n", LogicalToDeviceX(x), LogicalToDeviceY(by) ); |
afce4c03 | 1336 | |
d7657f75 | 1337 | fprintf( m_pstream, "(" ); |
9626e0bf | 1338 | const wxWX2MBbuf textbuf = text.mb_str(); |
b2abc293 VS |
1339 | size_t len = strlen(textbuf); |
1340 | size_t i; | |
ed880dd4 RR |
1341 | for (i = 0; i < len; i++) |
1342 | { | |
87138c52 | 1343 | int c = (unsigned char) textbuf[i]; |
d7657f75 | 1344 | if (c == ')' || c == '(' || c == '\\') |
ed880dd4 | 1345 | { |
d7657f75 | 1346 | /* Cope with special characters */ |
72cdf4c9 | 1347 | fprintf( m_pstream, "\\" ); |
2d5e89e1 | 1348 | fputc(c, m_pstream); |
ed880dd4 RR |
1349 | } |
1350 | else if ( c >= 128 ) | |
1351 | { | |
d7657f75 | 1352 | /* Cope with character codes > 127 */ |
72cdf4c9 | 1353 | fprintf(m_pstream, "\\%o", c); |
ed880dd4 RR |
1354 | } |
1355 | else | |
72cdf4c9 | 1356 | { |
2d5e89e1 | 1357 | fputc(c, m_pstream); |
72cdf4c9 | 1358 | } |
ed880dd4 | 1359 | } |
72cdf4c9 | 1360 | |
d7657f75 | 1361 | fprintf( m_pstream, ") show\n" ); |
ed880dd4 RR |
1362 | |
1363 | if (m_font.GetUnderlined()) | |
1364 | { | |
72cdf4c9 | 1365 | wxCoord uy = (wxCoord)(y + size - m_underlinePosition); |
f6bcfd97 | 1366 | char buffer[100]; |
afce4c03 | 1367 | |
f6bcfd97 | 1368 | sprintf( buffer, |
72cdf4c9 VZ |
1369 | "gsave\n" |
1370 | "%d %d moveto\n" | |
f6bcfd97 | 1371 | "%f setlinewidth\n" |
72cdf4c9 VZ |
1372 | "%d %d lineto\n" |
1373 | "stroke\n" | |
1374 | "grestore\n", | |
6a7b1d6e | 1375 | LogicalToDeviceX(x), LogicalToDeviceY(uy), |
f6bcfd97 | 1376 | m_underlineThickness, |
6a7b1d6e | 1377 | LogicalToDeviceX(x + text_w), LogicalToDeviceY(uy) ); |
f6bcfd97 | 1378 | for (i = 0; i < 100; i++) |
3ca6a5f0 | 1379 | if (buffer[i] == ',') buffer[i] = '.'; |
f6bcfd97 | 1380 | fprintf( m_pstream, buffer ); |
ed880dd4 | 1381 | } |
afce4c03 | 1382 | |
ed880dd4 RR |
1383 | CalcBoundingBox( x, y ); |
1384 | CalcBoundingBox( x + size * text.Length() * 2/3 , y ); | |
46eed000 | 1385 | #endif |
ed880dd4 RR |
1386 | } |
1387 | ||
95724b1a VZ |
1388 | void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle ) |
1389 | { | |
1390 | if (angle == 0.0) | |
1391 | { | |
1392 | DoDrawText(text, x, y); | |
1393 | return; | |
1394 | } | |
1395 | ||
1396 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); | |
1397 | ||
1398 | SetFont( m_font ); | |
1399 | ||
1400 | if (m_textForegroundColour.Ok()) | |
1401 | { | |
1402 | unsigned char red = m_textForegroundColour.Red(); | |
1403 | unsigned char blue = m_textForegroundColour.Blue(); | |
1404 | unsigned char green = m_textForegroundColour.Green(); | |
1405 | ||
1406 | if (!m_colour) | |
1407 | { | |
1408 | // Anything not white is black | |
479cd5de VZ |
1409 | if (! (red == (unsigned char) 255 && |
1410 | blue == (unsigned char) 255 && | |
1411 | green == (unsigned char) 255)) | |
95724b1a VZ |
1412 | { |
1413 | red = (unsigned char) 0; | |
1414 | green = (unsigned char) 0; | |
1415 | blue = (unsigned char) 0; | |
1416 | } | |
1417 | } | |
1418 | ||
1419 | // maybe setgray here ? | |
1420 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1421 | { | |
1422 | double redPS = (double)(red) / 255.0; | |
1423 | double bluePS = (double)(blue) / 255.0; | |
1424 | double greenPS = (double)(green) / 255.0; | |
479cd5de | 1425 | |
f6bcfd97 BP |
1426 | char buffer[100]; |
1427 | sprintf( buffer, | |
1428 | "%.8f %.8f %.8f setrgbcolor\n", | |
1429 | redPS, greenPS, bluePS ); | |
1430 | for (int i = 0; i < 100; i++) | |
3ca6a5f0 | 1431 | if (buffer[i] == ',') buffer[i] = '.'; |
f6bcfd97 | 1432 | fprintf( m_pstream, buffer ); |
479cd5de | 1433 | |
95724b1a VZ |
1434 | m_currentRed = red; |
1435 | m_currentBlue = blue; | |
1436 | m_currentGreen = green; | |
1437 | } | |
1438 | } | |
1439 | ||
1440 | int size = m_font.GetPointSize(); | |
1441 | ||
1442 | long by = y + (long)floor( double(size) * 2.0 / 3.0 ); // approximate baseline | |
1443 | ||
70846f0a | 1444 | // FIXME only correct for 90 degrees |
06b466c7 | 1445 | fprintf(m_pstream, "%d %d moveto\n", |
6a7b1d6e | 1446 | LogicalToDeviceX((wxCoord)(x + size)), LogicalToDeviceY((wxCoord)by) ); |
3ca6a5f0 | 1447 | |
f6bcfd97 BP |
1448 | char buffer[100]; |
1449 | sprintf(buffer, "%.8f rotate\n", angle); | |
b2abc293 | 1450 | size_t i; |
f6bcfd97 | 1451 | for (i = 0; i < 100; i++) |
3ca6a5f0 | 1452 | if (buffer[i] == ',') buffer[i] = '.'; |
f6bcfd97 | 1453 | fprintf(m_pstream, buffer); |
95724b1a | 1454 | |
95724b1a VZ |
1455 | fprintf( m_pstream, "(" ); |
1456 | const wxWX2MBbuf textbuf = text.mb_str(); | |
b2abc293 | 1457 | size_t len = strlen(textbuf); |
95724b1a VZ |
1458 | for (i = 0; i < len; i++) |
1459 | { | |
1460 | int c = (unsigned char) textbuf[i]; | |
1461 | if (c == ')' || c == '(' || c == '\\') | |
1462 | { | |
1463 | /* Cope with special characters */ | |
479cd5de | 1464 | fprintf( m_pstream, "\\" ); |
2d5e89e1 | 1465 | fputc(c, m_pstream); |
95724b1a VZ |
1466 | } |
1467 | else if ( c >= 128 ) | |
1468 | { | |
1469 | /* Cope with character codes > 127 */ | |
479cd5de | 1470 | fprintf(m_pstream, "\\%o", c); |
95724b1a VZ |
1471 | } |
1472 | else | |
479cd5de | 1473 | { |
2d5e89e1 | 1474 | fputc(c, m_pstream); |
479cd5de | 1475 | } |
95724b1a | 1476 | } |
479cd5de | 1477 | |
95724b1a | 1478 | fprintf( m_pstream, ") show\n" ); |
3ca6a5f0 | 1479 | |
f6bcfd97 BP |
1480 | sprintf( buffer, "%.8f rotate\n", -angle ); |
1481 | for (i = 0; i < 100; i++) | |
3ca6a5f0 | 1482 | if (buffer[i] == ',') buffer[i] = '.'; |
f6bcfd97 | 1483 | fprintf( m_pstream, buffer ); |
95724b1a VZ |
1484 | |
1485 | if (m_font.GetUnderlined()) | |
1486 | { | |
06b466c7 VZ |
1487 | wxCoord uy = (wxCoord)(y + size - m_underlinePosition); |
1488 | wxCoord w, h; | |
f6bcfd97 | 1489 | char buffer[100]; |
95724b1a VZ |
1490 | GetTextExtent(text, &w, &h); |
1491 | ||
f6bcfd97 | 1492 | sprintf( buffer, |
70846f0a | 1493 | "gsave\n" |
479cd5de | 1494 | "%d %d moveto\n" |
f6bcfd97 | 1495 | "%f setlinewidth\n" |
70846f0a VZ |
1496 | "%d %d lineto\n" |
1497 | "stroke\n" | |
479cd5de | 1498 | "grestore\n", |
6a7b1d6e | 1499 | LogicalToDeviceX(x), LogicalToDeviceY(uy), |
f6bcfd97 | 1500 | m_underlineThickness, |
6a7b1d6e | 1501 | LogicalToDeviceX(x + w), LogicalToDeviceY(uy) ); |
f6bcfd97 | 1502 | for (i = 0; i < 100; i++) |
3ca6a5f0 | 1503 | if (buffer[i] == ',') buffer[i] = '.'; |
f6bcfd97 | 1504 | fprintf( m_pstream, buffer ); |
95724b1a VZ |
1505 | } |
1506 | ||
1507 | CalcBoundingBox( x, y ); | |
1508 | CalcBoundingBox( x + size * text.Length() * 2/3 , y ); | |
1509 | } | |
ed880dd4 RR |
1510 | |
1511 | void wxPostScriptDC::SetBackground (const wxBrush& brush) | |
1512 | { | |
1513 | m_backgroundBrush = brush; | |
1514 | } | |
1515 | ||
1516 | void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function)) | |
1517 | { | |
223d09f6 | 1518 | wxFAIL_MSG( wxT("wxPostScriptDC::SetLogicalFunction not implemented.") ); |
ed880dd4 RR |
1519 | } |
1520 | ||
64698f9a | 1521 | void wxPostScriptDC::DoDrawSpline( wxList *points ) |
ed880dd4 | 1522 | { |
223d09f6 | 1523 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); |
afce4c03 | 1524 | |
ed880dd4 RR |
1525 | SetPen( m_pen ); |
1526 | ||
1527 | double a, b, c, d, x1, y1, x2, y2, x3, y3; | |
1528 | wxPoint *p, *q; | |
1529 | ||
1530 | wxNode *node = points->First(); | |
1531 | p = (wxPoint *)node->Data(); | |
afce4c03 | 1532 | x1 = p->x; |
ed880dd4 RR |
1533 | y1 = p->y; |
1534 | ||
1535 | node = node->Next(); | |
1536 | p = (wxPoint *)node->Data(); | |
afce4c03 | 1537 | c = p->x; |
ed880dd4 RR |
1538 | d = p->y; |
1539 | x3 = a = (double)(x1 + c) / 2; | |
1540 | y3 = b = (double)(y1 + d) / 2; | |
1541 | ||
72cdf4c9 | 1542 | fprintf( m_pstream, |
d7657f75 | 1543 | "newpath\n" |
72cdf4c9 VZ |
1544 | "%d %d moveto\n" |
1545 | "%d %d lineto\n", | |
6a7b1d6e RD |
1546 | LogicalToDeviceX((wxCoord)x1), LogicalToDeviceY((wxCoord)y1), |
1547 | LogicalToDeviceX((wxCoord)x3), LogicalToDeviceY((wxCoord)y3) ); | |
afce4c03 | 1548 | |
72cdf4c9 VZ |
1549 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); |
1550 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
ed880dd4 RR |
1551 | |
1552 | while ((node = node->Next()) != NULL) | |
1553 | { | |
1554 | q = (wxPoint *)node->Data(); | |
1555 | ||
d7657f75 RR |
1556 | x1 = x3; |
1557 | y1 = y3; | |
1558 | x2 = c; | |
1559 | y2 = d; | |
1560 | c = q->x; | |
1561 | d = q->y; | |
ed880dd4 RR |
1562 | x3 = (double)(x2 + c) / 2; |
1563 | y3 = (double)(y2 + d) / 2; | |
72cdf4c9 VZ |
1564 | |
1565 | fprintf( m_pstream, | |
1566 | "%d %d %d %d %d %d DrawSplineSection\n", | |
6a7b1d6e RD |
1567 | LogicalToDeviceX((wxCoord)x1), LogicalToDeviceY((wxCoord)y1), |
1568 | LogicalToDeviceX((wxCoord)x2), LogicalToDeviceY((wxCoord)y2), | |
1569 | LogicalToDeviceX((wxCoord)x3), LogicalToDeviceY((wxCoord)y3) ); | |
72cdf4c9 VZ |
1570 | |
1571 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1572 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
ed880dd4 | 1573 | } |
afce4c03 | 1574 | |
72cdf4c9 VZ |
1575 | /* |
1576 | At this point, (x2,y2) and (c,d) are the position of the | |
1577 | next-to-last and last point respectively, in the point list | |
1578 | */ | |
ed880dd4 | 1579 | |
d7657f75 | 1580 | fprintf( m_pstream, |
72cdf4c9 VZ |
1581 | "%d %d lineto\n" |
1582 | "stroke\n", | |
6a7b1d6e | 1583 | LogicalToDeviceX((wxCoord)c), LogicalToDeviceY((wxCoord)d) ); |
ed880dd4 RR |
1584 | } |
1585 | ||
72cdf4c9 | 1586 | wxCoord wxPostScriptDC::GetCharWidth() const |
ed880dd4 RR |
1587 | { |
1588 | // Chris Breeze: reasonable approximation using wxMODERN/Courier | |
72cdf4c9 | 1589 | return (wxCoord) (GetCharHeight() * 72.0 / 120.0); |
ed880dd4 RR |
1590 | } |
1591 | ||
1592 | ||
1593 | void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
1594 | { | |
223d09f6 | 1595 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); |
afce4c03 | 1596 | |
ed880dd4 RR |
1597 | m_signX = (xLeftRight ? 1 : -1); |
1598 | m_signY = (yBottomUp ? 1 : -1); | |
afce4c03 | 1599 | |
004fd0c8 DW |
1600 | // FIXME there is no such function in MSW nor in OS2/PM |
1601 | #if !defined(__WXMSW__) && !defined(__WXPM__) | |
ed880dd4 | 1602 | ComputeScaleAndOrigin(); |
9a6be59a | 1603 | #endif |
ed880dd4 RR |
1604 | } |
1605 | ||
72cdf4c9 | 1606 | void wxPostScriptDC::SetDeviceOrigin( wxCoord x, wxCoord y ) |
ed880dd4 | 1607 | { |
223d09f6 | 1608 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); |
afce4c03 | 1609 | |
4bc67cc5 RR |
1610 | int h = 0; |
1611 | int w = 0; | |
1612 | GetSize( &w, &h ); | |
afce4c03 | 1613 | |
4bc67cc5 | 1614 | wxDC::SetDeviceOrigin( x, h-y ); |
ed880dd4 RR |
1615 | } |
1616 | ||
4e4ea166 | 1617 | void wxPostScriptDC::DoGetSize(int* width, int* height) const |
ed880dd4 | 1618 | { |
7bcb11d3 | 1619 | wxPaperSize id = m_printData.GetPaperId(); |
ed880dd4 | 1620 | |
7bcb11d3 | 1621 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id); |
afce4c03 | 1622 | |
7bcb11d3 | 1623 | if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); |
afce4c03 | 1624 | |
ac2def68 RR |
1625 | int w = 595; |
1626 | int h = 842; | |
ed880dd4 RR |
1627 | if (paper) |
1628 | { | |
ac2def68 RR |
1629 | w = paper->GetSizeDeviceUnits().x; |
1630 | h = paper->GetSizeDeviceUnits().y; | |
ed880dd4 | 1631 | } |
72cdf4c9 | 1632 | |
ac2def68 | 1633 | if (m_printData.GetOrientation() == wxLANDSCAPE) |
ed880dd4 | 1634 | { |
ac2def68 | 1635 | int tmp = w; |
72cdf4c9 VZ |
1636 | w = h; |
1637 | h = tmp; | |
ed880dd4 | 1638 | } |
72cdf4c9 | 1639 | |
b64de916 VS |
1640 | if (width) *width = (int)(w * ms_PSScaleFactor); |
1641 | if (height) *height = (int)(h * ms_PSScaleFactor); | |
ed880dd4 RR |
1642 | } |
1643 | ||
4e4ea166 | 1644 | void wxPostScriptDC::DoGetSizeMM(int *width, int *height) const |
ed880dd4 | 1645 | { |
7bcb11d3 JS |
1646 | wxPaperSize id = m_printData.GetPaperId(); |
1647 | ||
1648 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id); | |
afce4c03 | 1649 | |
7bcb11d3 JS |
1650 | if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); |
1651 | ||
ac2def68 RR |
1652 | int w = 210; |
1653 | int h = 297; | |
7bcb11d3 | 1654 | if (paper) |
ed880dd4 | 1655 | { |
ac2def68 RR |
1656 | w = paper->GetWidth() / 10; |
1657 | h = paper->GetHeight() / 10; | |
ed880dd4 | 1658 | } |
72cdf4c9 | 1659 | |
ac2def68 | 1660 | if (m_printData.GetOrientation() == wxLANDSCAPE) |
ed880dd4 | 1661 | { |
ac2def68 | 1662 | int tmp = w; |
72cdf4c9 VZ |
1663 | w = h; |
1664 | h = tmp; | |
ed880dd4 | 1665 | } |
72cdf4c9 | 1666 | |
ac2def68 RR |
1667 | if (width) *width = w; |
1668 | if (height) *height = h; | |
7bcb11d3 JS |
1669 | } |
1670 | ||
1671 | // Resolution in pixels per logical inch | |
1672 | wxSize wxPostScriptDC::GetPPI(void) const | |
1673 | { | |
48c31b28 | 1674 | return wxSize((int)(72 * ms_PSScaleFactor), |
b64de916 | 1675 | (int)(72 * ms_PSScaleFactor)); |
7bcb11d3 | 1676 | } |
ed880dd4 | 1677 | |
7bcb11d3 | 1678 | |
d7657f75 | 1679 | bool wxPostScriptDC::StartDoc( const wxString& message ) |
7bcb11d3 | 1680 | { |
223d09f6 | 1681 | wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") ); |
7bcb11d3 JS |
1682 | |
1683 | if (m_printData.GetFilename() == "") | |
1684 | { | |
1685 | wxString filename = wxGetTempFileName("ps"); | |
1686 | m_printData.SetFilename(filename); | |
7bcb11d3 | 1687 | } |
72cdf4c9 | 1688 | |
401eb3de | 1689 | m_pstream = wxFopen( m_printData.GetFilename().c_str(), wxT("w+") ); // FIXME: use fn_str() here under Unicode? |
7bcb11d3 | 1690 | |
d7657f75 | 1691 | if (!m_pstream) |
ed880dd4 | 1692 | { |
f6bcfd97 | 1693 | wxLogError( _("Cannot open file for PostScript printing!")); |
7bcb11d3 JS |
1694 | m_ok = FALSE; |
1695 | return FALSE; | |
ed880dd4 | 1696 | } |
afce4c03 | 1697 | |
ed880dd4 RR |
1698 | m_ok = TRUE; |
1699 | ||
d7657f75 RR |
1700 | fprintf( m_pstream, "%%%%BeginProlog\n" ); |
1701 | fprintf( m_pstream, wxPostScriptHeaderEllipse ); | |
1702 | fprintf( m_pstream, wxPostScriptHeaderEllipticArc ); | |
1703 | fprintf( m_pstream, wxPostScriptHeaderColourImage ); | |
1704 | fprintf( m_pstream, wxPostScriptHeaderReencodeISO1 ); | |
1705 | fprintf( m_pstream, wxPostScriptHeaderReencodeISO2 ); | |
1706 | if (wxPostScriptHeaderSpline) | |
1707 | fprintf( m_pstream, wxPostScriptHeaderSpline ); | |
1708 | fprintf( m_pstream, "%%%%EndProlog\n" ); | |
1709 | ||
ed880dd4 RR |
1710 | SetBrush( *wxBLACK_BRUSH ); |
1711 | SetPen( *wxBLACK_PEN ); | |
1712 | SetBackground( *wxWHITE_BRUSH ); | |
1713 | SetTextForeground( *wxBLACK ); | |
1714 | ||
1715 | // set origin according to paper size | |
1716 | SetDeviceOrigin( 0,0 ); | |
afce4c03 | 1717 | |
ed880dd4 RR |
1718 | wxPageNumber = 1; |
1719 | m_pageNumber = 1; | |
1720 | m_title = message; | |
1721 | return TRUE; | |
1722 | } | |
1723 | ||
1724 | void wxPostScriptDC::EndDoc () | |
1725 | { | |
223d09f6 | 1726 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); |
afce4c03 | 1727 | |
ed880dd4 RR |
1728 | if (m_clipping) |
1729 | { | |
1730 | m_clipping = FALSE; | |
72cdf4c9 | 1731 | fprintf( m_pstream, "grestore\n" ); |
ed880dd4 RR |
1732 | } |
1733 | ||
d7657f75 RR |
1734 | fclose( m_pstream ); |
1735 | m_pstream = (FILE *) NULL; | |
ed880dd4 | 1736 | |
87138c52 | 1737 | wxChar *header_file = wxGetTempFileName("ps"); |
afce4c03 | 1738 | |
d7657f75 | 1739 | m_pstream = fopen( wxConvFile.cWX2MB(header_file) , "w+" ); |
ed880dd4 | 1740 | |
d7657f75 | 1741 | fprintf( m_pstream, "%%!PS-Adobe-2.0\n" ); // PostScript magic strings |
aece0491 | 1742 | fprintf( m_pstream, "%%%%Title: %s\n", (const char *)m_title.mb_str() ); |
ac2def68 | 1743 | fprintf( m_pstream, "%%%%Creator: %s\n", (const char*)wxConvCurrent->cWX2MB(wxTheApp->argv[0]) ); |
aece0491 | 1744 | fprintf( m_pstream, "%%%%CreationDate: %s\n", (const char *)wxNow().mb_str() ); |
ed880dd4 | 1745 | |
87138c52 | 1746 | wxChar userID[256]; |
ed880dd4 RR |
1747 | if ( wxGetEmailAddress(userID, sizeof(userID)) ) |
1748 | { | |
e90c1d2a | 1749 | fprintf( m_pstream, "%%%%For: %s ", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userID) ); |
87138c52 | 1750 | wxChar userName[245]; |
ed880dd4 | 1751 | if (wxGetUserName(userName, sizeof(userName))) |
e90c1d2a | 1752 | fprintf( m_pstream, " (%s)", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userName) ); |
72cdf4c9 | 1753 | fprintf( m_pstream, "\n" ); |
ed880dd4 RR |
1754 | } |
1755 | else if ( wxGetUserName(userID, sizeof(userID)) ) | |
1756 | { | |
e90c1d2a | 1757 | fprintf( m_pstream, "%%%%For: %s\n", wxMBSTRINGCAST wxConvCurrent->cWX2MB(userID) );; |
ed880dd4 RR |
1758 | } |
1759 | ||
1760 | // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com> | |
1761 | ||
72cdf4c9 | 1762 | wxCoord wx_printer_translate_x, wx_printer_translate_y; |
ed880dd4 | 1763 | double wx_printer_scale_x, wx_printer_scale_y; |
ed880dd4 | 1764 | |
479cd5de VZ |
1765 | wx_printer_translate_x = (wxCoord)m_printData.GetPrinterTranslateX(); |
1766 | wx_printer_translate_y = (wxCoord)m_printData.GetPrinterTranslateY(); | |
7bcb11d3 JS |
1767 | |
1768 | wx_printer_scale_x = m_printData.GetPrinterScaleX(); | |
1769 | wx_printer_scale_y = m_printData.GetPrinterScaleY(); | |
1770 | ||
1771 | if (m_printData.GetOrientation() == wxLANDSCAPE) | |
d7657f75 | 1772 | fprintf( m_pstream, "%%%%Orientation: Landscape\n" ); |
ed880dd4 | 1773 | else |
d7657f75 | 1774 | fprintf( m_pstream, "%%%%Orientation: Portrait\n" ); |
ed880dd4 RR |
1775 | |
1776 | // Compute the bounding box. Note that it is in the default user | |
1777 | // coordinate system, thus we have to convert the values. | |
6a7b1d6e RD |
1778 | wxCoord minX = (wxCoord) LogicalToDeviceX(m_minX); |
1779 | wxCoord minY = (wxCoord) LogicalToDeviceY(m_minY); | |
1780 | wxCoord maxX = (wxCoord) LogicalToDeviceX(m_maxX); | |
1781 | wxCoord maxY = (wxCoord) LogicalToDeviceY(m_maxY); | |
48c31b28 | 1782 | |
a30f8da8 VS |
1783 | // LOG2DEV may have changed the minimum to maximum vice versa |
1784 | if ( minX > maxX ) { wxCoord tmp = minX; minX = maxX; maxX = tmp; } | |
1785 | if ( minY > maxY ) { wxCoord tmp = minY; minY = maxY; maxY = tmp; } | |
48c31b28 | 1786 | |
a30f8da8 VS |
1787 | // account for used scaling (boundingbox is before scaling in ps-file) |
1788 | double scale_x = m_printData.GetPrinterScaleX() / ms_PSScaleFactor; | |
1789 | double scale_y = m_printData.GetPrinterScaleY() / ms_PSScaleFactor; | |
48c31b28 VZ |
1790 | |
1791 | wxCoord llx, lly, urx, ury; | |
a30f8da8 VS |
1792 | llx = (wxCoord) ((minX+wx_printer_translate_x)*scale_x); |
1793 | lly = (wxCoord) ((minY+wx_printer_translate_y)*scale_y); | |
1794 | urx = (wxCoord) ((maxX+wx_printer_translate_x)*scale_x); | |
1795 | ury = (wxCoord) ((maxY+wx_printer_translate_y)*scale_y); | |
1796 | // (end of bounding box computation) | |
1797 | ||
ed880dd4 RR |
1798 | |
1799 | // If we're landscape, our sense of "x" and "y" is reversed. | |
7bcb11d3 | 1800 | if (m_printData.GetOrientation() == wxLANDSCAPE) |
ed880dd4 | 1801 | { |
72cdf4c9 | 1802 | wxCoord tmp; |
ed880dd4 RR |
1803 | tmp = llx; llx = lly; lly = tmp; |
1804 | tmp = urx; urx = ury; ury = tmp; | |
1805 | ||
1806 | // We need either the two lines that follow, or we need to subtract | |
1807 | // min_x from real_translate_y, which is commented out below. | |
72cdf4c9 VZ |
1808 | llx = llx - (wxCoord)(m_minX*wx_printer_scale_y); |
1809 | urx = urx - (wxCoord)(m_minX*wx_printer_scale_y); | |
ed880dd4 RR |
1810 | } |
1811 | ||
1812 | // The Adobe specifications call for integers; we round as to make | |
1813 | // the bounding larger. | |
72cdf4c9 VZ |
1814 | fprintf( m_pstream, |
1815 | "%%%%BoundingBox: %d %d %d %d\n", | |
1816 | (wxCoord)floor((double)llx), (wxCoord)floor((double)lly), | |
1817 | (wxCoord)ceil((double)urx), (wxCoord)ceil((double)ury) ); | |
d7657f75 RR |
1818 | fprintf( m_pstream, "%%%%Pages: %d\n", (wxPageNumber - 1) ); |
1819 | fprintf( m_pstream, "%%%%EndComments\n\n" ); | |
ed880dd4 RR |
1820 | |
1821 | // To check the correctness of the bounding box, postscript commands | |
1822 | // to draw a box corresponding to the bounding box are generated below. | |
1823 | // But since we typically don't want to print such a box, the postscript | |
1824 | // commands are generated within comments. These lines appear before any | |
1825 | // adjustment of scale, rotation, or translation, and hence are in the | |
1826 | // default user coordinates. | |
d7657f75 | 1827 | fprintf( m_pstream, "%% newpath\n" ); |
72cdf4c9 VZ |
1828 | fprintf( m_pstream, "%% %d %d moveto\n", llx, lly ); |
1829 | fprintf( m_pstream, "%% %d %d lineto\n", urx, lly ); | |
1830 | fprintf( m_pstream, "%% %d %d lineto\n", urx, ury ); | |
1831 | fprintf( m_pstream, "%% %d %d lineto closepath stroke\n", llx, ury ); | |
ed880dd4 | 1832 | |
d7657f75 RR |
1833 | fclose( m_pstream ); |
1834 | m_pstream = (FILE*) NULL; | |
ed880dd4 | 1835 | |
87138c52 | 1836 | wxChar *tmp_file = wxGetTempFileName("ps"); |
ed880dd4 RR |
1837 | |
1838 | // Paste header Before wx_printer_file | |
d7657f75 RR |
1839 | wxConcatFiles (header_file, m_printData.GetFilename(), tmp_file ); |
1840 | wxRemoveFile( header_file ); | |
1841 | wxRemoveFile( m_printData.GetFilename() ); | |
1842 | wxRenameFile( tmp_file, m_printData.GetFilename() ); | |
ed880dd4 RR |
1843 | |
1844 | #if defined(__X__) || defined(__WXGTK__) | |
d7657f75 | 1845 | if (m_ok) |
ed880dd4 | 1846 | { |
d7657f75 RR |
1847 | wxString previewCommand(m_printData.GetPreviewCommand()); |
1848 | wxString printerCommand(m_printData.GetPrinterCommand()); | |
1849 | wxString printerOptions(m_printData.GetPrinterOptions()); | |
1850 | wxString filename(m_printData.GetFilename()); | |
ed880dd4 | 1851 | |
72cdf4c9 VZ |
1852 | switch (m_printData.GetPrintMode()) |
1853 | { | |
d7657f75 RR |
1854 | case wxPRINT_MODE_PREVIEW: |
1855 | { | |
1856 | wxChar *argv[3]; | |
1857 | argv[0] = WXSTRINGCAST previewCommand; | |
1858 | argv[1] = WXSTRINGCAST filename; | |
1859 | argv[2] = (wxChar*) NULL; | |
401eb3de RR |
1860 | #if defined(__WXGTK20__) && wxUSE_UNICODE |
1861 | #else | |
d7657f75 | 1862 | wxExecute( argv, TRUE ); |
401eb3de | 1863 | #endif |
d7657f75 RR |
1864 | wxRemoveFile( m_printData.GetFilename() ); |
1865 | } | |
1866 | break; | |
1867 | case wxPRINT_MODE_PRINTER: | |
1868 | { | |
1869 | wxChar *argv[4]; | |
1870 | int argc = 0; | |
1871 | argv[argc++] = WXSTRINGCAST printerCommand; | |
1872 | ||
1873 | // !SM! If we simply assign to argv[1] here, if printer options | |
1874 | // are blank, we get an annoying and confusing message from lpr. | |
1875 | wxChar *opts = WXSTRINGCAST printerOptions; | |
1876 | if (opts && *opts) | |
1877 | argv[argc++] = opts; | |
1878 | ||
1879 | argv[argc++] = WXSTRINGCAST filename; | |
1880 | argv[argc++] = (wxChar *) NULL; | |
401eb3de RR |
1881 | #if defined(__WXGTK20__) && wxUSE_UNICODE |
1882 | #else | |
d7657f75 | 1883 | wxExecute( argv, TRUE ); |
401eb3de | 1884 | #endif |
d7657f75 RR |
1885 | wxRemoveFile( filename ); |
1886 | } | |
1887 | break; | |
1888 | case wxPRINT_MODE_FILE: | |
1889 | case wxPRINT_MODE_NONE: | |
1890 | break; | |
1891 | } | |
ed880dd4 RR |
1892 | } |
1893 | #endif | |
1894 | } | |
1895 | ||
d7657f75 | 1896 | void wxPostScriptDC::StartPage() |
ed880dd4 | 1897 | { |
223d09f6 | 1898 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); |
afce4c03 | 1899 | |
d7657f75 | 1900 | fprintf( m_pstream, "%%%%Page: %d\n", wxPageNumber++ ); |
afce4c03 | 1901 | |
ac2def68 | 1902 | // What is this one supposed to do? RR. |
ed880dd4 RR |
1903 | // *m_pstream << "matrix currentmatrix\n"; |
1904 | ||
1905 | // Added by Chris Breeze | |
1906 | ||
9a6be59a VZ |
1907 | // Each page starts with an "initgraphics" which resets the |
1908 | // transformation and so we need to reset the origin | |
1909 | // (and rotate the page for landscape printing) | |
afce4c03 | 1910 | |
afce4c03 | 1911 | // Output scaling |
72cdf4c9 | 1912 | wxCoord translate_x, translate_y; |
afce4c03 | 1913 | double scale_x, scale_y; |
afce4c03 | 1914 | |
479cd5de VZ |
1915 | translate_x = (wxCoord)m_printData.GetPrinterTranslateX(); |
1916 | translate_y = (wxCoord)m_printData.GetPrinterTranslateY(); | |
7bcb11d3 JS |
1917 | |
1918 | scale_x = m_printData.GetPrinterScaleX(); | |
1919 | scale_y = m_printData.GetPrinterScaleY(); | |
1920 | ||
1921 | if (m_printData.GetOrientation() == wxLANDSCAPE) | |
afce4c03 | 1922 | { |
ac2def68 RR |
1923 | int h; |
1924 | GetSize( (int*) NULL, &h ); | |
1925 | translate_y -= h; | |
1926 | fprintf( m_pstream, "90 rotate\n" ); | |
72cdf4c9 | 1927 | |
ac2def68 | 1928 | // I copied this one from a PostScript tutorial, but to no avail. RR. |
72cdf4c9 | 1929 | // fprintf( m_pstream, "90 rotate llx neg ury nef translate\n" ); |
afce4c03 VZ |
1930 | } |
1931 | ||
f6bcfd97 | 1932 | char buffer[100]; |
48c31b28 | 1933 | sprintf( buffer, "%.8f %.8f scale\n", scale_x / ms_PSScaleFactor, |
b64de916 | 1934 | scale_y / ms_PSScaleFactor); |
f6bcfd97 BP |
1935 | for (int i = 0; i < 100; i++) |
1936 | if (buffer[i] == ',') buffer[i] = '.'; | |
1937 | fprintf( m_pstream, buffer ); | |
3ca6a5f0 | 1938 | |
72cdf4c9 | 1939 | fprintf( m_pstream, "%d %d translate\n", translate_x, translate_y ); |
ed880dd4 RR |
1940 | } |
1941 | ||
1942 | void wxPostScriptDC::EndPage () | |
1943 | { | |
223d09f6 | 1944 | wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); |
afce4c03 | 1945 | |
d7657f75 | 1946 | fprintf( m_pstream, "showpage\n" ); |
ed880dd4 RR |
1947 | } |
1948 | ||
72cdf4c9 VZ |
1949 | bool wxPostScriptDC::DoBlit( wxCoord xdest, wxCoord ydest, |
1950 | wxCoord fwidth, wxCoord fheight, | |
afce4c03 | 1951 | wxDC *source, |
72cdf4c9 | 1952 | wxCoord xsrc, wxCoord ysrc, |
f0a6b1cd | 1953 | int rop, bool WXUNUSED(useMask), wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask) ) |
ed880dd4 | 1954 | { |
223d09f6 | 1955 | wxCHECK_MSG( m_ok && m_pstream, FALSE, wxT("invalid postscript dc") ); |
afce4c03 | 1956 | |
223d09f6 | 1957 | wxCHECK_MSG( source, FALSE, wxT("invalid source dc") ); |
afce4c03 | 1958 | |
342b6a2f | 1959 | /* blit into a bitmap */ |
afce4c03 | 1960 | wxBitmap bitmap( (int)fwidth, (int)fheight ); |
45b776d4 JS |
1961 | wxMemoryDC memDC; |
1962 | memDC.SelectObject(bitmap); | |
342b6a2f | 1963 | memDC.Blit(0, 0, fwidth, fheight, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ |
45b776d4 | 1964 | memDC.SelectObject(wxNullBitmap); |
ea6f44b5 RR |
1965 | |
1966 | /* draw bitmap. scaling and positioning is done there */ | |
ea6f44b5 | 1967 | DrawBitmap( bitmap, xdest, ydest ); |
afce4c03 | 1968 | |
ed880dd4 RR |
1969 | return TRUE; |
1970 | } | |
1971 | ||
72cdf4c9 | 1972 | wxCoord wxPostScriptDC::GetCharHeight() const |
ed880dd4 RR |
1973 | { |
1974 | if (m_font.Ok()) | |
b64de916 | 1975 | return m_font.GetPointSize(); |
ed880dd4 RR |
1976 | else |
1977 | return 12; | |
1978 | } | |
1979 | ||
72cdf4c9 VZ |
1980 | void wxPostScriptDC::DoGetTextExtent(const wxString& string, |
1981 | wxCoord *x, wxCoord *y, | |
1982 | wxCoord *descent, wxCoord *externalLeading, | |
1983 | wxFont *theFont ) const | |
ed880dd4 | 1984 | { |
36b3b54a | 1985 | wxFont *fontToUse = theFont; |
afce4c03 | 1986 | |
36b3b54a RR |
1987 | if (!fontToUse) fontToUse = (wxFont*) &m_font; |
1988 | ||
223d09f6 | 1989 | wxCHECK_RET( fontToUse, wxT("GetTextExtent: no font defined") ); |
87138c52 | 1990 | |
9626e0bf | 1991 | const wxWX2MBbuf strbuf = string.mb_str(); |
ed880dd4 | 1992 | |
f036b31c | 1993 | #if !wxUSE_AFM_FOR_POSTSCRIPT |
36b3b54a RR |
1994 | /* Provide a VERY rough estimate (avoid using it). |
1995 | * Produces accurate results for mono-spaced font | |
1996 | * such as Courier (aka wxMODERN) */ | |
afce4c03 | 1997 | |
9a6be59a VZ |
1998 | int height = 12; |
1999 | if (fontToUse) | |
2000 | { | |
afce4c03 | 2001 | height = fontToUse->GetPointSize(); |
9a6be59a | 2002 | } |
72cdf4c9 VZ |
2003 | if ( x ) |
2004 | *x = strlen (strbuf) * height * 72 / 120; | |
2005 | if ( y ) | |
2006 | *y = (wxCoord) (height * 1.32); /* allow for descender */ | |
36b3b54a RR |
2007 | if (descent) *descent = 0; |
2008 | if (externalLeading) *externalLeading = 0; | |
ed880dd4 | 2009 | #else |
ed880dd4 | 2010 | |
afce4c03 VZ |
2011 | /* method for calculating string widths in postscript: |
2012 | / read in the AFM (adobe font metrics) file for the | |
2013 | / actual font, parse it and extract the character widths | |
2014 | / and also the descender. this may be improved, but for now | |
2015 | / it works well. the AFM file is only read in if the | |
2016 | / font is changed. this may be chached in the future. | |
2017 | / calls to GetTextExtent with the font unchanged are rather | |
2018 | / efficient!!! | |
2019 | / | |
2020 | / for each font and style used there is an AFM file necessary. | |
2021 | / currently i have only files for the roman font family. | |
2022 | / I try to get files for the other ones! | |
2023 | / | |
2024 | / CAVE: the size of the string is currently always calculated | |
2025 | / in 'points' (1/72 of an inch). this should later on be | |
2026 | / changed to depend on the mapping mode. | |
2027 | / CAVE: the path to the AFM files must be set before calling this | |
2028 | / function. this is usually done by a call like the following: | |
2029 | / wxSetAFMPath("d:\\wxw161\\afm\\"); | |
2030 | / | |
2031 | / example: | |
2032 | / | |
2033 | / wxPostScriptDC dc(NULL, TRUE); | |
2034 | / if (dc.Ok()){ | |
2035 | / wxSetAFMPath("d:\\wxw161\\afm\\"); | |
2036 | / dc.StartDoc("Test"); | |
2037 | / dc.StartPage(); | |
72cdf4c9 | 2038 | / wxCoord w,h; |
afce4c03 VZ |
2039 | / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL)); |
2040 | / dc.GetTextExtent("Hallo",&w,&h); | |
2041 | / dc.EndPage(); | |
2042 | / dc.EndDoc(); | |
2043 | / } | |
2044 | / | |
2045 | / by steve (stefan.hammes@urz.uni-heidelberg.de) | |
2046 | / created: 10.09.94 | |
2047 | / updated: 14.05.95 */ | |
36b3b54a RR |
2048 | |
2049 | /* these static vars are for storing the state between calls */ | |
2050 | static int lastFamily= INT_MIN; | |
2051 | static int lastSize= INT_MIN; | |
2052 | static int lastStyle= INT_MIN; | |
2053 | static int lastWeight= INT_MIN; | |
2054 | static int lastDescender = INT_MIN; | |
2055 | static int lastWidths[256]; /* widths of the characters */ | |
72cdf4c9 | 2056 | |
a439ecef VS |
2057 | double UnderlinePosition = 0.0; |
2058 | double UnderlineThickness = 0.0; | |
36b3b54a RR |
2059 | |
2060 | /* get actual parameters */ | |
733b25e1 RR |
2061 | int Family = fontToUse->GetFamily(); |
2062 | int Size = fontToUse->GetPointSize(); | |
2063 | int Style = fontToUse->GetStyle(); | |
2064 | int Weight = fontToUse->GetWeight(); | |
36b3b54a RR |
2065 | |
2066 | /* if we have another font, read the font-metrics */ | |
2067 | if (Family!=lastFamily || Size!=lastSize || Style!=lastStyle || Weight!=lastWeight) | |
2068 | { | |
2069 | /* store actual values */ | |
2070 | lastFamily = Family; | |
2071 | lastSize = Size; | |
2072 | lastStyle = Style; | |
2073 | lastWeight = Weight; | |
2074 | ||
08a9473b | 2075 | const char *name = NULL; |
36b3b54a RR |
2076 | |
2077 | switch (Family) | |
afce4c03 VZ |
2078 | { |
2079 | case wxMODERN: | |
733b25e1 RR |
2080 | case wxTELETYPE: |
2081 | { | |
2082 | if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "CourBoO.afm"; | |
2083 | else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "CourBo.afm"; | |
2084 | else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "CourO.afm"; | |
2085 | else name = "Cour.afm"; | |
afce4c03 | 2086 | break; |
733b25e1 | 2087 | } |
afce4c03 | 2088 | case wxROMAN: |
733b25e1 RR |
2089 | { |
2090 | if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "TimesBoO.afm"; | |
2091 | else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "TimesBo.afm"; | |
2092 | else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "TimesO.afm"; | |
2093 | else name = "TimesRo.afm"; | |
afce4c03 | 2094 | break; |
733b25e1 RR |
2095 | } |
2096 | case wxSCRIPT: | |
2097 | { | |
2098 | name = "Zapf.afm"; | |
2099 | Style = wxNORMAL; | |
2100 | Weight = wxNORMAL; | |
2101 | } | |
2102 | case wxSWISS: | |
afce4c03 | 2103 | default: |
733b25e1 RR |
2104 | { |
2105 | if ((Style == wxITALIC) && (Weight == wxBOLD)) name = "HelvBoO.afm"; | |
2106 | else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = "HelvBo.afm"; | |
2107 | else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = "HelvO.afm"; | |
2108 | else name = "Helv.afm"; | |
afce4c03 | 2109 | break; |
733b25e1 | 2110 | } |
afce4c03 | 2111 | } |
36b3b54a RR |
2112 | |
2113 | /* get the directory of the AFM files */ | |
5558ce7c | 2114 | wxString afmName = wxEmptyString; |
72cdf4c9 VZ |
2115 | if (!m_printData.GetFontMetricPath().IsEmpty()) |
2116 | { | |
021e0f21 | 2117 | afmName = m_printData.GetFontMetricPath(); |
72cdf4c9 | 2118 | } |
36b3b54a | 2119 | |
afce4c03 VZ |
2120 | /* 2. open and process the file |
2121 | / a short explanation of the AFM format: | |
2122 | / we have for each character a line, which gives its size | |
2123 | / e.g.: | |
2124 | / | |
2125 | / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ; | |
2126 | / | |
2127 | / that means, we have a character with ascii code 63, and width | |
2128 | / (444/1000 * fontSize) points. | |
2129 | / the other data is ignored for now! | |
2130 | / | |
2131 | / when the font has changed, we read in the right AFM file and store the | |
2132 | / character widths in an array, which is processed below (see point 3.). */ | |
36b3b54a RR |
2133 | |
2134 | /* new elements JC Sun Aug 25 23:21:44 MET DST 1996 */ | |
2135 | ||
733b25e1 | 2136 | afmName << name; |
021e0f21 | 2137 | FILE *afmFile = wxFopen(afmName,wxT("r")); |
48c31b28 | 2138 | |
d361e74e KB |
2139 | if (afmFile==NULL) |
2140 | { | |
3e469ea3 | 2141 | afmName = wxThePrintSetupData->GetAFMPath(); |
733b25e1 | 2142 | afmName << wxFILE_SEP_PATH << name; |
021e0f21 | 2143 | afmFile = wxFopen(afmName,wxT("r")); |
d361e74e | 2144 | } |
72cdf4c9 | 2145 | |
733b25e1 | 2146 | #if defined(__UNIX__) && !defined(__VMS__) |
79a8a691 | 2147 | if (afmFile==NULL) |
5558ce7c VS |
2148 | /* please do NOT change the line above to "else if (afmFile==NULL)" - |
2149 | - afmFile = fopen() may fail and in that case the next if branch | |
2150 | MUST be executed - and it would not if there was "else" */ | |
3e469ea3 | 2151 | { |
2c18f21d | 2152 | afmName = wxGetDataDir(); |
3e469ea3 | 2153 | afmName << wxFILE_SEP_PATH |
733b25e1 RR |
2154 | #if defined(__LINUX__) || defined(__FREEBSD__) |
2155 | << wxT("gs_afm") << wxFILE_SEP_PATH | |
2156 | #else | |
021e0f21 | 2157 | << wxT("afm") << wxFILE_SEP_PATH |
733b25e1 RR |
2158 | #endif |
2159 | << name; | |
021e0f21 | 2160 | afmFile = wxFopen(afmName,wxT("r")); |
3e469ea3 | 2161 | } |
3e469ea3 | 2162 | #endif |
479cd5de | 2163 | |
385bcb35 | 2164 | if (afmFile==NULL) |
36b3b54a | 2165 | { |
ccbfa8ec | 2166 | wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName.c_str() ); |
48c31b28 | 2167 | wxLogDebug( wxT(" using approximate values")); |
36b3b54a RR |
2168 | for (int i=0; i<256; i++) lastWidths[i] = 500; /* an approximate value */ |
2169 | lastDescender = -150; /* dito. */ | |
ed880dd4 | 2170 | } |
afce4c03 VZ |
2171 | else |
2172 | { | |
36b3b54a RR |
2173 | /* init the widths array */ |
2174 | for(int i=0; i<256; i++) lastWidths[i] = INT_MIN; | |
2175 | /* some variables for holding parts of a line */ | |
2176 | char cString[10],semiString[10],WXString[10],descString[20]; | |
2177 | char upString[30], utString[30], encString[50]; | |
2178 | char line[256]; | |
2179 | int ascii,cWidth; | |
2180 | /* read in the file and parse it */ | |
2181 | while(fgets(line,sizeof(line),afmFile)!=NULL) | |
afce4c03 | 2182 | { |
36b3b54a | 2183 | /* A.) check for descender definition */ |
021e0f21 | 2184 | if (strncmp(line,"Descender",9)==0) |
afce4c03 | 2185 | { |
36b3b54a | 2186 | if ((sscanf(line,"%s%d",descString,&lastDescender)!=2) || |
021e0f21 | 2187 | (strcmp(descString,"Descender")!=0)) |
afce4c03 | 2188 | { |
ccbfa8ec | 2189 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName.c_str(),line ); |
36b3b54a RR |
2190 | } |
2191 | } | |
2192 | /* JC 1.) check for UnderlinePosition */ | |
021e0f21 | 2193 | else if(strncmp(line,"UnderlinePosition",17)==0) |
afce4c03 | 2194 | { |
36b3b54a | 2195 | if ((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) || |
021e0f21 | 2196 | (strcmp(upString,"UnderlinePosition")!=0)) |
afce4c03 | 2197 | { |
ccbfa8ec | 2198 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName.c_str(), line ); |
36b3b54a RR |
2199 | } |
2200 | } | |
afce4c03 | 2201 | /* JC 2.) check for UnderlineThickness */ |
021e0f21 | 2202 | else if(strncmp(line,"UnderlineThickness",18)==0) |
afce4c03 | 2203 | { |
36b3b54a | 2204 | if ((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) || |
021e0f21 | 2205 | (strcmp(utString,"UnderlineThickness")!=0)) |
afce4c03 | 2206 | { |
ccbfa8ec | 2207 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName.c_str(), line ); |
36b3b54a RR |
2208 | } |
2209 | } | |
afce4c03 | 2210 | /* JC 3.) check for EncodingScheme */ |
021e0f21 | 2211 | else if(strncmp(line,"EncodingScheme",14)==0) |
afce4c03 | 2212 | { |
36b3b54a | 2213 | if ((sscanf(line,"%s%s",utString,encString)!=2) || |
021e0f21 | 2214 | (strcmp(utString,"EncodingScheme")!=0)) |
afce4c03 | 2215 | { |
ccbfa8ec | 2216 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName.c_str(), line ); |
36b3b54a | 2217 | } |
021e0f21 | 2218 | else if (strncmp(encString, "AdobeStandardEncoding", 21)) |
36b3b54a | 2219 | { |
ccbfa8ec | 2220 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"), |
3e469ea3 | 2221 | afmName.c_str(),line, encString); |
36b3b54a RR |
2222 | } |
2223 | } | |
2224 | /* B.) check for char-width */ | |
021e0f21 | 2225 | else if(strncmp(line,"C ",2)==0) |
afce4c03 | 2226 | { |
36b3b54a | 2227 | if (sscanf(line,"%s%d%s%s%d",cString,&ascii,semiString,WXString,&cWidth)!=5) |
afce4c03 | 2228 | { |
ccbfa8ec | 2229 | wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName.c_str(),line); |
36b3b54a | 2230 | } |
021e0f21 | 2231 | if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 || strcmp(WXString,"WX")!=0) |
afce4c03 | 2232 | { |
ccbfa8ec | 2233 | wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName.c_str(),line); |
36b3b54a RR |
2234 | } |
2235 | /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */ | |
2236 | if (ascii>=0 && ascii<256) | |
afce4c03 | 2237 | { |
36b3b54a RR |
2238 | lastWidths[ascii] = cWidth; /* store width */ |
2239 | } | |
afce4c03 VZ |
2240 | else |
2241 | { | |
2242 | /* MATTHEW: this happens a lot; don't print an error */ | |
48c31b28 | 2243 | /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */ |
36b3b54a RR |
2244 | } |
2245 | } | |
2246 | /* C.) ignore other entries. */ | |
2247 | } | |
2248 | fclose(afmFile); | |
ed880dd4 | 2249 | } |
36b3b54a | 2250 | /* hack to compute correct values for german 'Umlaute' |
afce4c03 VZ |
2251 | / the correct way would be to map the character names |
2252 | / like 'adieresis' to corresp. positions of ISOEnc and read | |
2253 | / these values from AFM files, too. Maybe later ... */ | |
36b3b54a RR |
2254 |