From d68bdb87eb1c87cb124ff7706151a9482f78a059 Mon Sep 17 00:00:00 2001 From: Nathan Jeffords Date: Fri, 1 Jan 2021 08:38:16 -0800 Subject: [PATCH] reposition glyph before passing it to ab_glyph to normalize its rendering The result of layout of sequence of glyphs causes individuals to have fractional positions, but since glyph renderings are reused for future instances of that glyph, this produces errors. This change accepts the errors but repositions the glyph to "0, 0" in an effort to get the cleanest possible rendering. --- crates/bevy_text/src/glyph_brush.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index 77570f9870ac76..bf24dd695cbc86 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -73,8 +73,11 @@ impl GlyphBrush { let mut positioned_glyphs = Vec::new(); for sg in glyphs { - let glyph_id = sg.glyph.id; - if let Some(outlined_glyph) = font.font.outline_glyph(sg.glyph) { + let SectionGlyph{section_index:_,byte_index:_,mut glyph,font_id:_} = sg; + let glyph_id = glyph.id; + let base_x = glyph.position.x.floor (); + glyph.position.x = 0.; + if let Some(outlined_glyph) = font.font.outline_glyph(glyph) { let bounds = outlined_glyph.px_bounds(); let handle_font_atlas: Handle = handle.as_weak(); let font_atlas_set = font_atlas_set_storage @@ -92,10 +95,10 @@ impl GlyphBrush { let glyph_width = glyph_rect.width(); let glyph_height = glyph_rect.height(); - let x = bounds.min.x + glyph_width / 2.0 - min_x; + let x = base_x + bounds.min.x + glyph_width / 2.0 - min_x; // the 0.5 accounts for odd-numbered heights (bump up by 1 pixel) // max_y = text block height, and up is negative (whereas for transform, up is positive) - let y = max_y - bounds.max.y + glyph_height / 2.0 + 0.5; + let y = max_y - bounds.max.y + glyph_height / 2.0; let position = Vec2::new(x, y); positioned_glyphs.push(PositionedGlyph {