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