Change font advance from int to uint

This commit is contained in:
Riyyi
2021-02-01 02:34:26 +01:00
parent 3ce136741d
commit 4cbf0a6811
2 changed files with 10 additions and 7 deletions
+5 -2
View File
@@ -1,4 +1,4 @@
#include <bits/stdint-uintn.h>
#include <limits> // std::numeric_limits
#include <string> // std::getline
#include "inferno/assert.h"
@@ -31,11 +31,14 @@ namespace Inferno {
const std::vector<std::string> data = findColumns(line);
unsigned char id = std::stoi(findValue("id", data));
unsigned long advance = std::stoul(findValue("xadvance", data));
ASSERT(advance <= std::numeric_limits<uint32_t>::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<uint32_t>(advance)
};
m_characterList.emplace(id, std::make_shared<Character>(character));
}
+5 -5
View File
@@ -1,7 +1,7 @@
#ifndef FONT_H
#define FONT_H
#include <cstdint> // int32_t
#include <cstdint> // uint32_t
#include <memory> // std::shared_ptr
#include <string> // std::string
#include <unordered_map> // 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
};
// -----------------------------------------