From ebf1141db25b47307d87ab4616bf2f0941bbcfd5 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Sat, 13 Feb 2021 15:05:16 +0100 Subject: [PATCH] Improve text extent rounding in wxGCDCImpl::DoGetTextExtent() Change wxGCDCImpl::DoGetTextExtent() from rounding to the nearest integer to rounding up: if e.g. height is 15.3 then 16 pixels should be used for height, and not 15. Rounding was previously improved from casting (which appears to be the initial code) in 0417955ddb (adding correct filling area to arc, correct rounding and clipping, 2007-10-21). Issues with nearest rounding became more visible after off-by-one fixes for wxDC::DrawLabel() with wxALIGN_RIGHT and wxALIGN_BOTTOM positioning. When using e.g. wxALIGN_RIGHT with a width of 72.4 the text could now be drawn beyond the extent on the right because the text is not offset by one to the left any longer. --- src/common/dcgraph.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index 4427c260a1..3936df0fff 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -1279,13 +1279,13 @@ void wxGCDCImpl::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord * ); if ( height ) - *height = (wxCoord)wxRound(h); + *height = (wxCoord)ceil(h); if ( descent ) - *descent = (wxCoord)wxRound(d); + *descent = (wxCoord)ceil(d); if ( externalLeading ) - *externalLeading = (wxCoord)wxRound(e); + *externalLeading = (wxCoord)ceil(e); if ( width ) - *width = (wxCoord)wxRound(w); + *width = (wxCoord)ceil(w); if ( theFont ) {