From 0f221521ab198f3e7e62ccb0a867cf997b61fe48 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 5 May 2016 09:28:44 -0700 Subject: [PATCH] Filter out whitespace glyphs from display list Fixes #10244. --- components/gfx/paint_context.rs | 22 ++++++++++++---------- components/gfx/text/glyph.rs | 4 ++++ components/layout/webrender_helpers.rs | 18 ++++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 047cfbac733..626cc77b392 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -1800,16 +1800,18 @@ impl ScaledFontExtensionMethods for ScaledFont { for slice in run.natural_word_slices_in_visual_order(range) { for glyph in slice.glyphs.iter_glyphs_for_byte_range(&slice.range) { let glyph_advance = glyph.advance(); - let glyph_offset = glyph.offset().unwrap_or(Point2D::zero()); - let azglyph = struct__AzGlyph { - mIndex: glyph.id() as u32, - mPosition: struct__AzPoint { - x: (origin.x + glyph_offset.x).to_f32_px(), - y: (origin.y + glyph_offset.y).to_f32_px(), - } - }; - origin = Point2D::new(origin.x + glyph_advance, origin.y); - azglyphs.push(azglyph) + if !slice.glyphs.is_whitespace() { + let glyph_offset = glyph.offset().unwrap_or(Point2D::zero()); + let azglyph = struct__AzGlyph { + mIndex: glyph.id() as u32, + mPosition: struct__AzPoint { + x: (origin.x + glyph_offset.x).to_f32_px(), + y: (origin.y + glyph_offset.y).to_f32_px(), + } + }; + azglyphs.push(azglyph) + } + origin.x = origin.x + glyph_advance; }; } diff --git a/components/gfx/text/glyph.rs b/components/gfx/text/glyph.rs index c5fe90e1c60..161282d2f4e 100644 --- a/components/gfx/text/glyph.rs +++ b/components/gfx/text/glyph.rs @@ -109,6 +109,7 @@ impl GlyphEntry { Au(((self.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT) as i32) } + #[inline] fn id(&self) -> GlyphId { self.value & GLYPH_ID_MASK } @@ -361,6 +362,7 @@ impl<'a> GlyphInfo<'a> { } } + #[inline] pub fn offset(self) -> Option> { match self { GlyphInfo::Simple(_, _) => None, @@ -436,10 +438,12 @@ impl<'a> GlyphStore { } } + #[inline] pub fn len(&self) -> ByteIndex { ByteIndex(self.entry_buffer.len() as isize) } + #[inline] pub fn is_whitespace(&self) -> bool { self.is_whitespace } diff --git a/components/layout/webrender_helpers.rs b/components/layout/webrender_helpers.rs index 053ecf87f50..a66d3821cf2 100644 --- a/components/layout/webrender_helpers.rs +++ b/components/layout/webrender_helpers.rs @@ -394,14 +394,16 @@ impl WebRenderDisplayItemConverter for DisplayItem { for slice in item.text_run.natural_word_slices_in_visual_order(&item.range) { for glyph in slice.glyphs.iter_glyphs_for_byte_range(&slice.range) { let glyph_advance = glyph.advance(); - let glyph_offset = glyph.offset().unwrap_or(Point2D::zero()); - let glyph = webrender_traits::GlyphInstance { - index: glyph.id(), - x: (origin.x + glyph_offset.x).to_f32_px(), - y: (origin.y + glyph_offset.y).to_f32_px(), - }; - origin = Point2D::new(origin.x + glyph_advance, origin.y); - glyphs.push(glyph); + if !slice.glyphs.is_whitespace() { + let glyph_offset = glyph.offset().unwrap_or(Point2D::zero()); + let glyph = webrender_traits::GlyphInstance { + index: glyph.id(), + x: (origin.x + glyph_offset.x).to_f32_px(), + y: (origin.y + glyph_offset.y).to_f32_px(), + }; + glyphs.push(glyph); + } + origin.x = origin.x + glyph_advance; }; }