Fix underline length for underlined text (wxPostScriptDC)
Draw underline relatively to the baseline and obtain line parameters using 'stringwidth' operator instead of calculating them manually based on the parameters returned by DoGetTextExtent(), which are not always accurate (e.g. if no AFM files are available). Closes #17788.
This commit is contained in:
@@ -120,6 +120,7 @@ All (GUI):
|
|||||||
- Improve wxImage::Scale() handling of pixels with alpha channel (Tim Kosse).
|
- Improve wxImage::Scale() handling of pixels with alpha channel (Tim Kosse).
|
||||||
- Fix parsing of RGBA strings in wxColour (Laurent Poujoulat).
|
- Fix parsing of RGBA strings in wxColour (Laurent Poujoulat).
|
||||||
- Refactor code in wxQuantize() for MSVC to avoid crash.
|
- Refactor code in wxQuantize() for MSVC to avoid crash.
|
||||||
|
- Fix drawing rotated and/or underlined text on wxPostScriptDC.
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -1354,9 +1354,9 @@ void wxPostScriptDCImpl::DoDrawText( const wxString& text, wxCoord x, wxCoord y
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCoord text_w, text_h, text_descent;
|
wxCoord text_descent;
|
||||||
|
|
||||||
GetOwner()->GetTextExtent(text, &text_w, &text_h, &text_descent);
|
GetOwner()->GetTextExtent(text, NULL, NULL, &text_descent);
|
||||||
|
|
||||||
int size = m_font.GetPointSize();
|
int size = m_font.GetPointSize();
|
||||||
|
|
||||||
@@ -1392,25 +1392,30 @@ void wxPostScriptDCImpl::DoDrawText( const wxString& text, wxCoord x, wxCoord y
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PsPrint( ") show\n" );
|
PsPrint( ")\n" );
|
||||||
|
|
||||||
if (m_font.GetUnderlined())
|
if (m_font.GetUnderlined())
|
||||||
{
|
{
|
||||||
wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
|
// We need relative underline position
|
||||||
|
// with reference to the baseline:
|
||||||
|
// uy = y + size - m_underlinePosition =>
|
||||||
|
// uy = by + text_descent - m_underlinePosition =>
|
||||||
|
// dy = -(text_descent - m_underlinePosition)
|
||||||
|
// It's negated due to the orientation of Y-axis.
|
||||||
buffer.Printf( "gsave\n"
|
buffer.Printf( "gsave\n"
|
||||||
"%f %f moveto\n"
|
"0.0 %f rmoveto\n"
|
||||||
"%f setlinewidth\n"
|
"%f setlinewidth\n"
|
||||||
"%f %f lineto\n"
|
"dup stringwidth rlineto\n"
|
||||||
"stroke\n"
|
"stroke\n"
|
||||||
"grestore\n",
|
"grestore\n",
|
||||||
XLOG2DEV(x), YLOG2DEV(uy),
|
-YLOG2DEVREL(text_descent - m_underlinePosition),
|
||||||
m_underlineThickness,
|
m_underlineThickness );
|
||||||
XLOG2DEV(x + text_w), YLOG2DEV(uy) );
|
|
||||||
buffer.Replace( ",", "." );
|
buffer.Replace( ",", "." );
|
||||||
PsPrint( buffer );
|
PsPrint( buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PsPrint("show\n");
|
||||||
|
|
||||||
CalcBoundingBox( x, y );
|
CalcBoundingBox( x, y );
|
||||||
CalcBoundingBox( x + size * text.length() * 2/3 , y );
|
CalcBoundingBox( x + size * text.length() * 2/3 , y );
|
||||||
}
|
}
|
||||||
@@ -1507,32 +1512,33 @@ void wxPostScriptDCImpl::DoDrawRotatedText( const wxString& text, wxCoord x, wxC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PsPrint( ") show\n" );
|
PsPrint( ")\n" );
|
||||||
|
|
||||||
buffer.Printf( "%f rotate\n", -angle );
|
|
||||||
buffer.Replace( ",", "." );
|
|
||||||
PsPrint( buffer );
|
|
||||||
|
|
||||||
if (m_font.GetUnderlined())
|
if (m_font.GetUnderlined())
|
||||||
{
|
{
|
||||||
wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
|
// We need relative underline position with reference
|
||||||
wxCoord w, h;
|
// to the baseline in rotated coordinate system:
|
||||||
GetOwner()->GetTextExtent(text, &w, &h);
|
// uy = y + size - m_underlinePosition =>
|
||||||
|
// uy = by + text_descent - m_underlinePosition =>
|
||||||
buffer.Printf(
|
// dy = -(text_descent - m_underlinePosition)
|
||||||
"gsave\n"
|
// It's negated due to the orientation of Y-axis.
|
||||||
"%f %f moveto\n"
|
buffer.Printf( "gsave\n"
|
||||||
"%f setlinewidth\n"
|
"0.0 %f rmoveto\n"
|
||||||
"%f %f lineto\n"
|
"%f setlinewidth\n"
|
||||||
"stroke\n"
|
"dup stringwidth rlineto\n"
|
||||||
"grestore\n",
|
"stroke\n"
|
||||||
XLOG2DEV(x), YLOG2DEV(uy),
|
"grestore\n",
|
||||||
m_underlineThickness,
|
-YLOG2DEVREL(text_descent - m_underlinePosition),
|
||||||
XLOG2DEV(x + w), YLOG2DEV(uy) );
|
m_underlineThickness );
|
||||||
buffer.Replace( ",", "." );
|
buffer.Replace( ",", "." );
|
||||||
PsPrint( buffer );
|
PsPrint( buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PsPrint("show\n");
|
||||||
|
buffer.Printf( "%f rotate\n", -angle );
|
||||||
|
buffer.Replace( ",", "." );
|
||||||
|
PsPrint( buffer );
|
||||||
|
|
||||||
CalcBoundingBox( x, y );
|
CalcBoundingBox( x, y );
|
||||||
CalcBoundingBox( x + size * text.length() * 2/3 , y );
|
CalcBoundingBox( x + size * text.length() * 2/3 , y );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user