mirror of
https://github.com/Ed94/VEFontCache-Odin.git
synced 2025-08-06 06:52:44 -07:00
General improvements (text and features)
* Added clear_atlas_region_caches & clear_shape_cache to VEFontCache (Usage Example: On hot-reloads to force refresh the caches if tuning the library) * Made glyph_draw's over_sample a vec2 for initialization (incase user wants to do some float value multiple of 4x4) * ADVANCE_SNAP_SMALLFONT_SIZE made a runtime option: Shaper_Context.adv_snap_small_font_threshold * Some improvement to text hinting and general rendering of text * Better defaults for initialization of the library
This commit is contained in:
@@ -13,6 +13,9 @@ Shaper_Kind :: enum {
|
||||
|
||||
Shaper_Context :: struct {
|
||||
hb_buffer : harfbuzz.Buffer,
|
||||
|
||||
snap_glyph_position : b32,
|
||||
adv_snap_small_font_threshold : f32,
|
||||
}
|
||||
|
||||
Shaper_Info :: struct {
|
||||
@@ -66,12 +69,13 @@ shaper_shape_from_text :: proc( ctx : ^Shaper_Context, info : ^Shaper_Info, outp
|
||||
|
||||
max_line_width := f32(0)
|
||||
line_count := 1
|
||||
line_height := (ascent - descent + line_gap) * size_scale
|
||||
line_height := ((ascent - descent + line_gap) * size_scale)
|
||||
|
||||
position, vertical_position : f32
|
||||
shape_run :: proc( buffer : harfbuzz.Buffer, script : harfbuzz.Script, font : harfbuzz.Font, output : ^Shaped_Text,
|
||||
position, vertical_position, max_line_width: ^f32, line_count: ^int,
|
||||
ascent, descent, line_gap, size, size_scale: f32 )
|
||||
ascent, descent, line_gap, size, size_scale: f32,
|
||||
snap_shape_pos : b32, adv_snap_small_font_threshold : f32 )
|
||||
{
|
||||
// Set script and direction. We use the system's default langauge.
|
||||
// script = HB_SCRIPT_LATIN
|
||||
@@ -101,24 +105,29 @@ shaper_shape_from_text :: proc( ctx : ^Shaper_Context, info : ^Shaper_Info, outp
|
||||
(max_line_width^) = max( max_line_width^, position^ )
|
||||
(position^) = 0.0
|
||||
(vertical_position^) -= line_height
|
||||
(vertical_position^) = cast(f32) i32(vertical_position^ + 0.5)
|
||||
(vertical_position^) = floor(vertical_position^ + 0.5)
|
||||
(line_count^) += 1
|
||||
continue
|
||||
}
|
||||
if abs( size ) <= ADVANCE_SNAP_SMALLFONT_SIZE
|
||||
if abs( size ) <= adv_snap_small_font_threshold
|
||||
{
|
||||
(position^) = ceil( position^ )
|
||||
}
|
||||
|
||||
append( & output.glyphs, glyph_id )
|
||||
|
||||
pos := position^
|
||||
pos := position^
|
||||
v_pos := vertical_position^
|
||||
offset_x := f32(hb_gposition.x_offset) * size_scale
|
||||
offset_y := f32(hb_gposition.y_offset) * size_scale
|
||||
append( & output.positions, Vec2 { cast(f32) i32( pos + offset_x + 0.5 ),
|
||||
v_pos + offset_y,
|
||||
})
|
||||
pos += offset_x
|
||||
v_pos += offset_y
|
||||
|
||||
if snap_shape_pos {
|
||||
pos = ceil(pos)
|
||||
v_pos = ceil(v_pos)
|
||||
}
|
||||
append( & output.positions, Vec2 {pos, v_pos})
|
||||
|
||||
(position^) += f32(hb_gposition.x_advance) * size_scale
|
||||
(vertical_position^) += f32(hb_gposition.y_advance) * size_scale
|
||||
@@ -151,13 +160,23 @@ shaper_shape_from_text :: proc( ctx : ^Shaper_Context, info : ^Shaper_Info, outp
|
||||
}
|
||||
|
||||
// End current run since we've encountered a script change.
|
||||
shape_run( ctx.hb_buffer, current_script, info.font, output, & position, & vertical_position, & max_line_width, & line_count, ascent, descent, line_gap, size, size_scale )
|
||||
shape_run(
|
||||
ctx.hb_buffer, current_script, info.font, output,
|
||||
& position, & vertical_position, & max_line_width, & line_count,
|
||||
ascent, descent, line_gap, size, size_scale,
|
||||
ctx.snap_glyph_position, ctx.adv_snap_small_font_threshold
|
||||
)
|
||||
harfbuzz.buffer_add( ctx.hb_buffer, hb_codepoint, codepoint == '\n' ? 1 : 0 )
|
||||
current_script = script
|
||||
}
|
||||
|
||||
// End the last run if needed
|
||||
shape_run( ctx.hb_buffer, current_script, info.font, output, & position, & vertical_position, & max_line_width, & line_count, ascent, descent, line_gap, size, size_scale )
|
||||
shape_run(
|
||||
ctx.hb_buffer, current_script, info.font, output,
|
||||
& position, & vertical_position, & max_line_width, & line_count,
|
||||
ascent, descent, line_gap, size, size_scale,
|
||||
ctx.snap_glyph_position, ctx.adv_snap_small_font_threshold
|
||||
)
|
||||
|
||||
// Set the final size
|
||||
output.size.x = max_line_width
|
||||
|
Reference in New Issue
Block a user