Make sure spaces at start of line get accounted for.
Fixes https://gitlab.com/kicad/code/kicad/issues/11276
This commit is contained in:
parent
3da47e6123
commit
4424865577
|
@ -197,7 +197,8 @@ VECTOR2I drawMarkup( BOX2I* aBoundingBox, std::vector<std::unique_ptr<GLYPH>>* a
|
||||||
{
|
{
|
||||||
VECTOR2I nextPosition = aPosition;
|
VECTOR2I nextPosition = aPosition;
|
||||||
|
|
||||||
if( aNode ) {
|
if( aNode )
|
||||||
|
{
|
||||||
TEXT_STYLE_FLAGS textStyle = aTextStyle;
|
TEXT_STYLE_FLAGS textStyle = aTextStyle;
|
||||||
|
|
||||||
if( !aNode->is_root() )
|
if( !aNode->is_root() )
|
||||||
|
@ -444,39 +445,36 @@ void FONT::LinebreakText( wxString& aText, int aColumnWidth, const VECTOR2I& aSi
|
||||||
|
|
||||||
for( size_t ii = 0; ii < textLines.Count(); ++ii )
|
for( size_t ii = 0; ii < textLines.Count(); ++ii )
|
||||||
{
|
{
|
||||||
int lineWidth = 0;
|
bool virginLine = true;
|
||||||
|
int lineWidth = 0;
|
||||||
std::vector<std::pair<wxString, int>> words;
|
std::vector<std::pair<wxString, int>> words;
|
||||||
|
|
||||||
wordbreakMarkup( &words, textLines[ii], aSize, textStyle );
|
wordbreakMarkup( &words, textLines[ii], aSize, textStyle );
|
||||||
|
|
||||||
for( size_t jj = 0; jj < words.size(); /* advance in loop */ )
|
for( size_t jj = 0; jj < words.size(); /* advance in loop */ )
|
||||||
{
|
{
|
||||||
if( lineWidth == 0
|
if( virginLine )
|
||||||
|| lineWidth + spaceWidth + words[jj].second < aColumnWidth - aThickness )
|
|
||||||
{
|
{
|
||||||
if( lineWidth > 0 )
|
// First word is always placed, even when wider than columnWidth.
|
||||||
{
|
aText += words[jj].first;
|
||||||
aText += " ";
|
lineWidth += words[jj].second;
|
||||||
lineWidth += spaceWidth;
|
jj++;
|
||||||
}
|
|
||||||
|
virginLine = false;
|
||||||
}
|
}
|
||||||
else if( lineWidth > 0 )
|
else if( lineWidth + spaceWidth + words[jj].second < aColumnWidth - aThickness )
|
||||||
{
|
{
|
||||||
aText += '\n';
|
aText += " " + words[jj].first;
|
||||||
lineWidth = 0;
|
lineWidth += spaceWidth + words[jj].second;
|
||||||
continue;
|
jj++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Would we want to further split the words into characters when it doesn't fit
|
aText += '\n';
|
||||||
// in the column width? For now just return the full word even if it doesn't fit
|
|
||||||
// to avoid an infinite loop.
|
lineWidth = 0;
|
||||||
|
virginLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
aText += words[jj].first;
|
|
||||||
lineWidth += words[jj].second;
|
|
||||||
|
|
||||||
jj++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the newlines back onto the string
|
// Add the newlines back onto the string
|
||||||
|
|
Loading…
Reference in New Issue