From 69c69e8b33ab83d7e6a6f06f3691f3bccf413f4c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 22 Aug 2022 19:18:37 +0100 Subject: Use utf8_string_view for processing text to renderings --- ui/font.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'ui/font.cpp') diff --git a/ui/font.cpp b/ui/font.cpp index 0e251ea..fc66d52 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -68,13 +68,12 @@ Font::Font(std::filesystem::path p, unsigned s) : path {std::move(p)}, size {get } void -Font::generateChars(const std::string_view chars) const +Font::generateChars(const utf8_string_view chars) const { std::optional ft; std::optional face; - for (auto c = &chars.front(); c <= &chars.back(); c = next_char(c)) { - const auto codepoint = get_codepoint(c); + for (auto codepoint : chars) { if (charsData.find(codepoint) == charsData.end()) { if (!ft) { ft.emplace(); @@ -148,7 +147,7 @@ Font::getTextureSize(unsigned int height) } Font::TextureQuads -Font::render(const std::string_view chars) const +Font::render(const utf8_string_view chars) const { constexpr static const std::array, 4> C {{ {{0, 0}, {0, 1}}, @@ -161,12 +160,12 @@ Font::render(const std::string_view chars) const glm::vec2 pos {}; TextureQuads out; - for (auto c = chars.data(); c <= &chars.back(); c = next_char(c)) { - if (isspace(*c)) { + for (auto codepoint : chars) { + if (std::isspace(static_cast(codepoint))) { pos.x += static_cast(size.y) / 4.F; continue; } - const auto & ch = charsData.at(get_codepoint(c)); + const auto & ch = charsData.at(codepoint); if (!ch.advance) { continue; } -- cgit v1.2.3