Skip to content

[api-major] Generate the non-embedded fonts with Hellbox, at the PDF widths - #22419

Open
calixteman wants to merge 2 commits into
mozilla:masterfrom
calixteman:hellbox
Open

calixteman wants to merge 2 commits into
mozilla:masterfrom
calixteman:hellbox

Conversation

@calixteman

Copy link
Copy Markdown
Contributor

This replaces the bundled Foxit Type1 and Liberation Sans files with Hellbox glyph data (Arimo, Tinos, Liberation Mono, Noto symbols) and a small generator (Rust to Wasm, with a JS fallback when Wasm isn't available).

It has few advantages:

  • Non-embedded standard fonts (and fonts mapped to them, e.g. Arial, Calibri, Courier New) get a generated font. It'll be especially useful on Android where we almost only have Noto font as fallback which cause some real rendering problems because of the glyph widths;
  • Widths are fitted, not distorted. Each glyph is scaled to its PDF width while its stems keep the font-wide weight, so stretched letters don't turn bold and squeezed ones don't turn thin. Black fonts are actually emboldened to weight 900.
  • XFA substitutes use the same generator, and their widths are now stored by Unicode code point.
  • it uses modern fonts.

It has few inconvenients:

  • it makes the overall size bigger.
  • the Liberation fonts we used have some hinting data where the new ones don't but as far as I can tell, nowadays it isn't a big deal.

@codecov-commenter

codecov-commenter commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.96154% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.50%. Comparing base (c7ca8a3) to head (33bc56d).

Files with missing lines Patch % Lines
external/hellbox/hellbox.js 76.87% 68 Missing ⚠️
src/core/hellbox.js 94.59% 4 Missing ⚠️
src/core/fonts.js 98.21% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22419      +/-   ##
==========================================
- Coverage   90.58%   90.50%   -0.08%     
==========================================
  Files         279      282       +3     
  Lines       68598    68637      +39     
==========================================
- Hits        62140    62121      -19     
- Misses       6458     6516      +58     
Flag Coverage Δ
browsertest 66.54% <83.84%> (+0.25%) ⬆️
fonttest 9.09% <13.11%> (+0.12%) ⬆️
unittest 62.74% <74.61%> (+1.47%) ⬆️
unittestcli 60.36% <74.80%> (+1.33%) ⬆️

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 Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Viewer preview

Commit 33bc56d (build logs).

Viewer Build Preview
Modern (gulp generic) ✅ viewer.html
Legacy (gulp generic-legacy) ✅ viewer.html

Previews are removed when the PR closes and may be pruned after 30 days without an update.

@codspeed

codspeed Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 13.57%

⚡ 1 improved benchmark
✅ 87 untouched benchmarks
⏩ 174 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ getOperatorList page 1 (alphatrans.pdf) 15.7 ms 13.9 ms +13.57%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing calixteman:hellbox (33bc56d) with master (c7ca8a3)

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. ↩

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Nov 2, 2026
@Snuffleupagus

Copy link
Copy Markdown
Collaborator

Tagging this [api-major], since it seems like a large/significant enough change to warrant that.

@Snuffleupagus Snuffleupagus changed the title Generate the non-embedded fonts with Hellbox, at the PDF widths [api-major] Generate the non-embedded fonts with Hellbox, at the PDF widths Nov 2, 2026
@Snuffleupagus

Snuffleupagus commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator
  • it makes the overall size bigger.

I'm guessing that's mostly because of the hellbox_nowasm_fallback.js file, hence I wonder how common it is nowadays for Wasm to be unavailable in Firefox?

@Snuffleupagus

Copy link
Copy Markdown
Collaborator

Could the first two commits perhaps be moved to its own PR, to make this one a little bit smaller?

Comment thread src/core/unicode.js Resolved
Comment thread src/core/fonts.js Resolved
@calixteman

Copy link
Copy Markdown
Contributor Author
  • it makes the overall size bigger.

I'm guessing that's mostly because of the hellbox_nowasm_fallback.js file, hence I wonder how commit it is nowadays for Wasm to not be available in Firefox?

No we don't have such stats and they'd be very likely meaningless because people disabling wasm (for fingerprinting reasons) very likely disabled telemetry too. I'll try see if we can have at least an upper bound.

Comment thread src/display/font_loader.js Resolved
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Nov 2, 2026
@Snuffleupagus Snuffleupagus linked an issue Nov 2, 2026 that may be closed by this pull request
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Reference tests

Results for 33bc56d (run, references from mozilla/pdf.js.refs@d16403bcaa).

Platform Status Tests Total runtime Errors Different FBF No reference Report
Linux ⚠️ 1414 13m 49s 0 215 0 0 view differences
Windows ⚠️ 1414 16m 42s 0 209 0 0 view differences

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

@Snuffleupagus

Copy link
Copy Markdown
Collaborator

Given that Firefox will download some data on demand (e.g. AI models), would it perhaps be feasible to not bundle the *_nowasm_fallback.js files by default in Firefox and instead fetch them only when needed for users that have disabled Wasm?

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Nov 2, 2026
@calixteman

Copy link
Copy Markdown
Contributor Author

Given that Firefox will download some data on demand (e.g. AI models), would it perhaps be feasible to not bundle the *_nowasm_fallback.js files by default in Firefox and instead fetch them only when needed for users that have disabled Wasm?

That's a good idea for sure (we could use to download Chinese fallback fonts for example) but I'm pretty sure that people who disable wasm, disable AI too and very likely disable remote settings.

@Snuffleupagus

Snuffleupagus commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Glancing at the browsertest results, there's obviously a lot of movement (which is expected), however there's also e.g. bug1802506 where the ends of the checkmark are now noticeably more jagged than before.

@Snuffleupagus Snuffleupagus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One thing I like about this patch is that it reduces the number of XFA special-cases in the evaluator/font code.

Comment thread src/core/evaluator.js Resolved
Comment thread src/core/glyf.js Resolved
Comment thread src/core/fonts.js Resolved
Comment thread src/core/fonts.js Resolved
Comment thread src/core/hellbox.js Resolved
Comment thread test/unit/api_spec.js Resolved
Comment thread src/display/font_loader.js Resolved
Comment thread src/display/font_loader.js Resolved
Comment thread src/display/font_loader.js Resolved
Comment thread src/display/font_loader.js Resolved
@calixteman

Copy link
Copy Markdown
Contributor Author

Glancing at the browsertest results, there's obviously a lot of movement (which is expected), however there's also e.g. bug1802506 where the ends of the checkmark are now noticeable more jagged than before.

It is how the glyph is now:
https://fonts.google.com/noto/specimen/Noto+Sans+Symbols+2?preview.text=%E2%9C%94&specimen.preview.text=%E2%9C%94

Replace bundled font programs with glyph data. Generate replacement fonts
with PDF widths and substitutes for missing XFA fonts. Use a JavaScript
fallback when WASM is disabled or fails to load.
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Nov 3, 2026
@calixteman

Copy link
Copy Markdown
Contributor Author

I reduced the size of the fallback in using terser.
A possibility is to compress the different fallbacks we've in using brotli for example and decompress them before loading.
It only matters for Firefox, I suppose (likely wrongly) that people using the lib handle themselves how those files are delivered (compressed or not).

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Nov 3, 2026

@Snuffleupagus Snuffleupagus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Given the size/scope of this, I think that we can probably just land this now to get it into Firefox Nightly as soon as possible since that should help with real-world testing.
Any problems can then be dealt with in follow-up patches.

r=me, thanks.

This branch was successfully deployed

1 active deployment
sync_pdfs — 33bc56da Deployed Nov 3, 2026 by calixteman via request #706
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.

Replace most Foxit fonts with Liberation fonts

3 participants