Commit Graph

11500 Commits

Author SHA1 Message Date
Jonas Jenwald
a1f7517996 Rename the src/display/dom_utils.js file to src/display/display_utils.js
This file (currently) contains not only DOM-specific helper functions/classes, but is used generally for various helper code relevant for main-thread functionality.
2019-02-23 16:30:16 +01:00
Jonas Jenwald
fb774a65b0 Avoid truncating/breaking some Type3 glyphs in compileType3Glyph (bug 1245391, issue 10568)
*Hopefully this patch makes sense, since I cannot claim to fully understand this function.*

With the changes made in PR 3354 *some* Type3 glyph outlines are no longer rendering correctly, since the final paths were being accidentally ignored.
The fact that Type3 fonts are not very common in PDF documents, and that most Type3 glyphs are unaffected by this regression, probably explains why this has gone unnoticed since 2013.
2019-02-21 23:29:43 +01:00
Tim van der Meij
ece6a31a44
Merge pull request #10560 from timvandermeij/updates
Update translations and packages
2019-02-17 17:38:49 +01:00
Tim van der Meij
a4fd6aa947
Update packages 2019-02-17 17:26:35 +01:00
Tim van der Meij
01ac6cd8c6
Update translations 2019-02-17 16:40:22 +01:00
Tim van der Meij
ff74a66672
Merge pull request #10558 from Snuffleupagus/PDFDataRangeTransport-tests
Re-factor the `PDFDataRangeTransport` unit-tests and enable them in Node.js/Travis
2019-02-17 16:06:55 +01:00
Jonas Jenwald
a0354494bd Re-factor the PDFDataRangeTransport unit-tests and enable them in Node.js/Travis
There doesn't appear to be any particular reason for only running these unit-tests in browsers, since the `PDFDataRangeTransport` functionality itself should be back-end agnostic.
2019-02-17 14:45:17 +01:00
Jonas Jenwald
507e0a4907 Add a new DOMFileReaderFactory helper to the unit-tests, and re-factor NodeFileReaderFactory to be asynchronous
This allows simplification of the 'creates pdf doc from URL and aborts loading after worker initialized' API unit-test.

Note that the `DOMFileReaderFactory` uses the Fetch API, for simplicity, since it should be available in all browsers where we're running tests.
2019-02-17 14:41:14 +01:00
Tim van der Meij
43491c19ee
Merge pull request #10548 from Snuffleupagus/generate-default_preferences
Generate the `default_preferences.json` file from `AppOptions`
2019-02-16 20:02:59 +01:00
Tim van der Meij
b6f58191ca
Merge pull request #10554 from Snuffleupagus/rendering-cancelled
Simplify the `updatetextlayermatches` event handling in `TextLayerBuilder`
2019-02-16 19:41:59 +01:00
Tim van der Meij
50afff9918
Merge pull request #10556 from Snuffleupagus/documentInfo-collection
[api-minor] Expose the existence of a `Collection` dictionary via the  `getMetadata` API method (issue 10555)
2019-02-16 19:26:44 +01:00
Tim van der Meij
ac7522d34b
Merge pull request #10557 from timvandermeij/config
Bump versions in `pdfjs.config`
2019-02-16 19:09:42 +01:00
Tim van der Meij
77de6ee1f6
Bump versions in pdfjs.config 2019-02-16 19:07:23 +01:00
Jonas Jenwald
599dcf5a44 Fix {PDFPageView, PDFThumbnailView}.cancelRendering to avoid visual artifacts when called directly
Currently these methods are only used from the respective `reset` methods, and from `{BaseViewer, PDFThumbnailViewer}._cancelRendering` which only runs when the active document is closed.

