2024-03-31 10:11:22 +00:00
|
|
|
#pragma once
|
2023-05-14 13:40:16 +00:00
|
|
|
|
|
|
|
#include <string>
|
2023-05-14 21:05:22 +00:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <stb_truetype.h>
|
2023-05-14 13:40:16 +00:00
|
|
|
|
|
|
|
namespace engine {
|
|
|
|
|
|
|
|
class Font {
|
2024-06-01 22:03:39 +00:00
|
|
|
std::unique_ptr<stbtt_fontinfo> m_font_info{};
|
|
|
|
std::unique_ptr<std::vector<uint8_t>> m_font_buffer{};
|
|
|
|
std::map<int, int> m_unicode_to_glyph{};
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Font(const std::string& path);
|
2024-03-31 10:11:22 +00:00
|
|
|
Font(const Font&) = delete;
|
|
|
|
|
2024-06-01 22:03:39 +00:00
|
|
|
~Font();
|
|
|
|
|
|
|
|
Font& operator=(const Font&) = delete;
|
2023-05-14 13:40:16 +00:00
|
|
|
|
2024-06-01 22:03:39 +00:00
|
|
|
std::unique_ptr<std::vector<uint8_t>> getTextBitmap(const std::string& text, float height_px, int& width_out, int& height_out);
|
2024-03-31 10:11:22 +00:00
|
|
|
|
2024-06-01 22:03:39 +00:00
|
|
|
private:
|
|
|
|
int getGlyphIndex(int unicode_codepoint);
|
2024-03-31 10:11:22 +00:00
|
|
|
};
|
2023-05-14 13:40:16 +00:00
|
|
|
|
2024-03-31 10:11:22 +00:00
|
|
|
} // namespace engine
|