Fix accents cut off in the first line of table cells - #1797
Open
lbesecker195 wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
OUOAinstead 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.jsnow 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.25empadding, the mask starts 2.556pt higher, and the padding is 3pt. Withpadding: 0, the mask does not move, so accents in the first line are still clipped in that case.Tests in
tests/unit/table.spec.jscapture the clip rectangle:Checklist:
Verification
yarn testrender.jschangeThe visual table snapshots pass unchanged.
yarn lintandprettier --checkon the changed files pass.I also rendered the table from the issue with
pdf2pngfrom the visual tests, in a scratch spec that is not part of this PR. With Helvetica, the first line readOUOA õüöä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