This patch changes `{PDFPageView, PDFThumbnailView}.cancelRendering` to *only* cancel any pending rendering operations, and doesn't attempt to reset e.g. the `renderingState`, since that causes visual glitches (duplicated canvases in the viewer) when called directly.
Furthermore, unless you "know" what you're doing, the `{PDFPageView, PDFThumbnailView}.reset` methods are what *should* normally be used instead.
2019-02-16 11:11:07 +01:00
Jonas Jenwald
1ded729130 Simplify the updatetextlayermatches event handling in TextLayerBuilder
This implements the nice suggestion from https://github.com/mozilla/pdf.js/pull/10099#discussion_r219698000, which I at the time didn't think would work.
I'll probably have to plead temporary insanity here, since it *should* have been totally obvious to me how this could be implemented. By simply not registering the event until the `textLayer` is actually rendered, removing the event on `cancel` works just fine.

This patch also removes the `pagecancelled` event, given that it's no longer used anywhere in the code-base and that its implemention was flawed since it wasn't guaranteed to be called in *every* situation where rendering was actually cancelled.
2019-02-16 11:11:04 +01:00
Jonas Jenwald
60f6d49ff7 [api-minor] Expose the existence of a Collection dictionary via the getMetadata API method (issue 10555)
Given the complexity of this functionality, and the fact that it doesn't seem widely used, I highly doubt that it'd ever make sense to support Collections; see also https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#M11.9.39646.2Heading.824.Collections
2019-02-15 15:40:31 +01:00
Jonas Jenwald
0f0650f426 Generate the default_preferences.json file from AppOptions
Currently any editing of the preferences require updates in *three* separate files, which isn't a great developer experience to say the least.

This has annoyed me sufficiently to write this patch, which moves the definition of all preferences into `AppOptions` and adds a new `gulp` task to generate the `default_preferences.json` file for the builds where it's needed.
2019-02-14 20:40:34 +01:00
Brendan Dahl
81f5835cd7
Merge pull request #10539 from Snuffleupagus/fallback-disableFontFace-v2
[api-minor] Fallback to the built-in font renderer when font loading fails
2019-02-12 12:08:01 -08:00
Tim van der Meij
a045a00af3
Merge pull request #10540 from Snuffleupagus/viewOnLoad-pref-schema-type
[Chrome extension] Add missing "type" entry for the `viewOnLoad` preference in the `preferences_schema.json` file (PR 10502 follow-up)
2019-02-12 00:14:01 +01:00
Tim van der Meij
1d90c76097
Merge pull request #10537 from timvandermeij/unittest
Improve unit test coverage
2019-02-12 00:12:29 +01:00
Tim van der Meij
9fa7ae1397
Merge pull request #10545 from timvandermeij/undo-bump
Undo the `pdfjs.config` version bumps
2019-02-12 00:07:38 +01:00
Tim van der Meij
67f3e48832
Undo the pdfjs.config version bumps
The release needs to be made again for the version number to be correct.
2019-02-12 00:05:51 +01:00
Jonas Jenwald
2b4709d1a8 [Chrome extension] Add missing "type" entry for the viewOnLoad preference in the preferences_schema.json file (PR 10502 follow-up)
Fixes 10538
2019-02-11 10:56:43 +01:00
Jonas Jenwald
b6d090cc14 Fallback to the built-in font renderer when font loading fails
After PR 9340 all glyphs are now re-mapped to a Private Use Area (PUA) which means that if a font fails to load, for whatever reason[1], all glyphs in the font will now render as Unicode glyph outlines.
This obviously doesn't look good, to say the least, and might be seen as a "regression" since previously many glyphs were left in their original positions which provided a slightly better fallback[2].

Hence this patch, which implements a *general* fallback to the PDF.js built-in font renderer for fonts that fail to load (i.e. are rejected by the sanitizer). One caveat here is that this only works for the Font Loading API, since it's easy to handle errors in that case[3].

The solution implemented in this patch does *not* in any way delay the loading of valid fonts, which was the problem with my previous attempt at a solution, and will only require a bit of extra work/waiting for those fonts that actually fail to load.

*Please note:* This patch doesn't fix any of the underlying PDF.js font conversion bugs that's responsible for creating corrupt font files, however it does *improve* rendering in a number of cases; refer to this possibly incomplete list:

