378 Commits
Author SHA1 Message Date
Calixte Denizet 6dbf5a89aa Get the bidi classes from the Unicode data in bidi()
The hand-written ranges gave a wrong class to many characters (e.g. ₪, €,
punctuation, Hebrew presentation forms, U+FEFF), hence a wrong reordering in
the text layer and in find. The table is generated from DerivedBidiClass.txt,
and surrogate pairs are now kept together.
2026-11-24 22:34:12 +01:00
Jonas Jenwald d874053ca6 Merge pull request #22580 from mozilla/update-qcms-0.0.1
Update qcms bindings to version 0.0.1
2026-11-22 21:44:37 +01:00
Jonas Jenwald 707d23cb45 Merge pull request #22579 from mozilla/update-quickjs-0.0.1
Update QuickJS sandbox to version 0.0.1
2026-11-22 21:42:33 +01:00
Jonas Jenwald 0d460b9537 Merge pull request #22578 from mozilla/update-openjpeg-0.0.1
Update OpenJPEG decoder to version 0.0.1
2026-11-22 21:42:11 +01:00
github-actions[bot] edf80373c2 Update qcms bindings to version 0.0.1 2026-11-22 16:21:47 +00:00
github-actions[bot] 82bf839523 Update QuickJS sandbox to version 0.0.1 2026-11-22 15:38:43 +00:00
github-actions[bot] 24c43064ef Update OpenJPEG decoder to version 0.0.1 2026-11-22 14:55:45 +00:00
github-actions[bot] 5ce33625ec Update JBIG2 decoder to version 0.0.1 2026-11-22 14:06:28 +00:00
Calixte Denizet 5808a188a5 Configure Gulp to emit named Firefox worker chunks 2026-11-20 17:28:27 +01:00
Calixte Denizet ae629c08bf Update Hellbox
The Unicode tables are coded with the range coder of Hellbox: unicode.bin is 2,639 bytes instead of 14,262, the Wasm module 131,848 bytes instead of 132,729, and the JS fallback 60,131 bytes with Brotli instead of 59,029.
2026-11-15 17:29:07 +01:00
Jonas Jenwald 06e4ecb51b [api-major] Compress the binary CMap files with Brotli
While the binary CMap format is fairly efficient already, by also compressing them maximally with Brotli we can reduce their size even further.
The decompression is done on load in the worker-thread, and thanks to the existing caching it only needs to happen *once* per file. By utilizing the `BrotliStream` class all builds/environments can use these smaller files, and in e.g. Firefox (which supports native decompression) even the largest binary CMap files are decompressed in *under* `1` millisecond.

