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

19839 commits

Author SHA1 Message Date
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
Nicolò Ribaudo
83d878d34c
Rename builder esprima fixtures to babel
f724ae98a1 changed the build
script to use Babel, so this commit updates the file names accordingly
2024-05-09 15:17:30 +02:00
Jonas Jenwald
469738c1ce Remove event listeners with signal in web/pdf_viewer.js 2024-05-08 16:07:43 +02:00
Jonas Jenwald
9418ed19e7 [api-minor] Remove the, now unused, pdfjsLibPromise global
This global was only introduced to work-around problems caused by the GENERIC PDF.js build using top level await. Since that was removed in the previous commit, this global is now dead code.
2024-05-07 18:21:56 +02:00
Jonas Jenwald
8d86e18a32 Restore the MAX_TEXT_DIVS_TO_RENDER limit in the textLayer
This limit is currently completely non-functional, since the check happens *after* the entire textLayer has been parsed and appended to the DOM. It seems that this has been *accidentally* broken ever since the introduction of `ReadableStream` support.
The reason that this hasn't caused noticeable textLayer-related performance issues in practice is probably because we nowadays manage to coalesce the textLayer into fewer overall DOM elements, whereas years ago many PDF documents ended up with one DOM element *per* glyph.

By moving this check, and thus restoring the functionality, we're also able to remove the `render` helper function and simplify the code.
2024-05-07 13:04:00 +02:00
Jonas Jenwald
30840e411e Ensure that the textLayer styleCache is always cleared, even on failure
By also moving it to the `TextLayerRenderTask`-instance, we can avoid a bit of manual parameter passing.
2024-05-07 13:04:00 +02:00
Jonas Jenwald
049848ba00 Unify the ReadableStream and TextContent code-paths in src/display/text_layer.js
The only reason that this code still accepts `TextContent` is for backward-compatibility purposes, so we can simplify the implementation by always using a `ReadableStream` internally.
2024-05-07 13:03:57 +02:00
Jonas Jenwald
2643570364 [api-minor] Re-factor how Node.js packages/polyfills are loaded (issue 17245)
*Please note:* This removes top level await from the GENERIC builds of the PDF.js library.

Despite top level await being supported in all modern browsers/environments, note [the MDN compatibility data](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#browser_compatibility), it seems that many frameworks and build-tools unfortunately have trouble with it.
Hence, in order to reduce the influx of support requests regarding top level await it thus seems that we'll have to try and fix this.

Given that top level await is only needed for Node.js environments, to load packages/polyfills, we re-factor things to limit the asynchronicity to that environment.
The "best" solution, with the least likelihood of causing future problems, would probably be to await the load of Node.js packages/polyfills e.g. at the top of the `getDocument`-function. Unfortunately that doesn't work though, since that's a *synchronous* function that we cannot change without breaking "the world".

Hence we instead await the load of Node.js packages/polyfills together with the `PDFWorker` initialization, since that's the *first point* of asynchronicity during initialization/loading of a PDF document. The reason that this works is that the Node.js packages/polyfills are only needed during fetching of the PDF document respectively during rendering, neither of which can happen *until* the worker has been initialized.
Hopefully this won't cause any future problems, since looking at the history of the PDF.js project I don't believe that we've (thus far) ever needed a Node.js dependency at an earlier point.
This new pattern for accessing Node.js packages/polyfills will also require some care during development *and* importantly reviewing, to ensure that no new top level await is added in the main code-base.
2024-05-06 23:20:03 +02:00
Jonas Jenwald
b6765403a1
Merge pull request #18026 from Snuffleupagus/validate-more-getArray
Validate even more dictionary properties
2024-05-06 22:09:42 +02:00
Tim van der Meij
14e87469db
Merge pull request #18041 from timvandermeij/integration-tests-timeout-freetext
Remove most `waitForTimeout` usage from the freetext editor integration tests
2024-05-06 20:00:03 +02:00
calixteman
30d0e3a0ba
Merge pull request #18044 from calixteman/bug1894849
Avoid to aria-hide the structure tree (bug 1894849)
2024-05-06 19:56:59 +02:00
Tim van der Meij
bb743389aa
Use waitForSelector instead of waitForFunction for focus checks
This commit replaces `waitForFunction` calls that use
`document.activeElement` to wait for an element to get focus by simpler
`waitForSelector` expressions that use the `:focus` selector. Note that
we already use this in other tests, so this improves consistency too.
2024-05-06 19:35:37 +02:00
Tim van der Meij
5c5c107ec5
Remove most waitForTimeout usage from the freetext editor integration tests
This commit replaces a `waitForTimeout` occurrence with an equivalent
`waitForSelector` expression, and removes two other `waitForTimeout`
occurrences that are obsolete because we already wait for an observable
event to trigger or class change to happen.

Note that the other `waitForTimeout` occurrences in this file are either
part of #17931 or remain until we find a good way to ensure that nothing
happened (because currently there is nothing we can await there).
2024-05-06 19:35:37 +02:00
Tim van der Meij
d79aaee62a
Merge pull request #18009 from nicolo-ribaudo/pin-node-21
Pin GitHub actions to Node.js 21
2024-05-06 14:47:56 +02:00
Jonas Jenwald
9b41bfc374 Introduce helper functions for parsing /Matrix and /BBox arrays 2024-05-03 22:37:50 +02:00
Jonas Jenwald
52f7ff155d Validate even more dictionary properties
This checks primarily Arrays, but also some other properties, that we'll end up sending (sometimes indirectly) to the main-thread.
2024-05-03 22:37:14 +02:00
Calixte Denizet
7742c3eb63 Avoid to aria-hide the structure tree (bug 1894849)
If one ancestor of the structure tree has the attribute aria-hidden
then it's invisible for screen readers.
2024-05-03 14:39:43 +02:00
Jonas Jenwald
1b811ac113
Merge pull request #18034 from Snuffleupagus/FileSpec-filename-stripPath
[api-minor] Improve the `FileSpec` implementation
2024-05-03 09:03:17 +02:00
Jonas Jenwald
a790f2df5d [api-minor] Remove the unused onlyStripPath option from the getFilenameFromUrl helper function 2024-05-03 08:29:41 +02:00
Jonas Jenwald
c419c8333b
Merge pull request #18037 from Snuffleupagus/validate-more-widths
Add even more validation of width-data (PR 18017 follow-up)
2024-05-02 14:41:02 +02:00