Commit Graph

13818 Commits

Author SHA1 Message Date
Jonas Jenwald
9360c7cbdc Avoid unnecessary parsing, in Page.GetStructTree, when no structTree is available (PR 13221 follow-up)
It's obviously (a bit) more efficient to return early in `Page.getStructTree`, rather than trying to first "parse" an *empty* structTree-root.

*Somehow I didn't think of this yesterday, but this feels like a much better solution overall; sorry about the churn here!*
2021-04-12 08:54:21 +02:00
Jonas Jenwald
0d2dd6c2fe Remove the unused "GetIsPureXfa" message handler in the worker (PR 13069 follow-up)
Looking at the API, there's no code which actually sends this message. Most likely it's a left-over from a previous version of PR 13069, since the `isPureXfa` parameter is being included in the "GetDoc" message.
2021-04-12 08:52:27 +02:00
Tim van der Meij
a3669a4f0d
Merge pull request #13217 from Snuffleupagus/generic-signature-warn
[GENERIC viewer] Display a warning message, using the `errorWrapper`, for documents with signatures (PR 13214 follow-up, issue 13215)
2021-04-11 18:41:41 +02:00
Tim van der Meij
646bb07884
Merge pull request #13221 from Snuffleupagus/structTree-fixes
[api-minor] A couple of smaller `PDFPageProxy.getStructTree` fixes (PR 13171 follow-up)
2021-04-11 18:32:50 +02:00
Tim van der Meij
daf4cd0f78
Merge pull request #13220 from Snuffleupagus/currentOutlineItemPromise-isPagesLoaded
Ensure that `currentOutlineButton` enabling/disabling won't depend on the exact timing of the "pagesloaded" event (PR 13212 follow-up)
2021-04-11 18:30:17 +02:00
Jonas Jenwald
52494be545 [GENERIC viewer] Display a warning message, using the errorWrapper, for documents with signatures (PR 13214 follow-up, issue 13215)
To simplify the overall implementation, given that it only applies to the GENERIC-viewer, this patch purposely re-uses the existing `errorWrapper`-functionality to display the message.
While that one is mostly intended for actual *errors*, by re-using it here we considerably reduce the amount of code/complexity necessary for supporting this new warning. It's obviously possible to re-factor/improve this later on, but the patch should do just fine here since it'll indeed inform users (of the GENERIC-viewer) about unverified signatures.

Finally this patch also tweaks the background-color of the `errorWrapper`, making it 20 percent lighter respectively darker (depending on the theme) to make it "stand out" a little bit *less*.[1] While it may perhaps be useful to re-style/re-factor the `errorWrapper`, this patch probably isn't the right place for doing that.

