diff options
Diffstat (limited to 'code/amr_fonts.h')
-rw-r--r-- | code/amr_fonts.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/code/amr_fonts.h b/code/amr_fonts.h new file mode 100644 index 0000000..f44893c --- /dev/null +++ b/code/amr_fonts.h @@ -0,0 +1,51 @@ +#ifndef AMR_FONTS_H +#define AMR_FONTS_H + +typedef struct amr_glyph_info { + u32 charset_start_index; + u32 charset_end_index; +} amr_glyph_info; + +typedef struct amr_font_details_debug { + i32 advance; + i32 lsb; + i32 x0, y0, x1, y1; + i32 kern; + f32 lx; + f32 ly; + i32 byte_offset; + i32 baseline; +} debug_font_details; + +typedef struct amr_font_state_debug { + stbtt_fontinfo font_info; +} amr_font_state; +// initialise a font and loads the font in the fontbuffer +// input: +// - font path +// - font buffer, must be initialised by caller +// - size of the font file, must be known beforehand +// output: +// - error code +u32 amr_InitFont(const u8 *FontPath, u8 *FontBuffer, u32 FontFz); +u32 amr_GetGlyphIdFromCodepoint(amr_glyph_info glyph, u32 *GlyphIndexArray, u32 Codepoint); + +u32 amr_InitFont(stbtt_fontinfo *font_info, const char *FontPath, u8 *FontBuffer, u32 FontSz) +{ + PlatformDebugFileRead(FontPath, FontBuffer, FontSz); + if (!stbtt_InitFont(font_info, FontBuffer, 0)) + { + printf("ERROR: failed to read arial font"); + assert(1 == 0); + } + + return 0; +} + +u32 amr_GetGlyphIdFromCodepoint(amr_glyph_info glyph, u32 *GlyphIndexArray, u32 Codepoint) +{ + u32 glyph_id = *(GlyphIndexArray + (Codepoint - glyph.charset_start_index)); + return glyph_id; +} + +#endif |