From ed77f522dd287f879a28d4eca798bb7458247488 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 11 Nov 2019 20:01:29 -0800 Subject: [PATCH] Align text to 4th column correctly Text mod calculation was off by one in alignment --- common/gal/stroke_font.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp index 81ffe6f930..69b3fdb81d 100644 --- a/common/gal/stroke_font.cpp +++ b/common/gal/stroke_font.cpp @@ -306,10 +306,15 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags ) // The choice of spaces is somewhat arbitrary but sufficient for aligning text if( *chIt == '\t' ) { - double fourSpaces = 4.0 * glyphSize.x * m_glyphBoundingBoxes[0].GetEnd().x; - double addlSpace = fourSpaces - std::fmod( xOffset, fourSpaces ); + double space = glyphSize.x * m_glyphBoundingBoxes[0].GetEnd().x; + + // We align to the 4th column (fmod) but only need to account for 3 of + // the four spaces here with the extra. This ensures that we have at + // least 1 space for the \t character + double addlSpace = 3.0 * space - std::fmod( xOffset, 4.0 * space ); // Add the remaining space (between 0 and 3 spaces) + // The fourth space is added by the 'dd' character xOffset += addlSpace; glyphSize = baseGlyphSize; @@ -496,8 +501,8 @@ VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, const VECT // The choice of spaces is somewhat arbitrary but sufficient for aligning text if( *it == '\t' ) { - double fourSpaces = 4.0 * m_glyphBoundingBoxes[0].GetEnd().x; - double addlSpace = fourSpaces - std::fmod( curX, fourSpaces ); + double spaces = m_glyphBoundingBoxes[0].GetEnd().x; + double addlSpace = 3.0 * spaces - std::fmod( curX, 4.0 * spaces ); // Add the remaining space (between 0 and 3 spaces) curX += addlSpace;