Browse Source

Change font advance from int to uint

master
Riyyi 3 years ago
parent
commit
4cbf0a6811
  1. 7
      inferno/src/inferno/render/font.cpp
  2. 10
      inferno/src/inferno/render/font.h

7
inferno/src/inferno/render/font.cpp

@ -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));
}

10
inferno/src/inferno/render/font.h

@ -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
};
// -----------------------------------------

Loading…
Cancel
Save