Commit Graph

11534 Commits

Author SHA1 Message Date
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
Tim van der Meij
291e62b41e
Merge pull request #10508 from Snuffleupagus/issue-8276
Do the final text scaling correctly in `flushTextContentItem` (issue 8276)
2019-01-29 22:46:36 +01:00
Jonas Jenwald
2b0b6178f7 Clean-up after the gets operatorList with JPEG image (issue 4888) unit-test
This unit-test wasn't destroying the `loadingTask` when complete, as it should have done.
2019-01-29 15:24:08 +01:00
Jonas Jenwald
6f94a05a29 Do the final text scaling correctly in flushTextContentItem (issue 8276)
It's necessary to take into account whether or not the text is vertical, to avoid either the textContent `width` or `height` becoming incorrect.
2019-01-29 15:24:04 +01:00
Tim van der Meij
55b12f5fd9
Merge pull request #10504 from Snuffleupagus/eslint-no-useless-catch
Enable the `no-useless-catch` ESLint rule
2019-01-28 22:37:14 +01:00
Jonas Jenwald
86472e9981 Enable the no-useless-catch ESLint rule
See https://eslint.org/docs/rules/no-useless-catch
2019-01-28 11:00:09 +01:00
Tim van der Meij
1f3e7700d2
Merge pull request #10499 from Snuffleupagus/renderTask-error-cleanup
Attempt to clean-up/restore pending rendering operations when errors occurs while a `RenderTask` runs (PR 10202 follow-up)
2019-01-27 15:12:59 +01:00
Tim van der Meij
d03d990e2e
Merge pull request #10501 from Snuffleupagus/getVisibleElements-avoid-unnecessary-backtrack
In `getVisibleElements`, check `firstVisibleElementInd` rather than `numViews` before backtracking (PR 10443 follow-up)
2019-01-27 15:06:13 +01:00
Jonas Jenwald
b50a512660 In getVisibleElements, check firstVisibleElementInd rather than numViews before backtracking (PR 10443 follow-up)
When `firstVisibleElementInd === 0`, regardless of the number of views, there's no reason to attempt to backtrack at all since it's never possible to find an element before the *first* one anyway.
2019-01-27 14:57:11 +01:00
Jonas Jenwald
5081063b9e Attempt to clean-up/restore pending rendering operations when errors occurs while a RenderTask runs (PR 10202 follow-up)
This piggybacks of the existing `cancel` functionality, to ensure that any pending operations are closed *and* that any temporary canvases are actually being removed.

Also simplifies `finishPaintTask` in `PDFPageView.draw` slightly, by converting it to an async function.
2019-01-26 16:02:51 +01:00
Tim van der Meij
40863eb275
Merge pull request #10489 from Snuffleupagus/single-page-scrollIntoView
Move more code/methods into `BaseViewer`, and simplify the `PDFSinglePageViewer._scrollIntoView` method slightly
2019-01-25 23:09:09 +01:00
Tim van der Meij
1eee1c5d2e
Merge pull request #10494 from Snuffleupagus/ColorSpace-isDefaultDecode
Reduce unnecessary duplication of the `isDefaultDecode` methods on `ColorSpace` instances
2019-01-25 22:43:28 +01:00
Jonas Jenwald
29f36d7a1b Reduce unnecessary duplication of the isDefaultDecode methods on ColorSpace instances
The recent PR 10482 made me realize that I missed an opportunity for simplification when doing the class conversion of this code in PR 10007.
2019-01-25 08:53:08 +01:00
Tim van der Meij
e2701d5422
Merge pull request #10482 from janpe2/indexed-decode
Implement Decode entry in Indexed images
2019-01-24 23:46:55 +01:00
Tim van der Meij
0d3c8d86a2
Merge pull request #10492 from Snuffleupagus/issue-10491
Ensure that `XRef.indexObjects` can handle object numbers with zero-padding (issue 10491)
2019-01-24 23:46:26 +01:00
Jonas Jenwald
41fbc71ef9 Ensure that XRef.indexObjects can handle object numbers with zero-padding (issue 10491)
All objects in the PDF document follow this pattern:
```
0000000001 0 obj
<<
% Some content here...
>>
endobj
0000000002 0 obj
<<
% More content here...
endobj

```
2019-01-24 22:37:18 +01:00
Jonas Jenwald
48e4adf770 Try to simplify the PDFSinglePageViewer._scrollIntoView method slightly, by unconditionally ensuring that rendering always occurs 2019-01-24 12:01:07 +01:00