aboutsummaryrefslogtreecommitdiff
path: root/src/common/Font.hpp
diff options
context:
space:
mode:
authorfschildt <florian.schildt@protonmail.com>2025-09-27 12:40:31 +0200
committerfschildt <florian.schildt@protonmail.com>2025-09-27 12:40:31 +0200
commitdbb42e741d29ab213f2a51fc8d9568c02f844647 (patch)
tree8f8e59c70b79082b0ee1410d8a891462e6a0f915 /src/common/Font.hpp
parentf28e9c3e03a9f94764b3811f7c4aa01991943fc7 (diff)
add font glyph drawing
Diffstat (limited to 'src/common/Font.hpp')
-rw-r--r--src/common/Font.hpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/common/Font.hpp b/src/common/Font.hpp
new file mode 100644
index 0000000..a594add
--- /dev/null
+++ b/src/common/Font.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <filesystem>
+#include <stb_truetype.h>
+
+
+struct MonoBitmap {
+ int32_t width;
+ int32_t height;
+ std::unique_ptr<uint8_t> pixels;
+};
+
+
+struct Glyph {
+ int32_t xoff;
+ int32_t yoff;
+ int32_t xadvance;
+ MonoBitmap bitmap;
+};
+
+
+class Font {
+public:
+ ~Font();
+
+ bool Init(const char* path, int font_size);
+ void Deinit();
+
+ void LoadGlyph(Glyph& glyph, uint32_t codepoint);
+
+
+private:
+ const char* m_file_content = nullptr;
+
+ float m_font_scale;
+ int m_font_baseline;
+ int m_font_yadvance;
+
+ stbtt_fontinfo m_font_info;
+ Glyph m_glyphs['~' - ' ' + 1];
+};
+
+