Skip to content

Apply the /ActualText of marked content in getTextContent (issue 12237) - #22315

Open
abgrad wants to merge 1 commit into
mozilla:masterfrom
abgrad:actualtext-marked-content
Open

abgrad wants to merge 1 commit into
mozilla:masterfrom
abgrad:actualtext-marked-content

Conversation

@abgrad

@abgrad abgrad commented Oct 23, 2026 •

Copy link
Copy Markdown

getTextContent now applies the /ActualText of marked content (section 14.9.4): the first visible glyph of the sequence gets the text, its other glyphs get none, and positions, spaces and line breaks are computed as before. It works the same with and without includeMarkedContent, so the text layer, find and the text under highlight annotations all get it. No new API.

This picks up the approach of #20014 and covers what it misses: named property lists (/Span /P0 BDC), nested sequences (the outermost /ActualText applies), sequences over several lines or without glyphs, a sequence left open at ET, and Form XObjects inside a sequence. Whitespace alone turns the glyphs into spaces; text without a visible char (e.g. the soft hyphen of issue 13226) is ignored.

It fixes the PDFs of issue #12237: Chrome-printed variable fonts whose Type3 glyphs map to U+0000 while a Span names the character.

Corpus check (local and linked test PDFs, first 10 pages, both modes): 1118 of 1121 files give identical text items. Changed:

  • bug1755201.pdf (InDesign small caps): the case is corrected, e.g. "quArterly publicAtion" becomes "quarterly publication".
  • issue19971.pdf page 6 (Chrome, Arabic): "fi" becomes "fi" and most letters are corrected, but in some right-to-left runs Chrome's own /ActualText is shifted by one glyph, which now shows in the text. Page 1, the reference test page, is unchanged.

Tests: api_spec builds its PDFs with assemblePdf, no new files. The PDFDocEncoding, UTF-16BE, non-string and missing /ActualText cases come from #22473 by 0x70b1a5.

@0x70b1a5

0x70b1a5 commented Nov 8, 2026

Copy link
Copy Markdown

We need this change too. We use /ActualText to make pdf.js text match pdftotext for small-caps fonts that decode to the wrong case.

Our version had two more test cases: a UTF-16BE string ( gives "é") and a non-string value (no actualText). Consider adding these.

See #22473

@abgrad
abgrad force-pushed the actualtext-marked-content branch from 9e0e078 to 457706d Compare November 11, 2026 09:51
@abgrad

abgrad commented Nov 11, 2026

Copy link
Copy Markdown
Author

@0x70b1a5 Thanks! I added your four cases as an evaluator unit test (credited in the commit) and switched to your shape: actualText is set only when the property list has a string /ActualText, so existing items keep their shape. Rebased on master as well.

@abgrad
abgrad force-pushed the actualtext-marked-content branch from 457706d to 3f286be Compare November 11, 2026 11:36
@abgrad abgrad changed the title Hand the ActualText of marked content along in getTextContent (issue 12237) Apply the /ActualText of marked content in getTextContent (issue 12237) Nov 11, 2026
@abgrad

abgrad commented Nov 11, 2026

Copy link
Copy Markdown
Author

@0x70b1a5 I reworked this along the lines of #20014: getTextContent now applies the /ActualText itself, in both modes, so small caps like those in bug1755201.pdf come out in the right case without consumer code, and there is no new actualText property. Your four cases are in the new api_spec test.

@0x70b1a5

Copy link
Copy Markdown

Splendid!

The first visible glyph of a marked content sequence with an /ActualText
gets that text and its other glyphs get none, while positions and spaces
are computed as before. The outermost /ActualText applies, also in Form
XObjects, and a sequence left open in a text object ends at ET in both
modes. Whitespace alone turns the glyphs into spaces, and text without a
visible char is ignored. Named property lists are resolved, which also
gives the MCID of such sequences.

The PDFDocEncoding, UTF-16BE, non-string and missing /ActualText test
cases come from PR 22473 by 0x70b1a5.

Co-authored-by: 0x70b1a5 <10970247+0x70b1a5@users.noreply.github.com>
@abgrad
abgrad force-pushed the actualtext-marked-content branch from 3f286be to 019e5ed Compare November 13, 2026 10:00

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants