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