From 8ecfd7407e942aedb942bbefaa273c8555623dc1 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 30 Jun 2024 13:36:54 -0400 Subject: [PATCH] VEFontCache: Adjustments to positioning & text size shape values --- code/font/VEFontCache/draw.odin | 2 +- code/font/VEFontCache/mappings.odin | 24 ++++++++++++++++++++++++ code/font/VEFontCache/misc.odin | 3 ++- code/font/VEFontCache/shaped_text.odin | 4 ++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/code/font/VEFontCache/draw.odin b/code/font/VEFontCache/draw.odin index 581e995..983871e 100644 --- a/code/font/VEFontCache/draw.odin +++ b/code/font/VEFontCache/draw.odin @@ -489,7 +489,7 @@ draw_text_batch :: proc(ctx: ^Context, entry: ^Entry, shaped: ^ShapedText, // Draw cacxhed glyph slot_position, _ := atlas_bbox( atlas, region_kind, atlas_index ) glyph_scale := bounds_size * entry.size_scale + glyph_padding - bounds_0_scaled := ceil( vbounds_0 * entry.size_scale ) + bounds_0_scaled := ceil(vbounds_0 * entry.size_scale) dst := glyph_translate + bounds_0_scaled * scale dst_scale := glyph_scale * scale textspace_x_form( & slot_position, & glyph_scale, atlas_size ) diff --git a/code/font/VEFontCache/mappings.odin b/code/font/VEFontCache/mappings.odin index e575c15..cc24907 100644 --- a/code/font/VEFontCache/mappings.odin +++ b/code/font/VEFontCache/mappings.odin @@ -12,6 +12,16 @@ import "core:math" ceil_f64 :: math.ceil_f64 ceil_f64le :: math.ceil_f64le ceil_f64be :: math.ceil_f64be + + floor_f16 :: math.floor_f16 + floor_f16le :: math.floor_f16le + floor_f16be :: math.floor_f16be + floor_f32 :: math.floor_f32 + floor_f32le :: math.floor_f32le + floor_f32be :: math.floor_f32be + floor_f64 :: math.floor_f64 + floor_f64le :: math.floor_f64le + floor_f64be :: math.floor_f64be import "core:math/linalg" import "core:mem" Kilobyte :: mem.Kilobyte @@ -54,6 +64,20 @@ clear :: proc { clear_dynamic_array, } +floor :: proc { + math.floor_f16, + math.floor_f16le, + math.floor_f16be, + math.floor_f32, + math.floor_f32le, + math.floor_f32be, + math.floor_f64, + math.floor_f64le, + math.floor_f64be, + + floor_vec2, +} + make :: proc { make_dynamic_array, make_dynamic_array_len, diff --git a/code/font/VEFontCache/misc.odin b/code/font/VEFontCache/misc.odin index cba3de4..1b04560 100644 --- a/code/font/VEFontCache/misc.odin +++ b/code/font/VEFontCache/misc.odin @@ -16,7 +16,8 @@ vec2_64_from_vec2 :: #force_inline proc "contextless" ( v2 : Vec2 ) -> Vec2 vec2_from_vec2i :: #force_inline proc "contextless" ( v2i : Vec2i ) -> Vec2 { return { f32(v2i.x), f32(v2i.y) }} vec2i_from_vec2 :: #force_inline proc "contextless" ( v2 : Vec2 ) -> Vec2i { return { i32(v2.x), i32(v2.y) }} -@(require_results) ceil_vec2 :: proc "contextless" ( v : Vec2 ) -> Vec2 { return { ceil_f32(v.x), ceil_f32(v.y) } } +@(require_results) ceil_vec2 :: proc "contextless" ( v : Vec2 ) -> Vec2 { return { ceil_f32(v.x), ceil_f32(v.y) } } +@(require_results) floor_vec2 :: proc "contextless" ( v : Vec2 ) -> Vec2 { return { floor_f32(v.x), floor_f32(v.y) } } // This buffer is used below excluisvely to prevent any allocator recusion when verbose logging from allocators. // This means a single line is limited to 32k buffer (increase naturally if this SOMEHOW becomes a bottleneck...) diff --git a/code/font/VEFontCache/shaped_text.odin b/code/font/VEFontCache/shaped_text.odin index 69c527f..96b8cd1 100644 --- a/code/font/VEFontCache/shaped_text.odin +++ b/code/font/VEFontCache/shaped_text.odin @@ -111,7 +111,7 @@ shape_text_uncached :: proc( ctx : ^Context, font : FontID, text_utf8 : string, continue } if abs( entry.size ) <= Advance_Snap_Smallfont_Size { - position.x = ceil( position.x ) + position.x = position.x } append( & output.glyphs, parser_find_glyph_index( & entry.parser_info, codepoint )) @@ -129,7 +129,7 @@ shape_text_uncached :: proc( ctx : ^Context, font : FontID, text_utf8 : string, output.end_cursor_pos = position max_line_width = max(max_line_width, position.x) - output.size.x = max_line_width + output.size.x = ceil(max_line_width) output.size.y = f32(line_count) * line_height } }