---
[1] Note how in the MOZCENTRAL-viewer, which instead uses the browser notification-bar, we're purposely using a neutral colour to not draw too much attention to the notification-bar.
2021-04-11 12:46:17 +02:00
Jonas Jenwald
5adee0cdd1 [api-minor] Let PDFPageProxy.getStructTree return null, rather than an empty structTree, for documents without any accessibility data (PR 13171 follow-up)
This is first of all consistent with existing API-methods, where we return `null` when the data in question doesn't exist. Secondly, it should also be (slightly) more efficient since there's less dummy-data that we need to transfer between threads.
Finally, this prevents us from adding an empty/unnecessary span to *every* single page even in documents without any structure tree data.
2021-04-11 12:35:33 +02:00
Jonas Jenwald
ff4dae05b0 Ensure that getStructTree won't break with disableAutoFetch = true set (PR 13171 follow-up)
Open http://localhost:8888/web/viewer.html?file=/test/pdfs/pdf.pdf#disableStream=true&disableAutoFetch=true and observe the following message in the console (repeated for each page of the document):
```
Uncaught (in promise)
Object { message: "Missing data [19787293, 19787294)", name: "UnknownErrorException", details: "MissingDataException: Missing data [19787293, 19787294)", stack: "BaseExceptionClosure@http://localhost:8888/src/shared/util.js:458:29\n@http://localhost:8888/src/shared/util.js:462:3\n" }
```
2021-04-11 12:15:33 +02:00
Jonas Jenwald
f285e41f02 Ensure that currentOutlineButton enabling/disabling won't depend on the exact timing of the "pagesloaded" event (PR 13212 follow-up)
I (unsurprisingly) managed to forget about handling the case where a "pagesloaded" event arrives *before* the outline has been parsed, in which case we'd not actually enable the `currentOutlineButton` as intended.
Also, in the "pagesloaded" event handler, we should ensure that there's actually any pages loaded since otherwise the "find current outlineItem"-feature doesn't make any sense.
2021-04-11 10:36:46 +02:00
Tim van der Meij
4ac1082838
Merge pull request #13216 from timvandermeij/unit-test-done
Remove obsolete done callbacks from the unit tests
2021-04-10 21:13:42 +02:00
Tim van der Meij
10574a0f8a
Remove obsolete done callbacks from the unit tests
The done callbacks are an outdated mechanism to signal Jasmine that a
unit test is done, mostly in cases where a unit test needed to wait for
an asynchronous operation to complete before doing its assertions.
Nowadays a much better mechanism is in place for that, namely simply
passing an asynchronous function to Jasmine, so we don't need callbacks
anymore (which require more code and may be more difficult to reason
about).

In these particular cases though the done callbacks never had any real
use since nothing asynchronous happens in these places. Synchronous
functions don't need to use done callbacks since Jasmine simply knows
it's done when the function reaches its normal end, so we can safely get
rid of these callbacks. The telltale sign is if the done callback is
used unconditionally at the end of the function.

