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

4006 commits

Author SHA1 Message Date
Tim van der Meij
f482232493
Merge pull request #19790 from Snuffleupagus/test-getAnnotationStorage-rm-entries
Simplify the `getAnnotationStorage` integration-test helper function
2025-04-12 13:36:20 +02:00
Jonas Jenwald
1048508dd1 Catch circular references in /Form XObjects (issue 19800)
For simplicity we will abort /Form XObject parsing *immediately* when encountering a circular reference, rather than letting it continue up until some limit (as e.g. PDFium appears to do), which should be fine since there are never any guarantees if/how *corrupt* PDF documents will render.
2025-04-11 16:54:22 +02:00
Jonas Jenwald
835a456767 Use adjustWidths unconditionally for all embedded fonts (issue 19802)
Previously we'd only do this for Type1/CFF fonts, see e.g. PR 6736, since the font-program may update the /FontMatrix.
However, it seems that we should do this unconditionally to account for fonts with non-default /FontMatrix-entries in the font-dictionary (which seem to be pretty rare).
2025-04-11 15:01:35 +02:00
Jonas Jenwald
fbc4f4b12a Handle non-integer and out-of-range values correctly in Indexed color spaces
In PDF version 2.0 the handling of Indexed color spaces was clarified as follows:
> The index value should be an integer in the range 0 to hival. If the value is a real number, it shall be rounded to the nearest integer (0.5 values shall be rounded up); if it is outside the range 0 to hival, it shall be adjusted to the nearest value within that range.

