From 4cbf0a6811293c61e11f740e98af932f4dfb2ae2 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 1 Feb 2021 02:34:26 +0100 Subject: [PATCH] Change font advance from int to uint --- inferno/src/inferno/render/font.cpp | 7 +++++-- inferno/src/inferno/render/font.h | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/inferno/src/inferno/render/font.cpp b/inferno/src/inferno/render/font.cpp index 75207d0..2b0afa4 100644 --- a/inferno/src/inferno/render/font.cpp +++ b/inferno/src/inferno/render/font.cpp @@ -1,4 +1,4 @@ -#include +#include // std::numeric_limits #include // std::getline #include "inferno/assert.h" @@ -31,11 +31,14 @@ namespace Inferno { const std::vector data = findColumns(line); unsigned char id = std::stoi(findValue("id", data)); + unsigned long advance = std::stoul(findValue("xadvance", data)); + ASSERT(advance <= std::numeric_limits::max(), "Font file xadvance is not in uint32_t range on line \n'{}'", line); + Character character = { { std::stoi(findValue("x", data)), std::stoi(findValue("y", data)) }, { std::stoi(findValue("width", data)), std::stoi(findValue("height", data)) }, { std::stoi(findValue("xoffset", data)), std::stoi(findValue("yoffset", data)) }, - std::stoi(findValue("xadvance", data)) + static_cast(advance) }; m_characterList.emplace(id, std::make_shared(character)); } diff --git a/inferno/src/inferno/render/font.h b/inferno/src/inferno/render/font.h index 2d15d75..3010b35 100644 --- a/inferno/src/inferno/render/font.h +++ b/inferno/src/inferno/render/font.h @@ -1,7 +1,7 @@ #ifndef FONT_H #define FONT_H -#include // int32_t +#include // uint32_t #include // std::shared_ptr #include // std::string #include // std::unordered_map @@ -16,10 +16,10 @@ namespace Inferno { class Texture; struct Character { - glm::ivec2 position; // Position - glm::ivec2 size; // Width/height - glm::ivec2 offset; // Offset from baseline to left / top of glyph - int32_t advance; // Amount to advance to next glyph + glm::ivec2 position; // Position + glm::ivec2 size; // Width/height + glm::ivec2 offset; // Offset from baseline to left / top of glyph + uint32_t advance; // Amount to advance to next glyph }; // -----------------------------------------