Skip to content

Squeeze a word running off the page onto it, so its tagged text keeps every letter - #17

Merged
bbertucc merged 2 commits into
mainfrom
page-edge
Oct 6, 2026
Merged

bbertucc merged 2 commits into
mainfrom
page-edge

Conversation

@bbertucc

@bbertucc bbertucc commented Oct 6, 2026

Copy link
Copy Markdown
Member

Newsletter-Winter-2016-Final failed text_lost with "5 characters of the tagged text are not readable" on pages 2 and 3.

The cause: words that run off the page's right or left edge. Extractors drop glyphs off the page. The source word's last glyph started just inside the edge, so it was kept. Ours, stretched to the same box in Helvetica, started just outside, so it was dropped ("Evan" read back as "Eva").

The fix clips the overlay word's box to the page horizontally, so the whole tagged word is drawn on the page. The text a screen reader gets is unchanged.

The test uses a monospaced source word whose narrow last letter starts just inside the page edge. It fails before the fix with text_lost. The newsletter (kept local) now tags with pixels identical and text preserved.

🤖 Generated with Claude Code

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All checks pass. I confirmed the new test fails with text_lost once placed is reverted to box: w.box, so it guards the fix.

I also checked a case the PR doesn't test. mupdf's extractor already drops a word drawn entirely off the page. So the clamp in src/tag.ts:252 never produces an inverted box (x0 > x1, which Overlay.word would draw at size 0.5 and scale 0.1), and inverted boxes can't reach the overlay today.

Non-blocking notes

  • src/tag.ts:252 Math.max(w.box[0], page[0]): the left-edge half of the clamp has no test. Only the right edge (Hail at x=276.4) is exercised. A word starting at x=-10 extracts with box [-1.34, …] and is clamped to 0, but the test suite never checks that path.
  • src/tag.ts:252: the clamp is horizontal only. The same glyph-dropping could hit a word that crosses the top or bottom edge. Not reached by any known input.
  • If extraction ever keeps off-page glyphs (for example, a changed mupdf stext option), placed would produce x0 > x1. A guard such as Math.min(x0, x1) would rule that out.

Accessibility impact: Words cut by the page edge now keep every letter in their tagged text, and nothing a screen reader gets is lost or reordered.

bbertucc and others added 2 commits October 6, 2026 18:09
… every letter

Extractors drop glyphs off the page. A source word whose last glyph starts
just inside the page edge kept it, but ours, stretched to the same box in
another font, could start just outside, and the text gate failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All checks pass.

My earlier note that the left-edge clamp had no test is fixed in 0dd1f0a. I put w.box[0] back in place of Math.max(w.box[0], page[0]) in src/tag.ts:279, and the new iWall at x=-4 case then failed with text_lost ("Page 1 lost text."). So the test guards both edges now.

Non-blocking notes

  • These are unchanged since 02bf560. The clamp is horizontal only, and nothing guards against x0 > x1 if extraction ever keeps glyphs that are off the page. No known input reaches either case.

Accessibility impact: Words cut by either side edge of the page now keep every letter in their tagged text, and nothing a screen reader gets is lost or reordered.

@bbertucc
bbertucc merged commit cbd1804 into main Oct 6, 2026
2 checks passed
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