1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 01:28:06 +02:00
Commit graph

19421 commits

Author SHA1 Message Date
Calixte Denizet
2369e40d2e [Editor] Update popup position and contents after a FreeText has been edited 2024-05-21 16:54:10 +02:00
Aditi
9edca0a5ed Add lang attribute to canvas element
Fixes issue #16843.
In certain cases, the text layer was misaligned
due to a difference between the `lang` attribute
of the viewer and the canvas. This commit addresses
the problem by adding the `lang` attribute to the canvas.

The issue was caused because PDF.js uses serif/sans-serif
fonts to generate the text layer and relies on system fonts.
The difference in the `lang` attribute led to different fonts
being picked, causing the misalignment.
2024-05-21 19:41:24 +05:30
Jonas Jenwald
dce9c6d956
Merge pull request #18125 from Snuffleupagus/issue-18122
Support corrupt PDF documents that contain "endsteam" commands (issue 18122)
2024-05-21 16:09:01 +02:00
Tim van der Meij
661a62bb30
Merge pull request #18121 from calixteman/update_puppeteer_22_9_0
Update puppeteer to 22.9.0
2024-05-21 14:29:29 +02:00
Tim van der Meij
8753bd9b99
Merge pull request #18113 from timvandermeij/through2
Remove the `through2` dependency in favor of the built-in Node.js `stream.Transform`
2024-05-21 14:20:14 +02:00
Jonas Jenwald
57014d0d13 Support corrupt PDF documents that contain "endsteam" commands (issue 18122)
This patch also re-factors the findStreamLength-helper to avoid even more code duplication.
2024-05-21 13:38:17 +02:00
Jonas Jenwald
9ee7c07b83
Merge pull request #18104 from Snuffleupagus/TextLayer-class
[api-minor] Re-factor the basic textLayer-functionality
2024-05-21 12:28:28 +02:00
Jonas Jenwald
59637c1fa8
Merge pull request #18115 from Snuffleupagus/freeze-evaluatorOptions
Freeze `evaluatorOptions` in the src/core/pdf_manager.js file
2024-05-21 12:19:04 +02:00
Calixte Denizet
9dcaff230c Update puppeteer to 22.9.0 2024-05-20 22:01:59 +02:00
Jonas Jenwald
db7e68aea8
Merge pull request #18119 from Snuffleupagus/issue-18117
Support charCodes larger than 32-bit in `adjustMapping` (issue 18117)
2024-05-20 13:08:28 +02:00
Jonas Jenwald
440b4b6eeb Support charCodes larger than 32-bit in adjustMapping (issue 18117)
This also required changing the initial `charCodeToGlyphId`-data to an Object, which seems generally correct since it's consistent with existing code in the `src\core\{cff_font, type1_font}.js` files.
2024-05-20 12:13:55 +02:00
Jonas Jenwald
3cd6c6c0e6 Freeze evaluatorOptions in the src/core/pdf_manager.js file
Given that these options are passed from the API we don't want to accidentally modify them.
2024-05-18 15:16:12 +02:00
Tim van der Meij
c7739dae13
Remove the through2 dependency in favor of the built-in Node.js stream.Transform
The `through2` dependency got introduced over four years ago in #11325 to
replace the unmaintained `gulp-transform` dependency. However, sadly the
same holds for `through2` since the last release was also four years ago.

Fortunately the `through2` dependency can trivially be replaced with the
built-in Node.js `stream.Transform` API nowadays. In fact, the `through2`
dependency mentions themselves in their README already that they are "a
tiny wrapper around Node.js streams.Transform". The `stream.Transform`
API is available in all Node.js versions we support, and in Node.js 6
already the simplified constructor approach for `stream.Transform` got
introduced to simplify creating custom stream transformers; see
https://nodejs.org/docs/latest-v6.x/api/stream.html#stream_new_stream_transform_options.

This commit therefore replaces `through2` by switching to the
`stream.Transform` API directly so we don't need any wrappers anymore.
Note that for our case the only change we have to make is to enable
object mode, see https://nodejs.org/api/stream.html#object-mode, because
we pass in `VinylFile` objects instead of e.g. regular `Buffer` objects.

I have confirmed in two ways that this is indeed a drop-in replacement:

- Running the Gulp targets that call the `transform` function and
  diffing the resulting `build` folder before/after this patch, with
  `diff -r build-old/ build-new/`, to ensure that there are no
  unexpected changes in the output.
- Changing the Gulpfile to, instead of UTF-8, transform the files to
  ASCII, and diffing the resulting `build` folder to confirm that the
  transformation logic works and produces different results, such as:

