From 4396506e95d7ec28e476e0ba3c697faddd479eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 13 Dec 2013 01:48:02 +0100 Subject: [PATCH] Text: fix rendering of scaled multi-line text. Take text size into account when advancing lines. I would probably not run into this issue if I would visually test this on anything else than unscaled pixel art font. --- src/Text/Renderer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Text/Renderer.cpp b/src/Text/Renderer.cpp index 605ed274e..36d25aa09 100644 --- a/src/Text/Renderer.cpp +++ b/src/Text/Renderer.cpp @@ -58,16 +58,18 @@ struct Vertex { Vector2 position, textureCoordinates; }; -std::tuple, Range2D> renderVerticesInternal(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, const Alignment alignment) { +std::tuple, Range2D> renderVerticesInternal(AbstractFont& font, const GlyphCache& cache, const Float size, const std::string& text, const Alignment alignment) { /* Output data, reserve memory as when the text would be ASCII-only. In reality the actual vertex count will be smaller, but allocating more at once is better than reallocating many times later. */ std::vector vertices; vertices.reserve(text.size()*4); - /* Total rendered bounds, intial line position, last+1 vertex on previous line */ + /* Total rendered bounds, intial line position, line increment, last+1 + vertex on previous line */ Range2D rectangle; Vector2 linePosition; + const Vector2 lineAdvance = Vector2::yAxis(font.lineHeight()*size/font.size()); std::size_t lastLineLastVertex = 0; /* Temp buffer so we don't allocate for each new line */ @@ -146,7 +148,7 @@ std::tuple, Range2D> renderVerticesInternal(AbstractFont& fo /* Move to next line */ } while(prevPos = pos+1, - linePosition -= Vector2::yAxis(font.lineHeight()), + linePosition -= lineAdvance, lastLineLastVertex = vertices.size(), pos != std::string::npos);