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