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