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