From 488e5ba67f71d9b25f7ff5dec2096762f23a8337 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 9 Jan 2025 23:53:59 -0500 Subject: [PATCH] shaper_shape_text_latin was not resolving atlas info and bounds + lru poollist touchup --- code/font/vefontcache/LRU.odin | 3 +-- code/font/vefontcache/shaper.odin | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/code/font/vefontcache/LRU.odin b/code/font/vefontcache/LRU.odin index 4cc2739..b3f6223 100644 --- a/code/font/vefontcache/LRU.odin +++ b/code/font/vefontcache/LRU.odin @@ -21,10 +21,9 @@ LRU_Fail_Mask_32 :: 0xFFFFFFFF LRU_Fail_Mask_64 :: 0xFFFFFFFFFFFFFFFF Pool_ListIter :: i32 -// Pool_ListValue :: LRU_Key -// Pool_List_Item :: struct( $V_Type : typeid ) #packed { Pool_List_Item :: struct( $V_Type : typeid ) #packed { +// Pool_List_Item :: struct( $V_Type : typeid ) { prev : Pool_ListIter, next : Pool_ListIter, value : V_Type, diff --git a/code/font/vefontcache/shaper.odin b/code/font/vefontcache/shaper.odin index 9144a74..fae97b5 100644 --- a/code/font/vefontcache/shaper.odin +++ b/code/font/vefontcache/shaper.odin @@ -311,7 +311,7 @@ shaper_shape_text_latin :: proc( ctx : ^Shaper_Context, atlas : Atlas, glyph_buffer_size : Vec2, entry : Entry, - font_px_Size : f32, + font_px_size : f32, font_scale : f32, text_utf8 : string, output : ^Shaped_Text @@ -346,7 +346,7 @@ shaper_shape_text_latin :: proc( ctx : ^Shaper_Context, prev_codepoint = rune(0) continue } - if abs( font_px_Size ) <= ctx.adv_snap_small_font_threshold { + if abs( font_px_size ) <= ctx.adv_snap_small_font_threshold { position.x = ceil(position.x) } @@ -371,6 +371,29 @@ shaper_shape_text_latin :: proc( ctx : ^Shaper_Context, output.size.x = max_line_width output.size.y = f32(line_count) * line_height + + // Resolve each glyphs: bounds, atlas lru, and the atlas region as we have everything we need now. + + resize( & output.atlas_lru_code, len(output.glyph) ) + resize( & output.region_kind, len(output.glyph) ) + resize( & output.bounds, len(output.glyph) ) + + profile_begin("atlas_lru_code") + for id, index in output.glyph + { + output.atlas_lru_code[index] = atlas_glyph_lru_code(entry.id, font_px_size, id) + } + profile_end() + + profile_begin("bounds & region") + for id, index in output.glyph + { + bounds := & output.bounds[index] + (bounds ^) = parser_get_bounds( entry.parser_info, id ) + bounds_size_scaled := (bounds.p1 - bounds.p0) * font_scale + output.region_kind[index] = atlas_decide_region( atlas, glyph_buffer_size, bounds_size_scaled ) + } + profile_end() } // Shapes are tracked by the library's context using the shape cache