diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index 11b73b388..3d5d83983 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -341,6 +341,27 @@ float Font::getKerning(uint32 leftglyph, uint32 rightglyph) return k; } +void Font::codepointsFromString(const std::string &text, Codepoints &codepoints) +{ + codepoints.reserve(text.size()); + + try + { + utf8::iterator i(text.begin(), text.begin(), text.end()); + utf8::iterator end(text.end(), text.begin(), text.end()); + + while (i != end) + { + uint32 g = *i++; + codepoints.push_back(g); + } + } + catch (utf8::exception &e) + { + throw love::Exception("UTF-8 decoding error: %s", e.what()); + } +} + float Font::getHeight() const { return (float) height; @@ -460,24 +481,7 @@ std::vector Font::generateVertices(const Codepoints &codepoin std::vector Font::generateVertices(const std::string &text, std::vector &vertices, float extra_spacing, Vector offset, TextInfo *info) { Codepoints codepoints; - codepoints.reserve(text.size()); - - try - { - utf8::iterator i(text.begin(), text.begin(), text.end()); - utf8::iterator end(text.end(), text.begin(), text.end()); - - while (i != end) - { - uint32 g = *i++; - codepoints.push_back(g); - } - } - catch (utf8::exception &e) - { - throw love::Exception("UTF-8 decoding error: %s", e.what()); - } - + codepointsFromString(text, codepoints); return generateVertices(codepoints, vertices, extra_spacing, offset, info); } @@ -698,7 +702,8 @@ void Font::getWrap(const std::string &text, float wraplimit, std::vectorpush_back(width); prevglyph = 0; // Reset kerning information. - width = 0.0f; + width = widthbeforelastspace = widthoftrailingspace = 0.0f; wline.clear(); lastspaceit = end; continue; } + if (prevglyph != ' ' && c == ' ') + widthbeforelastspace = width; + width = newwidth; prevglyph = c; @@ -760,9 +770,11 @@ void Font::getWrap(const std::string &text, float wraplimit, std::vectorpush_back(width); + linewidths->push_back(width - widthoftrailingspace); } } diff --git a/src/modules/graphics/opengl/Font.h b/src/modules/graphics/opengl/Font.h index fb94b7e53..926eb5d0c 100644 --- a/src/modules/graphics/opengl/Font.h +++ b/src/modules/graphics/opengl/Font.h @@ -205,6 +205,7 @@ private: const Glyph &addGlyph(uint32 glyph); const Glyph &findGlyph(uint32 glyph); float getKerning(uint32 leftglyph, uint32 rightglyph); + void codepointsFromString(const std::string &str, Codepoints &codepoints); void printv(const Matrix4 &t, const std::vector &drawcommands, const std::vector &vertices); std::vector> rasterizers;