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