From 5e848e6468a94a015a20bcebec7e9af3e9a0644f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 8 Jan 2022 15:41:23 +0100 Subject: [PATCH 1/4] create font atlas that can contains fonts of any size --- crates/bevy_text/src/font_atlas_set.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/bevy_text/src/font_atlas_set.rs b/crates/bevy_text/src/font_atlas_set.rs index 34a1a843c451a..6243272e7ffdb 100644 --- a/crates/bevy_text/src/font_atlas_set.rs +++ b/crates/bevy_text/src/font_atlas_set.rs @@ -76,10 +76,16 @@ impl FontAtlasSet { ) }; if !font_atlases.iter_mut().any(add_char_to_font_atlas) { + let glyph_max_size = glyph_texture + .texture_descriptor + .size + .height + .max(glyph_texture.texture_descriptor.size.width); + 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, From 56a560c33b813718d690b01992c0c5a5e9db9132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 8 Jan 2022 15:48:21 +0100 Subject: [PATCH 2/4] :paperclip: --- crates/bevy_text/src/font_atlas_set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_text/src/font_atlas_set.rs b/crates/bevy_text/src/font_atlas_set.rs index 6243272e7ffdb..3ca70d5ab2056 100644 --- a/crates/bevy_text/src/font_atlas_set.rs +++ b/crates/bevy_text/src/font_atlas_set.rs @@ -81,7 +81,7 @@ impl FontAtlasSet { .size .height .max(glyph_texture.texture_descriptor.size.width); - let containing = (1u32 << 32 - glyph_max_size.leading_zeros()).max(512) as f32; + let containing = (1u32 << (32 - glyph_max_size.leading_zeros())).max(512) as f32; font_atlases.push(FontAtlas::new( textures, texture_atlases, From 374735dbd0949e49f874f37b01685fbdf63355f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 1 Jun 2022 22:12:20 +0200 Subject: [PATCH 3/4] comments --- crates/bevy_text/src/font_atlas_set.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_text/src/font_atlas_set.rs b/crates/bevy_text/src/font_atlas_set.rs index 3ca70d5ab2056..6b84f22478bfe 100644 --- a/crates/bevy_text/src/font_atlas_set.rs +++ b/crates/bevy_text/src/font_atlas_set.rs @@ -76,11 +76,13 @@ impl FontAtlasSet { ) }; if !font_atlases.iter_mut().any(add_char_to_font_atlas) { - let glyph_max_size = glyph_texture + // 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 smaller 2^n value greather than glyph_max_size, and at least 512 let containing = (1u32 << (32 - glyph_max_size.leading_zeros())).max(512) as f32; font_atlases.push(FontAtlas::new( textures, From 600f41ddd12a1f3a5e3c537eb5509a1a618753b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 1 Jun 2022 22:20:52 +0200 Subject: [PATCH 4/4] improve comment Co-authored-by: Alice Cecile --- crates/bevy_text/src/font_atlas_set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_text/src/font_atlas_set.rs b/crates/bevy_text/src/font_atlas_set.rs index 6b84f22478bfe..4549f474bf515 100644 --- a/crates/bevy_text/src/font_atlas_set.rs +++ b/crates/bevy_text/src/font_atlas_set.rs @@ -82,7 +82,7 @@ impl FontAtlasSet { .size .height .max(glyph_texture.texture_descriptor.size.width); - // Pick the smaller 2^n value greather than glyph_max_size, and at least 512 + // 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,