3546 Commits

Author SHA1 Message Date
calixteman
952952c905
[api-minor] Rewrite the ps lexer & parser and add a small Wasm compiler
The main goal is to remove the eval-based interpreter.
In order to have some good performances, the new parser performs some optimizations
on the AST (similar to the ones in the previous implementation),
and the Wasm compiler generates code for the optimized AST.
For now, in case of errors or unsupported features, the Wasm compiler returns null
and the old interpreter is used as a fallback.
Few things are still missing:
 - a wasm-based interpreter using a stack (in case the ps code isn't stack-free);
 - a better js implementation in case of disabled wasm.

 but they will be added in follow-up patches.
2026-03-30 09:22:33 +02:00
Tim van der Meij
ada3438039
Merge pull request #21001 from Snuffleupagus/getDestFromStructElement-unit-test
Add a unit-test for the `Catalog.#getDestFromStructElement` method
2026-03-29 16:08:21 +02:00
Jonas Jenwald
d1f15fe352 Add a unit-test for the Catalog.#getDestFromStructElement method
This code already has an integration-test, however also having a unit-test shouldn't hurt since those are often easier to run and debug (and it nicely complements the existing `outline` unit-tests).

The patch also makes the following smaller changes to the method itself:
 - Avoid creating and parsing an empty Array, when doing the `pageRef` search.
 - Use `XRef.prototype.fetch` directly, when walking the parent chain, since the check just above ensures that the value is a Reference.
 - Use the `lookupRect` helper when parsing the /BBox entry.
2026-03-29 14:01:43 +02:00
Jonas Jenwald
0060eeb726 Use more logical assignment in the code-base 2026-03-27 12:18:04 +01:00
calixteman
018c1539dd
Merge pull request #20957 from calixteman/issue20956
Break text chunks only if the base font is different
2026-03-26 22:24:23 +01:00
calixteman
27e619f00d
Merge pull request #20992 from calixteman/organize_avoid_exception
Avoid exception when cloning a page with some modified annotations
2026-03-26 22:15:06 +01:00
Calixte Denizet
2e3d79e616
Break text chunks only if the base font is different
It fixes #20956.
2026-03-26 21:39:32 +01:00
calixteman
484518614d
Merge pull request #20976 from calixteman/bidi_tests
Add the bidi tests coming from BidiTest.txt and BidiCharacterTest.txt
2026-03-26 21:36:18 +01:00
Calixte Denizet
2b20e012bb
Avoid exception when cloning a page with some modified annotations
Some tests will come later.
2026-03-26 20:53:09 +01:00
Tim van der Meij
d3fd72e7e8
Merge pull request #20982 from calixteman/debugger_images_preview
Display mask in the tree view in the debugger
2026-03-26 20:29:42 +01:00
Titus Wormer
e914326346
Refactor to improve performance around image masks (bug 1941562)
* add support for directly writing masks into `rgbaBuf` if their size matches
* add support for writing into `rgbaBuf` to `resizeImageMask` to avoid extra
  allocs/copies
* respect `actualHeight` to avoid unnecessary work on non-emitted rows
* mark more operations as `internal`

This changes the path for what I believe is the common case for masks:
a mask to add transparency to the accompanying opaque image, both being
equal in size.
The other paths are not meaninfully unchanged.
That increases my confidence as these new paths can be easily tested
with a PNG with transparency.
2026-03-26 14:39:50 +01:00
Calixte Denizet
867af5c1e5
Display mask in the tree view in the debugger 2026-03-26 14:35:31 +01:00
Calixte Denizet
42c229c267
Add the bidi tests coming from BidiTest.txt and BidiCharacterTest.txt
Some tests were failing and has been fixed:
 - "Hello" + Alef + "(" + Bet: the "(" (neutral) was not considered as a part of the group Alef(Bet and the group wasn't reverted;
 - some intermediate neutrals were considered as strong.
2026-03-25 15:18:50 +01:00
Tim van der Meij
1756b48417
Merge pull request #20949 from Snuffleupagus/BinaryDataFactory-2
[api-minor] Replace the `CMapReaderFactory`, `StandardFontDataFactory`, and `WasmFactory` API options with a single factory/option
2026-03-22 21:20:49 +01:00
Tim van der Meij
0a6894d28b
Merge pull request #20948 from calixteman/issue20914
Interpret empty annotation border as [0, 0, 0]
2026-03-22 19:08:19 +01:00
Jonas Jenwald
3a372fde94 [api-minor] Replace the CMapReaderFactory, StandardFontDataFactory, and WasmFactory API options with a single factory/option
Currently we have no less than three different, but very similar, factories for reading built-in CMap files, standard font files, and wasm files on the main-thread.[1]
These factories were added at different points in time, since I cannot imagine that we'd add essentially three copies of the same code otherwise.

Nowadays these factories are often not even used[2], since worker-thread fetching is used whenever possible to improve performance. In particular, they will *only* be used when either:
 - The PDF.js library runs in Node.js environments.
 - The user manually sets `useWorkerFetch = false` when calling `getDocument`.
 - The user provides custom `CMapReaderFactory`, `StandardFontDataFactory`, and/or `WasmFactory` instances when calling `getDocument`.

By replacing these factories with *a single* new `BinaryDataFactory` factory/option the number of `getDocument` options are thus reduced, which cannot hurt.
This also reduces the total bundle-size of the Firefox PDF Viewer a little bit, and it slightly reduces the number of import maps that need to be maintained.

*Please note:* For users that provide custom `CMapReaderFactory`, `StandardFontDataFactory`, and `WasmFactory` instances when calling `getDocument` this will be a breaking change, however it's unlikely that (many) such users exist.
(The *internal* format data-format of `CMapReaderFactory` was changed in PR 18951, and there hasn't been a single question/complaint about it in well over a year.)

---

[1] Any new functionality could easily lead to more such factories being added in the future, which wouldn't be great.

[2] Note that the Firefox PDF Viewer no longer use these factories, since it "forcibly" sets `useWorkerFetch = true` during building.
2026-03-22 15:49:06 +01:00
calixteman
de48af76d4
Interpret empty annotation border as [0, 0, 0]
It fixes #20914.
2026-03-22 15:49:04 +01:00
calixteman
ec24053ddf
Don't add an EOL after a superscript 2026-03-22 14:20:18 +01:00
Tim van der Meij
869f25a489
Merge pull request #20940 from calixteman/issue20872
Fix the group bbox when the numbers are too big
2026-03-22 12:27:43 +01:00
calixteman
5992d0f097
Fix the group bbox when the numbers are too big
It fixes #20872.
2026-03-21 19:37:42 +01:00
Jonas Jenwald
262aeef3fa [api-minor] Simplify BaseCMapReaderFactory by having the worker-thread create the filename
The `BaseCMapReaderFactory`, `BaseStandardFontDataFactory`, and `BaseWasmFactory` classes are all very similar, and the only difference is really in their respective `fetch` methods.
By have the worker-thread "compute" the complete `filename` it's possible to simplify the `BaseCMapReaderFactory.prototype.fetch` method, which will allow future improvements to all of these classes.

A couple of things to note:
 - This code is unused, and it's not even bundled, in the Firefox PDF Viewer.
 - In browsers it's unused by default, and worker-thread fetching will always be used when possible since that's more efficient.

*Please note:* For users that provide a custom `CMapReaderFactory` instance when calling `getDocument` this could be a breaking change, however it's unlikely that any such users exist.
(The *internal* format of this data was changed previously in PR 18951, and there hasn't been a single question/complaint about it in well over a year.)
2026-03-21 15:54:40 +01:00
calixteman
918a319de6
Merge pull request #20885 from calixteman/gouraud_gpu
Implement Gouraud-based shading using WebGPU.
2026-03-21 15:18:56 +01:00
calixteman
86441e9eb8
Implement Gouraud-based shading using WebGPU.
The WebGPU feature hasn't been released yet but it's interesting to see how
we can use it in order to speed up the rendering of some objects.
This patch allows to render mesh patterns using WebGPU.

I didn't see any significant performance improvement on my machine (mac M2)
but it may be different on other platforms.
2026-03-21 14:34:32 +01:00
Calixte Denizet
eaa5eca73d Fix charSpacing in vertical mode
It fixes #20930.
And use the defaultVMetrics (coming from DW2 property) in the font.
2026-03-20 23:09:03 +01:00
calixteman
dabb2b960d
Merge pull request #20927 from Snuffleupagus/Firefox-enforce-worker-binary-fetch
[Firefox] Ensure that worker-thread fetching is used for built-in CMap, standard font, and wasm data
2026-03-20 17:45:43 +01:00
Jonas Jenwald
652822bef0 [Firefox] Ensure that worker-thread fetching is used for built-in CMap, standard font, and wasm data
Given that we "forcibly" set `useWorkerFetch = true` for the MOZCENTRAL build-target there's a small amount of dead code as a result, which we can thus remove during building.
2026-03-20 16:58:57 +01:00
calixteman
16aee06aac
Merge pull request #20925 from calixteman/reorganize_save_annotations
Add the possibility to save added annotations when reorganizing a pdf (bug 2023086)
2026-03-20 16:32:10 +01:00
Calixte Denizet
04272de41d
Add the possibility to save added annotations when reorganizing a pdf (bug 2023086) 2026-03-20 10:55:47 +01:00
Calixte Denizet
c17801b77e Avoid getting null value in RefSet when cloning 2026-03-20 10:41:58 +01:00
Tim van der Meij
ff1af5a058
Merge pull request #20916 from calixteman/fix_co
When merging pdfs, fix the CO after the fields have been cloned
2026-03-19 21:22:43 +01:00
Tim van der Meij
6245bb201c
Merge pull request #20915 from calixteman/fix_pageindice
Avoid to use a used slot when looking for a new page position
2026-03-19 21:22:32 +01:00
Tim van der Meij
8cae5d17f2
Merge pull request #20917 from calixteman/fix_dup_name_dest
Fix the destination names when they're duplicated
2026-03-19 21:22:19 +01:00
Calixte Denizet
cf67c1ef1e
Fix the destination names when they're duplicated 2026-03-19 10:52:39 +01:00
Calixte Denizet
b7da4b80a9
When merging pdfs, fix the CO after the fields have been cloned 2026-03-19 10:09:40 +01:00
Calixte Denizet
0bee641fed
Avoid to use a used slot when looking for a new page position 2026-03-19 09:40:16 +01:00
Jonas Jenwald
e52f2d1d67 Convert the internal Map to a properly private field in the Dict class 2026-03-19 09:36:29 +01:00
Jonas Jenwald
6c6bb19324 Use proper access methods in Dict.merge, rather than modifying the _map field manually 2026-03-19 09:36:29 +01:00
calixteman
bda7456724
Merge pull request #20892 from Snuffleupagus/Dict-get-helper
Reduce duplication in the `Dict.prototype.{get, getAsync, getArray}` methods
2026-03-18 21:40:30 +01:00
Jonas Jenwald
4b1f64f914 Change the NOOP fallback, in CompiledFont, to return a TypedArray
In PR 20367 the `CompiledFont.prototype.getPathJs` method was changed to return TypedArray data, however the `NOOP` fallback was (likely accidentally) left an empty string.
The compilation of font-paths in PR 20346 was then implemented such that an empty string just happened to be ignored silently, however the assert added in PR 20894 allowed me to spot this return value inconsistency.

*Please note:* Since this only applies to missing or broken glyphs, that wouldn't be rendered anyway, this doesn't show up in reference tests.
2026-03-18 14:01:51 +01:00
Jonas Jenwald
f4aadea001 Reduce duplication in the Dict.prototype.{get, getAsync, getArray} methods
These methods are all very similar, so let's introduce a private helper method to reduce unnecessary code duplication.
2026-03-18 11:15:23 +01:00
Jonas Jenwald
bdc16f8999
Merge pull request #20868 from Snuffleupagus/exportData-compileFontInfo
Move the `compileFontInfo` call into the `Font.prototype.exportData` method (PR 20197 follow-up)
2026-03-18 11:14:46 +01:00
Calixte Denizet
e67892d035
Add support for saving outlines after reorganize/merge (bug 2009574) 2026-03-17 22:22:13 +01:00
Tim van der Meij
83f06b4cf3
Merge pull request #20897 from calixteman/empty_shading
Don't throw when a mesh shading is degenerated
2026-03-17 21:18:24 +01:00
Calixte Denizet
fd1fea5f6a
Remove some useless operations when getting the text content
The removed code has been added in #20624 and it's useless since these
operations (i.e. save/restore) are already handled in preprocessor.read.
2026-03-17 16:00:29 +01:00
calixteman
085ab36680
Don't throw when a mesh shading is degenerated
The problem of throwing an error is that it removes an operation
from drawing list which can cause a rendering issue.
2026-03-16 23:23:14 +01:00
Jonas Jenwald
fa7ddbb9bc Simplify compilation of font paths (PR 20346 follow-up)
Given that `CompiledFont.prototype.getPathJs` already returns data in the desired TypedArray format, we should be able to directly copy the font-path data which helps shorten the code a little bit (rather than the "manual" handling in PR 20346).

To ensure that this keeps working as expected, a non-production `assert` is added to prevent any future surprises.
2026-03-16 14:51:36 +01:00
Jonas Jenwald
7d963ddc7c Move the compileFontInfo call into the Font.prototype.exportData method (PR 20197 follow-up)
After the changes in PR 20197 the code in the `TranslatedFont.prototype.send` method is not all that readable[1] given how it handles e.g. the `charProcOperatorList` data used with Type3 fonts.
Since this is the only spot where `Font.prototype.exportData` is used, it seems much simpler to move the `compileFontInfo` call there and *directly* return the intended data rather than messing with it after the fact.

Finally, while it doesn't really matter, the patch flips the order of the `charProcOperatorList` and `extra` properties throughout the code-base since the former is used with Type3 fonts while the latter (effectively) requires that debugging is enabled.

---

[1] I had to re-read it twice, also looking at all the involved methods, in order to convince myself that it's actually correct.
2026-03-16 09:29:17 +01:00
calixteman
3ff52e415f
Merge pull request #20862 from calixteman/bug2023106
Check for having Ref before adding them in a RefSet (bug 2023106)
2026-03-15 22:15:58 +01:00
Calixte Denizet
0fca64f01e
Check for having Ref before adding them in a RefSet (bug 2023106) 2026-03-15 22:03:39 +01:00
Tim van der Meij
315491dd32
Merge pull request #20840 from Snuffleupagus/getDocument-rm-length
[api-minor] Remove the `length` parameter from `getDocument`
2026-03-15 11:48:02 +01:00