Skip to content

Commit cbfe1b8

Browse files
authored
gg: use a larger fontstash text atlas by default (2048x2048, and customizable), instead of 512x512 (fix #21610) (#22959)
1 parent c1df71a commit cbfe1b8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

vlib/gg/text_rendering.c.v

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@ pub mut:
2121
scale f32 = 1.0
2222
}
2323

24+
const buff_size = int($d('gg_text_buff_size', 2048))
25+
26+
fn clear_atlas_callback(uptr voidptr, error int, val int) {
27+
if error == 1 { // atlas overflow error code
28+
fons := unsafe { &fontstash.Context(uptr) }
29+
fons.reset_atlas(buff_size, buff_size)
30+
}
31+
}
32+
2433
fn new_ft(c FTConfig) ?&FT {
2534
if c.font_path == '' {
2635
if c.bytes_normal.len > 0 {
27-
fons := sfons.create(512, 512, 1)
36+
fons := sfons.create(buff_size, buff_size, 1)
2837
bytes_normal := c.bytes_normal
2938
bytes_bold := if c.bytes_bold.len > 0 {
3039
c.bytes_bold
@@ -44,7 +53,7 @@ fn new_ft(c FTConfig) ?&FT {
4453
debug_font_println('setting italic variant to normal')
4554
bytes_normal
4655
}
47-
56+
fons.set_error_callback(clear_atlas_callback, fons)
4857
return &FT{
4958
fons: fons
5059
font_normal: fons.add_font_mem('sans', bytes_normal, false)
@@ -105,11 +114,12 @@ fn new_ft(c FTConfig) ?&FT {
105114
italic_path = c.font_path
106115
bytes
107116
}
108-
fons := sfons.create(512, 512, 1)
117+
fons := sfons.create(buff_size, buff_size, 1)
109118
debug_font_println('Font used for font_normal : ${normal_path}')
110119
debug_font_println('Font used for font_bold : ${bold_path}')
111120
debug_font_println('Font used for font_mono : ${mono_path}')
112121
debug_font_println('Font used for font_italic : ${italic_path}')
122+
fons.set_error_callback(clear_atlas_callback, fons)
113123
return &FT{
114124
fons: fons
115125
font_normal: fons.add_font_mem('sans', bytes, false)

0 commit comments

Comments
 (0)