Skip to content

Commit a16ffe6

Browse files
committed
create font atlas that can contains fonts of any size (#3592)
# Objective - Bevy currently panics when displaying text with a *very* big font size (with font size greater than 400, the glyph would have a width or height greater than 512) ``` thread 'main' panicked at 'Fatal error when processing text: failed to add glyph to newly-created atlas GlyphId(514).', crates/bevy_ui/src/widget/text.rs:118:21 ``` ## Solution - Create font atlas that scales up with the size of the glyphs
1 parent cc4062e commit a16ffe6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

crates/bevy_text/src/font_atlas_set.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,18 @@ impl FontAtlasSet {
7676
)
7777
};
7878
if !font_atlases.iter_mut().any(add_char_to_font_atlas) {
79+
// Find the largest dimension of the glyph, either its width or its height
80+
let glyph_max_size: u32 = glyph_texture
81+
.texture_descriptor
82+
.size
83+
.height
84+
.max(glyph_texture.texture_descriptor.size.width);
85+
// Pick the higher of 512 or the smallest power of 2 greater than glyph_max_size
86+
let containing = (1u32 << (32 - glyph_max_size.leading_zeros())).max(512) as f32;
7987
font_atlases.push(FontAtlas::new(
8088
textures,
8189
texture_atlases,
82-
Vec2::new(512.0, 512.0),
90+
Vec2::new(containing, containing),
8391
));
8492
if !font_atlases.last_mut().unwrap().add_glyph(
8593
textures,

0 commit comments

Comments
 (0)