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