power_play/src/font/font.h
2025-10-23 03:03:12 -05:00

65 lines
1.5 KiB
C

////////////////////////////////////////////////////////////
//~ Font types
#define F_LookupTableSize (256)
Struct(F_Glyph)
{
i32 advance;
Vec2 baseline_offset;
Vec2I32 atlas_p0;
Vec2I32 atlas_p1;
};
Struct(F_Font)
{
GPU_Resource *texture;
u32 image_width;
u32 image_height;
u16 glyphs_count;
F_Glyph *glyphs;
u16 *lookup;
/* Metrics */
f32 point_size;
f32 ascent;
f32 descent;
};
////////////////////////////////////////////////////////////
//~ Run types
Struct(F_RunRect)
{
Vec2 baseline_start_offset; /* Vector from start of baseline to top left of rect */
Vec2I32 atlas_p0;
Vec2I32 atlas_p1;
};
Struct(F_Run)
{
Vec2 p0; /* Start of baseline to top-left-most rect */
Vec2 p1; /* Start of baseline to bottom-right-most rect corner */
f32 baseline_length;
u32 count;
F_RunRect *rects;
};
////////////////////////////////////////////////////////////
//~ Font load job
JobDecl(F_Load, { AC_Asset *asset; f32 point_size; Resource resource; });
////////////////////////////////////////////////////////////
//~ Font load operations
AC_Asset *F_LoadAsset(Resource resource, f32 point_size, b32 wait);
F_Font *F_LoadFontAsync(Resource resource, f32 point_size);
F_Font *F_LoadFontWait(Resource resource, f32 point_size);
////////////////////////////////////////////////////////////
//~ Run operations
F_Glyph F_GlyphFromCodepoint(F_Font *font, u32 codepoint);
F_Run F_RunFromString(Arena *arena, F_Font *font, String str);