From 37b7d0e59490efbe84347c3f6212a5e4282588cd Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 19 Feb 2017 10:18:52 +0100 Subject: [PATCH] Fix calculating bounding box in wxPostScriptDC::DrawText and DrawRotatedText Calculate bounding box bearing in mind that drawn text can be a multi-line text. Closes #17801. --- src/generic/dcpsg.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index ce632204a4..7f699bb0fc 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -1449,8 +1449,10 @@ void wxPostScriptDCImpl::DoDrawText( const wxString& text, wxCoord x, wxCoord y DrawAnyText(textbuf, text_descent, size); - CalcBoundingBox( x, y ); - CalcBoundingBox( x + size * text.length() * 2/3 , y ); + wxCoord w, h; + GetOwner()->GetMultiLineTextExtent(text, &w, &h); + CalcBoundingBox(x, y); + CalcBoundingBox(x + w , y + h); } void wxPostScriptDCImpl::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle ) @@ -1492,8 +1494,16 @@ void wxPostScriptDCImpl::DoDrawRotatedText( const wxString& text, wxCoord x, wxC buffer.Replace( ",", "." ); PsPrint( buffer ); - CalcBoundingBox( x, y ); - CalcBoundingBox( x + size * text.length() * 2/3 , y ); + wxCoord w, h; + GetOwner()->GetMultiLineTextExtent(text, &w, &h); + // "upper left" and "upper right" + CalcBoundingBox(x, y); + CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(w*sin(rad))); + // "bottom left" and "bottom right" + x += (wxCoord)(h*sin(rad)); + y += (wxCoord)(h*cos(rad)); + CalcBoundingBox(x, y); + CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(w*sin(rad))); } void wxPostScriptDCImpl::SetBackground (const wxBrush& brush)