From cc2eac41bc091b685d1c5a76d41ec3c2893f314d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 13:25:41 +0100 Subject: [PATCH] Text: removing duplicate glyphs in Font::prerender(). --- src/Text/Font.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index de8627bee..2bdfce706 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -15,6 +15,7 @@ #include "Font.h" +#include #include #include FT_FREETYPE_H #include @@ -49,7 +50,6 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { glyphs.clear(); /** @bug Crash when atlas is too small */ - /** @todo Get rid of duplicate characters */ /* Get character codes from string */ /** @todo proper UTF-8 decoding */ @@ -61,6 +61,10 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { for(std::uint32_t charCode: charCodes) charIndices.push_back(FT_Get_Char_Index(_ftFont, charCode)); + /* Remove duplicates (e.g. uppercase and lowercase mapped to same glyph) */ + std::sort(charIndices.begin(), charIndices.end()); + charIndices.erase(std::unique(charIndices.begin(), charIndices.end()), charIndices.end()); + /* Sizes of all characters */ std::vector charSizes; charSizes.reserve(charIndices.size());