From 6c3d9ced08ebea44948d2e129bcef5e1752a4544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sat, 11 Dec 1999 21:52:43 +0000 Subject: [PATCH] wxPostScriptDC::DrawText now uses descent to determine baseline (instead of rough approximation), wxPostScriptDC::GetTextExtent now returns correct height (it did incorrectly add descent to pt size of font) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4907 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/dcpsg.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 40f98e14f2..4810b32078 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -1142,6 +1142,10 @@ void wxPostScriptDC::SetBrush( const wxBrush& brush ) void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) { wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); + + wxCoord text_w, text_h, text_descent; + + GetTextExtent(text, &text_w, &text_h, &text_descent); SetFont( m_font ); @@ -1183,7 +1187,10 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) int size = m_font.GetPointSize(); - wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline +// wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline +// commented by V. Slavik and replaced by accurate version +// - note that there is still rounding error in text_descent! + wxCoord by = y + size - text_descent; // baseline fprintf( m_pstream, "%d %d moveto\n", XLOG2DEV(x), YLOG2DEV(by) ); /* I don't know how to write char to a stream, so I use a mini string */ @@ -1221,8 +1228,6 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) if (m_font.GetUnderlined()) { wxCoord uy = (wxCoord)(y + size - m_underlinePosition); - wxCoord w, h; - GetTextExtent(text, &w, &h); fprintf( m_pstream, "gsave\n" @@ -1233,7 +1238,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y ) "grestore\n", XLOG2DEV(x), YLOG2DEV(uy), (wxCoord)m_underlineThickness, - XLOG2DEV(x + w), YLOG2DEV(uy) ); + XLOG2DEV(x + text_w), YLOG2DEV(uy) ); } CalcBoundingBox( x, y ); @@ -2098,10 +2103,12 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string, } /* add descender to height (it is usually a negative value) */ - if (lastDescender != INT_MIN) - { - height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */ - } + //if (lastDescender != INT_MIN) + //{ + // height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */ + //} + // - commented by V. Slavik - height already contains descender in it + // (judging from few experiments) /* return size values */ if ( x )