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