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