@@ -21,10 +21,19 @@ pub mut:
21
21
scale f32 = 1.0
22
22
}
23
23
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
+
24
33
fn new_ft (c FTConfig) ? & FT {
25
34
if c.font_path == '' {
26
35
if c.bytes_normal.len > 0 {
27
- fons := sfons.create (512 , 512 , 1 )
36
+ fons := sfons.create (buff_size, buff_size , 1 )
28
37
bytes_normal := c.bytes_normal
29
38
bytes_bold := if c.bytes_bold.len > 0 {
30
39
c.bytes_bold
@@ -44,7 +53,7 @@ fn new_ft(c FTConfig) ?&FT {
44
53
debug_font_println ('setting italic variant to normal' )
45
54
bytes_normal
46
55
}
47
-
56
+ fons. set_error_callback (clear_atlas_callback, fons)
48
57
return & FT{
49
58
fons: fons
50
59
font_normal: fons.add_font_mem ('sans' , bytes_normal, false )
@@ -105,11 +114,12 @@ fn new_ft(c FTConfig) ?&FT {
105
114
italic_path = c.font_path
106
115
bytes
107
116
}
108
- fons := sfons.create (512 , 512 , 1 )
117
+ fons := sfons.create (buff_size, buff_size , 1 )
109
118
debug_font_println ('Font used for font_normal : ${normal_path} ' )
110
119
debug_font_println ('Font used for font_bold : ${bold_path} ' )
111
120
debug_font_println ('Font used for font_mono : ${mono_path} ' )
112
121
debug_font_println ('Font used for font_italic : ${italic_path} ' )
122
+ fons.set_error_callback (clear_atlas_callback, fons)
113
123
return & FT{
114
124
fons: fons
115
125
font_normal: fons.add_font_mem ('sans' , bytes, false )
0 commit comments