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