[Bug 1524888](https://bugzilla.mozilla.org/show_bug.cgi?id=1524888)
Issue 10175
Issue 10232

---
[1] Usually because the PDF.js font conversion code wasn't able to parse the font file correctly.

[2] Glyphs fell back to some default font, which while not accurate was more useful than the current state.

[3] Furthermore I'm not sure how to implement this generally, assuming that's even possible, and don't really have time/interest to look into it either.
2019-02-11 10:27:08 +01:00
Jonas Jenwald
13230a1123 Remove the ability to pass in more than one font to BaseFontLoader.bind
- The only existing call-site, of this method, is never passing more than *one* font at a time anyway.
 - As far as I can remember, this functionality has never actually been used (caveat: I didn't check the git history).
 - This allows simplification of the method, especially by making use of the fact that it's now asynchronous.
 - It should be just as easy to call `BaseFontLoader.bind` from within a loop, rather than having the loop in the method itself.
2019-02-10 21:09:57 +01:00
Jonas Jenwald
af3fcca88d Convert BaseFontLoader.bind to be async, and only utilize BaseFontLoader._queueLoadingCallback when actually necessary
Currently all fonts are using the `_queueLoadingCallback` method to determine when they have been loaded[1]. However in most cases this is just adding unnecessary overhead, especially with `BaseFontLoader.bind` now being asynchronous, given how fonts are loaded:
 - For fonts loaded using the Font Loading API, it's already possible to easily tell when a font has been loaded simply by checking the `loaded` promise on the FontFace object itself.
 - For browsers, e.g. Firefox, which support synchronous font loading it's already assumed that fonts are immediately available.

Hence the `_queueLoadingCallback` method is moved into the `GenericFontLoader`, such that it's only utilized for fonts which are loaded using CSS.

---
[1] In the "fonts loaded using CSS" case, this is already a hack anyway as outlined in the comments.
2019-02-10 21:09:57 +01:00
Tim van der Meij
7c91e94b19
Implement the NodeCanvasFactory class to execute more unit tests in Node.js 2019-02-10 19:37:34 +01:00
Tim van der Meij
b6eddc40b5
Write unit tests for the string32 and toRomanNumerals utility functions 2019-02-10 18:58:52 +01:00
Tim van der Meij
dfe7d9bc26
Merge pull request #10530 from a4lg/fix-copytext-outofucs2
Fix copying on supplementary plane characters
2019-02-10 16:22:45 +01:00
Tim van der Meij
6757b6e2d0
Merge pull request #10534 from Snuffleupagus/dist-link
Try to hack-around the broken `pdfjs-dist` links, such that they will point to the main library releases (issue 10391)
2019-02-10 15:14:59 +01:00
Tsukasa OI
96ba6afd47 Fix copying on supplementary plane characters
pdf.js had a problem when copying characters on supplementary planes
(0xPPXXXX where PP is nonzero).  This is because certain methods of
PartialEvaluator use classic String.fromCharCode instead of ES6's
String.fromCodePoint.

Despite the fact that readToUnicode method *tried* to parse out-of-UCS2
code points by parsing UTF-16BE, it was inadequate because
String.fromCharCode only supports UCS-2 range of Unicode.
2019-02-10 18:14:53 +09:00
Jonas Jenwald
62d7332d49 Try to hack-around the broken pdfjs-dist links, such that they will point to the main library releases (issue 10391) 2019-02-09 17:25:20 +01:00
Tim van der Meij
eb7fc2625f
Merge pull request #10533 from timvandermeij/bump
Bump the version number in `pdfjs.config`
2019-02-09 15:26:10 +01:00
Tim van der Meij
554d50563f
Bump the version number in pdfjs.config 2019-02-09 15:23:51 +01:00
Tim van der Meij
14c012b650
Merge pull request #10532 from timvandermeij/bump
Bump base version and version prefix in `pdfjs.config`
2019-02-09 15:06:47 +01:00
Tim van der Meij
6a40f2fc62
Bump base version and version prefix in pdfjs.config 2019-02-09 14:59:48 +01:00
Tim van der Meij
2b6e6364ef
Merge pull request #10527 from Snuffleupagus/classList-add-remove
Add a polyfill for `classList.{add, remove}` with more than one parameter
2019-02-08 22:40:16 +01:00
Jonas Jenwald
3bcf9187ec Add a polyfill for classList.{add, remove} with more than one parameter
Unsurprisingly IE11 doesn't support this, so a polyfill is needed since otherwise the sidebar can no longer be opened.

Also, simplifies the existing `classList.toggle` polyfill.
2019-02-08 13:35:01 +01:00
Tim van der Meij
7d24fc34f9
Merge pull request #10525 from Snuffleupagus/more-classList-toggle
Convert more code to use `classList.toggle` with the `force` parameter
2019-02-06 23:53:43 +01:00
Jonas Jenwald
19795597a2 Convert more code to use classList.toggle with the force parameter
There's a bunch of code, in the viewer, which for historical reasons use `switch` statements to add and remove CSS classes.
This code can be simplified, and unnecessary duplication avoided, by using `classList.toggle` instead.
2019-02-06 17:18:45 +01:00
Tim van der Meij
c0d6e46e39
Merge pull request #10502 from Snuffleupagus/adjust-onLoad-prefs
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
2019-02-04 23:54:14 +01:00
Tim van der Meij
9f9d87c3ce
Merge pull request #10517 from Snuffleupagus/rm-currentScript-polyfill
[api-minor] Remove the `document.currentScript` polyfill
2019-02-03 15:42:30 +01:00
Jonas Jenwald
614e502227 [api-minor] Remove the document.currentScript polyfill
This polyfill is currently used in only *one* file, i.e. `src/display/api.js`, and only when trying to build a *fallback* `workerSrc` path.

Given that the global `workerSrc` should *always* be set[1] when using the PDF.js library[2], and that the fallback `workerSrc` should only be regarded as a best-effort solution anyway, there isn't a particularily strong reason to keep the compatibility code in my opinion.

---
[1] Other supported options include setting the global `workerPort`, or passing in a `PDFWorker` instance as part of the `getDocument` call.

[2] Which is clearly mentioned in the JSDocs in `src/display/worker_options.js`.
2019-02-03 14:09:24 +01:00
Tim van der Meij
80495e61b7
Merge pull request #10515 from Snuffleupagus/createPromiseCapability-settled
Add a `settled` property, tracking the fulfilled/rejected stated of the Promise, to `createPromiseCapability`
2019-02-02 15:41:25 +01:00
Jonas Jenwald
22468817e1 Add a settled property, tracking the fulfilled/rejected stated of the Promise, to createPromiseCapability
This allows cleaning-up code which is currently manually tracking the state of the Promise of a `createPromiseCapability` instance.
2019-02-02 15:18:56 +01:00
Jonas Jenwald
ef634b51e1 Re-factor how the "compatibility" values are specified in AppOptions
The intention with this change is to, more clearly, highlight when the default values may possibly be overridden by "compatibility" values.
2019-02-02 10:21:18 +01:00
Jonas Jenwald
9d8342002c Move the PDFHistory initialization into a helper method in PDFViewerApplication
This avoids having the initialization code "spread out", and will become even simpler once the `TODO` is addressed (which I'm planning on fixing as soon as possible).
2019-02-02 10:21:18 +01:00
Jonas Jenwald
4d4c98d1eb Attempt to migrate the old showPreviousViewOnLoad/disablePageMode preferences to the new viewOnLoad preference
This patch ignores the recently added `disableOpenActionDestination` preference, since the latest PDF.js version found on the "Chrome Web Store" doesn't include it.
2019-02-02 10:21:18 +01:00
Jonas Jenwald
6806248030 Modify a number of the viewer preferences, whose current default value is 0, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.

As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.

Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-02-02 10:21:18 +01:00
Jonas Jenwald
dd4620530d Change PDFSidebar.switchView to act as a wrapper for a "private" PDFSidebar._switchView method
The new "private" method will return a boolean, indicating if the `sidebarviewchanged` event was dispatched, thus allowing some simplification of the `PDFSidebar.setInitialView` method.
2019-02-02 10:21:16 +01:00