Make sure spaces at start of line get accounted for.

Fixes https://gitlab.com/kicad/code/kicad/issues/11276
This commit is contained in:
Jeff Young 2022-03-30 14:25:34 +01:00
parent 3da47e6123
commit 4424865577
1 changed files with 19 additions and 21 deletions

View File

@ -197,7 +197,8 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* a
{
VECTOR2I nextPosition = aPosition;
if( aNode ) {
if( aNode )
{
TEXT_STYLE_FLAGS textStyle = aTextStyle;
if( !aNode->is_root() )
@ -444,6 +445,7 @@ void FONT::LinebreakText( wxString& aText, int aColumnWidth, const VECTOR2I& aSi
for( size_t ii = 0; ii < textLines.Count(); ++ii )
{
bool virginLine = true;
int lineWidth = 0;
std::vector<std::pair<wxString, int>> words;
@ -451,32 +453,28 @@ void FONT::LinebreakText( wxString& aText, int aColumnWidth, const VECTOR2I& aSi
for( size_t jj = 0; jj < words.size(); /* advance in loop */ )
{
if( lineWidth == 0
|| lineWidth + spaceWidth + words[jj].second < aColumnWidth - aThickness )
if( virginLine )
{
if( lineWidth > 0 )
{
aText += " ";
lineWidth += spaceWidth;
// First word is always placed, even when wider than columnWidth.
aText += words[jj].first;
lineWidth += words[jj].second;
jj++;
virginLine = false;
}
}
else if( lineWidth > 0 )
else if( lineWidth + spaceWidth + words[jj].second < aColumnWidth - aThickness )
{
aText += '\n';
lineWidth = 0;
continue;
aText += " " + words[jj].first;
lineWidth += spaceWidth + words[jj].second;
jj++;
}
else
{
// TODO: Would we want to further split the words into characters when it doesn't fit
// in the column width? For now just return the full word even if it doesn't fit
// to avoid an infinite loop.
aText += '\n';
lineWidth = 0;
virginLine = true;
}
aText += words[jj].first;
lineWidth += words[jj].second;
jj++;
}
// Add the newlines back onto the string