Allow multiple fonts

This commit is contained in:
Krzosa Karol
2025-12-01 09:05:06 +01:00
parent c2f4686bc4
commit e34c2b0cef
12 changed files with 102 additions and 112 deletions

View File

@@ -16,6 +16,9 @@ struct Font {
float ascent;
float line_gap;
Int line_spacing;
Int char_spacing;
Rect2 white_texture_bounding_box;
};
@@ -92,6 +95,16 @@ Rect2 PackBitmap(Atlas *atlas, uint8_t *bitmap, int width, int height) {
return result;
}
Glyph *GetGlyph(Font *font, uint32_t codepoint) {
bool is_in_range = codepoint >= font->first_char && codepoint <= font->last_char;
if (is_in_range) {
uint32_t index = codepoint - font->first_char;
return &font->glyphs[index];
} else {
uint32_t index = '?' - font->first_char;
return &font->glyphs[index];
}
}
Font CreateFont(Atlas *atlas, int32_t size, String path) {
Allocator allocator = GetSystemAllocator();
Scratch scratch;
@@ -143,16 +156,9 @@ Font CreateFont(Atlas *atlas, int32_t size, String path) {
Add(&result.glyphs, glyph);
}
Glyph *g = GetGlyph(&result, '_');
result.char_spacing = (Int)g->xadvance ? (Int)g->xadvance : (Int)g->size.x;
result.line_spacing = (Int)(result.ascent - result.descent + result.line_gap);
return result;
}
Glyph *GetGlyph(Font *font, uint32_t codepoint) {
bool is_in_range = codepoint >= font->first_char && codepoint <= font->last_char;
if (is_in_range) {
uint32_t index = codepoint - font->first_char;
return &font->glyphs[index];
} else {
uint32_t index = '?' - font->first_char;
return &font->glyphs[index];
}
}