Commit Graph

16746 Commits

Author SHA1 Message Date
Jonas Jenwald
9d5085347a Move ProgressBar-related CSS variables into the loadingBar DOM-element (issue 15958)
This way we avoid reflowing the entire viewer when e.g. updating the loading progress.
2023-01-25 11:09:28 +01:00
calixteman
0b9d32bdad
Merge pull request #15957 from calixteman/1810800
Try to avoid to interpret wheel events as pinch-to-zoom ones (bug 1810800)
2023-01-24 21:35:12 +01:00
Calixte Denizet
1cb482be6a Try to avoid to interpret wheel events as pinch-to-zoom ones (bug 1810800) 2023-01-24 20:12:12 +01:00
calixteman
673f6820d1
Merge pull request #15952 from calixteman/l10n
Set up automated l10n review for new English strings
2023-01-22 20:44:37 +01:00
Calixte Denizet
be93a2a7d4 Set up automated l10n review for new English strings 2023-01-22 19:39:31 +01:00
Tim van der Meij
edfdb693e5
Merge pull request #15948 from Snuffleupagus/bug-1811668
Tweak `adjustType1ToUnicode` for fonts with a predefined *named* encoding (bug 1811668, PR 14050 follow-up)
2023-01-21 14:02:40 +01:00
Tim van der Meij
8278abb3f3
Merge pull request #15949 from Snuffleupagus/ProgressBar-setDisableAutoFetch
Move the `disableAutoFetch` functionality into the `ProgressBar`-class
2023-01-21 13:54:18 +01:00
Tim van der Meij
a27d7ba524
Merge pull request #15943 from Snuffleupagus/deprecate-direct-PDFDataRangeTransport
[api-minor] Deprecate calling `getDocument` directly with a `PDFDataRangeTransport`-instance
2023-01-21 13:50:20 +01:00
Jonas Jenwald
d7013bee54 Move the disableAutoFetch functionality into the ProgressBar-class
It seems nicer overall, since we're exporting the `ProgressBar` in the viewer-components, to move this functionality into the `ProgressBar`-class itself rather than handling it "manually" in the default-viewer.
2023-01-21 12:32:34 +01:00
Jonas Jenwald
40a46e4397 Tweak adjustType1ToUnicode for fonts with a predefined *named* encoding (bug 1811668, PR 14050 follow-up)
*Please note:* I cannot reproduce the problem reported in bug 1811668, regarding the context menu, and in any case it's not clear that that part is even a PDF Viewer bug.

Looking at bug 1811668 I couldn't help but noticing that the textLayer isn't correct, and it's unfortunately once again a problem with the `adjustType1ToUnicode` function. That's intended to help improve text-selection for fonts without a /ToUnicode-entry, and in many cases it does help (the original PR fixed lots of issues) however it's also caused some problems.

In order to improve text-selection in bug 1811668, we'll now properly ignore fonts that have a predefined *named* encoding specified since that's really the intention with PR 14050.
2023-01-21 12:21:21 +01:00
calixteman
7b95788248
Merge pull request #15947 from calixteman/gv_dont_update_find
[GV] Avoid to update the finder when the results aren't complete
2023-01-20 18:48:39 +01:00
Calixte Denizet
dc94b750de [GV] Avoid to update the finder when the results aren't complete
At the beginning of a search we can an update can be triggered with 0 over 0
found matches.
In the GeckoView context, we can't update the finder whenever we want but only
when it has been required.
2023-01-20 18:13:16 +01:00
calixteman
deb07aee06
Merge pull request #15941 from calixteman/change_current_view
Change 'Current View' to 'Current Page' in the secondary toolbar
2023-01-20 10:59:18 +01:00
Jonas Jenwald
29cd5ab24e
Merge pull request #15945 from Snuffleupagus/issue-15942
[JBIG2] Ensure that the `decodeInteger` function returns valid integers (issue 15942)
2023-01-19 21:14:47 +01:00
Jonas Jenwald
f2fce93826 [JBIG2] Ensure that the decodeInteger function returns valid integers (issue 15942)
The JBIG2 images in this PDF document are corrupt enough that even Adobe Reader warns about it when opening the file.
*Please note:* I don't really know the JBIG2 image format at all, however from a very brief look at the specification it seems that integers should be 32-bit.
2023-01-19 17:14:17 +01:00
Jonas Jenwald
7976fc7851 [api-minor] Deprecate calling getDocument directly with a PDFDataRangeTransport-instance
In general it's recommended to pass a *parameter object* when calling the `getDocument`-function in the API, since that's the only way to provide additional options, and the fact that it also accepts a URL or TypedArray directly is now mostly for backwards compatibility reasons.
However, the `getDocument`-function also accepts a direct `PDFDataRangeTransport`-instance which just seems unnecessary.

