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