mirror of
https://github.com/love2d/love.git
synced 2026-08-20 12:40:20 +02:00
Improve justified text alignment
This commit is contained in:
@@ -49,6 +49,7 @@ void GenericShaper::computeGlyphPositions(const ColoredCodepoints &codepoints, R
|
|||||||
|
|
||||||
// Spacing counter and newline handling.
|
// Spacing counter and newline handling.
|
||||||
Vector2 curpos = offset;
|
Vector2 curpos = offset;
|
||||||
|
float spacingremainder = 0;
|
||||||
|
|
||||||
float maxwidth = 0;
|
float maxwidth = 0;
|
||||||
uint32 prevglyph = 0;
|
uint32 prevglyph = 0;
|
||||||
@@ -125,7 +126,11 @@ void GenericShaper::computeGlyphPositions(const ColoredCodepoints &codepoints, R
|
|||||||
|
|
||||||
// Account for extra spacing given to space characters.
|
// Account for extra spacing given to space characters.
|
||||||
if (g == ' ' && extraspacing != 0.0f)
|
if (g == ' ' && extraspacing != 0.0f)
|
||||||
curpos.x += extraspacing;
|
{
|
||||||
|
spacingremainder += fmod(extraspacing, 1);
|
||||||
|
curpos.x += floorf(extraspacing) + floorf(spacingremainder);
|
||||||
|
spacingremainder = fmod(spacingremainder, 1);
|
||||||
|
}
|
||||||
|
|
||||||
prevglyph = g;
|
prevglyph = g;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ void HarfbuzzShaper::computeGlyphPositions(const ColoredCodepoints &codepoints,
|
|||||||
|
|
||||||
offset.y += getBaseline();
|
offset.y += getBaseline();
|
||||||
Vector2 curpos = offset;
|
Vector2 curpos = offset;
|
||||||
|
float spacingremainder = 0;
|
||||||
|
|
||||||
int colorindex = 0;
|
int colorindex = 0;
|
||||||
int ncolors = (int)codepoints.colors.size();
|
int ncolors = (int)codepoints.colors.size();
|
||||||
@@ -312,7 +313,11 @@ void HarfbuzzShaper::computeGlyphPositions(const ColoredCodepoints &codepoints,
|
|||||||
|
|
||||||
// Account for extra spacing given to space characters.
|
// Account for extra spacing given to space characters.
|
||||||
if (clustercodepoint == ' ' && extraspacing != 0.0f)
|
if (clustercodepoint == ' ' && extraspacing != 0.0f)
|
||||||
curpos.x += extraspacing;
|
{
|
||||||
|
spacingremainder += fmod(extraspacing, 1);
|
||||||
|
curpos.x += floorf(extraspacing) + floorf(spacingremainder);
|
||||||
|
spacingremainder = fmod(spacingremainder, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ std::vector<Font::DrawCommand> Font::generateVerticesFormatted(const love::font:
|
|||||||
auto end = start + range.getSize();
|
auto end = start + range.getSize();
|
||||||
float numspaces = std::count(start, end, ' ');
|
float numspaces = std::count(start, end, ' ');
|
||||||
if (width < wrap && numspaces >= 1)
|
if (width < wrap && numspaces >= 1)
|
||||||
extraspacing = floorf((wrap - width) / numspaces);
|
extraspacing = (wrap - width) / (numspaces - 1);
|
||||||
else
|
else
|
||||||
extraspacing = 0.0f;
|
extraspacing = 0.0f;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user