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