100 Commits
Author SHA1 Message Date
Jonas Jenwald 1316be0dca Directly call Set.prototype.delete in the ChunkedStreamManager code
There's no point in first checking if a value exists in a Set before deleting it, and this is just a left-over from before the code used Maps and Sets.

Also, remove a couple of unnecessary comments describing how `Set.prototype.add` works (when those where added there wasn't much Set usage in the code-base).
2026-10-03 18:38:26 +02:00
Jonas Jenwald bcf89431d5 Avoid creating a pointless requestId in the ChunkedStreamManager.prototype._requestChunks method
In cases where all the requested chunks are already available, and dispatching a range-request thus isn't necessary, there's no point in creating an unused `requestId` nor keeping track of it since it'll never be accessed given the early return.
2026-10-03 17:18:28 +02:00
Jonas Jenwald 1d29095df7 Convert SupportedImageMimeTypes into a Set
Using `Set.prototype.has` should be preferable to `Array.prototype.includes`, and given that `Iterator.prototype.join` is [supported in Firefox](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/join#browser_compatibility) (and polyfilled elsewhere) creating the string-representation isn't a problem.
2026-10-03 16:03:17 +02:00
Jonas Jenwald edd591f54b Remove handling of standalone number entries in the compiled font-info
After the previous patch this code is no longer used.
2026-10-03 14:11:31 +02:00
Jonas Jenwald e43c8ebf23 Stop exporting the Font ascent and descent by default
The only main-thread usage of these properties are in a fallback code-path in the `TextLayer` code, see below, however in that case these properties are accessed via the `TextStyle` object rather than through the font-info:
 - https://github.com/mozilla/pdf.js/blob/87a106c03447d05ab8d759d5f9fa888310a7299e/src/display/text_layer.js#L566-L579

 - https://github.com/mozilla/pdf.js/blob/87a106c03447d05ab8d759d5f9fa888310a7299e/src/display/api.js#L1187-L1194

*Note:* The code to write and read numbers in the compiled font-info will be removed in a follow-up, to make it easier to re-instate that code in the future.
2026-10-03 14:03:49 +02:00
Jonas Jenwald 02aa7f5e91 Stop passing extra properties to the FontInfo class
The `FontInfo` class doesn't use the `extra` properties for anything, and they are already exposed via the `FontFaceObject` instance which is how the debuggers access those properties.
2026-10-03 11:28:43 +02:00
Jonas Jenwald f8e53e0e0c Stop exporting the Font name by default
The only main-thread usage of this property is in the debuggers, hence we don't need to export it as part of the "compiled" font-info.
2026-10-02 23:14:11 +02:00
Jonas Jenwald ef62f31f24 Merge pull request #22035 from Snuffleupagus/FontInfo-shadow
Shadow the getters in `FontInfo`, `CssFontInfo`, and `SystemFontInfo` (PR 20197 follow-up)
2026-10-02 16:41:09 +02:00
Jonas Jenwald db561fecc6 Shadow the getters in FontInfo, CssFontInfo, and SystemFontInfo (PR 20197 follow-up)
Prior to PR 20197 each font-instance had just a single copy of all its relevant font-properties on the main-thread, however that's unfortunately no longer the case.
Given how the compilation was implemented, every single time that a font-property is accessed on the main-thread it'll now be re-parsed. Not only does this seem inefficient, especially for properties needed e.g. during text-rendering, but it'll lead to (potentially) a lot of duplicated object creation.

Consider what currently happens when rendering all pages of the following PDFs:
 - `tracemonkey.pdf` contains `24` separate fonts, but the `fontMatrix`-property is re-parsed a whopping `1009` times (once per `showText` operator).

 - `standard_fonts.pdf` contains `14` separate fonts, however we create no less than `186` separate `StandardFontInfo` instances.

 - `xfa_bug1716816.pdf` contains `4` separate fonts, however we create no less than `45` separate `CssFontInfo` instances.

This is obviously not limited to just the font-properties listed above, but those are mere examples to illustrate the problem.
By shadowing the font-property getters on the main-thread, obviously with the exception of `FontInfo.prototype.data`, we only need to parse each font-property *once* per font-instance.

*Note:* Unfortunately this *increases* the size of the `gulp mozcentral` bundle by `792` bytes, but that cannot really be helped since this seems like the correct thing to do regardless.
2026-10-02 15:25:24 +02:00
Jonas Jenwald a00ad131fd Introduce a helper to reduce duplication when reading compiled buffer-data from fonts
Currently the `FontInfo.prototype.{data, cssFontInfo, systemFontInfo}` getters duplicate virtually the same code when reading buffer-data, which seems completely unnecessary.

*Note:* This reduces the size of the `gulp mozcentral` bundle by `738` bytes, and with the upcoming worker-rendering this saving will be doubled.
2026-10-02 15:25:09 +02:00
Jonas Jenwald dc7ac33fcd Directly lookup entries in the cidToGidMap when building the charCodeToGlyphId map, for embedded composite fonts
Rather than first checking if the entry exists in the `cidToGidMap`, we can lookup it directly and instead fallback to `-1` when it doesn't exist.
2026-10-02 14:14:09 +02:00
Jonas Jenwald 05566bd110 Stop exporting the Font mimetype property
- All embedded font data, regardless of how it's specified in the PDF, is always converted into OpenType in the worker-thread. This has been the case since "forever" in the PDF.js project, hence the value of `Font.prototype.mimetype` never varies (when actually set).

 - With the introduction of the CSS Font Loading API, in the font-loading code, the `mimetype` property is no longer used *by default* in the main-thread.

 - Given that `Font.prototype.mimetype` is either a string or `null`, the way that PR 20197 implemented the serialization/deserialization isn't actually correct since an explicit `null` value is being converted into a `"null"` string.
2026-10-01 14:14:26 +02:00
Jonas Jenwald 62de7c55e1 Merge pull request #22042 from Snuffleupagus/rm-defaultVMetrics-export
Stop exporting the Font `defaultVMetrics` by default
2026-10-01 14:09:30 +02:00
Jonas Jenwald a02decd96c Stop exporting the Font defaultVMetrics by default
After PR 20933 the `Glyph.prototype.vmetric` property is now guaranteed to be always be defined for vertical fonts, since it'll fallback to the `defaultVMetrics` property; see https://github.com/mozilla/pdf.js/blob/18e8a26a3813a319b38c806076f0b0ef9baf1bf4/src/core/fonts.js#L3564
Hence it's no longer necessary to export the `defaultVMetrics` as part of the compiled Font info-data.

Additionally, with `Glyph.prototype.vmetric` always being defined, there's fallback code in both the worker/main-thread that should no longer be necessary.
2026-10-01 10:43:12 +02:00
Jonas Jenwald 18e8a26a38 Merge pull request #22028 from Snuffleupagus/rm-defaultWidth-export
Stop exporting the Font `defaultWidth` by default
2026-09-29 17:32:55 +02:00
Jonas Jenwald 8b614e49f7 Stop exporting the Font defaultWidth by default
With the exception of the unit-tests, this is now completely unused on the main-thread.
Note how the `glyph.width` property will always fallback to the `defaultWidth`: https://github.com/mozilla/pdf.js/blob/d52fdf411a6e4d338180687456e0df019e28475e/src/core/fonts.js#L3562-L3565
2026-09-29 17:02:43 +02:00
Jonas Jenwald a1c266da00 Merge pull request #22026 from Snuffleupagus/SystemFontInfo-rm-guessFallback
Remove the unused `SystemFontInfo.prototype.guessFallback`  getter
2026-09-29 17:02:01 +02:00
Jonas Jenwald c5d4809f11 Merge pull request #22015 from Snuffleupagus/SaveDocument-rm-async-functions
Remove unneeded `async` functions when creating StructTreeRoot-data during saving (PR 19026)
2026-09-29 13:05:58 +02:00
Jonas Jenwald 57243d72d8 Remove the unused SystemFontInfo.prototype.guessFallback getter
The `guessFallback` parameter is used during system-font parsing on the worker-thread, to ensure that the fallback-name is only appended once.
However, with the exception of the unit-tests this is completely unused on the main-thread.

This being a single byte of data isn't going to make any noticeable difference, however it does allow us to remove "unnecessary" code.
2026-09-29 12:03:10 +02:00
Jonas Jenwald 78745d9ecf Merge pull request #22016 from Snuffleupagus/compile-writeStrings
Add helper functions for encoding and writing strings in `src/core/obj_bin_transform_core.js`
2026-09-29 12:02:09 +02:00
Jonas Jenwald 8905373fa9 When compiling font-strings, set their length directly
After the previous patches the total length of the encoded strings are consistently available *before* writing them, hence we can directly set the length and remove the temporary (i.e. zero) placeholder entry.
2026-09-29 09:29:22 +02:00
Jonas Jenwald 24304f94b5 Use the encodeStrings/writeStrings helpers when writing style-strings in compileSystemFontInfo
*Note:* This reduces the size of the `gulp mozcentral` bundle by `281` bytes, which isn't a lot but still cannot hurt.
2026-09-29 09:29:22 +02:00
Jonas Jenwald 28181f1db6 Add helper functions for encoding and writing strings in src/core/obj_bin_transform_core.js
Currently `compileCssFontInfo`, `compileSystemFontInfo`, and `compileFontInfo` duplicate the same exact code for encoding and writing strings, which can be avoided with the introduction of two new helpers.

*Note:* This reduces the size of the `gulp mozcentral` bundle by `450` bytes, which isn't a lot but still cannot hurt.
2026-09-29 09:29:22 +02:00
Jonas Jenwald 5e18cef667 Add a helper function for writing buffer-data in compileFontInfo
Currently we duplicate the same exact code *twice* when writing the `systemFontInfoBuffer` and `cssFontInfoBuffer` data.

*Note:* This reduces the size of the `gulp mozcentral` bundle by `271` bytes, which isn't a lot but still cannot hurt.
2026-09-26 13:45:12 +02:00
Jonas Jenwald 78348aa61a Introduce a helper to reduce duplication when reading compiled string-data from fonts
Currently the `CssFontInfo`, `SystemFontInfo`, and `FontInfo` classes duplicate virtually the same code when reading string-data, which seems completely unnecessary.
The `SystemFontInfo.prototype.style` getter can also be re-factored to use the new helper function, rather than manually reading those strings.

*Note:* This reduces the size of the `gulp mozcentral` bundle by `627` bytes, and with the upcoming worker-rendering this saving will be doubled.
2026-09-25 11:07:39 +02:00
Jonas Jenwald aea270c8e9 Remove unneeded async functions when creating StructTreeRoot-data during saving (PR 19026)
These functions no longer need to be `async` after PR 19026, since no value is being returned now, and instead we can directly return the `StructTreeRoot.createStructureTree` respectively `StructTreeRoot.prototype.updateStructureTree` call since both methods (implicitly) return undefined.
2026-09-24 10:51:12 +02:00
Jonas Jenwald f083a797af Remove some redundant loop variables
There's not point in re-declaring these variables in the loop, and all the "original" variables are `const` as well.
2026-09-22 16:57:21 +02:00
Jonas Jenwald fcb04fa84a Remove unnecessary Array copying in the PatternInfo class (PR 20340 follow-up)
The de-serialization of Axial shading-patterns, implemented in PR 20340, will currently lead to the creation of unnecessary intermediate `Float32Array`s. Instead we can create the final Arrays *directly*, the same way as is done for Radial shading-patterns.
While this is an improvement the data is small and simple enough that it's not going to be measurable, however as a matter of principle we should nonetheless always avoid pointless copying of data.
2026-09-22 12:37:23 +02:00
Jonas Jenwald eee3276c8f Improve handling of non-embedded composite fonts with incomplete /CIDToGIDMap (PR 14025 follow-up)
This improves the rendering time of the `issue11915.pdf` document significantly, from 55-65 ms down to just 15-25 ms.
2026-09-22 08:58:23 +02:00
Jonas Jenwald a8057e037b Convert the CMap and ToUnicodeMap classes to store its data in Maps
The CMap-data and the ToUnicode-data is often sparse[1], which means that Arrays are not ideal data-structures for this purpose.
Note how there are separate paths, in the existing code, depending on the size of the data and that we're forced to either iterate over non-existing keys or use `for...in` iteration which "unnecessarily" stringify the keys.
By using Maps instead both of these issues can be avoided, and given that performance of Maps have been improved recently (in Firefox) this shouldn't be an issue.

Given how intertwined all of this functionality is, it unfortunately wasn't really possible to easily split this into several patches.
However, all of this code should (famous last words) be well covered by existing test-cases.

One notable difference is that iterating through CMap-data and ToUnicode-data now happens in insertion order, but given how this data is being used that's likely not an issue.

Also, copy the data returned by `CMap.prototype.getMap` since it's used as input to the `ToUnicodeMap` class. Note that we may amend the ToUnicode-data at the end of font parsing, hence we should not modify the underlying CMap-data.
Given how/where the CMap-data is accessed it's unlikely that this pre-existing "bug" has caused any issues, but it nonetheless seems like something that should be fixed.

*Note:* We purposely keep the `forEach` methods, since making the classes iterable seemed to be approximately an order or magnitude slower (based on very quick `console.{time, timeEnd}` benchmarking).

---

[1] In some cases even *extremely* sparse, see e.g. `issue8372.pdf`.
2026-09-22 08:58:23 +02:00
Jonas Jenwald db2ba7a7ea [api-minor] Stop sending a separate "test" message during Worker loading
Parts of the Worker loading code is really old (well over a decade), and goes back to a time where not all browsers supported Workers or had incomplete/broken implementations.
At this point in time it thus seems reasonable to assume that if Workers are available they first of all work correctly, and secondly that they support `postMessage` transfers.

Hence this patch, which suggests that we (ever so slightly) speed up the Worker loading by not having to wait for a separate "test" message.
Instead the worker-thread will send a test-object with the "ready" message, and we'll check on the main-thread that the expected data was received.

For the GENERIC viewer, on a fast laptop, this patch reduces Worker load-times between 1 and 6 milliseconds (the measurements are somewhat noisy).
While this obviously isn't a lot it cannot hurt, and it may be more significant on slower hardware.

*Note:* This won't improve loading performance of the Firefox PDF Viewer, since it uses a pre-loaded Worker nowadays.
However, the upcoming renderer-worker looks to be modelled on the existing `PDFWorker` and if we're going to be creating more Workers having their loading be as fast as possible seems like a worthy goal.
2026-09-19 18:51:07 +02:00
Jonas Jenwald b063000020 Convert the toFontChar Array, in the Font class, into a Map
In practice `toFontChar` is always a more or less sparse Array, and sometimes it's even *extremely* sparse (see e.g. `issue8372.pdf`), which means that a Map seems like a more appropriate data-structure.
2026-09-19 14:36:33 +02:00
Jonas Jenwald 394813a902 Convert the Differences Array, used with non-composite fonts, into a Map
In practice the Differences-data is a more or less sparse Array[1], which means that a Map seems like a more appropriate data-structure.

---

[1] Even in the `tracemonkey.pdf` document it's at most 254 entries, out of the maximum 256 ones, but with most of the fonts having considerably fewer entries.
2026-09-19 10:33:15 +02:00
Jonas Jenwald bb65fd4c6d Add a helper function for writing array-data in compileFontInfo
This is a follow-up to *the second* commit in PR 20861, since we can also avoid a little bit of effectively duplicated code when writing the `bbox`, `fontMatrix`, and `defaultVMetrics` data.

*Note:* This reduces the size of the `gulp mozcentral` bundle by `239` bytes, which isn't a lot but still cannot hurt.
2026-09-17 16:56:06 +02:00
Jonas Jenwald 1731c9338b Remove the createWithNullProto helper from the CFFParser unit-tests
Given that the full PDF.js library won't even run if `Object.prototype` has been incorrectly extended, it seems redundant to generate just these two expected-value Objects with an explicit `null` prototype.
Besides, we already compare against "regular" Objects all over the unit-tests without doing anything similar.
2026-09-17 11:26:59 +02:00
Jonas Jenwald 8afe14b671 Merge pull request #21967 from Snuffleupagus/evaluator-argIsDict
Define the "argument is Dictionary" callback validation function just once
2026-09-16 22:50:49 +02:00
Jonas Jenwald 57a630e32b Define the "argument is Dictionary" callback validation function just once
Rather than re-creating this function for every single "simple" operation, in `PartialEvaluator.prototype.getOperatorList`, we can define it just once instead.
Even for relatively simple PDFs, e.g. `tracemonkey.pdf`, this avoids creating a few thousand copies of that function when rendering all pages. For much larger PDFs, e.g. `pdf.pdf`, this avoids a few hundred thousand copies of that function.
2026-09-16 19:02:15 +02:00
Jonas Jenwald 2d544eb664 Convert charCodeToGlyphId, used in various font-code, into a Map
This data often needs to be iterated, and that's nicer to do with a Map than a plain Object.
2026-09-15 13:37:31 +02:00
Jonas Jenwald 4cd7338656 Merge pull request #21956 from Snuffleupagus/IdentityCMap-getMap-unreachable
Mark `IdentityCMap.prototype.getMap` as unreachable
2026-09-15 10:19:44 +02:00
Jonas Jenwald 88f6044946 Merge pull request #21955 from Snuffleupagus/CFFDict-Map
Convert the `CFFDict` classes to use Maps, rather than plain Objects
2026-09-14 16:37:42 +02:00
Jonas Jenwald 71cde9c384 Mark IdentityCMap.prototype.getMap as unreachable
At this point in time there's only a single `getMap` call-site in the entire code-base, and the preceding check guarantees that it cannot be an `IdentityCMap` instance; note https://github.com/mozilla/pdf.js/blob/5d7f2ba0f39826c1ac14dc1ae9e970920cc6dfeb/src/core/evaluator.js#L4043-L4046
2026-09-14 16:13:42 +02:00
Jonas Jenwald 35c0a9a6fb Convert the CFFDict classes to use Maps, rather than plain Objects 2026-09-14 12:37:34 +02:00
Jonas Jenwald 7ab3cb01dc Merge pull request #21952 from Snuffleupagus/FontLoader-testFontLoaded
Re-factor the test-font fallback loading in the `FontLoader` class
2026-09-13 16:56:54 +02:00
Jonas Jenwald 18194baa15 Remove an now unnecessary MOZCENTRAL check in the FontLoader.prototype.bind method
After the previous commit throwing an Error now results is (slightly) more code than keeping the `#testFontLoaded` call intact, and note that that method itself already throws in MOZCENTRAL builds.

Also, fix a typo in an error message thrown in WORKER_THREAD builds.
2026-09-13 16:17:35 +02:00
Jonas Jenwald 67338e3675 Re-factor the test-font fallback loading in the FontLoader class
The existing methods are only used as a fallback in non-Firefox browsers that lack support for the Font Loading API, and this is also very old code.
By combining this functionality into just a single (private) method, we ever so slight reduce the size of this code in the MOZCENTRAL build.
2026-09-13 15:46:58 +02:00
Jonas Jenwald c455a9d4f4 Re-factor the FontLoader.prototype.isFontLoadingAPISupported getter
This improves test-coverage a tiny bit, which shouldn't hurt.
2026-09-13 14:17:28 +02:00
Jonas Jenwald 65c9deb4cc Merge pull request #21948 from Snuffleupagus/FontLoader-inline-_loadTestFont
Inline the `_loadTestFont` definition in the `FontLoader.prototyp._prepareFontLoadEvent` method
2026-09-13 14:09:52 +02:00
Jonas Jenwald c832cf92fc Inline the _loadTestFont definition in the FontLoader.prototyp._prepareFontLoadEvent method
This method is only used as a fallback in non-Firefox browsers that lack support for the Font Loading API, hence by inlining that data we reduce the bundle size of the MOZCENTRAL build a tiny bit.
2026-09-13 13:26:41 +02:00
Jonas Jenwald cdab36c5b3 Change the FontFaceObject.prototype.getPathGenerator cache into a Map 2026-09-13 12:07:16 +02:00
Jonas Jenwald 6e17f42b63 Fix intermittent failures in the PDFDocumentProperties tests (PR 21938 follow-up)
After PR 21938 the integration-tests have started failing intermittently, but only in Google Chrome, so let's wait for *all* fields explicitly rather than just one of them.
2026-09-12 17:21:08 +02:00
Jonas Jenwald 0ce03b5a09 Merge pull request #21938 from Snuffleupagus/PDFDocumentProperties-reduce-l10n-get
Utilize Fluent better when localizing the `PDFDocumentProperties` dialog
2026-09-12 12:57:15 +02:00
Jonas Jenwald f23253f086 Utilize Fluent better when localizing the PDFDocumentProperties dialog
Currently we localize all of the necessary strings "manually", which is a pattern that we've moved away from in the code-base.
Instead we'll now set the "data-l10n-id" and "data-l10n-args" attributes on the relevant DOM elements, and let Fluent handle the localization automatically, which helps reduce overall asynchronicity in the `PDFDocumentProperties` code.

*Note:* We purposely keep the `#updateUI` helper, rather than updating l10n-attributes piecemeal, since it ensures that the dialog always displays consistent state.
2026-09-12 12:21:54 +02:00
Jonas Jenwald e5ec30410d Run the "gets current workerSrc" unit-test in Node.js (PR 17055 follow-up)
Compared to all the other unit-tests in the "PDFWorker" describe-block this one doesn't actually depend on Workers being available, since it only checks basic API functionality.
The reason that this unit-test was disabled in Node.js is that prior to PR 17055 the `GlobalWorkerOptions.workerSrc` option wasn't guaranteed to be set there.
2026-09-11 23:40:22 +02:00
Jonas Jenwald fd453c2ce3 Merge pull request #21935 from Snuffleupagus/Array-from
Avoid manual loops when generating some simple Arrays/TypedArrays
2026-09-11 22:56:37 +02:00
Jonas Jenwald 7edf1fd13a Avoid manual loops when generating some simple Arrays/TypedArrays
Also, utilize `TypedArray.prototype.fill` in the `src/core/lzw_stream.js` file.
2026-09-11 22:15:34 +02:00
Jonas Jenwald 0c52abe677 Merge pull request #21929 from Snuffleupagus/version-6.4
Bump library version to `6.4`
2026-09-10 21:46:43 +02:00
Jonas Jenwald c8536bc308 Bump library version to 6.4
See commit 3801e03652
2026-09-10 17:47:25 +02:00
Jonas Jenwald 9091e4f976 Stub out various FontLoader and FontFaceObject methods when building for workers
All of this code directly, or indirectly, assumes that the DOM is available which (obviously) isn't the case in workers.
This will help reduce the bundle size impact of the upcoming worker-rendering, by stubbing out code that cannot run there.
2026-09-10 12:39:15 +02:00
Jonas Jenwald 43508e1a15 Stub out OptionalContentConfig.prototype.getOrder when building for workers (PR 21349 follow-up)
This method is only invoked from the viewer, and with the upcoming worker-rendering we'll reduce bundle size a tiny bit this way.
2026-09-10 12:08:25 +02:00
Jonas Jenwald 7f28f84728 Use a "normal" import statement to access the importPrintedAppearances function, in the src/core/worker.js file (PR 21858 follow-up)
Currently this code is accessed with a dynamic import, which has the unfortunate side-effect of inflating the size of the *built* `pdf.worker.mjs` file a whole lot.

Given the relatively small size of the `src/core/editor/print_appearances.js` file it really doesn't seem like an issue to just bundle that code unconditionally, and the existing pre-processor checks means that the `importPrintedAppearances` code will only be invoked in MOZCENTRAL builds.

*NOTE:* This patch reduces the size of the `gulp mozcentral` bundle by `96` kilo-bytes, which I think is way too much to ignore.
2026-09-09 22:51:26 +02:00
Jonas Jenwald 3bba8538ef Merge pull request #21914 from Snuffleupagus/ViewHistory-rm-get
Remove the `ViewHistory.prototype.{get, set}` methods
2026-09-09 18:59:23 +02:00
Jonas Jenwald c824e569e0 Merge pull request #21915 from Snuffleupagus/forEach-arrow-callback
Replace `forEach` callback functions with arrow functions
2026-09-09 18:55:33 +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
Jonas Jenwald 2107bc4b9d Remove the ViewHistory.prototype.set method, and replace its call-sites with setMultiple instead
The `ViewHistory.prototype.set` method is first of all not used a lot, and secondly it's not used in any hot code-paths[1].
Hence we can use `setMultiple` consistently instead, which means that the `ViewHistory.prototype.set` method can be removed.

---

[1] Only when opening/closing the sidebar or changing sidebar view, and when changing scroll/spread modes in the viewer.
2026-09-09 12:26:22 +02:00
Jonas Jenwald 51c0c0007d Remove the unused ViewHistory.prototype.get method
This method is completely unused in the viewer, note the coverage data: https://app.codecov.io/gh/mozilla/pdf.js/commit/248bdcc235555ecf21f0b99f619e09eb5135241a/blob/web/view_history.js?dropdown=coverage#L82
2026-09-09 12:23:24 +02:00
Jonas Jenwald 66646a60f3 Merge pull request #21911 from Snuffleupagus/Font-missingGlyphs-Set
Convert the `missingGlyphs`, used in the `Font` class, into a Set
2026-09-08 18:28:32 +02:00
Jonas Jenwald 78f4b7b877 Merge pull request #21910 from Snuffleupagus/CFFOffsetTracker-offsets-Map
Convert the `CFFOffsetTracker` offsets into a Map
2026-09-08 18:24:39 +02:00
Jonas Jenwald 45c351d6a4 Convert the missingGlyphs, used in the Font class, into a Set
This seems like a more appropriate data-structure, rather than storing `true` values in a regular Object.

Also, fix existing inconsistencies in the `CMap.prototype.forEach` and `ToUnicodeMap.prototype.forEach` methods since they didn't always return integer charCodes. Note how various `forEach` call-sites previously did that manually, which seems like a "wrong" solution.
2026-09-08 17:28:29 +02:00
Jonas Jenwald 979f0d2aa5 Convert the CFFOffsetTracker offsets into a Map
Also, make the class field private.
2026-09-08 15:25:43 +02:00
Jonas Jenwald 0cdd6cde42 Merge pull request #21905 from Snuffleupagus/function-interpolate-reuse
Move the the `interpolate` helper, such that it can be re-used more in `src/core/function.js` code
2026-09-08 13:39:28 +02:00
Jonas Jenwald b52c4641b0 Move the the interpolate helper, such that it can be re-used more in src/core/function.js code
After PR 21891 the `interpolate` function is basically duplicated, since the stitched-handling currently inline effectively identical code.

Also, fix existing typos in a couple of method/function names ("Stiched" -> "Stitched").
2026-09-08 12:01:10 +02:00
Jonas Jenwald e67b540fc9 Merge pull request #21898 from Snuffleupagus/Ref-fromString-strict
Make `Ref.fromString` more strict, by not accepting "bad" arguments
2026-09-07 15:58:41 +02:00
Jonas Jenwald 4b4293cb9c Make Ref.fromString more strict, by not accepting "bad" arguments
In hindsight the *second* commit of PR 21888, which was intended to improve how `Ref.fromString` handles "bad" arguments, seems wrong since that method now accepts arguments that don't agree fully with the string representation used in the `Ref.get` method.

The `Ref.fromString` method will now properly validate the argument, and "reject" (i.e. return `null`) unless it matches the expected format.
2026-09-07 14:41:58 +02:00
Jonas Jenwald 2a131af2c0 Merge pull request #21893 from Snuffleupagus/Pattern-shorten
Shorten some Pattern-handling code a little bit
2026-09-06 17:52:24 +02:00
Jonas Jenwald ae1e279f6e Shorten some Pattern-handling code a little bit
Also, remove a couple of unused class fields and don't needlessly set the `RadialAxialShading.protoype.colorStops` field again; note https://github.com/mozilla/pdf.js/blob/b2035eea9206b92ee7eba2c9e92e573a82167ff1/src/core/pattern.js#L206
2026-09-06 16:44:26 +02:00
Jonas Jenwald bb10870d0d Ensure that Ref.fromString handles arguments with leading/trailing zeros
If the reference-string argument is malformed, see the updated unit-tests, we could miss existing cache entries and thus incorrectly re-create `Ref` instances.
Note that this *should* never happen in practice, but it nonetheless ought to be fixed.
2026-09-06 14:06:45 +02:00
Jonas Jenwald 7ba1f22fde Convert the CmdCache, NameCache, and RefCache to use Maps
This patch was tested with the following manifest file:
```json
[
  {
    "id": "tracemonkey-eq",
    "file": "pdfs/tracemonkey.pdf",
    "md5": "9a192d8b1a7dc652a19835f6f08098bd",
    "rounds": 200,
    "type": "eq"
  },
  {
    "id": "issue2618",
    "file": "pdfs/issue2618.pdf",
    "md5": "2c554a99a52288ca1a44a422eeafb8fb",
    "rounds": 200,
    "type": "eq"
  }
]
```
which gave the following results, indicating no significant regression, when comparing this patch against the `master` branch:
```
-- Grouped By pdf, page, stat --
pdf            | page | stat         | Count | Baseline(ms) | Current(ms) | +/- |     %  | Result(P<.05)
-------------- | ---- | ------------ | ----- | ------------ | ----------- | --- | ------ | -------------
issue2618      | 0    | Overall      |   200 |          479 |         469 | -10 |  -2.01 |        faster
issue2618      | 0    | Page Request |   200 |           13 |          12 |   0 |  -1.19 |
issue2618      | 0    | Rendering    |   200 |          466 |         457 |  -9 |  -2.03 |        faster
tracemonkey-eq | 0    | Overall      |   200 |           13 |          13 |   0 |  -0.90 |
tracemonkey-eq | 0    | Page Request |   200 |            1 |           1 |   0 | -13.79 |
tracemonkey-eq | 0    | Rendering    |   200 |           12 |          12 |   0 |  -0.37 |
tracemonkey-eq | 1    | Overall      |   200 |           28 |          28 |   0 |  -0.20 |
tracemonkey-eq | 1    | Page Request |   200 |            2 |           2 |   0 |  10.13 |
tracemonkey-eq | 1    | Rendering    |   200 |           26 |          26 |   0 |  -0.82 |
tracemonkey-eq | 2    | Overall      |   200 |           20 |          20 |   0 |   1.08 |
tracemonkey-eq | 2    | Page Request |   200 |            1 |           1 |   0 |   7.92 |
tracemonkey-eq | 2    | Rendering    |   200 |           19 |          20 |   0 |   1.03 |
tracemonkey-eq | 3    | Overall      |   200 |           29 |          29 |   0 |  -0.26 |
tracemonkey-eq | 3    | Page Request |   200 |            1 |           1 |   0 | -15.53 |
tracemonkey-eq | 3    | Rendering    |   200 |           28 |          28 |   0 |   0.16 |
tracemonkey-eq | 4    | Overall      |   200 |           20 |          21 |   0 |   1.69 |
tracemonkey-eq | 4    | Page Request |   200 |            1 |           1 |   0 |  24.29 |
tracemonkey-eq | 4    | Rendering    |   200 |           20 |          20 |   0 |   0.81 |
tracemonkey-eq | 5    | Overall      |   200 |           20 |          20 |   0 |   0.28 |
tracemonkey-eq | 5    | Page Request |   200 |            1 |           1 |   0 |   1.68 |
tracemonkey-eq | 5    | Rendering    |   200 |           19 |          19 |   0 |   0.24 |
tracemonkey-eq | 6    | Overall      |   200 |           24 |          24 |   0 |   1.10 |
tracemonkey-eq | 6    | Page Request |   200 |            1 |           1 |   0 |  52.55 |
tracemonkey-eq | 6    | Rendering    |   200 |           23 |          23 |   0 |  -0.41 |
tracemonkey-eq | 7    | Overall      |   200 |           23 |          23 |   0 |   0.04 |
tracemonkey-eq | 7    | Page Request |   200 |            1 |           1 |   0 |  -2.52 |
tracemonkey-eq | 7    | Rendering    |   200 |           23 |          23 |   0 |   0.02 |
tracemonkey-eq | 8    | Overall      |   200 |           24 |          24 |   0 |  -0.02 |
tracemonkey-eq | 8    | Page Request |   200 |            1 |           0 |   0 | -13.27 |
tracemonkey-eq | 8    | Rendering    |   200 |           23 |          23 |   0 |   0.33 |
tracemonkey-eq | 9    | Overall      |   200 |           21 |          21 |   0 |   0.74 |
tracemonkey-eq | 9    | Page Request |   200 |            1 |           1 |   0 |  -4.13 |
tracemonkey-eq | 9    | Rendering    |   200 |           20 |          20 |   0 |   0.94 |
tracemonkey-eq | 10   | Overall      |   200 |          107 |         106 |  -1 |  -1.27 |
tracemonkey-eq | 10   | Page Request |   200 |            1 |           0 |   0 | -44.83 |
tracemonkey-eq | 10   | Rendering    |   200 |          106 |         105 |  -1 |  -0.93 |
tracemonkey-eq | 11   | Overall      |   200 |           21 |          21 |  -1 |  -2.71 |
tracemonkey-eq | 11   | Page Request |   200 |            1 |           1 |   0 | -20.12 |
tracemonkey-eq | 11   | Rendering    |   200 |           21 |          20 |   0 |  -1.99 |
tracemonkey-eq | 12   | Overall      |   200 |           35 |          34 |  -1 |  -1.79 |
tracemonkey-eq | 12   | Page Request |   200 |            1 |           1 |   0 | -18.89 |        faster
tracemonkey-eq | 12   | Rendering    |   200 |           34 |          34 |   0 |  -1.37 |
tracemonkey-eq | 13   | Overall      |   200 |           11 |          11 |  -1 |  -6.44 |
tracemonkey-eq | 13   | Page Request |   200 |            1 |           0 |   0 | -16.67 |
tracemonkey-eq | 13   | Rendering    |   200 |           11 |          10 |  -1 |  -5.99 |
```
2026-09-06 14:06:23 +02:00
Jonas Jenwald b2035eea92 Merge pull request #21887 from Snuffleupagus/MediaAnnotation-ext
Improve the filename extension detection in `MediaAnnotation.prototype._getContentType`
2026-09-06 11:49:52 +02:00
Jonas Jenwald a754b49a7c Improve the filename extension detection in MediaAnnotation.prototype._getContentType
Rather than splitting the filename into an Array, and then take its last element, we can directly search for the *last* dot instead.

Doing this also fixes what appears to be a small oversight, since the current code may find a "valid" extension when one doesn't actually exist in the filename. For example, try running the following code in the console:
```js
var filename = "mp4";
filename.split(".").at(-1)?.toLowerCase();
```
2026-09-04 23:01:12 +02:00
Jonas Jenwald 8dd0057cf7 Convert the font seacMap and seacs structures into Maps
This changes `seacMap` from a regular Object into a Map, and the Type1/CFF `seacs` from (potentially very) sparse Arrays into Maps.

*Note:* These changes are covered by existing ref-tests such as: `issue818.pdf`, `issue4801`, `issue4573.pdf`, `bug1308536.pdf`, and `glyph_accent.pdf`.
2026-09-04 14:12:45 +02:00
Jonas Jenwald 94c722f524 Modernize the MessageHandler class
Convert the code to use Maps instead of regular Objects, and utilize private class fields.
2026-09-04 13:00:46 +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
Jonas Jenwald 3801e03652 Merge pull request #21868 from Snuffleupagus/issue-20399
[api-minor] Expose the `operatorList` to the `operationsFilter` callback function (issue 20399)
2026-09-01 19:05:11 +02:00
Jonas Jenwald 8390ba8de4 [api-minor] Expose the operatorList to the operationsFilter callback function (issue 20399)
Without this the `operationsFilter` functionality is perhaps too limited, since it's currently not really possible to e.g. ignore certain operators.
2026-09-01 18:15:18 +02:00
Jonas Jenwald 53541b2e1b Merge pull request #21863 from Snuffleupagus/collectActions-helper
Add a helper to reduce duplication in the `collectActions` function
2026-09-01 15:30:18 +02:00
Jonas Jenwald bcc0a2a0b2 Add a helper to reduce duplication in the collectActions function
The new helper avoids duplicating the same code twice, when invoking `_collectJS`, during parsing of actions.
2026-09-01 14:46:30 +02:00
Jonas Jenwald 3bc7da784c Merge pull request #21857 from Snuffleupagus/L10n-get-rm-fallback
Remove the unused `fallback` parameter from `L10n.prototype.get`
2026-09-01 14:44:47 +02:00
Jonas Jenwald 1f26e97cb6 Merge pull request #21862 from Snuffleupagus/isPlayAction-move-checks
Move checks into the `ScreenAnnotation.#isPlayAction` method
2026-09-01 14:44:11 +02:00
Jonas Jenwald 14a29369e9 Move checks into the ScreenAnnotation.#isPlayAction method
This avoids duplicating these checks in the `ScreenAnnotation.#renditionActions` method, which is a tiny bit shorter.
2026-09-01 12:39:57 +02:00
Jonas Jenwald e7c8b3ea76 Remove the unused fallback parameter from L10n.prototype.get
This parameter hasn't been used anywhere in the code-base after the introduction of Fluent, hence it can simply be removed now.
Furthermore, note also that the `L10n.prototype.get` method itself is not used very much nowadays.
2026-08-31 16:38:24 +02:00
Jonas Jenwald 561a4cced0 Merge pull request #21856 from Snuffleupagus/PDFDocumentProperties-parsePageSize-parallel-l10n-lookup
Get the l10n arguments at once in `PDFDocumentProperties.prototype.#parsePageSize`
2026-08-31 15:19:10 +02:00
Jonas Jenwald 21c8ec6540 Merge pull request #21840 from Snuffleupagus/issue-21836
Remove old `info` logging from the "GetOperatorList"/"GetTextContent" handlers (issue 21836)
2026-08-31 15:17:06 +02:00
Jonas Jenwald 268b6a4217 Get the l10n arguments at once in PDFDocumentProperties.prototype.#parsePageSize
Given that Fluent supports localizing multiple strings "at once", we can replace the current two or three calls (depending on page size) with just a single one.

This also, indirectly, improves test coverage of the `L10n` class since the "multiple ids branch" previously wasn't used anywhere in the code-base.
2026-08-31 12:34:28 +02:00
Jonas Jenwald 90400390cb Use arrow functions consistently with Promise catch methods
This improves consistency in the code-base, and it's a tiny bit shorter which never hurts.
2026-08-30 14:34:46 +02:00
Jonas Jenwald 501219a697 Remove the unused totalLength getter from the OperatorList class
The only actual `totalLength` invocations, outside of the unit-tests, were removed in the previous commit and this is now dead code.
2026-08-29 17:22:55 +02:00
Jonas Jenwald 0b1b07b02c Remove old info logging from the "GetOperatorList"/"GetTextContent" handlers (issue 21836)
Also remove an "ancient" comment, from the "GetOperatorList" handler, which no longer seems helpful.
Finally, since they're now unused, remove the return-values from the `Page.prototype.getOperatorList` method.
2026-08-29 17:08:30 +02:00
Jonas Jenwald 67c035f451 Inline the PDFDocument.prototype._parseHasJSActions method
This code is short and simple enough that it can just be inlined in the `hasJSActions` getter.
2026-08-29 13:52:08 +02:00
Jonas Jenwald c58a2758f7 Move some WorkerTask class field definitions out of the constructor
Also, make use of actually private fields in one case.
2026-08-29 13:52:00 +02:00
Jonas Jenwald d1725aba54 Merge pull request #21837 from Snuffleupagus/rm-ColorSpace-getoutputlength
Remove the unused `getOutputLength` method from the `ColorSpace` classes (PR 21637 follow-up)
2026-08-29 12:06:21 +02:00
Jonas Jenwald 159dca9e0e Remove the unused getOutputLength method from the ColorSpace classes (PR 21637 follow-up)
The only actual `getOutputLength` call-site, outside of the unit-tests, was removed in PR 21637 and these methods are now unused.
This code can always be easily re-instated if needed, thanks to version control, so let's avoid shipping dead code in the builds.
2026-08-28 23:01:15 +02:00