layout: Count word separators as justification opportunities when trimming whitespace (#31161)

Before counting whitepsace-only `GlyphStore`s where counted as a single
justification opportunity when trimming whitespace from the front and
back of lines. This isn't correct, instead count the actual number of
word seperators of the trimmed `GlyphStore`s.

These two counts can be different in the case where whitespace collapse
isn't happening yet (flexbox). In addition, using word seperators means
the code is making less assumptions about the contents of the line and
is more robust.

This fixes some crashes in flexbox tests on debug builds.

Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
This commit is contained in:
Martin Robinson 2024-01-23 12:47:13 +01:00 committed by GitHub
parent 1d67aa44ca
commit 7de0486e2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 19 deletions

View file

@ -434,7 +434,7 @@ pub struct GlyphStore {
/// A cache of the number of word separators in the entire glyph store.
/// See <https://drafts.csswg.org/css-text/#word-separator>.
total_word_separators: i32,
total_word_separators: usize,
/// Used to check if fast path should be used in glyph iteration.
has_detailed_glyphs: bool,
@ -476,7 +476,7 @@ impl<'a> GlyphStore {
}
#[inline]
pub fn total_word_separators(&self) -> i32 {
pub fn total_word_separators(&self) -> usize {
self.total_word_separators
}
@ -622,7 +622,7 @@ impl<'a> GlyphStore {
#[inline]
pub fn advance_for_byte_range(&self, range: &Range<ByteIndex>, extra_word_spacing: Au) -> Au {
if range.begin() == ByteIndex(0) && range.end() == self.len() {
self.total_advance + extra_word_spacing * self.total_word_separators
self.total_advance + extra_word_spacing * (self.total_word_separators as i32)
} else if !self.has_detailed_glyphs {
self.advance_for_byte_range_simple_glyphs(range, extra_word_spacing)
} else {