1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00
Commit graph

7024 commits

Author SHA1 Message Date
Jonas Jenwald
8c5fb7979f Also transfer ImageBitmaps for image masks and inline images
Currently we're only transferring TypedArrays, however there's no reason (as far as I can tell) to not also transfer `ImageBitmap`s in these cases.
2025-04-03 18:50:39 +02:00
Calixte Denizet
41bed561f0 Simplify updateRectMinMax in order to use slightly less memory 2025-04-03 17:06:58 +02:00
Jonas Jenwald
a45f961a1c
Merge pull request #19751 from Snuffleupagus/applyTransform-in-place
Change `Util.applyTransform` to use the point-argument as an in/out parameter
2025-04-02 20:47:21 +02:00
calixteman
b7437376f1
Merge pull request #19732 from calixteman/rm_useless_beginpath
Remove few useless beginPaths
2025-04-02 13:46:05 +02:00
Jonas Jenwald
4262603b06 Re-name the Util.applyTransformToBezierInPlace method
Given that all `Util.apply...` methods are now using in/out parameters, we can slightly shorten the name of this one.
2025-04-01 23:03:50 +02:00
Jonas Jenwald
c852e877d8 Change Util.applyInverseTransform to use the point-argument as an in/out parameter
This will help reduce the total number of Array allocations, which cannot hurt.
2025-04-01 23:03:44 +02:00
Jonas Jenwald
fa643bb22f Change Util.applyTransform to use the point-argument as an in/out parameter
This will help reduce the total number of Array allocations, which cannot hurt, and also allows us to remove the `Util.applyTransformInPlace` method.
2025-04-01 23:03:36 +02:00
Jonas Jenwald
e5fbf52405
Merge pull request #19736 from Snuffleupagus/compileType3Glyph-worker
[api-minor] Move Type3-glyph compilation to the worker-thread
2025-04-01 19:40:30 +02:00
Jonas Jenwald
b33522a208
Merge pull request #19746 from Snuffleupagus/evaluator-img-cache-tweaks
Reduce some code duplication when handling globally cached images
2025-04-01 19:15:10 +02:00
calixteman
25693dc0ee
Merge pull request #19712 from calixteman/optimize_save_construct
Optimize save-transform-constructPath-restore
2025-04-01 18:20:59 +02:00
Calixte Denizet
a35443ff45 Remove few useless beginPaths.
The ctx current path is no more changed since we use some Path2D when we want to fill/stroke them.
It makes calling ctx.beginPath useless.
2025-04-01 16:02:38 +02:00
Jonas Jenwald
9cd5a9658a [api-minor] Move Type3-glyph compilation to the worker-thread
After PR 19731 the format of compiled Type3-glyphs is now simple enough that the compilation can be moved to the worker-thread, without introducing any significant additional complexity.
This allows us to, ever so slightly, simplify the implementation in `src/display/canvas.js` since the Type3 operatorLists will now directly include standard path-rendering operators (using the format introduced in PR 19689).

As part of these changes we also stop caching Type3 image masks since: we've not come across any cases where that actually helps, they're usually fairly small, and it simplifies the code.

Note that one "negative" change introduced in this patch is that we'll now compile Type3-glyphs *eagerly*, whereas previously we'd only do that lazily upon their first use.
However, this doesn't seem to impact performance in any noticeable way since the compilation is fast enough (way below 1 ms/glyph in my testing) and Type3-fonts are also limited to just 256 glyphs. Also, many (or most?) Type3-fonts don't even use image masks and are thus not affected by these changes.
2025-04-01 09:09:00 +02:00
calixteman
a4950c0b71
Merge pull request #19721 from calixteman/simplif_singular_decomposition
Simplify singularValueDecompose2dScale in order to make it using less memory
2025-03-31 12:53:17 +02:00
Jonas Jenwald
213830f44f Use, and re-name, the addLocallyCachedImageOps helper for global images too
This avoids having to "manually" set the image operators for globally cached images.
2025-03-31 10:57:04 +02:00
Jonas Jenwald
e0e59eaf01 Define the global cache-data once in buildPaintImageXObject
Currently we duplicate the same identical code three times, which seems both unnecessary and error prone.
2025-03-31 10:29:29 +02:00
Calixte Denizet
6e9fbd9420 Simplify singularValueDecompose2dScale in order to make it using less memory
In using the Firefox profiler (with JS allocations tracking) and wuppertal.pdf, I noticed
we were using a bit too much memory for a function which is supposed to just compute 2 numbers.
The memory used by itself isn't so important but having a too much objects lead to waste some time
to gc them.

