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
This commit is contained in:
Václav Slavík
1999-12-11 21:52:43 +00:00
parent edbd0635f2
commit 6c3d9ced08

View File

@@ -1143,6 +1143,10 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
{ {
wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") ); 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 ); SetFont( m_font );
if (m_textForegroundColour.Ok()) if (m_textForegroundColour.Ok())
@@ -1183,7 +1187,10 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
int size = m_font.GetPointSize(); 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) ); 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 */ /* 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()) if (m_font.GetUnderlined())
{ {
wxCoord uy = (wxCoord)(y + size - m_underlinePosition); wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
wxCoord w, h;
GetTextExtent(text, &w, &h);
fprintf( m_pstream, fprintf( m_pstream,
"gsave\n" "gsave\n"
@@ -1233,7 +1238,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
"grestore\n", "grestore\n",
XLOG2DEV(x), YLOG2DEV(uy), XLOG2DEV(x), YLOG2DEV(uy),
(wxCoord)m_underlineThickness, (wxCoord)m_underlineThickness,
XLOG2DEV(x + w), YLOG2DEV(uy) ); XLOG2DEV(x + text_w), YLOG2DEV(uy) );
} }
CalcBoundingBox( x, y ); CalcBoundingBox( x, y );
@@ -2098,10 +2103,12 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string,
} }
/* add descender to height (it is usually a negative value) */ /* add descender to height (it is usually a negative value) */
if (lastDescender != INT_MIN) //if (lastDescender != INT_MIN)
{ //{
height += (wxCoord)(((-lastDescender)/1000.0F) * Size); /* MATTHEW: forgot scale */ // 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 */ /* return size values */
if ( x ) if ( x )