3 #include "deps/stb_truetype/stb_truetype.h"
5 #include "generic/managed.h"
6 #include "generic/identifiable.h"
10 struct stbtt_fontinfo;
24 uint16_t x0, y0, x1, y1;
25 float xoff, yoff, xadvance;
40 constexpr
const char* font_weight_name(FontWeight weight) {
41 return (weight == FONT_WEIGHT_NORMAL) ?
"Regular": (weight == FONT_WEIGHT_BOLD) ?
"Bold" : (weight == FONT_WEIGHT_BLACK) ?
"Black" :
"Light";
44 constexpr
const char* font_style_name(FontStyle style) {
45 return (style == FONT_STYLE_NORMAL) ?
"Normal" :
"Italic";
57 static std::string generate_name(
const std::string& family,
const uint16_t& size, FontWeight weight, FontStyle style) {
58 return family +
"-" + font_weight_name(weight) +
"-" + font_style_name(style) +
"-" + smlt::to_string(size);
65 bool is_valid()
const {
return bool(info_) && texture_; }
66 TexturePtr texture()
const;
67 MaterialPtr material()
const;
69 std::pair<Vec2, Vec2> texture_coordinates_for_character(char32_t c);
70 uint16_t character_width(char32_t ch);
71 uint16_t character_height(char32_t ch);
72 float character_advance(char32_t ch, char32_t next);
73 std::pair<int16_t, int16_t> character_offset(char32_t ch);
75 uint16_t size()
const {
return font_size_; }
77 int16_t ascent()
const;
78 int16_t descent()
const;
79 int16_t line_gap()
const;
83 uint16_t page_width(
char ch);
84 uint16_t page_height(
char ch);
86 uint16_t font_size_ = 0;
89 int16_t line_gap_ = 0;
94 float page_width_ = 0;
95 float page_height_ = 0;
97 std::unique_ptr<stbtt_fontinfo> info_;
98 std::vector<CharInfo> char_data_;
101 MaterialPtr material_;