]> git.saurik.com Git - wxWidgets.git/blob - src/common/postscrp.cpp
interchanged w and h in wxSplitterWindow::OnSashPositionChange (now
[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 #include <fstream.h>
54 #else
55 #include <iostream>
56 #include <fstream>
57 # ifdef _MSC_VER
58 using namespace std;
59 # endif
60 #endif
61
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
69 #ifdef __WXGTK__
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
78 #ifdef __WXMOTIF__
79 #include <X11/Xlib.h>
80 #include <X11/Xutil.h>
81 #endif
82
83 #ifdef __WXMSW__
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"
117 #elif defined(__X__) || defined(__WXGTK__)
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
125 wxPrintSetupData *wxThePrintSetupData = (wxPrintSetupData *) NULL;
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" */
134 #if wxUSE_XFIG_SPLINE_CODE
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.
153 static const char *wxPostScriptHeaderSpline = (char *) NULL;
154
155 #endif /* wxUSE_XFIG_SPLINE_CODE */
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
168 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule, wxModule)
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 ()
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
186 m_pstream = (ofstream *) NULL;
187
188 #ifdef __WXMSW__
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;
216 m_pstream = (ofstream *) NULL;
217
218 #ifdef __WXMSW__
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 ()
240 {
241 if (m_pstream)
242 delete m_pstream;
243 }
244
245 bool wxPostScriptDC::PrinterDialog(wxWindow *parent)
246 {
247 wxPostScriptPrintDialog dialog (parent, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL);
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 {
277 char *file = wxSaveFileSelector (_("PostScript"), "ps");
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";
302 *m_pstream << (cx + cw) << " " << YSCALE (cy) << " lineto\n";
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 ()
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 ()
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;
359 long radius = (long) sqrt((double) (dx*dx+dy*dy));
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
421 *m_pstream <<
422 "newpath\n" <<
423 (x+w/2) << " " << YSCALE (y+h/2) << " " <<
424 w/2 << " " << (h/2) << " " <<
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
434 *m_pstream <<
435 "newpath\n" <<
436 (x+w/2) << " " << YSCALE (y+h/2) << " " <<
437 (w/2) << " " << (h/2) << " " <<
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";
553 *m_pstream << (x + width) << " " << YSCALE (y) << " lineto\n";
554 *m_pstream << (x + width) << " " << YSCALE (y + height) << " lineto\n";
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";
568 *m_pstream << (x + width) << " " << YSCALE (y) << " lineto\n";
569 *m_pstream << (x + width) << " " << YSCALE (y + height) << " lineto\n";
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";
601 *m_pstream << (x + radius) << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n";
602
603 *m_pstream << x << " " << YSCALE (y + radius) << " moveto\n";
604
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";
607
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";
610
611 *m_pstream << (x + width - radius) << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n";
612
613 *m_pstream << (x + radius) << " " << YSCALE (y) << " lineto\n";
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";
627 *m_pstream << (x + radius) << " " << YSCALE (y + radius) << " " << radius << " 90 180 arc\n";
628
629 *m_pstream << x << " " << YSCALE (y + height - radius) << " lineto\n";
630
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";
633
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";
636
637 *m_pstream << (x + width - radius) << " " << YSCALE (y + radius) << " " << radius << " 0 90 arc\n";
638
639 *m_pstream << (x + radius) << " " << YSCALE (y) << " lineto\n";
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";
659 *m_pstream << (x + width / 2) << " " << YSCALE (y + height / 2) << " ";
660 *m_pstream << (width / 2) << " " << (height / 2) << " 0 360 ellipse\n";
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";
671 *m_pstream << (x + width / 2) << " " << YSCALE (y + height / 2) << " ";
672 *m_pstream << (width / 2) << " " << (height / 2) << " 0 360 ellipse\n";
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 {
682 #if defined(__X__) || defined(__WXGTK__)
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];
703 const char *name;
704 const char *style = "";
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";
775 *m_pstream << (m_font.GetPointSize() * m_scaleFactor) << " scalefont setfont\n";
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 */
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";
807
808 const char *psdash = (char *) NULL;
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 "
984 << (x + w) << " " << YSCALE (y + size - UnderlinePosition)
985 << " lineto stroke grestore\n";
986 }
987
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;
1064 fileBuffer = new char[VMS_BUFSIZ];
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 ()
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;
1147 m_pstream = (ofstream *) NULL;
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: "
1222 << floor((double)llx) << " " << floor((double)lly) << " "
1223 << ceil((double)urx) << " " << ceil((double)ury) << "\n";
1224 *m_pstream << "%%Pages: " << (wxPageNumber - 1) << "\n";
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;
1245 // The following line can be used instead of the adjustment to
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 */
1255
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;
1271 m_pstream = (ofstream *) NULL;
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
1285 #if defined(__X__) || defined(__WXGTK__)
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();
1294 argv[2] = (char *) NULL;
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;
1311
1312 argv[argc++] = wxThePrintSetupData->GetPrinterFile();
1313 argv[argc++] = (char *) NULL;
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 ()
1327 {
1328 if (!m_pstream)
1329 return;
1330 *m_pstream << "%%Page: " << (wxPageNumber++) << "\n";
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 ()
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
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
1417 #if !defined(__X__) && !defined(__WXGTK__)
1418 return FALSE;
1419 #endif
1420
1421 if (!source->IsKindOf(CLASSINFO(wxPaintDC))) return FALSE;
1422
1423 width = (long)floor((double)fwidth);
1424 height = (long)floor((double)fheight);
1425 x = (long)floor((double)xsrc);
1426 y = (long)floor((double)ysrc);
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
1439 #if defined(__X__) || defined(__WXGTK__)
1440
1441 /* Output data as hex digits: */
1442 Display *d;
1443 Colormap cm;
1444 XImage *image;
1445 long j, i;
1446 char s[3];
1447
1448 #ifdef __WXGTK__
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
1455 #else
1456
1457 #ifdef __WXMOTIF__
1458 // TODO. for now, use global display
1459 // d = source->display;
1460 d = (Display*) wxGetDisplay();
1461 #else
1462 d = (Display*) wxGetDisplay();
1463 #endif
1464
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);
1468
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 }
1498
1499 cachesrc[cache_pos] = xcol.pixel = spixel;
1500 XQueryColor(d, cm, &xcol);
1501
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;
1511
1512 if (++cache_pos >= CM_CACHE_SIZE) {
1513 cache_pos = 0;
1514 all_cache = TRUE;
1515 }
1516
1517 install:
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);
1531
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 ()
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 +++++
1584
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 */
1654 const char *name;
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
1659 name = wxTheFontNameDirectory->GetAFMName(Family, Weight, Style);
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 //
1677 // that means, we have a character with ascii code 63, and width
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.).
1683
1684 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1685
1686
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){
1717 if((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2)
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){
1725 if((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2)
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 lastWidths[196] = lastWidths['A']; // Ä
1771 lastWidths[228] = lastWidths['a']; // ä
1772 lastWidths[214] = lastWidths['O']; // Ö
1773 lastWidths[246] = lastWidths['o']; // ö
1774 lastWidths[220] = lastWidths['U']; // Ü
1775 lastWidths[252] = lastWidths['u']; // ü
1776 lastWidths[223] = lastWidths[251]; // ß
1777 }
1778
1779 // JC: calculate UnderlineThickness/UnderlinePosition
1780 UnderlinePosition = UnderlinePosition * fontToUse->GetPointSize() / 1000.0f;
1781 UnderlineThickness = UnderlineThickness * fontToUse->GetPointSize() / 1000.0f * m_scaleFactor;
1782
1783 // 3. now the font metrics are read in, calc size *******************
1784 // this is done by adding the widths of the characters in the
1785 // string. they are given in 1/1000 of the size!
1786
1787 long widthSum=0;
1788 long height=Size; // by default
1789 unsigned char *p;
1790 for(p=(unsigned char *)(const char *)string; *p; p++){
1791 if(lastWidths[*p]== INT_MIN){
1792 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1793 *p,*p);
1794 widthSum += (long)(lastWidths[' ']/1000.0F * Size); // assume space
1795 }else{
1796 widthSum += (long)((lastWidths[*p]/1000.0F)*Size);
1797 }
1798 }
1799 // add descender to height (it is usually a negative value)
1800 if(lastDescender!=INT_MIN){
1801 height += (long)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
1802 }
1803
1804 // return size values
1805 *x = widthSum;
1806 *y = height;
1807
1808 // return other parameters
1809 if (descent){
1810 if(lastDescender!=INT_MIN){
1811 *descent = (long)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */
1812 }else{
1813 *descent = 0;
1814 }
1815 }
1816
1817 // currently no idea how to calculate this!
1818 // if (externalLeading) *externalLeading = 0;
1819 if (externalLeading)
1820 *externalLeading = 0;
1821
1822 // ----- end of contributed code -----
1823 #endif
1824 }
1825
1826 void wxPostScriptDC::DrawSpline( wxList *points )
1827 {
1828 double a, b, c, d, x1, y1, x2, y2, x3, y3;
1829 wxPoint *p, *q;
1830
1831 wxNode *node = points->First();
1832 p = (wxPoint *)node->Data();
1833
1834 x1 = p->x; y1 = p->y;
1835
1836 node = node->Next();
1837 p = (wxPoint *)node->Data();
1838 c = p->x; d = p->y;
1839 x3 = a = (double)(x1 + c) / 2;
1840 y3 = b = (double)(y1 + d) / 2;
1841
1842 *(GetStream()) << "newpath " << x1 << " " << (GetYOrigin() - y1) << " moveto " << x3 << " " << (GetYOrigin() - y3);
1843 *(GetStream()) << " lineto\n";
1844 CalcBoundingBox( (long)x1, (long)(GetYOrigin() - y1));
1845 CalcBoundingBox( (long)x3, (long)(GetYOrigin() - y3));
1846
1847 while ((node = node->Next()) != NULL)
1848 {
1849 q = (wxPoint *)node->Data();
1850
1851 x1 = x3; y1 = y3;
1852 x2 = c; y2 = d;
1853 c = q->x; d = q->y;
1854 x3 = (double)(x2 + c) / 2;
1855 y3 = (double)(y2 + d) / 2;
1856 *(GetStream()) << x1 << " " << (GetYOrigin() - y1) << " " << x2 << " " << (GetYOrigin() - y2) << " ";
1857 *(GetStream()) << x3 << " " << (GetYOrigin() - y3) << " DrawSplineSection\n";
1858
1859 CalcBoundingBox( (long)x1, (long)(GetYOrigin() - y1));
1860 CalcBoundingBox( (long)x3, (long)(GetYOrigin() - y3));
1861 }
1862 /*
1863 * At this point, (x2,y2) and (c,d) are the position of the
1864 * next-to-last and last point respectively, in the point list
1865 */
1866 *(GetStream()) << c << " " << (GetYOrigin() - d) << " lineto stroke\n";
1867 }
1868
1869 long wxPostScriptDC::GetCharWidth ()
1870 {
1871 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1872 return (long) (GetCharHeight() * 72.0 / 120.0);
1873 }
1874
1875
1876 void wxPostScriptDC::SetMapMode (int mode)
1877 {
1878 m_mappingMode = mode;
1879 SetLogicalOrigin(0, 0);
1880 if(m_mappingMode == MM_METRIC)
1881 {
1882 SetUserScale(72.0f / 25.4f, 72.0f / 25.4f);
1883 }
1884 else
1885 {
1886 SetUserScale(1.0, 1.0);
1887 }
1888 return;
1889 }
1890
1891 /*
1892 * Set the logical origin.
1893 * Actually we are setting the printer's origin and since
1894 * postscript transformations are cumulative we need to reset
1895 * the previous origin. We also need to allow for the user scale
1896 * factor (which affects printer coords but not logical)
1897 */
1898 void wxPostScriptDC::SetLogicalOrigin(long x, long y)
1899 {
1900 if (m_scaleFactor)
1901 {
1902 long xOffset = (long) ((m_logicalOriginX - x) / m_scaleFactor);
1903 long yOffset = (long) ((y - m_logicalOriginY) / m_scaleFactor);
1904
1905 if (m_pstream)
1906 {
1907 *m_pstream << xOffset << " " << yOffset << " translate\n";
1908 }
1909 }
1910 m_logicalOriginX = x;
1911 m_logicalOriginY = y;
1912 }
1913
1914 /*
1915 * Obsolete - now performed by SetUserScale() and SetLogicalOrigin()
1916 */
1917 void
1918 wxPostScriptDC::SetupCTM()
1919 {
1920 }
1921
1922 /*
1923 * Set the user scale.
1924 * NB: Postscript transformations are cumulative and so we
1925 * need to take into account the current scale. Also, this
1926 * affects the logical origin
1927 */
1928 void wxPostScriptDC::SetUserScale (double x, double y)
1929 {
1930 // reset logical origin
1931 long xOrg = m_logicalOriginX;
1932 long yOrg = m_logicalOriginY;
1933 SetLogicalOrigin(0, 0);
1934
1935 // set new scale factor
1936 double factor = x;
1937 if (m_scaleFactor)
1938 {
1939 factor /= m_scaleFactor;
1940 }
1941 if (m_pstream)
1942 {
1943 *m_pstream << factor << " " << factor << " scale\n";
1944 }
1945
1946 // set logical origin at new scale
1947 SetLogicalOrigin(xOrg, yOrg);
1948
1949 m_userScaleX = x;
1950 m_userScaleY = y;
1951
1952 m_scaleFactor = m_userScaleX;
1953 }
1954
1955 long wxPostScriptDC::DeviceToLogicalX (int x) const
1956 {
1957 return x;
1958 }
1959
1960 long wxPostScriptDC::DeviceToLogicalXRel (int x) const
1961 {
1962 return x;
1963 }
1964
1965 long wxPostScriptDC::DeviceToLogicalY (int y) const
1966 {
1967 return y;
1968 }
1969
1970 long wxPostScriptDC::DeviceToLogicalYRel (int y) const
1971 {
1972 return y;
1973 }
1974
1975 long wxPostScriptDC::LogicalToDeviceX (long x) const
1976 {
1977 return x;
1978 }
1979
1980 long wxPostScriptDC::LogicalToDeviceXRel (long x) const
1981 {
1982 return x;
1983 }
1984
1985 long wxPostScriptDC::LogicalToDeviceY (long y) const
1986 {
1987 return y;
1988 }
1989
1990 long wxPostScriptDC::LogicalToDeviceYRel (long y) const
1991 {
1992 return y;
1993 }
1994
1995 void wxPostScriptDC::GetSize(int* width, int* height) const
1996 {
1997 const char *paperType = wxThePrintSetupData->GetPaperName();
1998 if (!paperType)
1999 paperType = _("A4 210 x 297 mm");
2000
2001 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
2002 if (!paper)
2003 paper = wxThePrintPaperDatabase->FindPaperType(_("A4 210 x 297 mm"));
2004 if (paper)
2005 {
2006 *width = paper->widthPixels;
2007 *height = paper->heightPixels;
2008 }
2009 else
2010 {
2011 *width = 1000;
2012 *height = 1000;
2013 }
2014 }
2015
2016 void wxPostScriptDC::GetSizeMM(long *width, long *height) const
2017 {
2018 const char *paperType = wxThePrintSetupData->GetPaperName();
2019 if (!paperType)
2020 paperType = _("A4 210 x 297 mm");
2021
2022 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
2023 if (!paper)
2024 paper = wxThePrintPaperDatabase->FindPaperType(_("A4 210 x 297 mm"));
2025 if (paper)
2026 {
2027 *width = paper->widthMM;
2028 *height = paper->heightMM;
2029 }
2030 else
2031 {
2032 *width = 1000;
2033 *height = 1000;
2034 }
2035 }
2036
2037 void wxPostScriptDC::CalcBoundingBox(long x, long y)
2038 {
2039 long device_x = (long) (x - m_logicalOriginX * m_scaleFactor);
2040 long device_y = (long) (y + m_logicalOriginY * m_scaleFactor);
2041
2042 if (device_x < m_minX) m_minX = device_x;
2043 if (device_y < m_minY) m_minY = device_y;
2044 if (device_x > m_maxX) m_maxX = device_x;
2045 if (device_y > m_maxY) m_maxY = device_y;
2046 }
2047
2048 IMPLEMENT_CLASS(wxPostScriptPrintDialog, wxDialog)
2049
2050 wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow *parent, const wxString& title,
2051 const wxPoint& pos, const wxSize& size, long style):
2052 wxDialog(parent, -1, title, pos, size, style)
2053 {
2054 wxBeginBusyCursor();
2055 char buf[100];
2056
2057 wxButton *okBut = new wxButton (this, wxID_OK, _("OK"), wxPoint(5, 5));
2058 (void) new wxButton (this, wxID_CANCEL, _("Cancel"), wxPoint(40, 5));
2059 okBut->SetDefault();
2060
2061 int yPos = 40;
2062
2063 #if defined(__WXGTK__) || defined (__WXMOTIF__)
2064 (void) new wxStaticText( this, -1, _("Printer Command: "),
2065 wxPoint(5, yPos) );
2066 (void) new wxTextCtrl( this, wxID_PRINTER_COMMAND, wxThePrintSetupData->GetPrinterCommand(),
2067 wxPoint(100, yPos), wxSize(100, -1) );
2068
2069 (void) new wxStaticText( this, -1, _("Printer Options: "),
2070 wxPoint(210, yPos) );
2071 (void) new wxTextCtrl( this, wxID_PRINTER_OPTIONS, wxThePrintSetupData->GetPrinterOptions(),
2072 wxPoint(305, yPos), wxSize(150, -1) );
2073
2074 yPos += 40;
2075 #endif
2076
2077 wxString orientation[2];
2078 orientation[0] = _("Portrait");
2079 orientation[1] = _("Landscape");
2080
2081 wxRadioBox *radio0 = new wxRadioBox(this, wxID_PRINTER_ORIENTATION, "Orientation: ", wxPoint(5, yPos), wxSize(-1,-1),
2082 2,orientation,2,0);
2083 radio0->SetSelection((int)wxThePrintSetupData->GetPrinterOrientation() - 1);
2084
2085 // @@@ Configuration hook
2086 if (wxThePrintSetupData->GetPrintPreviewCommand() == NULL)
2087 wxThePrintSetupData->SetPrintPreviewCommand(PS_VIEWER_PROG);
2088
2089 wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->previewCommand);
2090
2091 wxString print_modes[3];
2092 print_modes[0] = _("Send to Printer");
2093 print_modes[1] = _("Print to File");
2094 print_modes[2] = _("Preview Only");
2095
2096 int features = (wxThePrintSetupData->GetPrintPreviewCommand() && *wxThePrintSetupData->GetPrintPreviewCommand()) ? 3 : 2;
2097 wxRadioBox *radio1 = new wxRadioBox(this, wxID_PRINTER_MODES, _("PostScript:"),
2098 wxPoint(150, yPos), wxSize(-1,-1), features, print_modes, features, 0);
2099
2100 #ifdef __WXMSW__
2101 radio1->Enable(0, FALSE);
2102 if (wxThePrintSetupData->GetPrintPreviewCommand() && *wxThePrintSetupData->GetPrintPreviewCommand())
2103 radio1->Enable(2, FALSE);
2104 #endif
2105
2106 radio1->SetSelection((int)wxThePrintSetupData->GetPrinterMode());
2107
2108 long wx_printer_translate_x, wx_printer_translate_y;
2109 double wx_printer_scale_x, wx_printer_scale_y;
2110 wxThePrintSetupData->GetPrinterTranslation(&wx_printer_translate_x, &wx_printer_translate_y);
2111 wxThePrintSetupData->GetPrinterScaling(&wx_printer_scale_x, &wx_printer_scale_y);
2112
2113 sprintf (buf, "%.2f", wx_printer_scale_x);
2114
2115 yPos += 90;
2116
2117 (void) new wxStaticText(this, -1, _("X Scaling"), wxPoint(5, yPos));
2118 /* wxTextCtrl *text1 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_SCALE, buf, wxPoint(100, yPos), wxSize(100, -1));
2119
2120 sprintf (buf, "%.2f", wx_printer_scale_y);
2121 (void) new wxStaticText(this, -1, _("Y Scaling"), wxPoint(220, yPos));
2122 /* wxTextCtrl *text2 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_SCALE, buf, wxPoint(320, yPos), wxSize(100, -1));
2123
2124 yPos += 25;
2125
2126 (void) new wxStaticText(this, -1, _("X Translation"), wxPoint(5, yPos));
2127 sprintf (buf, "%.2ld", wx_printer_translate_x);
2128 /* wxTextCtrl *text3 = */ (void) new wxTextCtrl(this, wxID_PRINTER_X_TRANS, buf, wxPoint(100, yPos), wxSize(100, -1));
2129
2130 (void) new wxStaticText(this, -1, _("Y Translation"), wxPoint(220, yPos));
2131 sprintf (buf, "%.2ld", wx_printer_translate_y);
2132 /* wxTextCtrl *text4 = */ (void) new wxTextCtrl(this, wxID_PRINTER_Y_TRANS, buf, wxPoint(320, yPos), wxSize(100, -1));
2133
2134 Fit ();
2135
2136 wxEndBusyCursor();
2137 }
2138
2139 int wxPostScriptPrintDialog::ShowModal ()
2140 {
2141 if ( wxDialog::ShowModal() == wxID_OK )
2142 {
2143 // wxTextCtrl *text0 = (wxTextCtrl *)FindWindow(wxID_PRINTER_OPTIONS);
2144 wxTextCtrl *text1 = (wxTextCtrl *)FindWindow(wxID_PRINTER_X_SCALE);
2145 wxTextCtrl *text2 = (wxTextCtrl *)FindWindow(wxID_PRINTER_Y_SCALE);
2146 wxTextCtrl *text3 = (wxTextCtrl *)FindWindow(wxID_PRINTER_X_TRANS);
2147 wxTextCtrl *text4 = (wxTextCtrl *)FindWindow(wxID_PRINTER_Y_TRANS);
2148 // wxTextCtrl *text_prt = (wxTextCtrl *)FindWindow(wxID_PRINTER_COMMAND);
2149 wxRadioBox *radio0 = (wxRadioBox *)FindWindow(wxID_PRINTER_ORIENTATION);
2150 wxRadioBox *radio1 = (wxRadioBox *)FindWindow(wxID_PRINTER_MODES);
2151
2152 StringToDouble (WXSTRINGCAST text1->GetValue (), &wxThePrintSetupData->printerScaleX);
2153 StringToDouble (WXSTRINGCAST text2->GetValue (), &wxThePrintSetupData->printerScaleY);
2154 StringToLong (WXSTRINGCAST text3->GetValue (), &wxThePrintSetupData->printerTranslateX);
2155 StringToLong (WXSTRINGCAST text4->GetValue (), &wxThePrintSetupData->printerTranslateY);
2156
2157 #ifdef __X__
2158 // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ());
2159 // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ());
2160 #endif
2161
2162 wxThePrintSetupData->SetPrinterOrientation((radio0->GetSelection() == 1 ? PS_LANDSCAPE : PS_PORTRAIT));
2163
2164 // C++ wants this
2165 switch ( radio1->GetSelection() ) {
2166 case 0: wxThePrintSetupData->SetPrinterMode(PS_PRINTER); break;
2167 case 1: wxThePrintSetupData->SetPrinterMode(PS_FILE); break;
2168 case 2: wxThePrintSetupData->SetPrinterMode(PS_PREVIEW); break;
2169 }
2170 return wxID_OK;
2171 }
2172 return wxID_CANCEL;
2173 }
2174
2175 // PostScript printer settings
2176 // RETAINED FOR BACKWARD COMPATIBILITY
2177 void wxSetPrinterCommand(const char *cmd)
2178 {
2179 wxThePrintSetupData->SetPrinterCommand(cmd);
2180 }
2181
2182 void wxSetPrintPreviewCommand(const char *cmd)
2183 {
2184 wxThePrintSetupData->SetPrintPreviewCommand(cmd);
2185 }
2186
2187 void wxSetPrinterOptions(const char *flags)
2188 {
2189 wxThePrintSetupData->SetPrinterOptions(flags);
2190 }
2191
2192 void wxSetPrinterFile(const char *f)
2193 {
2194 wxThePrintSetupData->SetPrinterFile(f);
2195 }
2196
2197 void wxSetPrinterOrientation(int orient)
2198 {
2199 wxThePrintSetupData->SetPrinterOrientation(orient);
2200 }
2201
2202 void wxSetPrinterScaling(double x, double y)
2203 {
2204 wxThePrintSetupData->SetPrinterScaling(x, y);
2205 }
2206
2207 void wxSetPrinterTranslation(long x, long y)
2208 {
2209 wxThePrintSetupData->SetPrinterTranslation(x, y);
2210 }
2211
2212 // 1 = Preview, 2 = print to file, 3 = send to printer
2213 void wxSetPrinterMode(int mode)
2214 {
2215 wxThePrintSetupData->SetPrinterMode(mode);
2216 }
2217
2218 void wxSetAFMPath(const char *f)
2219 {
2220 wxThePrintSetupData->SetAFMPath(f);
2221 }
2222
2223 // Get current values
2224 char *wxGetPrinterCommand()
2225 {
2226 return wxThePrintSetupData->GetPrinterCommand();
2227 }
2228
2229 char *wxGetPrintPreviewCommand()
2230 {
2231 return wxThePrintSetupData->GetPrintPreviewCommand();
2232 }
2233
2234 char *wxGetPrinterOptions()
2235 {
2236 return wxThePrintSetupData->GetPrinterOptions();
2237 }
2238
2239 char *wxGetPrinterFile()
2240 {
2241 return wxThePrintSetupData->GetPrinterFile();
2242 }
2243
2244 int wxGetPrinterOrientation()
2245 {
2246 return wxThePrintSetupData->GetPrinterOrientation();
2247 }
2248
2249 void wxGetPrinterScaling(double* x, double* y)
2250 {
2251 wxThePrintSetupData->GetPrinterScaling(x, y);
2252 }
2253
2254 void wxGetPrinterTranslation(long *x, long *y)
2255 {
2256 wxThePrintSetupData->GetPrinterTranslation(x, y);
2257 }
2258
2259 int wxGetPrinterMode()
2260 {
2261 return wxThePrintSetupData->GetPrinterMode();
2262 }
2263
2264 char *wxGetAFMPath()
2265 {
2266 return wxThePrintSetupData->GetAFMPath();
2267 }
2268
2269 /*
2270 * Print setup data
2271 */
2272
2273 wxPrintSetupData::wxPrintSetupData()
2274 {
2275 printerCommand = (char *) NULL;
2276 previewCommand = (char *) NULL;
2277 printerFlags = (char *) NULL;
2278 printerOrient = PS_PORTRAIT;
2279 printerScaleX = (double)1.0;
2280 printerScaleY = (double)1.0;
2281 printerTranslateX = 0;
2282 printerTranslateY = 0;
2283 // 1 = Preview, 2 = print to file, 3 = send to printer
2284 printerMode = 3;
2285 afmPath = (char *) NULL;
2286 paperName = (char *) NULL;
2287 printColour = TRUE;
2288 printerFile = (char *) NULL;
2289 }
2290
2291 wxPrintSetupData::~wxPrintSetupData()
2292 {
2293 if (printerCommand)
2294 delete[] printerCommand;
2295 if (previewCommand)
2296 delete[] previewCommand;
2297 if (printerFlags)
2298 delete[] printerFlags;
2299 if (afmPath)
2300 delete[] afmPath;
2301 if (paperName)
2302 delete[] paperName;
2303 if (printerFile)
2304 delete[] printerFile;
2305 }
2306
2307 void wxPrintSetupData::SetPrinterCommand(const char *cmd)
2308 {
2309 if (cmd == printerCommand)
2310 return;
2311
2312 if (printerCommand)
2313 delete[] printerCommand;
2314 if (cmd)
2315 printerCommand = copystring(cmd);
2316 else
2317 printerCommand = (char *) NULL;
2318 }
2319
2320 void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd)
2321 {
2322 if (cmd == previewCommand)
2323 return;
2324
2325 if (previewCommand)
2326 delete[] previewCommand;
2327 if (cmd)
2328 previewCommand = copystring(cmd);
2329 else
2330 previewCommand = (char *) NULL;
2331 }
2332
2333 void wxPrintSetupData::SetPaperName(const char *name)
2334 {
2335 if (name == paperName)
2336 return;
2337
2338 if (paperName)
2339 delete[] paperName;
2340 if (name)
2341 paperName = copystring(name);
2342 else
2343 paperName = (char *) NULL;
2344 }
2345
2346 void wxPrintSetupData::SetPrinterOptions(const char *flags)
2347 {
2348 if (printerFlags == flags)
2349 return;
2350
2351 if (printerFlags)
2352 delete[] printerFlags;
2353 if (flags)
2354 printerFlags = copystring(flags);
2355 else
2356 printerFlags = (char *) NULL;
2357 }
2358
2359 void wxPrintSetupData::SetPrinterFile(const char *f)
2360 {
2361 if (f == printerFile)
2362 return;
2363
2364 if (printerFile)
2365 delete[] printerFile;
2366 if (f)
2367 printerFile = copystring(f);
2368 else
2369 printerFile = (char *) NULL;
2370 }
2371
2372 void wxPrintSetupData::SetPrinterOrientation(int orient)
2373 {
2374 printerOrient = orient;
2375 }
2376
2377 void wxPrintSetupData::SetPrinterScaling(double x, double y)
2378 {
2379 printerScaleX = x;
2380 printerScaleY = y;
2381 }
2382
2383 void wxPrintSetupData::SetPrinterTranslation(long x, long y)
2384 {
2385 printerTranslateX = x;
2386 printerTranslateY = y;
2387 }
2388
2389 // 1 = Preview, 2 = print to file, 3 = send to printer
2390 void wxPrintSetupData::SetPrinterMode(int mode)
2391 {
2392 printerMode = mode;
2393 }
2394
2395 void wxPrintSetupData::SetAFMPath(const char *f)
2396 {
2397 if (f == afmPath)
2398 return;
2399
2400 if (afmPath)
2401 delete[] afmPath;
2402 if (f)
2403 afmPath = copystring(f);
2404 else
2405 afmPath = (char *) NULL;
2406 }
2407
2408 void wxPrintSetupData::SetColour(bool col)
2409 {
2410 printColour = col;
2411 }
2412
2413 // Get current values
2414 char *wxPrintSetupData::GetPrinterCommand()
2415 {
2416 return printerCommand;
2417 }
2418
2419 char *wxPrintSetupData::GetPrintPreviewCommand()
2420 {
2421 return previewCommand;
2422 }
2423
2424 char *wxPrintSetupData::GetPrinterOptions()
2425 {
2426 return printerFlags;
2427 }
2428
2429 char *wxPrintSetupData::GetPrinterFile()
2430 {
2431 return printerFile;
2432 }
2433
2434 char *wxPrintSetupData::GetPaperName()
2435 {
2436 return paperName;
2437 }
2438
2439 int wxPrintSetupData::GetPrinterOrientation()
2440 {
2441 return printerOrient;
2442 }
2443
2444 void wxPrintSetupData::GetPrinterScaling(double *x, double *y)
2445 {
2446 *x = printerScaleX;
2447 *y = printerScaleY;
2448 }
2449
2450 void wxPrintSetupData::GetPrinterTranslation(long *x, long *y)
2451 {
2452 *x = printerTranslateX;
2453 *y = printerTranslateY;
2454 }
2455
2456 int wxPrintSetupData::GetPrinterMode()
2457 {
2458 return printerMode;
2459 }
2460
2461 char *wxPrintSetupData::GetAFMPath()
2462 {
2463 return afmPath;
2464 }
2465
2466 bool wxPrintSetupData::GetColour()
2467 {
2468 return printColour;
2469 }
2470
2471 void wxPrintSetupData::operator=(wxPrintSetupData& data)
2472 {
2473 SetPrinterCommand(data.GetPrinterCommand());
2474 SetPrintPreviewCommand(data.GetPrintPreviewCommand());
2475 SetPrinterOptions(data.GetPrinterOptions());
2476 long x, y;
2477 data.GetPrinterTranslation(&x, &y);
2478 SetPrinterTranslation(x, y);
2479
2480 double x1, y1;
2481 data.GetPrinterScaling(&x1, &y1);
2482 SetPrinterScaling(x1, y1);
2483
2484 SetPrinterOrientation(data.GetPrinterOrientation());
2485 SetPrinterMode(data.GetPrinterMode());
2486 SetAFMPath(data.GetAFMPath());
2487 SetPaperName(data.GetPaperName());
2488 SetColour(data.GetColour());
2489 }
2490
2491 void wxInitializePrintSetupData(bool init)
2492 {
2493 if (init)
2494 {
2495 wxThePrintSetupData = new wxPrintSetupData;
2496
2497 wxThePrintSetupData->SetPrintPreviewCommand(PS_VIEWER_PROG);
2498 wxThePrintSetupData->SetPrinterOrientation(PS_PORTRAIT);
2499 wxThePrintSetupData->SetPrinterMode(PS_PREVIEW);
2500 wxThePrintSetupData->SetPaperName(_("A4 210 x 297 mm"));
2501
2502 // Could have a .ini file to read in some defaults
2503 // - and/or use environment variables, e.g. WXWIN
2504 #ifdef __VMS__
2505 wxThePrintSetupData->SetPrinterCommand("print");
2506 wxThePrintSetupData->SetPrinterOptions("/nonotify/queue=psqueue");
2507 wxThePrintSetupData->SetAFMPath("sys$ps_font_metrics:");
2508 #endif
2509 #ifdef __WXMSW__
2510 wxThePrintSetupData->SetPrinterCommand("print");
2511 wxThePrintSetupData->SetAFMPath("c:\\windows\\system\\");
2512 wxThePrintSetupData->SetPrinterOptions(NULL);
2513 #endif
2514 #if !defined(__VMS__) && !defined(__WXMSW__)
2515 wxThePrintSetupData->SetPrinterCommand("lpr");
2516 wxThePrintSetupData->SetPrinterOptions((char *) NULL);
2517 wxThePrintSetupData->SetAFMPath((char *) NULL);
2518 #endif
2519 }
2520 else
2521 {
2522 if (wxThePrintSetupData)
2523 delete wxThePrintSetupData;
2524 wxThePrintSetupData = (wxPrintSetupData *) NULL;
2525 }
2526 }
2527
2528 /*
2529 * Paper size database for PostScript
2530 */
2531
2532 wxPrintPaperType::wxPrintPaperType(const char *name, int wmm, int hmm, int wp, int hp)
2533 {
2534 widthMM = wmm;
2535 heightMM = hmm;
2536 widthPixels = wp;
2537 heightPixels = hp;
2538 pageName = copystring(name);
2539 }
2540
2541 wxPrintPaperType::~wxPrintPaperType()
2542 {
2543 delete[] pageName;
2544 }
2545
2546 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING)
2547 {
2548 DeleteContents(TRUE);
2549 }
2550
2551 wxPrintPaperDatabase::~wxPrintPaperDatabase()
2552 {
2553 }
2554
2555 void wxPrintPaperDatabase::CreateDatabase()
2556 {
2557 // Need correct values for page size in pixels.
2558 // Each unit is one 'point' = 1/72 of an inch.
2559 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
2560 // in wxPostScriptDC code, so we can start from top left.
2561 // So access this database and translate by appropriate number
2562 // of points for this paper size. OR IS IT OK ALREADY?
2563 // Can't remember where the PostScript origin is by default.
2564 // Heck, someone will know how to make it hunky-dory...
2565 // JACS 25/5/95
2566
2567 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
2568 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
2569 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
2570 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
2571 }
2572
2573 void wxPrintPaperDatabase::ClearDatabase()
2574 {
2575 Clear();
2576 }
2577
2578 void wxPrintPaperDatabase::AddPaperType(const char *name, int wmm, int hmm, int wp, int hp)
2579 {
2580 Append(name, new wxPrintPaperType(name, wmm, hmm, wp, hp));
2581 }
2582
2583 wxPrintPaperType *wxPrintPaperDatabase::FindPaperType(const char *name)
2584 {
2585 wxNode *node = Find(name);
2586 if (node)
2587 return (wxPrintPaperType *)node->Data();
2588 else
2589 return (wxPrintPaperType *) NULL;
2590 }
2591
2592 /*
2593 * Initialization/cleanup module
2594 */
2595
2596 bool wxPostScriptModule::OnInit()
2597 {
2598 wxInitializePrintSetupData();
2599 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
2600 wxThePrintPaperDatabase->CreateDatabase();
2601
2602 return TRUE;
2603 }
2604
2605 void wxPostScriptModule::OnExit()
2606 {
2607 wxInitializePrintSetupData(FALSE);
2608 delete wxThePrintPaperDatabase;
2609 wxThePrintPaperDatabase = NULL;
2610 }
2611
2612
2613 #endif