Skip to content

Commit

Permalink
reposition glyph before passing it to ab_glyph to normalize its rende…
Browse files Browse the repository at this point in the history
…ring

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.
  • Loading branch information
blunted2night committed Jan 1, 2021
1 parent 06132fe commit c5ad039
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/bevy_text/src/glyph_brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ 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<FontAtlasSet> = handle.as_weak();
let font_atlas_set = font_atlas_set_storage
Expand All @@ -92,10 +100,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 {
Expand Down

0 comments on commit c5ad039

Please sign in to comment.