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