*Note:* This reduces the size of the `gulp mozcentral` bundle by `320076` bytes, i.e. over 312 kilo-bytes.
2026-11-12 18:46:24 +01:00
Jonas Jenwald 28aaa49007 Enable "large window" support in the Brotli JS decoder (issue 22487)
While the Brotli decoder does contain an `enableLargeWindow` function, it however does *not* currently expose any option for it. Note that according to [this document](https://pdfa.org/download-area/publications/pdf-extension-brotli.pdf#%5B%7B%22num%22%3A224%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C51.023%2C538.141%2Cnull%5D), a Brotli decoder needs to have "large window" support.

Hence, until an option is exposed upstream, we can patch that in via the "release-brotli" gulp task.
2026-11-09 22:48:16 +01:00
Calixte Denizet 173e54bdee Lazily initialize the Brotli JS decoder
The upstream decode.js calls `makeBrotliDecode()` at module evaluation,
which unpacks the 122KB dictionary and builds the lookup tables each
time the worker starts, even if the PDF doesn't contain any Brotli
stream.
So export the factory instead and only call it the first time the
fallback is actually used. The `release-brotli` task now applies this
change to the downloaded file.
2026-11-05 19:25:39 +01:00
Calixte Denizet f16437faec Generate non-embedded standard fonts with Hellbox
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.
2026-11-03 18:03:47 +01:00
Calixte Denizet 0d5441e67d Improve the performances of the jpx decoder and reduce its size and the jbig2 one
The fallbacks are now built with wasm2js instead of the deprecated WASM=0 and only contain the converted modules.
The compilation of the openjpeg decoder has been improved too.
2026-10-15 13:09:50 +02:00
Calixte Denizet a3beacc1a3 Ship the QuickJS license files with the sandbox
Add the upstream QuickJS and pdf.js.quickjs licenses and copy them alongside quickjs-eval.js and quickjs-eval.wasm.

Fixes #22143.
2026-10-14 17:38:34 +02:00
Calixte Denizet a72eb1599f Fix JPX images with subsampled components or mismatched component counts
Update the OpenJPEG decoder in order to support any number of components, to pad the missing ones to match the color space and to upsample the subsampled ones.

Use the last filter to detect JPX and JBIG2 images.
2026-10-13 13:21:13 +02:00
Calixte Denizet 89b3bee995 Fit the Nova zoom select in the compact toolbar (bug 2075731)
In compact density the toolbar shrinks to 32px but the select kept its 32px
min-height, so its border overflowed and was clipped. Use the small button
size there, like the 24px toolbar buttons.
2026-10-09 16:34:58 +02:00
calixteman c38cf7b4b5 Replace webpack-stream with the Webpack API
Collect Webpack output in memory as Vinyl files and close the compiler
after each run. Log compilation diagnostics and fail the stream on errors.

Remove webpack-stream and its unused dependencies, including memory-fs
and Vinyl 2.
2026-10-05 19:29:15 +02:00
calixteman f786355550 Update OpenJpeg to 8314119b067c0fc77834731168daaebd379fdb12 2026-10-01 15:43:30 +02:00
Tim van der Meij 7ba4589a47 Enable the unicorn/prefer-short-arrow-method linting rule
This makes the code a bit more compact, and consistent with newer code
where we already use this. For more information about the rule, see
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-short-arrow-method.md.
2026-09-22 20:16:39 +02:00
Calixte Denizet c3a2798726 Update JBIG2 decoder to pdfium@bb1f9f71 2026-09-18 22:19:18 +02:00
Jonas Jenwald 9cad39aec7 Replace forEach callback functions with arrow functions
This improves consistency in the code-base, and it's also a tiny bit shorter which cannot hurt.
2026-09-09 13:56:07 +02:00
calixteman c5af039649 Replace kleur with util.styleText
All supported Node.js versions provide `util.styleText`. Preserve the existing color-enabling rules and the styles used by the build and test output.
2026-09-06 18:24:18 +02:00
Tim van der Meij 5b20b7b78e Merge pull request #21879 from Snuffleupagus/callback-arrow-fn
Replace simple callback functions with arrow functions
2026-09-03 21:00:32 +02:00
Jonas Jenwald cd8c463ed9 Replace simple callback functions with arrow functions
This improves consistency in the code-base, and it's also slightly shorter which cannot hurt.
2026-09-03 12:53:53 +02:00
Calixte Denizet fcea525640 Use moz-message-bar for the Firefox features notification (bug 2057608)
Bug 2066198 lets the PDF viewer load the moz-message-bar module from a
chrome: URL. Add the required CSP and localization entries, and preserve viewer
focus on dismissal.
2026-09-03 09:13:36 +02:00
Calixte Denizet 26341dcdbd Add JSDoc linting
Enable rules that validate existing JSDoc comments and fix the reported issues.
2026-08-31 11:57:30 +02:00
Tim van der Meij e9c4923e1d Merge pull request #21783 from calixteman/improve-firefox-watch-builds
Improve Firefox watch builds
2026-08-15 16:37:08 +02:00
calixteman 25ef610af4 Improve Firefox watch builds 2026-08-15 15:36:42 +02:00
Calixte Denizet fd8ed8422f Nova-ify the viewer (bug 2063405) 2026-08-14 17:20:05 +02:00
calixteman b6887013e0 Merge pull request #21725 from Jaybhade/fix-math-clamp-operand-order
Fix the two MathClamp calls the prefer-math-clamp fixer mis-ordered
2026-08-13 19:18:56 +02:00
calixteman deefadb61c Merge pull request #21750 from calixteman/fix-liberation-license
Fix the license file for the bundled Liberation fonts
2026-08-10 19:28:44 +02:00
Calixte Denizet 4315a4be31 Fix the license file for the bundled Liberation fonts
The `LiberationSans-*.ttf` files are the unmodified upstream release of
Liberation Sans 1.07.4: their `name` table reports `Version 1.07.4` and
points at the Liberation Fonts license, and their glyph count, cmap
coverage and advance widths match the upstream 1.07.4 build exactly.

That version is licensed under the GPL v2 with the Liberation font
exception, but `LICENSE_LIBERATION` contains the SIL Open Font License
1.1, which only applies starting with Liberation 2.0.

So replace it with the `License.txt` and `COPYING` files shipped with the
1.07.4 release, and document in the README where the fonts come from and
what needs to be updated when they're replaced.

It fixes #21746.
2026-08-10 19:20:26 +02:00
Calixte Denizet 79ccf813a4 Fix the license text bundled for pdf.js.qcms
The file `external/qcms/LICENSE_PDFJS_QCMS` contained a BSD-2-Clause text
(copied from the openjpeg one), whereas https://github.com/mozilla/pdf.js.qcms
is released under the MIT license.

It fixes #21745.
2026-08-10 17:25:53 +02:00
Jayesh Bhade a163deb6eb Fix the two MathClamp calls the prefer-math-clamp fixer mis-ordered
The rule rewrites `Math.max(C, Math.min(A, B))` to `MathClamp(A, C, B)`, always
taking the inner call's first operand as the value. `Math.min` is commutative,
so the value is just as often the second one, and then the fixer swaps it with
the upper bound: the result is `Math.min(C, v)`, which no longer applies the
lower bound at all. Both call sites the fixer rewrote hit that case, so the
max-outer patterns are now reported without a fix.

Reporting them still needs its own message. `Math.max(C, Math.min(A, B))` is
only `MathClamp(A, C, B)` when `C <= B`, and the rule can't know whether that
holds, so telling the reader to "use MathClamp" is wrong advice. The message
states the condition instead, and `useClamp` is left to the min-outer patterns,
which are exact.

In `PSStackBasedInterpreter.build` the outputs were therefore never clamped up
to the Range minimum. The interpreter runs whenever `PSStackToTree` can't turn
the program into a tree — a stack-shrinking `if`, or a `copy`/`index`/`roll`
whose operand isn't a constant — and it then let a Type 4 function return e.g.
-1.5 for a component declared as `/Range [0 1]`.

In `SplitView.#clampFirstSize` the first pane's size was never clamped up to
`#minSize`: dragging the resizer past it wrote a negative `flexGrow`.

The existing range-clamping test only checked the upper bound, which is the one
the wrong operand order preserves.
2026-08-08 00:21:33 +05:30
calixteman fc01f7d033 Enable the regexp/no-super-linear-move ESLint rule
It flags the regexes whose search is quadratic in the input length, like
the autolinker and XFA-path ones fixed recently.

The three existing offenders: `\s*` matched the CSS indentation but also
the line terminators that make `^` match with the `m` flag (the
preprocessed CSS is unchanged), `(\d+)` made every digit of a number a
candidate start position, and `/T.*$/` could fail on the `$` and
backtrack since `.` doesn't match a line terminator.
2026-08-04 18:29:27 +02:00
Jonas Jenwald ee59db5018 Replace simple return if statements with ternary operators
In a couple of cases, where a boolean is returned, it's also possible to use an OR operator rather a ternary.

*Note:* This patch reduces the size of the `gulp mozcentral` bundle by `960` bytes.
2026-07-31 12:24:08 +02:00
calixteman e7acffcef3 Update qcms wrapper
Few performance improvements have been made in the qcms wrapper, see:
https://github.com/mozilla/pdf.js.qcms/commit/2ae4ee72334782928210ba4050e3e77d9b2d35be
2026-07-27 20:33:49 +02:00
calixteman 850020a84e Address follow-up review comments in coverage_search.mjs
Use a Headers object for the request and log informational progress
messages via console.log instead of console.error.
2026-07-19 21:54:45 +02:00
calixteman e6c7ab5425 Skip the cache existence check when --no-download is set
Move the `fs.existsSync(indexPath)` check below the `--no-download`
early return: in that mode the check is unused (the read after
refreshIndex already validates existence), so it's wasted disk I/O.
2026-07-19 16:42:05 +02:00
calixteman c7dc7d7dd0 Sanitize the cached ETag and index to satisfy CodeQL
Address two CodeQL findings on the per-test index downloader:

- "File data in outbound network request": validate the cached ETag
  against the RFC 7232 grammar before sending it as If-None-Match, so
  the cache file's contents can't be injected into the request header.
- "Network data written to file": cache the re-serialized JSON
  (JSON.stringify(JSON.parse(...))) instead of the raw response body,
  so only well-formed JSON produced by our own serializer is written.
2026-07-19 16:13:20 +02:00
calixteman d504000012 Download the per-test coverage index
`coverage_search` now fetches `per-test-index.json` from the pdf.js.refs
gh-pages branch, caches it locally, and only re-downloads it (via ETag)
when it changed, so querying which ref tests cover a line/function no
longer needs a local `--coverage-per-test` build. `--no-download` reuses
the cached index offline and `--index` points at a local one.

`browsertest` and `makeref` accept the same `--code` filter to run (or
regenerate refs for) only the covering tests, dropping any covered IDs
that aren't in this branch's manifest so the run isn't rejected.
2026-07-19 15:37:05 +02:00
Jonas Jenwald f0822e527e Replace a couple of indexOf calls with startsWith
These cases weren't detected/fixed by the following ESLint plugin rule; see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-starts-ends-with.md

Additionally, replace the `if` with a ternary statement in the `external/builder/builder.mjs` file since this patch touches that code anyway.
2026-07-09 13:56:24 +02:00
Nicolò Ribaudo b9609d0365 Update to Babel 8 2026-06-30 10:45:15 +02:00
calixteman 7a7e4fd382 Update quickjs to rev 3d5e064e9dd67c70f7962836505a7fa067bf0a4e 2026-06-08 09:26:36 +02:00
Jonas Jenwald 6d8d6f1349 Revert "Remove unused variables with the Babel plugin" 2026-05-26 21:00:25 +02:00
Nicolò Ribaudo 2691868904 Remove unused variables with the Babel plugin
- functions were already removed
- variables can be removed when their initializer does not have side effects
- classes can be removed when they have no static blocks

Fixes #21337
2026-05-26 16:35:57 +02:00
Calixte Denizet 7bda0fc97c Enable 'eslint-plugin-regexp' and fix existing findings
Enable the recommended preset and fix or per-line-disable the 78
findings it surfaces. Most are equivalent rewrites, intentional
patterns (control chars, the whatwg email regex, autolinker URL regex)
keep their behavior via targeted disables.
2026-05-25 14:31:55 +02:00
Calixte Denizet f8f497a03a Add a lint-chmod task to catch stray executable bits 2026-05-14 13:55:14 +02:00