Skip to content

Commit

Permalink
create font atlas that can contains fonts of any size (bevyengine#3592)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
mockersf authored and james7132 committed Jun 7, 2022
1 parent 5db2933 commit 4918ad6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/bevy_text/src/font_atlas_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ impl FontAtlasSet {
)
};
if !font_atlases.iter_mut().any(add_char_to_font_atlas) {
// Find the largest dimension of the glyph, either its width or its height
let glyph_max_size: u32 = glyph_texture
.texture_descriptor
.size
.height
.max(glyph_texture.texture_descriptor.size.width);
// Pick the higher of 512 or the smallest power of 2 greater than glyph_max_size
let containing = (1u32 << (32 - glyph_max_size.leading_zeros())).max(512) as f32;
font_atlases.push(FontAtlas::new(
textures,
texture_atlases,
Vec2::new(512.0, 512.0),
Vec2::new(containing, containing),
));
if !font_atlases.last_mut().unwrap().add_glyph(
textures,
Expand Down

0 comments on commit 4918ad6

Please sign in to comment.