diff options
Diffstat (limited to 'src/common/Font.hpp')
| -rw-r--r-- | src/common/Font.hpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/common/Font.hpp b/src/common/Font.hpp index 91afe06..af4ddb5 100644 --- a/src/common/Font.hpp +++ b/src/common/Font.hpp @@ -1,10 +1,12 @@ #pragma once -#include <filesystem> +#include <common/defs.hpp> #include <stb_truetype.h> +#include <memory> -struct MonoBitmap { + +struct AlphaBitmap { int32_t w; int32_t h; std::unique_ptr<uint8_t> pixels; @@ -15,7 +17,7 @@ struct Glyph { int32_t xoff; int32_t yoff; int32_t xadvance; - MonoBitmap bitmap; + AlphaBitmap bitmap; }; @@ -24,12 +26,22 @@ public: ~Font(); bool Init(const char* path, int font_size); - void Deinit(); + AlphaBitmap& GetAlphaBitmap(char32_t c); + Glyph& GetGlyph(char32_t c); + + - void LoadGlyph(Glyph& glyph, uint32_t codepoint); +private: + bool ReadFile(const char* path); + void LoadGlyph(Glyph& glyph, char32_t c); private: + static constexpr char first_ascii_ch = ' '; + static constexpr char last_ascii_ch = '~'; + static constexpr char ascii_glyph_count = last_ascii_ch - first_ascii_ch + 1; + + const char* m_file_content = nullptr; float m_font_scale; @@ -37,7 +49,8 @@ private: int m_font_yadvance; stbtt_fontinfo m_font_info; - Glyph m_glyphs['~' - ' ' + 1]; + Glyph m_glyphs[ascii_glyph_count]; + Glyph m_fail_glyph; }; |