Please refer to https://github.com/pdf-association/pdf-differences/tree/main/IndexedColor
2025-04-09 15:31:49 +02:00
Jonas Jenwald
60bf9b133a Simplify the getAnnotationStorage integration-test helper function
As can be seen [at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries#parameters) the `Object.fromEntries` method accepts a `Map` directly, hence using the `Map.prototype.entries` method is superfluous here.
2025-04-09 13:42:22 +02:00
Jonas Jenwald
22657e2b6e
Merge pull request #19778 from Snuffleupagus/replace-getAll
[api-minor] Replace various `getAll` methods with iterators
2025-04-08 17:26:24 +02:00
Jonas Jenwald
38d01250f4 Enable the no-array-reduce ESLint plugin rule
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-reduce.md

Note that this still allows "simple" usage of `Array.prototype.reduce`, however most of those cases will be possible to replace with `Math.sumPrecise` once that becomes generally available (currently not supported in Node.js or QuickJS).
2025-04-08 12:21:20 +02:00
Nicolò Ribaudo
da5b681b16
[chrome] Fix text selection with .markedContent
The current text layer approach based on absolutely positioned
`<span>` elements by default causes flickering with text selection,
and we have browser-specific workarounds to solve that.

In Chrome, the workaround involves moving the `.endOfContent` element to
right after the last element that contains some selected content. This
works well in simple PDFs, but breaks when we have `span.markedContent`
elements. Given a text layer structure like the following, rendered
as four consecutive lines:
```html
<span class="markedContent">
  <br>
  <span>development enter the construction phase (estimated at around</span>
</span>
<span class="markedContent">
  <br>
  <span>300 MEUR).</span>
</span>
<span class="markedContent">
  <br>
  <span>Kreate's EBITA increased to 2.8 MEUR (Q4'23: 2.7 MEUR) and the</span>
</span>
<span class="markedContent">
  <br>
  <span>margin rose to 3.7% (Q4'23: 3.4%). However, profitability was</span>
</span>
```
when starting to select from inside the first line and dragging down
to the empty space after the second line, Chrome will anchor the
selection at the beginning of either the `<br>` or the `<span>` inside
the last `.markedContent`, depending on whether the selection is in
"per-character mode" (i.e. click and drag) or "per-word mode" (i.e.
double click and drag). This causes us to insert the `.endOfContent`
element in the wrong place (one element too far), which causes one
more line to be selected, which triggers another `"selecctionchange"`
event, which causes us to move `.endOfContent` again, and so on, looping
until when the whole page is selected.

This commit fixes the issue by making sure that when the end of the
selection range points to the _begining_ of an element, we walk back
the dom finding the first non-empty element, and attatch `.endOfContent`
to the end of that.
2025-04-07 17:36:40 +02:00
Jonas Jenwald
2c593b06e4 [api-minor] Replace various getAll methods with iterators
These `getAll` methods are not used anywhere within the PDF.js code-base, outside of tests, and were mostly added (speculatively) for third-party users.
To still allow access to the same data we instead introduce iterators on these classes, which (slightly) shortens the code and allows us to remove the `objectFromMap` helper function.

A summary of the changes in this patch:
 - Replace the `getAll` methods with iterators in the following classes: `AnnotationStorage`, `Metadata`, and `OptionalContentGroup`.

 - Change, and also re-name, `AnnotationStorage.prototype.setAll` into a test-only method since it's not used elsewhere.

 - Remove the `Metadata.prototype.has` method, since it's only used in tests and can be trivially replaced by calling `Metadata.prototype.get` and checking if the returned value is `null`.
2025-04-06 21:43:16 +02:00
Tim van der Meij
72feb4c256
Merge pull request #19775 from Snuffleupagus/AFSimple_Calculate-MIN-MAX-destructuring
Use Array-destructuring when computing MIN/MAX in `AFSimple_Calculate`
2025-04-06 18:32:37 +02:00
Jonas Jenwald
ec5b5184d3 Remove Array.prototype.reduce usage from the unit-tests
Using `Array.prototype.reduce` often leads to less readable code, and in these cases we can replace it with other Array-methods instead.
2025-04-06 12:12:37 +02:00
Jonas Jenwald
0845552ff9 Use Array-destructuring when computing MIN/MAX in AFSimple_Calculate
This appears to work fine with QuickJS, as evident by the added unit-test, and allows us to remove more `Array.prototype.reduce` usage.
2025-04-06 11:44:08 +02:00
Jonas Jenwald
dad6febc39 Pass the /Info-strings as a Map to the src/core/writer.js code
We want to iterate through the data in the `computeMD5` function, and `Map`s have "nicer" support for that than generic objects.
(Somewhat recently `Map` performance was improved in Firefox, however this also isn't really performance sensitive code.)
2025-04-04 13:36:13 +02:00
Tim van der Meij
ed08a6a988
Isolate the "basic operations" freetext editor integration tests
This commit reduces the number of freetext editor integration test suite
failures, in full isolation, from 5 to 0 by fixing the following issues
in the "basic operations" block:

- Most tests relied on the first test to enable freetext editing mode.
  For isolation we now do it explicitly in all tests.
- Most tests relied on the other tests having created editors. For
  isolation we now create the editors explicitly in the tests themselves.
- Most tests relied on previous tests for the editor numbering. For
  isolation we change the editor numbering to the one after initial
  document load. Since we can't have state (editors) from a previous
  test anymore we can remove various `clearAll` calls as well.
2025-03-30 18:52:19 +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
Jonas Jenwald
5b7b94c078 Spell "properly" in viewer integration-test names 2025-03-29 16:35:22 +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
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
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
Calixte Denizet
62df96894d [Editor] in the signature UI, disable the description input if there is no signature (bug 1956114) 2025-03-26 23:02:13 +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
Calixte Denizet
a3c31904f1 Take into account the group bbox
It fixes #16742.
2025-03-24 15:07:31 +01:00
calixteman
bcba053a5e
Merge pull request #19715 from calixteman/issue18529
Take into account the path and the line width when consuming a stroked path
2025-03-24 14:41:29 +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
Tim van der Meij
d01913e62e
Isolate the "create editor with keyboard" freetext editor integration tests
This commit reduces the number of freetext editor integration test suite
failures, in full isolation, from 6 to 5 by fixing the following issues
in the "create editor with keyboard" block:

- The second test relied on the first test to enable freetext editing
  mode and put focus on the page (annotation layer). For isolation we
  now do that explicitly in the second test.
- The second test relied on the first test for the editor numbering. For
  isolation we change the editor numbering to the one after initial
  document load.

Moreover, the test names have been updated to clarify with scenario is
being tested, which came up during comparison of the changes against
commit ea5eafa to make sure that we are still testing the originally
intended scenarios (confirmed by disabling the relevant code from the
commit per scenario and noticing the corresponding test failing).
2025-03-23 14:28:03 +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
Tim van der Meij
80d4d7058f
Merge pull request #19706 from timvandermeij/integration-tests-freetext-isolate-part-1
Isolate the "move editor with arrows" freetext editor integration tests
2025-03-23 12:01:30 +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
Tim van der Meij
440d519326
Isolate the "move editor with arrows" freetext editor integration tests
This commit reduces the number of freetext editor integration test suite
failures, in full isolation, from 8 to 6 by fixing the following issues
in the "move editor with arrows" block:

- The second and third test relied on the first test to enable freetext
  editing mode. For isolation we now do it explicitly in both tests.
- The second test relied on the first test having created an editor. For
  isolation we now create the editor explicitly in the second test.
- The third test relied on the previous tests for the editor numbering.
  For isolation we change the editor numbering to the one after initial
  document load. Since we can't have state (editors) from a previous
  test anymore we can remove the `clearAll` call as well.
2025-03-22 20:46:21 +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
1c73e526e0
Isolate the scripting integration tests
To avoid being able to introduce dependencies between tests, and to
bring existing dependencies to the surface, this commit makes sure that
we close the document between tests so that we can't accidentally rely
on state set by a previous test. This prevents multiple tests from
failing if one of them fails and makes debugging easier by being able to
run each test on their own independent of other tests.

This commit, combined with the previous ones, is enough to make the
scripting integration test suite pass consistently if random mode in
Jasmine is enabled, proving that the tests are fully isolated now.
2025-03-22 18:31:23 +01:00
Tim van der Meij
0f3692a621
Remove the dependency between the order-dependent scripting integration tests
The integration tests are order-dependent because they rely on input
field state set by a previous test. This commit fixes the issue by
updating the values to match the initial state of the document, which
makes sure that we don't build upon values from previous tests while
still testing the intended logic in the individual tests like before.
2025-03-22 18:31:23 +01:00
Tim van der Meij
334d681359
Refactor the order-dependent scripting integration tests
By checking for the expected value directly we can shorten the code, and
it simplifies removing the dependencies between the tests in the next
commit (by having fewer places to change). Note that this follows the
same pattern as PRs #19192, #19001 and #18399 and also helps to remove
any further possibilities for intermittent failures.
2025-03-22 18:31:10 +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
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
Tim van der Meij
2a4f970e00
Fix the "Signature Editor Basic operations must check copy and paste" integration test
This integration test fails intermittently because of concurrent
clipboard access due to running the test in parallel in both browsers.
It can be reproduced by introducing `await waitForTimeout(1000)` between
the copy and paste operations.

This commit fixes the issue by running the test sequentially instead,
mirroring the change from commit 0e94f2bd.
2025-03-16 20:35:36 +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
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
Jonas Jenwald
ef01ceda1b Change a couple of "password" ref-tests to "eq" tests
Currrently these are just "load" tests, and by also testing rendering we get slightly better test-coverage for the `src/core/crypto.js` file.
2025-03-13 11:58:13 +01:00
calixteman
38cb01c629
Merge pull request #19648 from calixteman/bug1953290
[Editor] Fix the role of the different editors in order to make them interactive elements (bug 1953290)
2025-03-13 09:20:26 +01:00
Calixte Denizet
7fce3eac93 [Editor] Fix the role of the different editors in order to make them interactive elements (bug 1953290)
Having some interactive elements forces the screen readers to switch to form mode
and consequently they delegate the keyboard stuff to the browser.
This patch sets an aria label on each editor in order to have a better description than just
'application'.
2025-03-12 22:19:31 +01:00
Jonas Jenwald
319d239f41 Add an OutputScale static method to get the devicePixelRatio
Currently we lookup the `devicePixelRatio`, with fallback handling, in a number of spots in the code-base.
Rather than duplicating code we can instead add a new static method in the `OutputScale` class, since that one is now exposed in the API.
2025-03-12 21:07:06 +01:00
Jonas Jenwald
ee34c5c648 Let Lexer.prototype.getNumber treat more cases of a single minus sign as zero (bug 1953099)
This patch extends the approach of PR 14543, by also treating e.g. minus signs followed by '(' or '<' as zero.
Inside of a /Contents stream those characters will generally mean the start of one or more glyphs.
2025-03-12 17:50:13 +01:00
Jonas Jenwald
221eba29b9 Don't close the secondaryToolbar when clicking inside it (PR 18385 follow-up)
When the DOM structure of the viewer was updated in PR 18385 it caused the `secondaryToolbar` to accidentally start closing when clicking inside of it, since the `secondaryToolbar` now reside *under* the `toolbar` in the DOM.

**Steps to reproduce:**
 - Open the viewer.
 - Open the `secondaryToolbar`.
 - Try to change document rotation at least *twice*.

**Expected behaviour:**
 The document rotation can be changed an arbitrary number of times.

**Actual results:**
 The `secondaryToolbar` closes after changing rotation just once.
2025-03-11 19:26:23 +01:00
Calixte Denizet
4b4f85484e Always use the absolute value of the line thickness (issue 19633) 2025-03-11 14:03:23 +01:00
Calixte Denizet
b5a7b827b5 [Editor] Add an aria label to an added signature (bug 1952571) 2025-03-10 19:15:05 +01:00
calixteman
febf59ce75
Merge pull request #19636 from calixteman/bug1952558
[Editor] Make sure the save checkbox isn't focusable when saving is disabled (bug 1952558)
2025-03-10 18:46:40 +01:00
Calixte Denizet
69a2e5137d [Editor] Make sure the save checkbox isn't focusable when saving is disabled (bug 1952558)
And fix the the width of the warning message when the limit of signatures has been reached:
in french the string is longer than the dialog's one.
2025-03-10 18:08:42 +01:00