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