Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table overflow issue #2325

Closed
kesara opened this issue Dec 9, 2024 · 3 comments · Fixed by #2326
Closed

Table overflow issue #2325

kesara opened this issue Dec 9, 2024 · 3 comments · Fixed by #2326
Labels
bug Existing features not working as expected
Milestone

Comments

@kesara
Copy link
Contributor

kesara commented Dec 9, 2024

This was tested in WeasyPrint version 62.3 and WeasyPrint version 63.0.
This happens when overflow-wrap is set to break-word or normal. anywhere seems to work fine.

Input:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width initial-scale=1.0">
  <title>Table with Links</title>
  <style>
    table {
      width: 100%;
      max-width: 10px;
      border: 1px solid black;
      overflow-wrap: break-word; /* or normal */
    }

    th td {
      border: 1px solid black;
      padding: 8px;
      text-align: left;
    }

    a {
      margin-right: 8px;
      text-decoration: none;
      color: blue;
    }
  </style>
</head>
<body>
  <h1>Example 1</h1>
  <table>
    <thead>
      <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
        <th>Links</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>
          <a href="https://example.org">123.456.78</a>,
          <a href="https://example.org">234.567.89</a>,
          <a href="https://example.org">345.678.90</a>
        </td>
      </tr>
    </tbody>
  </table>
  <h1>Example 2</h1>
  <table>
    <thead>
      <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
        <th>Links</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>
          <a href="https://example.org">foooooobar</a>,
          <a href="https://example.org">foooooobar</a>,
          <a href="https://example.org">foooooobar</a>
        </td>
      </tr>
    </tbody>
  </table>
  <h1>Example 3</h1>
  <table>
    <thead>
      <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
        <th>Links</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>
          <a href="https://example.org">S 123.456.78</a>,
          <a href="https://example.org">S 234.567.89</a>,
          <a href="https://example.org">S 345.678.90</a>
        </td>
      </tr>
    </tbody>
  </table>
  <h1>Example 3</h1>
  <table>
    <thead>
      <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
        <th>Links</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>
          <a href="https://example.org">S foooooobar</a>,
          <a href="https://example.org">S foooooobar</a>,
          <a href="https://example.org">S foooooobar</a>
        </td>
      </tr>
    </tbody>
  </table>
</body>
</html>


Weasyprint PDF rendering:
Image

Firefox rendering:
Image

@kesara
Copy link
Contributor Author

kesara commented Dec 9, 2024

Better example:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width initial-scale=1.0">
  <title>Table with Links</title>
  <style>
    table {
      width: 100%;
      border: 1px solid black;
    }

    .brwd {
      overflow-wrap: break-word;
    }

    .nrml {
      overflow-wrap: normal;
    }

    .anywhere {
      overflow-wrap: anywhere;
    }
  </style>
</head>
<body>
  <h1>overflow-wrap: normal</h1>
  <table class="nrml">
    <thead>
      <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
        <th>Links</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>
          <a href="https://example.org">foooooooooooooooobar</a>,
          <a href="https://example.org">foooooooooooooooobar</a>,
          <a href="https://example.org">foooooooooooooooobar</a>
        </td>
      </tr>
    </tbody>
  </table>
  <h1>overflow-wrap: break-word</h1>
  <table class="brwd">
    <thead>
      <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
        <th>Links</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>
          <a href="https://example.org">foooooooooooooooobar</a>,
          <a href="https://example.org">foooooooooooooooobar</a>,
          <a href="https://example.org">foooooooooooooooobar</a>
        </td>
      </tr>
    </tbody>
  </table>
  <h1>overflow-wrap: anywhere</h1>
  <table class="anywhere">
    <thead>
      <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
        <th>Links</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>Data foooooooooobar</td>
        <td>
          <a href="https://example.org">foooooooooooooooobar</a>,
          <a href="https://example.org">foooooooooooooooobar</a>,
          <a href="https://example.org">foooooooooooooooobar</a>
        </td>
      </tr>
    </tbody>
  </table>
</body>
</html>

table_1.pdf

@liZe liZe added the bug Existing features not working as expected label Dec 9, 2024
@liZe
Copy link
Member

liZe commented Dec 9, 2024

This bug is caused by a dirty workaround that has been hidden since… 2013.

if minimum and child_text == b' ':

Here, during minimum size calculation, we break the line if we only have a space, because, well, spaces are a very common way to break lines. So:

  • if we have only a space between tags, minimum size works thanks to this hack,
  • if we have text with a space inside between tags, it works because the line can be split by split_first_line,
  • if we have text with a space only at the beginning/end of the text between tags, it fails.

For example, your sample works without the comma between a tags, or with "a a" instead of the comma. With , , it fails.

It only fails with layouts where the minimum size is required (tables and floats for example), but it works for other full-width layouts thanks to the "real" algorithm:

can_break = None
if last_letter is True:
last_letter = ' '
elif last_letter is False:
last_letter = ' ' # no-break space
elif box.style['white_space'] in ('pre', 'nowrap'):
can_break = False
if can_break is None:
if None in (last_letter, first):
can_break = False
elif first in (True, False):
can_break = first
else:
can_break = can_break_text(
last_letter + first, child.style['lang'])

Just as for this code, we should get track of the letters at tags boundaries to detect possible line breaks correctly, or even reuse the real algorithm, but that would much more complicated, and probably much slower.

Or we can just replace the current hack that worked until now by another one that will hopefully work for the next 11 years.

@kesara
Copy link
Contributor Author

kesara commented Dec 10, 2024

Yeah, I noticed that this doesn't happen when there's in-between a tags and a tag text has spaces.
It is one of those edge cases.

kesara added a commit to kesara/WeasyPrint that referenced this issue Dec 10, 2024
liZe added a commit to kesara/WeasyPrint that referenced this issue Dec 10, 2024
@liZe liZe added this to the 64.0 milestone Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants