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

18958 commits

Author SHA1 Message Date
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
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
Calixte Denizet
093bdfd971 [Editor] Fix the CSS properties of the canvas when it's used in a stampEditor (bug 1895909)
And move the page canvas properties under canvasWrapper in order to avoid future regressions.
2024-05-13 16:58:19 +02:00
Tim van der Meij
df23679bc6
Merge pull request #18079 from mozilla/revert-18019-safari-zoom-fix
Revert "Fix rendering problem when zooming on Safari" for causing bug 1895909
2024-05-13 16:45:03 +02:00
Jonas Jenwald
75a1955fd0
Revert "Fix rendering problem when zooming on Safari" 2024-05-13 16:14:38 +02:00
Jonas Jenwald
1a3ea15950 [api-minor] Respect the drawingDelay also when CSS-only zooming is used (issue 18022)
If a user manually calls `PDFPageView.prototype.update()` with a `drawingDelay`-option then it'll always be necessary to re-call the method *without* a delay afterwards, regardless of the `maxCanvasPixels`-value (e.g. even when CSS-only zooming is used).
2024-05-13 15:24:48 +02:00
Tim van der Meij
d9cff1af04
Merge pull request #18069 from Snuffleupagus/rm-spaceWidth
Remove the unused `Font.prototype.spaceWidth` getter (PR 13424 follow-up)
2024-05-13 15:18:44 +02:00
Tim van der Meij
1c25e951a4
Merge pull request #18055 from Snuffleupagus/PDFViewer-signal
Remove event listeners with `signal` in web/pdf_viewer.js
2024-05-13 15:16:01 +02:00
Nicolò Ribaudo
46626ac64a
Update the Babel plugin to remove empty class constructors
This only happens when it's safe to do so. The exceptions are:
- when the class extends another subclass: removing the constructor would remove the error about the missing super() call
- when there are default parameters, that could have side effects
- when there are destructured prameters, that could have side effects
2024-05-13 11:51:43 +02:00
Jonas Jenwald
4aee67227e Remove the unused Font.prototype.spaceWidth getter (PR 13424 follow-up)
This getter became unused in PR 13424, well over two years ago, and apparently none of us noticed that.
2024-05-11 11:50:51 +02:00
Jonas Jenwald
5f6f1686b5 Remove the ignoreErrors option from the FontFaceObject class
- The `stopAtErrors` API option, which is the inverse of the "internal" `ignoreErrors` option, is explicitly documented as applying to *parsing* (i.e. the worker-thread) while the `FontFaceObject` class is used during rendering (i.e. the main-thread); see b6765403a1/src/display/api.js (L164-L167)

 - A glyph that fails in the `FontRendererFactory`, on the worker-thread, will already cause (overall) parsing to stop when `ignoreErrors === false` hence checking the option on the main-thread as well seems redundant; see b6765403a1/src/core/evaluator.js (L4527-L4533)

 - Removing this option simplifies the code, and slightly reduces the number of options that we need to handle in the main-thread code.
2024-05-11 10:18:23 +02:00
Jonas Jenwald
5e50479ac6 Use more object destructuring in the "commonobj" handler in the API 2024-05-11 09:44:10 +02:00
Jonas Jenwald
5fbc5ba16a Move the loadPDFBug function into PDFViewerApplication._parseHashParams
Given that this is a debug-only function we don't need to define it "globally" in the `web/app.js` file.
2024-05-11 09:42:05 +02:00
Jonas Jenwald
ba8c620e4b Inline the loadFakeWorker function at its only call-site in web/app.js
Given that this is a debug-only, and fairly short, function we can just inline the code.
2024-05-11 09:42:05 +02:00
Jonas Jenwald
4a8d742592 Move the reporting of page Stats into the API
This avoids having to add a couple of event listeners in the viewer, when debugging is enabled, and is consistent with the existing handling of `FontInspector` and `StepperManager` in the API.
2024-05-11 09:42:05 +02:00