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