summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-08-22 19:18:37 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-08-22 19:18:37 +0100
commit69c69e8b33ab83d7e6a6f06f3691f3bccf413f4c (patch)
treeebc5f7be617701a3cb2741e159c93e404a55eb50
parentMake utf8_string_view work on any contiguous collection of chars (diff)
downloadilt-69c69e8b33ab83d7e6a6f06f3691f3bccf413f4c.tar.bz2
ilt-69c69e8b33ab83d7e6a6f06f3691f3bccf413f4c.tar.xz
ilt-69c69e8b33ab83d7e6a6f06f3691f3bccf413f4c.zip
Use utf8_string_view for processing text to renderings
-rw-r--r--ui/font.cpp13
-rw-r--r--ui/font.h7
2 files changed, 10 insertions, 10 deletions
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> ft;
std::optional<Face> 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<std::pair<glm::vec2, glm::vec2>, 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<int>(codepoint))) {
pos.x += static_cast<float>(size.y) / 4.F;
continue;
}
- const auto & ch = charsData.at(get_codepoint(c));
+ const auto & ch = charsData.at(codepoint);
if (!ch.advance) {
continue;
}
diff --git a/ui/font.h b/ui/font.h
index f8a29de..52b92a7 100644
--- a/ui/font.h
+++ b/ui/font.h
@@ -10,6 +10,7 @@
#include <glm/glm.hpp>
#include <map>
#include <string_view>
+#include <unicode.h>
#include <vector>
class Font {
@@ -21,7 +22,7 @@ public:
using Quad = std::array<glm::vec4, 4>;
using Quads = std::vector<Quad>;
using TextureQuads = std::map<GLuint /*textureId*/, Quads>;
- TextureQuads render(const std::string_view text) const;
+ TextureQuads render(const utf8_string_view text) const;
struct CharData {
size_t textureIdx;
@@ -38,12 +39,12 @@ public:
static glm::uvec3 getTextureSize(unsigned int height);
protected:
- void generateChars(const std::string_view text) const;
+ void generateChars(const utf8_string_view text) const;
const CharData getChar(char) const;
std::size_t getTextureWithSpace(unsigned int adv) const;
std::filesystem::path path;
glm::uvec3 size;
- mutable std::map<uint32_t, CharData> charsData;
+ mutable std::map<decltype(get_codepoint(nullptr)), CharData> charsData;
mutable std::vector<FontTexture> fontTextures;
};