66 lines
1.5 KiB
C
66 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 size;
|
|
f32 ascent;
|
|
f32 descent;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Run types
|
|
|
|
Struct(F_RunRect)
|
|
{
|
|
Vec2 offset; /* Vector from baseline offset to top left of glyph rect */
|
|
f32 pos; /* Horizontal distance from start of baseline */
|
|
f32 advance;
|
|
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 */
|
|
u32 count;
|
|
F_RunRect *rects;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Font load job
|
|
|
|
JobDecl(F_Load, { AC_Asset *asset; f32 size; ResourceKey resource; });
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Font load operations
|
|
|
|
AC_Asset *F_LoadAsset(ResourceKey resource, f32 size, b32 wait);
|
|
F_Font *F_LoadFontAsync(ResourceKey resource, f32 size);
|
|
F_Font *F_LoadFontWait(ResourceKey resource, f32 size);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Run operations
|
|
|
|
F_Glyph F_GlyphFromCodepoint(F_Font *font, u32 codepoint);
|
|
F_Run F_RunFromString(Arena *arena, F_Font *font, String str);
|