diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index d5a13b1a5ad04..eee2ea76528d0 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -176,8 +176,12 @@ impl TextPipeline { for (span_index, (entity, depth, span, text_font, _color, line_height)) in text_spans.enumerate() { - // Save this section entity in the computed text block. - computed.entities.push(TextEntity { entity, depth }); + // Save this span entity in the computed text block. + computed.entities.push(TextEntity { + entity, + depth, + font_smoothing: text_font.font_smoothing, + }); if span.is_empty() { continue; @@ -371,8 +375,7 @@ impl TextPipeline { let mut temp_glyph; let span_index = layout_glyph.metadata; - let font_smoothing = FontSmoothing::AntiAliased; - + let font_smoothing = computed.entities[span_index].font_smoothing; let layout_glyph = if font_smoothing == FontSmoothing::None { // If font smoothing is disabled, round the glyph positions and sizes, // effectively discarding all subpixel layout. diff --git a/crates/bevy_text/src/text.rs b/crates/bevy_text/src/text.rs index 9f4c350ae84f0..4f03eec3eda22 100644 --- a/crates/bevy_text/src/text.rs +++ b/crates/bevy_text/src/text.rs @@ -33,6 +33,8 @@ pub struct TextEntity { pub entity: Entity, /// Records the hierarchy depth of the entity within a `TextLayout`. pub depth: usize, + /// Antialiasing method to use when rendering the text. + pub font_smoothing: FontSmoothing, } /// Computed information for a text block. diff --git a/examples/testbed/ui.rs b/examples/testbed/ui.rs index 7433269bd090e..ab9cd951238e6 100644 --- a/examples/testbed/ui.rs +++ b/examples/testbed/ui.rs @@ -149,7 +149,7 @@ mod image { } mod text { - use bevy::{color::palettes::css::*, prelude::*}; + use bevy::{color::palettes::css::*, prelude::*, text::FontSmoothing}; pub fn setup(mut commands: Commands, asset_server: Res) { commands.spawn((Camera2d, DespawnOnExit(super::Scene::Text))); @@ -607,6 +607,25 @@ mod text { ), ], )); + + for font_smoothing in [FontSmoothing::AntiAliased, FontSmoothing::None] { + top += 35.; + commands.spawn(( + Node { + left: px(100.), + top: px(top), + ..Default::default() + }, + Text::new(format!("FontSmoothing::{:?}", font_smoothing)), + TextFont { + font: asset_server.load("fonts/MonaSans-VariableFont.ttf").into(), + font_size: 25., + font_smoothing, + ..default() + }, + DespawnOnExit(super::Scene::Text), + )); + } } }