1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPostScriptDC implementation
4 // Author: Julian Smart, Robert Roebling, Markus Holzhem
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 #include "wx/postscrp.h"
18 #include "wx/dcmemory.h"
21 #include "wx/filedlg.h"
23 #include "wx/msgdlg.h"
25 //-----------------------------------------------------------------------------
26 // start and end of document/page
27 //-----------------------------------------------------------------------------
29 static const char *wxPostScriptHeaderEllipse
= "\
30 /ellipsedict 8 dict def\n\
31 ellipsedict /mtrx matrix put\n\
35 /startangle exch def\n\
40 /savematrix mtrx currentmatrix def\n\
43 0 0 1 startangle endangle arc\n\
44 savematrix setmatrix\n\
49 static const char *wxPostScriptHeaderEllipticArc
= "\
50 /ellipticarcdict 8 dict def\n\
51 ellipticarcdict /mtrx matrix put\n\
53 { ellipticarcdict begin\n\
56 /startangle exch def\n\
61 /savematrix mtrx currentmatrix def\n\
64 do_fill { 0 0 moveto } if\n\
65 0 0 1 startangle endangle arc\n\
66 savematrix setmatrix\n\
67 do_fill { fill }{ stroke } ifelse\n\
71 static const char *wxPostScriptHeaderSpline
= "\
72 /DrawSplineSection {\n\
79 /xa x1 x2 x1 sub 0.666667 mul add def\n\
80 /ya y1 y2 y1 sub 0.666667 mul add def\n\
81 /xb x3 x2 x3 sub 0.666667 mul add def\n\
82 /yb y3 y2 y3 sub 0.666667 mul add def\n\
84 xa ya xb yb x3 y3 curveto\n\
88 static const char *wxPostScriptHeaderColourImage
= "\
89 % define 'colorimage' if it isn't defined\n\
90 % ('colortogray' and 'mergeprocs' come from xwd2ps\n\
92 /colorimage where % do we know about 'colorimage'?\n\
93 { pop } % yes: pop off the 'dict' returned\n\
95 /colortogray { % define an RGB->I function\n\
96 /rgbdata exch store % call input 'rgbdata'\n\
97 rgbdata length 3 idiv\n\
100 0 1 npixls 1 sub {\n\
102 rgbdata rgbindx get 20 mul % Red\n\
103 rgbdata rgbindx 1 add get 32 mul % Green\n\
104 rgbdata rgbindx 2 add get 12 mul % Blue\n\
105 add add 64 idiv % I = .5G + .31R + .18B\n\
107 /rgbindx rgbindx 3 add store\n\
109 grays 0 npixls getinterval\n\
112 % Utility procedure for colorimage operator.\n\
113 % This procedure takes two procedures off the\n\
114 % stack and merges them into a single procedure.\n\
116 /mergeprocs { % def\n\
135 /colorimage { % def\n\
136 pop pop % remove 'false 3' operands\n\
137 {colortogray} mergeprocs\n\
140 } ifelse % end of 'false' case\n\
143 static char wxPostScriptHeaderReencodeISO1
[] =
145 "dup dup findfont dup length dict begin\n"
146 "{ 1 index /FID ne { def }{ pop pop } ifelse } forall\n"
147 "/Encoding ISOLatin1Encoding def\n"
148 "currentdict end definefont\n"
150 "/ISOLatin1Encoding [\n"
151 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
152 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
153 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
154 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
155 "/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright\n"
156 "/parenleft/parenright/asterisk/plus/comma/minus/period/slash\n"
157 "/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon\n"
158 "/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N\n"
159 "/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright\n"
160 "/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m\n"
161 "/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde\n"
162 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
163 "/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef\n"
164 "/.notdef/dotlessi/grave/acute/circumflex/tilde/macron/breve\n"
165 "/dotaccent/dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut\n";
167 static char wxPostScriptHeaderReencodeISO2
[] =
168 "/ogonek/caron/space/exclamdown/cent/sterling/currency/yen/brokenbar\n"
169 "/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot\n"
170 "/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior\n"
171 "/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine\n"
172 "/guillemotright/onequarter/onehalf/threequarters/questiondown\n"
173 "/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla\n"
174 "/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex\n"
175 "/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis\n"
176 "/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute\n"
177 "/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis\n"
178 "/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave\n"
179 "/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex\n"
180 "/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis\n"
181 "/yacute/thorn/ydieresis\n"
184 //-------------------------------------------------------------------------------
186 //-------------------------------------------------------------------------------
188 wxPostScriptDC::wxPostScriptDC ()
190 m_pstream
= (ofstream
*) NULL
;
200 m_underlinePosition
= 0.0;
201 m_underlineThickness
= 0.0;
203 m_signX
= 1; // default x-axis left to right
204 m_signY
= -1; // default y-axis bottom up -> top down
207 wxPostScriptDC::wxPostScriptDC (const wxString
& file
, bool interactive
, wxWindow
*parent
)
209 m_pstream
= (ofstream
*) NULL
;
219 m_underlinePosition
= 0.0;
220 m_underlineThickness
= 0.0;
222 m_signX
= 1; // default x-axis left to right
223 m_signY
= -1; // default y-axis bottom up -> top down
225 Create(file
, interactive
, parent
);
228 bool wxPostScriptDC::Create(const wxString
& file
, bool interactive
, wxWindow
*parent
)
230 m_isInteractive
= interactive
;
236 // Can only send to file in Windows
237 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
242 if ((m_ok
= PrinterDialog (parent
) ) == FALSE
) return FALSE
;
252 wxPostScriptDC::~wxPostScriptDC ()
254 if (m_pstream
) delete m_pstream
;
257 bool wxPostScriptDC::PrinterDialog(wxWindow
*parent
)
259 wxPostScriptPrintDialog
dialog( parent
, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400),
260 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
);
261 m_ok
= (dialog
.ShowModal () == wxID_OK
);
263 if (!m_ok
) return FALSE
;
265 if ((m_filename
== "") &&
266 (wxThePrintSetupData
->GetPrinterMode() == PS_PREVIEW
||
267 wxThePrintSetupData
->GetPrinterMode() == PS_PRINTER
))
271 wxThePrintSetupData
->SetPrinterFile("preview");
273 // For PS_PRINTER action this depends on a Unix-style print spooler
274 // since the wx_printer_file can be destroyed during a session
275 // @@@ TODO: a Windows-style answer for non-Unix
277 wxGetUserId (userId
, sizeof (userId
) / sizeof (char));
279 strcpy (tmp
, "/tmp/preview_");
280 strcat (tmp
, userId
);
281 wxThePrintSetupData
->SetPrinterFile(tmp
);
284 strcpy(tmp2
, wxThePrintSetupData
->GetPrinterFile());
285 strcat (tmp2
, ".ps");
286 wxThePrintSetupData
->SetPrinterFile(tmp2
);
289 else if ((m_filename
== "") && (wxThePrintSetupData
->GetPrinterMode() == PS_FILE
))
291 char *file
= wxSaveFileSelector (_("PostScript"), "ps");
297 wxThePrintSetupData
->SetPrinterFile(file
);
305 void wxPostScriptDC::SetClippingRegion (long x
, long y
, long w
, long h
)
307 if (m_clipping
) return;
309 if (!m_pstream
) return;
311 wxDC::SetClippingRegion( x
, y
, w
, h
);
314 *m_pstream
<< "gsave\n"
316 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
317 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
) << " lineto\n"
318 << XLOG2DEV(x
+w
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
319 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+h
) << " lineto\n"
320 << "closepath clip newpath\n";
323 void wxPostScriptDC::SetClippingRegion( const wxRegion
&WXUNUSED(region
) )
327 void wxPostScriptDC::DestroyClippingRegion()
329 if (!m_pstream
) return;
331 wxDC::DestroyClippingRegion();
336 *m_pstream
<< "grestore\n";
340 void wxPostScriptDC::Clear()
342 wxFAIL_MSG( "wxPostScriptDC::Clear not implemented." );
345 void wxPostScriptDC::FloodFill (long WXUNUSED(x
), long WXUNUSED(y
), const wxColour
&WXUNUSED(col
), int WXUNUSED(style
))
347 wxFAIL_MSG( "wxPostScriptDC::FloodFill not implemented." );
350 bool wxPostScriptDC::GetPixel (long WXUNUSED(x
), long WXUNUSED(y
), wxColour
* WXUNUSED(col
)) const
352 wxFAIL_MSG( "wxPostScriptDC::GetPixel not implemented." );
356 void wxPostScriptDC::CrossHair (long WXUNUSED(x
), long WXUNUSED(y
))
358 wxFAIL_MSG( "wxPostScriptDC::CrossHair not implemented." );
361 void wxPostScriptDC::DrawLine (long x1
, long y1
, long x2
, long y2
)
363 if (!m_pstream
) return;
365 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
369 *m_pstream
<< "newpath\n"
370 << XLOG2DEV(x1
) << " " << YLOG2DEV (y1
) << " moveto\n"
371 << XLOG2DEV(x2
) << " " << YLOG2DEV (y2
) << " lineto\n"
374 CalcBoundingBox( x1
, y1
);
375 CalcBoundingBox( x2
, y2
);
378 #define RAD2DEG 57.29577951308
380 void wxPostScriptDC::DrawArc (long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
382 if (!m_pstream
) return;
386 long radius
= (long) sqrt(dx
*dx
+dy
*dy
);
387 double alpha1
, alpha2
;
389 if (x1
== x2
&& y1
== y2
)
393 } else if (radius
== 0.0)
395 alpha1
= alpha2
= 0.0;
398 alpha1
= (x1
- xc
== 0) ?
399 (y1
- yc
< 0) ? 90.0 : -90.0 :
400 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
401 alpha2
= (x2
- xc
== 0) ?
402 (y2
- yc
< 0) ? 90.0 : -90.0 :
403 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
405 while (alpha1
<= 0) alpha1
+= 360;
406 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
407 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
408 while (alpha2
> 360) alpha2
-= 360;
410 if (m_brush
.GetStyle() != wxTRANSPARENT
)
413 *m_pstream
<< "newpath\n"
414 << XLOG2DEV(xc
) << " "
415 << YLOG2DEV(yc
) << " "
416 << XLOG2DEVREL(radius
) << " "
417 << YLOG2DEVREL(radius
) << " "
419 << alpha2
<< " ellipse\n"
420 << XLOG2DEV(xc
) << " "
421 << YLOG2DEV(yc
) << " lineto\n"
426 if (m_pen
.GetStyle() != wxTRANSPARENT
)
429 *m_pstream
<< "newpath\n"
430 << XLOG2DEV(xc
) << " "
431 << YLOG2DEV(yc
) << " "
432 << XLOG2DEVREL(radius
) << " "
433 << YLOG2DEVREL(radius
) << " "
435 << alpha2
<< " ellipse\n"
439 CalcBoundingBox( xc
-radius
, yc
-radius
);
440 CalcBoundingBox( xc
+radius
, yc
+radius
);
443 void wxPostScriptDC::DrawEllipticArc(long x
,long y
,long w
,long h
,double sa
,double ea
)
445 if (!m_pstream
) return;
447 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
448 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
454 DrawEllipse(x
,y
,w
,h
);
458 if (m_brush
.GetStyle () != wxTRANSPARENT
)
462 *m_pstream
<< "newpath\n"
463 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
464 << XLOG2DEVREL(w
/2) << " " << YLOG2DEVREL(h
/2) << " "
465 << int(sa
) <<" "<< int(ea
) << " true ellipticarc\n";
467 CalcBoundingBox( x
,y
);
468 CalcBoundingBox( x
+w
, y
+h
);
471 if (m_pen
.GetStyle () != wxTRANSPARENT
)
475 *m_pstream
<< "newpath\n"
476 << XLOG2DEV(x
+w
/2) << " " << YLOG2DEV(y
+h
/2) << " "
477 << XLOG2DEVREL(w
/2) << " " << XLOG2DEVREL(h
/2) << " "
478 << int(sa
) <<" "<< int(ea
) << " false ellipticarc\n";
480 CalcBoundingBox( x
, y
);
481 CalcBoundingBox( x
+w
, y
+h
);
485 void wxPostScriptDC::DrawPoint (long x
, long y
)
487 if (!m_pstream
) return;
489 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
493 *m_pstream
<< "newpath\n"
494 << XLOG2DEV(x
) << " " << YLOG2DEV (y
) << " moveto\n"
495 << XLOG2DEV(x
+1) << " " << YLOG2DEV (y
) << " lineto\n"
498 CalcBoundingBox( x
, y
);
501 void wxPostScriptDC::DrawPolygon (int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
503 if (!m_pstream
) return;
507 if (m_brush
.GetStyle () != wxTRANSPARENT
)
511 *m_pstream
<< "newpath\n";
513 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
514 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
515 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
516 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
518 for (int i
= 1; i
< n
; i
++)
520 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
521 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
522 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
523 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
525 *m_pstream
<< "fill\n";
528 if (m_pen
.GetStyle () != wxTRANSPARENT
)
532 *m_pstream
<< "newpath\n";
534 long xx
= XLOG2DEV(points
[0].x
+ xoffset
);
535 long yy
= YLOG2DEV(points
[0].y
+ yoffset
);
536 *m_pstream
<< xx
<< " " << yy
<< " moveto\n";
537 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
539 for (int i
= 1; i
< n
; i
++)
541 xx
= XLOG2DEV(points
[i
].x
+ xoffset
);
542 yy
= YLOG2DEV(points
[i
].y
+ yoffset
);
543 *m_pstream
<< xx
<< " " << yy
<< " lineto\n";
544 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
547 *m_pstream
<< "stroke\n";
551 void wxPostScriptDC::DrawLines (int n
, wxPoint points
[], long xoffset
, long yoffset
)
553 if (!m_pstream
) return;
555 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
560 for (int i
=0; i
<n
; ++i
)
562 CalcBoundingBox( XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
));
565 *m_pstream
<< "newpath\n"
566 << XLOG2DEV(points
[0].x
+xoffset
) << " "
567 << YLOG2DEV(points
[0].y
+yoffset
) << " moveto\n";
569 for (int i
= 1; i
< n
; i
++)
571 *m_pstream
<< XLOG2DEV(points
[i
].x
+xoffset
) << " "
572 << YLOG2DEV(points
[i
].y
+yoffset
) << " lineto\n";
575 *m_pstream
<< "stroke\n";
578 void wxPostScriptDC::DrawRectangle (long x
, long y
, long width
, long height
)
580 if (!m_pstream
) return;
582 if (m_brush
.GetStyle () != wxTRANSPARENT
)
586 *m_pstream
<< "newpath\n"
587 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
588 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
589 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
590 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
594 CalcBoundingBox( x
, y
);
595 CalcBoundingBox( x
+ width
, y
+ height
);
598 if (m_pen
.GetStyle () != wxTRANSPARENT
)
602 *m_pstream
<< "newpath\n"
603 << XLOG2DEV(x
) << " " << YLOG2DEV(y
) << " moveto\n"
604 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
) << " lineto\n"
605 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
606 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
610 CalcBoundingBox( x
, y
);
611 CalcBoundingBox( x
+ width
, y
+ height
);
615 void wxPostScriptDC::DrawRoundedRectangle (long x
, long y
, long width
, long height
, double radius
)
617 if (!m_pstream
) return;
621 // Now, a negative radius is interpreted to mean
622 // 'the proportion of the smallest X or Y dimension'
623 double smallest
= 0.0;
628 radius
= (-radius
* smallest
);
631 long rad
= (long) radius
;
633 if (m_brush
.GetStyle () != wxTRANSPARENT
)
637 // Draw rectangle anticlockwise
638 *m_pstream
<< "newpath\n"
639 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
640 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
641 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
642 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
643 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
644 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
645 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
646 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
650 CalcBoundingBox( x
, y
);
651 CalcBoundingBox( x
+ width
, y
+ height
);
654 if (m_pen
.GetStyle () != wxTRANSPARENT
)
658 // Draw rectangle anticlockwise
659 *m_pstream
<< "newpath\n"
660 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 90 180 arc\n"
661 << XLOG2DEV(x
) << " " << YLOG2DEV(y
+ rad
) << " moveto\n"
662 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 180 270 arc\n"
663 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
) << " lineto\n"
664 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ height
- rad
) << " " << XLOG2DEVREL(rad
) << " 270 0 arc\n"
665 << XLOG2DEV(x
+ width
) << " " << YLOG2DEV(y
+ rad
) << " lineto\n"
666 << XLOG2DEV(x
+ width
- rad
) << " " << YLOG2DEV(y
+ rad
) << " " << XLOG2DEVREL(rad
) << " 0 90 arc\n"
667 << XLOG2DEV(x
+ rad
) << " " << YLOG2DEV(y
) << " lineto\n"
671 CalcBoundingBox( x
, y
);
672 CalcBoundingBox( x
+ width
, y
+ height
);
676 void wxPostScriptDC::DrawEllipse (long x
, long y
, long width
, long height
)
678 if (!m_pstream
) return;
680 if (m_brush
.GetStyle () != wxTRANSPARENT
)
684 *m_pstream
<< "newpath\n"
685 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
686 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
689 CalcBoundingBox( x
- width
, y
- height
);
690 CalcBoundingBox( x
+ width
, y
+ height
);
693 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
697 *m_pstream
<< "newpath\n"
698 << XLOG2DEV(x
+ width
/ 2) << " " << YLOG2DEV(y
+ height
/ 2) << " "
699 << XLOG2DEV(width
/ 2) << " " << YLOG2DEVREL(height
/ 2) << " 0 360 ellipse\n"
702 CalcBoundingBox( x
- width
, y
- height
);
703 CalcBoundingBox( x
+ width
, y
+ height
);
707 void wxPostScriptDC::DrawIcon (const wxIcon
& icon
, long x
, long y
)
710 memDC
.SelectObject( icon
);
711 Blit(x
, y
, icon
.GetWidth(), icon
.GetHeight(), &memDC
, 0, 0);
714 void wxPostScriptDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool useMask
)
717 memDC
.SelectObject( bitmap
);
718 Blit( x
, y
, bitmap
.GetWidth(), bitmap
.GetHeight(), &memDC
, 0, 0, useMask
);
721 void wxPostScriptDC::SetFont (const wxFont
& font
)
723 if (!m_pstream
) return;
725 if (!font
.Ok()) return;
729 char *name
= wxTheFontNameDirectory
->GetPostScriptName( m_font
.GetFamily(),
732 if (!name
) name
= "Times-Roman";
734 *m_pstream
<< "/" << name
<< " reencodeISO def\n"
735 << "/" << name
<< " findfont\n"
736 << YLOG2DEVREL(font
.GetPointSize())
737 << " scalefont setfont\n";
740 void wxPostScriptDC::SetPen( const wxPen
& pen
)
742 if (!m_pstream
) return;
744 if (!pen
.Ok()) return;
746 int oldStyle
= m_pen
.GetStyle();
750 *m_pstream
<< XLOG2DEVREL(m_pen
.GetWidth()) << " setlinewidth\n";
753 Line style - WRONG: 2nd arg is OFFSET
755 Here, I'm afraid you do not conceive meaning of parameters of 'setdash'
756 operator correctly. You should look-up this in the Red Book: the 2nd parame-
757 ter is not number of values in the array of the first one, but an offset
758 into this description of the pattern. I mean a real *offset* not index
759 into array. I.e. If the command is [3 4] 1 setdash is used, then there
760 will be first black line *2* units long, then space 4 units, then the
761 pattern of *3* units black, 4 units space will be repeated.
764 static const char *dotted
= "[2 5] 2";
765 static const char *short_dashed
= "[4 4] 2";
766 static const char *long_dashed
= "[4 8] 2";
767 static const char *dotted_dashed
= "[6 6 2 6] 4";
769 const char *psdash
= (char *) NULL
;
770 switch (m_pen
.GetStyle ())
772 case wxDOT
: psdash
= dotted
; break;
773 case wxSHORT_DASH
: psdash
= short_dashed
; break;
774 case wxLONG_DASH
: psdash
= long_dashed
; break;
775 case wxDOT_DASH
: psdash
= dotted_dashed
; break;
778 default: psdash
= "[] 0"; break;
781 if (oldStyle
!= m_pen
.GetStyle())
783 *m_pstream
<< psdash
<< " setdash\n";
787 unsigned char red
= m_pen
.GetColour().Red();
788 unsigned char blue
= m_pen
.GetColour().Blue();
789 unsigned char green
= m_pen
.GetColour().Green();
793 // Anything not white is black
794 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
795 && green
== (unsigned char) 255))
797 red
= (unsigned char) 0;
798 green
= (unsigned char) 0;
799 blue
= (unsigned char) 0;
805 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
807 long redPS
= (long) (((int) red
) / 255.0);
808 long bluePS
= (long) (((int) blue
) / 255.0);
809 long greenPS
= (long) (((int) green
) / 255.0);
811 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
814 m_currentBlue
= blue
;
815 m_currentGreen
= green
;
819 void wxPostScriptDC::SetBrush( const wxBrush
& brush
)
821 if (!m_pstream
) return;
823 if (!brush
.Ok()) return;
828 unsigned char red
= m_brush
.GetColour ().Red ();
829 unsigned char blue
= m_brush
.GetColour ().Blue ();
830 unsigned char green
= m_brush
.GetColour ().Green ();
834 // Anything not black is white
835 if (!(red
== (unsigned char) 0 && blue
== (unsigned char) 0
836 && green
== (unsigned char) 0))
838 red
= (unsigned char) 255;
839 green
= (unsigned char) 255;
840 blue
= (unsigned char) 255;
846 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
848 long redPS
= (long) (((int) red
) / 255.0);
849 long bluePS
= (long) (((int) blue
) / 255.0);
850 long greenPS
= (long) (((int) green
) / 255.0);
851 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
853 m_currentBlue
= blue
;
854 m_currentGreen
= green
;
858 void wxPostScriptDC::DrawText( const wxString
& text
, long x
, long y
, bool WXUNUSED(use16bit
) )
860 if (!m_pstream
) return;
864 if (m_textForegroundColour
.Ok ())
866 unsigned char red
= m_textForegroundColour
.Red ();
867 unsigned char blue
= m_textForegroundColour
.Blue ();
868 unsigned char green
= m_textForegroundColour
.Green ();
872 // Anything not white is black
873 if (!(red
== (unsigned char) 255 && blue
== (unsigned char) 255
874 && green
== (unsigned char) 255))
876 red
= (unsigned char) 0;
877 green
= (unsigned char) 0;
878 blue
= (unsigned char) 0;
882 // maybe setgray here ?
884 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
886 long redPS
= (long) (((int) red
) / 255.0);
887 long bluePS
= (long) (((int) blue
) / 255.0);
888 long greenPS
= (long) (((int) green
) / 255.0);
889 *m_pstream
<< redPS
<< " " << greenPS
<< " " << bluePS
<< " setrgbcolor\n";
892 m_currentBlue
= blue
;
893 m_currentGreen
= green
;
897 int size
= m_font
.GetPointSize();
899 long by
= y
+ (long)floor( float(size
) * 2.0 / 3.0 ); // approximate baseline
900 *m_pstream
<< XLOG2DEV(x
) << " " << YLOG2DEV(by
) << " moveto\n";
903 int len
= strlen ((char *)(const char *)text
);
905 for (i
= 0; i
< len
; i
++)
907 int c
= (unsigned char) text
[i
];
908 if ( c
== ')' || c
== '(' || c
== '\\')
910 *m_pstream
<< "\\" << (char) c
;
914 // Cope with character codes > 127
916 sprintf(tmp
, "\\%o", c
);
920 *m_pstream
<< (char) c
;
923 *m_pstream
<< ")" << " show\n";
925 if (m_font
.GetUnderlined())
927 long uy
= (long)(y
+ size
- m_underlinePosition
);
929 GetTextExtent(text
, &w
, &h
);
931 *m_pstream
<< "gsave " << XLOG2DEV(x
) << " " << YLOG2DEV(uy
)
933 << (long)m_underlineThickness
<< " setlinewidth "
934 << XLOG2DEV(x
+ w
) << " " << YLOG2DEV(uy
)
935 << " lineto stroke grestore\n";
938 CalcBoundingBox( x
, y
);
939 CalcBoundingBox( x
+ size
* text
.Length() * 2/3 , y
);
943 void wxPostScriptDC::SetBackground (const wxBrush
& brush
)
945 m_backgroundBrush
= brush
;
948 void wxPostScriptDC::SetLogicalFunction (int WXUNUSED(function
))
950 wxFAIL_MSG( "wxPostScriptDC::SetLogicalFunction not implemented." );
953 void wxPostScriptDC::DrawSpline( wxList
*points
)
955 if (!m_pstream
) return;
959 double a
, b
, c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
962 wxNode
*node
= points
->First();
963 p
= (wxPoint
*)node
->Data();
968 p
= (wxPoint
*)node
->Data();
971 x3
= a
= (double)(x1
+ c
) / 2;
972 y3
= b
= (double)(y1
+ d
) / 2;
974 *m_pstream
<< "newpath "
975 << XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " moveto "
976 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " lineto\n";
978 CalcBoundingBox( (long)x1
, (long)y1
);
979 CalcBoundingBox( (long)x3
, (long)y3
);
981 while ((node
= node
->Next()) != NULL
)
983 q
= (wxPoint
*)node
->Data();
991 x3
= (double)(x2
+ c
) / 2;
992 y3
= (double)(y2
+ d
) / 2;
993 *m_pstream
<< XLOG2DEV((long)x1
) << " " << YLOG2DEV((long)y1
) << " "
994 << XLOG2DEV((long)x2
) << " " << YLOG2DEV((long)y2
) << " "
995 << XLOG2DEV((long)x3
) << " " << YLOG2DEV((long)y3
) << " DrawSplineSection\n";
997 CalcBoundingBox( (long)x1
, (long)y1
);
998 CalcBoundingBox( (long)x3
, (long)y3
);
1002 At this point, (x2,y2) and (c,d) are the position of the
1003 next-to-last and last point respectively, in the point list
1006 *m_pstream
<< XLOG2DEV((long)c
) << " " << YLOG2DEV((long)d
) << " lineto stroke\n";
1009 long wxPostScriptDC::GetCharWidth ()
1011 // Chris Breeze: reasonable approximation using wxMODERN/Courier
1012 return (long) (GetCharHeight() * 72.0 / 120.0);
1016 void wxPostScriptDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1018 m_signX
= (xLeftRight
? 1 : -1);
1019 m_signY
= (yBottomUp
? 1 : -1);
1021 ComputeScaleAndOrigin();
1024 void wxPostScriptDC::SetDeviceOrigin( long x
, long y
)
1030 wxDC::SetDeviceOrigin( x
, h
-y
);
1033 void wxPostScriptDC::GetSize(int* width
, int* height
) const
1035 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1037 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1039 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1041 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1045 *width
= paper
->widthPixels
;
1046 *height
= paper
->heightPixels
;
1055 bool wxPostScriptDC::StartDoc (const wxString
& message
)
1057 if (m_filename
== "")
1059 m_filename
= wxGetTempFileName("ps");
1060 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1065 wxThePrintSetupData
->SetPrinterFile((char *)(const char *)m_filename
);
1068 m_pstream
= new ofstream (wxThePrintSetupData
->GetPrinterFile());
1070 if (!m_pstream
|| !m_pstream
->good())
1072 wxMessageBox (_("Cannot open file!"), _("Error"), wxOK
);
1079 SetBrush( *wxBLACK_BRUSH
);
1080 SetPen( *wxBLACK_PEN
);
1081 SetBackground( *wxWHITE_BRUSH
);
1082 SetTextForeground( *wxBLACK
);
1084 // set origin according to paper size
1085 SetDeviceOrigin( 0,0 );
1093 void wxPostScriptDC::EndDoc ()
1095 if (!m_pstream
) return;
1100 *m_pstream
<< "grestore\n";
1106 m_pstream
= (ofstream
*) NULL
;
1109 char *header_file
= wxGetTempFileName("ps");
1111 m_pstream
= new ofstream( header_file
);
1113 *m_pstream
<< "%!PS-Adobe-2.0\n"; /* PostScript magic strings */
1114 *m_pstream
<< "%%Title: " << (const char *) m_title
<< "\n";
1115 *m_pstream
<< "%%Creator: " << wxTheApp
->argv
[0] << "\n";
1116 *m_pstream
<< "%%CreationDate: " << wxNow() << "\n";
1119 if ( wxGetEmailAddress(userID
, sizeof(userID
)) )
1121 *m_pstream
<< "%%For: " << (char *)userID
;
1123 if (wxGetUserName(userName
, sizeof(userName
)))
1124 *m_pstream
<< " (" << (char *)userName
<< ")";
1127 else if ( wxGetUserName(userID
, sizeof(userID
)) )
1129 *m_pstream
<< "%%For: " << (char *)userID
<< "\n";
1132 // THE FOLLOWING HAS BEEN CONTRIBUTED BY Andy Fyfe <andy@hyperparallel.com>
1134 long wx_printer_translate_x
, wx_printer_translate_y
;
1135 double wx_printer_scale_x
, wx_printer_scale_y
;
1136 wxThePrintSetupData
->GetPrinterTranslation(&wx_printer_translate_x
, &wx_printer_translate_y
);
1137 wxThePrintSetupData
->GetPrinterScaling(&wx_printer_scale_x
, &wx_printer_scale_y
);
1139 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1141 *m_pstream
<< "%%Orientation: Landscape\n";
1145 *m_pstream
<< "%%Orientation: Portrait\n";
1148 // Compute the bounding box. Note that it is in the default user
1149 // coordinate system, thus we have to convert the values.
1150 long llx
= (long) ((XLOG2DEV(m_minX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1151 long lly
= (long) ((YLOG2DEV(m_minY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1152 long urx
= (long) ((XLOG2DEV(m_maxX
)+wx_printer_translate_x
)*wx_printer_scale_x
);
1153 long ury
= (long) ((YLOG2DEV(m_maxY
)+wx_printer_translate_y
)*wx_printer_scale_y
);
1155 // If we're landscape, our sense of "x" and "y" is reversed.
1156 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1159 tmp
= llx
; llx
= lly
; lly
= tmp
;
1160 tmp
= urx
; urx
= ury
; ury
= tmp
;
1162 // We need either the two lines that follow, or we need to subtract
1163 // min_x from real_translate_y, which is commented out below.
1164 llx
= llx
- (long)(m_minX
*wx_printer_scale_y
);
1165 urx
= urx
- (long)(m_minX
*wx_printer_scale_y
);
1168 // The Adobe specifications call for integers; we round as to make
1169 // the bounding larger.
1170 *m_pstream
<< "%%BoundingBox: "
1171 << floor((double)llx
) << " " << floor((double)lly
) << " "
1172 << ceil((double)urx
) << " " << ceil((double)ury
) << "\n";
1173 *m_pstream
<< "%%Pages: " << (wxPageNumber
- 1) << "\n";
1174 *m_pstream
<< "%%EndComments\n\n";
1176 // To check the correctness of the bounding box, postscript commands
1177 // to draw a box corresponding to the bounding box are generated below.
1178 // But since we typically don't want to print such a box, the postscript
1179 // commands are generated within comments. These lines appear before any
1180 // adjustment of scale, rotation, or translation, and hence are in the
1181 // default user coordinates.
1182 *m_pstream
<< "% newpath\n";
1183 *m_pstream
<< "% " << llx
<< " " << lly
<< " moveto\n";
1184 *m_pstream
<< "% " << urx
<< " " << lly
<< " lineto\n";
1185 *m_pstream
<< "% " << urx
<< " " << ury
<< " lineto\n";
1186 *m_pstream
<< "% " << llx
<< " " << ury
<< " lineto closepath stroke\n";
1188 *m_pstream
<< "%%BeginProlog\n";
1189 *m_pstream
<< wxPostScriptHeaderEllipse
;
1190 *m_pstream
<< wxPostScriptHeaderEllipticArc
;
1191 *m_pstream
<< wxPostScriptHeaderReencodeISO1
;
1192 *m_pstream
<< wxPostScriptHeaderReencodeISO2
;
1194 if (wxPostScriptHeaderSpline
)
1195 *m_pstream
<< wxPostScriptHeaderSpline
;
1196 *m_pstream
<< "%%EndProlog\n";
1199 m_pstream
= (ofstream
*) NULL
;
1201 char *tmp_file
= wxGetTempFileName("ps");
1203 // Paste header Before wx_printer_file
1204 wxConcatFiles (header_file
, wxThePrintSetupData
->GetPrinterFile(), tmp_file
);
1205 wxRemoveFile (header_file
);
1206 wxRemoveFile (wxThePrintSetupData
->GetPrinterFile());
1207 wxRenameFile(tmp_file
, wxThePrintSetupData
->GetPrinterFile());
1209 #if defined(__X__) || defined(__WXGTK__)
1212 switch (wxThePrintSetupData
->GetPrinterMode()) {
1216 argv
[0] = wxThePrintSetupData
->GetPrintPreviewCommand();
1217 argv
[1] = wxThePrintSetupData
->GetPrinterFile();
1218 argv
[2] = (char *) NULL
;
1219 wxExecute (argv
, TRUE
);
1220 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1228 argv
[argc
++] = wxThePrintSetupData
->GetPrinterCommand();
1230 // !SM! If we simply assign to argv[1] here, if printer options
1231 // are blank, we get an annoying and confusing message from lpr.
1232 char * opts
= wxThePrintSetupData
->GetPrinterOptions();
1234 argv
[argc
++] = opts
;
1236 argv
[argc
++] = wxThePrintSetupData
->GetPrinterFile();
1237 argv
[argc
++] = (char *) NULL
;
1238 wxExecute (argv
, TRUE
);
1239 wxRemoveFile(wxThePrintSetupData
->GetPrinterFile());
1250 void wxPostScriptDC::StartPage ()
1252 if (!m_pstream
) return;
1254 *m_pstream
<< "%%Page: " << (wxPageNumber
++) << "\n";
1256 // *m_pstream << "matrix currentmatrix\n";
1258 // Added by Chris Breeze
1260 // Each page starts with an "initgraphics" which resets the
1261 // transformation and so we need to reset the origin
1262 // (and rotate the page for landscape printing)
1265 m_scaleFactor = 1.0;
1266 m_logicalOriginX = 0;
1267 m_logicalOriginY = 0;
1271 long translate_x
, translate_y
;
1272 double scale_x
, scale_y
;
1273 wxThePrintSetupData
->GetPrinterTranslation(&translate_x
, &translate_y
);
1274 wxThePrintSetupData
->GetPrinterScaling(&scale_x
, &scale_y
);
1276 if (wxThePrintSetupData
->GetPrinterOrientation() == PS_LANDSCAPE
)
1278 translate_y
-= m_maxY
;
1279 *m_pstream
<< "90 rotate\n";
1282 *m_pstream
<< scale_x
<< " " << scale_y
<< " scale\n";
1283 *m_pstream
<< translate_x
<< " " << translate_y
<< " translate\n";
1286 void wxPostScriptDC::EndPage ()
1288 if (!m_pstream
) return;
1290 *m_pstream
<< "showpage\n";
1293 bool wxPostScriptDC::Blit (long xdest
, long ydest
, long fwidth
, long fheight
,
1294 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(rop
), bool WXUNUSED(useMask
))
1299 long wxPostScriptDC::GetCharHeight ()
1302 return m_font
.GetPointSize();
1307 void wxPostScriptDC::GetTextExtent (const wxString
& string
, long *x
, long *y
,
1308 long *descent
, long *externalLeading
, wxFont
*theFont
,
1309 bool WXUNUSED(use16
))
1311 // if (!m_pstream) return;
1313 wxFont
*fontToUse
= theFont
;
1315 if (!fontToUse
) fontToUse
= (wxFont
*) &m_font
;
1317 #if !USE_AFM_FOR_POSTSCRIPT
1318 // Provide a VERY rough estimate (avoid using it)
1319 // Chris Breeze 5/11/97: produces accurate results for mono-spaced
1320 // font such as Courier (aka wxMODERN)
1324 height
= fontToUse
->GetPointSize();
1326 *x
= strlen (string
) * height
* 72 / 120;
1327 *y
= (long) (height
* 1.32); // allow for descender
1331 if (externalLeading
)
1332 *externalLeading
= 0;
1334 // +++++ start of contributed code +++++
1336 // ************************************************************
1337 // method for calculating string widths in postscript:
1338 // read in the AFM (adobe font metrics) file for the
1339 // actual font, parse it and extract the character widths
1340 // and also the descender. this may be improved, but for now
1341 // it works well. the AFM file is only read in if the
1342 // font is changed. this may be chached in the future.
1343 // calls to GetTextExtent with the font unchanged are rather
1346 // for each font and style used there is an AFM file necessary.
1347 // currently i have only files for the roman font family.
1348 // i try to get files for the other ones!
1350 // CAVE: the size of the string is currently always calculated
1351 // in 'points' (1/72 of an inch). this should later on be
1352 // changed to depend on the mapping mode.
1353 // CAVE: the path to the AFM files must be set before calling this
1354 // function. this is usually done by a call like the following:
1355 // wxSetAFMPath("d:\\wxw161\\afm\\");
1359 // wxPostScriptDC dc(NULL, TRUE);
1361 // wxSetAFMPath("d:\\wxw161\\afm\\");
1362 // dc.StartDoc("Test");
1365 // dc.SetFont(new wxFont(10, wxROMAN, wxNORMAL, wxNORMAL));
1366 // dc.GetTextExtent("Hallo",&w,&h);
1371 // by steve (stefan.hammes@urz.uni-heidelberg.de)
1372 // created: 10.09.94
1373 // updated: 14.05.95
1375 assert(fontToUse
&& "void wxPostScriptDC::GetTextExtent: no font defined");
1376 assert(x
&& "void wxPostScriptDC::GetTextExtent: x == NULL");
1377 assert(y
&& "void wxPostScriptDC::GetTextExtent: y == NULL");
1379 // these static vars are for storing the state between calls
1380 static int lastFamily
= INT_MIN
;
1381 static int lastSize
= INT_MIN
;
1382 static int lastStyle
= INT_MIN
;
1383 static int lastWeight
= INT_MIN
;
1384 static int lastDescender
= INT_MIN
;
1385 static int lastWidths
[256]; // widths of the characters
1387 // get actual parameters
1388 const int Family
= fontToUse
->GetFamily();
1389 const int Size
= fontToUse
->GetPointSize();
1390 const int Style
= fontToUse
->GetStyle();
1391 const int Weight
= fontToUse
->GetWeight();
1393 // if we have another font, read the font-metrics
1394 if(Family
!=lastFamily
||Size
!=lastSize
||Style
!=lastStyle
||Weight
!=lastWeight
){
1395 // store actual values
1396 lastFamily
= Family
;
1399 lastWeight
= Weight
;
1401 // read in new font metrics **************************************
1403 // 1. construct filename ******************************************
1404 /* MATTHEW: [2] Use wxTheFontNameDirectory */
1407 // Julian - we'll need to do this a different way now we've removed the
1408 // font directory system. Must find Stefan's original code.
1410 name
= wxTheFontNameDirectory
->GetAFMName(Family
, Weight
, Style
);
1414 // get the directory of the AFM files
1418 strcpy(afmName
,wxGetAFMPath());
1420 // 2. open and process the file **********************************
1422 // a short explanation of the AFM format:
1423 // we have for each character a line, which gives its size
1426 // C 63 ; WX 444 ; N question ; B 49 -14 395 676 ;
1428 // that means, we have a character with ascii code 63, and width
1429 // (444/1000 * fontSize) points.
1430 // the other data is ignored for now!
1432 // when the font has changed, we read in the right AFM file and store the
1433 // character widths in an array, which is processed below (see point 3.).
1435 // new elements JC Sun Aug 25 23:21:44 MET DST 1996
1438 strcat(afmName
,name
);
1439 strcat(afmName
,".afm");
1440 FILE *afmFile
= fopen(afmName
,"r");
1442 wxDebugMsg("GetTextExtent: can't open AFM file '%s'\n",afmName
);
1443 wxDebugMsg(" using approximate values\n");
1445 for (i
=0; i
<256; i
++) lastWidths
[i
] = 500; // an approximate value
1446 lastDescender
= -150; // dito.
1449 // init the widths array
1450 for(i
=0; i
<256; i
++) lastWidths
[i
]= INT_MIN
;
1451 // some variables for holding parts of a line
1452 char cString
[10],semiString
[10],WXString
[10],descString
[20];
1453 char upString
[30], utString
[30], encString
[50];
1456 // read in the file and parse it
1457 while(fgets(line
,sizeof(line
),afmFile
)!=NULL
){
1458 // A.) check for descender definition
1459 if(strncmp(line
,"Descender",9)==0){
1460 if((sscanf(line
,"%s%d",descString
,&lastDescender
)!=2)
1461 || (strcmp(descString
,"Descender")!=0)) {
1462 wxDebugMsg("AFM-file '%s': line '%s' has error (bad descender)\n",
1466 // JC 1.) check for UnderlinePosition
1467 else if(strncmp(line
,"UnderlinePosition",17)==0){
1468 if((sscanf(line
,"%s%lf",upString
,&UnderlinePosition
)!=2)
1469 || (strcmp(upString
,"UnderlinePosition")!=0)) {
1470 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlinePosition)\n",
1474 // JC 2.) check for UnderlineThickness
1475 else if(strncmp(line
,"UnderlineThickness",18)==0){
1476 if((sscanf(line
,"%s%lf",utString
,&UnderlineThickness
)!=2)
1477 || (strcmp(utString
,"UnderlineThickness")!=0)) {
1478 wxDebugMsg("AFM-file '%s': line '%s' has error (bad UnderlineThickness)\n",
1482 // JC 3.) check for EncodingScheme
1483 else if(strncmp(line
,"EncodingScheme",14)==0){
1484 if((sscanf(line
,"%s%s",utString
,encString
)!=2)
1485 || (strcmp(utString
,"EncodingScheme")!=0)) {
1486 wxDebugMsg("AFM-file '%s': line '%s' has error (bad EncodingScheme)\n",
1489 else if (strncmp(encString
, "AdobeStandardEncoding", 21))
1491 wxDebugMsg("AFM-file '%s': line '%s' has error (unsupported EncodingScheme %s)\n",
1492 afmName
,line
, encString
);
1495 // B.) check for char-width
1496 else if(strncmp(line
,"C ",2)==0){
1497 if(sscanf(line
,"%s%d%s%s%d",
1498 cString
,&ascii
,semiString
,WXString
,&cWidth
)!=5){
1499 wxDebugMsg("AFM-file '%s': line '%s' has an error (bad character width)\n",afmName
,line
);
1501 if(strcmp(cString
,"C")!=0 || strcmp(semiString
,";")!=0 ||
1502 strcmp(WXString
,"WX")!=0){
1503 wxDebugMsg("AFM-file '%s': line '%s' has a format error\n",afmName
,line
);
1505 //printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth);
1506 if(ascii
>=0 && ascii
<256){
1507 lastWidths
[ascii
] = cWidth
; // store width
1509 /* MATTHEW: this happens a lot; don't print an error */
1510 // wxDebugMsg("AFM-file '%s': ASCII value %d out of range\n",afmName,ascii);
1513 // C.) ignore other entries.
1517 // hack to compute correct values for german 'Umlaute'
1518 // the correct way would be to map the character names
1519 // like 'adieresis' to corresp. positions of ISOEnc and read
1520 // these values from AFM files, too. Maybe later ...
1521 lastWidths
[196] = lastWidths
['A']; // Ä
1522 lastWidths
[228] = lastWidths
['a']; // ä
1523 lastWidths
[214] = lastWidths
['O']; // Ö
1524 lastWidths
[246] = lastWidths
['o']; // ö
1525 lastWidths
[220] = lastWidths
['U']; // Ü
1526 lastWidths
[252] = lastWidths
['u']; // ü
1527 lastWidths
[223] = lastWidths
[251]; // ß
1530 // JC: calculate UnderlineThickness/UnderlinePosition
1531 m_underlinePosition
= m_underlinePosition
* fontToUse
->GetPointSize() / 1000.0f
;
1532 m_underlineThickness
= m_underlineThickness
* fontToUse
->GetPointSize() / 1000.0f
* m_scaleFactor
;
1534 // 3. now the font metrics are read in, calc size *******************
1535 // this is done by adding the widths of the characters in the
1536 // string. they are given in 1/1000 of the size!
1539 long height
=Size
; // by default
1541 for(p
=(unsigned char *)(const char *)string
; *p
; p
++){
1542 if(lastWidths
[*p
]== INT_MIN
){
1543 wxDebugMsg("GetTextExtent: undefined width for character '%c' (%d)\n",
1545 widthSum
+= (long)(lastWidths
[' ']/1000.0F
* Size
); // assume space
1547 widthSum
+= (long)((lastWidths
[*p
]/1000.0F
)*Size
);
1550 // add descender to height (it is usually a negative value)
1551 if(lastDescender
!=INT_MIN
){
1552 height
+= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1555 // return size values
1559 // return other parameters
1561 if(lastDescender
!=INT_MIN
){
1562 *descent
= (long)(((-lastDescender
)/1000.0F
) * Size
); /* MATTHEW: forgot scale */
1568 // currently no idea how to calculate this!
1569 // if (externalLeading) *externalLeading = 0;
1570 if (externalLeading
)
1571 *externalLeading
= 0;
1573 // ----- end of contributed code -----
1577 void wxPostScriptDC::GetSizeMM(long *width
, long *height
) const
1579 const char *paperType
= wxThePrintSetupData
->GetPaperName();
1581 if (!paperType
) paperType
= _("A4 210 x 297 mm");
1583 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1585 if (!paper
) paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
1589 *width
= paper
->widthMM
;
1590 *height
= paper
->heightMM
;