Skip to content

Commit 09ddfff

Browse files
FontSmoothing fixes (#22455)
# Objective 1. The `font_smoothing` field of `TextFont` is ignored in main currently. Instead it always uses `FontSmoothing::Antialiased`. 2. The `FontSmoothing` enum is missing from the `bevy_text` prelude. 3. The `FontSmoothing` bug wasn't caught by the screenshot CI. ## Solution 1. Store the antialiasing mode in `ComputedTextBlock`, for use in `TextPipeline::update_buffer`. 2. Add `FontSmoothing` to `bevy_text::prelude`. 3. Add a font smoothing example to `testbed_ui`'s `Text` scene. ## Testing Check `testbed_ui`'s text scene. Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
1 parent 301db8a commit 09ddfff

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

crates/bevy_text/src/pipeline.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@ impl TextPipeline {
176176
for (span_index, (entity, depth, span, text_font, _color, line_height)) in
177177
text_spans.enumerate()
178178
{
179-
// Save this section entity in the computed text block.
180-
computed.entities.push(TextEntity { entity, depth });
179+
// Save this span entity in the computed text block.
180+
computed.entities.push(TextEntity {
181+
entity,
182+
depth,
183+
font_smoothing: text_font.font_smoothing,
184+
});
181185

182186
if span.is_empty() {
183187
continue;
@@ -371,8 +375,7 @@ impl TextPipeline {
371375

372376
let mut temp_glyph;
373377
let span_index = layout_glyph.metadata;
374-
let font_smoothing = FontSmoothing::AntiAliased;
375-
378+
let font_smoothing = computed.entities[span_index].font_smoothing;
376379
let layout_glyph = if font_smoothing == FontSmoothing::None {
377380
// If font smoothing is disabled, round the glyph positions and sizes,
378381
// effectively discarding all subpixel layout.

crates/bevy_text/src/text.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub struct TextEntity {
3333
pub entity: Entity,
3434
/// Records the hierarchy depth of the entity within a `TextLayout`.
3535
pub depth: usize,
36+
/// Antialiasing method to use when rendering the text.
37+
pub font_smoothing: FontSmoothing,
3638
}
3739

3840
/// Computed information for a text block.

examples/testbed/ui.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ mod image {
149149
}
150150

151151
mod text {
152-
use bevy::{color::palettes::css::*, prelude::*};
152+
use bevy::{color::palettes::css::*, prelude::*, text::FontSmoothing};
153153

154154
pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
155155
commands.spawn((Camera2d, DespawnOnExit(super::Scene::Text)));
@@ -607,6 +607,25 @@ mod text {
607607
),
608608
],
609609
));
610+
611+
for font_smoothing in [FontSmoothing::AntiAliased, FontSmoothing::None] {
612+
top += 35.;
613+
commands.spawn((
614+
Node {
615+
left: px(100.),
616+
top: px(top),
617+
..Default::default()
618+
},
619+
Text::new(format!("FontSmoothing::{:?}", font_smoothing)),
620+
TextFont {
621+
font: asset_server.load("fonts/MonaSans-VariableFont.ttf").into(),
622+
font_size: 25.,
623+
font_smoothing,
624+
..default()
625+
},
626+
DespawnOnExit(super::Scene::Text),
627+
));
628+
}
610629
}
611630
}
612631

0 commit comments

Comments
 (0)