From 2be72f6acd24045d294d7ee7bdfddec54564e140 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 31 Aug 2021 10:23:47 +0100 Subject: [PATCH] Partially revert e1366361 This fixes a bug when creating a TextLayout with whitespace at the start of lines. --- .../juce_graphics/fonts/juce_TextLayout.cpp | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index 70547a5645..a0d350ccd7 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -354,26 +354,23 @@ namespace TextLayoutHelpers if (newGlyphs.size() > 0) { - if (! t.isWhitespace && ! t.isNewLine) + currentRun->glyphs.ensureStorageAllocated (currentRun->glyphs.size() + newGlyphs.size()); + auto tokenOrigin = t.area.getPosition().translated (0, t.font.getAscent()); + + if (needToSetLineOrigin) { - currentRun->glyphs.ensureStorageAllocated (currentRun->glyphs.size() + newGlyphs.size()); - auto tokenOrigin = t.area.getPosition().translated (0, t.font.getAscent()); + needToSetLineOrigin = false; + currentLine->lineOrigin = tokenOrigin; + } - if (needToSetLineOrigin) - { - needToSetLineOrigin = false; - currentLine->lineOrigin = tokenOrigin; - } + auto glyphOffset = tokenOrigin - currentLine->lineOrigin; - 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)); - } + 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(); @@ -497,7 +494,7 @@ namespace TextLayoutHelpers for (i = 0; i < tokens.size(); ++i) { - auto& t = *tokens.getUnchecked(i); + auto& t = *tokens.getUnchecked (i); t.area.setPosition (x, y); t.line = totalLines; x += t.area.getWidth();