So this patch aims to simplify it a bit.
2025-03-31 10:28:01 +02:00
Tim van der Meij
45cbe8bb0d
Merge pull request #19735 from Snuffleupagus/Type3WordSpacing
Apply char/word-spacing correctly for missing Type3-glyphs
2025-03-30 12:07:54 +02:00
Tim van der Meij
1ccc82beff
Merge pull request #19733 from Snuffleupagus/import-vite-ignore
[api-minor] Attempt to improve support for using the PDF.js builds with Vite
2025-03-30 11:58:20 +02:00
Tim van der Meij
97bf09b795
Merge pull request #19739 from Snuffleupagus/buildPaintImageXObject-fn-OPS
Reduce duplication when specifying the fn-operations in `buildPaintImageXObject`
2025-03-30 11:55:53 +02:00
Jonas Jenwald
8e3a3387e0 Reduce duplication when specifying the fn-operations in buildPaintImageXObject
Currently we explicitly specify the fn-`OPS` both when adding entries to the operatorList and to the image-caches, and by using a temporary variable we can reduce a bit of duplication (similar to the existing args-handling).
2025-03-29 15:56:46 +01:00
Jonas Jenwald
09118670ca Simplify handling of the color-parameter in TilingPattern (PR 4824 follow-up)
The color-parameter is already available through `IR` (i.e. the internal representation), and after the changes in PR 4824 (which landed in 2014) we no longer need any special handling for it.
2025-03-29 13:02:13 +01:00
Jonas Jenwald
667645798f Apply char/word-spacing correctly for missing Type3-glyphs
In the included PDF document the Type3-font doesn't contain any glyph definition for "space", despite that character being referenced in the /Contents stream.
While missing Type3-glyphs obviously cannot be rendered, we still need to update the current canvas position such that any char/word-spacing is correctly applied.

The test-case was found at https://github.com/pdf-association/pdf-differences/tree/main/Type3WordSpacing
2025-03-29 00:12:08 +01:00
Jonas Jenwald
8bcc3664c9 [api-minor] Attempt to improve support for using the PDF.js builds with Vite
Similar to Webpack there's apparently other bundlers that will not leave `import`-calls alone unless magic comments are used.
Hence we extend the builder to also append `/* @vite-ignore */` comments to `import`-calls, in order to attempt to improve support for using the PDF.js builds together with Vite.

This patch also renames `__non_webpack_import__` to `__raw_import__` since the functionality is no longer bundler-specific.

***PLEASE NOTE:*** This patch is provided as-is, and it does *not* mean that the PDF.js project can/will provide official support for Vite.
2025-03-28 16:34:00 +01:00
Jonas Jenwald
f577271908 Simplify the compileType3Glyph function to just return the Path2D objects
Originally this function would "manually" invoke the rendering commands for Type3-glyphs, however that was changed some time ago:
 - Initial `Path2D` support was added in PR 14858, but the old code kept for Node.js compatibility.
 - Since PR 15951 we've been using a `Path2D` polyfill in Node.js environments.

