Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/bevy_text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pub use text_access::*;
pub mod prelude {
#[doc(hidden)]
pub use crate::{
Font, FontHinting, FontSource, FontStyle, FontWeight, FontWidth, Justify, LineBreak,
Strikethrough, StrikethroughColor, TextColor, TextError, TextFont, TextLayout, TextSpan,
Underline, UnderlineColor,
Font, FontHinting, FontSmoothing, FontSource, FontStyle, FontWeight, FontWidth, Justify,
LineBreak, Strikethrough, StrikethroughColor, TextColor, TextError, TextFont, TextLayout,
TextSpan, Underline, UnderlineColor,
};
}

Expand Down
9 changes: 6 additions & 3 deletions crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ impl TextPipeline {
text_spans.enumerate()
{
// Save this span entity in the computed text block.
computed.entities.push(TextEntity { entity, depth });
computed.entities.push(TextEntity {
entity,
depth,
font_smoothing: text_font.font_smoothing,
});

if span.is_empty() {
continue;
Expand Down Expand Up @@ -346,8 +350,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.
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 20 additions & 1 deletion examples/testbed/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssetServer>) {
commands.spawn((Camera2d, DespawnOnExit(super::Scene::Text)));
Expand Down Expand Up @@ -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),
));
}
}
}

Expand Down