some cleanup and changes to get_font_vertical_metrics

This commit is contained in:
2024-06-28 18:00:18 -04:00
parent d454778fd6
commit 5461227a04
4 changed files with 8 additions and 96 deletions

View File

@@ -486,13 +486,17 @@ measure_text_size :: proc( ctx : ^Context, font : FontID, text_utf8 : string ) -
return shaped.size return shaped.size
} }
get_font_vertical_metrics :: #force_inline proc ( ctx : ^Context, font : FontID ) -> ( ascent, descent, line_gap : i32 ) get_font_vertical_metrics :: #force_inline proc ( ctx : ^Context, font : FontID ) -> ( ascent, descent, line_gap : f32 )
{ {
assert( ctx != nil ) assert( ctx != nil )
assert( font >= 0 && int(font) < len(ctx.entries) ) assert( font >= 0 && int(font) < len(ctx.entries) )
entry := & ctx.entries[ font ] entry := & ctx.entries[ font ]
ascent, descent, line_gap = parser_get_font_vertical_metrics( & entry.parser_info ) ascent_i32, descent_i32, line_gap_i32 := parser_get_font_vertical_metrics( & entry.parser_info )
ascent = ceil(f32(ascent_i32) * entry.size_scale)
descent = ceil(f32(descent_i32) * entry.size_scale)
line_gap = ceil(f32(line_gap_i32) * entry.size_scale)
return return
} }

View File

@@ -86,72 +86,6 @@ atlas_bbox :: proc( atlas : ^Atlas, region : AtlasRegionKind, local_idx : i32 )
return return
} }
// decide_codepoint_region :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph
// ) -> (region_kind : AtlasRegionKind, region : ^AtlasRegion, over_sample : Vec2)
// {
// if parser_is_glyph_empty( & entry.parser_info, glyph_index ) {
// region_kind = .None
// }
// bounds_0, bounds_1 := parser_get_glyph_box( & entry.parser_info, glyph_index )
// bounds_width := f32(bounds_1.x - bounds_0.x)
// bounds_height := f32(bounds_1.y - bounds_0.y)
// atlas := & ctx.atlas
// glyph_buffer := & ctx.glyph_buffer
// glyph_padding := f32(atlas.glyph_padding) * 2
// bounds_width_scaled := cast(u32) (bounds_width * entry.size_scale + glyph_padding)
// bounds_height_scaled := cast(u32) (bounds_height * entry.size_scale + glyph_padding)
// if bounds_width_scaled <= atlas.region_a.width && bounds_height_scaled <= atlas.region_a.height
// {
// // Region A for small glyphs. These are good for things such as punctuation.
// region_kind = .A
// region = & atlas.region_a
// }
// else if bounds_width_scaled <= atlas.region_b.width && bounds_height_scaled <= atlas.region_b.height
// {
// // Region B for tall glyphs. These are good for things such as european alphabets.
// region_kind = .B
// region = & atlas.region_b
// }
// else if bounds_width_scaled <= atlas.region_c.width && bounds_height_scaled <= atlas.region_c.height
// {
// // Region C for big glyphs. These are good for things such as asian typography.
// region_kind = .C
// region = & atlas.region_c
// }
// else if bounds_width_scaled <= atlas.region_d.width && bounds_height_scaled <= atlas.region_d.height
// {
// // Region D for huge glyphs. These are good for things such as titles and 4k.
// region_kind = .D
// region = & atlas.region_d
// }
// else if bounds_width_scaled <= glyph_buffer.width && bounds_height_scaled <= glyph_buffer.height
// {
// // Region 'E' for massive glyphs. These are rendered uncached and un-oversampled.
// region_kind = .E
// region = nil
// if bounds_width_scaled <= glyph_buffer.width / 2 && bounds_height_scaled <= glyph_buffer.height / 2 {
// over_sample = { 2.0, 2.0 }
// }
// else {
// over_sample = { 1.0, 1.0 }
// }
// return
// }
// else {
// region_kind = .None
// return
// }
// over_sample = glyph_buffer.over_sample
// assert(region != nil)
// return
// }
decide_codepoint_region :: proc(ctx : ^Context, entry : ^Entry, glyph_index : Glyph decide_codepoint_region :: proc(ctx : ^Context, entry : ^Entry, glyph_index : Glyph
) -> (region_kind : AtlasRegionKind, region : ^AtlasRegion, over_sample : Vec2) ) -> (region_kind : AtlasRegionKind, region : ^AtlasRegion, over_sample : Vec2)
{ {

View File

@@ -15,6 +15,8 @@ Freetype implementation supports specifying a FT_Memory handle which is a pointe
}; };
``` ```
This library (seems) to perform best if the text commands are fed in 'whitespace aware chunks', where instead of feeding it entire blobs of text, the user identfies the "words" in the text and feeding the visible and whitespce chunks derived from this to draw_text as separate calls. This improves the caching of the text shapes. The downside is there has to be a time where the text is parsed into tokens beforehand so that the this iteration does not have to occur continously.
### startup ### startup
Initializes a provided context. Initializes a provided context.

View File

@@ -661,34 +661,6 @@ flush_glyph_buffer_to_atlas :: proc( ctx : ^Context )
} }
} }
// flush_glyph_buffer_to_atlas :: proc( ctx : ^Context )
// {
// // profile(#procedure)
// // Flush drawcalls to draw list
// if len(ctx.glyph_buffer.clear_draw_list.calls) > 0 {
// merge_draw_list( & ctx.draw_list, & ctx.glyph_buffer.clear_draw_list)
// clear_draw_list( & ctx.glyph_buffer.clear_draw_list)
// }
// if len(ctx.glyph_buffer.draw_list.calls) > 0 {
// merge_draw_list( & ctx.draw_list, & ctx.glyph_buffer.draw_list)
// clear_draw_list( & ctx.glyph_buffer.draw_list)
// }
// // Clear glyph_update_FBO
// if ctx.glyph_buffer.batch_x != 0
// {
// call := DrawCall {
// pass = .Glyph,
// start_index = 0,
// end_index = 0,
// clear_before_draw = true,
// }
// append( & ctx.draw_list.calls, call)
// ctx.glyph_buffer.batch_x = 0
// }
// }
// ve_fontcache_merge_drawlist // ve_fontcache_merge_drawlist
merge_draw_list :: proc( dst, src : ^DrawList ) merge_draw_list :: proc( dst, src : ^DrawList )
{ {