5 #include "deps/stb_truetype/stb_truetype.h"
7 #include "generic/managed.h"
8 #include "generic/identifiable.h"
12 struct stbtt_fontinfo;
46 constexpr
const char* font_weight_name(FontWeight weight) {
47 return (weight == FONT_WEIGHT_NORMAL) ?
"Regular": (weight == FONT_WEIGHT_BOLD) ?
"Bold" : (weight == FONT_WEIGHT_BLACK) ?
"Black" :
"Light";
50 constexpr
const char* font_style_name(FontStyle style) {
51 return (style == FONT_STYLE_NORMAL) ?
"Normal" :
"Italic";
63 static std::string generate_name(
const std::string& family,
const uint16_t& size, FontWeight weight, FontStyle style) {
64 return family +
"-" + font_weight_name(weight) +
"-" + font_style_name(style) +
"-" + smlt::to_string(size);
71 bool is_valid()
const {
return bool(info_) && texture_; }
72 TexturePtr texture()
const;
73 MaterialPtr material()
const;
75 std::pair<Vec2, Vec2> char_texcoords(char32_t c)
const;
76 std::pair<Vec2, Vec2> char_corners(char32_t c)
const;
78 uint16_t character_width(char32_t ch);
79 uint16_t character_height(char32_t ch);
80 float character_advance(char32_t ch, char32_t next);
81 Vec2 character_offset(char32_t ch);
83 uint16_t size()
const {
return font_size_; }
85 int16_t ascent()
const;
86 int16_t descent()
const;
87 int16_t line_gap()
const;
91 uint16_t page_width(
char ch)
const;
92 uint16_t page_height(
char ch)
const;
94 uint16_t font_size_ = 0;
97 int16_t line_gap_ = 0;
102 float page_width_ = 0;
103 float page_height_ = 0;
105 std::unique_ptr<stbtt_fontinfo> info_;
106 std::map<char32_t, CharInfo> char_data_;
109 MaterialPtr material_;