```
diff build/lib/core/standard_fonts.js build-ascii/lib/core/standard_fonts.js
284c284
<   t["Trinité"] = true;
---
>   t["Trinit�"] = true;
```
2024-05-17 16:32:31 +02:00
Jonas Jenwald
15b5808eee [api-minor] Re-factor the basic textLayer-functionality
This is very old code, and predates e.g. the introduction of JavaScript classes, which creates unnecessarily unwieldy code in the viewer.
By introducing a new `TextLayer` class in the API, similar to how e.g. the `AnnotationLayer` looks, we're able to keep most parameters on the class-instance itself. This removes the need to manually track them in the viewer, and simplifies the call-sites.

This also removes the `numTextDivs` parameter from the "textlayerrendered" event, since that's only added to support default-viewer functionality that no longer exists.

Finally we try, as far as possible, to polyfill the old `renderTextLayer` and `updateTextLayer` functions since they are exposed in the library API.
For *simple* invocations of `renderTextLayer` the behaviour should thus be the same, with only a warning printed in the console.
2024-05-17 14:20:20 +02:00
Tim van der Meij
63b66b412c
Merge pull request #18109 from Snuffleupagus/textLayer-no-cleanup-on-pending
Don't invoke `cleanupTextLayer` when there are pending textLayers
2024-05-17 14:10:33 +02:00
Jonas Jenwald
d8e0fca609 Don't invoke cleanupTextLayer when there are pending textLayers
*Please note:* This doesn't really affect the viewer, but may affect the library API if multiple PDF documents are opened in parallel.

Since we clean-up "global" textLayer-data when destroying a PDF document, this means that other active PDFs could potentially break by invoking `cleanupTextLayer` unconditionally. Note that textLayer rendering is an asynchronous task, and we thus need to ensure those are all finished before running clean-up.
2024-05-17 08:52:10 +02:00
Tim van der Meij
ab9574fc62
Merge pull request #18107 from timvandermeij/needle
Remove the obsolete `needle` dependency
2024-05-16 20:31:51 +02:00
Tim van der Meij
ca056d79dd
Remove the obsolete needle dependency
The `needle` dependency originally got introduced in #12024, almost four
years ago, to be able to use pre-built binaries for the `canvas`
dependency on macOS. However, nowadays the `needle` dependency isn't
used by `canvas` anymore, or any other package we use for that matter,
as shown by the empty NPM dependency tree:

```
$ npm ls needle
pdf.js
└── needle@3.3.1
```

