Skip to content

Commit

Permalink
Don’t remove inline block’s trailing space twice
Browse files Browse the repository at this point in the history
When we calculate the minimum width of an inline block, the size of the
trailing space is already removed by split_first_line. There’s no need to
remove it twice.

We should probably fix split_first_line to remove the trailing space only when
it’s been asked to. But there’s no obvious situation when we want the minimum
width to include trailing spaces, as the minimum size requires line breaks
everywhere, including after each space.

At least, this commit doesn’t remove trailing spaces twice.

Related to #1520.
  • Loading branch information
liZe committed Dec 13, 2021
1 parent a65ca19 commit 7a5c285
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/test_text.py
Expand Up @@ -950,8 +950,8 @@ def test_overflow_wrap_2(wrap, text, body_width, expected_width):
@pytest.mark.parametrize('wrap, text, body_width, expected_width', (
('anywhere', 'aaaaaa', 10, 20),
('anywhere', 'aaaaaa', 40, 40),
# ('break-word', 'abcdef', 40, 120),
# ('normal', 'abcdef', 40, 120),
('break-word', 'aaaaaa', 40, 120),
('normal', 'abcdef', 40, 120),
))
def test_overflow_wrap_trailing_space(wrap, text, body_width, expected_width):
page, = render_pages('''
Expand Down
11 changes: 4 additions & 7 deletions weasyprint/layout/preferred.py
Expand Up @@ -198,19 +198,16 @@ def inline_min_content_width(context, box, outer=True, skip_stack=None,
widths = inline_line_widths(
context, box, outer, is_line_start, minimum=True,
skip_stack=skip_stack, first_line=first_line)

if first_line:
widths = [next(widths)]
else:
widths = list(widths)
widths[-1] -= trailing_whitespace_size(context, box)
return adjust(box, outer, max(widths))
width = next(widths) if first_line else max(widths)
return adjust(box, outer, width)


def inline_max_content_width(context, box, outer=True, is_line_start=False):
"""Return the max-content width for an ``InlineBox``."""
widths = list(
inline_line_widths(context, box, outer, is_line_start, minimum=False))
# Remove trailing space, as split_first_line keeps trailing spaces when
# max_width is not set.
widths[-1] -= trailing_whitespace_size(context, box)
return adjust(box, outer, max(widths))

Expand Down

0 comments on commit 7a5c285

Please sign in to comment.