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

7007 commits

Author SHA1 Message Date
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
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
Tim van der Meij
9023395550
Merge pull request #19681 from Snuffleupagus/AbortSignal-any-basic-polyfill
[api-minor] Add a basic `AbortSignal.any` polyfill in PDF.js `legacy` builds
2025-03-22 13:20:18 +01:00
Jonas Jenwald
fe19d9666f Replace the setValues function with Array.prototype.fill() in the src/core/bidi.js file
This code is originally from 2012, see PR 1218, and the Array-method wasn't available until Firefox 31 (released on 2014-07-22).
2025-03-21 23:00:38 +01:00
Jonas Jenwald
50eb97afb3 Improve the implementation in src/core/writer.js a little bit
- Let the `writeString` helper function return the new offset, to avoid having to recompute that in multiple spots.

 - In the `computeMD5` helper function we can create the `md5Buffer` via Array-destructuring, rather than using a manual loop.
2025-03-20 21:13:34 +01:00
Jonas Jenwald
f90732e4c3 Extend getSupplementalGlyphMapForCalibri with Pound-sign (issue 19695) 2025-03-20 20:12:24 +01:00
Jonas Jenwald
e6c869c127 Fix the MD5 computation in the src/core/writer.js file
Currently the MD5 computation doesn't actually work (at all?), since we're invoking the `calculateMD5` function without providing all of the necessary parameters and the PDF-data thus isn't taken into account.

Fixing this caused unit-tests to fail, which isn't that surprising since the current date/time is used in the MD5 computation, and we thus utilize Jasmine to work-around that.
2025-03-20 14:41:25 +01:00
Calixte Denizet
276c8f3518 [Editor] Take into account the parent rotation when switch to edit mode (issue #19424) 2025-03-19 14:26:55 +01:00
Jonas Jenwald
028e4f7ea8 [api-minor] Add a basic AbortSignal.any polyfill in PDF.js legacy builds
This is an admittedly very basic polyfill, to allow us to remove a bunch of inline feature testing, that I've thrown together based on reading https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static and related MDN articles.

Compared to PR 19218 it's obviously much more "primitive", however the implementation is simple and it doesn't suffer from any licensing issues (since I wrote the code myself).
2025-03-18 10:54:49 +01:00
Jonas Jenwald
00e3a4d87a
Merge pull request #19674 from Snuffleupagus/core-document-more-async
Introduce more `async` code in the `src/core/document.js` file
2025-03-17 21:40:16 +01:00
Jonas Jenwald
6243afa85e
Merge pull request #19675 from Snuffleupagus/IccColorSpace-fetchSync
Introduce a `fetchSync` helper function for the `IccColorSpace` classes
2025-03-17 20:22:00 +01:00
Jonas Jenwald
afb14bdc0b For JPEG images with CMYK-data, ensure that the alpha-component is set correctly when WebAssembly is disabled (issue 19676) 2025-03-17 16:15:32 +01:00
Jonas Jenwald
1fb6edc713 Introduce a fetchSync helper function for the IccColorSpace classes
This reduces code duplication a tiny bit, which shouldn't hurt.
2025-03-17 14:58:53 +01:00
Jonas Jenwald
d00482380a Introduce more async code in the src/core/document.js file 2025-03-17 13:20:51 +01:00
Tim van der Meij
f44cba86d5
Don't get ICC color space files if required API options are missing
This commit improves validation of the API options for the ICC color
space logic. If `useWasm` is `true` but the corresponding `wasmUrl`
or `iccUrl` API options are not provided we can avoid requesting
files with `null` URLs which always results in a 404 response.
2025-03-16 16:29:42 +01:00
Jonas Jenwald
9e8d4e4d46 [api-minor] Attempt to support fetching the raw data of the PDF document from the PDFDocumentLoadingTask-instance (issue 15085)
The new API-functionality will allow a PDF document to be downloaded in the viewer e.g. while the PasswordPrompt is open, or in cases when document initialization failed.
Normally the raw data of the PDF document would be accessed via the `PDFDocumentProxy.prototype.getData` method, however in these cases the `PDFDocumentProxy`-instance isn't available.
2025-03-16 10:09:44 +01:00
Jonas Jenwald
8a24c1907a Replace a few simple regular expressions in the XFA-code with string parsing
- Add a couple of `limit` parameters in cases where those were "missing", for `String.prototype.split()` calls, to avoid unnecessary parsing.

 - Remove some "pointless" initial trimming of leading/trailing spaces, since that's already done at a later parsing step in many cases.
2025-03-15 17:25:26 +01:00
Jonas Jenwald
ec30f0788b Slightly shorten a couple of MeshStreamReader methods
By using object destructuring in the `readCoordinate` and `readComponents` methods we can ever so slightly shorten this code.
2025-03-14 12:57:41 +01:00
Jonas Jenwald
78b310afb1
Merge pull request #19650 from Snuffleupagus/shorten-crypto
Shorten the `src/core/crypto.js` file a little bit
2025-03-13 12:46:53 +01:00