Skip to content

Fix accents cut off in the first line of table cells - #1797

Open
lbesecker195 wants to merge 1 commit into
foliojs:masterfrom
lbesecker195:fix/table-cell-accent-clipping
Open

Fix accents cut off in the first line of table cells#1797
lbesecker195 wants to merge 1 commit into
foliojs:masterfrom
lbesecker195:fix/table-cell-accent-clipping

Conversation

@lbesecker195

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix for #1720.

A table cell clips its text to a rectangle that starts at the top padding. The first line of text starts at the font ascender. Accented capitals rise above the ascender. In Helvetica, the ascender is 718, Ä reaches 901, and Õ reaches 917. The top of each accent was cut off, so the first line showed OUOA instead of ÕÜÖÄ. Later lines were fine because the line above leaves room. That is also why adding padding did not help: the mask follows the padding.

lib/table/render.js now extends the mask upward into the top padding by the part of the font bbox above the ascender, scaled to the font size. The extension is capped at the top padding, so the mask never goes past the cell. The sides and the bottom are unchanged. Standard fonts store the bbox as an array in 1000 units, and embedded fonts use the fontkit bbox in font units, so the helper handles both.

For the default Helvetica 12pt with the default 0.25em padding, the mask starts 2.556pt higher, and the padding is 3pt. With padding: 0, the mask does not move, so accents in the first line are still clipped in that case.

Tests in tests/unit/table.spec.js capture the clip rectangle:

  • With Helvetica and the default padding, the top moves up by the bbox overshoot, and the bottom still stops at the padding.
  • With a 1pt padding, the top stops at the cell edge.
  • With embedded Roboto, the top uses the fontkit bbox.

Checklist:

  • Unit Tests
  • Documentation N/A
  • Update CHANGELOG.md
  • Ready to be merged

Verification

yarn test
Without the render.js change 504 passed, 3 failed (the new tests)
With the change 507 passed, 60 test files

The visual table snapshots pass unchanged. yarn lint and prettier --check on the changed files pass.

I also rendered the table from the issue with pdf2png from the visual tests, in a scratch spec that is not part of this PR. With Helvetica, the first line read OUOA õüöä before the change and ÕÜÖÄ õüöä after. With Roboto, the image was byte-identical before and after, since its ascender already covers these glyphs.

🤖 Generated with Claude Code

The text mask of a table cell started exactly at the top padding, where
the first line begins at the font ascender. Accented capitals such as
Ä and Õ rise above the ascender, so their accents were clipped in the
first line only. Extend the mask into the top padding by the height of
the font bbox above the ascender, without going past the cell.

Fixes foliojs#1720

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant