Skip to content

Commit

Permalink
Merge pull request #1520 from aschmitz/overflow-wrap-anywhere
Browse files Browse the repository at this point in the history
Support "overflow-wrap: anywhere"
  • Loading branch information
liZe committed Dec 13, 2021
2 parents f5d6d54 + 1b27388 commit 3c382e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
27 changes: 27 additions & 0 deletions tests/test_text.py
Expand Up @@ -891,6 +891,7 @@ def test_hyphenate_limit_chars_punctuation(css):

@assert_no_logs
@pytest.mark.parametrize('wrap, text, test, full_text', (
('anywhere', 'aaaaaaaa', lambda a: a > 1, 'aaaaaaaa'),
('break-word', 'aaaaaaaa', lambda a: a > 1, 'aaaaaaaa'),
('normal', 'aaaaaaaa', lambda a: a == 1, 'aaaaaaaa'),
('break-word', 'hyphenations', lambda a: a > 3,
Expand Down Expand Up @@ -920,6 +921,32 @@ def test_overflow_wrap(wrap, text, test, full_text):
assert full_text == lines_full_text


@assert_no_logs
@pytest.mark.parametrize('wrap, text, body_width, expected_width', (
('anywhere', 'aaaaaa', 10, 20),
('anywhere', 'aaaaaa', 40, 40),
('break-word', 'aaaaaa', 40, 100),
('normal', 'aaaaaa', 40, 100),
))
def test_overflow_wrap_2(wrap, text, body_width, expected_width):
page, = render_pages('''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
body {width: %dpx; font-family: weasyprint; font-size: 20px; }
table {overflow-wrap: %s; white-space: normal; }
</style>
<table><tr><td>%s
''' % (body_width, wrap, text))
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
tr, = row_group.children
td, = tr.children
assert td.width == expected_width


def white_space_lines(width, space):
page, = render_pages('''
<style>
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/css/validation/properties.py
Expand Up @@ -1176,7 +1176,7 @@ def white_space(keyword):
@single_keyword
def overflow_wrap(keyword):
"""``overflow-wrap`` property validation."""
return keyword in ('normal', 'break-word')
return keyword in ('anywhere', 'normal', 'break-word')


@property()
Expand Down
3 changes: 2 additions & 1 deletion weasyprint/text/line_break.py
Expand Up @@ -536,7 +536,8 @@ def split_first_line(text, style, context, max_width, justification_spacing,
first_line_width, _ = line_size(first_line, style)
space = max_width - first_line_width
# If we can break words and the first line is too long
if not minimum and overflow_wrap == 'break-word' and space < 0:
if space < 0 and (overflow_wrap == 'anywhere' or
(overflow_wrap == 'break-word' and not minimum)):
# Is it really OK to remove hyphenation for word-break ?
hyphenated = False
# TODO: Modify code to preserve W3C condition:
Expand Down

0 comments on commit 3c382e3

Please sign in to comment.