6 #include "deps/stb_truetype/stb_truetype.h"
8 #include "generic/managed.h"
9 #include "generic/identifiable.h"
12 #include "utils/limited_vector.h"
18 struct stbtt_fontinfo;
53 constexpr
const char* font_weight_name(FontWeight weight) {
54 return (weight == FONT_WEIGHT_NORMAL) ?
"Regular": (weight == FONT_WEIGHT_BOLD) ?
"Bold" : (weight == FONT_WEIGHT_BLACK) ?
"Black" :
"Light";
57 constexpr
const char* font_style_name(FontStyle style) {
58 return (style == FONT_STYLE_NORMAL) ?
"Normal" :
"Italic";
77 const static std::size_t max_pages = 4;
79 static std::string generate_name(
const std::string& family,
const uint16_t& size, FontWeight weight, FontStyle style) {
80 return family +
"-" + font_weight_name(weight) +
"-" + font_style_name(style) +
"-" + smlt::to_string(size);
85 bool on_init()
override;
87 std::size_t page_count()
const {
91 const FontPage* page(std::size_t i)
const;
93 std::pair<Vec2, Vec2> char_texcoords(char32_t c)
const;
94 std::pair<Vec2, Vec2> char_corners(char32_t c)
const;
96 uint16_t character_width(char32_t ch);
97 uint16_t character_height(char32_t ch);
98 float character_advance(char32_t ch, char32_t next);
99 Vec2 character_offset(char32_t ch);
100 uint16_t character_page(char32_t ch);
102 uint16_t size()
const {
return font_size_; }
104 int16_t ascent()
const;
105 int16_t descent()
const;
106 int16_t line_gap()
const;
110 uint16_t page_width(char16_t ch)
const;
111 uint16_t page_height(char16_t ch)
const;
113 uint16_t font_size_ = 0;
115 int16_t descent_ = 0;
116 int16_t line_gap_ = 0;
119 std::unique_ptr<stbtt_fontinfo> info_;
120 std::map<char16_t, CharInfo> char_data_;