added snap_glyph_width

This commit is contained in:
2025-02-13 19:39:44 -05:00
parent de8841a0cb
commit 0d0344e423
3 changed files with 19 additions and 9 deletions

View File

@@ -227,6 +227,7 @@ init :: proc "c" ()
} }
glyph_draw_opts := ve.Init_Glyph_Draw_Params_Default glyph_draw_opts := ve.Init_Glyph_Draw_Params_Default
glyph_draw_opts.snap_glyph_width = false
glyph_draw_opts.snap_glyph_height = false glyph_draw_opts.snap_glyph_height = false
shaper_opts := ve.Init_Shaper_Params_Default shaper_opts := ve.Init_Shaper_Params_Default

View File

@@ -84,6 +84,7 @@ Glyph_Draw_Buffer :: struct{
size : Vec2i, size : Vec2i,
draw_padding : f32, draw_padding : f32,
snap_glyph_height : f32, snap_glyph_height : f32,
snap_glyph_width : f32,
allocated_x : i32, // Space used (horizontally) within the glyph buffer allocated_x : i32, // Space used (horizontally) within the glyph buffer
clear_draw_list : Draw_List, clear_draw_list : Draw_List,
@@ -703,13 +704,13 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
dst_glyph_pos := glyph.region_pos dst_glyph_pos := glyph.region_pos
dst_glyph_size := bounds_size_scaled + atlas.glyph_padding dst_glyph_size := bounds_size_scaled + atlas.glyph_padding
dst_glyph_size.x = ceil(dst_glyph_size.x) dst_glyph_size.x = max(dst_glyph_size.x, ceil(dst_glyph_size.x) * glyph_buffer.snap_glyph_width) // Note(Ed): Can (in specific cases, rare.) improve hinting
dst_glyph_size.y = max(dst_glyph_size.y, ceil(dst_glyph_size.y) * glyph_buffer.snap_glyph_height) // Note(Ed): Seems to improve hinting dst_glyph_size.y = max(dst_glyph_size.y, ceil(dst_glyph_size.y) * glyph_buffer.snap_glyph_height) // Note(Ed): Seems to improve hinting
to_glyph_buffer_space( & dst_glyph_pos, & dst_glyph_size, atlas_size ) to_glyph_buffer_space( & dst_glyph_pos, & dst_glyph_size, atlas_size )
src_position := Vec2 { glyph.buffer_x, 0 } src_position := Vec2 { glyph.buffer_x, 0 }
src_size := (bounds_size_scaled + atlas.glyph_padding) * glyph_buffer.over_sample src_size := (bounds_size_scaled + atlas.glyph_padding) * glyph_buffer.over_sample
src_size.x = ceil(src_size.x) src_size.x = max(src_size.x, ceil(src_size.x) * glyph_buffer.snap_glyph_width) // Note(Ed): Can (in specific cases, rare.) improve hinting
src_size.y = max(src_size.y, ceil(src_size.y) * glyph_buffer.snap_glyph_height) // Note(Ed): Seems to improve hinting src_size.y = max(src_size.y, ceil(src_size.y) * glyph_buffer.snap_glyph_height) // Note(Ed): Seems to improve hinting
to_target_space( & src_position, & src_size, glyph_buffer_size ) to_target_space( & src_position, & src_size, glyph_buffer_size )

View File

@@ -24,6 +24,9 @@ Entry :: struct {
used : b32, used : b32,
curve_quality : f32, curve_quality : f32,
// TODO(Ed): Move over settings related to (snapping) hinting, oversample, px_scalar, etc;
// to here as there is no need to restrict the user to have one option for all fonts.
ascent : f32, ascent : f32,
descent : f32, descent : f32,
line_gap : f32, line_gap : f32,
@@ -113,7 +116,10 @@ Init_Atlas_Params_Default :: Init_Atlas_Params {
} }
Init_Glyph_Draw_Params :: struct { Init_Glyph_Draw_Params :: struct {
// During the draw list generation stage when blitting to atlas, the quad wil be ceil()'d to the closest pixel. // During the draw list generation stage when blitting to atlas, the quad's width will be ceil()'d to the closest pixel.
// Generally its not recommend todo this and is disabled on most renderers, but on rare occasion some fonts benefit from this.
snap_glyph_width : b32,
// During the draw list generation stage when blitting to atlas, the quad's height be ceil()'d to the closest pixel.
snap_glyph_height : b32, snap_glyph_height : b32,
// Intended to be x16 (4x4) super-sampling from the glyph buffer to the atlas. // Intended to be x16 (4x4) super-sampling from the glyph buffer to the atlas.
// Oversized glyphs don't use this and instead do 2x or 1x depending on how massive they are. // Oversized glyphs don't use this and instead do 2x or 1x depending on how massive they are.
@@ -128,12 +134,13 @@ Init_Glyph_Draw_Params :: struct {
} }
Init_Glyph_Draw_Params_Default :: Init_Glyph_Draw_Params { Init_Glyph_Draw_Params_Default :: Init_Glyph_Draw_Params {
snap_glyph_height = true, snap_glyph_width = false,
over_sample = 4, snap_glyph_height = true,
draw_padding = Init_Atlas_Params_Default.glyph_padding, over_sample = 4,
shape_gen_scratch_reserve = 512, draw_padding = Init_Atlas_Params_Default.glyph_padding,
buffer_glyph_limit = 16, shape_gen_scratch_reserve = 512,
batch_glyph_limit = 256, buffer_glyph_limit = 16,
batch_glyph_limit = 256,
} }
Init_Shaper_Params :: struct { Init_Shaper_Params :: struct {
@@ -293,6 +300,7 @@ startup :: proc( ctx : ^Context, parser_kind : Parser_Kind = .STB_TrueType, // N
Glyph_Buffer_Setup: Glyph_Buffer_Setup:
{ {
glyph_buffer := & ctx.glyph_buffer glyph_buffer := & ctx.glyph_buffer
glyph_buffer.snap_glyph_width = cast(f32) i32(glyph_draw_params.snap_glyph_width)
glyph_buffer.snap_glyph_height = cast(f32) i32(glyph_draw_params.snap_glyph_height) glyph_buffer.snap_glyph_height = cast(f32) i32(glyph_draw_params.snap_glyph_height)
glyph_buffer.over_sample = { f32(glyph_draw_params.over_sample), f32(glyph_draw_params.over_sample) } glyph_buffer.over_sample = { f32(glyph_draw_params.over_sample), f32(glyph_draw_params.over_sample) }
glyph_buffer.size.x = atlas.region_d.slot_size.x * i32(glyph_buffer.over_sample.x) * i32(glyph_draw_params.buffer_glyph_limit) glyph_buffer.size.x = atlas.region_d.slot_size.x * i32(glyph_buffer.over_sample.x) * i32(glyph_draw_params.buffer_glyph_limit)