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