1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

TextLayout: Skip whitespace tokens in TokenList::createLayout() to fix misalignment when using horizontally centred justification

This commit is contained in:
ed 2021-07-07 09:40:40 +01:00
parent 09c06fb946
commit e1366361ed

View file

@ -354,31 +354,30 @@ namespace TextLayoutHelpers
if (newGlyphs.size() > 0)
{
currentRun->glyphs.ensureStorageAllocated (currentRun->glyphs.size() + newGlyphs.size());
auto tokenOrigin = t.area.getPosition().translated (0, t.font.getAscent());
if (needToSetLineOrigin)
if (! t.isWhitespace && ! t.isNewLine)
{
needToSetLineOrigin = false;
currentLine->lineOrigin = tokenOrigin;
}
currentRun->glyphs.ensureStorageAllocated (currentRun->glyphs.size() + newGlyphs.size());
auto tokenOrigin = t.area.getPosition().translated (0, t.font.getAscent());
auto glyphOffset = tokenOrigin - currentLine->lineOrigin;
if (needToSetLineOrigin)
{
needToSetLineOrigin = false;
currentLine->lineOrigin = tokenOrigin;
}
for (int j = 0; j < newGlyphs.size(); ++j)
{
auto x = xOffsets.getUnchecked (j);
currentRun->glyphs.add (TextLayout::Glyph (newGlyphs.getUnchecked(j),
glyphOffset.translated (x, 0),
xOffsets.getUnchecked (j + 1) - x));
auto glyphOffset = tokenOrigin - currentLine->lineOrigin;
for (int j = 0; j < newGlyphs.size(); ++j)
{
auto x = xOffsets.getUnchecked (j);
currentRun->glyphs.add (TextLayout::Glyph (newGlyphs.getUnchecked (j),
glyphOffset.translated (x, 0),
xOffsets.getUnchecked (j + 1) - x));
}
}
charPosition += newGlyphs.size();
}
else if (t.isWhitespace || t.isNewLine)
{
++charPosition;
}
if (auto* nextToken = tokens[i + 1])
{