Prepping to start getting freetype working (2)

This commit is contained in:
2024-07-01 20:30:36 -04:00
parent b67c1567d2
commit 70b2d1fe55
5 changed files with 34 additions and 21 deletions

View File

@@ -56,9 +56,9 @@ ParserContext :: struct {
// fonts : HMapChained(ParserFontInfo),
}
parser_init :: proc( ctx : ^ParserContext )
parser_init :: proc( ctx : ^ParserContext, kind : ParserKind )
{
switch ctx.kind
switch kind
{
case .Freetype:
result := freetype.init_free_type( & ctx.ft_library )
@@ -68,6 +68,8 @@ parser_init :: proc( ctx : ^ParserContext )
// Do nothing intentional
}
ctx.kind = kind
// error : AllocatorError
// ctx.fonts, error = make( HMapChained(ParserFontInfo), 256 )
// assert( error == .None, "VEFontCache.parser_init: Failed to allocate fonts array" )
@@ -99,6 +101,7 @@ parser_load_font :: proc( ctx : ^ParserContext, label : string, data : []byte )
font.label = label
font.data = data
font.kind = ctx.kind
return
}
@@ -190,6 +193,19 @@ parser_get_font_vertical_metrics :: #force_inline proc "contextless" ( font : ^P
switch font.kind
{
case .Freetype:
info := font.freetype_info
ascent = i32(info.ascender)
descent = i32(info.descender)
line_gap = i32(info.height) - (ascent - descent)
// FreeType stores these values in font units, so we need to convert them to pixels
units_per_em := i32(info.units_per_em)
if units_per_em != 0 {
ascent = (ascent * i32(info.size.metrics.y_ppem)) / units_per_em
descent = (descent * i32(info.size.metrics.y_ppem)) / units_per_em
line_gap = (line_gap * i32(info.size.metrics.y_ppem)) / units_per_em
}
case .STB_TrueType:
stbtt.GetFontVMetrics( & font.stbtt_info, & ascent, & descent, & line_gap )