]>
Commit | Line | Data |
---|---|---|
ed880dd4 | 1 | ///////////////////////////////////////////////////////////////////////////// |
389076f1 | 2 | // Name: src/generic/dcpsg.cpp |
bf38cbff | 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$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
ed880dd4 RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
9a6be59a VZ |
12 | #include "wx/wxprec.h" |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
88a7a4e1 | 18 | #if wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT |
06cfab17 | 19 | |
88a7a4e1 | 20 | #include "wx/generic/dcpsg.h" |
ce4169a4 | 21 | |
88a7a4e1 WS |
22 | #ifndef WX_PRECOMP |
23 | #include "wx/intl.h" | |
e4db172a | 24 | #include "wx/log.h" |
de6185e2 | 25 | #include "wx/utils.h" |
f38924e8 | 26 | #include "wx/dcmemory.h" |
18680f86 | 27 | #include "wx/math.h" |
155ecd4c | 28 | #include "wx/image.h" |
f2e1afc9 | 29 | #include "wx/icon.h" |
88a7a4e1 | 30 | #endif // WX_PRECOMP |
06cfab17 | 31 | |
9a05fd8d | 32 | #include "wx/prntbase.h" |
8850cbd3 | 33 | #include "wx/generic/prntdlgg.h" |
7bcb11d3 | 34 | #include "wx/paper.h" |
d361e74e | 35 | #include "wx/filefn.h" |
d36d1be9 | 36 | #include "wx/stdpaths.h" |
57c208c5 | 37 | |
bf38cbff JS |
38 | #ifdef __WXMSW__ |
39 | ||
40 | #ifdef DrawText | |
41 | #undef DrawText | |
42 | #endif | |
43 | ||
44 | #ifdef StartDoc | |
45 | #undef StartDoc | |
46 | #endif | |
47 | ||
48 | #ifdef GetCharWidth | |
49 | #undef GetCharWidth | |
50 | #endif | |
51 | ||
52 | #ifdef FindWindow | |
53 | #undef FindWindow | |
54 | #endif | |
55 | ||
56 | #endif | |
57 | ||
ed880dd4 RR |
58 | //----------------------------------------------------------------------------- |
59 | // start and end of document/page | |
60 | //----------------------------------------------------------------------------- | |
61 | ||
c31c771b RR |
62 | static const char *wxPostScriptHeaderConicTo = "\ |
63 | /conicto {\n\ | |
64 | /to_y exch def\n\ | |
65 | /to_x exch def\n\ | |
66 | /conic_cntrl_y exch def\n\ | |
67 | /conic_cntrl_x exch def\n\ | |
68 | currentpoint\n\ | |
69 | /p0_y exch def\n\ | |
70 | /p0_x exch def\n\ | |
71 | /p1_x p0_x conic_cntrl_x p0_x sub 2 3 div mul add def\n\ | |
72 | /p1_y p0_y conic_cntrl_y p0_y sub 2 3 div mul add def\n\ | |
73 | /p2_x p1_x to_x p0_x sub 1 3 div mul add def\n\ | |
74 | /p2_y p1_y to_y p0_y sub 1 3 div mul add def\n\ | |
75 | p1_x p1_y p2_x p2_y to_x to_y curveto\n\ | |
76 | } bind def\n\ | |
c31c771b | 77 | "; |
a47391f3 | 78 | |
ed880dd4 RR |
79 | static const char *wxPostScriptHeaderEllipse = "\ |
80 | /ellipsedict 8 dict def\n\ | |
81 | ellipsedict /mtrx matrix put\n\ | |
82 | /ellipse {\n\ | |
9a6be59a VZ |
83 | ellipsedict begin\n\ |
84 | /endangle exch def\n\ | |
85 | /startangle exch def\n\ | |
86 | /yrad exch def\n\ | |
87 | /xrad exch def\n\ | |
88 | /y exch def\n\ | |
89 | /x exch def\n\ | |
90 | /savematrix mtrx currentmatrix def\n\ | |
91 | x y translate\n\ | |
92 | xrad yrad scale\n\ | |
93 | 0 0 1 startangle endangle arc\n\ | |
94 | savematrix setmatrix\n\ | |
95 | end\n\ | |
96 | } def\n\ | |
ed880dd4 RR |
97 | "; |
98 | ||
99 | static const char *wxPostScriptHeaderEllipticArc= "\ | |
100 | /ellipticarcdict 8 dict def\n\ | |
101 | ellipticarcdict /mtrx matrix put\n\ | |
102 | /ellipticarc\n\ | |
103 | { ellipticarcdict begin\n\ | |
104 | /do_fill exch def\n\ | |
105 | /endangle exch def\n\ | |
106 | /startangle exch def\n\ | |
107 | /yrad exch def\n\ | |
108 | /xrad exch def \n\ | |
109 | /y exch def\n\ | |
110 | /x exch def\n\ | |
111 | /savematrix mtrx currentmatrix def\n\ | |
112 | x y translate\n\ | |
113 | xrad yrad scale\n\ | |
114 | do_fill { 0 0 moveto } if\n\ | |
115 | 0 0 1 startangle endangle arc\n\ | |
116 | savematrix setmatrix\n\ | |
117 | do_fill { fill }{ stroke } ifelse\n\ | |
118 | end\n\ | |
119 | } def\n"; | |
120 | ||
121 | static const char *wxPostScriptHeaderSpline = "\ | |
122 | /DrawSplineSection {\n\ | |
9a6be59a VZ |
123 | /y3 exch def\n\ |
124 | /x3 exch def\n\ | |
125 | /y2 exch def\n\ | |
126 | /x2 exch def\n\ | |
127 | /y1 exch def\n\ | |
128 | /x1 exch def\n\ | |
129 | /xa x1 x2 x1 sub 0.666667 mul add def\n\ | |
130 | /ya y1 y2 y1 sub 0.666667 mul add def\n\ | |
131 | /xb x3 x2 x3 sub 0.666667 mul add def\n\ | |
132 | /yb y3 y2 y3 sub 0.666667 mul add def\n\ | |
133 | x1 y1 lineto\n\ | |
134 | xa ya xb yb x3 y3 curveto\n\ | |
135 | } def\n\ | |
ed880dd4 RR |
136 | "; |
137 | ||
138 | static const char *wxPostScriptHeaderColourImage = "\ | |
244e5e34 VZ |
139 | % define 'colorimage' if it isn't defined\n\ |
140 | % ('colortogray' and 'mergeprocs' come from xwd2ps\n\ | |
141 | % via xgrab)\n\ | |
142 | /colorimage where % do we know about 'colorimage'?\n\ | |
143 | { pop } % yes: pop off the 'dict' returned\n\ | |
144 | { % no: define one\n\ | |
145 | /colortogray { % define an RGB->I function\n\ | |
146 | /rgbdata exch store % call input 'rgbdata'\n\ | |
ed880dd4 RR |
147 | rgbdata length 3 idiv\n\ |
148 | /npixls exch store\n\ | |
149 | /rgbindx 0 store\n\ | |
150 | 0 1 npixls 1 sub {\n\ | |
151 | grays exch\n\ | |
244e5e34 VZ |
152 | rgbdata rgbindx get 20 mul % Red\n\ |
153 | rgbdata rgbindx 1 add get 32 mul % Green\n\ | |
154 | rgbdata rgbindx 2 add get 12 mul % Blue\n\ | |
155 | add add 64 idiv % I = .5G + .31R + .18B\n\ | |
ed880dd4 RR |
156 | put\n\ |
157 | /rgbindx rgbindx 3 add store\n\ | |
158 | } for\n\ | |
159 | grays 0 npixls getinterval\n\ | |
160 | } bind def\n\ | |
161 | \n\ | |
244e5e34 VZ |
162 | % Utility procedure for colorimage operator.\n\ |
163 | % This procedure takes two procedures off the\n\ | |
164 | % stack and merges them into a single procedure.\n\ | |
ed880dd4 | 165 | \n\ |
244e5e34 | 166 | /mergeprocs { % def\n\ |
ed880dd4 RR |
167 | dup length\n\ |
168 | 3 -1 roll\n\ | |
169 | dup\n\ | |
170 | length\n\ | |
171 | dup\n\ | |
172 | 5 1 roll\n\ | |
173 | 3 -1 roll\n\ | |
174 | add\n\ | |
175 | array cvx\n\ | |
176 | dup\n\ | |
177 | 3 -1 roll\n\ | |
178 | 0 exch\n\ | |
179 | putinterval\n\ | |
180 | dup\n\ | |
181 | 4 2 roll\n\ | |
182 | putinterval\n\ | |
183 | } bind def\n\ | |
184 | \n\ | |
244e5e34 VZ |
185 | /colorimage { % def\n\ |
186 | pop pop % remove 'false 3' operands\n\ | |
ed880dd4 RR |
187 | {colortogray} mergeprocs\n\ |
188 | image\n\ | |
189 | } bind def\n\ | |
244e5e34 | 190 | } ifelse % end of 'false' case\n\ |
ed880dd4 RR |
191 | "; |
192 | ||
193 | static char wxPostScriptHeaderReencodeISO1[] = | |
194 | "\n/reencodeISO {\n" | |
195 | "dup dup findfont dup length dict begin\n" | |
196 | "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n" | |
197 | "/Encoding ISOLatin1Encoding def\n" | |
198 | "currentdict end definefont\n" | |
199 | "} def\n" | |
200 | "/ISOLatin1Encoding [\n" | |
201 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
202 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
203 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
204 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
205 | "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n" | |
206 | "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n" | |
207 | "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n" | |
208 | "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n" | |
209 | "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n" | |
210 | "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n" | |
211 | "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n" | |
212 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
213 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
214 | "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n" | |
215 | "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n"; | |
216 | ||
217 | static char wxPostScriptHeaderReencodeISO2[] = | |
218 | "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n" | |
219 | "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n" | |
220 | "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n" | |
221 | "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n" | |
222 | "/guillemotright/onequarter/onehalf/threequarters/questiondown\n" | |
223 | "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n" | |
224 | "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n" | |
225 | "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n" | |
226 | "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n" | |
227 | "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n" | |
228 | "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n" | |
229 | "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n" | |
230 | "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n" | |
231 | "/yacute/thorn/ydieresis\n" | |
232 | "] def\n\n"; | |
233 | ||
ed880dd4 RR |
234 | //------------------------------------------------------------------------------- |
235 | // wxPostScriptDC | |
236 | //------------------------------------------------------------------------------- | |
237 | ||
4f37154e RR |
238 | |
239 | #if wxUSE_NEW_DC | |
240 | ||
241 | IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC) | |
242 | ||
243 | wxPostScriptDC::wxPostScriptDC() | |
244 | { | |
245 | m_pimpl = new wxPostScriptImplDC( this ); | |
246 | } | |
247 | ||
248 | wxPostScriptDC::wxPostScriptDC(const wxPrintData& printData) | |
249 | { | |
250 | m_pimpl = new wxPostScriptImplDC( this, printData ); | |
251 | } | |
252 | ||
253 | #endif | |
254 | ||
255 | ||
eb7637b5 RR |
256 | // conversion |
257 | static const double RAD2DEG = 180.0 / M_PI; | |
258 | ||
259 | // we don't want to use only 72 dpi from PS print | |
260 | static const int DPI = 600; | |
261 | static const double PS2DEV = 600.0 / 72.0; | |
262 | static const double DEV2PS = 72.0 / 600.0; | |
263 | ||
264 | #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS) | |
265 | #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS) | |
266 | #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS) | |
267 | #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS) | |
268 | ||
4f37154e RR |
269 | |
270 | #if wxUSE_NEW_DC | |
271 | IMPLEMENT_ABSTRACT_CLASS(wxPostScriptImplDC, wxImplDC) | |
272 | #else | |
273 | IMPLEMENT_ABSTRACT_CLASS(wxPostScriptDC, wxDC) | |
274 | #endif | |
eba33006 | 275 | |
eb7637b5 | 276 | //------------------------------------------------------------------------------- |
b64de916 | 277 | |
4f37154e RR |
278 | #if wxUSE_NEW_DC |
279 | wxPostScriptImplDC::wxPostScriptImplDC( wxPostScriptDC *owner ) : | |
280 | wxImplDC( owner ) | |
b64de916 | 281 | { |
4f37154e | 282 | Init(); |
b64de916 | 283 | |
4f37154e RR |
284 | m_pageHeight = 842 * PS2DEV; |
285 | ||
286 | m_ok = true; | |
b64de916 | 287 | } |
48c31b28 | 288 | |
4f37154e RR |
289 | wxPostScriptImplDC::wxPostScriptImplDC( wxPostScriptDC *owner, const wxPrintData& data ) : |
290 | wxImplDC( owner ) | |
ed880dd4 | 291 | { |
4f37154e RR |
292 | Init(); |
293 | ||
294 | // this calculates m_pageHeight required for | |
295 | // taking the inverted Y axis into account | |
296 | SetPrintData( data ); | |
afce4c03 | 297 | |
4f37154e RR |
298 | m_ok = true; |
299 | } | |
300 | #endif | |
afce4c03 | 301 | |
afce4c03 | 302 | |
4f37154e RR |
303 | #if wxUSE_NEW_DC |
304 | wxPostScriptImplDC::wxPostScriptImplDC( wxPrinterDC *owner ) : | |
305 | wxImplDC( owner ) | |
306 | #else | |
307 | wxPostScriptDC::wxPostScriptDC() | |
308 | #endif | |
309 | { | |
310 | Init(); | |
ed880dd4 | 311 | |
eb7637b5 | 312 | m_pageHeight = 842 * PS2DEV; |
4f37154e RR |
313 | |
314 | m_ok = true; | |
315 | } | |
316 | ||
317 | #if wxUSE_NEW_DC | |
318 | wxPostScriptImplDC::wxPostScriptImplDC( wxPrinterDC *owner, const wxPrintData& data ) : | |
319 | wxImplDC( owner ) | |
320 | #else | |
321 | wxPostScriptDC::wxPostScriptDC( const wxPrintData& data ) | |
322 | #endif | |
323 | { | |
324 | Init(); | |
325 | ||
326 | // this calculates m_pageHeight required for | |
327 | // taking the inverted Y axis into account | |
328 | SetPrintData( data ); | |
329 | ||
330 | m_ok = true; | |
ed880dd4 RR |
331 | } |
332 | ||
4f37154e | 333 | void wxPostScriptImplDC::Init() |
7bcb11d3 | 334 | { |
d7657f75 | 335 | m_pstream = (FILE*) NULL; |
7bcb11d3 JS |
336 | |
337 | m_currentRed = 0; | |
338 | m_currentGreen = 0; | |
339 | m_currentBlue = 0; | |
340 | ||
341 | m_pageNumber = 0; | |
342 | ||
ca65c044 | 343 | m_clipping = false; |
7bcb11d3 JS |
344 | |
345 | m_underlinePosition = 0.0; | |
346 | m_underlineThickness = 0.0; | |
347 | ||
7bcb11d3 JS |
348 | } |
349 | ||
4f37154e | 350 | wxPostScriptImplDC::~wxPostScriptImplDC () |
ed880dd4 | 351 | { |
d7657f75 RR |
352 | if (m_pstream) |
353 | { | |
354 | fclose( m_pstream ); | |
72cdf4c9 | 355 | m_pstream = (FILE*) NULL; |
d7657f75 | 356 | } |
ed880dd4 RR |
357 | } |
358 | ||
4f37154e | 359 | bool wxPostScriptImplDC::IsOk() const |
4bc67cc5 | 360 | { |
ef539066 | 361 | return m_ok; |
4bc67cc5 | 362 | } |
afce4c03 | 363 | |
4f37154e RR |
364 | wxRect wxPostScriptImplDC::GetPaperRect() |
365 | { | |
366 | int w = 0; | |
367 | int h = 0; | |
368 | DoGetSize( &w, &h ); | |
369 | return wxRect(0,0,w,h); | |
370 | } | |
371 | ||
372 | int wxPostScriptImplDC::GetResolution() | |
373 | { | |
374 | return DPI; | |
375 | } | |
376 | ||
377 | void wxPostScriptImplDC::DoSetClippingRegion (wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
ed880dd4 | 378 | { |
846051ec | 379 | wxCHECK_RET( m_ok , wxT("invalid postscript dc") ); |
afce4c03 | 380 | |
4f37154e RR |
381 | if (m_clipping) |
382 | DestroyClippingRegion(); | |
ed880dd4 | 383 | |
4f37154e RR |
384 | #if wxUSE_NEW_DC |
385 | m_clipX1 = x; | |
386 | m_clipY1 = y; | |
387 | m_clipX2 = x + w; | |
388 | m_clipY2 = y + h; | |
389 | #else | |
7087444f | 390 | wxDC::DoSetClippingRegion(x, y, w, h); |
4f37154e | 391 | #endif |
afce4c03 | 392 | |
ca65c044 | 393 | m_clipping = true; |
846051ec | 394 | |
eb7637b5 RR |
395 | wxString buffer; |
396 | buffer.Printf( "gsave\n" | |
397 | "newpath\n" | |
398 | "%f %f moveto\n" | |
399 | "%f %f lineto\n" | |
400 | "%f %f lineto\n" | |
401 | "%f %f lineto\n" | |
402 | "closepath clip newpath\n", | |
403 | XLOG2DEV(x), YLOG2DEV(y), | |
404 | XLOG2DEV(x+w), YLOG2DEV(y), | |
405 | XLOG2DEV(x+w), YLOG2DEV(y+h), | |
406 | XLOG2DEV(x), YLOG2DEV(y+h) ); | |
407 | buffer.Replace( ",", "." ); | |
408 | PsPrint( buffer ); | |
ed880dd4 RR |
409 | } |
410 | ||
ed880dd4 | 411 | |
4f37154e | 412 | void wxPostScriptImplDC::DestroyClippingRegion() |
ed880dd4 | 413 | { |
846051ec | 414 | wxCHECK_RET( m_ok , wxT("invalid postscript dc") ); |
afce4c03 | 415 | |
ed880dd4 RR |
416 | if (m_clipping) |
417 | { | |
ca65c044 | 418 | m_clipping = false; |
244e5e34 | 419 | PsPrint( "grestore\n" ); |
ed880dd4 | 420 | } |
004fd0c8 | 421 | |
4f37154e RR |
422 | #if wxUSE_NEW_DC |
423 | wxImplDC::DestroyClippingRegion(); | |
424 | #else | |
7087444f | 425 | wxDC::DestroyClippingRegion(); |
4f37154e | 426 | #endif |
ed880dd4 RR |
427 | } |
428 | ||
4f37154e | 429 | void wxPostScriptImplDC::Clear() |
ed880dd4 | 430 | { |
f632aa1e JS |
431 | // This should fail silently to avoid unnecessary |
432 | // asserts | |
4f37154e | 433 | // wxFAIL_MSG( wxT("wxPostScriptImplDC::Clear not implemented.") ); |
ed880dd4 RR |
434 | } |
435 | ||
4f37154e | 436 | bool wxPostScriptImplDC::DoFloodFill (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour &WXUNUSED(col), int WXUNUSED(style)) |
ed880dd4 | 437 | { |
4f37154e | 438 | wxFAIL_MSG( wxT("wxPostScriptImplDC::FloodFill not implemented.") ); |
ca65c044 | 439 | return false; |
ed880dd4 RR |
440 | } |
441 | ||
4f37154e | 442 | bool wxPostScriptImplDC::DoGetPixel (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour * WXUNUSED(col)) const |
ed880dd4 | 443 | { |
4f37154e | 444 | wxFAIL_MSG( wxT("wxPostScriptImplDC::GetPixel not implemented.") ); |
ca65c044 | 445 | return false; |
ed880dd4 RR |
446 | } |
447 | ||
4f37154e | 448 | void wxPostScriptImplDC::DoCrossHair (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) |
ed880dd4 | 449 | { |
4f37154e | 450 | wxFAIL_MSG( wxT("wxPostScriptImplDC::CrossHair not implemented.") ); |
ed880dd4 RR |
451 | } |
452 | ||
4f37154e | 453 | void wxPostScriptImplDC::DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) |
ed880dd4 | 454 | { |
846051ec | 455 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 456 | |
ed880dd4 | 457 | if (m_pen.GetStyle() == wxTRANSPARENT) return; |
afce4c03 | 458 | |
ed880dd4 | 459 | SetPen( m_pen ); |
afce4c03 | 460 | |
eb7637b5 RR |
461 | wxString buffer; |
462 | buffer.Printf( "newpath\n" | |
463 | "%f %f moveto\n" | |
464 | "%f %f lineto\n" | |
465 | "stroke\n", | |
466 | XLOG2DEV(x1), YLOG2DEV(y1), | |
467 | XLOG2DEV(x2), YLOG2DEV(y2) ); | |
468 | buffer.Replace( ",", "." ); | |
469 | PsPrint( buffer ); | |
afce4c03 | 470 | |
ed880dd4 RR |
471 | CalcBoundingBox( x1, y1 ); |
472 | CalcBoundingBox( x2, y2 ); | |
473 | } | |
474 | ||
4f37154e | 475 | void wxPostScriptImplDC::DoDrawArc (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc) |
ed880dd4 | 476 | { |
846051ec | 477 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 478 | |
72cdf4c9 VZ |
479 | wxCoord dx = x1 - xc; |
480 | wxCoord dy = y1 - yc; | |
eb7637b5 | 481 | double radius = sqrt( (double)(dx*dx+dy*dy) ); |
ed880dd4 RR |
482 | double alpha1, alpha2; |
483 | ||
afce4c03 | 484 | if (x1 == x2 && y1 == y2) |
ed880dd4 | 485 | { |
d7657f75 RR |
486 | alpha1 = 0.0; |
487 | alpha2 = 360.0; | |
72cdf4c9 | 488 | } |
c77a6796 | 489 | else if ( wxIsNullDouble(radius) ) |
ed880dd4 | 490 | { |
c77a6796 VZ |
491 | alpha1 = |
492 | alpha2 = 0.0; | |
72cdf4c9 | 493 | } |
d7657f75 | 494 | else |
ed880dd4 | 495 | { |
d7657f75 RR |
496 | alpha1 = (x1 - xc == 0) ? |
497 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
498 | -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; | |
499 | alpha2 = (x2 - xc == 0) ? | |
500 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
501 | -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; | |
ed880dd4 RR |
502 | } |
503 | while (alpha1 <= 0) alpha1 += 360; | |
504 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between | |
505 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree | |
506 | while (alpha2 > 360) alpha2 -= 360; | |
507 | ||
eb7637b5 RR |
508 | int i_radius = wxRound( radius ); |
509 | ||
afce4c03 | 510 | if (m_brush.GetStyle() != wxTRANSPARENT) |
ed880dd4 | 511 | { |
d7657f75 | 512 | SetBrush( m_brush ); |
72cdf4c9 | 513 | |
eb7637b5 RR |
514 | wxString buffer; |
515 | buffer.Printf( "newpath\n" | |
516 | "%f %f %f %f %f %f ellipse\n" | |
517 | "%f %f lineto\n" | |
518 | "closepath\n" | |
519 | "fill\n", | |
84ef8365 VZ |
520 | XLOG2DEV(xc), YLOG2DEV(yc), |
521 | XLOG2DEVREL(i_radius), YLOG2DEVREL(i_radius), | |
eb7637b5 RR |
522 | alpha1, alpha2, |
523 | XLOG2DEV(xc), YLOG2DEV(yc) ); | |
524 | buffer.Replace( ",", "." ); | |
525 | PsPrint( buffer ); | |
d7657f75 | 526 | |
eb7637b5 RR |
527 | CalcBoundingBox( xc-i_radius, yc-i_radius ); |
528 | CalcBoundingBox( xc+i_radius, yc+i_radius ); | |
ed880dd4 | 529 | } |
afce4c03 VZ |
530 | |
531 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
ed880dd4 | 532 | { |
d7657f75 | 533 | SetPen( m_pen ); |
84ef8365 | 534 | |
eb7637b5 RR |
535 | wxString buffer; |
536 | buffer.Printf( "newpath\n" | |
537 | "%f %f %f %f %f %f ellipse\n" | |
538 | "%f %f lineto\n" | |
ed838581 RR |
539 | "closepath\n" |
540 | "stroke\n", | |
84ef8365 VZ |
541 | XLOG2DEV(xc), YLOG2DEV(yc), |
542 | XLOG2DEVREL(i_radius), YLOG2DEVREL(i_radius), | |
eb7637b5 RR |
543 | alpha1, alpha2, |
544 | XLOG2DEV(xc), YLOG2DEV(yc) ); | |
545 | buffer.Replace( ",", "." ); | |
546 | PsPrint( buffer ); | |
72cdf4c9 | 547 | |
eb7637b5 RR |
548 | CalcBoundingBox( xc-i_radius, yc-i_radius ); |
549 | CalcBoundingBox( xc+i_radius, yc+i_radius ); | |
ed880dd4 | 550 | } |
ed880dd4 RR |
551 | } |
552 | ||
4f37154e | 553 | void wxPostScriptImplDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) |
ed880dd4 | 554 | { |
846051ec | 555 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 556 | |
c77a6796 VZ |
557 | if ( sa >= 360 || sa <= -360 ) |
558 | sa -= int(sa/360)*360; | |
559 | if ( ea >= 360 || ea <=- 360 ) | |
560 | ea -= int(ea/360)*360; | |
561 | if ( sa < 0 ) | |
562 | sa += 360; | |
563 | if ( ea < 0 ) | |
564 | ea += 360; | |
afce4c03 | 565 | |
c77a6796 | 566 | if ( wxIsSameDouble(sa, ea) ) |
ed880dd4 | 567 | { |
4f37154e | 568 | DoDrawEllipse(x,y,w,h); |
ed880dd4 RR |
569 | return; |
570 | } | |
571 | ||
572 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
573 | { | |
574 | SetBrush( m_brush ); | |
72cdf4c9 | 575 | |
eb7637b5 RR |
576 | wxString buffer; |
577 | buffer.Printf( "newpath\n" | |
578 | "%f %f %f %f %f %f true ellipticarc\n", | |
579 | XLOG2DEV(x+w/2), YLOG2DEV(y+h/2), | |
580 | XLOG2DEVREL(w/2), YLOG2DEVREL(h/2), | |
581 | sa, ea ); | |
582 | buffer.Replace( ",", "." ); | |
583 | PsPrint( buffer ); | |
72cdf4c9 | 584 | |
ed880dd4 RR |
585 | CalcBoundingBox( x ,y ); |
586 | CalcBoundingBox( x+w, y+h ); | |
72cdf4c9 VZ |
587 | } |
588 | ||
ed880dd4 RR |
589 | if (m_pen.GetStyle () != wxTRANSPARENT) |
590 | { | |
591 | SetPen( m_pen ); | |
592 | ||
eb7637b5 RR |
593 | wxString buffer; |
594 | buffer.Printf( "newpath\n" | |
595 | "%f %f %f %f %f %f false ellipticarc\n", | |
596 | XLOG2DEV(x+w/2), YLOG2DEV(y+h/2), | |
597 | XLOG2DEVREL(w/2), YLOG2DEVREL(h/2), | |
ed838581 | 598 | sa, ea ); |
eb7637b5 RR |
599 | buffer.Replace( ",", "." ); |
600 | PsPrint( buffer ); | |
72cdf4c9 | 601 | |
d7657f75 | 602 | CalcBoundingBox( x ,y ); |
ed880dd4 RR |
603 | CalcBoundingBox( x+w, y+h ); |
604 | } | |
605 | } | |
606 | ||
4f37154e | 607 | void wxPostScriptImplDC::DoDrawPoint (wxCoord x, wxCoord y) |
ed880dd4 | 608 | { |
846051ec | 609 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 610 | |
ed880dd4 | 611 | if (m_pen.GetStyle() == wxTRANSPARENT) return; |
afce4c03 | 612 | |
ed880dd4 | 613 | SetPen (m_pen); |
afce4c03 | 614 | |
eb7637b5 RR |
615 | wxString buffer; |
616 | buffer.Printf( "newpath\n" | |
617 | "%f %f moveto\n" | |
618 | "%f %f lineto\n" | |
619 | "stroke\n", | |
620 | XLOG2DEV(x), YLOG2DEV(y), | |
621 | XLOG2DEV(x+1), YLOG2DEV(y) ); | |
622 | buffer.Replace( ",", "." ); | |
623 | PsPrint( buffer ); | |
afce4c03 | 624 | |
ed880dd4 RR |
625 | CalcBoundingBox( x, y ); |
626 | } | |
627 | ||
4f37154e | 628 | void wxPostScriptImplDC::DoDrawPolygon (int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) |
ed880dd4 | 629 | { |
846051ec | 630 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 631 | |
ed880dd4 | 632 | if (n <= 0) return; |
afce4c03 | 633 | |
ed880dd4 RR |
634 | if (m_brush.GetStyle () != wxTRANSPARENT) |
635 | { | |
d7657f75 RR |
636 | SetBrush( m_brush ); |
637 | ||
244e5e34 | 638 | PsPrint( "newpath\n" ); |
afce4c03 | 639 | |
eb7637b5 RR |
640 | double xx = XLOG2DEV(points[0].x + xoffset); |
641 | double yy = YLOG2DEV(points[0].y + yoffset); | |
72cdf4c9 | 642 | |
eb7637b5 RR |
643 | wxString buffer; |
644 | buffer.Printf( "%f %f moveto\n", xx, yy ); | |
645 | buffer.Replace( ",", "." ); | |
646 | PsPrint( buffer ); | |
72cdf4c9 | 647 | |
d7657f75 | 648 | CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset ); |
ed880dd4 | 649 | |
d7657f75 RR |
650 | for (int i = 1; i < n; i++) |
651 | { | |
eb7637b5 RR |
652 | xx = XLOG2DEV(points[i].x + xoffset); |
653 | yy = YLOG2DEV(points[i].y + yoffset); | |
72cdf4c9 | 654 | |
eb7637b5 RR |
655 | buffer.Printf( "%f %f lineto\n", xx, yy ); |
656 | buffer.Replace( ",", "." ); | |
657 | PsPrint( buffer ); | |
ed880dd4 | 658 | |
d7657f75 RR |
659 | CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset); |
660 | } | |
72cdf4c9 | 661 | |
244e5e34 | 662 | PsPrint( (fillStyle == wxODDEVEN_RULE ? "eofill\n" : "fill\n") ); |
ed880dd4 RR |
663 | } |
664 | ||
665 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
666 | { | |
d7657f75 | 667 | SetPen( m_pen ); |
72cdf4c9 | 668 | |
244e5e34 | 669 | PsPrint( "newpath\n" ); |
ed880dd4 | 670 | |
eb7637b5 RR |
671 | double xx = XLOG2DEV(points[0].x + xoffset); |
672 | double yy = YLOG2DEV(points[0].y + yoffset); | |
72cdf4c9 | 673 | |
eb7637b5 RR |
674 | wxString buffer; |
675 | buffer.Printf( "%f %f moveto\n", xx, yy ); | |
676 | buffer.Replace( ",", "." ); | |
677 | PsPrint( buffer ); | |
72cdf4c9 | 678 | |
d7657f75 | 679 | CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset ); |
ed880dd4 | 680 | |
d7657f75 RR |
681 | for (int i = 1; i < n; i++) |
682 | { | |
eb7637b5 RR |
683 | xx = XLOG2DEV(points[i].x + xoffset); |
684 | yy = YLOG2DEV(points[i].y + yoffset); | |
72cdf4c9 | 685 | |
eb7637b5 RR |
686 | buffer.Printf( "%f %f lineto\n", xx, yy ); |
687 | buffer.Replace( ",", "." ); | |
688 | PsPrint( buffer ); | |
72cdf4c9 | 689 | |
d7657f75 RR |
690 | CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset); |
691 | } | |
ed880dd4 | 692 | |
244e5e34 VZ |
693 | PsPrint( "closepath\n" ); |
694 | PsPrint( "stroke\n" ); | |
ed880dd4 RR |
695 | } |
696 | } | |
697 | ||
4f37154e | 698 | void wxPostScriptImplDC::DoDrawPolyPolygon (int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) |
6e76b35d | 699 | { |
244e5e34 | 700 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
6e76b35d VZ |
701 | |
702 | if (n <= 0) return; | |
703 | ||
704 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
705 | { | |
706 | SetBrush( m_brush ); | |
707 | ||
244e5e34 | 708 | PsPrint( "newpath\n" ); |
6e76b35d VZ |
709 | |
710 | int ofs = 0; | |
793db755 | 711 | for (int i = 0; i < n; ofs += count[i++]) |
6e76b35d | 712 | { |
eb7637b5 RR |
713 | double xx = XLOG2DEV(points[ofs].x + xoffset); |
714 | double yy = YLOG2DEV(points[ofs].y + yoffset); | |
6e76b35d | 715 | |
eb7637b5 RR |
716 | wxString buffer; |
717 | buffer.Printf( "%f %f moveto\n", xx, yy ); | |
718 | buffer.Replace( ",", "." ); | |
719 | PsPrint( buffer ); | |
6e76b35d VZ |
720 | |
721 | CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset ); | |
722 | ||
793db755 | 723 | for (int j = 1; j < count[i]; j++) |
6e76b35d | 724 | { |
eb7637b5 RR |
725 | xx = XLOG2DEV(points[ofs+j].x + xoffset); |
726 | yy = YLOG2DEV(points[ofs+j].y + yoffset); | |
6e76b35d | 727 | |
eb7637b5 RR |
728 | buffer.Printf( "%f %f lineto\n", xx, yy ); |
729 | buffer.Replace( ",", "." ); | |
730 | PsPrint( buffer ); | |
6e76b35d VZ |
731 | |
732 | CalcBoundingBox( points[ofs+j].x + xoffset, points[ofs+j].y + yoffset); | |
733 | } | |
734 | } | |
244e5e34 | 735 | PsPrint( (fillStyle == wxODDEVEN_RULE ? "eofill\n" : "fill\n") ); |
6e76b35d VZ |
736 | } |
737 | ||
738 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
739 | { | |
740 | SetPen( m_pen ); | |
741 | ||
244e5e34 | 742 | PsPrint( "newpath\n" ); |
6e76b35d VZ |
743 | |
744 | int ofs = 0; | |
793db755 | 745 | for (int i = 0; i < n; ofs += count[i++]) |
6e76b35d | 746 | { |
eb7637b5 RR |
747 | double xx = XLOG2DEV(points[ofs].x + xoffset); |
748 | double yy = YLOG2DEV(points[ofs].y + yoffset); | |
6e76b35d | 749 | |
eb7637b5 RR |
750 | wxString buffer; |
751 | buffer.Printf( "%f %f moveto\n", xx, yy ); | |
752 | buffer.Replace( ",", "." ); | |
753 | PsPrint( buffer ); | |
6e76b35d VZ |
754 | |
755 | CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset ); | |
756 | ||
793db755 | 757 | for (int j = 1; j < count[i]; j++) |
6e76b35d | 758 | { |
eb7637b5 RR |
759 | xx = XLOG2DEV(points[ofs+j].x + xoffset); |
760 | yy = YLOG2DEV(points[ofs+j].y + yoffset); | |
6e76b35d | 761 | |
eb7637b5 RR |
762 | buffer.Printf( "%f %f lineto\n", xx, yy ); |
763 | buffer.Replace( ",", "." ); | |
764 | PsPrint( buffer ); | |
6e76b35d VZ |
765 | |
766 | CalcBoundingBox( points[ofs+j].x + xoffset, points[ofs+j].y + yoffset); | |
767 | } | |
768 | } | |
244e5e34 VZ |
769 | PsPrint( "closepath\n" ); |
770 | PsPrint( "stroke\n" ); | |
6e76b35d VZ |
771 | } |
772 | } | |
773 | ||
4f37154e | 774 | void wxPostScriptImplDC::DoDrawLines (int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) |
ed880dd4 | 775 | { |
846051ec | 776 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 777 | |
d7657f75 | 778 | if (m_pen.GetStyle() == wxTRANSPARENT) return; |
72cdf4c9 | 779 | |
d7657f75 | 780 | if (n <= 0) return; |
afce4c03 | 781 | |
ed880dd4 | 782 | SetPen (m_pen); |
afce4c03 | 783 | |
9a6be59a VZ |
784 | int i; |
785 | for ( i =0; i<n ; i++ ) | |
eb7637b5 RR |
786 | CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset ); |
787 | ||
788 | wxString buffer; | |
789 | buffer.Printf( "newpath\n" | |
790 | "%f %f moveto\n", | |
791 | XLOG2DEV(points[0].x+xoffset), | |
792 | YLOG2DEV(points[0].y+yoffset) ); | |
793 | buffer.Replace( ",", "." ); | |
794 | PsPrint( buffer ); | |
84ef8365 | 795 | |
244e5e34 | 796 | for (i = 1; i < n; i++) |
846051ec | 797 | { |
eb7637b5 RR |
798 | buffer.Printf( "%f %f lineto\n", |
799 | XLOG2DEV(points[i].x+xoffset), | |
800 | YLOG2DEV(points[i].y+yoffset) ); | |
801 | buffer.Replace( ",", "." ); | |
802 | PsPrint( buffer ); | |
ed880dd4 | 803 | } |
ca65c044 | 804 | |
244e5e34 | 805 | PsPrint( "stroke\n" ); |
ed880dd4 RR |
806 | } |
807 | ||
4f37154e | 808 | void wxPostScriptImplDC::DoDrawRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
ed880dd4 | 809 | { |
846051ec | 810 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
84ef8365 | 811 | |
728ddc45 RR |
812 | width--; |
813 | height--; | |
afce4c03 | 814 | |
ed880dd4 RR |
815 | if (m_brush.GetStyle () != wxTRANSPARENT) |
816 | { | |
817 | SetBrush( m_brush ); | |
72cdf4c9 | 818 | |
eb7637b5 RR |
819 | wxString buffer; |
820 | buffer.Printf( "newpath\n" | |
821 | "%f %f moveto\n" | |
822 | "%f %f lineto\n" | |
823 | "%f %f lineto\n" | |
824 | "%f %f lineto\n" | |
825 | "closepath\n" | |
826 | "fill\n", | |
827 | XLOG2DEV(x), YLOG2DEV(y), | |
828 | XLOG2DEV(x + width), YLOG2DEV(y), | |
829 | XLOG2DEV(x + width), YLOG2DEV(y + height), | |
830 | XLOG2DEV(x), YLOG2DEV(y + height) ); | |
831 | buffer.Replace( ",", "." ); | |
832 | PsPrint( buffer ); | |
ed880dd4 RR |
833 | |
834 | CalcBoundingBox( x, y ); | |
835 | CalcBoundingBox( x + width, y + height ); | |
836 | } | |
afce4c03 | 837 | |
ed880dd4 RR |
838 | if (m_pen.GetStyle () != wxTRANSPARENT) |
839 | { | |
840 | SetPen (m_pen); | |
841 | ||
eb7637b5 RR |
842 | wxString buffer; |
843 | buffer.Printf( "newpath\n" | |
844 | "%f %f moveto\n" | |
845 | "%f %f lineto\n" | |
846 | "%f %f lineto\n" | |
847 | "%f %f lineto\n" | |
848 | "closepath\n" | |
849 | "stroke\n", | |
850 | XLOG2DEV(x), YLOG2DEV(y), | |
851 | XLOG2DEV(x + width), YLOG2DEV(y), | |
852 | XLOG2DEV(x + width), YLOG2DEV(y + height), | |
853 | XLOG2DEV(x), YLOG2DEV(y + height) ); | |
854 | buffer.Replace( ",", "." ); | |
855 | PsPrint( buffer ); | |
72cdf4c9 | 856 | |
ed880dd4 RR |
857 | CalcBoundingBox( x, y ); |
858 | CalcBoundingBox( x + width, y + height ); | |
859 | } | |
860 | } | |
861 | ||
4f37154e | 862 | void wxPostScriptImplDC::DoDrawRoundedRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) |
ed880dd4 | 863 | { |
846051ec | 864 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 865 | |
728ddc45 RR |
866 | width--; |
867 | height--; | |
868 | ||
ed880dd4 RR |
869 | if (radius < 0.0) |
870 | { | |
871 | // Now, a negative radius is interpreted to mean | |
872 | // 'the proportion of the smallest X or Y dimension' | |
999836aa | 873 | double smallest = width < height ? width : height; |
ed880dd4 RR |
874 | radius = (-radius * smallest); |
875 | } | |
afce4c03 | 876 | |
72cdf4c9 | 877 | wxCoord rad = (wxCoord) radius; |
ed880dd4 RR |
878 | |
879 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
880 | { | |
881 | SetBrush( m_brush ); | |
afce4c03 | 882 | |
d7657f75 | 883 | /* Draw rectangle anticlockwise */ |
eb7637b5 RR |
884 | wxString buffer; |
885 | buffer.Printf( "newpath\n" | |
886 | "%f %f %f 90 180 arc\n" | |
887 | "%f %f lineto\n" | |
888 | "%f %f %f 180 270 arc\n" | |
889 | "%f %f lineto\n" | |
890 | "%f %f %f 270 0 arc\n" | |
891 | "%f %f lineto\n" | |
892 | "%f %f %f 0 90 arc\n" | |
893 | "%f %f lineto\n" | |
894 | "closepath\n" | |
895 | "fill\n", | |
896 | XLOG2DEV(x + rad), YLOG2DEV(y + rad), XLOG2DEVREL(rad), | |
897 | XLOG2DEV(x), YLOG2DEV(y + height - rad), | |
898 | XLOG2DEV(x + rad), YLOG2DEV(y + height - rad), XLOG2DEVREL(rad), | |
899 | XLOG2DEV(x + width - rad), YLOG2DEV(y + height), | |
900 | XLOG2DEV(x + width - rad), YLOG2DEV(y + height - rad), XLOG2DEVREL(rad), | |
901 | XLOG2DEV(x + width), YLOG2DEV(y + rad), | |
902 | XLOG2DEV(x + width - rad), YLOG2DEV(y + rad), XLOG2DEVREL(rad), | |
903 | XLOG2DEV(x + rad), YLOG2DEV(y) ); | |
904 | buffer.Replace( ",", "." ); | |
905 | PsPrint( buffer ); | |
ed880dd4 RR |
906 | |
907 | CalcBoundingBox( x, y ); | |
908 | CalcBoundingBox( x + width, y + height ); | |
909 | } | |
afce4c03 | 910 | |
ed880dd4 RR |
911 | if (m_pen.GetStyle () != wxTRANSPARENT) |
912 | { | |
913 | SetPen (m_pen); | |
afce4c03 | 914 | |
d7657f75 | 915 | /* Draw rectangle anticlockwise */ |
eb7637b5 RR |
916 | wxString buffer; |
917 | buffer.Printf( "newpath\n" | |
918 | "%f %f %f 90 180 arc\n" | |
919 | "%f %f lineto\n" | |
920 | "%f %f %f 180 270 arc\n" | |
921 | "%f %f lineto\n" | |
922 | "%f %f %f 270 0 arc\n" | |
923 | "%f %f lineto\n" | |
924 | "%f %f %f 0 90 arc\n" | |
925 | "%f %f lineto\n" | |
926 | "closepath\n" | |
927 | "stroke\n", | |
928 | XLOG2DEV(x + rad), YLOG2DEV(y + rad), XLOG2DEVREL(rad), | |
929 | XLOG2DEV(x), YLOG2DEV(y + height - rad), | |
930 | XLOG2DEV(x + rad), YLOG2DEV(y + height - rad), XLOG2DEVREL(rad), | |
931 | XLOG2DEV(x + width - rad), YLOG2DEV(y + height), | |
932 | XLOG2DEV(x + width - rad), YLOG2DEV(y + height - rad), XLOG2DEVREL(rad), | |
933 | XLOG2DEV(x + width), YLOG2DEV(y + rad), | |
934 | XLOG2DEV(x + width - rad), YLOG2DEV(y + rad), XLOG2DEVREL(rad), | |
935 | XLOG2DEV(x + rad), YLOG2DEV(y) ); | |
936 | buffer.Replace( ",", "." ); | |
937 | PsPrint( buffer ); | |
ed880dd4 RR |
938 | |
939 | CalcBoundingBox( x, y ); | |
940 | CalcBoundingBox( x + width, y + height ); | |
941 | } | |
942 | } | |
943 | ||
4f37154e | 944 | void wxPostScriptImplDC::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
ed880dd4 | 945 | { |
846051ec | 946 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 947 | |
728ddc45 RR |
948 | width--; |
949 | height--; | |
950 | ||
ed880dd4 RR |
951 | if (m_brush.GetStyle () != wxTRANSPARENT) |
952 | { | |
953 | SetBrush (m_brush); | |
954 | ||
eb7637b5 RR |
955 | wxString buffer; |
956 | buffer.Printf( "newpath\n" | |
957 | "%f %f %f %f 0 360 ellipse\n" | |
958 | "fill\n", | |
959 | XLOG2DEV(x + width / 2), YLOG2DEV(y + height / 2), | |
960 | XLOG2DEVREL(width / 2), YLOG2DEVREL(height / 2) ); | |
961 | buffer.Replace( ",", "." ); | |
962 | PsPrint( buffer ); | |
ed880dd4 RR |
963 | |
964 | CalcBoundingBox( x - width, y - height ); | |
965 | CalcBoundingBox( x + width, y + height ); | |
966 | } | |
afce4c03 | 967 | |
d7657f75 | 968 | if (m_pen.GetStyle () != wxTRANSPARENT) |
ed880dd4 RR |
969 | { |
970 | SetPen (m_pen); | |
971 | ||
eb7637b5 RR |
972 | wxString buffer; |
973 | buffer.Printf( "newpath\n" | |
974 | "%f %f %f %f 0 360 ellipse\n" | |
975 | "stroke\n", | |
976 | XLOG2DEV(x + width / 2), YLOG2DEV(y + height / 2), | |
977 | XLOG2DEVREL(width / 2), YLOG2DEVREL(height / 2) ); | |
978 | buffer.Replace( ",", "." ); | |
979 | PsPrint( buffer ); | |
ed880dd4 RR |
980 | |
981 | CalcBoundingBox( x - width, y - height ); | |
982 | CalcBoundingBox( x + width, y + height ); | |
983 | } | |
984 | } | |
985 | ||
4f37154e | 986 | void wxPostScriptImplDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) |
ed880dd4 | 987 | { |
4f37154e | 988 | DoDrawBitmap( icon, x, y, true ); |
ed880dd4 RR |
989 | } |
990 | ||
d7657f75 RR |
991 | /* this has to be char, not wxChar */ |
992 | static char hexArray[] = "0123456789ABCDEF"; | |
d7657f75 | 993 | |
4f37154e | 994 | void wxPostScriptImplDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool WXUNUSED(useMask) ) |
ed880dd4 | 995 | { |
846051ec | 996 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
ef539066 RR |
997 | |
998 | if (!bitmap.Ok()) return; | |
afce4c03 | 999 | |
368d59f0 | 1000 | wxImage image = bitmap.ConvertToImage(); |
afce4c03 | 1001 | |
ef539066 | 1002 | if (!image.Ok()) return; |
afce4c03 | 1003 | |
b64de916 VS |
1004 | wxCoord w = image.GetWidth(); |
1005 | wxCoord h = image.GetHeight(); | |
1006 | ||
eb7637b5 RR |
1007 | double ww = XLOG2DEVREL(image.GetWidth()); |
1008 | double hh = YLOG2DEVREL(image.GetHeight()); | |
1009 | ||
1010 | double xx = XLOG2DEV(x); | |
1011 | double yy = YLOG2DEV(y + bitmap.GetHeight()); | |
1012 | ||
1013 | wxString buffer; | |
1014 | buffer.Printf( "/origstate save def\n" | |
1015 | "20 dict begin\n" | |
ed838581 RR |
1016 | "/pix %d string def\n" |
1017 | "/grays %d string def\n" | |
eb7637b5 RR |
1018 | "/npixels 0 def\n" |
1019 | "/rgbindx 0 def\n" | |
1020 | "%f %f translate\n" | |
1021 | "%f %f scale\n" | |
ed838581 RR |
1022 | "%d %d 8\n" |
1023 | "[%d 0 0 %d 0 %d]\n" | |
eb7637b5 RR |
1024 | "{currentfile pix readhexstring pop}\n" |
1025 | "false 3 colorimage\n", | |
b64de916 | 1026 | w, w, xx, yy, ww, hh, w, h, w, -h, h ); |
eb7637b5 RR |
1027 | buffer.Replace( ",", "." ); |
1028 | PsPrint( buffer ); | |
244e5e34 VZ |
1029 | |
1030 | unsigned char* data = image.GetData(); | |
1031 | ||
c56ae042 | 1032 | // size of the buffer = width*rgb(3)*hexa(2)+'\n' |
eb7637b5 | 1033 | wxCharBuffer charbuffer(w*6 + 1); |
244e5e34 VZ |
1034 | int firstDigit, secondDigit; |
1035 | ||
1036 | //rows | |
1037 | for (int j = 0; j < h; j++) | |
1038 | { | |
eb7637b5 | 1039 | char* bufferindex = charbuffer.data(); |
244e5e34 VZ |
1040 | |
1041 | //cols | |
1042 | for (int i = 0; i < w*3; i++) | |
ef539066 | 1043 | { |
244e5e34 VZ |
1044 | firstDigit = (int)(*data/16.0); |
1045 | secondDigit = (int)(*data - (firstDigit*16.0)); | |
1046 | *(bufferindex++) = hexArray[firstDigit]; | |
1047 | *(bufferindex++) = hexArray[secondDigit]; | |
1048 | ||
1049 | data++; | |
d7657f75 | 1050 | } |
244e5e34 VZ |
1051 | *(bufferindex++) = '\n'; |
1052 | *bufferindex = 0; | |
84ef8365 | 1053 | |
ed838581 RR |
1054 | if (m_pstream) |
1055 | fwrite( charbuffer, 1, strlen( charbuffer ), m_pstream ); | |
1056 | else | |
1057 | PsPrint( charbuffer ); | |
ef539066 | 1058 | } |
244e5e34 VZ |
1059 | |
1060 | PsPrint( "end\n" ); | |
1061 | PsPrint( "origstate restore\n" ); | |
ed880dd4 RR |
1062 | } |
1063 | ||
4f37154e | 1064 | void wxPostScriptImplDC::SetFont( const wxFont& font ) |
ed880dd4 | 1065 | { |
846051ec | 1066 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 1067 | |
ed880dd4 | 1068 | if (!font.Ok()) return; |
afce4c03 | 1069 | |
ed880dd4 | 1070 | m_font = font; |
57c208c5 | 1071 | |
36b3b54a RR |
1072 | int Style = m_font.GetStyle(); |
1073 | int Weight = m_font.GetWeight(); | |
1074 | ||
733b25e1 | 1075 | const char *name; |
d7657f75 | 1076 | switch (m_font.GetFamily()) |
36b3b54a RR |
1077 | { |
1078 | case wxTELETYPE: | |
1079 | case wxMODERN: | |
733b25e1 RR |
1080 | { |
1081 | if (Style == wxITALIC) | |
1082 | { | |
1083 | if (Weight == wxBOLD) | |
1084 | name = "/Courier-BoldOblique"; | |
1085 | else | |
1086 | name = "/Courier-Oblique"; | |
1087 | } | |
1088 | else | |
1089 | { | |
1090 | if (Weight == wxBOLD) | |
1091 | name = "/Courier-Bold"; | |
1092 | else | |
1093 | name = "/Courier"; | |
1094 | } | |
36b3b54a | 1095 | break; |
733b25e1 | 1096 | } |
36b3b54a | 1097 | case wxROMAN: |
733b25e1 RR |
1098 | { |
1099 | if (Style == wxITALIC) | |
1100 | { | |
1101 | if (Weight == wxBOLD) | |
1102 | name = "/Times-BoldItalic"; | |
1103 | else | |
1104 | name = "/Times-Italic"; | |
1105 | } | |
1106 | else | |
1107 | { | |
1108 | if (Weight == wxBOLD) | |
1109 | name = "/Times-Bold"; | |
1110 | else | |
1111 | name = "/Times-Roman"; | |
1112 | } | |
36b3b54a | 1113 | break; |
733b25e1 | 1114 | } |
36b3b54a | 1115 | case wxSCRIPT: |
733b25e1 RR |
1116 | { |
1117 | name = "/ZapfChancery-MediumItalic"; | |
36b3b54a | 1118 | break; |
733b25e1 RR |
1119 | } |
1120 | case wxSWISS: | |
36b3b54a | 1121 | default: |
733b25e1 RR |
1122 | { |
1123 | if (Style == wxITALIC) | |
1124 | { | |
1125 | if (Weight == wxBOLD) | |
1126 | name = "/Helvetica-BoldOblique"; | |
1127 | else | |
1128 | name = "/Helvetica-Oblique"; | |
1129 | } | |
1130 | else | |
1131 | { | |
1132 | if (Weight == wxBOLD) | |
1133 | name = "/Helvetica-Bold"; | |
1134 | else | |
1135 | name = "/Helvetica"; | |
1136 | } | |
1137 | break; | |
1138 | } | |
36b3b54a | 1139 | } |
57c208c5 | 1140 | |
29402f45 JS |
1141 | // We may legitimately call SetFont before BeginDoc |
1142 | if (!m_pstream) | |
1143 | return; | |
ca65c044 | 1144 | |
244e5e34 VZ |
1145 | PsPrint( name ); |
1146 | PsPrint( " reencodeISO def\n" ); | |
1147 | PsPrint( name ); | |
1148 | PsPrint( " findfont\n" ); | |
ca65c044 | 1149 | |
84ef8365 | 1150 | |
eb7637b5 RR |
1151 | double size = (double) m_font.GetPointSize(); |
1152 | wxString buffer; | |
1153 | buffer.Printf( "%f scalefont setfont\n", size * DEV2PS * m_scaleX ); | |
1154 | buffer.Replace( ",", "." ); | |
244e5e34 | 1155 | PsPrint( buffer ); |
ed880dd4 RR |
1156 | } |
1157 | ||
4f37154e | 1158 | void wxPostScriptImplDC::SetPen( const wxPen& pen ) |
ed880dd4 | 1159 | { |
846051ec | 1160 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 1161 | |
ed880dd4 | 1162 | if (!pen.Ok()) return; |
afce4c03 | 1163 | |
ed880dd4 RR |
1164 | int oldStyle = m_pen.GetStyle(); |
1165 | ||
1166 | m_pen = pen; | |
1167 | ||
eb7637b5 | 1168 | double width; |
84ef8365 | 1169 | |
eb7637b5 RR |
1170 | if (m_pen.GetWidth() <= 0) |
1171 | width = 0.1; | |
1172 | else | |
1173 | width = (double) m_pen.GetWidth(); | |
1174 | ||
1175 | wxString buffer; | |
1176 | buffer.Printf( "%f setlinewidth\n", width * DEV2PS * m_scaleX ); | |
1177 | buffer.Replace( ",", "." ); | |
244e5e34 | 1178 | PsPrint( buffer ); |
f6bcfd97 | 1179 | |
ed880dd4 RR |
1180 | /* |
1181 | Line style - WRONG: 2nd arg is OFFSET | |
afce4c03 | 1182 | |
ed880dd4 RR |
1183 | Here, I'm afraid you do not conceive meaning of parameters of 'setdash' |
1184 | operator correctly. You should look-up this in the Red Book: the 2nd parame- | |
1185 | ter is not number of values in the array of the first one, but an offset | |
1186 | into this description of the pattern. I mean a real *offset* not index | |
1187 | into array. I.e. If the command is [3 4] 1 setdash is used, then there | |
72cdf4c9 | 1188 | will be first black line *2* units wxCoord, then space 4 units, then the |
ed880dd4 RR |
1189 | pattern of *3* units black, 4 units space will be repeated. |
1190 | */ | |
1191 | ||
1192 | static const char *dotted = "[2 5] 2"; | |
1193 | static const char *short_dashed = "[4 4] 2"; | |
72cdf4c9 | 1194 | static const char *wxCoord_dashed = "[4 8] 2"; |
ed880dd4 RR |
1195 | static const char *dotted_dashed = "[6 6 2 6] 4"; |
1196 | ||
999836aa VZ |
1197 | const char *psdash; |
1198 | ||
d7657f75 | 1199 | switch (m_pen.GetStyle()) |
ed880dd4 RR |
1200 | { |
1201 | case wxDOT: psdash = dotted; break; | |
1202 | case wxSHORT_DASH: psdash = short_dashed; break; | |
244e5e34 | 1203 | case wxLONG_DASH: psdash = wxCoord_dashed; break; |
ed880dd4 | 1204 | case wxDOT_DASH: psdash = dotted_dashed; break; |
f081c944 RR |
1205 | case wxUSER_DASH: |
1206 | { | |
1207 | wxDash *dashes; | |
1208 | int nDashes = m_pen.GetDashes (&dashes); | |
1209 | PsPrint ("["); | |
1210 | for (int i = 0; i < nDashes; ++i) | |
1211 | { | |
eb7637b5 | 1212 | buffer.Printf( "%d ", dashes [i] ); |
f081c944 RR |
1213 | PsPrint( buffer ); |
1214 | } | |
1215 | PsPrint ("] 0 setdash\n"); | |
88a7a4e1 WS |
1216 | psdash = 0; |
1217 | } | |
f081c944 | 1218 | break; |
ed880dd4 RR |
1219 | case wxSOLID: |
1220 | case wxTRANSPARENT: | |
1221 | default: psdash = "[] 0"; break; | |
1222 | } | |
afce4c03 | 1223 | |
f081c944 | 1224 | if ( psdash && (oldStyle != m_pen.GetStyle()) ) |
ed880dd4 | 1225 | { |
244e5e34 VZ |
1226 | PsPrint( psdash ); |
1227 | PsPrint( " setdash\n" ); | |
ed880dd4 RR |
1228 | } |
1229 | ||
1230 | // Line colour | |
1231 | unsigned char red = m_pen.GetColour().Red(); | |
1232 | unsigned char blue = m_pen.GetColour().Blue(); | |
1233 | unsigned char green = m_pen.GetColour().Green(); | |
1234 | ||
1235 | if (!m_colour) | |
1236 | { | |
1237 | // Anything not white is black | |
72cdf4c9 VZ |
1238 | if (! (red == (unsigned char) 255 && |
1239 | blue == (unsigned char) 255 && | |
d7657f75 RR |
1240 | green == (unsigned char) 255) ) |
1241 | { | |
1242 | red = (unsigned char) 0; | |
1243 | green = (unsigned char) 0; | |
1244 | blue = (unsigned char) 0; | |
72cdf4c9 | 1245 | } |
d7657f75 | 1246 | // setgray here ? |
ed880dd4 RR |
1247 | } |
1248 | ||
1249 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1250 | { | |
d7657f75 RR |
1251 | double redPS = (double)(red) / 255.0; |
1252 | double bluePS = (double)(blue) / 255.0; | |
1253 | double greenPS = (double)(green) / 255.0; | |
ca65c044 | 1254 | |
eb7637b5 RR |
1255 | wxString buffer; |
1256 | buffer.Printf( "%f %f %f setrgbcolor\n", redPS, greenPS, bluePS ); | |
1257 | buffer.Replace( ",", "." ); | |
244e5e34 | 1258 | PsPrint( buffer ); |
ca65c044 | 1259 | |
d7657f75 RR |
1260 | m_currentRed = red; |
1261 | m_currentBlue = blue; | |
1262 | m_currentGreen = green; | |
ed880dd4 RR |
1263 | } |
1264 | } | |
1265 | ||
4f37154e | 1266 | void wxPostScriptImplDC::SetBrush( const wxBrush& brush ) |
ed880dd4 | 1267 | { |
846051ec | 1268 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 1269 | |
ed880dd4 | 1270 | if (!brush.Ok()) return; |
afce4c03 | 1271 | |
ed880dd4 RR |
1272 | m_brush = brush; |
1273 | ||
1274 | // Brush colour | |
3c1b65a4 RR |
1275 | unsigned char red = m_brush.GetColour().Red(); |
1276 | unsigned char blue = m_brush.GetColour().Blue(); | |
1277 | unsigned char green = m_brush.GetColour().Green(); | |
ed880dd4 RR |
1278 | |
1279 | if (!m_colour) | |
1280 | { | |
d7657f75 | 1281 | // Anything not white is black |
72cdf4c9 VZ |
1282 | if (! (red == (unsigned char) 255 && |
1283 | blue == (unsigned char) 255 && | |
d7657f75 RR |
1284 | green == (unsigned char) 255) ) |
1285 | { | |
1286 | red = (unsigned char) 0; | |
1287 | green = (unsigned char) 0; | |
1288 | blue = (unsigned char) 0; | |
72cdf4c9 | 1289 | } |
d7657f75 | 1290 | // setgray here ? |
ed880dd4 | 1291 | } |
72cdf4c9 | 1292 | |
ed880dd4 RR |
1293 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) |
1294 | { | |
d7657f75 RR |
1295 | double redPS = (double)(red) / 255.0; |
1296 | double bluePS = (double)(blue) / 255.0; | |
1297 | double greenPS = (double)(green) / 255.0; | |
72cdf4c9 | 1298 | |
eb7637b5 RR |
1299 | wxString buffer; |
1300 | buffer.Printf( "%f %f %f setrgbcolor\n", redPS, greenPS, bluePS ); | |
1301 | buffer.Replace( ",", "." ); | |
244e5e34 | 1302 | PsPrint( buffer ); |
72cdf4c9 | 1303 | |
d7657f75 RR |
1304 | m_currentRed = red; |
1305 | m_currentBlue = blue; | |
1306 | m_currentGreen = green; | |
ed880dd4 RR |
1307 | } |
1308 | } | |
1309 | ||
4f37154e | 1310 | void wxPostScriptImplDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) |
ed880dd4 | 1311 | { |
846051ec | 1312 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
479cd5de | 1313 | |
eb7637b5 | 1314 | const wxWX2MBbuf textbuf = text.mb_str(); |
84ef8365 | 1315 | if ( !textbuf ) |
eb7637b5 | 1316 | return; |
84ef8365 | 1317 | |
a148cfb6 RR |
1318 | if (m_textForegroundColour.Ok()) |
1319 | { | |
1320 | unsigned char red = m_textForegroundColour.Red(); | |
1321 | unsigned char blue = m_textForegroundColour.Blue(); | |
1322 | unsigned char green = m_textForegroundColour.Green(); | |
1323 | ||
1324 | if (!m_colour) | |
1325 | { | |
1326 | // Anything not white is black | |
1327 | if (! (red == (unsigned char) 255 && | |
1328 | blue == (unsigned char) 255 && | |
1329 | green == (unsigned char) 255)) | |
1330 | { | |
1331 | red = (unsigned char) 0; | |
1332 | green = (unsigned char) 0; | |
1333 | blue = (unsigned char) 0; | |
1334 | } | |
1335 | } | |
1336 | ||
1337 | // maybe setgray here ? | |
1338 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1339 | { | |
1340 | double redPS = (double)(red) / 255.0; | |
1341 | double bluePS = (double)(blue) / 255.0; | |
1342 | double greenPS = (double)(green) / 255.0; | |
1343 | ||
eb7637b5 RR |
1344 | wxString buffer; |
1345 | buffer.Printf( "%f %f %f setrgbcolor\n", redPS, greenPS, bluePS ); | |
1346 | buffer.Replace( ",", "." ); | |
244e5e34 | 1347 | PsPrint( buffer ); |
a148cfb6 RR |
1348 | |
1349 | m_currentRed = red; | |
1350 | m_currentBlue = blue; | |
1351 | m_currentGreen = green; | |
1352 | } | |
1353 | } | |
a47391f3 | 1354 | |
6c3d9ced | 1355 | wxCoord text_w, text_h, text_descent; |
479cd5de | 1356 | |
4f37154e | 1357 | GetOwner()->GetTextExtent(text, &text_w, &text_h, &text_descent); |
afce4c03 | 1358 | |
ed880dd4 RR |
1359 | int size = m_font.GetPointSize(); |
1360 | ||
6c3d9ced VS |
1361 | // wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline |
1362 | // commented by V. Slavik and replaced by accurate version | |
1363 | // - note that there is still rounding error in text_descent! | |
1364 | wxCoord by = y + size - text_descent; // baseline | |
244e5e34 | 1365 | |
eb7637b5 RR |
1366 | wxString buffer; |
1367 | buffer.Printf( "%f %f moveto\n", XLOG2DEV(x), YLOG2DEV(by) ); | |
1368 | buffer.Replace( ",", "." ); | |
1369 | PsPrint( buffer ); | |
244e5e34 | 1370 | PsPrint( "(" ); |
ca65c044 | 1371 | |
244e5e34 VZ |
1372 | size_t len = strlen(textbuf); |
1373 | size_t i; | |
1374 | for (i = 0; i < len; i++) | |
ed880dd4 | 1375 | { |
244e5e34 VZ |
1376 | int c = (unsigned char) textbuf[i]; |
1377 | if (c == ')' || c == '(' || c == '\\') | |
ed880dd4 | 1378 | { |
244e5e34 VZ |
1379 | /* Cope with special characters */ |
1380 | PsPrint( "\\" ); | |
eb7637b5 | 1381 | PsPrint( (char) c ); |
ed880dd4 | 1382 | } |
244e5e34 | 1383 | else if ( c >= 128 ) |
72cdf4c9 | 1384 | { |
244e5e34 | 1385 | /* Cope with character codes > 127 */ |
eb7637b5 RR |
1386 | buffer.Printf( "\\%o", c ); |
1387 | PsPrint( buffer ); | |
244e5e34 VZ |
1388 | } |
1389 | else | |
1390 | { | |
eb7637b5 | 1391 | PsPrint( (char) c ); |
244e5e34 VZ |
1392 | } |
1393 | } | |
ca65c044 | 1394 | |
244e5e34 | 1395 | PsPrint( ") show\n" ); |
ca65c044 | 1396 | |
244e5e34 VZ |
1397 | if (m_font.GetUnderlined()) |
1398 | { | |
1399 | wxCoord uy = (wxCoord)(y + size - m_underlinePosition); | |
84ef8365 | 1400 | |
eb7637b5 RR |
1401 | buffer.Printf( "gsave\n" |
1402 | "%f %f moveto\n" | |
1403 | "%f setlinewidth\n" | |
1404 | "%f %f lineto\n" | |
1405 | "stroke\n" | |
1406 | "grestore\n", | |
1407 | XLOG2DEV(x), YLOG2DEV(uy), | |
f6bcfd97 | 1408 | m_underlineThickness, |
eb7637b5 RR |
1409 | XLOG2DEV(x + text_w), YLOG2DEV(uy) ); |
1410 | buffer.Replace( ",", "." ); | |
244e5e34 | 1411 | PsPrint( buffer ); |
ed880dd4 | 1412 | } |
afce4c03 | 1413 | |
ed880dd4 | 1414 | CalcBoundingBox( x, y ); |
88a7a4e1 | 1415 | CalcBoundingBox( x + size * text.length() * 2/3 , y ); |
ed880dd4 RR |
1416 | } |
1417 | ||
4f37154e | 1418 | void wxPostScriptImplDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle ) |
95724b1a | 1419 | { |
c77a6796 | 1420 | if ( wxIsNullDouble(angle) ) |
95724b1a VZ |
1421 | { |
1422 | DoDrawText(text, x, y); | |
1423 | return; | |
1424 | } | |
1425 | ||
846051ec | 1426 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
95724b1a VZ |
1427 | |
1428 | SetFont( m_font ); | |
1429 | ||
1430 | if (m_textForegroundColour.Ok()) | |
1431 | { | |
1432 | unsigned char red = m_textForegroundColour.Red(); | |
1433 | unsigned char blue = m_textForegroundColour.Blue(); | |
1434 | unsigned char green = m_textForegroundColour.Green(); | |
1435 | ||
1436 | if (!m_colour) | |
1437 | { | |
1438 | // Anything not white is black | |
479cd5de VZ |
1439 | if (! (red == (unsigned char) 255 && |
1440 | blue == (unsigned char) 255 && | |
1441 | green == (unsigned char) 255)) | |
95724b1a VZ |
1442 | { |
1443 | red = (unsigned char) 0; | |
1444 | green = (unsigned char) 0; | |
1445 | blue = (unsigned char) 0; | |
1446 | } | |
1447 | } | |
1448 | ||
1449 | // maybe setgray here ? | |
1450 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1451 | { | |
1452 | double redPS = (double)(red) / 255.0; | |
1453 | double bluePS = (double)(blue) / 255.0; | |
1454 | double greenPS = (double)(green) / 255.0; | |
479cd5de | 1455 | |
eb7637b5 RR |
1456 | wxString buffer; |
1457 | buffer.Printf( "%f %f %f setrgbcolor\n", redPS, greenPS, bluePS ); | |
1458 | buffer.Replace( ",", "." ); | |
244e5e34 | 1459 | PsPrint( buffer ); |
84ef8365 | 1460 | |
95724b1a VZ |
1461 | m_currentRed = red; |
1462 | m_currentBlue = blue; | |
1463 | m_currentGreen = green; | |
1464 | } | |
1465 | } | |
1466 | ||
1467 | int size = m_font.GetPointSize(); | |
1468 | ||
eb7637b5 RR |
1469 | wxString buffer; |
1470 | buffer.Printf( "%f %f moveto\n", XLOG2DEV(x), YLOG2DEV(y)); | |
1471 | buffer.Replace( ",", "." ); | |
1472 | PsPrint( buffer ); | |
ca65c044 | 1473 | |
eb7637b5 RR |
1474 | buffer.Printf( "%f rotate\n", angle ); |
1475 | buffer.Replace( ",", "." ); | |
1476 | PsPrint( buffer ); | |
ca65c044 | 1477 | |
244e5e34 VZ |
1478 | PsPrint( "(" ); |
1479 | const wxWX2MBbuf textbuf = text.mb_str(); | |
1480 | size_t len = strlen(textbuf); | |
eb7637b5 | 1481 | size_t i; |
244e5e34 VZ |
1482 | for (i = 0; i < len; i++) |
1483 | { | |
1484 | int c = (unsigned char) textbuf[i]; | |
1485 | if (c == ')' || c == '(' || c == '\\') | |
95724b1a | 1486 | { |
244e5e34 VZ |
1487 | /* Cope with special characters */ |
1488 | PsPrint( "\\" ); | |
eb7637b5 | 1489 | PsPrint( (char) c ); |
95724b1a | 1490 | } |
244e5e34 | 1491 | else if ( c >= 128 ) |
479cd5de | 1492 | { |
244e5e34 | 1493 | /* Cope with character codes > 127 */ |
eb7637b5 RR |
1494 | buffer.Printf( "\\%o", c); |
1495 | PsPrint( buffer ); | |
479cd5de | 1496 | } |
244e5e34 | 1497 | else |
846051ec | 1498 | { |
eb7637b5 | 1499 | PsPrint( (char) c ); |
846051ec | 1500 | } |
244e5e34 | 1501 | } |
ca65c044 | 1502 | |
244e5e34 | 1503 | PsPrint( ") show\n" ); |
ca65c044 | 1504 | |
eb7637b5 RR |
1505 | buffer.Printf( "%f rotate\n", -angle ); |
1506 | buffer.Replace( ",", "." ); | |
244e5e34 | 1507 | PsPrint( buffer ); |
ca65c044 | 1508 | |
244e5e34 VZ |
1509 | if (m_font.GetUnderlined()) |
1510 | { | |
1511 | wxCoord uy = (wxCoord)(y + size - m_underlinePosition); | |
1512 | wxCoord w, h; | |
4f37154e | 1513 | GetOwner()->GetTextExtent(text, &w, &h); |
244e5e34 | 1514 | |
84ef8365 | 1515 | buffer.Printf( |
846051ec | 1516 | "gsave\n" |
eb7637b5 | 1517 | "%f %f moveto\n" |
846051ec | 1518 | "%f setlinewidth\n" |
eb7637b5 | 1519 | "%f %f lineto\n" |
846051ec JS |
1520 | "stroke\n" |
1521 | "grestore\n", | |
eb7637b5 | 1522 | XLOG2DEV(x), YLOG2DEV(uy), |
846051ec | 1523 | m_underlineThickness, |
eb7637b5 RR |
1524 | XLOG2DEV(x + w), YLOG2DEV(uy) ); |
1525 | buffer.Replace( ",", "." ); | |
244e5e34 | 1526 | PsPrint( buffer ); |
95724b1a | 1527 | } |
ca65c044 | 1528 | |
95724b1a | 1529 | CalcBoundingBox( x, y ); |
88a7a4e1 | 1530 | CalcBoundingBox( x + size * text.length() * 2/3 , y ); |
95724b1a | 1531 | } |
ed880dd4 | 1532 | |
4f37154e | 1533 | void wxPostScriptImplDC::SetBackground (const wxBrush& brush) |
ed880dd4 RR |
1534 | { |
1535 | m_backgroundBrush = brush; | |
1536 | } | |
1537 | ||
4f37154e | 1538 | void wxPostScriptImplDC::SetLogicalFunction (int WXUNUSED(function)) |
ed880dd4 | 1539 | { |
4f37154e | 1540 | wxFAIL_MSG( wxT("wxPostScriptImplDC::SetLogicalFunction not implemented.") ); |
ed880dd4 RR |
1541 | } |
1542 | ||
389076f1 | 1543 | #if wxUSE_SPLINES |
4f37154e | 1544 | void wxPostScriptImplDC::DoDrawSpline( const wxPointList *points ) |
ed880dd4 | 1545 | { |
846051ec | 1546 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 1547 | |
ed880dd4 RR |
1548 | SetPen( m_pen ); |
1549 | ||
8a39593e | 1550 | // a and b are not used |
846051ec | 1551 | //double a, b; |
8a39593e | 1552 | double c, d, x1, y1, x2, y2, x3, y3; |
ed880dd4 RR |
1553 | wxPoint *p, *q; |
1554 | ||
b0d7707b RR |
1555 | wxPointList::compatibility_iterator node = points->GetFirst(); |
1556 | p = node->GetData(); | |
afce4c03 | 1557 | x1 = p->x; |
ed880dd4 RR |
1558 | y1 = p->y; |
1559 | ||
b1d4dd7a | 1560 | node = node->GetNext(); |
b0d7707b | 1561 | p = node->GetData(); |
afce4c03 | 1562 | c = p->x; |
ed880dd4 | 1563 | d = p->y; |
a47391f3 | 1564 | x3 = |
8a39593e | 1565 | #if 0 |
a47391f3 JS |
1566 | a = |
1567 | #endif | |
8a39593e | 1568 | (double)(x1 + c) / 2; |
a47391f3 | 1569 | y3 = |
8a39593e | 1570 | #if 0 |
a47391f3 JS |
1571 | b = |
1572 | #endif | |
8a39593e | 1573 | (double)(y1 + d) / 2; |
ed880dd4 | 1574 | |
eb7637b5 RR |
1575 | wxString buffer; |
1576 | buffer.Printf( "newpath\n" | |
1577 | "%f %f moveto\n" | |
1578 | "%f %f lineto\n", | |
1579 | XLOG2DEV(wxRound(x1)), YLOG2DEV(wxRound(y1)), | |
1580 | XLOG2DEV(wxRound(x3)), YLOG2DEV(wxRound(y3)) ); | |
1581 | buffer.Replace( ",", "." ); | |
1582 | PsPrint( buffer ); | |
afce4c03 | 1583 | |
72cdf4c9 VZ |
1584 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); |
1585 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
ed880dd4 | 1586 | |
244e5e34 VZ |
1587 | node = node->GetNext(); |
1588 | while (node) | |
ed880dd4 | 1589 | { |
b0d7707b | 1590 | q = node->GetData(); |
ed880dd4 | 1591 | |
d7657f75 RR |
1592 | x1 = x3; |
1593 | y1 = y3; | |
1594 | x2 = c; | |
1595 | y2 = d; | |
1596 | c = q->x; | |
1597 | d = q->y; | |
ed880dd4 RR |
1598 | x3 = (double)(x2 + c) / 2; |
1599 | y3 = (double)(y2 + d) / 2; | |
72cdf4c9 | 1600 | |
eb7637b5 RR |
1601 | buffer.Printf( "%f %f %f %f %f %f DrawSplineSection\n", |
1602 | XLOG2DEV(wxRound(x1)), YLOG2DEV(wxRound(y1)), | |
1603 | XLOG2DEV(wxRound(x2)), YLOG2DEV(wxRound(y2)), | |
1604 | XLOG2DEV(wxRound(x3)), YLOG2DEV(wxRound(y3)) ); | |
1605 | buffer.Replace( ",", "." ); | |
1606 | PsPrint( buffer ); | |
72cdf4c9 VZ |
1607 | |
1608 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1609 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
999836aa VZ |
1610 | |
1611 | node = node->GetNext(); | |
ed880dd4 | 1612 | } |
afce4c03 | 1613 | |
72cdf4c9 VZ |
1614 | /* |
1615 | At this point, (x2,y2) and (c,d) are the position of the | |
1616 | next-to-last and last point respectively, in the point list | |
1617 | */ | |
ed880dd4 | 1618 | |
eb7637b5 RR |
1619 | buffer.Printf( "%f %f lineto\nstroke\n", XLOG2DEV(wxRound(c)), YLOG2DEV(wxRound(d)) ); |
1620 | buffer.Replace( ",", "." ); | |
1621 | PsPrint( buffer ); | |
ed880dd4 | 1622 | } |
389076f1 | 1623 | #endif // wxUSE_SPLINES |
ed880dd4 | 1624 | |
4f37154e | 1625 | wxCoord wxPostScriptImplDC::GetCharWidth() const |
ed880dd4 RR |
1626 | { |
1627 | // Chris Breeze: reasonable approximation using wxMODERN/Courier | |
72cdf4c9 | 1628 | return (wxCoord) (GetCharHeight() * 72.0 / 120.0); |
ed880dd4 RR |
1629 | } |
1630 | ||
4f37154e | 1631 | void wxPostScriptImplDC::SetPrintData(const wxPrintData& data) |
eb7637b5 | 1632 | { |
84ef8365 | 1633 | m_printData = data; |
eb7637b5 RR |
1634 | |
1635 | wxPaperSize id = m_printData.GetPaperId(); | |
1636 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id); | |
1637 | if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); | |
1638 | int w = 595; | |
1639 | int h = 842; | |
1640 | if (paper) | |
1641 | { | |
1642 | w = paper->GetSizeDeviceUnits().x; | |
1643 | h = paper->GetSizeDeviceUnits().y; | |
1644 | } | |
1645 | ||
1646 | if (m_printData.GetOrientation() == wxLANDSCAPE) | |
1647 | m_pageHeight = w * PS2DEV; | |
1648 | else | |
1649 | m_pageHeight = h * PS2DEV; | |
04ab8b6d | 1650 | } |
ed880dd4 | 1651 | |
eb7637b5 RR |
1652 | #if wxUSE_NEW_DC |
1653 | #else | |
4f37154e | 1654 | void wxPostScriptImplDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) |
ed880dd4 | 1655 | { |
eb7637b5 | 1656 | wxDCBase::SetAxisOrientation(xLeftRight,yBottomUp); |
ed880dd4 RR |
1657 | } |
1658 | ||
4f37154e | 1659 | void wxPostScriptImplDC::SetMapMode(int mode) |
ed880dd4 | 1660 | { |
04ab8b6d RR |
1661 | wxDCBase::SetMapMode(mode); |
1662 | } | |
afce4c03 | 1663 | |
4f37154e | 1664 | void wxPostScriptImplDC::SetUserScale(double x, double y) |
04ab8b6d RR |
1665 | { |
1666 | wxDCBase::SetUserScale(x,y); | |
1667 | } | |
afce4c03 | 1668 | |
4f37154e | 1669 | void wxPostScriptImplDC::SetLogicalScale(double x, double y) |
04ab8b6d RR |
1670 | { |
1671 | wxDCBase::SetLogicalScale(x,y); | |
1672 | } | |
1673 | ||
4f37154e | 1674 | void wxPostScriptImplDC::SetLogicalOrigin(wxCoord x, wxCoord y) |
04ab8b6d RR |
1675 | { |
1676 | wxDCBase::SetLogicalOrigin(x,y); | |
1677 | } | |
1678 | ||
4f37154e | 1679 | void wxPostScriptImplDC::SetDeviceOrigin(wxCoord x, wxCoord y) |
04ab8b6d RR |
1680 | { |
1681 | wxDCBase::SetDeviceOrigin(x,y); | |
ed880dd4 | 1682 | } |
eb7637b5 | 1683 | #endif |
ed880dd4 | 1684 | |
4f37154e | 1685 | void wxPostScriptImplDC::ComputeScaleAndOrigin() |
ed838581 RR |
1686 | { |
1687 | const wxRealPoint origScale(m_scaleX, m_scaleY); | |
1688 | ||
1689 | #if wxUSE_NEW_DC | |
1690 | wxImplDC::ComputeScaleAndOrigin(); | |
1691 | #else | |
1692 | wxDC::ComputeScaleAndOrigin(); | |
1693 | #endif | |
1694 | ||
1695 | // If scale has changed call SetPen to recalulate the line width | |
1696 | // and SetFont to recalculate font size | |
1697 | if ( wxRealPoint(m_scaleX, m_scaleY) != origScale && m_pen.IsOk() ) | |
1698 | { | |
1699 | SetPen( m_pen ); | |
1700 | SetFont( m_font ); | |
1701 | } | |
1702 | } | |
1703 | ||
4f37154e | 1704 | void wxPostScriptImplDC::DoGetSize(int* width, int* height) const |
ed880dd4 | 1705 | { |
7bcb11d3 | 1706 | wxPaperSize id = m_printData.GetPaperId(); |
ed880dd4 | 1707 | |
7bcb11d3 | 1708 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id); |
afce4c03 | 1709 | |
7bcb11d3 | 1710 | if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); |
afce4c03 | 1711 | |
ac2def68 RR |
1712 | int w = 595; |
1713 | int h = 842; | |
ed880dd4 RR |
1714 | if (paper) |
1715 | { | |
ac2def68 RR |
1716 | w = paper->GetSizeDeviceUnits().x; |
1717 | h = paper->GetSizeDeviceUnits().y; | |
ed880dd4 | 1718 | } |
72cdf4c9 | 1719 | |
ac2def68 | 1720 | if (m_printData.GetOrientation() == wxLANDSCAPE) |
ed880dd4 | 1721 | { |
ac2def68 | 1722 | int tmp = w; |
72cdf4c9 VZ |
1723 | w = h; |
1724 | h = tmp; | |
ed880dd4 | 1725 | } |
72cdf4c9 | 1726 | |
84ef8365 | 1727 | if (width) |
eb7637b5 | 1728 | *width = wxRound( w * PS2DEV ); |
84ef8365 VZ |
1729 | |
1730 | if (height) | |
eb7637b5 | 1731 | *height = wxRound( h * PS2DEV ); |
ed880dd4 RR |
1732 | } |
1733 | ||
4f37154e | 1734 | void wxPostScriptImplDC::DoGetSizeMM(int *width, int *height) const |
ed880dd4 | 1735 | { |
7bcb11d3 JS |
1736 | wxPaperSize id = m_printData.GetPaperId(); |
1737 | ||
1738 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id); | |
afce4c03 | 1739 | |
7bcb11d3 JS |
1740 | if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); |
1741 | ||
ac2def68 RR |
1742 | int w = 210; |
1743 | int h = 297; | |
7bcb11d3 | 1744 | if (paper) |
ed880dd4 | 1745 | { |
ac2def68 RR |
1746 | w = paper->GetWidth() / 10; |
1747 | h = paper->GetHeight() / 10; | |
ed880dd4 | 1748 | } |
72cdf4c9 | 1749 | |
ac2def68 | 1750 | if (m_printData.GetOrientation() == wxLANDSCAPE) |
ed880dd4 | 1751 | { |
ac2def68 | 1752 | int tmp = w; |
72cdf4c9 VZ |
1753 | w = h; |
1754 | h = tmp; | |
ed880dd4 | 1755 | } |
72cdf4c9 | 1756 | |
ac2def68 RR |
1757 | if (width) *width = w; |
1758 | if (height) *height = h; | |
7bcb11d3 JS |
1759 | } |
1760 | ||
1761 | // Resolution in pixels per logical inch | |
4f37154e | 1762 | wxSize wxPostScriptImplDC::GetPPI(void) const |
7bcb11d3 | 1763 | { |
eb7637b5 | 1764 | return wxSize( DPI, DPI ); |
7bcb11d3 | 1765 | } |
ed880dd4 | 1766 | |
7bcb11d3 | 1767 | |
4f37154e | 1768 | bool wxPostScriptImplDC::StartDoc( const wxString& message ) |
7bcb11d3 | 1769 | { |
ca65c044 | 1770 | wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") ); |
32b13913 | 1771 | |
6038ec8e | 1772 | if (m_printData.GetPrintMode() != wxPRINT_MODE_STREAM ) |
7bcb11d3 | 1773 | { |
ca65c044 | 1774 | if (m_printData.GetFilename() == wxEmptyString) |
244e5e34 VZ |
1775 | { |
1776 | wxString filename = wxGetTempFileName( wxT("ps") ); | |
1777 | m_printData.SetFilename(filename); | |
1778 | } | |
72cdf4c9 | 1779 | |
392857fb | 1780 | m_pstream = wxFopen( m_printData.GetFilename(), wxT("w+") ); |
7bcb11d3 | 1781 | |
244e5e34 VZ |
1782 | if (!m_pstream) |
1783 | { | |
1784 | wxLogError( _("Cannot open file for PostScript printing!")); | |
ca65c044 WS |
1785 | m_ok = false; |
1786 | return false; | |
244e5e34 | 1787 | } |
ed880dd4 | 1788 | } |
afce4c03 | 1789 | |
ca65c044 | 1790 | m_ok = true; |
244e5e34 | 1791 | m_title = message; |
ed880dd4 | 1792 | |
eb7637b5 RR |
1793 | wxString buffer; |
1794 | ||
244e5e34 | 1795 | PsPrint( "%!PS-Adobe-2.0\n" ); |
84ef8365 | 1796 | |
eb7637b5 RR |
1797 | buffer.Printf( "%%%%Title: %s\n", m_title ); |
1798 | PsPrint( buffer ); | |
77ffb593 | 1799 | PsPrint( "%%Creator: wxWidgets PostScript renderer\n" ); |
84ef8365 | 1800 | |
eb7637b5 RR |
1801 | buffer.Printf( "%%%%CreationDate: %s\n", wxNow() ); |
1802 | PsPrint( buffer ); | |
84ef8365 | 1803 | |
eba33006 | 1804 | if (m_printData.GetOrientation() == wxLANDSCAPE) |
244e5e34 | 1805 | PsPrint( "%%Orientation: Landscape\n" ); |
eba33006 | 1806 | else |
244e5e34 | 1807 | PsPrint( "%%Orientation: Portrait\n" ); |
a47391f3 | 1808 | |
244e5e34 | 1809 | const wxChar *paper; |
3fc306e9 RR |
1810 | switch (m_printData.GetPaperId()) |
1811 | { | |
670f9935 WS |
1812 | case wxPAPER_LETTER: paper = wxT("Letter"); break; // Letter: paper ""; 8 1/2 by 11 inches |
1813 | case wxPAPER_LEGAL: paper = wxT("Legal"); break; // Legal, 8 1/2 by 14 inches | |
1814 | case wxPAPER_A4: paper = wxT("A4"); break; // A4 Sheet, 210 by 297 millimeters | |
244e5e34 | 1815 | case wxPAPER_TABLOID: paper = wxT("Tabloid"); break; // Tabloid, 11 by 17 inches |
670f9935 WS |
1816 | case wxPAPER_LEDGER: paper = wxT("Ledger"); break; // Ledger, 17 by 11 inches |
1817 | case wxPAPER_STATEMENT: paper = wxT("Statement"); break; // Statement, 5 1/2 by 8 1/2 inches | |
1818 | case wxPAPER_EXECUTIVE: paper = wxT("Executive"); break; // Executive, 7 1/4 by 10 1/2 inches | |
1819 | case wxPAPER_A3: paper = wxT("A3"); break; // A3 sheet, 297 by 420 millimeters | |
1820 | case wxPAPER_A5: paper = wxT("A5"); break; // A5 sheet, 148 by 210 millimeters | |
1821 | case wxPAPER_B4: paper = wxT("B4"); break; // B4 sheet, 250 by 354 millimeters | |
1822 | case wxPAPER_B5: paper = wxT("B5"); break; // B5 sheet, 182-by-257-millimeter paper | |
1823 | case wxPAPER_FOLIO: paper = wxT("Folio"); break; // Folio, 8-1/2-by-13-inch paper | |
1824 | case wxPAPER_QUARTO: paper = wxT("Quaro"); break; // Quarto, 215-by-275-millimeter paper | |
1825 | case wxPAPER_10X14: paper = wxT("10x14"); break; // 10-by-14-inch sheet | |
244e5e34 | 1826 | default: paper = wxT("A4"); |
3fc306e9 | 1827 | } |
84ef8365 | 1828 | |
eb7637b5 RR |
1829 | buffer.Printf( "%%%%DocumentPaperSizes: %s\n", paper ); |
1830 | PsPrint( buffer ); | |
84ef8365 | 1831 | |
244e5e34 VZ |
1832 | PsPrint( "%%EndComments\n\n" ); |
1833 | ||
1834 | PsPrint( "%%BeginProlog\n" ); | |
1835 | PsPrint( wxPostScriptHeaderConicTo ); | |
1836 | PsPrint( wxPostScriptHeaderEllipse ); | |
1837 | PsPrint( wxPostScriptHeaderEllipticArc ); | |
1838 | PsPrint( wxPostScriptHeaderColourImage ); | |
244e5e34 VZ |
1839 | PsPrint( wxPostScriptHeaderReencodeISO1 ); |
1840 | PsPrint( wxPostScriptHeaderReencodeISO2 ); | |
d7657f75 | 1841 | if (wxPostScriptHeaderSpline) |
244e5e34 VZ |
1842 | PsPrint( wxPostScriptHeaderSpline ); |
1843 | PsPrint( "%%EndProlog\n" ); | |
d7657f75 | 1844 | |
ed880dd4 RR |
1845 | SetBrush( *wxBLACK_BRUSH ); |
1846 | SetPen( *wxBLACK_PEN ); | |
1847 | SetBackground( *wxWHITE_BRUSH ); | |
1848 | SetTextForeground( *wxBLACK ); | |
1849 | ||
1850 | // set origin according to paper size | |
1851 | SetDeviceOrigin( 0,0 ); | |
afce4c03 | 1852 | |
ed880dd4 | 1853 | m_pageNumber = 1; |
ca65c044 | 1854 | return true; |
ed880dd4 RR |
1855 | } |
1856 | ||
4f37154e | 1857 | void wxPostScriptImplDC::EndDoc () |
ed880dd4 | 1858 | { |
244e5e34 | 1859 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 1860 | |
ed880dd4 RR |
1861 | if (m_clipping) |
1862 | { | |
ca65c044 | 1863 | m_clipping = false; |
244e5e34 | 1864 | PsPrint( "grestore\n" ); |
ed880dd4 RR |
1865 | } |
1866 | ||
244e5e34 VZ |
1867 | if ( m_pstream ) { |
1868 | fclose( m_pstream ); | |
1869 | m_pstream = (FILE *) NULL; | |
1870 | } | |
ed880dd4 | 1871 | |
a47391f3 | 1872 | #if 0 |
ed880dd4 | 1873 | // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com> |
72cdf4c9 | 1874 | wxCoord wx_printer_translate_x, wx_printer_translate_y; |
ed880dd4 | 1875 | double wx_printer_scale_x, wx_printer_scale_y; |
ed880dd4 | 1876 | |
479cd5de VZ |
1877 | wx_printer_translate_x = (wxCoord)m_printData.GetPrinterTranslateX(); |
1878 | wx_printer_translate_y = (wxCoord)m_printData.GetPrinterTranslateY(); | |
7bcb11d3 JS |
1879 | |
1880 | wx_printer_scale_x = m_printData.GetPrinterScaleX(); | |
1881 | wx_printer_scale_y = m_printData.GetPrinterScaleY(); | |
1882 | ||
ed880dd4 RR |
1883 | // Compute the bounding box. Note that it is in the default user |
1884 | // coordinate system, thus we have to convert the values. | |
eb7637b5 RR |
1885 | wxCoord minX = (wxCoord) XLOG2DEV(m_minX); |
1886 | wxCoord minY = (wxCoord) YLOG2DEV(m_minY); | |
1887 | wxCoord maxX = (wxCoord) XLOG2DEV(m_maxX); | |
1888 | wxCoord maxY = (wxCoord) YLOG2DEV(m_maxY); | |
48c31b28 | 1889 | |
a30f8da8 VS |
1890 | // LOG2DEV may have changed the minimum to maximum vice versa |
1891 | if ( minX > maxX ) { wxCoord tmp = minX; minX = maxX; maxX = tmp; } | |
1892 | if ( minY > maxY ) { wxCoord tmp = minY; minY = maxY; maxY = tmp; } | |
48c31b28 | 1893 | |
a30f8da8 VS |
1894 | // account for used scaling (boundingbox is before scaling in ps-file) |
1895 | double scale_x = m_printData.GetPrinterScaleX() / ms_PSScaleFactor; | |
1896 | double scale_y = m_printData.GetPrinterScaleY() / ms_PSScaleFactor; | |
48c31b28 VZ |
1897 | |
1898 | wxCoord llx, lly, urx, ury; | |
a30f8da8 VS |
1899 | llx = (wxCoord) ((minX+wx_printer_translate_x)*scale_x); |
1900 | lly = (wxCoord) ((minY+wx_printer_translate_y)*scale_y); | |
1901 | urx = (wxCoord) ((maxX+wx_printer_translate_x)*scale_x); | |
1902 | ury = (wxCoord) ((maxY+wx_printer_translate_y)*scale_y); | |
1903 | // (end of bounding box computation) | |
1904 | ||
ed880dd4 RR |
1905 | |
1906 | // If we're landscape, our sense of "x" and "y" is reversed. | |
7bcb11d3 | 1907 | if (m_printData.GetOrientation() == wxLANDSCAPE) |
ed880dd4 | 1908 | { |
72cdf4c9 | 1909 | wxCoord tmp; |
ed880dd4 RR |
1910 | tmp = llx; llx = lly; lly = tmp; |
1911 | tmp = urx; urx = ury; ury = tmp; | |
1912 | ||
1913 | // We need either the two lines that follow, or we need to subtract | |
1914 | // min_x from real_translate_y, which is commented out below. | |
72cdf4c9 VZ |
1915 | llx = llx - (wxCoord)(m_minX*wx_printer_scale_y); |
1916 | urx = urx - (wxCoord)(m_minX*wx_printer_scale_y); | |
ed880dd4 RR |
1917 | } |
1918 | ||
1919 | // The Adobe specifications call for integers; we round as to make | |
1920 | // the bounding larger. | |
244e5e34 | 1921 | PsPrintf( wxT("%%%%BoundingBox: %d %d %d %d\n"), |
72cdf4c9 VZ |
1922 | (wxCoord)floor((double)llx), (wxCoord)floor((double)lly), |
1923 | (wxCoord)ceil((double)urx), (wxCoord)ceil((double)ury) ); | |
ed880dd4 RR |
1924 | |
1925 | // To check the correctness of the bounding box, postscript commands | |
1926 | // to draw a box corresponding to the bounding box are generated below. | |
1927 | // But since we typically don't want to print such a box, the postscript | |
1928 | // commands are generated within comments. These lines appear before any | |
1929 | // adjustment of scale, rotation, or translation, and hence are in the | |
1930 | // default user coordinates. | |
244e5e34 VZ |
1931 | PsPrint( "% newpath\n" ); |
1932 | PsPrintf( wxT("%% %d %d moveto\n"), llx, lly ); | |
1933 | PsPrintf( wxT("%% %d %d lineto\n"), urx, lly ); | |
1934 | PsPrintf( wxT("%% %d %d lineto\n"), urx, ury ); | |
1935 | PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx, ury ); | |
09c9194a | 1936 | #endif |
ed880dd4 | 1937 | |
8850cbd3 | 1938 | #ifndef __WXMSW__ |
32b13913 | 1939 | wxPostScriptPrintNativeData *data = |
8850cbd3 RR |
1940 | (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); |
1941 | ||
6038ec8e | 1942 | if (m_ok && (m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER)) |
ed880dd4 | 1943 | { |
09c9194a | 1944 | wxString command; |
8850cbd3 | 1945 | command += data->GetPrinterCommand(); |
09c9194a | 1946 | command += wxT(" "); |
8850cbd3 | 1947 | command += data->GetPrinterOptions(); |
cb27bab1 | 1948 | command += wxT(" "); |
09c9194a | 1949 | command += m_printData.GetFilename(); |
ed880dd4 | 1950 | |
ca65c044 | 1951 | wxExecute( command, true ); |
09c9194a | 1952 | wxRemoveFile( m_printData.GetFilename() ); |
ed880dd4 RR |
1953 | } |
1954 | #endif | |
1955 | } | |
1956 | ||
4f37154e | 1957 | void wxPostScriptImplDC::StartPage() |
ed880dd4 | 1958 | { |
846051ec | 1959 | wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); |
afce4c03 | 1960 | |
eb7637b5 RR |
1961 | wxString buffer; |
1962 | buffer.Printf( wxT("%%%%Page: %d\n"), m_pageNumber++ ); | |
1963 | PsPrint( buffer ); | |
afce4c03 | 1964 | |
eb7637b5 | 1965 | #if 0 |
32b13913 | 1966 | wxPostScriptPrintNativeData *data = |
8850cbd3 RR |
1967 | (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); |
1968 | ||
eb7637b5 RR |
1969 | wxCoord translate_x = (wxCoord)data->GetPrinterTranslateX(); |
1970 | wxCoord translate_y = (wxCoord)data->GetPrinterTranslateY(); | |
7bcb11d3 | 1971 | |
eb7637b5 RR |
1972 | buffer.Printf( "%d %d translate\n", translate_x, translate_y ); |
1973 | PsPrint( buffer ); | |
84ef8365 | 1974 | |
eb7637b5 RR |
1975 | double scale_x = data->GetPrinterScaleX(); |
1976 | double scale_y = data->GetPrinterScaleY(); | |
84ef8365 | 1977 | |
eb7637b5 RR |
1978 | buffer.Printf( "%f %f scale\n", scale_x, scale_y ); |
1979 | buffer.Replace( ",", "." ); | |
1980 | PsPrint( buffer ); | |
84ef8365 | 1981 | |
eb7637b5 | 1982 | #endif |
7bcb11d3 | 1983 | |
eb7637b5 | 1984 | // Each page starts with an "initgraphics" which resets the |
84ef8365 | 1985 | // transformation and so we need to rotate the page for |
eb7637b5 RR |
1986 | // landscape printing) |
1987 | ||
1988 | // I copied this one from a PostScript tutorial, but to no avail. RR. | |
1989 | // PsPrint( "90 rotate llx neg ury nef translate\n" ); | |
84ef8365 | 1990 | |
7bcb11d3 | 1991 | if (m_printData.GetOrientation() == wxLANDSCAPE) |
244e5e34 | 1992 | PsPrint( "90 rotate\n" ); |
ed880dd4 RR |
1993 | } |
1994 | ||
4f37154e | 1995 | void wxPostScriptImplDC::EndPage () |
ed880dd4 | 1996 | { |
846051ec | 1997 | wxCHECK_RET( m_ok , wxT("invalid postscript dc") ); |
afce4c03 | 1998 | |
244e5e34 | 1999 | PsPrint( "showpage\n" ); |
ed880dd4 RR |
2000 | } |
2001 | ||
4f37154e | 2002 | bool wxPostScriptImplDC::DoBlit( wxCoord xdest, wxCoord ydest, |
72cdf4c9 | 2003 | wxCoord fwidth, wxCoord fheight, |
afce4c03 | 2004 | wxDC *source, |
72cdf4c9 | 2005 | wxCoord xsrc, wxCoord ysrc, |
f0a6b1cd | 2006 | int rop, bool WXUNUSED(useMask), wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask) ) |
ed880dd4 | 2007 | { |
ca65c044 | 2008 | wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") ); |
afce4c03 | 2009 | |
ca65c044 | 2010 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
afce4c03 | 2011 | |
4f37154e | 2012 | // blit into a bitmap |
afce4c03 | 2013 | wxBitmap bitmap( (int)fwidth, (int)fheight ); |
45b776d4 JS |
2014 | wxMemoryDC memDC; |
2015 | memDC.SelectObject(bitmap); | |
342b6a2f | 2016 | memDC.Blit(0, 0, fwidth, fheight, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ |
45b776d4 | 2017 | memDC.SelectObject(wxNullBitmap); |
ea6f44b5 | 2018 | |
4f37154e RR |
2019 | //draw bitmap. scaling and positioning is done there |
2020 | GetOwner()->DrawBitmap( bitmap, xdest, ydest ); | |
afce4c03 | 2021 | |
ca65c044 | 2022 | return true; |
ed880dd4 RR |
2023 | } |
2024 | ||
4f37154e | 2025 | wxCoord wxPostScriptImplDC::GetCharHeight() const |
ed880dd4 RR |
2026 | { |
2027 | if (m_font.Ok()) | |
b64de916 | 2028 | return m_font.GetPointSize(); |
ed880dd4 RR |
2029 | else |
2030 | return 12; | |
2031 | } | |
2032 | ||
4f37154e | 2033 | void wxPostScriptImplDC::PsPrint( const wxString& str ) |
eb7637b5 RR |
2034 | { |
2035 | const wxCharBuffer psdata(str.utf8_str()); | |
2036 | ||
2037 | wxPostScriptPrintNativeData *data = | |
2038 | (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); | |
2039 | ||
2040 | switch (m_printData.GetPrintMode()) | |
2041 | { | |
2042 | #if wxUSE_STREAMS | |
2043 | // append to output stream | |
2044 | case wxPRINT_MODE_STREAM: | |
2045 | { | |
2046 | wxOutputStream* outputstream = data->GetOutputStream(); | |
2047 | wxCHECK_RET( outputstream, wxT("invalid outputstream") ); | |
2048 | outputstream->Write( psdata, strlen( psdata ) ); | |
2049 | } | |
2050 | break; | |
2051 | #endif // wxUSE_STREAMS | |
2052 | ||
2053 | // save data into file | |
2054 | default: | |
2055 | wxCHECK_RET( m_pstream, wxT("invalid postscript dc") ); | |
2056 | fwrite( psdata, 1, strlen( psdata ), m_pstream ); | |
2057 | } | |
2058 | } | |
2059 | ||
4f37154e | 2060 | void wxPostScriptImplDC::DoGetTextExtent(const wxString& string, |
72cdf4c9 VZ |
2061 | wxCoord *x, wxCoord *y, |
2062 | wxCoord *descent, wxCoord *externalLeading, | |
c94f845b | 2063 | const wxFont *theFont ) const |
ed880dd4 | 2064 | { |
c94f845b | 2065 | const wxFont *fontToUse = theFont; |
afce4c03 | 2066 | |
c94f845b | 2067 | if (!fontToUse) fontToUse = &m_font; |
36b3b54a | 2068 | |
223d09f6 | 2069 | wxCHECK_RET( fontToUse, wxT("GetTextExtent: no font defined") ); |
87138c52 | 2070 | |
32b13913 | 2071 | if (string.empty()) |
3fc306e9 RR |
2072 | { |
2073 | if (x) (*x) = 0; | |
2074 | if (y) (*y) = 0; | |
272995af JS |
2075 | if (descent) (*descent) = 0; |
2076 | if (externalLeading) (*externalLeading) = 0; | |
3fc306e9 RR |
2077 | return; |
2078 | } | |
a47391f3 | 2079 | |
3fc306e9 RR |
2080 | // GTK 2.0 |
2081 | ||
9626e0bf | 2082 | const wxWX2MBbuf strbuf = string.mb_str(); |
84ef8365 | 2083 | |
eb7637b5 | 2084 | // conversion failed (non e.g. ISO characters) |
84ef8365 | 2085 | if ( !strbuf ) |
eb7637b5 | 2086 | return; |
ed880dd4 | 2087 | |
f036b31c | 2088 | #if !wxUSE_AFM_FOR_POSTSCRIPT |
36b3b54a RR |
2089 | /* Provide a VERY rough estimate (avoid using it). |
2090 | * Produces accurate results for mono-spaced font | |
2091 | * such as Courier (aka wxMODERN) */ | |
afce4c03 | 2092 | |
9a6be59a VZ |
2093 | int height = 12; |
2094 | if (fontToUse) | |
2095 | { | |
afce4c03 | 2096 | height = fontToUse->GetPointSize(); |
9a6be59a | 2097 | } |
72cdf4c9 VZ |
2098 | if ( x ) |
2099 | *x = strlen (strbuf) * height * 72 / 120; | |
2100 | if ( y ) | |
2101 | *y = (wxCoord) (height * 1.32); /* allow for descender */ | |
36b3b54a RR |
2102 | if (descent) *descent = 0; |
2103 | if (externalLeading) *externalLeading = 0; | |
ed880dd4 | 2104 | #else |
ed880dd4 | 2105 | |
afce4c03 VZ |
2106 | /* method for calculating string widths in postscript: |
2107 | / read in the AFM (adobe font metrics) file for the | |
2108 | / actual font, parse it and extract the character widths | |
2109 | / and also the descender. this may be improved, but for now | |
2110 | / it works well. the AFM file is only read in if the | |
2111 | / font is changed. this may be chached in the future. | |
2112 | / calls to GetTextExtent with the font unchanged are rather | |
2113 | / efficient!!! | |
2114 | / | |
2115 | / for each font and style used there is an AFM file necessary. | |
2116 | / currently i have only files for the roman font family. | |
2117 | / I try to get files for the other ones! | |
2118 | / | |
2119 | / CAVE: the size of the string is currently always calculated | |
2120 | / in 'points' (1/72 of an inch). this should later on be | |
2121 | / changed to depend on the mapping mode. | |
2122 | / CAVE: the path to the AFM files must be set before calling this | |
eb7637b5 | 2123 | / fun3B3Bction. this is usually done by a call like the following: |
afce4c03 VZ |
2124 | / wxSetAFMPath("d:\\wxw161\\afm\\"); |
2125 | / | |
2126 | / example: | |
2127 | / | |
ca65c044 | 2128 | / wxPostScriptDC dc(NULL, true); |
afce4c03 VZ |
2129 | / if (dc.Ok()){ |
2130 | / wxSetAFMPath("d:\\wxw161\\afm\\"); | |
2131 | / dc.StartDoc("Test"); | |
2132 | / dc.StartPage(); | |
72cdf4c9 | 2133 | / wxCoord w,h; |
afce4c03 VZ |
2134 | / dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL)); |
2135 | / dc.GetTextExtent("Hallo",&w,&h); | |
2136 | / dc.EndPage(); | |
2137 | / dc.EndDoc(); | |
2138 | / } | |
2139 | / | |
2140 | / by steve (stefan.hammes@urz.uni-heidelberg.de) | |
2141 | / created: 10.09.94 | |
2142 | / updated: 14.05.95 */ | |
36b3b54a RR |
2143 | |
2144 | /* these static vars are for storing the state between calls */ | |
2145 | static int lastFamily= INT_MIN; | |
2146 | static int lastSize= INT_MIN; | |
2147 | static int lastStyle= INT_MIN; | |
2148 | static int lastWeight= INT_MIN; | |
2149 | static int lastDescender = INT_MIN; | |
2150 | static int lastWidths[256]; /* widths of the characters */ | |
72cdf4c9 | 2151 | |
a439ecef VS |
2152 | double UnderlinePosition = 0.0; |
2153 | double UnderlineThickness = 0.0; | |
36b3b54a | 2154 | |
eba33006 | 2155 | // Get actual parameters |
733b25e1 RR |
2156 | int Family = fontToUse->GetFamily(); |
2157 | int Size = fontToUse->GetPointSize(); | |
2158 | int Style = fontToUse->GetStyle(); | |
2159 | int Weight = fontToUse->GetWeight(); | |
36b3b54a | 2160 | |
eba33006 | 2161 | // If we have another font, read the font-metrics |
36b3b54a RR |
2162 | if (Family!=lastFamily || Size!=lastSize || Style!=lastStyle || Weight!=lastWeight) |
2163 | { | |
eba33006 | 2164 | // Store actual values |
36b3b54a RR |
2165 | lastFamily = Family; |
2166 | lastSize = Size; | |
2167 | lastStyle = Style; | |
2168 | lastWeight = Weight; | |
2169 | ||
999836aa | 2170 | const wxChar *name; |
36b3b54a RR |
2171 | |
2172 | switch (Family) | |
afce4c03 VZ |
2173 | { |
2174 | case wxMODERN: | |
733b25e1 RR |
2175 | case wxTELETYPE: |
2176 | { | |
2b5f62a0 VZ |
2177 | if ((Style == wxITALIC) && (Weight == wxBOLD)) name = wxT("CourBoO.afm"); |
2178 | else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = wxT("CourBo.afm"); | |
2179 | else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = wxT("CourO.afm"); | |
2180 | else name = wxT("Cour.afm"); | |
afce4c03 | 2181 | break; |
733b25e1 | 2182 | } |
afce4c03 | 2183 | case wxROMAN: |
733b25e1 | 2184 | { |
2b5f62a0 VZ |
2185 | if ((Style == wxITALIC) && (Weight == wxBOLD)) name = wxT("TimesBoO.afm"); |
2186 | else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = wxT("TimesBo.afm"); | |
2187 | else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = wxT("TimesO.afm"); | |
2188 | else name = wxT("TimesRo.afm"); | |
afce4c03 | 2189 | break; |
733b25e1 RR |
2190 | } |
2191 | case wxSCRIPT: | |
2192 | { | |
2b5f62a0 | 2193 | name = wxT("Zapf.afm"); |
999836aa | 2194 | break; |
733b25e1 RR |
2195 | } |
2196 | case wxSWISS: | |
afce4c03 | 2197 | default: |
733b25e1 | 2198 | { |
2b5f62a0 VZ |
2199 | if ((Style == wxITALIC) && (Weight == wxBOLD)) name = wxT("HelvBoO.afm"); |
2200 | else if ((Style != wxITALIC) && (Weight == wxBOLD)) name = wxT("HelvBo.afm"); | |
2201 | else if ((Style == wxITALIC) && (Weight != wxBOLD)) name = wxT("HelvO.afm"); | |
2202 | else name = wxT("Helv.afm"); | |
afce4c03 | 2203 | break; |
733b25e1 | 2204 | } |
afce4c03 | 2205 | } |
36b3b54a | 2206 | |
eba33006 | 2207 | FILE *afmFile = NULL; |
a47391f3 | 2208 | |
d36d1be9 VZ |
2209 | // Get the directory of the AFM files |
2210 | wxString afmName; | |
2211 | ||
2212 | // VZ: I don't know if the cast always works under Unix but it clearly | |
2213 | // never does under Windows where the pointer is | |
2214 | // wxWindowsPrintNativeData and so calling GetFontMetricPath() on | |
2215 | // it just crashes | |
2216 | #ifndef __WIN32__ | |
32b13913 | 2217 | wxPostScriptPrintNativeData *data = |
398c701f | 2218 | wxDynamicCast(m_printData.GetNativeData(), wxPostScriptPrintNativeData); |
32b13913 | 2219 | |
398c701f | 2220 | if (data && !data->GetFontMetricPath().empty()) |
72cdf4c9 | 2221 | { |
8850cbd3 | 2222 | afmName = data->GetFontMetricPath(); |
eba33006 | 2223 | afmName << wxFILE_SEP_PATH << name; |
d361e74e | 2224 | } |
d36d1be9 | 2225 | #endif // __WIN32__ |
72cdf4c9 | 2226 | |
d36d1be9 VZ |
2227 | if ( !afmName.empty() ) |
2228 | afmFile = wxFopen(afmName, wxT("r")); | |
2229 | ||
d36d1be9 VZ |
2230 | if ( !afmFile ) |
2231 | { | |
2232 | #if defined(__UNIX__) && !defined(__VMS__) | |
2c18f21d | 2233 | afmName = wxGetDataDir(); |
d36d1be9 VZ |
2234 | #else // !__UNIX__ |
2235 | afmName = wxStandardPaths::Get().GetDataDir(); | |
2236 | #endif // __UNIX__/!__UNIX__ | |
2237 | ||
3e469ea3 | 2238 | afmName << wxFILE_SEP_PATH |
733b25e1 RR |
2239 | #if defined(__LINUX__) || defined(__FREEBSD__) |
2240 | << wxT("gs_afm") << wxFILE_SEP_PATH | |
2241 | #else | |
021e0f21 | 2242 | << wxT("afm") << wxFILE_SEP_PATH |
733b25e1 RR |
2243 | #endif |
2244 | << name; | |
392857fb | 2245 | afmFile = wxFopen(afmName,wxT("r")); |
3e469ea3 | 2246 | } |
479cd5de | 2247 | |
eba33006 RR |
2248 | /* 2. open and process the file |
2249 | / a short explanation of the AFM format: | |
2250 | / we have for each character a line, which gives its size | |
2251 | / e.g.: | |
2252 | / | |
2253 | / C 63 ; WX 444 ; N question ; B 49 -14 395 676 ; | |
2254 | / | |
2255 | / that means, we have a character with ascii code 63, and width | |
2256 | / (444/1000 * fontSize) points. | |
2257 | / the other data is ignored for now! | |
2258 | / | |
2259 | / when the font has changed, we read in the right AFM file and store the | |
2260 | / character widths in an array, which is processed below (see point 3.). */ | |
385bcb35 | 2261 | if (afmFile==NULL) |
36b3b54a | 2262 | { |
ccbfa8ec | 2263 | wxLogDebug( wxT("GetTextExtent: can't open AFM file '%s'"), afmName.c_str() ); |
48c31b28 | 2264 | wxLogDebug( wxT(" using approximate values")); |
36b3b54a RR |
2265 | for (int i=0; i<256; i++) lastWidths[i] = 500; /* an approximate value */ |
2266 | lastDescender = -150; /* dito. */ | |
ed880dd4 | 2267 | } |
afce4c03 VZ |
2268 | else |
2269 | { | |
36b3b54a RR |
2270 | /* init the widths array */ |
2271 | for(int i=0; i<256; i++) lastWidths[i] = INT_MIN; | |
2272 | /* some variables for holding parts of a line */ | |
32b13913 WS |
2273 | char cString[10], semiString[10], WXString[10]; |
2274 | char descString[20]; | |
2275 | char upString[30], utString[30]; | |
2276 | char encString[50]; | |
36b3b54a RR |
2277 | char line[256]; |
2278 | int ascii,cWidth; | |
2279 | /* read in the file and parse it */ | |
2280 | while(fgets(line,sizeof(line),afmFile)!=NULL) | |
afce4c03 | 2281 | { |
36b3b54a | 2282 | /* A.) check for descender definition */ |
021e0f21 | 2283 | if (strncmp(line,"Descender",9)==0) |
afce4c03 | 2284 | { |
36b3b54a | 2285 | if ((sscanf(line,"%s%d",descString,&lastDescender)!=2) || |
021e0f21 | 2286 | (strcmp(descString,"Descender")!=0)) |
afce4c03 | 2287 | { |
ccbfa8ec | 2288 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad descender)"), afmName.c_str(),line ); |
36b3b54a RR |
2289 | } |
2290 | } | |
2291 | /* JC 1.) check for UnderlinePosition */ | |
021e0f21 | 2292 | else if(strncmp(line,"UnderlinePosition",17)==0) |
afce4c03 | 2293 | { |
36b3b54a | 2294 | if ((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) || |
021e0f21 | 2295 | (strcmp(upString,"UnderlinePosition")!=0)) |
afce4c03 | 2296 | { |
ccbfa8ec | 2297 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlinePosition)"), afmName.c_str(), line ); |
36b3b54a RR |
2298 | } |
2299 | } | |
afce4c03 | 2300 | /* JC 2.) check for UnderlineThickness */ |
021e0f21 | 2301 | else if(strncmp(line,"UnderlineThickness",18)==0) |
afce4c03 | 2302 | { |
36b3b54a | 2303 | if ((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) || |
021e0f21 | 2304 | (strcmp(utString,"UnderlineThickness")!=0)) |
afce4c03 | 2305 | { |
ccbfa8ec | 2306 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad UnderlineThickness)"), afmName.c_str(), line ); |
36b3b54a RR |
2307 | } |
2308 | } | |
afce4c03 | 2309 | /* JC 3.) check for EncodingScheme */ |
021e0f21 | 2310 | else if(strncmp(line,"EncodingScheme",14)==0) |
afce4c03 | 2311 | { |
36b3b54a | 2312 | if ((sscanf(line,"%s%s",utString,encString)!=2) || |
021e0f21 | 2313 | (strcmp(utString,"EncodingScheme")!=0)) |
afce4c03 | 2314 | { |
ccbfa8ec | 2315 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (bad EncodingScheme)"), afmName.c_str(), line ); |
36b3b54a | 2316 | } |
021e0f21 | 2317 | else if (strncmp(encString, "AdobeStandardEncoding", 21)) |
36b3b54a | 2318 | { |
ccbfa8ec | 2319 | wxLogDebug( wxT("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)"), |
3e469ea3 | 2320 | afmName.c_str(),line, encString); |
36b3b54a RR |
2321 | } |
2322 | } | |
2323 | /* B.) check for char-width */ | |
021e0f21 | 2324 | else if(strncmp(line,"C ",2)==0) |
afce4c03 | 2325 | { |
36b3b54a | 2326 | if (sscanf(line,"%s%d%s%s%d",cString,&ascii,semiString,WXString,&cWidth)!=5) |
afce4c03 | 2327 | { |
ccbfa8ec | 2328 | wxLogDebug(wxT("AFM-file '%s': line '%s' has an error (bad character width)"),afmName.c_str(),line); |
36b3b54a | 2329 | } |
021e0f21 | 2330 | if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 || strcmp(WXString,"WX")!=0) |
afce4c03 | 2331 | { |
ccbfa8ec | 2332 | wxLogDebug(wxT("AFM-file '%s': line '%s' has a format error"),afmName.c_str(),line); |
36b3b54a RR |
2333 | } |
2334 | /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */ | |
2335 | if (ascii>=0 && ascii<256) | |
afce4c03 | 2336 | { |
36b3b54a RR |
2337 | lastWidths[ascii] = cWidth; /* store width */ |
2338 | } | |
afce4c03 VZ |
2339 | else |
2340 | { | |
2341 | /* MATTHEW: this happens a lot; don't print an error */ | |
48c31b28 | 2342 | /* wxLogDebug("AFM-file '%s': ASCII value %d out of range",afmName.c_str(),ascii); */ |
36b3b54a RR |
2343 | } |
2344 | } | |
2345 | /* C.) ignore other entries. */ | |
2346 | } | |
2347 | fclose(afmFile); | |
ed880dd4 | 2348 | } |
36b3b54a | 2349 | /* hack to compute correct values for german 'Umlaute' |
afce4c03 VZ |
2350 | / the correct way would be to map the character names |
2351 | / like 'adieresis' to corresp. positions of ISOEnc and read | |
2352 | / these values from AFM files, too. Maybe later ... */ | |
b52e49f5 VZ |
2353 | |
2354 | // NB: casts to int are needed to suppress gcc 3.3 warnings | |
2355 |