From 5461227a0421eadfdac4b5ffb2a9d98d47fec2f2 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Fri, 28 Jun 2024 18:00:18 -0400 Subject: [PATCH] some cleanup and changes to get_font_vertical_metrics --- VEFontCache.odin | 8 ++++-- atlas.odin | 66 ------------------------------------------------ docs/Readme.md | 2 ++ draw.odin | 28 -------------------- 4 files changed, 8 insertions(+), 96 deletions(-) diff --git a/VEFontCache.odin b/VEFontCache.odin index 7dba58f..d6bff85 100644 --- a/VEFontCache.odin +++ b/VEFontCache.odin @@ -486,13 +486,17 @@ measure_text_size :: proc( ctx : ^Context, font : FontID, text_utf8 : string ) - 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( font >= 0 && int(font) < len(ctx.entries) ) 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 } diff --git a/atlas.odin b/atlas.odin index c20a0fb..dd942ef 100644 --- a/atlas.odin +++ b/atlas.odin @@ -86,72 +86,6 @@ atlas_bbox :: proc( atlas : ^Atlas, region : AtlasRegionKind, local_idx : i32 ) 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 ) -> (region_kind : AtlasRegionKind, region : ^AtlasRegion, over_sample : Vec2) { diff --git a/docs/Readme.md b/docs/Readme.md index 7a3c91a..010f9ce 100644 --- a/docs/Readme.md +++ b/docs/Readme.md @@ -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 Initializes a provided context. diff --git a/draw.odin b/draw.odin index 845311e..1e8ad8c 100644 --- a/draw.odin +++ b/draw.odin @@ -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 merge_draw_list :: proc( dst, src : ^DrawList ) {