Hence, after the previous commit, we can further simplify this function by *directly* returning/using the `Path2D` object when rendering Type3-glyphs; see also https://github.com/mozilla/pdf.js/pull/19731#discussion_r2018712695
While this won't improve performance significantly, when compared to the introduction of `Path2D`, it definately cannot hurt.
2025-03-28 15:20:43 +01:00
Jonas Jenwald
852b7e407a Pre-apply the transform when building the Path2D objects for Type3-fonts
Rather than updating the transform every time that we're painting a Type3-glyph, we can instead just compute the "final" coordinates during building of the `Path2D` objects.
2025-03-28 13:28:25 +01:00
Calixte Denizet
6ff1626cf3 Update @fluent/dom to 0.10.1 2025-03-28 09:39:02 +01:00
calixteman
3da8901f26
Merge pull request #19728 from calixteman/bug1956513
[Editor] Set an aria-description for an added signature (bug 1956513)
2025-03-27 21:31:02 +01:00
Calixte Denizet
7d8c64b2ff [Editor] Set an aria-description for an added signature (bug 1956513)
NVDA behaves differently depending if the user is hovering or focusing an added signature.
An aria-description is read in both cases while an aria-label is not.
2025-03-27 18:14:06 +01:00
Jonas Jenwald
29788eb0b8 Use Util.rectBoundingBox more in the annotation code (PR 19713 follow-up)
By changing the return format of the various `pointsCallback` functions we can use the `Util.rectBoundingBox` helper in the `MarkupAnnotation.prototype._setDefaultAppearance` method as well, thus shortening the code slightly.
2025-03-27 13:46:36 +01:00
Jonas Jenwald
c6b9338f6f
Merge pull request #19719 from Snuffleupagus/structTree-xref
Pass the `XRef`-instance explicitly to the `StructTreeRoot` class, and simplify the `StructElementNode.prototype.role` getter
2025-03-25 19:41:20 +01:00
Jonas Jenwald
22107145df
Merge pull request #19691 from Snuffleupagus/xfa-template-rm-reduce
Remove `Array.prototype.reduce` usage from the `src/core/xfa/template.js` file
2025-03-25 18:17:12 +01:00
Jonas Jenwald
532406427b Simplify the StructElementNode.prototype.role getter a tiny bit
Given that the `roleMap` only contains `Name`-strings, the lookup can be simplified thanks to modern JavaScript features.
2025-03-25 18:04:56 +01:00
Jonas Jenwald
3c93d63731 Pass the XRef-instance explicitly to the StructTreeRoot class
This avoids the current situation where we're accessing it through various dictionaries, since that's a somewhat brittle solution given that in the general case a `Dict`-instance may not have the `xref`-field set (see e.g. the empty-Dict).
2025-03-25 18:04:51 +01:00
Calixte Denizet
6146e5fee7 Optimize save-transform-constructPath-restore
The 4 operations can be replaced with just one in applying the transform to the points coordinates.
2025-03-25 15:31:45 +01:00
Calixte Denizet
dee80cb082 In the struct tree a kid can be a reference to an MCID entry (issue #19694) 2025-03-25 15:01:52 +01:00
Calixte Denizet
1d0227af62 Don't overwrite the global alpha when switching to smask mode
It fixes #issue16287.
2025-03-24 21:35:09 +01:00
calixteman
b57da32d70
Merge pull request #19716 from calixteman/issue16742
Take into account the group bbox
2025-03-24 16:57:34 +01:00
Jonas Jenwald
9456b88f6b Remove Array.prototype.reduce usage from the src/core/xfa/template.js file
Using `Array.prototype.reduce` often leads to less readable code, and in these cases we can replace that with other Array-methods instead.
2025-03-24 16:40:41 +01:00
Jonas Jenwald
fceaab8864
Merge pull request #19713 from Snuffleupagus/Util-minMax-methods
Add new bounding-box helpers in `Util` to reduce code duplication
2025-03-24 16:39:05 +01:00
Jonas Jenwald
d8d4f2a850
Merge pull request #19714 from Snuffleupagus/MathClamp-3
Use the `MathClamp` helper function even more (PR 19617 follow-up)
2025-03-24 16:35:07 +01:00
Calixte Denizet
a3c31904f1 Take into account the group bbox
It fixes #16742.
2025-03-24 15:07:31 +01:00
Jonas Jenwald
b85f0903ca Add new bounding-box helpers in Util to reduce code duplication
Currently we have a `Util`-helper for computing the bounding-box of a Bézier curve, however for simple points and rectangles we repeat virtually identical code in many spots throughout the code-base.

 - Introduce new `Util.pointBoundingBox` and `Util.rectBoundingBox` helpers.

 - Remove the "fallback" from `Util.bezierBoundingBox` and only support passing in a `minMax`-array, since there's only a single call-site using the other format and it could be easily updated.
2025-03-23 19:20:02 +01:00
Calixte Denizet
2369e2d84f Take into account the path and the line width when consuming a stroked path 2025-03-23 18:08:06 +01:00
Jonas Jenwald
4547e582ff Use the MathClamp helper function even more (PR 19617 follow-up)
There's a few more spots that I accidentally missed in PR 19617.
2025-03-23 17:11:06 +01:00
calixteman
7c5695f5c6
Merge pull request #19708 from calixteman/fix_save_smask_mode
Fix save/restore while in smask mode
2025-03-23 14:45:09 +01:00
Jonas Jenwald
e73224ded7 Introduce Math.sumPrecise usage in the code-base
This is a new JavaScript feature that makes it easy to compute the sum of list of values; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sumPrecise

This allows us to remove most cases of `Array.prototype.reduce`, which helps improve readability since that (in my opinion) often isn't the most intuitive code.
2025-03-23 13:03:56 +01:00
Calixte Denizet
c275c72977 Fix save/restore while in smask mode
The rendering bug with issue17779.pdf is due to the fact that we call save on the suspended ctx
but not on the the current ctx. So each time we've something like save/transform/restore then
the transform not "removed" when restoring.
So this patch just apply the save/restore operations to ctx which are mirrored on the suspended one.
2025-03-22 23:26:51 +01:00
calixteman
d009e4b3a7
Merge pull request #19689 from calixteman/use_path2d
[api-minor] Use a Path2D when doing a path operation in the canvas (bug 1946953)
2025-03-22 21:46:27 +01:00
Calixte Denizet
be1f5671bb [api-minor] Use a Path2D when doing a path operation in the canvas (bug 1946953)
With this patch, all the paths components are collected in the worker until a path
operation is met (i.e., stroke, fill, ...).
Then in the canvas a Path2D is created and will replace the path data transfered from the worker,
this way when rescaling, the Path2D can be reused.
In term of performances, using Path2D is very slightly improving speed when scaling the canvas.
2025-03-22 20:35:24 +01:00
Tim van der Meij
11e89b74d9
Merge pull request #19696 from Snuffleupagus/issue-19695
Extend `getSupplementalGlyphMapForCalibri` with Pound-sign (issue 19695)
2025-03-22 13:21:07 +01:00