This is all done in an effort to over time get rid of all callbacks in
the unit test code.
2021-04-10 20:29:39 +02:00
Tim van der Meij
d9d626a5e1
Merge pull request #13214 from calixteman/signatures
Display widget signature
2021-04-10 19:35:16 +02:00
Calixte Denizet
5875ebb1ca Display widget signature
- but don't validate them for now;
  - Firefox will display a bar to warn that the signature validation is not supported (see https://bugzilla.mozilla.org/show_bug.cgi?id=854315)
  - almost all (all ?) pdf readers display signatures;
  - validation is done in edge but for now it's behind a pref.
2021-04-10 19:13:28 +02:00
Tim van der Meij
86374d4f75
Merge pull request #13212 from Snuffleupagus/BaseTreeViewer-init-checks
Check that the correct `pdfDocument` is still active, before rendering the outline/attachments/layers
2021-04-10 14:32:41 +02:00
Jonas Jenwald
27062f72c2 Improve the handling of the currentOutlineButton enabling/disabling (PR 12777 follow-up)
It's obviously better and more correct to handle the "pagesloaded" case within `PDFOutlineViewer` *itself*, rather than essentially splitting the logic in two parts and forcing `PDFSidebar` to deal with what should've been handled internally in `PDFOutlineViewer`.

This is what I *should* have done in PR	12777, but for some reason didn't figure out how to implement it well enough back then; sorry about the churn here!
2021-04-10 13:12:47 +02:00
Jonas Jenwald
05b0798824 Check that the correct pdfDocument is still active, before rendering the outline/attachments/layers
*This patch fixes some technical debt in the viewer.*

Given that most API methods are (purposely) asynchronous, there's always a risk that the viewer could have been `close`d before the requested data arrives.
Lately we've started to check this case before using the data, to prevent errors and/or inconsistent state, however the outline/attachments/layers fetching and rendering is old enough that it pre-dates those checks.
2021-04-10 13:12:40 +02:00
Tim van der Meij
f5e973d555
Merge pull request #13197 from Snuffleupagus/issue-8233
Improve the image quality of thumbnails rendered by `PDFThumbnailView.draw` (issue 8233)
2021-04-09 21:51:42 +02:00
Tim van der Meij
03c8c89002
Merge pull request #13171 from brendandahl/struct-tree
[api-minor] Add support for basic structure tree for accessibility.
2021-04-09 21:32:44 +02:00
Tim van der Meij
b0473eb353
Merge pull request #13207 from Snuffleupagus/api-AnnotationStorage-params
[api-minor] Remove the manual passing of an `AnnotationStorage`-instance when calling various API-method
2021-04-09 21:09:16 +02:00
Tim van der Meij
0ae5a6ef05
Merge pull request #13209 from Snuffleupagus/rm-PDFPageView-enableScripting
Remove the `enableScripting` option from the `PDFPageView` constructor
2021-04-09 20:59:29 +02:00
Tim van der Meij
acb5c5093b
Merge pull request #13210 from brendandahl/cache-source-map
Cache babel source map.
2021-04-09 20:56:07 +02:00
Tim van der Meij
bf7ae6f82a
Merge pull request #13204 from eltociear/patch-2
Fix typo in canvas.js
2021-04-09 20:54:54 +02:00
Brendan Dahl
a31d142253 Cache babel source map.
When source is already cached and you reload,
the source map is lost which makes debugging
async functions difficult.
2021-04-09 10:34:54 -07:00
Brendan Dahl
fc9501a637 Add support for basic structure tree for accessibility.
When a PDF is "marked" we now generate a separate DOM that represents
the structure tree from the PDF.  This DOM is inserted into the <canvas>
element and allows screen readers to walk the tree and have more
information about headings, images, links, etc. To link the structure
tree DOM (which is empty) to the text layer aria-owns is used. This
required modifying the text layer creation so that marked items are
now tracked.
2021-04-09 09:56:28 -07:00
Jonas Jenwald
ec9e29807a Remove the enableScripting option from the PDFPageView constructor
Scripting, as implemented, requires access to a complete document/viewer in order to work. Hence it doesn't really make sense to keep the `enableScripting`-option on `PDFPageView`-instances.[1]

---
[1] Note that there's the `PDFSinglePageViewer`, which can be used in cases where you want access to all features/functionality of the viewer but only display *one* page at a time.
2021-04-09 14:20:47 +02:00
Jonas Jenwald
737a8e846d Add deprecated handling of the now removed AnnotationStorage API-parameters
These changes are done separately, to make it easier to remove them in the future.
2021-04-09 13:25:03 +02:00
Jonas Jenwald
72ef183085 [api-minor] Remove the manual passing of an AnnotationStorage-instance when calling various API-method
Note how we purposely don't expose the `AnnotationStorage`-class directly in the official API (see `src/pdf.js`), since trying to use *multiple* ones simultaneously doesn't really make sense (e.g. in the viewer).
Instead we lazily initialize, and cache, just *one* instance via `PDFDocumentProxy.annotationStorage` which should thus be available internally in the API itself without having to be manually passed to various methods.

To support these changes, the `AnnotationStorage`-instance initialization is moved into the `WorkerTransport`-class to allow both `PDFDocumentProxy` and `PDFPageProxy` to access it.
This patch implements the following simplifications:
 - Remove the `annotationStorage`-parameter from `PDFDocumentProxy.saveDocument`, since it's already available internally.
   Furthermore, while it's currently possible to call that method without an `AnnotationStorage`-instance, that really does *not* make any sense at all. In this case you're effectively reducing `PDFDocumentProxy.saveDocument` to a "regular" `PDFDocumentProxy.getData` call, but with *a lot* more overhead, which was obviously not the intention of the `PDFDocumentProxy.saveDocument`-method.

 - Try to discourage third-party users from calling `PDFDocumentProxy.saveDocument` unconditionally, as a replacement for `PDFDocumentProxy.getData` (note the previous point).

 - Replace the `annotationStorage`-parameter, in `PDFPageProxy.render`, with a boolean `includeAnnotationStorage`-parameter which simply indicates if the (internally available) `AnnotationStorage`-instance should be used during rendering (e.g. for printing).

 - By removing the need to *manually* provide `annotationStorage`-parameters to various API-methods, using the API should become simpler (e.g. for third-parties) since you no longer need to worry about manually fetching and passing around this data.
2021-04-09 13:24:25 +02:00
Ikko Ashimine
c4c4333d54
Fix typo in canvas.js
Reseting -> Resetting
2021-04-08 23:45:24 +09:00
Jonas Jenwald
d8e0794650 Improve the image quality of thumbnails rendered by PDFThumbnailView.draw (issue 8233)
The reason for the fairly large discrepancy, in the thumbnail quality, between the `draw`/`setImage`-methods is that in the former case we *directly* render the thumbnails at the final size that they'll appear at in the sidebar. In the latter case, we instead downsize the (generally) much larger "regular" pages.

To address this, I'm thus proposing that we let `PDFThumbnailView.draw` render thumbnails at *twice* their intended size and then downsize them to the final size.
Obviously this will increase *peak* memory usage during thumbnail rendering in `PDFThumbnailView.draw`, since doubling the width/height of a `canvas` will lead to its pixel-count increasing by a factor of `4`. Furthermore, since you need four components per pixel (given that it's RGBA-data), this will thus lead to the *temporary* thumbnail `canvas`-sizes increasing by a factor of `16` during rendering. Hence why rendering thumbnails at their "original" scale, i.e. using something like `PDFPageProxy.getViewport({ scale: 1 });`, would be an absolutely terrible idea!

To reduce the size and scope of these changes, I've tried to re-factor and re-use as much of the existing downsizing-implementation already present in `PDFThumbnailView` as possible.

While this will generally *not* make thumbnails rendered by `PDFThumbnailView.draw` look *identical* to those based on the rendered pages (via `PDFThumbnailView.setImage`), it's a considerable improvement as far as I'm concerned and enough to call the issue fixed.

*Please note:* This patch will not lead to *any* additional overhead, in either memory usage or parsing, for thumbnails which are based on the rendered pages.
2021-04-08 13:58:24 +02:00
Jonas Jenwald
32a00b9b2b Stop looping over childNodes, in PDFThumbnailView.reset, when removing the thumbnail
A loop is less efficient than just overwriting the content, which is what we've generally been using (for years) in other parts of the code-base (see e.g. `BaseViewer` and `PDFThumbnailViewer`).
2021-04-08 12:22:07 +02:00
Jonas Jenwald
8ea83f7030 Convert some properties, on PDFThumbnailView-instances, to local variables
These properties are always updated/used together, and there's no other methods which depend on just one of them, hence they're changed into local variables instead.
Looking through the history of this code, it seems they were converted *from* local variables and to properties all the way back in PR 2914; however as far as I can tell from that diff it doesn't seem to have been necessary even back then!?
2021-04-08 12:21:52 +02:00
Tim van der Meij
6429ccc002
Merge pull request #13194 from Snuffleupagus/ttcf-fuzzy-match
Fuzzy-match the fontName, for TrueType Collection fonts, where the "name"-table is wrong (issue 13193)
2021-04-07 20:50:19 +02:00
Tim van der Meij
5945f7c4a1
Merge pull request #13186 from Snuffleupagus/rm-deprecated-code
Remove some `deprecated` code
2021-04-07 20:38:59 +02:00
Tim van der Meij
336ebd6fa1
Merge pull request #13184 from timvandermeij/sets
Convert objects to sets in places where we only track keys
2021-04-07 20:34:49 +02:00
Jonas Jenwald
f986ccdf0e Fuzzy-match the fontName, for TrueType Collection fonts, where the "name"-table is wrong (issue 13193)
The fontName, as defined in the PDF document, cannot be found in *any* of the "name"-tables in the TrueType Collection font. To work-around that, this patch adds a *fallback* code-path to allow using an approximately matching fontName rather than outright failing.
2021-04-07 15:25:32 +02:00
Jonas Jenwald
4e81e0e14f Remove the deprecated AnnotationStorage.getOrCreateValue-method (PR 12759 follow-up)
While this method has only been deprecated in one releases now, the `AnnotationStorage`-functionality is new enough that third-party implementations hopefully don't rely heavily on it just yet. (And removing this quickly should help reduce the likelihood that someone starts using it.)
2021-04-06 13:22:06 +02:00
Jonas Jenwald
92ec10bfca Remove the deprecated PDFLinkService.navigateTo-method (PR 12440 follow-up)
This method has been deprecated in two releases now, hence we shouldn't need to keep this code around.
2021-04-06 13:08:50 +02:00
Jonas Jenwald
b2758c3023 Remove the deprecated properties from the "presentationmodechanged" event (PR 12788 follow-up)
These properties have been deprecated in two releases now, hence we shouldn't need to keep this code around.
2021-04-06 13:04:23 +02:00
Tim van der Meij
ff393d6e96
Convert the pendingFindMatches member, in web/pdf_find_controller.js, from an object to a set
We only want to track page numbers instead of actual data, so using a
set conveys that intention more clearly and is slightly more efficient.
2021-04-05 19:33:53 +02:00
Tim van der Meij
fc0cd4a443
Convert the startXRefParsedCache variable, in src/core/obj.js, from an object to a set
We only want to track XRef starting points instead of actual data, so
using a set conveys that intention more clearly and is slightly more
efficient.
2021-04-05 19:32:58 +02:00
Tim van der Meij
6ddc297170
Merge pull request #13183 from timvandermeij/bump
Bump versions in `pdfjs.config`
2021-04-05 16:01:29 +02:00
Tim van der Meij
37c88bfaed
Bump versions in pdfjs.config 2021-04-05 15:56:18 +02:00
Tim van der Meij
228adbf673
Merge pull request #13172 from Snuffleupagus/cleanup-keepFonts
[api-minor] Add an option, in `PDFDocumentProxy.cleanup`, to allow fonts to remain attached to the DOM
2021-04-05 14:21:34 +02:00
Tim van der Meij
11f2eab4b8
Merge pull request #13179 from Snuffleupagus/more-Set
Utilize `Set` a bit more in the code-base
2021-04-05 14:06:53 +02:00
Tim van der Meij
3698bc1287
Merge pull request #13175 from Snuffleupagus/app-close-save
[GENERIC viewer] Avoid data loss in forms, by triggering saving when the document is closed (issue 12257)
2021-04-05 14:03:18 +02:00
Tim van der Meij
3f90565272
Merge pull request #13177 from Snuffleupagus/update-packages
Update packages and translations
2021-04-05 13:31:30 +02:00
Jonas Jenwald
16fd838f52 Convert the renderTasks, used in PDFPageProxy.render/PDFPageProxy.getOperatorList, to a Set
When removing tasks we're currently forced to *indirectly* iterate through the array, which can be avoided by using a Set instead.
Furthermore, we can also (slightly) modernize the code responsible for initializing the `renderTasks`.
2021-04-05 10:51:28 +02:00
Jonas Jenwald
68d3a333ac Change the seenStyles object, in PartialEvaluator.getTextContent, to a Set
Given that what we actually want is only to keep track of the loadedFont-names, rather than storing any actual data, using an object isn't really necessary here. Furthermore, in the current code, we're also using `in` when checking if the data exists, which is generally less efficient than just checking for the value directly.
2021-04-05 10:34:02 +02:00
Jonas Jenwald
3d9f6ec0f9 Update l10n files 2021-04-04 11:04:05 +02:00
Jonas Jenwald
f4727f0fec Update npm packages 2021-04-04 10:53:29 +02:00