From afea4f34dbd0bf5a6f2bc692186d046afcf87b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Feb 2013 16:48:22 +0100 Subject: [PATCH] Text: proper UTF-8 support in Font::prerender(). --- src/Text/Font.cpp | 10 ++++++++-- src/Text/Font.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index a2d02e97a..cffabf54b 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -19,6 +19,7 @@ #include #include FT_FREETYPE_H #include +#include #include "Extensions.h" #include "Image.h" @@ -62,8 +63,13 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { /** @bug Crash when atlas is too small */ /* Get character codes from string */ - /** @todo proper UTF-8 decoding */ - std::vector charCodes(characters.begin(), characters.end()); + std::vector charCodes; + charCodes.reserve(characters.size()); + for(std::size_t i = 0; i != characters.size(); ) { + std::uint32_t codepoint; + std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(characters, i); + charCodes.push_back(codepoint); + } /* Get character indices */ std::vector charIndices; diff --git a/src/Text/Font.h b/src/Text/Font.h index 07cc72761..1c12d55f2 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -86,7 +86,7 @@ class MAGNUM_TEXT_EXPORT Font { /** * @brief Prerender given character set - * @param characters Characters to render + * @param characters UTF-8 characters to render * @param atlasSize Size of resulting atlas * * Creates new atlas with prerendered characters, replacing the