Investigation showed that the `canvas` package depends on the
`node-pre-gyp` package which in turn depended on `needle` (see
https://github.com/Automattic/node-canvas/issues/1110#issuecomment-411232630),
but in version 1.0.0 of `node-pre-gyp` from three years ago the `needle`
dependency got dropped in favor of `node-fetch` (see
a74f5e367c/CHANGELOG.md (L52)).
This explains why the NPM dependency tree is empty now and proves that
we can safely get rid of this dependency now.
2024-05-16 20:07:01 +02:00
Tim van der Meij
e8e9a3e29f
Merge pull request #18106 from timvandermeij/rimraf
Remove the `rimraf` dependency in favor of the built-in Node.js `fs.rmSync`
2024-05-16 19:19:42 +02:00
Tim van der Meij
fad14321a8
Remove the rimraf dependency in favor of the built-in Node.js fs.rmSync
In Node.js 14.14.0 the `fs.rmSync` function was added that removes files
and directories. The `recursive` option is used to remove directories
and their contents, making it a drop-in replacement for the `rimraf`
dependency we use.

Given that PDF.js now requires Node.js 18+ we can be sure that this
option is available, so we can safely remove `rimraf` and reduce the
number of project dependencies.

Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
2024-05-16 17:37:27 +02:00
Tim van der Meij
0603d1ac18
Merge pull request #18077 from Snuffleupagus/issue-18022
[api-minor] Respect the `drawingDelay` also when CSS-only zooming is used (issue 18022)
2024-05-16 14:19:40 +02:00
Tim van der Meij
128705c16e
Merge pull request #18103 from Snuffleupagus/pr-18089-followup
Actually disable `TextLayerRenderTask.prototype.#processItems` when `MAX_TEXT_DIVS_TO_RENDER` is reached (PR 18089 follow-up)
2024-05-16 14:17:09 +02:00
Jonas Jenwald
d5f3829f91 Actually disable TextLayerRenderTask.prototype.#processItems when MAX_TEXT_DIVS_TO_RENDER is reached (PR 18089 follow-up)
I broke this accidentally in PR 18089, sorry about that!
Note that since `#processItems` is private we can no longer just "replace" the method as was done in PR 18052.
2024-05-16 11:48:11 +02:00
Tim van der Meij
4db843617f
Merge pull request #18047 from Snuffleupagus/issue-18042
Avoid re-parsing global images that failed decoding (issue 18042, PR 17428 follow-up)
2024-05-15 15:40:18 +02:00
Tim van der Meij
b800268fca
Merge pull request #18094 from Snuffleupagus/rm-unnecessary-signal
Remove unnecessary `signal` parameter from `removeEventListener` calls
2024-05-15 13:34:41 +02:00
Tim van der Meij
66c2bf62c1
Merge pull request #18093 from timvandermeij/exception
Implement a unit test for the `BaseException` class
2024-05-15 13:33:25 +02:00
Jonas Jenwald
656963e72a Remove unnecessary signal parameter from removeEventListener calls
This parameter is not necessary, as outlined in https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#options
2024-05-15 09:09:50 +02:00
Tim van der Meij
6b237e3358
Implement a unit test for the BaseException class
The issue from #18003 hasn't been shown to be caused by PDF.js, but it
did surface that we don't have (direct) unit test coverage for the
`BaseException` class. This made it more difficult to prove that the
`stack` property was already available on exception instances, but more
importantly it caused the CI to be green even though the suggested
change would have caused the `stack` property to disappear.

To avoid future regressions, for e.g. similar changes or a rewrite from
a closure to a proper class, this commit introduces a dedicated unit
test for `BaseException` that asserts that our exception instances
indeed expose all expected properties.
2024-05-14 20:21:42 +02:00
Tim van der Meij
7e5e06b886
Merge pull request #18091 from Snuffleupagus/rm-_fetchDocument
Inline the `_fetchDocument` helper function in `getDocument`
2024-05-14 18:27:04 +02:00
Tim van der Meij
44b7cc517d
Merge pull request #18092 from timvandermeij/updates
Update dependencies and translations to the most  recent versions
2024-05-14 18:00:43 +02:00
Jonas Jenwald
6b171540b7 Initialize the networkStream synchronously in getDocument
This is fairly old code, and at some point the need for this to be asynchronous disappeared.
2024-05-14 17:04:25 +02:00
Jonas Jenwald
cbb8748a22 Inline the _fetchDocument helper function in getDocument
This function has been modified a number of times over the years, and at this point it's small/simple enough that we can just inline the code instead.
2024-05-14 16:29:41 +02:00
Tim van der Meij
b0dbacd0e1
Update translations to the most recent versions 2024-05-14 16:26:34 +02:00
Tim van der Meij
d7f2bc044a
Upgrade eslint-plugin-unicorn to version 53.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v53.0.0
doesn't indicate any breaking changes that should impact us.

Most notably it contains support for ESLint 9, which brings us a step
closer towards #17928.
2024-05-14 16:23:36 +02:00
Tim van der Meij
161b942d41
Update dependencies to the most recent versions
The Puppeteer update should in particular be helpful for us because it
contains improved WebDriver BiDi compatibility, a newer Chrome version
(both might help for #17962) and an official deprecation of CDP for
Firefox. Note that the latter doesn't require changes on our end because
we already use WebDriver BiDi unconditionally for Firefox since commit
4db0174. The full release notes can be found at
https://github.com/puppeteer/puppeteer/releases/tag/puppeteer-core-v22.8.0.
2024-05-14 16:22:06 +02:00
Tim van der Meij
33f3228e00
Merge pull request #18087 from calixteman/update_openjpeg
Update openjpeg build (bug 1896577)
2024-05-14 16:05:52 +02:00
Tim van der Meij
c6d7ae2076
Merge pull request #18089 from Snuffleupagus/textLayer-private
Improve the `TextLayerRenderTask` implementation
2024-05-14 16:03:05 +02:00
Tim van der Meij
40f9371bf8
Merge pull request #17923 from nicolo-ribaudo/fix-text-selection
Fix flickering on text selection
2024-05-14 15:58:20 +02:00
Tim van der Meij
ac7b86d341
Merge pull request #18080 from calixteman/bug1895909
[Editor] Fix the CSS properties of the canvas when it's used in a stampEditor (bug 1895909)
2024-05-14 15:33:53 +02:00
Nicolò Ribaudo
6f2e4d0d94
Fix flickering on text selection
When seleciting on a touch screen device, whenever the finger moves to a
blank area (so over `div.textLayer` directly rather than on a `<span>`),
the selection jumps to include all the text between the beginning of the
.textLayer and the selection side that is not being moved.

The existing selection flickering fix when using the mouse cannot be
trivially re-used on mobile, because when modifying a selection on
a touchscreen device Firefox will not emit any pointer event (and
Chrome will emit them inconsistently). Instead, we have to listen to the
'selectionchange' event.

The fix is different in Firefox and Chrome:
- on Firefox, we have to make sure that, when modifying the selection,
  hovering on blank areas will hover on the .endOfContent element
  rather than on the .textLayer element. This is done by adjusting the
  z-indexes so that .endOfContent is above .textLayer.
- on Chrome, hovering on blank areas needs to trigger hovering on an
  element that is either immediately after (or immediately before,
  depending on which side of the selection the user is moving) the
  currently selected text. This is done by moving the .endOfContent
  element around between the correct `<span>`s in the text layer.

The new anti-flickering code is also used when selecting using a mouse:
the improvement in Firefox is only observable on multi-page selection,
while in Chrome it also affects selection within a single page.

After this commit, the `z-index`es inside .textLayer are as follows:
- .endOfContent has `z-index: 0`
- everything else has `z-index: 1`
  - except for .markedContent, which have `z-index: 0`
    and their contents have `z-index: 1`.

`.textLayer` has an explicit `z-index: 0` to introduce a new stacking context,
so that its contents are not drawn on top of `.annotationLayer`.
2024-05-14 14:31:12 +02:00
Jonas Jenwald
036fd11ad7 Improve the TextLayerRenderTask implementation
- Change all possible semi-private methods into properly private ones. Note that this code is old enough to predate standard classes.

 - Move the `appendText` helper function into `TextLayerRenderTask`, as a private method, to avoid having to manually pass in the scope.

 - Simplify `#layoutText` by directly passing in all necessary data. This is possible after the changes PR 18052.
2024-05-14 14:10:17 +02:00
Jonas Jenwald
c5f92437f7 Avoid re-parsing global images that failed decoding (issue 18042, PR 17428 follow-up)
For images that failed to decode once we want to avoid a pointless round-trip to the main-thread, which could otherwise happen for globally cached images.
2024-05-14 13:58:36 +02:00
Jonas Jenwald
bb9bb34721
Merge pull request #17941 from Snuffleupagus/getTextContent-lang
[api-minor] Include the document /Lang attribute in the textContent-data
2024-05-14 13:57:46 +02:00
Jonas Jenwald
36a496b409
Merge pull request #18060 from nicolo-ribaudo/babel-plugin-class
Update the Babel plugin to remove empty class constructors
2024-05-14 13:14:54 +02:00
Jonas Jenwald
6d523c316c [api-minor] Include the document /Lang attribute in the textContent-data
- These changes will allow a simpler way of implementing PR 17770.

 - The /Lang attribute is fetched lazily, with the first `getTextContent` invocation. Given the existing worker-thread caching, this will thus only need to be done *once* per PDF document (and most PDFs don't included this data).

 - This makes the /Lang attribute *directly available* in the `textLayer`, which has the following advantages:
    - We don't need to block, and thus delay, overall viewer initialization on fetching it (nor pass it around throughout the viewer).

    - Third-party users of the `textLayer` will automatically benefit from this, once we start actually using the /Lang attribute in PR 17770.
      *Please note:* This also, importantly, means that the `text` reference-tests will then cover this code (which wouldn't otherwise have been the case).
2024-05-14 12:44:41 +02:00
Jonas Jenwald
c0b5d93ef4
Merge pull request #18052 from Snuffleupagus/textLayer-only-ReadableStream
Restore broken functionality and simplify the implementation in `src/display/text_layer.js`
2024-05-14 12:30:27 +02:00
Jonas Jenwald
298d72133e
Merge pull request #18051 from Snuffleupagus/NodePackages
[api-minor] Re-factor how Node.js packages/polyfills are  loaded (issue 17245)
2024-05-14 11:43:57 +02:00
Calixte Denizet
699e8aa3e4 Update openjpeg build (bug 1896577)
It just contains fixes for:
 - bug 1896577
 - https://github.com/mozilla/pdf.js.openjpeg/issues/1
2024-05-14 10:11:58 +02:00
Jonas Jenwald
761abc7cc3
Merge pull request #18066 from Snuffleupagus/rm-FontFaceObject-ignoreErrors
Remove the `ignoreErrors` option from the `FontFaceObject` class
2024-05-14 09:49:08 +02:00
Tim van der Meij
0347e59b99
Merge pull request #18061 from Snuffleupagus/api-report-Stats
Slightly re-factor how the viewer initializes debug-only functionality
2024-05-13 19:38:59 +02:00