mirror of
https://github.com/Ed94/VEFontCache-Odin.git
synced 2025-08-05 14:42:42 -07:00
Prepping to start getting freetype working (2)
This commit is contained in:
@@ -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 )
|
||||
|
@@ -32,7 +32,6 @@ Entry_Default :: Entry {
|
||||
Context :: struct {
|
||||
backing : Allocator,
|
||||
|
||||
parser_kind : ParserKind,
|
||||
parser_ctx : ParserContext,
|
||||
shaper_ctx : ShaperContext,
|
||||
|
||||
@@ -267,7 +266,7 @@ startup :: proc( ctx : ^Context, parser_kind : ParserKind,
|
||||
assert( error == .None, "VEFontCache.init : Failed to allocate vertices array for clear_draw_list" )
|
||||
}
|
||||
|
||||
parser_init( & parser_ctx )
|
||||
parser_init( & parser_ctx, parser_kind )
|
||||
shaper_init( & shaper_ctx )
|
||||
}
|
||||
|
||||
@@ -355,10 +354,7 @@ load_font :: proc( ctx : ^Context, label : string, data : []byte, size_px : f32,
|
||||
used = true
|
||||
|
||||
parser_info = parser_load_font( & parser_ctx, label, data )
|
||||
// assert( parser_info != nil, "VEFontCache.load_font: Failed to load font info from parser" )
|
||||
|
||||
shaper_info = shaper_load_font( & shaper_ctx, label, data, transmute(rawptr) id )
|
||||
// assert( shaper_info != nil, "VEFontCache.load_font: Failed to load font from shaper")
|
||||
|
||||
size = size_px
|
||||
size_scale = size_px < 0.0 ? \
|
||||
|
Reference in New Issue
Block a user