Skip to content

Only set the Glyph.prototype.originalCharCode property when debugging - #22350

Merged
Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:Glyph-conditional-originalCharCode
Oct 27, 2026
Merged

Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:Glyph-conditional-originalCharCode

Conversation

@Snuffleupagus

Copy link
Copy Markdown
Collaborator

This property was added in PR #13494 specifically for the debugger, however it wasn't actually used anywhere else.
More recently PR #20334 started using that property in getTextContent, however it's not clear to me that doing so was necessarily correct. First of all, note that Glyph instances already contain an isSpace property. Secondly, and more importantly, using the "raw" charCode may be wrong in composite fonts with multi-byte strings.

Note how the isSpace property is determined in the PDF.js code:

pdf.js/src/core/fonts.js

Lines 3721 to 3732 in 8e62d24

// Space is char with code 0x20 and length 1 in multiple-byte codes.
const glyph = this._charToGlyph(
charcode,
length === 1 && chars.charCodeAt(i - 1) === 0x20
);
glyphs.push(glyph);
}
} else {
for (let i = 0, ii = chars.length; i < ii; ++i) {
const charcode = chars.charCodeAt(i);
const glyph = this._charToGlyph(charcode, charcode === 0x20);
glyphs.push(glyph);
which is based on the following specification text:

Word spacing shall be applied to every occurrence of the single-byte character code 32 in a string when using
a simple font or a composite font that defines code 32 as a single-byte code. It shall not apply to occurrences of the byte value 32 in multiple-byte codes.

This property was added in PR 13494 specifically for the debugger, however it wasn't actually used anywhere else.
More recently PR 20334 started using that property in `getTextContent`, however it's not clear to me that doing so was necessarily correct. First of all, note that `Glyph` instances already contain an `isSpace` property. Secondly, and more importantly, using the "raw" charCode may be wrong in composite fonts with multi-byte strings.

Note how the `isSpace` property is determined in the PDF.js code:
https://github.com/mozilla/pdf.js/blob/8e62d2475645a9a625b3e98964fc241d3f9c144f/src/core/fonts.js#L3721-L3732
which is based on [the following specification text](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#page=253):
> Word spacing shall be applied to every occurrence of the single-byte character code 32 in a string when using
a simple font or a composite font that defines code 32 as a single-byte code. It shall not apply to occurrences of
the byte value 32 in multiple-byte codes.
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Reference tests

Results for 7b0a38d (run, references from mozilla/pdf.js.refs@b11d8aa217).

Platform Status Tests Total runtime Errors Different FBF No reference Report
Linux ⚠️ 1411 11m 59s 0 1 0 0 view differences
Windows ⚠️ 1411 15m 41s 0 1 0 0 view differences

The report is kept for 30 days and replaced by the next run.

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Viewer preview

🗑️ Viewer previews removed.

@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.58%. Comparing base (8e62d24) to head (7b0a38d).

Files with missing lines Patch % Lines
src/core/fonts.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22350      +/-   ##
==========================================
- Coverage   90.59%   90.58%   -0.01%     
==========================================
  Files         278      278              
  Lines       68535    68536       +1     
==========================================
- Hits        62088    62085       -3     
- Misses       6447     6451       +4     
Flag Coverage Δ
browsertest 66.19% <75.00%> (-0.05%) ⬇️
fonttest 8.99% <0.00%> (-0.01%) ⬇️
integrationtest 69.55% <75.00%> (+<0.01%) ⬆️
unittest 61.26% <75.00%> (-0.01%) ⬇️
unittestcli 59.00% <75.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 27, 2026
@codspeed

codspeed Bot commented Oct 27, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks
⏩ 174 skipped benchmarks1


Comparing Snuffleupagus:Glyph-conditional-originalCharCode (7b0a38d) with master (8e62d24)

Open in CodSpeed

Footnotes

  1. 174 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@Snuffleupagus

Copy link
Copy Markdown
Collaborator Author

While it's difficult to tell if the test "failures" are a problem just from the reference images, comparing issue15910.pdf locally in the viewer with textLayer-debugging enabled shows that this patch is an improvement:

  • master

    master
  • This patch

    patch

@calixteman calixteman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thank you.

@Snuffleupagus
Snuffleupagus merged commit 2a1b241 into mozilla:master Oct 27, 2026
32 checks passed
@Snuffleupagus
Snuffleupagus deleted the Glyph-conditional-originalCharCode branch October 27, 2026 12:32
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 27, 2026

This branch was successfully deployed

1 active deployment
sync_pdfs — 7b0a38d2 Deployed Oct 27, 2026 by Snuffleupagus via request #627
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants