]> git.saurik.com Git - wxWidgets.git/blob - src/common/postscrp.cpp
Removed DrawOpenSpline since it doesn't seem to be needed, with required changes
[wxWidgets.git] / src / common / postscrp.cpp
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
27 #if wxUSE_POSTSCRIPT
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
47 #ifdef __WXMSW__
48 #include "wx/msw/private.h"
49 #endif
50
51 #if wxUSE_IOSTREAMH
52 #include <iostream.h>
53 #else
54 #include <iostream>
55 #endif
56
57 #include <fstream.h>
58 #include <math.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <limits.h>
63 #include <assert.h>
64
65 #ifdef __WXGTK__
66
67 #include "gdk/gdkx.h" // GDK_DISPLAY
68 #include "gdk/gdkprivate.h" // XImage
69 #include <X11/Xlib.h>
70 #include <X11/Xutil.h>
71
72 #endif
73
74 #ifdef __WXMOTIF__
75 #include <X11/Xlib.h>
76 #include <X11/Xutil.h>
77 #endif
78
79 #ifdef __WXMSW__
80
81 #ifdef DrawText
82 #undef DrawText
83 #endif
84
85 #ifdef StartDoc
86 #undef StartDoc
87 #endif
88
89 #ifdef GetCharWidth
90 #undef GetCharWidth
91 #endif
92
93 #ifdef FindWindow
94 #undef FindWindow
95 #endif
96
97 #endif
98
99 // Declarations local to this file
100 #define YSCALE(y) (m_yOrigin / m_scaleFactor - (y))
101
102 // Determine the Default Postscript Previewer
103 // available on the platform
104 #if defined(__SUN__) && defined(__XVIEW__)
105 // OpenWindow/NeWS's Postscript Previewer
106 # define PS_VIEWER_PROG "pageview"
107 #elif defined(__VMS__)
108 #define PS_VIEWER_PROG "view/format=ps/select=x_display"
109 #elif defined(__SGI__)
110 // SGI's Display Postscript Previewer
111 //# define PS_VIEWER_PROG "dps"
112 # define PS_VIEWER_PROG "xpsview"
113 #elif defined(__X__) || defined(__WXGTK__)
114 // Front-end to ghostscript
115 # define PS_VIEWER_PROG "ghostview"
116 #else
117 // Windows ghostscript/ghostview
118 # define PS_VIEWER_PROG NULL
119 #endif
120
121 wxPrintSetupData *wxThePrintSetupData = (wxPrintSetupData *) NULL;
122
123 // these should move into wxPostscriptDC:
124 double UnderlinePosition = 0.0F;
125 double UnderlineThickness = 0.0F;
126
127 #define _MAXPATHLEN 500
128
129 /* See "wxspline.inc" and "xfspline.inc" */
130 #if wxUSE_XFIG_SPLINE_CODE
131 static const char *wxPostScriptHeaderSpline = " \
132 /DrawSplineSection {\n\
133 /y3 exch def\n\
134 /x3 exch def\n\
135 /y2 exch def\n\
136 /x2 exch def\n\
137 /y1 exch def\n\
138 /x1 exch def\n\
139 /xa x1 x2 x1 sub 0.666667 mul add def\n\
140 /ya y1 y2 y1 sub 0.666667 mul add def\n\
141 /xb x3 x2 x3 sub 0.666667 mul add def\n\
142 /yb y3 y2 y3 sub 0.666667 mul add def\n\
143 x1 y1 lineto\n\
144 xa ya xb yb x3 y3 curveto\n\
145 } def\n\
146 ";
147 #else
148 // No extra PS header for this spline implementation.
149 static const char *wxPostScriptHeaderSpline = (char *) NULL;
150
151 #endif /* wxUSE_XFIG_SPLINE_CODE */
152
153 // steve, 05.09.94
154 // VMS has a bug in the ofstream class.
155 // the buffering doesn't work correctly. therefore
156 // we will allocate (temporarily) a very big buffer (1MB), so
157 // that a buffer overflow will not occur.
158 #ifdef __VMS__
159 #define VMS_BUFSIZ (1024L*1024L)
160 static char *fileBuffer = NULL;
161 #endif
162
163 #if !USE_SHARED_LIBRARY
164 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC)
165 IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData, wxObject)
166 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType, wxObject)
167 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase, wxList)
168 #endif
169
170 wxPostScriptDC::wxPostScriptDC (void)
171 {
172 // m_yOrigin = 792; // For EPS output
173 m_yOrigin = 842; // For A4 output
174
175 m_minX = 1000;
176 m_minY = 1000;
177 m_maxX = -1000;
178 m_maxY = -1000;
179 m_title = "";
180
181 m_pstream = (ofstream *) NULL;
182
183 #ifdef __WXMSW__
184 // Can only send to file in Windows
185 wxThePrintSetupData->SetPrinterMode(PS_FILE);
186 #endif
187
188 m_currentRed = 255;
189 m_currentGreen = 255;
190 m_currentBlue = 0;
191 }
192
193 wxPostScriptDC::wxPostScriptDC (const wxString& file, bool interactive, wxWindow *parent)
194 {
195 Create(file, interactive, parent);
196 }
197
198 bool wxPostScriptDC::Create(const wxString& file, bool interactive, wxWindow *parent)
199 {
200 m_isInteractive = interactive;
201
202 m_yOrigin = 792; // For EPS output
203 // m_yOrigin = 842; // For A4 output
204
205 m_minX = 1000;
206 m_minY = 1000;
207 m_maxX = -1000;
208 m_maxY = -1000;
209 m_title = "";
210 m_filename = file;
211 m_pstream = (ofstream *) NULL;
212
213 #ifdef __WXMSW__
214 // Can only send to file in Windows
215 wxThePrintSetupData->SetPrinterMode(PS_FILE);
216 #endif
217
218 if (m_isInteractive)
219 {
220 if ((m_ok = PrinterDialog (parent) ) == FALSE) return FALSE;
221 }
222 else
223 m_ok = TRUE;
224
225 m_currentRed = 255;
226 m_currentGreen = 255;
227 m_currentBlue = 0;
228
229 m_scaleFactor = 1.0;
230
231 return m_ok;
232 }
233
234 wxPostScriptDC::~wxPostScriptDC (void)
235 {
236 if (m_pstream)
237 delete m_pstream;
238 }
239
240 bool wxPostScriptDC::PrinterDialog(wxWindow *parent)
241 {
242 wxPostScriptPrintDialog dialog (parent, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL);
243 m_ok = (dialog.ShowModal () == wxID_OK) ;
244
245 if (!m_ok)
246 return FALSE;
247
248 if ((m_filename == "") && (wxThePrintSetupData->GetPrinterMode() == PS_PREVIEW || wxThePrintSetupData->GetPrinterMode() == PS_PRINTER))
249 {
250 // steve, 05.09.94
251 #ifdef __VMS__
252 wxThePrintSetupData->SetPrinterFile("preview");
253 #else
254 // For PS_PRINTER action this depends on a Unix-style print spooler
255 // since the wx_printer_file can be destroyed during a session
256 // @@@ TODO: a Windows-style answer for non-Unix
257 char userId[256];
258 wxGetUserId (userId, sizeof (userId) / sizeof (char));
259 char tmp[256];
260 strcpy (tmp, "/tmp/preview_");
261 strcat (tmp, userId);
262 wxThePrintSetupData->SetPrinterFile(tmp);
263 #endif
264 char tmp2[256];
265 strcpy(tmp2, wxThePrintSetupData->GetPrinterFile());
266 strcat (tmp2, ".ps");
267 wxThePrintSetupData->SetPrinterFile(tmp2);
268 m_filename = tmp2;
269 }
270 else if ((m_filename == "") && (wxThePrintSetupData->GetPrinterMode() == PS_FILE))
271 {
272 char *file = wxSaveFileSelector (_("PostScript"), "ps");
273 if (!file)
274 {
275 m_ok = FALSE;
276 return FALSE;
277 }
278 wxThePrintSetupData->SetPrinterFile(file);
279 m_filename = file;
280 m_ok = TRUE;
281 }
282
283 return m_ok;
284 }
285
286 void wxPostScriptDC::SetClippingRegion (long cx, long cy, long cw, long ch)
287 {
288 if (m_clipping)
289 return;
290 if (!m_pstream)
291 return;
292
293 m_clipping = TRUE;
294 *m_pstream << "gsave\n";
295 *m_pstream << "newpath\n";
296 *m_pstream << cx << " " << YSCALE (cy) << " moveto\n";
297 *m_pstream << (cx + cw) << " " << YSCALE (cy) << " lineto\n";
298 *m_pstream << cx + cw << " " << YSCALE (cy + ch) << " lineto\n";
299 *m_pstream << cx << " " << YSCALE (cy + ch) << " lineto\n";
300 *m_pstream << "closepath clip newpath\n";
301 }
302
303 void wxPostScriptDC::DestroyClippingRegion (void)
304 {
305 if (!m_pstream)
306 return;
307 if (m_clipping)
308 {
309 m_clipping = FALSE;
310 *m_pstream << "grestore\n";
311 }
312 }
313
314 void wxPostScriptDC::Clear (void)
315 {
316 }
317
318 void wxPostScriptDC::FloodFill (long WXUNUSED(x), long WXUNUSED(y), wxColour * WXUNUSED(col), int WXUNUSED(style))
319 {
320 }
321
322 bool wxPostScriptDC::GetPixel (long WXUNUSED(x), long WXUNUSED(y), wxColour * WXUNUSED(col)) const
323 {
324 return FALSE;
325 }
326
327 void wxPostScriptDC::CrossHair (long WXUNUSED(x), long WXUNUSED(y))
328 {
329 }
330
331 void wxPostScriptDC::DrawLine (long x1, long y1, long x2, long y2)
332 {
333 if (!m_pstream)
334 return;
335 if (m_pen.Ok())
336 SetPen (m_pen);
337 *m_pstream << "newpath\n";
338 *m_pstream << x1 << " " << YSCALE (y1) << " moveto\n";
339 *m_pstream << x2 << " " << YSCALE (y2) << " lineto\n";
340 *m_pstream << "stroke\n";
341 CalcBoundingBox (x1, (long)YSCALE (y1));
342 CalcBoundingBox (x2, (long)YSCALE (y2));
343 }
344
345 #define RAD2DEG 57.29577951308
346
347 void wxPostScriptDC::DrawArc (long x1, long y1, long x2, long y2, long xc, long yc)
348 {
349 if (!m_pstream)
350 return;
351
352 long dx = x1 - xc;
353 long dy = y1 - yc;
354 long radius = (long) sqrt((double) (dx*dx+dy*dy));
355 double alpha1, alpha2;
356
357 if (x1 == x2 && y1 == y2) {
358 alpha1 = 0.0;
359 alpha2 = 360.0;
360 } else if (radius == 0.0) {
361 alpha1 = alpha2 = 0.0;
362 } else {
363 alpha1 = (x1 - xc == 0) ?
364 (y1 - yc < 0) ? 90.0 : -90.0 :
365 -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG;
366 alpha2 = (x2 - xc == 0) ?
367 (y2 - yc < 0) ? 90.0 : -90.0 :
368 -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG;
369 }
370 while (alpha1 <= 0) alpha1 += 360;
371 while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between
372 while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree
373 while (alpha2 > 360) alpha2 -= 360;
374
375 if (m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT) {
376 SetBrush(m_brush);
377 *m_pstream << "newpath\n"
378 << xc << " " << YSCALE(yc) << " "
379 << radius << " " << radius << " "
380 << alpha1 << " " << alpha2 << " ellipse\n"
381 << xc << " " << YSCALE(yc) << " lineto\n"
382 << "closepath\n"
383 << "fill\n";
384 }
385 if (m_pen.Ok() && m_pen.GetStyle() != wxTRANSPARENT) {
386 SetPen(m_pen);
387 *m_pstream << "newpath\n"
388 << xc << " " << YSCALE(yc) << " "
389 << radius << " " << radius << " "
390 << alpha1 << " " << alpha2 << " ellipse\n"
391 << "stroke\n";
392 }
393 CalcBoundingBox(x1, (long)YSCALE(y1));
394 CalcBoundingBox(x2, (long)YSCALE(y2));
395 }
396
397 void wxPostScriptDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea)
398 {
399 if (!m_pstream)
400 return;
401
402 if (sa>=360 || sa<=-360) sa=sa-int(sa/360)*360;
403 if (ea>=360 || ea<=-360) ea=ea-int(ea/360)*360;
404 if (sa<0) sa+=360;
405 if (ea<0) ea+=360;
406 if (sa==ea)
407 {
408 DrawEllipse(x,y,w,h);
409 return;
410 }
411
412 if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT)
413 {
414 SetBrush (m_brush);
415
416 *m_pstream <<
417 "newpath\n" <<
418 (x+w/2) << " " << YSCALE (y+h/2) << " " <<
419 w/2 << " " << (h/2) << " " <<
420 int(sa) <<" "<< int(ea)<<" true ellipticarc\n";
421
422 CalcBoundingBox (x , (long)YSCALE (y ));
423 CalcBoundingBox (x+w,(long)YSCALE(y+h));
424 }
425 if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT)
426 {
427 SetPen (m_pen);
428
429 *m_pstream <<
430 "newpath\n" <<
431 (x+w/2) << " " << YSCALE (y+h/2) << " " <<
432 (w/2) << " " << (h/2) << " " <<
433 int(sa) <<" "<< int(ea)<<" false ellipticarc\n";
434
435 CalcBoundingBox (x , (long)YSCALE (y ));
436 CalcBoundingBox (x+w,(long)YSCALE(y+h));
437 }
438 }
439
440 void wxPostScriptDC::DrawPoint (long x, long y)
441 {
442 if (!m_pstream)
443 return;
444 if (m_pen.Ok())
445 SetPen (m_pen);
446 *m_pstream << "newpath\n";
447 *m_pstream << x << " " << YSCALE (y) << " moveto\n";
448 *m_pstream << (x+1) << " " << YSCALE (y) << " lineto\n";
449 *m_pstream << "stroke\n";
450 CalcBoundingBox (x, (long)YSCALE (y));
451 }
452
453 void wxPostScriptDC::DrawPolygon (int n, wxPoint points[], long xoffset, long yoffset, int WXUNUSED(fillStyle))
454 {
455 if (!m_pstream)
456 return;
457 if (n > 0)
458 {
459 if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT)
460 {
461 SetBrush (m_brush);
462 *m_pstream << "newpath\n";
463
464 long xx = points[0].x + xoffset;
465 long yy = (long) YSCALE (points[0].y + yoffset);
466 *m_pstream << xx << " " << yy << " moveto\n";
467 CalcBoundingBox (xx, yy);
468
469 int i;
470 for (i = 1; i < n; i++)
471 {
472 xx = points[i].x + xoffset;
473 yy = (long) YSCALE (points[i].y + yoffset);
474 *m_pstream << xx << " " << yy << " lineto\n";
475 CalcBoundingBox (xx, yy);
476 }
477 *m_pstream << "fill\n";
478 }
479
480 if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT)
481 {
482 SetPen (m_pen);
483 *m_pstream << "newpath\n";
484
485 long xx = points[0].x + xoffset;
486 long yy = (long) YSCALE (points[0].y + yoffset);
487 *m_pstream << xx << " " << yy << " moveto\n";
488 CalcBoundingBox (xx, yy);
489
490 int i;
491 for (i = 1; i < n; i++)
492 {
493 xx = points[i].x + xoffset;
494 yy = (long) YSCALE (points[i].y + yoffset);
495 *m_pstream << xx << " " << yy << " lineto\n";
496 CalcBoundingBox (xx, yy);
497 }
498
499 // Close the polygon
500 xx = points[0].x + xoffset;
501 yy = (long) YSCALE (points[0].y + yoffset);
502 *m_pstream << xx << " " << yy << " lineto\n";
503
504 // Output the line
505 *m_pstream << "stroke\n";
506 }
507 }
508 }
509
510 void wxPostScriptDC::DrawLines (int n, wxPoint points[], long xoffset, long yoffset)
511 {
512 if (!m_pstream)
513 return;
514 if (n > 0)
515 {
516 if (m_pen.Ok())
517 SetPen (m_pen);
518
519 *m_pstream << "newpath\n";
520
521 long xx = points[0].x + xoffset;
522 long yy = (long) YSCALE (points[0].y + yoffset);
523 *m_pstream << xx << " " << yy << " moveto\n";
524 CalcBoundingBox (xx, yy);
525
526 int i;
527 for (i = 1; i < n; i++)
528 {
529 xx = points[i].x + xoffset;
530 yy = (long) YSCALE (points[i].y + yoffset);
531 *m_pstream << xx << " " << yy << " lineto\n";
532 CalcBoundingBox (xx, yy);
533 }
534 *m_pstream << "stroke\n";
535 }
536 }
537
538 void wxPostScriptDC::DrawRectangle (long x, long y, long width, long height)
539 {
540 if (!m_pstream)
541 return;
542 if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT)
543 {
544 SetBrush (m_brush);
545
546 *m_pstream << "newpath\n";
547 *m_pstream << x << " " << YSCALE (y) << " moveto\n";
548 *m_pstream << (x + width) << " " << YSCALE (y) << " lineto\n";
549 *m_pstream << (x + width) << " " << YSCALE (y + height) << " lineto\n";
550 *m_pstream << x << " " << YSCALE (y + height) << " lineto\n";
551 *m_pstream << "closepath\n";
552 *m_pstream << "fill\n";
553
554 CalcBoundingBox (x, (long)YSCALE (y));
555 CalcBoundingBox (x + width, (long)YSCALE (y + height));
556 }
557 if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT)
558 {
559 SetPen (m_pen);
560
561 *m_pstream << "newpath\n";
562 *m_pstream << x << " " << YSCALE (y) << " moveto\n";
563 *m_pstream << (x + width) << " " << YSCALE (y) << " lineto\n";
564 *m_pstream << (x + width) << " " << YSCALE (y + height) << " lineto\n";
565 *m_pstream << x << " " << YSCALE (y + height) << " lineto\n";
566 *m_pstream << "closepath\n";
567 *m_pstream << "stroke\n";
568
569 CalcBoundingBox (x, (long)YSCALE (y));
570 CalcBoundingBox (x + width, (long)YSCALE (y + height));
571 }
572 }
573
574 void wxPostScriptDC::DrawRoundedRectangle (long x, long y, long width, long height, double radius)
575 {
576 if (!m_pstream)
577 return;
578
579 if (radius < 0.0)
580 {
581 // Now, a negative radius is interpreted to mean
582 // 'the proportion of the smallest X or Y dimension'
583 double smallest = 0.0;
584 if (width < height)
585 smallest = width;
586 else
587 smallest = height;
588 radius = (-radius * smallest);
589 }
590
591 if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT)
592 {
593 SetBrush (m_brush);
594 // Draw rectangle anticlockwise
595 *m_pstream << "newpath\n";
596 *m_pstream << (x + radius) << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n";
597
598 *m_pstream << x << " " << YSCALE (y + radius) << " moveto\n";
599
600 *m_pstream << (x + radius) << " " << YSCALE (y + height - radius) << " " << radius << " 180 270 arc\n";
601 *m_pstream << (x + width - radius) << " " << YSCALE (y + height) << " lineto\n";
602
603 *m_pstream << (x + width - radius) << " " << YSCALE (y + height - radius) << " " << radius << " 270 0 arc\n";
604 *m_pstream << (x + width) << " " << YSCALE (y + radius) << " lineto\n";
605
606 *m_pstream << (x + width - radius) << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n";
607
608 *m_pstream << (x + radius) << " " << YSCALE (y) << " lineto\n";
609
610 *m_pstream << "closepath\n";
611
612 *m_pstream << "fill\n";
613
614 CalcBoundingBox (x, (long)YSCALE (y));
615 CalcBoundingBox (x + width, (long)YSCALE (y + height));
616 }
617 if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT)
618 {
619 SetPen (m_pen);
620 // Draw rectangle anticlockwise
621 *m_pstream << "newpath\n";
622 *m_pstream << (x + radius) << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n";
623
624 *m_pstream << x << " " << YSCALE (y + height - radius) << " lineto\n";
625
626 *m_pstream << (x + radius) << " " << YSCALE (y + height - radius) << " " << radius << " 180 270 arc\n";
627 *m_pstream << (x + width - radius) << " " << YSCALE (y + height) << " lineto\n";
628
629 *m_pstream << (x + width - radius) << " " << YSCALE (y + height - radius) << " " << radius << " 270 0 arc\n";
630 *m_pstream << (x + width) << " " << YSCALE (y + radius) << " lineto\n";
631
632 *m_pstream << (x + width - radius) << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n";
633
634 *m_pstream << (x + radius) << " " << YSCALE (y) << " lineto\n";
635
636 *m_pstream << "closepath\n";
637
638 *m_pstream << "stroke\n";
639
640 CalcBoundingBox (x, (long)YSCALE (y));
641 CalcBoundingBox (x + width, (long)YSCALE (y + height));
642 }
643 }
644
645 void wxPostScriptDC::DrawEllipse (long x, long y, long width, long height)
646 {
647 if (!m_pstream)
648 return;
649 if (m_brush.Ok() && m_brush.GetStyle () != wxTRANSPARENT)
650 {
651 SetBrush (m_brush);
652
653 *m_pstream << "newpath\n";
654 *m_pstream << (x + width / 2) << " " << YSCALE (y + height / 2) << " ";
655 *m_pstream << (width / 2) << " " << (height / 2) << " 0 360 ellipse\n";
656 *m_pstream << "fill\n";
657
658 CalcBoundingBox (x - width, (long)YSCALE (y - height));
659 CalcBoundingBox (x + width, (long)YSCALE (y + height));
660 }
661 if (m_pen.Ok() && m_pen.GetStyle () != wxTRANSPARENT)
662 {
663 SetPen (m_pen);
664
665 *m_pstream << "newpath\n";
666 *m_pstream << (x + width / 2) << " " << YSCALE (y + height / 2) << " ";
667 *m_pstream << (width / 2) << " " << (height / 2) << " 0 360 ellipse\n";
668 *m_pstream << "stroke\n";
669
670 CalcBoundingBox (x - width, (long)YSCALE (y - height));
671 CalcBoundingBox (x + width, (long)YSCALE (y + height));
672 }
673 }
674
675 void wxPostScriptDC::DrawIcon (const wxIcon& icon, long x, long y)
676 {
677 #if defined(__X__) || defined(__WXGTK__)
678 wxMemoryDC memDC;
679 memDC.SelectObject(icon);
680 Blit(x, y, icon.GetWidth(), icon.GetHeight(), &memDC, 0, 0);
681 #endif
682 }
683
684 void wxPostScriptDC::SetFont (const wxFont& the_font)
685 {
686 if (!m_pstream)
687 return;
688
689 if (m_font == the_font)
690 return;
691
692 m_font = the_font;
693
694 if ( !m_font.Ok() )
695 return;
696
697 char buf[100];
698 const char *name;
699 const char *style = "";
700 int Style = m_font.GetStyle ();
701 int Weight = m_font.GetWeight ();
702
703 switch (m_font.GetFamily ())
704 {
705 case wxTELETYPE:
706 case wxMODERN:
707 name = "/Courier";
708 break;
709 case wxSWISS:
710 name = "/Helvetica";
711 break;
712 case wxROMAN:
713 // name = "/Times-Roman";
714 name = "/Times"; // Altered by EDZ
715 break;
716 case wxSCRIPT:
717 name = "/Zapf-Chancery-MediumItalic";
718 Style = wxNORMAL;
719 Weight = wxNORMAL;
720 break;
721 default:
722 case wxDEFAULT: // Sans Serif Font
723 name = "/LucidaSans";
724 }
725
726 if (Style == wxNORMAL && (Weight == wxNORMAL || Weight == wxLIGHT))
727 {
728 if (m_font.GetFamily () == wxROMAN)
729 style = "-Roman";
730 else
731 style = "";
732 }
733 else if (Style == wxNORMAL && Weight == wxBOLD)
734 style = "-Bold";
735
736 else if (Style == wxITALIC && (Weight == wxNORMAL || Weight == wxLIGHT))
737 {
738 if (m_font.GetFamily () == wxROMAN)
739 style = "-Italic";
740 else
741 style = "-Oblique";
742 }
743 else if (Style == wxITALIC && Weight == wxBOLD)
744 {
745 if (m_font.GetFamily () == wxROMAN)
746 style = "-BoldItalic";
747 else
748 style = "-BoldOblique";
749 }
750 else if (Style == wxSLANT && (Weight == wxNORMAL || Weight == wxLIGHT))
751 {
752 if (m_font.GetFamily () == wxROMAN)
753 style = "-Italic";
754 else
755 style = "-Oblique";
756 }
757 else if (Style == wxSLANT && Weight == wxBOLD)
758 {
759 if (m_font.GetFamily () == wxROMAN)
760 style = "-BoldItalic";
761 else
762 style = "-BoldOblique";
763 }
764 else
765 style = "";
766
767 strcpy (buf, name);
768 strcat (buf, style);
769 *m_pstream << buf << " findfont\n";
770 *m_pstream << (m_font.GetPointSize() * m_scaleFactor) << " scalefont setfont\n";
771 }
772
773 void wxPostScriptDC::SetPen (const wxPen& pen)
774 {
775 if (!m_pstream)
776 return;
777
778 int oldStyle = m_pen.GetStyle();
779
780 m_pen = pen;
781
782 if (!m_pen.Ok())
783 return;
784
785 // Line width
786 *m_pstream << m_pen.GetWidth () << " setlinewidth\n";
787
788 // Line style - WRONG: 2nd arg is OFFSET
789 /*
790 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
791 operator correctly. You should look-up this in the Red Book: the 2nd parame-
792 ter is not number of values in the array of the first one, but an offset
793 into this description of the pattern. I mean a real *offset* not index
794 into array. I.e. If the command is [3 4] 1 setdash is used, then there
795 will be first black line *2* units long, then space 4 units, then the
796 pattern of *3* units black, 4 units space will be repeated.
797 */
798 static const char *dotted = "[2 5] 2";
799 static const char *short_dashed = "[4 4] 2";
800 static const char *long_dashed = "[4 8] 2";
801 static const char *dotted_dashed = "[6 6 2 6] 4";
802
803 const char *psdash = (char *) NULL;
804 switch (m_pen.GetStyle ())
805 {
806 case wxDOT:
807 psdash = dotted;
808 break;
809 case wxSHORT_DASH:
810 psdash = short_dashed;
811 break;
812 case wxLONG_DASH:
813 psdash = long_dashed;
814 break;
815 case wxDOT_DASH:
816 psdash = dotted_dashed;
817 break;
818 case wxSOLID:
819 case wxTRANSPARENT:
820 default:
821 psdash = "[] 0";
822 break;
823 }
824 if (oldStyle != m_pen.GetStyle())
825 *m_pstream << psdash << " setdash\n";
826
827 // Line colour
828 unsigned char red = m_pen.GetColour ().Red ();
829 unsigned char blue = m_pen.GetColour ().Blue ();
830 unsigned char green = m_pen.GetColour ().Green ();
831
832 if (!m_colour)
833 {
834 // Anything not white is black
835 if (!(red == (unsigned char) 255 && blue == (unsigned char) 255
836 && green == (unsigned char) 255))
837 {
838 red = (unsigned char) 0;
839 green = (unsigned char) 0;
840 blue = (unsigned char) 0;
841 }
842 }
843
844 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
845 {
846 long redPS = (long) (((int) red) / 255.0);
847 long bluePS = (long) (((int) blue) / 255.0);
848 long greenPS = (long) (((int) green) / 255.0);
849
850 *m_pstream << redPS << " " << greenPS << " " << bluePS << " setrgbcolor\n";
851
852 m_currentRed = red;
853 m_currentBlue = blue;
854 m_currentGreen = green;
855 }
856 }
857
858 void wxPostScriptDC::SetBrush (const wxBrush& brush)
859 {
860 if (!m_pstream)
861 return;
862
863 m_brush = brush;
864
865 if ( !m_brush.Ok() )
866 return;
867
868 // Brush colour
869 unsigned char red = m_brush.GetColour ().Red ();
870 unsigned char blue = m_brush.GetColour ().Blue ();
871 unsigned char green = m_brush.GetColour ().Green ();
872
873 if (!m_colour)
874 {
875 // Anything not black is white
876 if (!(red == (unsigned char) 0 && blue == (unsigned char) 0
877 && green == (unsigned char) 0))
878 {
879 red = (unsigned char) 255;
880 green = (unsigned char) 255;
881 blue = (unsigned char) 255;
882 }
883 }
884
885 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
886 {
887 long redPS = (long) (((int) red) / 255.0);
888 long bluePS = (long) (((int) blue) / 255.0);
889 long greenPS = (long) (((int) green) / 255.0);
890 *m_pstream << redPS << " " << greenPS << " " << bluePS << " setrgbcolor\n";
891 m_currentRed = red;
892 m_currentBlue = blue;
893 m_currentGreen = green;
894 }
895 }
896
897 void wxPostScriptDC::DrawText (const wxString& text, long x, long y, bool WXUNUSED(use16bit))
898 {
899 if (!m_pstream)
900 return;
901
902 // TODO: SetFont checks for identity so this will always be a NULL operation
903 if (m_font.Ok())
904 SetFont (m_font);
905
906 if (m_textForegroundColour.Ok ())
907 {
908 unsigned char red = m_textForegroundColour.Red ();
909 unsigned char blue = m_textForegroundColour.Blue ();
910 unsigned char green = m_textForegroundColour.Green ();
911
912 if (!m_colour)
913 {
914 // Anything not white is black
915 if (!(red == (unsigned char) 255 && blue == (unsigned char) 255
916 && green == (unsigned char) 255))
917 {
918 red = (unsigned char) 0;
919 green = (unsigned char) 0;
920 blue = (unsigned char) 0;
921 }
922 }
923 if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
924 {
925 long redPS = (long) (((int) red) / 255.0);
926 long bluePS = (long) (((int) blue) / 255.0);
927 long greenPS = (long) (((int) green) / 255.0);
928 *m_pstream << redPS << " " << greenPS << " " << bluePS << " setrgbcolor\n";
929
930 m_currentRed = red;
931 m_currentBlue = blue;
932 m_currentGreen = green;
933 }
934 }
935
936 int size = 10;
937 if (m_font.Ok())
938 size = m_font.GetPointSize ();
939
940 *m_pstream << x << " " << YSCALE (y + size) << " moveto\n";
941
942 // *m_pstream << "(" << text << ")" << " show\n";
943 *m_pstream << "(";
944 int len = strlen ((char *)(const char *)text);
945 int i;
946 for (i = 0; i < len; i++)
947 {
948 /*
949 char ch = text[i];
950 if (ch == ')' || ch == '(' || ch == '\\')
951 *m_pstream << "\\";
952 *m_pstream << ch;
953 */
954 int c = (unsigned char) text[i];
955 if ( c == ')' || c == '(' || c == '\\')
956 {
957 *m_pstream << "\\" << (char) c;
958 }
959 else if ( c >= 128 )
960 {
961 // Cope with character codes > 127
962 char tmp[5];
963 sprintf(tmp, "\\%o", c);
964 *m_pstream << tmp;
965 }
966 else
967 *m_pstream << (char) c;
968 }
969
970 *m_pstream << ")" << " show\n";
971
972 if (m_font.GetUnderlined())
973 {
974 long w, h;
975 GetTextExtent(text, &w, &h);
976 *m_pstream << "gsave " << x << " " << YSCALE (y + size - UnderlinePosition)
977 << " moveto\n"
978 << UnderlineThickness << " setlinewidth "
979 << (x + w) << " " << YSCALE (y + size - UnderlinePosition)
980 << " lineto stroke grestore\n";
981 }
982
983 CalcBoundingBox (x, (long)YSCALE (y + size));
984 CalcBoundingBox (x + size * strlen ((char *)(const char *)text), (long)YSCALE (y));
985 }
986
987
988 void wxPostScriptDC::SetBackground (const wxBrush& brush)
989 {
990 m_backgroundBrush = brush;
991 }
992
993 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function))
994 {
995 }
996
997 static const char *wxPostScriptHeaderEllipse = "\
998 /ellipsedict 8 dict def\n\
999 ellipsedict /mtrx matrix put\n\
1000 /ellipse\n\
1001 { ellipsedict begin\n\
1002 /endangle exch def\n\
1003 /startangle exch def\n\
1004 /yrad exch def\n\
1005 /xrad exch def\n\
1006 /y exch def\n\
1007 /x exch def\n\
1008 /savematrix mtrx currentmatrix def\n\
1009 x y translate\n\
1010 xrad yrad scale\n\
1011 0 0 1 startangle endangle arc\n\
1012 savematrix setmatrix\n\
1013 end\n\
1014 } def\n\
1015 ";
1016
1017 static const char *wxPostScriptHeaderEllipticArc= "\
1018 /ellipticarcdict 8 dict def\n\
1019 ellipticarcdict /mtrx matrix put\n\
1020 /ellipticarc\n\
1021 { ellipticarcdict begin\n\
1022 /do_fill exch def\n\
1023 /endangle exch def\n\
1024 /startangle exch def\n\
1025 /yrad exch def\n\
1026 /xrad exch def \n\
1027 /y exch def\n\
1028 /x exch def\n\
1029 /savematrix mtrx currentmatrix def\n\
1030 x y translate\n\
1031 xrad yrad scale\n\
1032 do_fill { 0 0 moveto } if\n\
1033 0 0 1 startangle endangle arc\n\
1034 savematrix setmatrix\n\
1035 do_fill { fill }{ stroke } ifelse\n\
1036 end\n\
1037 } def\n";
1038
1039 bool wxPostScriptDC::StartDoc (const wxString& message)
1040 {
1041 if (m_filename == "")
1042 {
1043 #ifdef __VMS__
1044 m_filename = "wxtmp.ps";
1045 #else
1046 m_filename = wxGetTempFileName("ps");
1047 #endif
1048 wxThePrintSetupData->SetPrinterFile((char *)(const char *)m_filename);
1049 m_ok = TRUE;
1050 }
1051 else
1052 wxThePrintSetupData->SetPrinterFile((char *)(const char *)m_filename);
1053
1054 #ifdef __VMS__
1055 // steve, 05.09.94
1056 // VMS is sh*t!
1057 m_pstream = new ofstream;
1058 if(fileBuffer) delete[] fileBuffer;
1059 fileBuffer = new char[VMS_BUFSIZ];
1060 m_pstream->setbuf(fileBuffer,VMS_BUFSIZ);
1061 m_pstream->open(wxThePrintSetupData->GetPrinterFile());
1062 #else
1063 m_pstream = new ofstream (wxThePrintSetupData->GetPrinterFile());
1064 #endif
1065 if (!m_pstream || !m_pstream->good())
1066 {
1067 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK);
1068 m_ok = FALSE;
1069 return FALSE;
1070 }
1071 m_ok = TRUE;
1072
1073 SetBrush (*wxBLACK_BRUSH);
1074 SetPen (*wxBLACK_PEN);
1075
1076 wxPageNumber = 1;
1077 m_title = message;
1078 return TRUE;
1079 }
1080
1081
1082 void wxPostScriptDC::EndDoc (void)
1083 {
1084 static char wxPostScriptHeaderReencodeISO1[] =
1085 "\n/reencodeISO {\n"
1086 "dup dup findfont dup length dict begin\n"
1087 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
1088 "/Encoding ISOLatin1Encoding def\n"
1089 "currentdict end definefont\n"
1090 "} def\n"
1091 "/ISOLatin1Encoding [\n"
1092 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1093 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1094 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1095 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1096 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
1097 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
1098 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
1099 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
1100 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
1101 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
1102 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
1103 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1104 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
1105 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
1106 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
1107
1108 static char wxPostScriptHeaderReencodeISO2[] =
1109 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
1110 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
1111 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
1112 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
1113 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
1114 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
1115 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
1116 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
1117 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
1118 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
1119 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
1120 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
1121 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
1122 "/yacute/thorn/ydieresis\n"
1123 "] def\n\n";
1124
1125 if (!m_pstream)
1126 return;
1127 if (m_clipping)
1128 {
1129 m_clipping = FALSE;
1130 *m_pstream << "grestore\n";
1131 }
1132
1133 // Will reuse m_pstream for header
1134 #ifdef __VMS__
1135 // see the definition of fileBuffer for explanation
1136 m_pstream->close(); // steve, 05.09.94
1137 if(fileBuffer) delete[] fileBuffer;
1138 #endif
1139 if (m_pstream)
1140 {
1141 delete m_pstream;
1142 m_pstream = (ofstream *) NULL;
1143 }
1144
1145 // Write header now
1146 // steve, 05.09.94
1147 #ifdef __VMS__
1148 char *header_file = "header.ps";
1149 #else
1150 char *header_file = wxGetTempFileName("ps");
1151 #endif
1152 m_pstream = new ofstream (header_file);
1153
1154 *m_pstream << "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1155 *m_pstream << "%%Title: " << (const char *) m_title << "\n";
1156 *m_pstream << "%%Creator: " << wxTheApp->argv[0] << "\n";
1157 // time_t when; time (&when);
1158 // *m_pstream << "%%CreationDate: " << ctime (&when);
1159 *m_pstream << "%%CreationDate: " << wxNow() << "\n";
1160
1161 // User Id information
1162 char userID[256];
1163 if ( wxGetEmailAddress(userID, sizeof(userID)) )
1164 {
1165 *m_pstream << "%%For: " << (char *)userID;
1166 char userName[245];
1167 if (wxGetUserName(userName, sizeof(userName)))
1168 *m_pstream << " (" << (char *)userName << ")";
1169 *m_pstream << "\n";
1170 }
1171 else if ( wxGetUserName(userID, sizeof(userID)) )
1172 {
1173 *m_pstream << "%%For: " << (char *)userID << "\n";
1174 }
1175
1176 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1177
1178 long wx_printer_translate_x, wx_printer_translate_y;
1179 double wx_printer_scale_x, wx_printer_scale_y;
1180 wxThePrintSetupData->GetPrinterTranslation(&wx_printer_translate_x, &wx_printer_translate_y);
1181 wxThePrintSetupData->GetPrinterScaling(&wx_printer_scale_x, &wx_printer_scale_y);
1182
1183 if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE)
1184 {
1185 *m_pstream << "%%Orientation: Landscape\n";
1186 }
1187 else
1188 {
1189 *m_pstream << "%%Orientation: Portrait\n";
1190 }
1191
1192 // Compute the bounding box. Note that it is in the default user
1193 // coordinate system, thus we have to convert the values.
1194 long llx = (long) ((m_minX+wx_printer_translate_x)*wx_printer_scale_x);
1195 long lly = (long) ((m_minY+wx_printer_translate_y)*wx_printer_scale_y);
1196 long urx = (long) ((m_maxX+wx_printer_translate_x)*wx_printer_scale_x);
1197 long ury = (long) ((m_maxY+wx_printer_translate_y)*wx_printer_scale_y);
1198
1199 #if 0
1200 // If we're landscape, our sense of "x" and "y" is reversed.
1201 if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE)
1202 {
1203 double tmp;
1204 tmp = llx; llx = lly; lly = tmp;
1205 tmp = urx; urx = ury; ury = tmp;
1206
1207 // We need either the two lines that follow, or we need to subtract
1208 // min_x from real_translate_y, which is commented out below.
1209 llx = llx - m_minX*wx_printer_scale_y;
1210 urx = urx - m_minX*wx_printer_scale_y;
1211 }
1212 #endif
1213
1214 // The Adobe specifications call for integers; we round as to make
1215 // the bounding larger.
1216 *m_pstream << "%%BoundingBox: "
1217 << floor((double)llx) << " " << floor((double)lly) << " "
1218 << ceil((double)urx) << " " << ceil((double)ury) << "\n";
1219 *m_pstream << "%%Pages: " << (wxPageNumber - 1) << "\n";
1220 *m_pstream << "%%EndComments\n\n";
1221
1222 // To check the correctness of the bounding box, postscript commands
1223 // to draw a box corresponding to the bounding box are generated below.
1224 // But since we typically don't want to print such a box, the postscript
1225 // commands are generated within comments. These lines appear before any
1226 // adjustment of scale, rotation, or translation, and hence are in the
1227 // default user coordinates.
1228 *m_pstream << "% newpath\n";
1229 *m_pstream << "% " << llx << " " << lly << " moveto\n";
1230 *m_pstream << "% " << urx << " " << lly << " lineto\n";
1231 *m_pstream << "% " << urx << " " << ury << " lineto\n";
1232 *m_pstream << "% " << llx << " " << ury << " lineto closepath stroke\n";
1233
1234 #if 0
1235 // Output scaling
1236 long real_translate_y = wx_printer_translate_y;
1237 if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE)
1238 {
1239 real_translate_y -= m_maxY;
1240 // The following line can be used instead of the adjustment to
1241 // llx and urx above.
1242 // real_translate_y -= m_minX;
1243 *m_pstream << "90 rotate\n";
1244 }
1245
1246 /* Probably don't want this now we have it in EndPage, below.
1247 * We should rationalise the scaling code to one place. JACS, October 1995
1248 * Do we take the next 2 lines out or not?
1249 */
1250
1251 *m_pstream << wx_printer_scale_x << " " << wx_printer_scale_y << " scale\n";
1252 *m_pstream << wx_printer_translate_x << " " << real_translate_y << " translate\n";
1253 #endif
1254
1255 *m_pstream << "%%BeginProlog\n";
1256 *m_pstream << wxPostScriptHeaderEllipse;
1257 *m_pstream << wxPostScriptHeaderEllipticArc;
1258 *m_pstream << wxPostScriptHeaderReencodeISO1;
1259 *m_pstream << wxPostScriptHeaderReencodeISO2;
1260
1261 if (wxPostScriptHeaderSpline)
1262 *m_pstream << wxPostScriptHeaderSpline;
1263 *m_pstream << "%%EndProlog\n";
1264
1265 delete m_pstream;
1266 m_pstream = (ofstream *) NULL;
1267
1268 #ifdef __VMS__
1269 char *tmp_file = "tmp.ps";
1270 #else
1271 char *tmp_file = wxGetTempFileName("ps");
1272 #endif
1273
1274 // Paste header Before wx_printer_file
1275 wxConcatFiles (header_file, wxThePrintSetupData->GetPrinterFile(), tmp_file);
1276 wxRemoveFile (header_file);
1277 wxRemoveFile (wxThePrintSetupData->GetPrinterFile());
1278 wxRenameFile(tmp_file, wxThePrintSetupData->GetPrinterFile());
1279
1280 #if defined(__X__) || defined(__WXGTK__)
1281 if (m_ok)
1282 {
1283 switch (wxThePrintSetupData->GetPrinterMode()) {
1284 case PS_PREVIEW:
1285 {
1286 char *argv[3];
1287 argv[0] = wxThePrintSetupData->GetPrintPreviewCommand();
1288 argv[1] = wxThePrintSetupData->GetPrinterFile();
1289 argv[2] = (char *) NULL;
1290 wxExecute (argv, TRUE);
1291 wxRemoveFile(wxThePrintSetupData->GetPrinterFile());
1292 }
1293 break;
1294
1295 case PS_PRINTER:
1296 {
1297 char *argv[4];
1298 int argc = 0;
1299 argv[argc++] = wxThePrintSetupData->GetPrinterCommand();
1300
1301 // !SM! If we simply assign to argv[1] here, if printer options
1302 // are blank, we get an annoying and confusing message from lpr.
1303 char * opts = wxThePrintSetupData->GetPrinterOptions();
1304 if (opts && *opts)
1305 argv[argc++] = opts;
1306
1307 argv[argc++] = wxThePrintSetupData->GetPrinterFile();
1308 argv[argc++] = (char *) NULL;
1309 wxExecute (argv, TRUE);
1310 wxRemoveFile(wxThePrintSetupData->GetPrinterFile());
1311 }
1312 break;
1313
1314 case PS_FILE:
1315 break;
1316 }
1317 }
1318 #endif
1319 }
1320
1321 void wxPostScriptDC::StartPage (void)
1322 {
1323 if (!m_pstream)
1324 return;
1325 *m_pstream << "%%Page: " << (wxPageNumber++) << "\n";
1326 // *m_pstream << "matrix currentmatrix\n";
1327
1328 // Added by Chris Breeze
1329
1330 // Each page starts with an "initgraphics" which resets the
1331 // transformation and so we need to reset the origin
1332 // (and rotate the page for landscape printing)
1333 m_scaleFactor = 1.0;
1334 m_logicalOriginX = 0;
1335 m_logicalOriginY = 0;
1336
1337 // Output scaling
1338 long translate_x, translate_y;
1339 double scale_x, scale_y;
1340 wxThePrintSetupData->GetPrinterTranslation(&translate_x, &translate_y);
1341 wxThePrintSetupData->GetPrinterScaling(&scale_x, &scale_y);
1342
1343 if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE)
1344 {
1345 translate_y -= GetYOrigin();
1346 *m_pstream << "90 rotate\n";
1347 }
1348
1349 *m_pstream << scale_x << " " << scale_y << " scale\n";
1350 *m_pstream << translate_x << " " << translate_y << " translate\n";
1351 }
1352
1353 void wxPostScriptDC::EndPage (void)
1354 {
1355 if (!m_pstream)
1356 return;
1357 *m_pstream << "showpage\n";
1358
1359 // Removed by Chris Breeze
1360 #if 0
1361 *m_pstream << "setmatrix\n";
1362
1363 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1364
1365 long wx_printer_translate_x, wx_printer_translate_y;
1366 double wx_printer_scale_x, wx_printer_scale_y;
1367 wxThePrintSetupData->GetPrinterTranslation(&wx_printer_translate_x, &wx_printer_translate_y);
1368 wxThePrintSetupData->GetPrinterScaling(&wx_printer_scale_x, &wx_printer_scale_y);
1369
1370 // Compute the bounding box. Note that it is in the default user
1371 // coordinate system, thus we have to convert the values.
1372 long llx = (m_minX+wx_printer_translate_x)*wx_printer_scale_x;
1373 long lly = (m_minY+wx_printer_translate_y)*wx_printer_scale_y;
1374 long urx = (m_maxX+wx_printer_translate_x)*wx_printer_scale_x;
1375 long ury = (m_maxY+wx_printer_translate_y)*wx_printer_scale_y;
1376
1377 // If we're landscape, our sense of "x" and "y" is reversed.
1378 if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE)
1379 {
1380 long tmp;
1381 tmp = llx; llx = lly; lly = tmp;
1382 tmp = urx; urx = ury; ury = tmp;
1383
1384 // We need either the two lines that follow, or we need to subtract
1385 // m_minX from real_translate_y, which is commented out below.
1386 llx = llx - m_minX*wx_printer_scale_y;
1387 urx = urx - m_minX*wx_printer_scale_y;
1388 }
1389
1390 // Output scaling
1391 long real_translate_y = wx_printer_translate_y;
1392 if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE)
1393 {
1394 real_translate_y -= m_maxY;
1395 // The following line can be used instead of the adjustment to
1396 // llx and urx above.
1397 // real_translate_y -= m_minX;
1398 *m_pstream << "90 rotate\n";
1399 }
1400
1401 *m_pstream << wx_printer_scale_x << " " << wx_printer_scale_y << " scale\n";
1402 *m_pstream << wx_printer_translate_x << " " << real_translate_y << " translate\n";
1403 #endif
1404 }
1405
1406 bool wxPostScriptDC::
1407 Blit (long xdest, long ydest, long fwidth, long fheight,
1408 wxDC *source, long xsrc, long ysrc, int WXUNUSED(rop), bool WXUNUSED(useMask))
1409 {
1410 long width, height, x, y;
1411
1412 #if !defined(__X__) && !defined(__WXGTK__)
1413 return FALSE;
1414 #endif
1415
1416 if (!source->IsKindOf(CLASSINFO(wxPaintDC))) return FALSE;
1417
1418 width = (long)floor((double)fwidth);
1419 height = (long)floor((double)fheight);
1420 x = (long)floor((double)xsrc);
1421 y = (long)floor((double)ysrc);
1422
1423 /* PostScript setup: */
1424 *m_pstream << "gsave\n";
1425 *m_pstream << xdest << " " << YSCALE(ydest + fheight) << " translate\n";
1426 *m_pstream << fwidth << " " << fheight << " scale\n";
1427 *m_pstream << "/DataString " << width << " string def\n";
1428 *m_pstream << width << " " << height << " 8 [ ";
1429 *m_pstream << width << " 0 0 " << (-height) << " 0 " << height;
1430 *m_pstream << " ]\n{\n";
1431 *m_pstream << " currentfile DataString readhexstring pop\n";
1432 *m_pstream << "} bind image\n";
1433
1434 #if defined(__X__) || defined(__WXGTK__)
1435
1436 /* Output data as hex digits: */
1437 Display *d;
1438 Colormap cm;
1439 XImage *image;
1440 long j, i;
1441 char s[3];
1442
1443 #ifdef __WXGTK__
1444
1445 d = gdk_display;
1446 cm = ((GdkColormapPrivate*)gdk_colormap_get_system())->xcolormap;
1447 GdkWindow *gwin = ((wxClientDC*)source)->GetWindow();
1448 image = XGetImage(d, ((GdkWindowPrivate*)gwin)->xwindow, x, y, width, height, AllPlanes, ZPixmap);
1449
1450 #else
1451
1452 #ifdef __WXMOTIF__
1453 // TODO. for now, use global display
1454 // d = source->display;
1455 d = (Display*) wxGetDisplay();
1456 #else
1457 d = (Display*) wxGetDisplay();
1458 #endif
1459
1460 cm = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) d);
1461 // TODO - implement GetPixmap() and uncomment this line
1462 // image = XGetImage(d, source->GetPixmap(), x, y, width, height, AllPlanes, ZPixmap);
1463
1464 #endif
1465
1466
1467 s[2] = 0;
1468
1469 #define CM_CACHE_SIZE 256
1470 unsigned long cachesrc[CM_CACHE_SIZE];
1471 int cachedest[CM_CACHE_SIZE], cache_pos = 0, all_cache = FALSE;
1472
1473 for (j = 0; j < height; j++) {
1474 for (i = 0; i < width; i++) {
1475 XColor xcol;
1476 unsigned long spixel;
1477 int pixel, k;
1478 const unsigned short MAX_COLOR = 0xFFFF;
1479
1480 spixel = XGetPixel(image, i, j);
1481
1482 for (k = cache_pos; k--; )
1483 if (cachesrc[k] == spixel) {
1484 pixel = cachedest[k];
1485 goto install;
1486 }
1487 if (all_cache)
1488 for (k = CM_CACHE_SIZE; k-- > cache_pos; )
1489 if (cachesrc[k] == spixel) {
1490 pixel = cachedest[k];
1491 goto install;
1492 }
1493
1494 cachesrc[cache_pos] = xcol.pixel = spixel;
1495 XQueryColor(d, cm, &xcol);
1496
1497 long r, g, b;
1498
1499 r = (long)((double)(xcol.red) / MAX_COLOR);
1500 g = (long)((double)(xcol.green) / MAX_COLOR);
1501 b = (long)((double)(xcol.blue) / MAX_COLOR);
1502
1503 pixel = (int)(255 * sqrt(((r * r) + (g * g) + (b * b)) / 3));
1504
1505 cachedest[cache_pos] = pixel;
1506
1507 if (++cache_pos >= CM_CACHE_SIZE) {
1508 cache_pos = 0;
1509 all_cache = TRUE;
1510 }
1511
1512 install:
1513 int h, l;
1514
1515 h = (pixel >> 4) & 0xF;
1516 l = pixel & 0xF;
1517
1518 if (h <= 9)
1519 s[0] = '0' + h;
1520 else
1521 s[0] = 'a' + (h - 10);
1522 if (l <= 9)
1523 s[1] = '0' + l;
1524 else
1525 s[1] = 'a' + (l - 10);
1526
1527 *m_pstream << s;
1528 }
1529 *m_pstream << "\n";
1530 }
1531
1532 XDestroyImage(image);
1533 #endif
1534
1535 *m_pstream << "grestore\n";
1536
1537 CalcBoundingBox(xdest, (long)YSCALE(ydest));
1538 CalcBoundingBox(xdest + fwidth, (long)YSCALE(ydest + fheight));
1539
1540 return TRUE;
1541 }
1542
1543 long wxPostScriptDC::GetCharHeight (void)
1544 {
1545 if (m_font.Ok())
1546 return m_font.GetPointSize ();
1547 else
1548 return 12;
1549 }
1550
1551 void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y,
1552 long *descent, long *externalLeading, wxFont *theFont,
1553 bool WXUNUSED(use16))
1554 {
1555 wxFont *fontToUse = theFont;
1556 if (!fontToUse)
1557 fontToUse = (wxFont*) &m_font;
1558
1559 if (!m_pstream)
1560 return;
1561 #if !USE_AFM_FOR_POSTSCRIPT
1562 // Provide a VERY rough estimate (avoid using it)
1563 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1564 // font such as Courier (aka wxMODERN)
1565 int height = 12;
1566 if (fontToUse)
1567 {
1568 height = fontToUse->GetPointSize();
1569 }
1570 *x = strlen (string) * height * 72 / 120;
1571 *y = (long) (height * 1.32); // allow for descender
1572
1573 if (descent)
1574 *descent = 0;
1575 if (externalLeading)
1576 *externalLeading = 0;
1577 #else
1578 // +++++ start of contributed code +++++
1579
1580 // ************************************************************
1581 // method for calculating string widths in postscript:
1582 // read in the AFM (adobe font metrics) file for the
1583 // actual font, parse it and extract the character widths
1584 // and also the descender. this may be improved, but for now
1585 // it works well. the AFM file is only read in if the
1586 // font is changed. this may be chached in the future.
1587 // calls to GetTextExtent with the font unchanged are rather
1588 // efficient!!!
1589 //
1590 // for each font and style used there is an AFM file necessary.
1591 // currently i have only files for the roman font family.
1592 // i try to get files for the other ones!
1593 //
1594 // CAVE: the size of the string is currently always calculated
1595 // in 'points' (1/72 of an inch). this should later on be
1596 // changed to depend on the mapping mode.
1597 // CAVE: the path to the AFM files must be set before calling this
1598 // function. this is usually done by a call like the following:
1599 // wxSetAFMPath("d:\\wxw161\\afm\\");
1600 //
1601 // example:
1602 //
1603 // wxPostScriptDC dc(NULL, TRUE);
1604 // if (dc.Ok()){
1605 // wxSetAFMPath("d:\\wxw161\\afm\\");
1606 // dc.StartDoc("Test");
1607 // dc.StartPage();
1608 // long w,h;
1609 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1610 // dc.GetTextExtent("Hallo",&w,&h);
1611 // dc.EndPage();
1612 // dc.EndDoc();
1613 // }
1614 //
1615 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1616 // created: 10.09.94
1617 // updated: 14.05.95
1618
1619 assert(fontToUse && "void wxPostScriptDC::GetTextExtent: no font defined");
1620 assert(x && "void wxPostScriptDC::GetTextExtent: x == NULL");
1621 assert(y && "void wxPostScriptDC::GetTextExtent: y == NULL");
1622
1623 // these static vars are for storing the state between calls
1624 static int lastFamily= INT_MIN;
1625 static int lastSize= INT_MIN;
1626 static int lastStyle= INT_MIN;
1627 static int lastWeight= INT_MIN;
1628 static int lastDescender = INT_MIN;
1629 static int lastWidths[256]; // widths of the characters
1630
1631 // get actual parameters
1632 const int Family = fontToUse->GetFamily();
1633 const int Size = fontToUse->GetPointSize();
1634 const int Style = fontToUse->GetStyle();
1635 const int Weight = fontToUse->GetWeight();
1636
1637 // if we have another font, read the font-metrics
1638 if(Family!=lastFamily||Size!=lastSize||Style!=lastStyle||Weight!=lastWeight){
1639 // store actual values
1640 lastFamily = Family;
1641 lastSize = Size;
1642 lastStyle = Style;
1643 lastWeight = Weight;
1644
1645 // read in new font metrics **************************************
1646
1647 // 1. construct filename ******************************************
1648 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1649 const char *name;
1650
1651 // Julian - we'll need to do this a different way now we've removed the
1652 // font directory system. Must find Stefan's original code.
1653
1654 name = wxTheFontNameDirectory->GetAFMName(Family, Weight, Style);
1655 if (!name)
1656 name = "unknown";
1657
1658 // get the directory of the AFM files
1659 char afmName[256];
1660 afmName[0] = 0;
1661 if (wxGetAFMPath())
1662 strcpy(afmName,wxGetAFMPath());
1663
1664 // 2. open and process the file **********************************
1665
1666 // a short explanation of the AFM format:
1667 // we have for each character a line, which gives its size
1668 // e.g.:
1669 //
1670 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1671 //
1672 // that means, we have a character with ascii code 63, and width
1673 // (444/1000 * fontSize) points.
1674 // the other data is ignored for now!
1675 //
1676 // when the font has changed, we read in the right AFM file and store the
1677 // character widths in an array, which is processed below (see point 3.).
1678
1679 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1680
1681
1682 strcat(afmName,name);
1683 strcat(afmName,".afm");
1684 FILE *afmFile = fopen(afmName,"r");
1685 if(afmFile==NULL){
1686 wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName);
1687 wxDebugMsg(" using approximate values\n");
1688 int i;
1689 for (i=0; i<256; i++) lastWidths[i] = 500; // an approximate value
1690 lastDescender = -150; // dito.
1691 }else{
1692 int i;
1693 // init the widths array
1694 for(i=0; i<256; i++) lastWidths[i]= INT_MIN;
1695 // some variables for holding parts of a line
1696 char cString[10],semiString[10],WXString[10],descString[20];
1697 char upString[30], utString[30], encString[50];
1698 char line[256];
1699 int ascii,cWidth;
1700 // read in the file and parse it
1701 while(fgets(line,sizeof(line),afmFile)!=NULL){
1702 // A.) check for descender definition
1703 if(strncmp(line,"Descender",9)==0){
1704 if((sscanf(line,"%s%d",descString,&lastDescender)!=2)
1705 || (strcmp(descString,"Descender")!=0)) {
1706 wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n",
1707 afmName,line);
1708 }
1709 }
1710 // JC 1.) check for UnderlinePosition
1711 else if(strncmp(line,"UnderlinePosition",17)==0){
1712 if((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2)
1713 || (strcmp(upString,"UnderlinePosition")!=0)) {
1714 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1715 afmName,line);
1716 }
1717 }
1718 // JC 2.) check for UnderlineThickness
1719 else if(strncmp(line,"UnderlineThickness",18)==0){
1720 if((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2)
1721 || (strcmp(utString,"UnderlineThickness")!=0)) {
1722 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1723 afmName,line);
1724 }
1725 }
1726 // JC 3.) check for EncodingScheme
1727 else if(strncmp(line,"EncodingScheme",14)==0){
1728 if((sscanf(line,"%s%s",utString,encString)!=2)
1729 || (strcmp(utString,"EncodingScheme")!=0)) {
1730 wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1731 afmName,line);
1732 }
1733 else if (strncmp(encString, "AdobeStandardEncoding", 21))
1734 {
1735 wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1736 afmName,line, encString);
1737 }
1738 }
1739 // B.) check for char-width
1740 else if(strncmp(line,"C ",2)==0){
1741 if(sscanf(line,"%s%d%s%s%d",
1742 cString,&ascii,semiString,WXString,&cWidth)!=5){
1743 wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName,line);
1744 }
1745 if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 ||
1746 strcmp(WXString,"WX")!=0){
1747 wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName,line);
1748 }
1749 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1750 if(ascii>=0 && ascii<256){
1751 lastWidths[ascii] = cWidth; // store width
1752 }else{
1753 /* MATTHEW: this happens a lot; don't print an error */
1754 // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1755 }
1756 }
1757 // C.) ignore other entries.
1758 }
1759 fclose(afmFile);
1760 }
1761 // hack to compute correct values for german 'Umlaute'
1762 // the correct way would be to map the character names
1763 // like 'adieresis' to corresp. positions of ISOEnc and read
1764 // these values from AFM files, too. Maybe later ...
1765 lastWidths[196] = lastWidths['A']; // Ä
1766 lastWidths[228] = lastWidths['a']; // ä
1767 lastWidths[214] = lastWidths['O']; // Ö
1768 lastWidths[246] = lastWidths['o']; // ö
1769 lastWidths[220] = lastWidths['U']; // Ü
1770 lastWidths[252] = lastWidths['u']; // ü
1771 lastWidths[223] = lastWidths[251]; // ß
1772 }
1773
1774 // JC: calculate UnderlineThickness/UnderlinePosition
1775 UnderlinePosition = UnderlinePosition * fontToUse->GetPointSize() / 1000.0f;
1776 UnderlineThickness = UnderlineThickness * fontToUse->GetPointSize() / 1000.0f * m_scaleFactor;
1777
1778 // 3. now the font metrics are read in, calc size *******************
1779 // this is done by adding the widths of the characters in the
1780 // string. they are given in 1/1000 of the size!
1781
1782 long widthSum=0;
1783 long height=Size; // by default
1784 unsigned char *p;
1785 for(p=(unsigned char *)(const char *)string; *p; p++){
1786 if(lastWidths[*p]== INT_MIN){
1787 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1788 *p,*p);
1789 widthSum += (long)(lastWidths[' ']/1000.0F * Size); // assume space
1790 }else{
1791 widthSum += (long)((lastWidths[*p]/1000.0F)*Size);
1792 }
1793 }
1794 // add descender to height (it is usually a negative value)
1795 if(lastDescender!=INT_MIN){
1796 height += (long)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
1797 }
1798
1799 // return size values
1800 *x = widthSum;
1801 *y = height;
1802
1803 // return other parameters
1804 if (descent){
1805 if(lastDescender!=INT_MIN){
1806 *descent = (long)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
1807 }else{
1808 *descent = 0;
1809 }
1810 }
1811
1812 // currently no idea how to calculate this!
1813 // if (externalLeading) *externalLeading = 0;
1814 if (externalLeading)
1815 *externalLeading = 0;
1816
1817 // ----- end of contributed code -----
1818 #endif
1819 }
1820
1821 void wxPostScriptDC::DrawSpline( wxList *points )
1822 {
1823 double a, b, c, d, x1, y1, x2, y2, x3, y3;
1824 wxPoint *p, *q;
1825
1826 wxNode *node = points->First();
1827 p = (wxPoint *)node->Data();
1828
1829 x1 = p->x; y1 = p->y;
1830
1831 node = node->Next();
1832 p = (wxPoint *)node->Data();
1833 c = p->x; d = p->y;
1834 x3 = a = (double)(x1 + c) / 2;
1835 y3 = b = (double)(y1 + d) / 2;
1836
1837 *(GetStream()) << "newpath " << x1 << " " << (GetYOrigin() - y1) << " moveto " << x3 << " " << (GetYOrigin() - y3);
1838 *(GetStream()) << " lineto\n";
1839 CalcBoundingBox( (long)x1, (long)(GetYOrigin() - y1));
1840 CalcBoundingBox( (long)x3, (long)(GetYOrigin() - y3));
1841
1842 while ((node = node->Next()) != NULL)
1843 {
1844 q = (wxPoint *)node->Data();
1845
1846 x1 = x3; y1 = y3;
1847 x2 = c; y2 = d;
1848 c = q->x; d = q->y;
1849 x3 = (double)(x2 + c) / 2;
1850 y3 = (double)(y2 + d) / 2;
1851 *(GetStream()) << x1 << " " << (GetYOrigin() - y1) << " " << x2 << " " << (GetYOrigin() - y2) << " ";
1852 *(GetStream()) << x3 << " " << (GetYOrigin() - y3) << " DrawSplineSection\n";
1853
1854 CalcBoundingBox( (long)x1, (long)(GetYOrigin() - y1));
1855 CalcBoundingBox( (long)x3, (long)(GetYOrigin() - y3));
1856 }
1857 /*
1858 * At this point, (x2,y2) and (c,d) are the position of the
1859 * next-to-last and last point respectively, in the point list
1860 */
1861 *(GetStream()) << c << " " << (GetYOrigin() - d) << " lineto stroke\n";
1862 }
1863
1864 long wxPostScriptDC::GetCharWidth (void)
1865 {
1866 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1867 return (long) (GetCharHeight() * 72.0 / 120.0);
1868 }
1869
1870
1871 void wxPostScriptDC::SetMapMode (int mode)
1872 {
1873 m_mappingMode = mode;
1874 SetLogicalOrigin(0, 0);
1875 if(m_mappingMode == MM_METRIC)
1876 {
1877 SetUserScale(72.0f / 25.4f, 72.0f / 25.4f);
1878 }
1879 else
1880 {
1881 SetUserScale(1.0, 1.0);
1882 }
1883 return;
1884 }
1885
1886 /*
1887 * Set the logical origin.
1888 * Actually we are setting the printer's origin and since
1889 * postscript transformations are cumulative we need to reset
1890 * the previous origin. We also need to allow for the user scale
1891 * factor (which affects printer coords but not logical)
1892 */
1893 void wxPostScriptDC::SetLogicalOrigin(long x, long y)
1894 {
1895 if (m_scaleFactor)
1896 {
1897 long xOffset = (long) ((m_logicalOriginX - x) / m_scaleFactor);
1898 long yOffset = (long) ((y - m_logicalOriginY) / m_scaleFactor);
1899
1900 if (m_pstream)
1901 {
1902 *m_pstream << xOffset << " " << yOffset << " translate\n";
1903 }
1904 }
1905 m_logicalOriginX = x;
1906 m_logicalOriginY = y;
1907 }
1908
1909 /*
1910 * Obsolete - now performed by SetUserScale() and SetLogicalOrigin()
1911 */
1912 void
1913 wxPostScriptDC::SetupCTM()
1914 {
1915 }
1916
1917 /*
1918 * Set the user scale.
1919 * NB: Postscript transformations are cumulative and so we
1920 * need to take into account the current scale. Also, this
1921 * affects the logical origin
1922 */
1923 void wxPostScriptDC::SetUserScale (double x, double y)
1924 {
1925 // reset logical origin
1926 long xOrg = m_logicalOriginX;
1927 long yOrg = m_logicalOriginY;
1928 SetLogicalOrigin(0, 0);
1929
1930 // set new scale factor
1931 double factor = x;
1932 if (m_scaleFactor)
1933 {
1934 factor /= m_scaleFactor;
1935 }
1936 if (m_pstream)
1937 {
1938 *m_pstream << factor << " " << factor << " scale\n";
1939 }
1940
1941 // set logical origin at new scale
1942 SetLogicalOrigin(xOrg, yOrg);
1943
1944 m_userScaleX = x;
1945 m_userScaleY = y;
1946
1947 m_scaleFactor = m_userScaleX;
1948 }
1949
1950 long wxPostScriptDC::DeviceToLogicalX (int x) const
1951 {
1952 return x;
1953 }
1954
1955 long wxPostScriptDC::DeviceToLogicalXRel (int x) const
1956 {
1957 return x;
1958 }
1959
1960 long wxPostScriptDC::DeviceToLogicalY (int y) const
1961 {
1962 return y;
1963 }
1964
1965 long wxPostScriptDC::DeviceToLogicalYRel (int y) const
1966 {
1967 return y;
1968 }
1969
1970 long wxPostScriptDC::LogicalToDeviceX (long x) const
1971 {
1972 return x;
1973 }
1974
1975 long wxPostScriptDC::LogicalToDeviceXRel (long x) const
1976 {
1977 return x;
1978 }
1979
1980 long wxPostScriptDC::LogicalToDeviceY (long y) const
1981 {
1982 return y;
1983 }
1984
1985 long wxPostScriptDC::LogicalToDeviceYRel (long y) const
1986 {
1987 return y;
1988 }
1989
1990 void wxPostScriptDC::GetSize(int* width, int* height) const
1991 {
1992 const char *paperType = wxThePrintSetupData->GetPaperName();
1993 if (!paperType)
1994 paperType = _("A4 210 x 297 mm");
1995
1996 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
1997 if (!paper)
1998 paper = wxThePrintPaperDatabase->FindPaperType(_("A4 210 x 297 mm"));
1999 if (paper)
2000 {
2001 *width = paper->widthPixels;
2002 *height = paper->heightPixels;
2003 }
2004 else
2005 {
2006 *width = 1000;
2007 *height = 1000;
2008 }
2009 }
2010
2011 void wxPostScriptDC::GetSizeMM(long *width, long *height) const
2012 {
2013 const char *paperType = wxThePrintSetupData->GetPaperName();
2014 if (!paperType)
2015 paperType = _("A4 210 x 297 mm");
2016
2017 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
2018 if (!paper)
2019 paper = wxThePrintPaperDatabase->FindPaperType(_("A4 210 x 297 mm"));
2020 if (paper)
2021 {
2022 *width = paper->widthMM;
2023 *height = paper->heightMM;
2024 }
2025 else
2026 {
2027 *width = 1000;
2028 *height = 1000;
2029 }
2030 }
2031
2032 void wxPostScriptDC::CalcBoundingBox(long x, long y)
2033 {
2034 long device_x = (long) (x - m_logicalOriginX * m_scaleFactor);
2035 long device_y = (long) (y + m_logicalOriginY * m_scaleFactor);
2036
2037 if (device_x < m_minX) m_minX = device_x;
2038 if (device_y < m_minY) m_minY = device_y;
2039 if (device_x > m_maxX) m_maxX = device_x;
2040 if (device_y > m_maxY) m_maxY = device_y;
2041 }
2042
2043 IMPLEMENT_CLASS(wxPostScriptPrintDialog, wxDialog)
2044
2045 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow *parent, const wxString& title,
2046 const wxPoint& pos, const wxSize& size, long style):
2047 wxDialog(parent, -1, title, pos, size, style)
2048 {
2049 wxBeginBusyCursor();
2050 char buf[100];
2051
2052 wxButton *okBut = new wxButton (this, wxID_OK, _("OK"), wxPoint(5, 5));
2053 (void) new wxButton (this, wxID_CANCEL, _("Cancel"), wxPoint(40, 5));
2054 okBut->SetDefault();
2055
2056 int yPos = 40;
2057
2058 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2059 (void) new wxStaticText( this, -1, _("Printer Command: "),
2060 wxPoint(5, yPos) );
2061 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND, wxThePrintSetupData->GetPrinterCommand(),
2062 wxPoint(100, yPos), wxSize(100, -1) );
2063
2064 (void) new wxStaticText( this, -1, _("Printer Options: "),
2065 wxPoint(210, yPos) );
2066 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS, wxThePrintSetupData->GetPrinterOptions(),
2067 wxPoint(305, yPos), wxSize(150, -1) );
2068
2069 yPos += 40;
2070 #endif
2071
2072 wxString orientation[2];
2073 orientation[0] = _("Portrait");
2074 orientation[1] = _("Landscape");
2075
2076 wxRadioBox *radio0 = new wxRadioBox(this, wxID_PRINTER_ORIENTATION, "Orientation: ", wxPoint(5, yPos), wxSize(-1,-1),
2077 2,orientation,2,0);
2078 radio0->SetSelection((int)wxThePrintSetupData->GetPrinterOrientation() - 1);
2079
2080 // @@@ Configuration hook
2081 if (wxThePrintSetupData->GetPrintPreviewCommand() == NULL)
2082 wxThePrintSetupData->SetPrintPreviewCommand(PS_VIEWER_PROG);
2083
2084 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->previewCommand);
2085
2086 wxString print_modes[3];
2087 print_modes[0] = _("Send to Printer");
2088 print_modes[1] = _("Print to File");
2089 print_modes[2] = _("Preview Only");
2090
2091 int features = (wxThePrintSetupData->GetPrintPreviewCommand() && *wxThePrintSetupData->GetPrintPreviewCommand()) ? 3 : 2;
2092 wxRadioBox *radio1 = new wxRadioBox(this, wxID_PRINTER_MODES, _("PostScript:"),
2093 wxPoint(150, yPos), wxSize(-1,-1), features, print_modes, features, 0);
2094
2095 #ifdef __WXMSW__
2096 radio1->Enable(0, FALSE);
2097 if (wxThePrintSetupData->GetPrintPreviewCommand() && *wxThePrintSetupData->GetPrintPreviewCommand())
2098 radio1->Enable(2, FALSE);
2099 #endif
2100
2101 radio1->SetSelection((int)wxThePrintSetupData->GetPrinterMode());
2102
2103 long wx_printer_translate_x, wx_printer_translate_y;
2104 double wx_printer_scale_x, wx_printer_scale_y;
2105 wxThePrintSetupData->GetPrinterTranslation(&wx_printer_translate_x, &wx_printer_translate_y);
2106 wxThePrintSetupData->GetPrinterScaling(&wx_printer_scale_x, &wx_printer_scale_y);
2107
2108 sprintf (buf, "%.2f", wx_printer_scale_x);
2109
2110 yPos += 90;
2111
2112 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos));
2113 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE, buf, wxPoint(100, yPos), wxSize(100, -1));
2114
2115 sprintf (buf, "%.2f", wx_printer_scale_y);
2116 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos));
2117 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE, buf, wxPoint(320, yPos), wxSize(100, -1));
2118
2119 yPos += 25;
2120
2121 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos));
2122 sprintf (buf, "%.2ld", wx_printer_translate_x);
2123 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS, buf, wxPoint(100, yPos), wxSize(100, -1));
2124
2125 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos));
2126 sprintf (buf, "%.2ld", wx_printer_translate_y);
2127 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS, buf, wxPoint(320, yPos), wxSize(100, -1));
2128
2129 Fit ();
2130
2131 wxEndBusyCursor();
2132 }
2133
2134 int wxPostScriptPrintDialog::ShowModal (void)
2135 {
2136 if ( wxDialog::ShowModal() == wxID_OK )
2137 {
2138 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2139 wxTextCtrl *text1 = (wxTextCtrl *)FindWindow(wxID_PRINTER_X_SCALE);
2140 wxTextCtrl *text2 = (wxTextCtrl *)FindWindow(wxID_PRINTER_Y_SCALE);
2141 wxTextCtrl *text3 = (wxTextCtrl *)FindWindow(wxID_PRINTER_X_TRANS);
2142 wxTextCtrl *text4 = (wxTextCtrl *)FindWindow(wxID_PRINTER_Y_TRANS);
2143 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2144 wxRadioBox *radio0 = (wxRadioBox *)FindWindow(wxID_PRINTER_ORIENTATION);
2145 wxRadioBox *radio1 = (wxRadioBox *)FindWindow(wxID_PRINTER_MODES);
2146
2147 StringToDouble (WXSTRINGCAST text1->GetValue (), &wxThePrintSetupData->printerScaleX);
2148 StringToDouble (WXSTRINGCAST text2->GetValue (), &wxThePrintSetupData->printerScaleY);
2149 StringToLong (WXSTRINGCAST text3->GetValue (), &wxThePrintSetupData->printerTranslateX);
2150 StringToLong (WXSTRINGCAST text4->GetValue (), &wxThePrintSetupData->printerTranslateY);
2151
2152 #ifdef __X__
2153 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2154 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2155 #endif
2156
2157 wxThePrintSetupData->SetPrinterOrientation((radio0->GetSelection() == 1 ? PS_LANDSCAPE : PS_PORTRAIT));
2158
2159 // C++ wants this
2160 switch ( radio1->GetSelection() ) {
2161 case 0: wxThePrintSetupData->SetPrinterMode(PS_PRINTER); break;
2162 case 1: wxThePrintSetupData->SetPrinterMode(PS_FILE); break;
2163 case 2: wxThePrintSetupData->SetPrinterMode(PS_PREVIEW); break;
2164 }
2165 return wxID_OK;
2166 }
2167 return wxID_CANCEL;
2168 }
2169
2170 // PostScript printer settings
2171 // RETAINED FOR BACKWARD COMPATIBILITY
2172 void wxSetPrinterCommand(const char *cmd)
2173 {
2174 wxThePrintSetupData->SetPrinterCommand(cmd);
2175 }
2176
2177 void wxSetPrintPreviewCommand(const char *cmd)
2178 {
2179 wxThePrintSetupData->SetPrintPreviewCommand(cmd);
2180 }
2181
2182 void wxSetPrinterOptions(const char *flags)
2183 {
2184 wxThePrintSetupData->SetPrinterOptions(flags);
2185 }
2186
2187 void wxSetPrinterFile(const char *f)
2188 {
2189 wxThePrintSetupData->SetPrinterFile(f);
2190 }
2191
2192 void wxSetPrinterOrientation(int orient)
2193 {
2194 wxThePrintSetupData->SetPrinterOrientation(orient);
2195 }
2196
2197 void wxSetPrinterScaling(double x, double y)
2198 {
2199 wxThePrintSetupData->SetPrinterScaling(x, y);
2200 }
2201
2202 void wxSetPrinterTranslation(long x, long y)
2203 {
2204 wxThePrintSetupData->SetPrinterTranslation(x, y);
2205 }
2206
2207 // 1 = Preview, 2 = print to file, 3 = send to printer
2208 void wxSetPrinterMode(int mode)
2209 {
2210 wxThePrintSetupData->SetPrinterMode(mode);
2211 }
2212
2213 void wxSetAFMPath(const char *f)
2214 {
2215 wxThePrintSetupData->SetAFMPath(f);
2216 }
2217
2218 // Get current values
2219 char *wxGetPrinterCommand(void)
2220 {
2221 return wxThePrintSetupData->GetPrinterCommand();
2222 }
2223
2224 char *wxGetPrintPreviewCommand(void)
2225 {
2226 return wxThePrintSetupData->GetPrintPreviewCommand();
2227 }
2228
2229 char *wxGetPrinterOptions(void)
2230 {
2231 return wxThePrintSetupData->GetPrinterOptions();
2232 }
2233
2234 char *wxGetPrinterFile(void)
2235 {
2236 return wxThePrintSetupData->GetPrinterFile();
2237 }
2238
2239 int wxGetPrinterOrientation(void)
2240 {
2241 return wxThePrintSetupData->GetPrinterOrientation();
2242 }
2243
2244 void wxGetPrinterScaling(double* x, double* y)
2245 {
2246 wxThePrintSetupData->GetPrinterScaling(x, y);
2247 }
2248
2249 void wxGetPrinterTranslation(long *x, long *y)
2250 {
2251 wxThePrintSetupData->GetPrinterTranslation(x, y);
2252 }
2253
2254 int wxGetPrinterMode(void)
2255 {
2256 return wxThePrintSetupData->GetPrinterMode();
2257 }
2258
2259 char *wxGetAFMPath(void)
2260 {
2261 return wxThePrintSetupData->GetAFMPath();
2262 }
2263
2264 /*
2265 * Print setup data
2266 */
2267
2268 wxPrintSetupData::wxPrintSetupData(void)
2269 {
2270 printerCommand = (char *) NULL;
2271 previewCommand = (char *) NULL;
2272 printerFlags = (char *) NULL;
2273 printerOrient = PS_PORTRAIT;
2274 printerScaleX = (double)1.0;
2275 printerScaleY = (double)1.0;
2276 printerTranslateX = 0;
2277 printerTranslateY = 0;
2278 // 1 = Preview, 2 = print to file, 3 = send to printer
2279 printerMode = 3;
2280 afmPath = (char *) NULL;
2281 paperName = (char *) NULL;
2282 printColour = TRUE;
2283 printerFile = (char *) NULL;
2284 }
2285
2286 wxPrintSetupData::~wxPrintSetupData(void)
2287 {
2288 if (printerCommand)
2289 delete[] printerCommand;
2290 if (previewCommand)
2291 delete[] previewCommand;
2292 if (printerFlags)
2293 delete[] printerFlags;
2294 if (afmPath)
2295 delete[] afmPath;
2296 if (paperName)
2297 delete[] paperName;
2298 if (printerFile)
2299 delete[] printerFile;
2300 }
2301
2302 void wxPrintSetupData::SetPrinterCommand(const char *cmd)
2303 {
2304 if (cmd == printerCommand)
2305 return;
2306
2307 if (printerCommand)
2308 delete[] printerCommand;
2309 if (cmd)
2310 printerCommand = copystring(cmd);
2311 else
2312 printerCommand = (char *) NULL;
2313 }
2314
2315 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd)
2316 {
2317 if (cmd == previewCommand)
2318 return;
2319
2320 if (previewCommand)
2321 delete[] previewCommand;
2322 if (cmd)
2323 previewCommand = copystring(cmd);
2324 else
2325 previewCommand = (char *) NULL;
2326 }
2327
2328 void wxPrintSetupData::SetPaperName(const char *name)
2329 {
2330 if (name == paperName)
2331 return;
2332
2333 if (paperName)
2334 delete[] paperName;
2335 if (name)
2336 paperName = copystring(name);
2337 else
2338 paperName = (char *) NULL;
2339 }
2340
2341 void wxPrintSetupData::SetPrinterOptions(const char *flags)
2342 {
2343 if (printerFlags == flags)
2344 return;
2345
2346 if (printerFlags)
2347 delete[] printerFlags;
2348 if (flags)
2349 printerFlags = copystring(flags);
2350 else
2351 printerFlags = (char *) NULL;
2352 }
2353
2354 void wxPrintSetupData::SetPrinterFile(const char *f)
2355 {
2356 if (f == printerFile)
2357 return;
2358
2359 if (printerFile)
2360 delete[] printerFile;
2361 if (f)
2362 printerFile = copystring(f);
2363 else
2364 printerFile = (char *) NULL;
2365 }
2366
2367 void wxPrintSetupData::SetPrinterOrientation(int orient)
2368 {
2369 printerOrient = orient;
2370 }
2371
2372 void wxPrintSetupData::SetPrinterScaling(double x, double y)
2373 {
2374 printerScaleX = x;
2375 printerScaleY = y;
2376 }
2377
2378 void wxPrintSetupData::SetPrinterTranslation(long x, long y)
2379 {
2380 printerTranslateX = x;
2381 printerTranslateY = y;
2382 }
2383
2384 // 1 = Preview, 2 = print to file, 3 = send to printer
2385 void wxPrintSetupData::SetPrinterMode(int mode)
2386 {
2387 printerMode = mode;
2388 }
2389
2390 void wxPrintSetupData::SetAFMPath(const char *f)
2391 {
2392 if (f == afmPath)
2393 return;
2394
2395 if (afmPath)
2396 delete[] afmPath;
2397 if (f)
2398 afmPath = copystring(f);
2399 else
2400 afmPath = (char *) NULL;
2401 }
2402
2403 void wxPrintSetupData::SetColour(bool col)
2404 {
2405 printColour = col;
2406 }
2407
2408 // Get current values
2409 char *wxPrintSetupData::GetPrinterCommand(void)
2410 {
2411 return printerCommand;
2412 }
2413
2414 char *wxPrintSetupData::GetPrintPreviewCommand(void)
2415 {
2416 return previewCommand;
2417 }
2418
2419 char *wxPrintSetupData::GetPrinterOptions(void)
2420 {
2421 return printerFlags;
2422 }
2423
2424 char *wxPrintSetupData::GetPrinterFile(void)
2425 {
2426 return printerFile;
2427 }
2428
2429 char *wxPrintSetupData::GetPaperName(void)
2430 {
2431 return paperName;
2432 }
2433
2434 int wxPrintSetupData::GetPrinterOrientation(void)
2435 {
2436 return printerOrient;
2437 }
2438
2439 void wxPrintSetupData::GetPrinterScaling(double *x, double *y)
2440 {
2441 *x = printerScaleX;
2442 *y = printerScaleY;
2443 }
2444
2445 void wxPrintSetupData::GetPrinterTranslation(long *x, long *y)
2446 {
2447 *x = printerTranslateX;
2448 *y = printerTranslateY;
2449 }
2450
2451 int wxPrintSetupData::GetPrinterMode(void)
2452 {
2453 return printerMode;
2454 }
2455
2456 char *wxPrintSetupData::GetAFMPath(void)
2457 {
2458 return afmPath;
2459 }
2460
2461 bool wxPrintSetupData::GetColour(void)
2462 {
2463 return printColour;
2464 }
2465
2466 void wxPrintSetupData::operator=(wxPrintSetupData& data)
2467 {
2468 SetPrinterCommand(data.GetPrinterCommand());
2469 SetPrintPreviewCommand(data.GetPrintPreviewCommand());
2470 SetPrinterOptions(data.GetPrinterOptions());
2471 long x, y;
2472 data.GetPrinterTranslation(&x, &y);
2473 SetPrinterTranslation(x, y);
2474
2475 double x1, y1;
2476 data.GetPrinterScaling(&x1, &y1);
2477 SetPrinterScaling(x1, y1);
2478
2479 SetPrinterOrientation(data.GetPrinterOrientation());
2480 SetPrinterMode(data.GetPrinterMode());
2481 SetAFMPath(data.GetAFMPath());
2482 SetPaperName(data.GetPaperName());
2483 SetColour(data.GetColour());
2484 }
2485
2486 void wxInitializePrintSetupData(bool init)
2487 {
2488 if (init)
2489 {
2490 wxThePrintSetupData = new wxPrintSetupData;
2491
2492 wxThePrintSetupData->SetPrintPreviewCommand(PS_VIEWER_PROG);
2493 wxThePrintSetupData->SetPrinterOrientation(PS_PORTRAIT);
2494 wxThePrintSetupData->SetPrinterMode(PS_PREVIEW);
2495 wxThePrintSetupData->SetPaperName(_("A4 210 x 297 mm"));
2496
2497 // Could have a .ini file to read in some defaults
2498 // - and/or use environment variables, e.g. WXWIN
2499 #ifdef __VMS__
2500 wxThePrintSetupData->SetPrinterCommand("print");
2501 wxThePrintSetupData->SetPrinterOptions("/nonotify/queue=psqueue");
2502 wxThePrintSetupData->SetAFMPath("sys$ps_font_metrics:");
2503 #endif
2504 #ifdef __WXMSW__
2505 wxThePrintSetupData->SetPrinterCommand("print");
2506 wxThePrintSetupData->SetAFMPath("c:\\windows\\system\\");
2507 wxThePrintSetupData->SetPrinterOptions(NULL);
2508 #endif
2509 #if !defined(__VMS__) && !defined(__WXMSW__)
2510 wxThePrintSetupData->SetPrinterCommand("lpr");
2511 wxThePrintSetupData->SetPrinterOptions((char *) NULL);
2512 wxThePrintSetupData->SetAFMPath((char *) NULL);
2513 #endif
2514 }
2515 else
2516 {
2517 if (wxThePrintSetupData)
2518 delete wxThePrintSetupData;
2519 wxThePrintSetupData = (wxPrintSetupData *) NULL;
2520 }
2521 }
2522
2523 /*
2524 * Paper size database for PostScript
2525 */
2526
2527 wxPrintPaperType::wxPrintPaperType(const char *name, int wmm, int hmm, int wp, int hp)
2528 {
2529 widthMM = wmm;
2530 heightMM = hmm;
2531 widthPixels = wp;
2532 heightPixels = hp;
2533 pageName = copystring(name);
2534 }
2535
2536 wxPrintPaperType::~wxPrintPaperType(void)
2537 {
2538 delete[] pageName;
2539 }
2540
2541 wxPrintPaperDatabase::wxPrintPaperDatabase(void):wxList(wxKEY_STRING)
2542 {
2543 DeleteContents(TRUE);
2544 }
2545
2546 wxPrintPaperDatabase::~wxPrintPaperDatabase(void)
2547 {
2548 }
2549
2550 void wxPrintPaperDatabase::CreateDatabase(void)
2551 {
2552 // Need correct values for page size in pixels.
2553 // Each unit is one 'point' = 1/72 of an inch.
2554 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2555 // in wxPostScriptDC code, so we can start from top left.
2556 // So access this database and translate by appropriate number
2557 // of points for this paper size. OR IS IT OK ALREADY?
2558 // Can't remember where the PostScript origin is by default.
2559 // Heck, someone will know how to make it hunky-dory...
2560 // JACS 25/5/95
2561
2562 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2563 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2564 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2565 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2566 }
2567
2568 void wxPrintPaperDatabase::ClearDatabase(void)
2569 {
2570 Clear();
2571 }
2572
2573 void wxPrintPaperDatabase::AddPaperType(const char *name, int wmm, int hmm, int wp, int hp)
2574 {
2575 Append(name, new wxPrintPaperType(name, wmm, hmm, wp, hp));
2576 }
2577
2578 wxPrintPaperType *wxPrintPaperDatabase::FindPaperType(const char *name)
2579 {
2580 wxNode *node = Find(name);
2581 if (node)
2582 return (wxPrintPaperType *)node->Data();
2583 else
2584 return (wxPrintPaperType *) NULL;
2585 }
2586
2587 /*
2588 * Initialization/cleanup module
2589 */
2590
2591 bool wxPostScriptModule::OnInit()
2592 {
2593 wxInitializePrintSetupData();
2594 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
2595 wxThePrintPaperDatabase->CreateDatabase();
2596
2597 return TRUE;
2598 }
2599
2600 void wxPostScriptModule::OnExit()
2601 {
2602 wxInitializePrintSetupData(FALSE);
2603 delete wxThePrintPaperDatabase;
2604 wxThePrintPaperDatabase = NULL;
2605 }
2606
2607
2608 #endif