]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: postscrp.cpp | |
3 | // Purpose: wxPostScriptDC implementation | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "postscrp.h" | |
14 | #pragma implementation | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | // For compilers that support precompilation, includes "wx.h". | |
19 | #include "wx/wxprec.h" | |
20 | ||
21 | #ifdef __BORLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
25 | #include "wx/defs.h" | |
26 | ||
47d67540 | 27 | #if wxUSE_POSTSCRIPT |
c801d85f KB |
28 | |
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/intl.h" | |
31 | #include "wx/frame.h" | |
32 | #include "wx/postscrp.h" | |
33 | #include "wx/utils.h" | |
34 | #include "wx/filedlg.h" | |
35 | #include "wx/msgdlg.h" | |
36 | #include "wx/app.h" | |
37 | #include "wx/button.h" | |
38 | #include "wx/radiobox.h" | |
39 | #include "wx/textctrl.h" | |
40 | #include "wx/stattext.h" | |
41 | #include "wx/icon.h" | |
42 | #include "wx/list.h" | |
43 | #endif | |
44 | ||
45 | #include "wx/dcmemory.h" | |
46 | ||
2049ba38 | 47 | #ifdef __WXMSW__ |
c801d85f KB |
48 | #include "wx/msw/private.h" |
49 | #endif | |
50 | ||
47d67540 | 51 | #if wxUSE_IOSTREAMH |
c801d85f | 52 | #include <iostream.h> |
fbc535ff | 53 | #include <fstream.h> |
c801d85f KB |
54 | #else |
55 | #include <iostream> | |
fbc535ff JS |
56 | #include <fstream> |
57 | # ifdef _MSC_VER | |
58 | using namespace std; | |
59 | # endif | |
c801d85f KB |
60 | #endif |
61 | ||
c801d85f KB |
62 | #include <math.h> |
63 | #include <stdio.h> | |
64 | #include <stdlib.h> | |
65 | #include <string.h> | |
66 | #include <limits.h> | |
67 | #include <assert.h> | |
68 | ||
2049ba38 | 69 | #ifdef __WXGTK__ |
c801d85f KB |
70 | |
71 | #include "gdk/gdkx.h" // GDK_DISPLAY | |
72 | #include "gdk/gdkprivate.h" // XImage | |
73 | #include <X11/Xlib.h> | |
74 | #include <X11/Xutil.h> | |
75 | ||
76 | #endif | |
77 | ||
46ccb510 JS |
78 | #ifdef __WXMOTIF__ |
79 | #include <X11/Xlib.h> | |
80 | #include <X11/Xutil.h> | |
81 | #endif | |
82 | ||
2049ba38 | 83 | #ifdef __WXMSW__ |
c801d85f KB |
84 | |
85 | #ifdef DrawText | |
86 | #undef DrawText | |
87 | #endif | |
88 | ||
89 | #ifdef StartDoc | |
90 | #undef StartDoc | |
91 | #endif | |
92 | ||
93 | #ifdef GetCharWidth | |
94 | #undef GetCharWidth | |
95 | #endif | |
96 | ||
97 | #ifdef FindWindow | |
98 | #undef FindWindow | |
99 | #endif | |
100 | ||
101 | #endif | |
102 | ||
103 | // Declarations local to this file | |
104 | #define YSCALE(y) (m_yOrigin / m_scaleFactor - (y)) | |
105 | ||
106 | // Determine the Default Postscript Previewer | |
107 | // available on the platform | |
108 | #if defined(__SUN__) && defined(__XVIEW__) | |
109 | // OpenWindow/NeWS's Postscript Previewer | |
110 | # define PS_VIEWER_PROG "pageview" | |
111 | #elif defined(__VMS__) | |
112 | #define PS_VIEWER_PROG "view/format=ps/select=x_display" | |
113 | #elif defined(__SGI__) | |
114 | // SGI's Display Postscript Previewer | |
115 | //# define PS_VIEWER_PROG "dps" | |
116 | # define PS_VIEWER_PROG "xpsview" | |
2049ba38 | 117 | #elif defined(__X__) || defined(__WXGTK__) |
c801d85f KB |
118 | // Front-end to ghostscript |
119 | # define PS_VIEWER_PROG "ghostview" | |
120 | #else | |
121 | // Windows ghostscript/ghostview | |
122 | # define PS_VIEWER_PROG NULL | |
123 | #endif | |
124 | ||
c67daf87 | 125 | wxPrintSetupData *wxThePrintSetupData = (wxPrintSetupData *) NULL; |
c801d85f KB |
126 | |
127 | // these should move into wxPostscriptDC: | |
128 | double UnderlinePosition = 0.0F; | |
129 | double UnderlineThickness = 0.0F; | |
130 | ||
131 | #define _MAXPATHLEN 500 | |
132 | ||
133 | /* See "wxspline.inc" and "xfspline.inc" */ | |
47d67540 | 134 | #if wxUSE_XFIG_SPLINE_CODE |
c801d85f KB |
135 | static const char *wxPostScriptHeaderSpline = " \ |
136 | /DrawSplineSection {\n\ | |
137 | /y3 exch def\n\ | |
138 | /x3 exch def\n\ | |
139 | /y2 exch def\n\ | |
140 | /x2 exch def\n\ | |
141 | /y1 exch def\n\ | |
142 | /x1 exch def\n\ | |
143 | /xa x1 x2 x1 sub 0.666667 mul add def\n\ | |
144 | /ya y1 y2 y1 sub 0.666667 mul add def\n\ | |
145 | /xb x3 x2 x3 sub 0.666667 mul add def\n\ | |
146 | /yb y3 y2 y3 sub 0.666667 mul add def\n\ | |
147 | x1 y1 lineto\n\ | |
148 | xa ya xb yb x3 y3 curveto\n\ | |
149 | } def\n\ | |
150 | "; | |
151 | #else | |
152 | // No extra PS header for this spline implementation. | |
c67daf87 | 153 | static const char *wxPostScriptHeaderSpline = (char *) NULL; |
c801d85f | 154 | |
47d67540 | 155 | #endif /* wxUSE_XFIG_SPLINE_CODE */ |
c801d85f KB |
156 | |
157 | // steve, 05.09.94 | |
158 | // VMS has a bug in the ofstream class. | |
159 | // the buffering doesn't work correctly. therefore | |
160 | // we will allocate (temporarily) a very big buffer (1MB), so | |
161 | // that a buffer overflow will not occur. | |
162 | #ifdef __VMS__ | |
163 | #define VMS_BUFSIZ (1024L*1024L) | |
164 | static char *fileBuffer = NULL; | |
165 | #endif | |
166 | ||
167 | #if !USE_SHARED_LIBRARY | |
e86d366c | 168 | IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule, wxModule) |
c801d85f KB |
169 | IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC) |
170 | IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData, wxObject) | |
171 | IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType, wxObject) | |
172 | IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase, wxList) | |
173 | #endif | |
174 | ||
175 | wxPostScriptDC::wxPostScriptDC (void) | |
176 | { | |
177 | // m_yOrigin = 792; // For EPS output | |
178 | m_yOrigin = 842; // For A4 output | |
179 | ||
180 | m_minX = 1000; | |
181 | m_minY = 1000; | |
182 | m_maxX = -1000; | |
183 | m_maxY = -1000; | |
184 | m_title = ""; | |
185 | ||
c67daf87 | 186 | m_pstream = (ofstream *) NULL; |
c801d85f | 187 | |
2049ba38 | 188 | #ifdef __WXMSW__ |
c801d85f KB |
189 | // Can only send to file in Windows |
190 | wxThePrintSetupData->SetPrinterMode(PS_FILE); | |
191 | #endif | |
192 | ||
193 | m_currentRed = 255; | |
194 | m_currentGreen = 255; | |
195 | m_currentBlue = 0; | |
196 | } | |
197 | ||
198 | wxPostScriptDC::wxPostScriptDC (const wxString& file, bool interactive, wxWindow *parent) | |
199 | { | |
200 | Create(file, interactive, parent); | |
201 | } | |
202 | ||
203 | bool wxPostScriptDC::Create(const wxString& file, bool interactive, wxWindow *parent) | |
204 | { | |
205 | m_isInteractive = interactive; | |
206 | ||
207 | m_yOrigin = 792; // For EPS output | |
208 | // m_yOrigin = 842; // For A4 output | |
209 | ||
210 | m_minX = 1000; | |
211 | m_minY = 1000; | |
212 | m_maxX = -1000; | |
213 | m_maxY = -1000; | |
214 | m_title = ""; | |
215 | m_filename = file; | |
c67daf87 | 216 | m_pstream = (ofstream *) NULL; |
c801d85f | 217 | |
2049ba38 | 218 | #ifdef __WXMSW__ |
c801d85f KB |
219 | // Can only send to file in Windows |
220 | wxThePrintSetupData->SetPrinterMode(PS_FILE); | |
221 | #endif | |
222 | ||
223 | if (m_isInteractive) | |
224 | { | |
225 | if ((m_ok = PrinterDialog (parent) ) == FALSE) return FALSE; | |
226 | } | |
227 | else | |
228 | m_ok = TRUE; | |
229 | ||
230 | m_currentRed = 255; | |
231 | m_currentGreen = 255; | |
232 | m_currentBlue = 0; | |
233 | ||
234 | m_scaleFactor = 1.0; | |
235 | ||
236 | return m_ok; | |
237 | } | |
238 | ||
239 | wxPostScriptDC::~wxPostScriptDC (void) | |
240 | { | |
241 | if (m_pstream) | |
242 | delete m_pstream; | |
243 | } | |
244 | ||
245 | bool wxPostScriptDC::PrinterDialog(wxWindow *parent) | |
246 | { | |
1a5a8367 | 247 | wxPostScriptPrintDialog dialog (parent, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL); |
c801d85f KB |
248 | m_ok = (dialog.ShowModal () == wxID_OK) ; |
249 | ||
250 | if (!m_ok) | |
251 | return FALSE; | |
252 | ||
253 | if ((m_filename == "") && (wxThePrintSetupData->GetPrinterMode() == PS_PREVIEW || wxThePrintSetupData->GetPrinterMode() == PS_PRINTER)) | |
254 | { | |
255 | // steve, 05.09.94 | |
256 | #ifdef __VMS__ | |
257 | wxThePrintSetupData->SetPrinterFile("preview"); | |
258 | #else | |
259 | // For PS_PRINTER action this depends on a Unix-style print spooler | |
260 | // since the wx_printer_file can be destroyed during a session | |
261 | // @@@ TODO: a Windows-style answer for non-Unix | |
262 | char userId[256]; | |
263 | wxGetUserId (userId, sizeof (userId) / sizeof (char)); | |
264 | char tmp[256]; | |
265 | strcpy (tmp, "/tmp/preview_"); | |
266 | strcat (tmp, userId); | |
267 | wxThePrintSetupData->SetPrinterFile(tmp); | |
268 | #endif | |
269 | char tmp2[256]; | |
270 | strcpy(tmp2, wxThePrintSetupData->GetPrinterFile()); | |
271 | strcat (tmp2, ".ps"); | |
272 | wxThePrintSetupData->SetPrinterFile(tmp2); | |
273 | m_filename = tmp2; | |
274 | } | |
275 | else if ((m_filename == "") && (wxThePrintSetupData->GetPrinterMode() == PS_FILE)) | |
276 | { | |
1a5a8367 | 277 | char *file = wxSaveFileSelector (_("PostScript"), "ps"); |
c801d85f KB |
278 | if (!file) |
279 | { | |
280 | m_ok = FALSE; | |
281 | return FALSE; | |
282 | } | |
283 | wxThePrintSetupData->SetPrinterFile(file); | |
284 | m_filename = file; | |
285 | m_ok = TRUE; | |
286 | } | |
287 | ||
288 | return m_ok; | |
289 | } | |
290 | ||
291 | void wxPostScriptDC::SetClippingRegion (long cx, long cy, long cw, long ch) | |
292 | { | |
293 | if (m_clipping) | |
294 | return; | |
295 | if (!m_pstream) | |
296 | return; | |
297 | ||
298 | m_clipping = TRUE; | |
299 | *m_pstream << "gsave\n"; | |
300 | *m_pstream << "newpath\n"; | |
301 | *m_pstream << cx << " " << YSCALE (cy) << " moveto\n"; | |
dfad0599 | 302 | *m_pstream << (cx + cw) << " " << YSCALE (cy) << " lineto\n"; |
c801d85f KB |
303 | *m_pstream << cx + cw << " " << YSCALE (cy + ch) << " lineto\n"; |
304 | *m_pstream << cx << " " << YSCALE (cy + ch) << " lineto\n"; | |
305 | *m_pstream << "closepath clip newpath\n"; | |
306 | } | |
307 | ||
308 | void wxPostScriptDC::DestroyClippingRegion (void) | |
309 | { | |
310 | if (!m_pstream) | |
311 | return; | |
312 | if (m_clipping) | |
313 | { | |
314 | m_clipping = FALSE; | |
315 | *m_pstream << "grestore\n"; | |
316 | } | |
317 | } | |
318 | ||
319 | void wxPostScriptDC::Clear (void) | |
320 | { | |
321 | } | |
322 | ||
323 | void wxPostScriptDC::FloodFill (long WXUNUSED(x), long WXUNUSED(y), wxColour * WXUNUSED(col), int WXUNUSED(style)) | |
324 | { | |
325 | } | |
326 | ||
327 | bool wxPostScriptDC::GetPixel (long WXUNUSED(x), long WXUNUSED(y), wxColour * WXUNUSED(col)) const | |
328 | { | |
329 | return FALSE; | |
330 | } | |
331 | ||
332 | void wxPostScriptDC::CrossHair (long WXUNUSED(x), long WXUNUSED(y)) | |
333 | { | |
334 | } | |
335 | ||
336 | void wxPostScriptDC::DrawLine (long x1, long y1, long x2, long y2) | |
337 | { | |
338 | if (!m_pstream) | |
339 | return; | |
340 | if (m_pen.Ok()) | |
341 | SetPen (m_pen); | |
342 | *m_pstream << "newpath\n"; | |
343 | *m_pstream << x1 << " " << YSCALE (y1) << " moveto\n"; | |
344 | *m_pstream << x2 << " " << YSCALE (y2) << " lineto\n"; | |
345 | *m_pstream << "stroke\n"; | |
346 | CalcBoundingBox (x1, (long)YSCALE (y1)); | |
347 | CalcBoundingBox (x2, (long)YSCALE (y2)); | |
348 | } | |
349 | ||
350 | #define RAD2DEG 57.29577951308 | |
351 | ||
352 | void wxPostScriptDC::DrawArc (long x1, long y1, long x2, long y2, long xc, long yc) | |
353 | { | |
354 | if (!m_pstream) | |
355 | return; | |
356 | ||
357 | long dx = x1 - xc; | |
358 | long dy = y1 - yc; | |
16c1f7f3 | 359 | long radius = (long) sqrt((double) (dx*dx+dy*dy)); |
c801d85f KB |
360 | double alpha1, alpha2; |
361 | ||
362 | if (x1 == x2 && y1 == y2) { | |
363 | alpha1 = 0.0; | |
364 | alpha2 = 360.0; | |
365 | } else if (radius == 0.0) { | |
366 | alpha1 = alpha2 = 0.0; | |
367 | } else { | |
368 | alpha1 = (x1 - xc == 0) ? | |
369 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
370 | -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; | |
371 | alpha2 = (x2 - xc == 0) ? | |
372 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
373 | -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; | |
374 | } | |
375 | while (alpha1 <= 0) alpha1 += 360; | |
376 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between | |
377 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree | |
378 | while (alpha2 > 360) alpha2 -= 360; | |
379 | ||
380 | if (m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT) { | |
381 | SetBrush(m_brush); | |
382 | *m_pstream << "newpath\n" | |
383 | << xc << " " << YSCALE(yc) << " " | |
384 | << radius << " " << radius << " " | |
385 | << alpha1 << " " << alpha2 << " ellipse\n" | |
386 | << xc << " " << YSCALE(yc) << " lineto\n" | |
387 | << "closepath\n" | |
388 | << "fill\n"; | |
389 | } | |
390 | if (m_pen.Ok() && m_pen.GetStyle() != wxTRANSPARENT) { | |
391 | SetPen(m_pen); | |
392 | *m_pstream << "newpath\n" | |
393 | << xc << " " << YSCALE(yc) << " " | |
394 | << radius << " " << radius << " " | |
395 | << alpha1 << " " << alpha2 << " ellipse\n" | |
396 | << "stroke\n"; | |
397 | } | |
398 | CalcBoundingBox(x1, (long)YSCALE(y1)); | |
399 | CalcBoundingBox(x2, (long)YSCALE(y2)); | |
400 | } | |
401 | ||
402 | void wxPostScriptDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea) | |
403 | { | |
404 | if (!m_pstream) | |
405 | return; | |
406 | ||
407 | if (sa>=360 || sa<=-360) sa=sa-int(sa/360)*360; | |
408 | if (ea>=360 || ea<=-360) ea=ea-int(ea/360)*360; | |
409 | if (sa<0) sa+=360; | |
410 | if (ea<0) ea+=360; | |
411 | if (sa==ea) | |
412 | { | |
413 | DrawEllipse(x,y,w,h); | |
414 | return; | |
415 | } | |
416 | ||
417 | if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT) | |
418 | { | |
419 | SetBrush (m_brush); | |
420 | ||
e86d366c | 421 | *m_pstream << |
c801d85f | 422 | "newpath\n" << |
dfad0599 JS |
423 | (x+w/2) << " " << YSCALE (y+h/2) << " " << |
424 | w/2 << " " << (h/2) << " " << | |
c801d85f KB |
425 | int(sa) <<" "<< int(ea)<<" true ellipticarc\n"; |
426 | ||
427 | CalcBoundingBox (x , (long)YSCALE (y )); | |
428 | CalcBoundingBox (x+w,(long)YSCALE(y+h)); | |
429 | } | |
430 | if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT) | |
431 | { | |
432 | SetPen (m_pen); | |
433 | ||
e86d366c | 434 | *m_pstream << |
c801d85f | 435 | "newpath\n" << |
dfad0599 JS |
436 | (x+w/2) << " " << YSCALE (y+h/2) << " " << |
437 | (w/2) << " " << (h/2) << " " << | |
c801d85f KB |
438 | int(sa) <<" "<< int(ea)<<" false ellipticarc\n"; |
439 | ||
440 | CalcBoundingBox (x , (long)YSCALE (y )); | |
441 | CalcBoundingBox (x+w,(long)YSCALE(y+h)); | |
442 | } | |
443 | } | |
444 | ||
445 | void wxPostScriptDC::DrawPoint (long x, long y) | |
446 | { | |
447 | if (!m_pstream) | |
448 | return; | |
449 | if (m_pen.Ok()) | |
450 | SetPen (m_pen); | |
451 | *m_pstream << "newpath\n"; | |
452 | *m_pstream << x << " " << YSCALE (y) << " moveto\n"; | |
453 | *m_pstream << (x+1) << " " << YSCALE (y) << " lineto\n"; | |
454 | *m_pstream << "stroke\n"; | |
455 | CalcBoundingBox (x, (long)YSCALE (y)); | |
456 | } | |
457 | ||
458 | void wxPostScriptDC::DrawPolygon (int n, wxPoint points[], long xoffset, long yoffset, int WXUNUSED(fillStyle)) | |
459 | { | |
460 | if (!m_pstream) | |
461 | return; | |
462 | if (n > 0) | |
463 | { | |
464 | if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT) | |
465 | { | |
466 | SetBrush (m_brush); | |
467 | *m_pstream << "newpath\n"; | |
468 | ||
469 | long xx = points[0].x + xoffset; | |
470 | long yy = (long) YSCALE (points[0].y + yoffset); | |
471 | *m_pstream << xx << " " << yy << " moveto\n"; | |
472 | CalcBoundingBox (xx, yy); | |
473 | ||
474 | int i; | |
475 | for (i = 1; i < n; i++) | |
476 | { | |
477 | xx = points[i].x + xoffset; | |
478 | yy = (long) YSCALE (points[i].y + yoffset); | |
479 | *m_pstream << xx << " " << yy << " lineto\n"; | |
480 | CalcBoundingBox (xx, yy); | |
481 | } | |
482 | *m_pstream << "fill\n"; | |
483 | } | |
484 | ||
485 | if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT) | |
486 | { | |
487 | SetPen (m_pen); | |
488 | *m_pstream << "newpath\n"; | |
489 | ||
490 | long xx = points[0].x + xoffset; | |
491 | long yy = (long) YSCALE (points[0].y + yoffset); | |
492 | *m_pstream << xx << " " << yy << " moveto\n"; | |
493 | CalcBoundingBox (xx, yy); | |
494 | ||
495 | int i; | |
496 | for (i = 1; i < n; i++) | |
497 | { | |
498 | xx = points[i].x + xoffset; | |
499 | yy = (long) YSCALE (points[i].y + yoffset); | |
500 | *m_pstream << xx << " " << yy << " lineto\n"; | |
501 | CalcBoundingBox (xx, yy); | |
502 | } | |
503 | ||
504 | // Close the polygon | |
505 | xx = points[0].x + xoffset; | |
506 | yy = (long) YSCALE (points[0].y + yoffset); | |
507 | *m_pstream << xx << " " << yy << " lineto\n"; | |
508 | ||
509 | // Output the line | |
510 | *m_pstream << "stroke\n"; | |
511 | } | |
512 | } | |
513 | } | |
514 | ||
515 | void wxPostScriptDC::DrawLines (int n, wxPoint points[], long xoffset, long yoffset) | |
516 | { | |
517 | if (!m_pstream) | |
518 | return; | |
519 | if (n > 0) | |
520 | { | |
521 | if (m_pen.Ok()) | |
522 | SetPen (m_pen); | |
523 | ||
524 | *m_pstream << "newpath\n"; | |
525 | ||
526 | long xx = points[0].x + xoffset; | |
527 | long yy = (long) YSCALE (points[0].y + yoffset); | |
528 | *m_pstream << xx << " " << yy << " moveto\n"; | |
529 | CalcBoundingBox (xx, yy); | |
530 | ||
531 | int i; | |
532 | for (i = 1; i < n; i++) | |
533 | { | |
534 | xx = points[i].x + xoffset; | |
535 | yy = (long) YSCALE (points[i].y + yoffset); | |
536 | *m_pstream << xx << " " << yy << " lineto\n"; | |
537 | CalcBoundingBox (xx, yy); | |
538 | } | |
539 | *m_pstream << "stroke\n"; | |
540 | } | |
541 | } | |
542 | ||
543 | void wxPostScriptDC::DrawRectangle (long x, long y, long width, long height) | |
544 | { | |
545 | if (!m_pstream) | |
546 | return; | |
547 | if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT) | |
548 | { | |
549 | SetBrush (m_brush); | |
550 | ||
551 | *m_pstream << "newpath\n"; | |
552 | *m_pstream << x << " " << YSCALE (y) << " moveto\n"; | |
dfad0599 JS |
553 | *m_pstream << (x + width) << " " << YSCALE (y) << " lineto\n"; |
554 | *m_pstream << (x + width) << " " << YSCALE (y + height) << " lineto\n"; | |
c801d85f KB |
555 | *m_pstream << x << " " << YSCALE (y + height) << " lineto\n"; |
556 | *m_pstream << "closepath\n"; | |
557 | *m_pstream << "fill\n"; | |
558 | ||
559 | CalcBoundingBox (x, (long)YSCALE (y)); | |
560 | CalcBoundingBox (x + width, (long)YSCALE (y + height)); | |
561 | } | |
562 | if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT) | |
563 | { | |
564 | SetPen (m_pen); | |
565 | ||
566 | *m_pstream << "newpath\n"; | |
567 | *m_pstream << x << " " << YSCALE (y) << " moveto\n"; | |
dfad0599 JS |
568 | *m_pstream << (x + width) << " " << YSCALE (y) << " lineto\n"; |
569 | *m_pstream << (x + width) << " " << YSCALE (y + height) << " lineto\n"; | |
c801d85f KB |
570 | *m_pstream << x << " " << YSCALE (y + height) << " lineto\n"; |
571 | *m_pstream << "closepath\n"; | |
572 | *m_pstream << "stroke\n"; | |
573 | ||
574 | CalcBoundingBox (x, (long)YSCALE (y)); | |
575 | CalcBoundingBox (x + width, (long)YSCALE (y + height)); | |
576 | } | |
577 | } | |
578 | ||
579 | void wxPostScriptDC::DrawRoundedRectangle (long x, long y, long width, long height, double radius) | |
580 | { | |
581 | if (!m_pstream) | |
582 | return; | |
583 | ||
584 | if (radius < 0.0) | |
585 | { | |
586 | // Now, a negative radius is interpreted to mean | |
587 | // 'the proportion of the smallest X or Y dimension' | |
588 | double smallest = 0.0; | |
589 | if (width < height) | |
590 | smallest = width; | |
591 | else | |
592 | smallest = height; | |
593 | radius = (-radius * smallest); | |
594 | } | |
595 | ||
596 | if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT) | |
597 | { | |
598 | SetBrush (m_brush); | |
599 | // Draw rectangle anticlockwise | |
600 | *m_pstream << "newpath\n"; | |
dfad0599 | 601 | *m_pstream << (x + radius) << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n"; |
c801d85f KB |
602 | |
603 | *m_pstream << x << " " << YSCALE (y + radius) << " moveto\n"; | |
604 | ||
dfad0599 JS |
605 | *m_pstream << (x + radius) << " " << YSCALE (y + height - radius) << " " << radius << " 180 270 arc\n"; |
606 | *m_pstream << (x + width - radius) << " " << YSCALE (y + height) << " lineto\n"; | |
c801d85f | 607 | |
dfad0599 JS |
608 | *m_pstream << (x + width - radius) << " " << YSCALE (y + height - radius) << " " << radius << " 270 0 arc\n"; |
609 | *m_pstream << (x + width) << " " << YSCALE (y + radius) << " lineto\n"; | |
c801d85f | 610 | |
dfad0599 | 611 | *m_pstream << (x + width - radius) << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n"; |
c801d85f | 612 | |
dfad0599 | 613 | *m_pstream << (x + radius) << " " << YSCALE (y) << " lineto\n"; |
c801d85f KB |
614 | |
615 | *m_pstream << "closepath\n"; | |
616 | ||
617 | *m_pstream << "fill\n"; | |
618 | ||
619 | CalcBoundingBox (x, (long)YSCALE (y)); | |
620 | CalcBoundingBox (x + width, (long)YSCALE (y + height)); | |
621 | } | |
622 | if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT) | |
623 | { | |
624 | SetPen (m_pen); | |
625 | // Draw rectangle anticlockwise | |
626 | *m_pstream << "newpath\n"; | |
dfad0599 | 627 | *m_pstream << (x + radius) << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n"; |
c801d85f KB |
628 | |
629 | *m_pstream << x << " " << YSCALE (y + height - radius) << " lineto\n"; | |
630 | ||
dfad0599 JS |
631 | *m_pstream << (x + radius) << " " << YSCALE (y + height - radius) << " " << radius << " 180 270 arc\n"; |
632 | *m_pstream << (x + width - radius) << " " << YSCALE (y + height) << " lineto\n"; | |
c801d85f | 633 | |
dfad0599 JS |
634 | *m_pstream << (x + width - radius) << " " << YSCALE (y + height - radius) << " " << radius << " 270 0 arc\n"; |
635 | *m_pstream << (x + width) << " " << YSCALE (y + radius) << " lineto\n"; | |
c801d85f | 636 | |
dfad0599 | 637 | *m_pstream << (x + width - radius) << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n"; |
c801d85f | 638 | |
dfad0599 | 639 | *m_pstream << (x + radius) << " " << YSCALE (y) << " lineto\n"; |
c801d85f KB |
640 | |
641 | *m_pstream << "closepath\n"; | |
642 | ||
643 | *m_pstream << "stroke\n"; | |
644 | ||
645 | CalcBoundingBox (x, (long)YSCALE (y)); | |
646 | CalcBoundingBox (x + width, (long)YSCALE (y + height)); | |
647 | } | |
648 | } | |
649 | ||
650 | void wxPostScriptDC::DrawEllipse (long x, long y, long width, long height) | |
651 | { | |
652 | if (!m_pstream) | |
653 | return; | |
654 | if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT) | |
655 | { | |
656 | SetBrush (m_brush); | |
657 | ||
658 | *m_pstream << "newpath\n"; | |
dfad0599 JS |
659 | *m_pstream << (x + width / 2) << " " << YSCALE (y + height / 2) << " "; |
660 | *m_pstream << (width / 2) << " " << (height / 2) << " 0 360 ellipse\n"; | |
c801d85f KB |
661 | *m_pstream << "fill\n"; |
662 | ||
663 | CalcBoundingBox (x - width, (long)YSCALE (y - height)); | |
664 | CalcBoundingBox (x + width, (long)YSCALE (y + height)); | |
665 | } | |
666 | if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT) | |
667 | { | |
668 | SetPen (m_pen); | |
669 | ||
670 | *m_pstream << "newpath\n"; | |
dfad0599 JS |
671 | *m_pstream << (x + width / 2) << " " << YSCALE (y + height / 2) << " "; |
672 | *m_pstream << (width / 2) << " " << (height / 2) << " 0 360 ellipse\n"; | |
c801d85f KB |
673 | *m_pstream << "stroke\n"; |
674 | ||
675 | CalcBoundingBox (x - width, (long)YSCALE (y - height)); | |
676 | CalcBoundingBox (x + width, (long)YSCALE (y + height)); | |
677 | } | |
678 | } | |
679 | ||
680 | void wxPostScriptDC::DrawIcon (const wxIcon& icon, long x, long y) | |
681 | { | |
2049ba38 | 682 | #if defined(__X__) || defined(__WXGTK__) |
c801d85f KB |
683 | wxMemoryDC memDC; |
684 | memDC.SelectObject(icon); | |
685 | Blit(x, y, icon.GetWidth(), icon.GetHeight(), &memDC, 0, 0); | |
686 | #endif | |
687 | } | |
688 | ||
689 | void wxPostScriptDC::SetFont (const wxFont& the_font) | |
690 | { | |
691 | if (!m_pstream) | |
692 | return; | |
693 | ||
694 | if (m_font == the_font) | |
695 | return; | |
696 | ||
697 | m_font = the_font; | |
698 | ||
699 | if ( !m_font.Ok() ) | |
700 | return; | |
701 | ||
702 | char buf[100]; | |
85ccdcce VZ |
703 | const char *name; |
704 | const char *style = ""; | |
c801d85f KB |
705 | int Style = m_font.GetStyle (); |
706 | int Weight = m_font.GetWeight (); | |
707 | ||
708 | switch (m_font.GetFamily ()) | |
709 | { | |
710 | case wxTELETYPE: | |
711 | case wxMODERN: | |
712 | name = "/Courier"; | |
713 | break; | |
714 | case wxSWISS: | |
715 | name = "/Helvetica"; | |
716 | break; | |
717 | case wxROMAN: | |
718 | // name = "/Times-Roman"; | |
719 | name = "/Times"; // Altered by EDZ | |
720 | break; | |
721 | case wxSCRIPT: | |
722 | name = "/Zapf-Chancery-MediumItalic"; | |
723 | Style = wxNORMAL; | |
724 | Weight = wxNORMAL; | |
725 | break; | |
726 | default: | |
727 | case wxDEFAULT: // Sans Serif Font | |
728 | name = "/LucidaSans"; | |
729 | } | |
730 | ||
731 | if (Style == wxNORMAL && (Weight == wxNORMAL || Weight == wxLIGHT)) | |
732 | { | |
733 | if (m_font.GetFamily () == wxROMAN) | |
734 | style = "-Roman"; | |
735 | else | |
736 | style = ""; | |
737 | } | |
738 | else if (Style == wxNORMAL && Weight == wxBOLD) | |
739 | style = "-Bold"; | |
740 | ||
741 | else if (Style == wxITALIC && (Weight == wxNORMAL || Weight == wxLIGHT)) | |
742 | { | |
743 | if (m_font.GetFamily () == wxROMAN) | |
744 | style = "-Italic"; | |
745 | else | |
746 | style = "-Oblique"; | |
747 | } | |
748 | else if (Style == wxITALIC && Weight == wxBOLD) | |
749 | { | |
750 | if (m_font.GetFamily () == wxROMAN) | |
751 | style = "-BoldItalic"; | |
752 | else | |
753 | style = "-BoldOblique"; | |
754 | } | |
755 | else if (Style == wxSLANT && (Weight == wxNORMAL || Weight == wxLIGHT)) | |
756 | { | |
757 | if (m_font.GetFamily () == wxROMAN) | |
758 | style = "-Italic"; | |
759 | else | |
760 | style = "-Oblique"; | |
761 | } | |
762 | else if (Style == wxSLANT && Weight == wxBOLD) | |
763 | { | |
764 | if (m_font.GetFamily () == wxROMAN) | |
765 | style = "-BoldItalic"; | |
766 | else | |
767 | style = "-BoldOblique"; | |
768 | } | |
769 | else | |
770 | style = ""; | |
771 | ||
772 | strcpy (buf, name); | |
773 | strcat (buf, style); | |
774 | *m_pstream << buf << " findfont\n"; | |
dfad0599 | 775 | *m_pstream << (m_font.GetPointSize() * m_scaleFactor) << " scalefont setfont\n"; |
c801d85f KB |
776 | } |
777 | ||
778 | void wxPostScriptDC::SetPen (const wxPen& pen) | |
779 | { | |
780 | if (!m_pstream) | |
781 | return; | |
782 | ||
783 | int oldStyle = m_pen.GetStyle(); | |
784 | ||
785 | m_pen = pen; | |
786 | ||
787 | if (!m_pen.Ok()) | |
788 | return; | |
789 | ||
790 | // Line width | |
791 | *m_pstream << m_pen.GetWidth () << " setlinewidth\n"; | |
792 | ||
793 | // Line style - WRONG: 2nd arg is OFFSET | |
794 | /* | |
795 | Here, I'm afraid you do not conceive meaning of parameters of 'setdash' | |
796 | operator correctly. You should look-up this in the Red Book: the 2nd parame- | |
797 | ter is not number of values in the array of the first one, but an offset | |
798 | into this description of the pattern. I mean a real *offset* not index | |
799 | into array. I.e. If the command is [3 4] 1 setdash is used, then there | |
800 | will be first black line *2* units long, then space 4 units, then the | |
801 | pattern of *3* units black, 4 units space will be repeated. | |
802 | */ | |
85ccdcce VZ |
803 | static const char *dotted = "[2 5] 2"; |
804 | static const char *short_dashed = "[4 4] 2"; | |
805 | static const char *long_dashed = "[4 8] 2"; | |
806 | static const char *dotted_dashed = "[6 6 2 6] 4"; | |
c801d85f | 807 | |
c67daf87 | 808 | const char *psdash = (char *) NULL; |
c801d85f KB |
809 | switch (m_pen.GetStyle ()) |
810 | { | |
811 | case wxDOT: | |
812 | psdash = dotted; | |
813 | break; | |
814 | case wxSHORT_DASH: | |
815 | psdash = short_dashed; | |
816 | break; | |
817 | case wxLONG_DASH: | |
818 | psdash = long_dashed; | |
819 | break; | |
820 | case wxDOT_DASH: | |
821 | psdash = dotted_dashed; | |
822 | break; | |
823 | case wxSOLID: | |
824 | case wxTRANSPARENT: | |
825 | default: | |
826 | psdash = "[] 0"; | |
827 | break; | |
828 | } | |
829 | if (oldStyle != m_pen.GetStyle()) | |
830 | *m_pstream << psdash << " setdash\n"; | |
831 | ||
832 | // Line colour | |
833 | unsigned char red = m_pen.GetColour ().Red (); | |
834 | unsigned char blue = m_pen.GetColour ().Blue (); | |
835 | unsigned char green = m_pen.GetColour ().Green (); | |
836 | ||
837 | if (!m_colour) | |
838 | { | |
839 | // Anything not white is black | |
840 | if (!(red == (unsigned char) 255 && blue == (unsigned char) 255 | |
841 | && green == (unsigned char) 255)) | |
842 | { | |
843 | red = (unsigned char) 0; | |
844 | green = (unsigned char) 0; | |
845 | blue = (unsigned char) 0; | |
846 | } | |
847 | } | |
848 | ||
849 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
850 | { | |
851 | long redPS = (long) (((int) red) / 255.0); | |
852 | long bluePS = (long) (((int) blue) / 255.0); | |
853 | long greenPS = (long) (((int) green) / 255.0); | |
854 | ||
855 | *m_pstream << redPS << " " << greenPS << " " << bluePS << " setrgbcolor\n"; | |
856 | ||
857 | m_currentRed = red; | |
858 | m_currentBlue = blue; | |
859 | m_currentGreen = green; | |
860 | } | |
861 | } | |
862 | ||
863 | void wxPostScriptDC::SetBrush (const wxBrush& brush) | |
864 | { | |
865 | if (!m_pstream) | |
866 | return; | |
867 | ||
868 | m_brush = brush; | |
869 | ||
870 | if ( !m_brush.Ok() ) | |
871 | return; | |
872 | ||
873 | // Brush colour | |
874 | unsigned char red = m_brush.GetColour ().Red (); | |
875 | unsigned char blue = m_brush.GetColour ().Blue (); | |
876 | unsigned char green = m_brush.GetColour ().Green (); | |
877 | ||
878 | if (!m_colour) | |
879 | { | |
880 | // Anything not black is white | |
881 | if (!(red == (unsigned char) 0 && blue == (unsigned char) 0 | |
882 | && green == (unsigned char) 0)) | |
883 | { | |
884 | red = (unsigned char) 255; | |
885 | green = (unsigned char) 255; | |
886 | blue = (unsigned char) 255; | |
887 | } | |
888 | } | |
889 | ||
890 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
891 | { | |
892 | long redPS = (long) (((int) red) / 255.0); | |
893 | long bluePS = (long) (((int) blue) / 255.0); | |
894 | long greenPS = (long) (((int) green) / 255.0); | |
895 | *m_pstream << redPS << " " << greenPS << " " << bluePS << " setrgbcolor\n"; | |
896 | m_currentRed = red; | |
897 | m_currentBlue = blue; | |
898 | m_currentGreen = green; | |
899 | } | |
900 | } | |
901 | ||
902 | void wxPostScriptDC::DrawText (const wxString& text, long x, long y, bool WXUNUSED(use16bit)) | |
903 | { | |
904 | if (!m_pstream) | |
905 | return; | |
906 | ||
907 | // TODO: SetFont checks for identity so this will always be a NULL operation | |
908 | if (m_font.Ok()) | |
909 | SetFont (m_font); | |
910 | ||
911 | if (m_textForegroundColour.Ok ()) | |
912 | { | |
913 | unsigned char red = m_textForegroundColour.Red (); | |
914 | unsigned char blue = m_textForegroundColour.Blue (); | |
915 | unsigned char green = m_textForegroundColour.Green (); | |
916 | ||
917 | if (!m_colour) | |
918 | { | |
919 | // Anything not white is black | |
920 | if (!(red == (unsigned char) 255 && blue == (unsigned char) 255 | |
921 | && green == (unsigned char) 255)) | |
922 | { | |
923 | red = (unsigned char) 0; | |
924 | green = (unsigned char) 0; | |
925 | blue = (unsigned char) 0; | |
926 | } | |
927 | } | |
928 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
929 | { | |
930 | long redPS = (long) (((int) red) / 255.0); | |
931 | long bluePS = (long) (((int) blue) / 255.0); | |
932 | long greenPS = (long) (((int) green) / 255.0); | |
933 | *m_pstream << redPS << " " << greenPS << " " << bluePS << " setrgbcolor\n"; | |
934 | ||
935 | m_currentRed = red; | |
936 | m_currentBlue = blue; | |
937 | m_currentGreen = green; | |
938 | } | |
939 | } | |
940 | ||
941 | int size = 10; | |
942 | if (m_font.Ok()) | |
943 | size = m_font.GetPointSize (); | |
944 | ||
945 | *m_pstream << x << " " << YSCALE (y + size) << " moveto\n"; | |
946 | ||
947 | // *m_pstream << "(" << text << ")" << " show\n"; | |
948 | *m_pstream << "("; | |
949 | int len = strlen ((char *)(const char *)text); | |
950 | int i; | |
951 | for (i = 0; i < len; i++) | |
952 | { | |
953 | /* | |
954 | char ch = text[i]; | |
955 | if (ch == ')' || ch == '(' || ch == '\\') | |
956 | *m_pstream << "\\"; | |
957 | *m_pstream << ch; | |
958 | */ | |
959 | int c = (unsigned char) text[i]; | |
960 | if ( c == ')' || c == '(' || c == '\\') | |
961 | { | |
962 | *m_pstream << "\\" << (char) c; | |
963 | } | |
964 | else if ( c >= 128 ) | |
965 | { | |
966 | // Cope with character codes > 127 | |
967 | char tmp[5]; | |
968 | sprintf(tmp, "\\%o", c); | |
969 | *m_pstream << tmp; | |
970 | } | |
971 | else | |
972 | *m_pstream << (char) c; | |
973 | } | |
974 | ||
975 | *m_pstream << ")" << " show\n"; | |
976 | ||
977 | if (m_font.GetUnderlined()) | |
978 | { | |
979 | long w, h; | |
980 | GetTextExtent(text, &w, &h); | |
981 | *m_pstream << "gsave " << x << " " << YSCALE (y + size - UnderlinePosition) | |
982 | << " moveto\n" | |
983 | << UnderlineThickness << " setlinewidth " | |
dfad0599 | 984 | << (x + w) << " " << YSCALE (y + size - UnderlinePosition) |
c801d85f KB |
985 | << " lineto stroke grestore\n"; |
986 | } | |
e86d366c | 987 | |
c801d85f KB |
988 | CalcBoundingBox (x, (long)YSCALE (y + size)); |
989 | CalcBoundingBox (x + size * strlen ((char *)(const char *)text), (long)YSCALE (y)); | |
990 | } | |
991 | ||
992 | ||
993 | void wxPostScriptDC::SetBackground (const wxBrush& brush) | |
994 | { | |
995 | m_backgroundBrush = brush; | |
996 | } | |
997 | ||
998 | void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function)) | |
999 | { | |
1000 | } | |
1001 | ||
1002 | static const char *wxPostScriptHeaderEllipse = "\ | |
1003 | /ellipsedict 8 dict def\n\ | |
1004 | ellipsedict /mtrx matrix put\n\ | |
1005 | /ellipse\n\ | |
1006 | { ellipsedict begin\n\ | |
1007 | /endangle exch def\n\ | |
1008 | /startangle exch def\n\ | |
1009 | /yrad exch def\n\ | |
1010 | /xrad exch def\n\ | |
1011 | /y exch def\n\ | |
1012 | /x exch def\n\ | |
1013 | /savematrix mtrx currentmatrix def\n\ | |
1014 | x y translate\n\ | |
1015 | xrad yrad scale\n\ | |
1016 | 0 0 1 startangle endangle arc\n\ | |
1017 | savematrix setmatrix\n\ | |
1018 | end\n\ | |
1019 | } def\n\ | |
1020 | "; | |
1021 | ||
1022 | static const char *wxPostScriptHeaderEllipticArc= "\ | |
1023 | /ellipticarcdict 8 dict def\n\ | |
1024 | ellipticarcdict /mtrx matrix put\n\ | |
1025 | /ellipticarc\n\ | |
1026 | { ellipticarcdict begin\n\ | |
1027 | /do_fill exch def\n\ | |
1028 | /endangle exch def\n\ | |
1029 | /startangle exch def\n\ | |
1030 | /yrad exch def\n\ | |
1031 | /xrad exch def \n\ | |
1032 | /y exch def\n\ | |
1033 | /x exch def\n\ | |
1034 | /savematrix mtrx currentmatrix def\n\ | |
1035 | x y translate\n\ | |
1036 | xrad yrad scale\n\ | |
1037 | do_fill { 0 0 moveto } if\n\ | |
1038 | 0 0 1 startangle endangle arc\n\ | |
1039 | savematrix setmatrix\n\ | |
1040 | do_fill { fill }{ stroke } ifelse\n\ | |
1041 | end\n\ | |
1042 | } def\n"; | |
1043 | ||
1044 | bool wxPostScriptDC::StartDoc (const wxString& message) | |
1045 | { | |
1046 | if (m_filename == "") | |
1047 | { | |
1048 | #ifdef __VMS__ | |
1049 | m_filename = "wxtmp.ps"; | |
1050 | #else | |
1051 | m_filename = wxGetTempFileName("ps"); | |
1052 | #endif | |
1053 | wxThePrintSetupData->SetPrinterFile((char *)(const char *)m_filename); | |
1054 | m_ok = TRUE; | |
1055 | } | |
1056 | else | |
1057 | wxThePrintSetupData->SetPrinterFile((char *)(const char *)m_filename); | |
1058 | ||
1059 | #ifdef __VMS__ | |
1060 | // steve, 05.09.94 | |
1061 | // VMS is sh*t! | |
1062 | m_pstream = new ofstream; | |
1063 | if(fileBuffer) delete[] fileBuffer; | |
e86d366c | 1064 | fileBuffer = new char[VMS_BUFSIZ]; |
c801d85f KB |
1065 | m_pstream->setbuf(fileBuffer,VMS_BUFSIZ); |
1066 | m_pstream->open(wxThePrintSetupData->GetPrinterFile()); | |
1067 | #else | |
1068 | m_pstream = new ofstream (wxThePrintSetupData->GetPrinterFile()); | |
1069 | #endif | |
1070 | if (!m_pstream || !m_pstream->good()) | |
1071 | { | |
1072 | wxMessageBox (_("Cannot open file!"), _("Error"), wxOK); | |
1073 | m_ok = FALSE; | |
1074 | return FALSE; | |
1075 | } | |
1076 | m_ok = TRUE; | |
1077 | ||
1078 | SetBrush (*wxBLACK_BRUSH); | |
1079 | SetPen (*wxBLACK_PEN); | |
1080 | ||
1081 | wxPageNumber = 1; | |
1082 | m_title = message; | |
1083 | return TRUE; | |
1084 | } | |
1085 | ||
1086 | ||
1087 | void wxPostScriptDC::EndDoc (void) | |
1088 | { | |
1089 | static char wxPostScriptHeaderReencodeISO1[] = | |
1090 | "\n/reencodeISO {\n" | |
1091 | "dup dup findfont dup length dict begin\n" | |
1092 | "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n" | |
1093 | "/Encoding ISOLatin1Encoding def\n" | |
1094 | "currentdict end definefont\n" | |
1095 | "} def\n" | |
1096 | "/ISOLatin1Encoding [\n" | |
1097 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
1098 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
1099 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
1100 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
1101 | "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n" | |
1102 | "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n" | |
1103 | "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n" | |
1104 | "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n" | |
1105 | "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n" | |
1106 | "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n" | |
1107 | "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n" | |
1108 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
1109 | "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n" | |
1110 | "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n" | |
1111 | "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n"; | |
1112 | ||
1113 | static char wxPostScriptHeaderReencodeISO2[] = | |
1114 | "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n" | |
1115 | "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n" | |
1116 | "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n" | |
1117 | "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n" | |
1118 | "/guillemotright/onequarter/onehalf/threequarters/questiondown\n" | |
1119 | "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n" | |
1120 | "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n" | |
1121 | "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n" | |
1122 | "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n" | |
1123 | "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n" | |
1124 | "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n" | |
1125 | "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n" | |
1126 | "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n" | |
1127 | "/yacute/thorn/ydieresis\n" | |
1128 | "] def\n\n"; | |
1129 | ||
1130 | if (!m_pstream) | |
1131 | return; | |
1132 | if (m_clipping) | |
1133 | { | |
1134 | m_clipping = FALSE; | |
1135 | *m_pstream << "grestore\n"; | |
1136 | } | |
1137 | ||
1138 | // Will reuse m_pstream for header | |
1139 | #ifdef __VMS__ | |
1140 | // see the definition of fileBuffer for explanation | |
1141 | m_pstream->close(); // steve, 05.09.94 | |
1142 | if(fileBuffer) delete[] fileBuffer; | |
1143 | #endif | |
1144 | if (m_pstream) | |
1145 | { | |
1146 | delete m_pstream; | |
c67daf87 | 1147 | m_pstream = (ofstream *) NULL; |
c801d85f KB |
1148 | } |
1149 | ||
1150 | // Write header now | |
1151 | // steve, 05.09.94 | |
1152 | #ifdef __VMS__ | |
1153 | char *header_file = "header.ps"; | |
1154 | #else | |
1155 | char *header_file = wxGetTempFileName("ps"); | |
1156 | #endif | |
1157 | m_pstream = new ofstream (header_file); | |
1158 | ||
1159 | *m_pstream << "%!PS-Adobe-2.0\n"; /* PostScript magic strings */ | |
1160 | *m_pstream << "%%Title: " << (const char *) m_title << "\n"; | |
1161 | *m_pstream << "%%Creator: " << wxTheApp->argv[0] << "\n"; | |
1162 | // time_t when; time (&when); | |
1163 | // *m_pstream << "%%CreationDate: " << ctime (&when); | |
1164 | *m_pstream << "%%CreationDate: " << wxNow() << "\n"; | |
1165 | ||
1166 | // User Id information | |
1167 | char userID[256]; | |
1168 | if ( wxGetEmailAddress(userID, sizeof(userID)) ) | |
1169 | { | |
1170 | *m_pstream << "%%For: " << (char *)userID; | |
1171 | char userName[245]; | |
1172 | if (wxGetUserName(userName, sizeof(userName))) | |
1173 | *m_pstream << " (" << (char *)userName << ")"; | |
1174 | *m_pstream << "\n"; | |
1175 | } | |
1176 | else if ( wxGetUserName(userID, sizeof(userID)) ) | |
1177 | { | |
1178 | *m_pstream << "%%For: " << (char *)userID << "\n"; | |
1179 | } | |
1180 | ||
1181 | // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com> | |
1182 | ||
1183 | long wx_printer_translate_x, wx_printer_translate_y; | |
1184 | double wx_printer_scale_x, wx_printer_scale_y; | |
1185 | wxThePrintSetupData->GetPrinterTranslation(&wx_printer_translate_x, &wx_printer_translate_y); | |
1186 | wxThePrintSetupData->GetPrinterScaling(&wx_printer_scale_x, &wx_printer_scale_y); | |
1187 | ||
1188 | if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) | |
1189 | { | |
1190 | *m_pstream << "%%Orientation: Landscape\n"; | |
1191 | } | |
1192 | else | |
1193 | { | |
1194 | *m_pstream << "%%Orientation: Portrait\n"; | |
1195 | } | |
1196 | ||
1197 | // Compute the bounding box. Note that it is in the default user | |
1198 | // coordinate system, thus we have to convert the values. | |
1199 | long llx = (long) ((m_minX+wx_printer_translate_x)*wx_printer_scale_x); | |
1200 | long lly = (long) ((m_minY+wx_printer_translate_y)*wx_printer_scale_y); | |
1201 | long urx = (long) ((m_maxX+wx_printer_translate_x)*wx_printer_scale_x); | |
1202 | long ury = (long) ((m_maxY+wx_printer_translate_y)*wx_printer_scale_y); | |
1203 | ||
1204 | #if 0 | |
1205 | // If we're landscape, our sense of "x" and "y" is reversed. | |
1206 | if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) | |
1207 | { | |
1208 | double tmp; | |
1209 | tmp = llx; llx = lly; lly = tmp; | |
1210 | tmp = urx; urx = ury; ury = tmp; | |
1211 | ||
1212 | // We need either the two lines that follow, or we need to subtract | |
1213 | // min_x from real_translate_y, which is commented out below. | |
1214 | llx = llx - m_minX*wx_printer_scale_y; | |
1215 | urx = urx - m_minX*wx_printer_scale_y; | |
1216 | } | |
1217 | #endif | |
1218 | ||
1219 | // The Adobe specifications call for integers; we round as to make | |
1220 | // the bounding larger. | |
1221 | *m_pstream << "%%BoundingBox: " | |
16c1f7f3 JS |
1222 | << floor((double)llx) << " " << floor((double)lly) << " " |
1223 | << ceil((double)urx) << " " << ceil((double)ury) << "\n"; | |
dfad0599 | 1224 | *m_pstream << "%%Pages: " << (wxPageNumber - 1) << "\n"; |
c801d85f KB |
1225 | *m_pstream << "%%EndComments\n\n"; |
1226 | ||
1227 | // To check the correctness of the bounding box, postscript commands | |
1228 | // to draw a box corresponding to the bounding box are generated below. | |
1229 | // But since we typically don't want to print such a box, the postscript | |
1230 | // commands are generated within comments. These lines appear before any | |
1231 | // adjustment of scale, rotation, or translation, and hence are in the | |
1232 | // default user coordinates. | |
1233 | *m_pstream << "% newpath\n"; | |
1234 | *m_pstream << "% " << llx << " " << lly << " moveto\n"; | |
1235 | *m_pstream << "% " << urx << " " << lly << " lineto\n"; | |
1236 | *m_pstream << "% " << urx << " " << ury << " lineto\n"; | |
1237 | *m_pstream << "% " << llx << " " << ury << " lineto closepath stroke\n"; | |
1238 | ||
1239 | #if 0 | |
1240 | // Output scaling | |
1241 | long real_translate_y = wx_printer_translate_y; | |
1242 | if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) | |
1243 | { | |
1244 | real_translate_y -= m_maxY; | |
e86d366c | 1245 | // The following line can be used instead of the adjustment to |
c801d85f KB |
1246 | // llx and urx above. |
1247 | // real_translate_y -= m_minX; | |
1248 | *m_pstream << "90 rotate\n"; | |
1249 | } | |
1250 | ||
1251 | /* Probably don't want this now we have it in EndPage, below. | |
1252 | * We should rationalise the scaling code to one place. JACS, October 1995 | |
1253 | * Do we take the next 2 lines out or not? | |
1254 | */ | |
e86d366c | 1255 | |
c801d85f KB |
1256 | *m_pstream << wx_printer_scale_x << " " << wx_printer_scale_y << " scale\n"; |
1257 | *m_pstream << wx_printer_translate_x << " " << real_translate_y << " translate\n"; | |
1258 | #endif | |
1259 | ||
1260 | *m_pstream << "%%BeginProlog\n"; | |
1261 | *m_pstream << wxPostScriptHeaderEllipse; | |
1262 | *m_pstream << wxPostScriptHeaderEllipticArc; | |
1263 | *m_pstream << wxPostScriptHeaderReencodeISO1; | |
1264 | *m_pstream << wxPostScriptHeaderReencodeISO2; | |
1265 | ||
1266 | if (wxPostScriptHeaderSpline) | |
1267 | *m_pstream << wxPostScriptHeaderSpline; | |
1268 | *m_pstream << "%%EndProlog\n"; | |
1269 | ||
1270 | delete m_pstream; | |
c67daf87 | 1271 | m_pstream = (ofstream *) NULL; |
c801d85f KB |
1272 | |
1273 | #ifdef __VMS__ | |
1274 | char *tmp_file = "tmp.ps"; | |
1275 | #else | |
1276 | char *tmp_file = wxGetTempFileName("ps"); | |
1277 | #endif | |
1278 | ||
1279 | // Paste header Before wx_printer_file | |
1280 | wxConcatFiles (header_file, wxThePrintSetupData->GetPrinterFile(), tmp_file); | |
1281 | wxRemoveFile (header_file); | |
1282 | wxRemoveFile (wxThePrintSetupData->GetPrinterFile()); | |
1283 | wxRenameFile(tmp_file, wxThePrintSetupData->GetPrinterFile()); | |
1284 | ||
2049ba38 | 1285 | #if defined(__X__) || defined(__WXGTK__) |
c801d85f KB |
1286 | if (m_ok) |
1287 | { | |
1288 | switch (wxThePrintSetupData->GetPrinterMode()) { | |
1289 | case PS_PREVIEW: | |
1290 | { | |
1291 | char *argv[3]; | |
1292 | argv[0] = wxThePrintSetupData->GetPrintPreviewCommand(); | |
1293 | argv[1] = wxThePrintSetupData->GetPrinterFile(); | |
c67daf87 | 1294 | argv[2] = (char *) NULL; |
c801d85f KB |
1295 | wxExecute (argv, TRUE); |
1296 | wxRemoveFile(wxThePrintSetupData->GetPrinterFile()); | |
1297 | } | |
1298 | break; | |
1299 | ||
1300 | case PS_PRINTER: | |
1301 | { | |
1302 | char *argv[4]; | |
1303 | int argc = 0; | |
1304 | argv[argc++] = wxThePrintSetupData->GetPrinterCommand(); | |
1305 | ||
1306 | // !SM! If we simply assign to argv[1] here, if printer options | |
1307 | // are blank, we get an annoying and confusing message from lpr. | |
1308 | char * opts = wxThePrintSetupData->GetPrinterOptions(); | |
1309 | if (opts && *opts) | |
1310 | argv[argc++] = opts; | |
e86d366c | 1311 | |
c801d85f | 1312 | argv[argc++] = wxThePrintSetupData->GetPrinterFile(); |
c67daf87 | 1313 | argv[argc++] = (char *) NULL; |
c801d85f KB |
1314 | wxExecute (argv, TRUE); |
1315 | wxRemoveFile(wxThePrintSetupData->GetPrinterFile()); | |
1316 | } | |
1317 | break; | |
1318 | ||
1319 | case PS_FILE: | |
1320 | break; | |
1321 | } | |
1322 | } | |
1323 | #endif | |
1324 | } | |
1325 | ||
1326 | void wxPostScriptDC::StartPage (void) | |
1327 | { | |
1328 | if (!m_pstream) | |
1329 | return; | |
dfad0599 | 1330 | *m_pstream << "%%Page: " << (wxPageNumber++) << "\n"; |
c801d85f KB |
1331 | // *m_pstream << "matrix currentmatrix\n"; |
1332 | ||
1333 | // Added by Chris Breeze | |
1334 | ||
1335 | // Each page starts with an "initgraphics" which resets the | |
1336 | // transformation and so we need to reset the origin | |
1337 | // (and rotate the page for landscape printing) | |
1338 | m_scaleFactor = 1.0; | |
1339 | m_logicalOriginX = 0; | |
1340 | m_logicalOriginY = 0; | |
1341 | ||
1342 | // Output scaling | |
1343 | long translate_x, translate_y; | |
1344 | double scale_x, scale_y; | |
1345 | wxThePrintSetupData->GetPrinterTranslation(&translate_x, &translate_y); | |
1346 | wxThePrintSetupData->GetPrinterScaling(&scale_x, &scale_y); | |
1347 | ||
1348 | if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) | |
1349 | { | |
1350 | translate_y -= GetYOrigin(); | |
1351 | *m_pstream << "90 rotate\n"; | |
1352 | } | |
1353 | ||
1354 | *m_pstream << scale_x << " " << scale_y << " scale\n"; | |
1355 | *m_pstream << translate_x << " " << translate_y << " translate\n"; | |
1356 | } | |
1357 | ||
1358 | void wxPostScriptDC::EndPage (void) | |
1359 | { | |
1360 | if (!m_pstream) | |
1361 | return; | |
1362 | *m_pstream << "showpage\n"; | |
1363 | ||
1364 | // Removed by Chris Breeze | |
1365 | #if 0 | |
1366 | *m_pstream << "setmatrix\n"; | |
1367 | ||
1368 | // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com> | |
1369 | ||
1370 | long wx_printer_translate_x, wx_printer_translate_y; | |
1371 | double wx_printer_scale_x, wx_printer_scale_y; | |
1372 | wxThePrintSetupData->GetPrinterTranslation(&wx_printer_translate_x, &wx_printer_translate_y); | |
1373 | wxThePrintSetupData->GetPrinterScaling(&wx_printer_scale_x, &wx_printer_scale_y); | |
1374 | ||
1375 | // Compute the bounding box. Note that it is in the default user | |
1376 | // coordinate system, thus we have to convert the values. | |
1377 | long llx = (m_minX+wx_printer_translate_x)*wx_printer_scale_x; | |
1378 | long lly = (m_minY+wx_printer_translate_y)*wx_printer_scale_y; | |
1379 | long urx = (m_maxX+wx_printer_translate_x)*wx_printer_scale_x; | |
1380 | long ury = (m_maxY+wx_printer_translate_y)*wx_printer_scale_y; | |
1381 | ||
1382 | // If we're landscape, our sense of "x" and "y" is reversed. | |
1383 | if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) | |
1384 | { | |
1385 | long tmp; | |
1386 | tmp = llx; llx = lly; lly = tmp; | |
1387 | tmp = urx; urx = ury; ury = tmp; | |
1388 | ||
1389 | // We need either the two lines that follow, or we need to subtract | |
1390 | // m_minX from real_translate_y, which is commented out below. | |
1391 | llx = llx - m_minX*wx_printer_scale_y; | |
1392 | urx = urx - m_minX*wx_printer_scale_y; | |
1393 | } | |
1394 | ||
1395 | // Output scaling | |
1396 | long real_translate_y = wx_printer_translate_y; | |
1397 | if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) | |
1398 | { | |
1399 | real_translate_y -= m_maxY; | |
1400 | // The following line can be used instead of the adjustment to | |
1401 | // llx and urx above. | |
1402 | // real_translate_y -= m_minX; | |
1403 | *m_pstream << "90 rotate\n"; | |
1404 | } | |
1405 | ||
1406 | *m_pstream << wx_printer_scale_x << " " << wx_printer_scale_y << " scale\n"; | |
1407 | *m_pstream << wx_printer_translate_x << " " << real_translate_y << " translate\n"; | |
1408 | #endif | |
1409 | } | |
1410 | ||
c801d85f KB |
1411 | bool wxPostScriptDC:: |
1412 | Blit (long xdest, long ydest, long fwidth, long fheight, | |
1413 | wxDC *source, long xsrc, long ysrc, int WXUNUSED(rop), bool WXUNUSED(useMask)) | |
1414 | { | |
1415 | long width, height, x, y; | |
1416 | ||
2049ba38 | 1417 | #if !defined(__X__) && !defined(__WXGTK__) |
c801d85f KB |
1418 | return FALSE; |
1419 | #endif | |
1420 | ||
1421 | if (!source->IsKindOf(CLASSINFO(wxPaintDC))) return FALSE; | |
1422 | ||
16c1f7f3 JS |
1423 | width = (long)floor((double)fwidth); |
1424 | height = (long)floor((double)fheight); | |
1425 | x = (long)floor((double)xsrc); | |
1426 | y = (long)floor((double)ysrc); | |
c801d85f KB |
1427 | |
1428 | /* PostScript setup: */ | |
1429 | *m_pstream << "gsave\n"; | |
1430 | *m_pstream << xdest << " " << YSCALE(ydest + fheight) << " translate\n"; | |
1431 | *m_pstream << fwidth << " " << fheight << " scale\n"; | |
1432 | *m_pstream << "/DataString " << width << " string def\n"; | |
1433 | *m_pstream << width << " " << height << " 8 [ "; | |
1434 | *m_pstream << width << " 0 0 " << (-height) << " 0 " << height; | |
1435 | *m_pstream << " ]\n{\n"; | |
1436 | *m_pstream << " currentfile DataString readhexstring pop\n"; | |
1437 | *m_pstream << "} bind image\n"; | |
1438 | ||
2049ba38 | 1439 | #if defined(__X__) || defined(__WXGTK__) |
c801d85f KB |
1440 | |
1441 | /* Output data as hex digits: */ | |
1442 | Display *d; | |
1443 | Colormap cm; | |
1444 | XImage *image; | |
1445 | long j, i; | |
1446 | char s[3]; | |
e86d366c | 1447 | |
2049ba38 | 1448 | #ifdef __WXGTK__ |
c801d85f KB |
1449 | |
1450 | d = gdk_display; | |
1451 | cm = ((GdkColormapPrivate*)gdk_colormap_get_system())->xcolormap; | |
1452 | GdkWindow *gwin = ((wxClientDC*)source)->GetWindow(); | |
1453 | image = XGetImage(d, ((GdkWindowPrivate*)gwin)->xwindow, x, y, width, height, AllPlanes, ZPixmap); | |
1454 | ||
e86d366c | 1455 | #else |
c801d85f | 1456 | |
2049ba38 | 1457 | #ifdef __WXMOTIF__ |
46ccb510 JS |
1458 | // TODO. for now, use global display |
1459 | // d = source->display; | |
1460 | d = (Display*) wxGetDisplay(); | |
c801d85f | 1461 | #else |
46ccb510 | 1462 | d = (Display*) wxGetDisplay(); |
c801d85f KB |
1463 | #endif |
1464 | ||
46ccb510 JS |
1465 | cm = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) d); |
1466 | // TODO - implement GetPixmap() and uncomment this line | |
1467 | // image = XGetImage(d, source->GetPixmap(), x, y, width, height, AllPlanes, ZPixmap); | |
e86d366c | 1468 | |
c801d85f KB |
1469 | #endif |
1470 | ||
1471 | ||
1472 | s[2] = 0; | |
1473 | ||
1474 | #define CM_CACHE_SIZE 256 | |
1475 | unsigned long cachesrc[CM_CACHE_SIZE]; | |
1476 | int cachedest[CM_CACHE_SIZE], cache_pos = 0, all_cache = FALSE; | |
1477 | ||
1478 | for (j = 0; j < height; j++) { | |
1479 | for (i = 0; i < width; i++) { | |
1480 | XColor xcol; | |
1481 | unsigned long spixel; | |
1482 | int pixel, k; | |
1483 | const unsigned short MAX_COLOR = 0xFFFF; | |
1484 | ||
1485 | spixel = XGetPixel(image, i, j); | |
1486 | ||
1487 | for (k = cache_pos; k--; ) | |
1488 | if (cachesrc[k] == spixel) { | |
1489 | pixel = cachedest[k]; | |
1490 | goto install; | |
1491 | } | |
1492 | if (all_cache) | |
1493 | for (k = CM_CACHE_SIZE; k-- > cache_pos; ) | |
1494 | if (cachesrc[k] == spixel) { | |
1495 | pixel = cachedest[k]; | |
1496 | goto install; | |
1497 | } | |
e86d366c | 1498 | |
c801d85f KB |
1499 | cachesrc[cache_pos] = xcol.pixel = spixel; |
1500 | XQueryColor(d, cm, &xcol); | |
e86d366c | 1501 | |
c801d85f KB |
1502 | long r, g, b; |
1503 | ||
1504 | r = (long)((double)(xcol.red) / MAX_COLOR); | |
1505 | g = (long)((double)(xcol.green) / MAX_COLOR); | |
1506 | b = (long)((double)(xcol.blue) / MAX_COLOR); | |
1507 | ||
1508 | pixel = (int)(255 * sqrt(((r * r) + (g * g) + (b * b)) / 3)); | |
1509 | ||
1510 | cachedest[cache_pos] = pixel; | |
e86d366c | 1511 | |
c801d85f KB |
1512 | if (++cache_pos >= CM_CACHE_SIZE) { |
1513 | cache_pos = 0; | |
1514 | all_cache = TRUE; | |
1515 | } | |
1516 | ||
e86d366c | 1517 | install: |
c801d85f KB |
1518 | int h, l; |
1519 | ||
1520 | h = (pixel >> 4) & 0xF; | |
1521 | l = pixel & 0xF; | |
1522 | ||
1523 | if (h <= 9) | |
1524 | s[0] = '0' + h; | |
1525 | else | |
1526 | s[0] = 'a' + (h - 10); | |
1527 | if (l <= 9) | |
1528 | s[1] = '0' + l; | |
1529 | else | |
1530 | s[1] = 'a' + (l - 10); | |
e86d366c | 1531 | |
c801d85f KB |
1532 | *m_pstream << s; |
1533 | } | |
1534 | *m_pstream << "\n"; | |
1535 | } | |
1536 | ||
1537 | XDestroyImage(image); | |
1538 | #endif | |
1539 | ||
1540 | *m_pstream << "grestore\n"; | |
1541 | ||
1542 | CalcBoundingBox(xdest, (long)YSCALE(ydest)); | |
1543 | CalcBoundingBox(xdest + fwidth, (long)YSCALE(ydest + fheight)); | |
1544 | ||
1545 | return TRUE; | |
1546 | } | |
1547 | ||
1548 | long wxPostScriptDC::GetCharHeight (void) | |
1549 | { | |
1550 | if (m_font.Ok()) | |
1551 | return m_font.GetPointSize (); | |
1552 | else | |
1553 | return 12; | |
1554 | } | |
1555 | ||
1556 | void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, | |
1557 | long *descent, long *externalLeading, wxFont *theFont, | |
1558 | bool WXUNUSED(use16)) | |
1559 | { | |
1560 | wxFont *fontToUse = theFont; | |
1561 | if (!fontToUse) | |
1562 | fontToUse = (wxFont*) &m_font; | |
1563 | ||
1564 | if (!m_pstream) | |
1565 | return; | |
1566 | #if !USE_AFM_FOR_POSTSCRIPT | |
1567 | // Provide a VERY rough estimate (avoid using it) | |
1568 | // Chris Breeze 5/11/97: produces accurate results for mono-spaced | |
1569 | // font such as Courier (aka wxMODERN) | |
1570 | int height = 12; | |
1571 | if (fontToUse) | |
1572 | { | |
1573 | height = fontToUse->GetPointSize(); | |
1574 | } | |
1575 | *x = strlen (string) * height * 72 / 120; | |
1576 | *y = (long) (height * 1.32); // allow for descender | |
1577 | ||
1578 | if (descent) | |
1579 | *descent = 0; | |
1580 | if (externalLeading) | |
1581 | *externalLeading = 0; | |
1582 | #else | |
1583 | // +++++ start of contributed code +++++ | |
e86d366c | 1584 | |
c801d85f KB |
1585 | // ************************************************************ |
1586 | // method for calculating string widths in postscript: | |
1587 | // read in the AFM (adobe font metrics) file for the | |
1588 | // actual font, parse it and extract the character widths | |
1589 | // and also the descender. this may be improved, but for now | |
1590 | // it works well. the AFM file is only read in if the | |
1591 | // font is changed. this may be chached in the future. | |
1592 | // calls to GetTextExtent with the font unchanged are rather | |
1593 | // efficient!!! | |
1594 | // | |
1595 | // for each font and style used there is an AFM file necessary. | |
1596 | // currently i have only files for the roman font family. | |
1597 | // i try to get files for the other ones! | |
1598 | // | |
1599 | // CAVE: the size of the string is currently always calculated | |
1600 | // in 'points' (1/72 of an inch). this should later on be | |
1601 | // changed to depend on the mapping mode. | |
1602 | // CAVE: the path to the AFM files must be set before calling this | |
1603 | // function. this is usually done by a call like the following: | |
1604 | // wxSetAFMPath("d:\\wxw161\\afm\\"); | |
1605 | // | |
1606 | // example: | |
1607 | // | |
1608 | // wxPostScriptDC dc(NULL, TRUE); | |
1609 | // if (dc.Ok()){ | |
1610 | // wxSetAFMPath("d:\\wxw161\\afm\\"); | |
1611 | // dc.StartDoc("Test"); | |
1612 | // dc.StartPage(); | |
1613 | // long w,h; | |
1614 | // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL)); | |
1615 | // dc.GetTextExtent("Hallo",&w,&h); | |
1616 | // dc.EndPage(); | |
1617 | // dc.EndDoc(); | |
1618 | // } | |
1619 | // | |
1620 | // by steve (stefan.hammes@urz.uni-heidelberg.de) | |
1621 | // created: 10.09.94 | |
1622 | // updated: 14.05.95 | |
1623 | ||
1624 | assert(fontToUse && "void wxPostScriptDC::GetTextExtent: no font defined"); | |
1625 | assert(x && "void wxPostScriptDC::GetTextExtent: x == NULL"); | |
1626 | assert(y && "void wxPostScriptDC::GetTextExtent: y == NULL"); | |
1627 | ||
1628 | // these static vars are for storing the state between calls | |
1629 | static int lastFamily= INT_MIN; | |
1630 | static int lastSize= INT_MIN; | |
1631 | static int lastStyle= INT_MIN; | |
1632 | static int lastWeight= INT_MIN; | |
1633 | static int lastDescender = INT_MIN; | |
1634 | static int lastWidths[256]; // widths of the characters | |
1635 | ||
1636 | // get actual parameters | |
1637 | const int Family = fontToUse->GetFamily(); | |
1638 | const int Size = fontToUse->GetPointSize(); | |
1639 | const int Style = fontToUse->GetStyle(); | |
1640 | const int Weight = fontToUse->GetWeight(); | |
1641 | ||
1642 | // if we have another font, read the font-metrics | |
1643 | if(Family!=lastFamily||Size!=lastSize||Style!=lastStyle||Weight!=lastWeight){ | |
1644 | // store actual values | |
1645 | lastFamily = Family; | |
1646 | lastSize = Size; | |
1647 | lastStyle = Style; | |
1648 | lastWeight = Weight; | |
1649 | ||
1650 | // read in new font metrics ************************************** | |
1651 | ||
1652 | // 1. construct filename ****************************************** | |
1653 | /* MATTHEW: [2] Use wxTheFontNameDirectory */ | |
85ccdcce | 1654 | const char *name; |
c801d85f KB |
1655 | |
1656 | // Julian - we'll need to do this a different way now we've removed the | |
1657 | // font directory system. Must find Stefan's original code. | |
1658 | ||
a3622daa | 1659 | name = wxTheFontNameDirectory->GetAFMName(Family, Weight, Style); |
c801d85f KB |
1660 | if (!name) |
1661 | name = "unknown"; | |
1662 | ||
1663 | // get the directory of the AFM files | |
1664 | char afmName[256]; | |
1665 | afmName[0] = 0; | |
1666 | if (wxGetAFMPath()) | |
1667 | strcpy(afmName,wxGetAFMPath()); | |
1668 | ||
1669 | // 2. open and process the file ********************************** | |
1670 | ||
1671 | // a short explanation of the AFM format: | |
1672 | // we have for each character a line, which gives its size | |
1673 | // e.g.: | |
1674 | // | |
1675 | // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ; | |
1676 | // | |
e86d366c | 1677 | // that means, we have a character with ascii code 63, and width |
c801d85f KB |
1678 | // (444/1000 * fontSize) points. |
1679 | // the other data is ignored for now! | |
1680 | // | |
1681 | // when the font has changed, we read in the right AFM file and store the | |
1682 | // character widths in an array, which is processed below (see point 3.). | |
e86d366c | 1683 | |
c801d85f KB |
1684 | // new elements JC Sun Aug 25 23:21:44 MET DST 1996 |
1685 | ||
e86d366c | 1686 | |
c801d85f KB |
1687 | strcat(afmName,name); |
1688 | strcat(afmName,".afm"); | |
1689 | FILE *afmFile = fopen(afmName,"r"); | |
1690 | if(afmFile==NULL){ | |
1691 | wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName); | |
1692 | wxDebugMsg(" using approximate values\n"); | |
1693 | int i; | |
1694 | for (i=0; i<256; i++) lastWidths[i] = 500; // an approximate value | |
1695 | lastDescender = -150; // dito. | |
1696 | }else{ | |
1697 | int i; | |
1698 | // init the widths array | |
1699 | for(i=0; i<256; i++) lastWidths[i]= INT_MIN; | |
1700 | // some variables for holding parts of a line | |
1701 | char cString[10],semiString[10],WXString[10],descString[20]; | |
1702 | char upString[30], utString[30], encString[50]; | |
1703 | char line[256]; | |
1704 | int ascii,cWidth; | |
1705 | // read in the file and parse it | |
1706 | while(fgets(line,sizeof(line),afmFile)!=NULL){ | |
1707 | // A.) check for descender definition | |
1708 | if(strncmp(line,"Descender",9)==0){ | |
1709 | if((sscanf(line,"%s%d",descString,&lastDescender)!=2) | |
1710 | || (strcmp(descString,"Descender")!=0)) { | |
1711 | wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n", | |
1712 | afmName,line); | |
1713 | } | |
1714 | } | |
1715 | // JC 1.) check for UnderlinePosition | |
1716 | else if(strncmp(line,"UnderlinePosition",17)==0){ | |
3fc5256f | 1717 | if((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) |
c801d85f KB |
1718 | || (strcmp(upString,"UnderlinePosition")!=0)) { |
1719 | wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n", | |
1720 | afmName,line); | |
1721 | } | |
1722 | } | |
1723 | // JC 2.) check for UnderlineThickness | |
1724 | else if(strncmp(line,"UnderlineThickness",18)==0){ | |
40a97c00 | 1725 | if((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) |
c801d85f KB |
1726 | || (strcmp(utString,"UnderlineThickness")!=0)) { |
1727 | wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n", | |
1728 | afmName,line); | |
1729 | } | |
1730 | } | |
1731 | // JC 3.) check for EncodingScheme | |
1732 | else if(strncmp(line,"EncodingScheme",14)==0){ | |
1733 | if((sscanf(line,"%s%s",utString,encString)!=2) | |
1734 | || (strcmp(utString,"EncodingScheme")!=0)) { | |
1735 | wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n", | |
1736 | afmName,line); | |
1737 | } | |
1738 | else if (strncmp(encString, "AdobeStandardEncoding", 21)) | |
1739 | { | |
1740 | wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n", | |
1741 | afmName,line, encString); | |
1742 | } | |
1743 | } | |
1744 | // B.) check for char-width | |
1745 | else if(strncmp(line,"C ",2)==0){ | |
1746 | if(sscanf(line,"%s%d%s%s%d", | |
1747 | cString,&ascii,semiString,WXString,&cWidth)!=5){ | |
1748 | wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName,line); | |
1749 | } | |
1750 | if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 || | |
1751 | strcmp(WXString,"WX")!=0){ | |
1752 | wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName,line); | |
1753 | } | |
1754 | //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); | |
1755 | if(ascii>=0 && ascii<256){ | |
1756 | lastWidths[ascii] = cWidth; // store width | |
1757 | }else{ | |
1758 | /* MATTHEW: this happens a lot; don't print an error */ | |
1759 | // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii); | |
1760 | } | |
1761 | } | |
1762 | // C.) ignore other entries. | |
1763 | } | |
1764 | fclose(afmFile); | |
1765 | } | |
1766 | // hack to compute correct values for german 'Umlaute' | |
1767 | // the correct way would be to map the character names | |
1768 | // like 'adieresis' to corresp. positions of ISOEnc and read | |
1769 | // these values from AFM files, too. Maybe later ... | |
1770 |