*Please note:* The `PDFDataRangeTransport`-implementation was added specifically for the *built-in* Firefox PDF Viewer, however it's most likely not commonly used by any third-party (given that it requires manual PDF-data loading).
Furthermore, the default-viewer always provides a *parameter object* when calling the `getDocument`-function and it's thus completely unaffected by these changes.
2023-01-19 14:25:55 +01:00
Jonas Jenwald
c629a85a5c
Merge pull request #15935 from Snuffleupagus/_centerAtPos
Add a `PDFViewerApplication` helper method to center the position after wheel/pinch-zooming
2023-01-19 14:25:10 +01:00
Jonas Jenwald
1a95890728
Merge pull request #15937 from Snuffleupagus/textLayer-highlight-color-vars
Use CSS variables for the textLayer `highlight` colors (PR 15921 follow-up)
2023-01-19 13:38:58 +01:00
Jonas Jenwald
eee65e4b6e Add a PDFViewerApplication helper method to center the position after wheel/pinch-zooming
This avoids having to repeat the same code twice, now that we support both wheel- and pinch-zooming.
2023-01-19 13:35:35 +01:00
Calixte Denizet
31ae3a4ba0 Change 'Current View' to 'Current Page' in the secondary toolbar
Content Design team (UX) proposed this change.
2023-01-19 09:54:25 +01:00
Jonas Jenwald
f25e33ee7f
Merge pull request #15940 from Snuffleupagus/license_header_2023
Update the year in the `license_header` files
2023-01-18 22:36:21 +01:00
Jonas Jenwald
7b36686fca Update the year in the license_header files 2023-01-18 22:28:18 +01:00
Jonas Jenwald
4b5817f8ff Use consistent forced-colors media-queries throughout the CSS files
Note how e.g. the `viewer.css` and `pdf_viewer.css` files already used this format.
2023-01-18 10:49:52 +01:00
Jonas Jenwald
67b1d15384 Use CSS variables for the textLayer highlight colors (PR 15921 follow-up)
Rather than adding `@media (forced-colors: active) { ... }`-blocks throughout the CSS code, we should utilize CSS variables instead as in our other CSS files.
2023-01-18 10:42:22 +01:00
Jonas Jenwald
42b1cff7b0
Merge pull request #15934 from Snuffleupagus/issue-15910-2
Fallback to using the `name` table to infer the encoding for TrueType fonts missing such data (issue 15910)
2023-01-17 23:01:23 +01:00
calixteman
e65f1767ab
Merge pull request #15930 from calixteman/15929
Move --scale-factor variable in the viewer container (fix #15929)
2023-01-17 16:37:49 +01:00
Jonas Jenwald
d6be5141e9 Fallback to using the name table to infer the encoding for TrueType fonts missing such data (issue 15910)
The relevant TrueType font is missing both /ToUnicode *and* /Encoding entires, either of which would have prevented the (current) broken textLayer rendering.
My first idea was that we could use the `post` table in the TrueType font, see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6post.html, to get the actual glyphNames and amend the fallback ToUnicode-map that way. Unfortunately that didn't work, since the `post` table only contained ".notdef" and "" (i.e. empty string) entries.

Instead we try to use the `name` table in the TrueType font, see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html, to determine if the platform is Windows and thus fallback to generate a ToUnicode-map from the `WinAnsiEncoding`.
2023-01-17 16:04:51 +01:00
Calixte Denizet
089ed6fb65 Move --scale-factor variable in the viewer container (fix #15929)
When a css variable is update in a node then all the children under this
node are updated.
In order to avoid to update all the UI when a page is rescaling, this
patch moves the --scale-factor from the :root to the viewer container.
2023-01-17 10:50:53 +01:00
Jonas Jenwald
d8d5545e03
Merge pull request #15926 from Snuffleupagus/annotation-appearance-stream
Ensure that Annotation `appearance`-entries are actually Streams
2023-01-16 15:00:12 +01:00
Jonas Jenwald
8f3fa18c93
Merge pull request #15920 from Snuffleupagus/transfer-pdf-data
[api-minor] Enable transferring of TypedArray PDF data by default (PR 15908 follow-up)
2023-01-16 13:20:57 +01:00
Jonas Jenwald
cefaecc2e8 Ensure that Annotation appearance-entries are actually Streams
Note how all over the `src/core/annotation.js`-code we're assuming that if an `appearance`-entry exists it's also a Stream. However, we're not actually checking that thoroughly enough which causes issues in some badly generated PDF documents.
2023-01-16 13:02:53 +01:00
calixteman
e9c8aa63e3
Merge pull request #15921 from fchasen/forced-colors-highlights
Update highlight background when forced colors are active (bug 1759886)
2023-01-16 11:16:22 +01:00
Tim van der Meij
0e563ee6da
Merge pull request #15925 from Snuffleupagus/update-rimraf
Update `rimraf` to version 4
2023-01-15 18:15:59 +01:00
Jonas Jenwald
32357e3d17 Update rimraf to version 4
The primary change is that the `rimraf` function now returns a Promise instead of taking a callback; please see https://github.com/isaacs/rimraf#major-changes-from-v3-to-v4
2023-01-15 15:38:30 +01:00
Jonas Jenwald
1ca0a7a26c
Merge pull request #15923 from Snuffleupagus/zoom-black-canvas
[Regression] Avoid showing a black canvas during zooming with a `drawingDelay` set (PR 15812 follow-up)
2023-01-15 12:29:06 +01:00
Tim van der Meij
bc3b59fa5e
Merge pull request #15924 from Snuffleupagus/update-packages
Update packages and translations
2023-01-15 11:35:16 +01:00
Jonas Jenwald
cbf9843a79 Update l10n files 2023-01-15 10:43:46 +01:00
Jonas Jenwald
d527bd0d92 Update npm packages 2023-01-15 10:34:56 +01:00
Jonas Jenwald
906745de38 [Regression] Avoid showing a black canvas during zooming with a drawingDelay set (PR 15812 follow-up)
After the changes in PR 15812 we'll now *intermittently* display completely black canvases during zooming. To reproduce this, try switching to wrapped-scrolling and zoom in/out very quickly using either the mouse-wheel or pinching.
2023-01-14 23:25:04 +01:00
Tim van der Meij
517d7a6dc3
Merge pull request #15905 from timvandermeij/core-utils-unit-tests
Improve unit test coverage of `src/core/core_utils.js`
2023-01-14 15:24:53 +01:00
Tim van der Meij
9e3adb5ec7
Implement unit tests for the numberToString utility function 2023-01-14 15:09:58 +01:00
Tim van der Meij
a6dfcc89fa
Implement unit tests for the recoverJsURL utility function 2023-01-14 15:09:58 +01:00
Jonas Jenwald
397f943ca3 [api-minor] Enable transferring of TypedArray PDF data by default (PR 15908 follow-up)
This patch removes the recently introduced `transferPdfData` API-option, and simply enables transferring of TypedArray data *by default* instead of copying it. This will help reduce main-thread memory usage, however it will take ownership of the TypedArrays. Currently this only applies to the following cases:
 - TypedArrays passed to the `getDocument`-function in the API, in order to open PDF documents from binary data.
 - TypedArrays passed to a `PDFDataRangeTransport`-instance, used to support custom PDF document fetching/loading (see e.g. the Firefox PDF Viewer).

*PLEASE NOTE:* To avoid being affected by this, please simply *copy* any TypedArray data before passing it to either of the functions/methods mentioned above.

Now that we transfer TypedArray data that we previously only copied, we need to be more careful with input validation. Given how the `{IPDFStreamReader, IPDFStreamRangeReader}.read` methods will always return ArrayBuffer data, which is then transferred to the worker-thread[1], the actual TypedArray data passed to the API thus need to have the same exact size as its underlying ArrayBuffer to prevent issues.
Hence we'll check for this and only allow transferring of *safe* TypedArray data, and fallback to simply copying the data just as before. This obviously shouldn't be an issue in the Firefox PDF Viewer, but for the general PDF.js library we need to be more careful here.

---
[1] See e09ad99973/src/display/api.js (L2492-L2506) respectively e09ad99973/src/display/api.js (L2578-L2590)
2023-01-14 10:39:36 +01:00
Fred Chasen
0a6b1cd2e9 Update highlight background color for forced colors 2023-01-13 14:35:12 -08:00
Jonas Jenwald
99cfab18c1 Combine the array-like and ArrayBuffer branches, when handling binary data, in getDocument 2023-01-13 13:28:44 +01:00
Jonas Jenwald
e09ad99973
Merge pull request #15916 from Snuffleupagus/fetch-transfer
[api-minor] Enabling transferring of data fetched with the `PDFFetchStream` implementation
2023-01-13 13:28:12 +01:00
Jonas Jenwald
1d683708e8
Merge pull request #15917 from Snuffleupagus/pr-15908-followup
Improve input validation in `PDFDataTransportStream._onReceiveData` (PR 15908 follow-up)
2023-01-12 15:32:59 +01:00
Jonas Jenwald
1362cd91d0 Improve input validation in PDFDataTransportStream._onReceiveData (PR 15908 follow-up)
The mozilla-central [method `PdfDataListener.readData`](https://searchfox.org/mozilla-central/rev/893a8f062ec6144c84403fbfb0a57234418b89cf/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#207-210) can return `null`, hence it seems like a very good idea to update `PDFDataTransportStream._onReceiveData` to handle that gracefully since the current code will throw in that case.

Also, improves the JSDocs for the `PDFDataRangeTransport` class in the API.
2023-01-12 15:24:59 +01:00
Jonas Jenwald
cee97fcd15 [api-minor] Enabling transferring of data fetched with the PDFFetchStream implementation
Note how in the API we're transferring the PDF data that's fetched over the network[1]:
 - f28bf23a31/src/display/api.js (L2467-L2480)
 - f28bf23a31/src/display/api.js (L2553-L2564)

To support that functionality we have the `PDFDataTransportStream`, `PDFFetchStream`, `PDFNetworkStream`, and `PDFNodeStream` implementations. Here these stream-implementations vary slightly in how they handle `ArrayBuffer`s internally, w.r.t. transferring or copying the data:
 - In `PDFDataTransportStream` we optionally, after PR 15908, allow transferring of the PDF data as provided externally (used e.g. in the Firefox PDF Viewer).
 - In `PDFFetchStream` we're currenly always copying the PDF data returned by the Fetch API, which seems unnecessary. As discussed in PR 15908, it'd seem very weird if this sort of browser API didn't allow transferring of the returned data.
 - In `PDFNetworkStream` we're already, since many years, transferring the PDF data returned by the `XMLHttpRequest` functionality. Note how the `getArrayBuffer` helper function simply returns an `ArrayBuffer` response as-is.
 - In `PDFNodeStream` we're currently copying the PDF data, however this is unfortunately necessary since Node.js returns data as a `Buffer` object[2].

Given that the `PDFNetworkStream` has been, indirectly, supporting transferring of PDF data for years it would seem really strange if this didn't also apply to the `PDFFetchStream`-implementation.
Hence this patch simply enables transferring of PDF data, when accessed using the Fetch API, unconditionally to help reduced main-thread memory usage since the `PDFFetchStream`-implementation is used *by default* in browsers (for the GENERIC build).

---
[1] As opposed to PDF data being provided as e.g. a TypedArray when calling `getDocument` in the API.

[2] This is a "special" Node.js object, see https://nodejs.org/api/buffer.html#buffer, which doesn't exist in browsers.
2023-01-12 13:59:21 +01:00
Jonas Jenwald
f28bf23a31
Merge pull request #15908 from Snuffleupagus/bug-1809164
[api-minor] Add a new `transferPdfData` option to allow transferring more data to the worker-thread (bug 1809164)
2023-01-11 17:34:51 +01:00