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 borders: single border display bug with border-collapse: collapse #752

Closed
gandboy91 opened this issue Aug 30, 2021 · 2 comments · Fixed by #761
Closed

table borders: single border display bug with border-collapse: collapse #752

gandboy91 opened this issue Aug 30, 2021 · 2 comments · Fixed by #761

Comments

@gandboy91
Copy link

When some cell borders are hidden (as 2, 3 and 4 cells in example)
There's buggy behavior of table borders in generated pdf.
It's usually ok with default 100% zoom level.
But if it's zoomed in or zoomed out, some borders looks very unstable (cell 3 in example)
Depending on zoom level it can be thinner or thicker than other borders.

example is created with openhtmltopdf sandbox.
html

image

image
image

markup

<table>
  <tr>
    <td>1</td>
    <td class="no-border-right">2</td>
    <td class="no-border-left no-border-right">3</td>
    <td class="no-border-left">4</td>
  </tr>
  <tr>
    <td>5</td>
    <td>6</td>
    <td>7</td>
    <td>8</td>
  </tr>
</table>

css

table {
  border-collapse: collapse;
  border: 1px solid black;
}
table td {
  border: 1px solid black;
  width: 100px;
}
table td.no-border-right {
  border-right: none;
}
table td.no-border-left {
  border-left: none;
}

P.S. even without border collapse, with cellpadding="0" and some tricks
like display only right and bottom cell borders and for all table left and top borders
(to make sure that there's indeed only single border everywhere)
border thickness is displayed buggy when zoom in/zoom out

@danfickle
Copy link
Owner

I think I've found the culprit!

It turns out to be related to anti-aliasing. Specifically, the top and bottom borders for cell 3 are not anti-aliased while all others are. I think this is because all the other borders need to have a bevel (diagonal edge) (which we calculate explicitly) to meet with vertical lines.

You can see this in effect with the magnifier on your operating system. Alternatively, if using Acrobat, you can turn off anti-aliasing of lines by unticking "Edit Preferences -> Page Display -> Smooth line art". Please reply if changing this setting fixes your actual document so I know I'm going in the right direction. The bad news is that there is no way to turn off AA for lines at the document level.

The good news is that for most cases we should be able to disable anti-aliasing by not beveling our lines. This should work well for borders where meeting borders are the same color and thickness. With borders meeting different colors or thickness, there doesn't seem to be a great solution.

I'll start work on this.

danfickle added a commit that referenced this issue Sep 7, 2021
with solid style borders only.

This should stop them being anti-aliased and problematic.

Unfortunately some tests had to be re-proofed for this change.

Additional test kindly provided by @gandboy91
@gandboy91
Copy link
Author

Thank you for your fix and explanation! 👍
Fixing it for one-colored same thickness lines seems enough for most cases I guess :)

Will wait for next release!

danfickle added a commit that referenced this issue Sep 10, 2021
…isable bevels on borders.

Doing so avoids ugly anti-aliasing effects, especially on tables. Property is:
-fs-border-rendering: no-bevel and inherits so can be set at the table level to apply to all cells.

This commit is a better alternative to the work in #755.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants