layout: Fix bug where whitespace didn't have line decorations (#38007)

This PR fixes the issue where underlines weren't appearing on
whitespaces. This was due to whitespace being ignored in the `glyphs`
function of `components/layout/display_list/mod.rs` when the fragment
didn't have a selection. I added in a check to include the whitespace if
there's a selection or if there are any line decorations. I also renamed
the field from `ignore_whitespace` to `include_whitespace` to make it a
bit clearer since it was being reversed everywhere it was used anyway.

**Before:**
<img width="1235" height="169" alt="image"
src="https://github.com/user-attachments/assets/51d47781-355f-4915-8100-f3a7db81027f"
/>

**After:**
<img width="1235" height="169" alt="image"
src="https://github.com/user-attachments/assets/9b44fe77-d600-4080-9f3a-2c9b33924f51"
/>


Testing: `/css/css-text/white-space/pre-wrap-018.html` is now passing.
Also verified manually by running
`data:text/html;base64,PGRpdiBzdHlsZT0idGV4dC1kZWNvcmF0aW9uOiB1bmRlcmxpbmU7Ij5IZWxsbyBXb3JsZCE8L2Rpdj4=
`
Fixes: https://github.com/servo/servo/issues/33463

---------

Signed-off-by: Leo Ring <leoring03@gmail.com>
Signed-off-by: leo030303 <59373587+leo030303@users.noreply.github.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
leo030303 2025-07-13 14:34:51 +01:00 committed by GitHub
parent 35a145613e
commit 93e5b672a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 5 deletions

View file

@ -740,12 +740,14 @@ impl Fragment {
let rect = fragment.rect.translate(containing_block.origin.to_vector());
let mut baseline_origin = rect.origin;
baseline_origin.y += fragment.font_metrics.ascent;
let include_whitespace =
fragment.has_selection() || text_decorations.iter().any(|item| !item.line.is_empty());
let glyphs = glyphs(
&fragment.glyphs,
baseline_origin,
fragment.justification_adjustment,
!fragment.has_selection(),
include_whitespace,
);
if glyphs.is_empty() {
return;
@ -1628,7 +1630,7 @@ fn glyphs(
glyph_runs: &[Arc<GlyphStore>],
mut baseline_origin: PhysicalPoint<Au>,
justification_adjustment: Au,
ignore_whitespace: bool,
include_whitespace: bool,
) -> Vec<wr::GlyphInstance> {
use fonts_traits::ByteIndex;
use range::Range;
@ -1636,7 +1638,7 @@ fn glyphs(
let mut glyphs = vec![];
for run in glyph_runs {
for glyph in run.iter_glyphs_for_byte_range(&Range::new(ByteIndex(0), run.len())) {
if !run.is_whitespace() || !ignore_whitespace {
if !run.is_whitespace() || include_whitespace {
let glyph_offset = glyph.offset().unwrap_or(Point2D::zero());
let point = units::LayoutPoint::new(
baseline_origin.x.to_f32_px() + glyph_offset.x.to_f32_px(),

View file

@ -0,0 +1,2 @@
[text-decoration-skip-spaces-003.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[pre-wrap-018.html]
expected: FAIL