1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
|