Commit Graph

13521 Commits

Author SHA1 Message Date
Jonas Jenwald
cacb1cc7ba Re-enable the issue6961 test-case (issue 7112) 2021-02-02 10:31:16 +01:00
Brendan Dahl
e16c99fc02
Merge pull request #12879 from calixteman/xfa_parser
XFA - Add a parser for XFA files
2021-02-01 18:34:39 -08:00
Calixte Denizet
0ff5cd7eb5 XFA - Add a parser for XFA files
- the parser is base on a class extending XMLParserBase
 - it handle xml namespaces:
   * each namespace is assocated with a builder
   * builder builds nodes belonging to the namespace
   * when a node is inserted in the parent namespace compatibility is checked (if required)
 - to avoid name collision between xml names and object properties, use Symbol.
2021-02-01 13:45:31 +01:00
Tim van der Meij
c92011e093
Merge pull request #12935 from Snuffleupagus/fullscreen-MOZCENTRAL-rm-prefixes
Remove prefixed fullscreen properties/methods from the MOZCENTRAL builds
2021-01-31 14:20:50 +01:00
Jonas Jenwald
1c802e0e6c Remove prefixed fullscreen properties/methods from the MOZCENTRAL builds
The unprefixed version of the fullscreen API has been enabled for quite some time in Firefox, see below, hence we can (slightly) clean-up the relevant code.

 - https://developer.mozilla.org/en-us/docs/Web/API/Document/fullscreenEnabled#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#browser_compatibility
2021-01-31 13:45:14 +01:00
Tim van der Meij
59f938d073
Merge pull request #12933 from Snuffleupagus/rm-CSS-variables-polyfill
Stop polyfilling CSS variables in GENERIC builds
2021-01-30 16:00:55 +01:00
Jonas Jenwald
619e1d8bcf Stop polyfilling CSS variables in GENERIC builds
At this point in time, all browsers that we support have native support for CSS variables; please see https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties#browser_compatibility and 9af8501e6c/gulpfile.js (L79-L91)

This reduces the size of the *built* `viewer.css` file, in GENERIC builds, from `93 814` to `55 285` bytes (~41 percent).
2021-01-30 15:38:07 +01:00
Tim van der Meij
9af8501e6c
Merge pull request #12932 from Snuffleupagus/rm-ms-prefix
Stop including `-ms` prefixed CSS rules in GENERIC builds
2021-01-30 14:36:35 +01:00
Jonas Jenwald
88ca213399 Stop including -ms prefixed CSS rules in GENERIC builds
Given that IE 11/Edge is now unsupported in PDF.js, and that Microsoft Edge is now a Chromium-browser, we can avoid (some) unnecessary bloat in the built CSS files.
2021-01-30 14:00:04 +01:00
Tim van der Meij
31b78921ca
Merge pull request #12931 from Snuffleupagus/errorFontLoadNative-no-fallback-bar
Stop showing the fallback bar for "errorFontLoadNative" errors (PR 10539 follow-up)
2021-01-29 22:04:28 +01:00
Jonas Jenwald
fec8c4c43f Access this._onUnsupportedFeature directly in FontFaceObject.getPathGenerator
Given that `FontFaceObject` is not exposed in the public API, but only accessed internally, there's no need to assume that a `FontFaceObject`-instance is ever initialized without `onUnsupportedFeature` being provided. This is also consistent with the `BaseFontLoader` implementation.
2021-01-29 16:48:55 +01:00
Jonas Jenwald
5a522a5c71 Stop showing the fallback bar for "errorFontLoadNative" errors (PR 10539 follow-up)
With PR 10539, we'll now always attempt to fallback to the PDF.js built-in font renderer for fonts that fail to load (i.e. are rejected by the sanitizer). Generally speaking, these errors are the result of insufficient validation in the PDF.js font code, however in almost all cases we've seen thus far our built-in font renderer manages just fine.
However, we still trigger the `onUnsupportedFeature` reporting, which in Firefox causes the fallback bar to be displayed. Given that, in a majority of cases[1], things look fine it seems unfortunate to bother the user with the fallback bar here.

Note that even though we no longer show the fallback bar in this case, we still report telemetry as before.

---
[1] The only *known* case where things aren't fine with the built-in font renderer is issue 10232, however that document is sufficiently broken that there's a couple of other things that will trigger the fallback bar.
2021-01-29 16:48:51 +01:00
Tim van der Meij
d6de6ea0fa
Merge pull request #12920 from roiLeo/patch-1
fix(acroforms): pdf path in acroforms example
2021-01-28 23:53:24 +01:00
Tim van der Meij
e4e92d10e8
Merge pull request #12922 from Snuffleupagus/getTextContent-globalImageCache
Ignore globally cached images in `PartialEvaluator.getTextContent` (PR 11930 follow-up)
2021-01-28 23:44:10 +01:00
Tim van der Meij
8805614a03
Merge pull request #12924 from brendandahl/fix-clone
Fix font data clone error when pdfBug is enabled.
2021-01-28 23:42:12 +01:00
Jonas Jenwald
72da2aa166 Ignore globally cached images in PartialEvaluator.getTextContent (PR 11930 follow-up)
Given that we'll only cache `/XObject`s of the `Image`-type globally, we can utilize that in `PartialEvaluator.getTextContent` as well. This way, in cases such as e.g. issue 12098, we can avoid having to fetch/parse `/XObject`s that we already know to be `Image`s. This is helpful, since `Stream`s are not cached on the `XRef` instance (given their potential size) and the lookup can thus be somewhat expensive in general.

Also, skip a redundant `RefSetCache.has` check in the `GlobalImageCache.getData` method.
2021-01-28 10:19:26 +01:00
Brendan Dahl
52fb5abb0b Fix font data clone error when pdfBug is enabled.
The widths property should be an object to match what metrics returns.

In ZapfDingbats.pdf I was getting a data clone error with pdfBug enabled.
In buildCharCodeToWidth() there was an encoding with the name "at" which
is also the name of a method on an array. buildCharCodeToWidth assumes an
object is passed in, so when it checked for the "at" property, it found the
method and copied it over.

This only seemed to affect Firefox.
2021-01-27 14:38:43 -08:00
Tim van der Meij
d52e5b0505
Merge pull request #12903 from Snuffleupagus/GlobalImageCache-byteSize
Improve global image caching for small images (PR 11912 follow-up, issue 12098)
2021-01-27 22:20:58 +01:00
Tim van der Meij
286271152f
Merge pull request #12910 from calixteman/bidi
Add back dir property in spans in text layer
2021-01-27 22:09:00 +01:00
roiLeo
7c4d751ea9
fix(acroforms): pdf path in acroforms example 2021-01-27 11:12:36 +01:00
Tim van der Meij
639437d287
Merge pull request #12911 from calixteman/reg_test
Fix text layer regression tests in using the correct line-height property
2021-01-26 23:45:45 +01:00
Tim van der Meij
d850773360
Merge pull request #12916 from Snuffleupagus/dist-sandbox
Include `pdf.sandbox.js` when building the pdfjs-dist files
2021-01-26 23:42:47 +01:00
Jonas Jenwald
85a4bc85e7 Include pdf.sandbox.js when building the pdfjs-dist files
Currently it's missing in pdfjs-dist, however that's not a big issue considering that it's broken in non-TESTING builds before PR 12914 anyway.
2021-01-26 16:34:19 +01:00
calixteman
465697eb10
JS - QuickJS sandbox initialization must be the last evaluated string (#12914)
- aims to fix issue #12912
2021-01-26 14:56:01 +01:00
Jonas Jenwald
1ab6d2c604 Improve global image caching for small images (PR 11912 follow-up, issue 12098)
When implementing the `GlobalImageCache` functionality I was mostly worried about the effect of *very large* images, hence the maximum number of cached images were purposely kept quite low[1].
However, there's one fairly obvious problem with that approach: In documents with hundreds, or even thousands, of *small* images the `GlobalImageCache` as implemented becomes essentially pointless.

Hence this patch, where the `GlobalImageCache`-implementation is changed in the following ways:
 - We're still guaranteed to be able to cache a *minimum* number of images, set to `10` (similar as before).
 - If the *total* size of all the cached image data is below a threshold[2], we're allowed to cache additional images.

This patch thus *improve*, but doesn't completely fix, issue 12098. Note that that document is created by a *very poor* PDF generator, since every single page contains the *entire* document (with all of its /Resources) and to create the individual pages clipping is used.[3]

---
[1] Currently set to `10` images; imagine what would happen to overall memory usage if we encountered e.g. 50 images each 10 MB in size.

[2] This value was chosen, somewhat randomly, to be `40` megabytes; basically five times the [maximum individual image size per page](6249ef517d/src/display/api.js (L2483-L2484)).

[3] This surely has to be some kind of record w.r.t. how badly PDF generators can mess things up...
2021-01-26 12:00:12 +01:00
Calixte Denizet
539256c351 Add back dir property in spans in text layer
- aims to fix #12909
2021-01-26 12:00:05 +01:00
calixteman
a3f6882b06
JS -- add support for choice widget (#12826) 2021-01-25 23:40:57 +01:00
Calixte Denizet
52641e8643 Fix text layer regression tests in using the correct line-height property 2021-01-25 23:01:07 +01:00
Tim van der Meij
6249ef517d
Merge pull request #12901 from timvandermeij/bump-versions
Bump versions in `pdfjs.config`
2021-01-24 18:53:54 +01:00
Tim van der Meij
7e4709433a
Bump versions in pdfjs.config 2021-01-24 18:49:33 +01:00
Tim van der Meij
f2c7338b02
Merge pull request #12897 from calixteman/12895
JS - Fix mouse event names
2021-01-24 12:28:24 +01:00
Tim van der Meij
00b4eb2a2c
Merge pull request #12898 from Snuffleupagus/update-packages
Update packages and translations
2021-01-24 12:26:23 +01:00
Tim van der Meij
12e6d9b81e
Merge pull request #12899 from Snuffleupagus/eslint-env-es2021
Update the ESLint `env` to use "es2021"
2021-01-24 12:23:39 +01:00
Jonas Jenwald
eb015ca023 Update the ESLint env to use "es2021"
Currently this is inconsistent, since we're using ECMAScript 2021 in the parser options.
2021-01-24 11:25:43 +01:00
Jonas Jenwald
09442351b8 Update l10n files 2021-01-24 08:43:09 +01:00
Jonas Jenwald
bc32515507 Update the eslint-plugin-unicorn package to the latest version
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v27.0.0 for additional details.
2021-01-24 08:38:38 +01:00
Jonas Jenwald
fea6d2fd34 Update npm packages 2021-01-24 08:34:00 +01:00
Calixte Denizet
34d2e72df2 JS - Fix mouse event names
- fix issue #12895
2021-01-23 20:26:22 +01:00
Tim van der Meij
d4c4f5d4e5
Merge pull request #12870 from Snuffleupagus/page-advance
Add previous/next-page functionality that takes scroll/spread-modes into account (issue 11946)
2021-01-23 19:35:08 +01:00
Tim van der Meij
7102e4a5c3
Merge pull request #12893 from Snuffleupagus/eslint-no-use-before-define
Enable, a basic version of, the ESLint `no-use-before-define` rule
2021-01-23 18:46:36 +01:00
Jonas Jenwald
61ceae6b4c Enable, a basic version of, the ESLint no-use-before-define rule
Given how our existing code-base is written, we simply can't (and probably don't want to) enable *all* of this ESLint rule. The reason is that we have a lot of code, especially related to functions, which is fine at runtime but might to a static analyzer *look* like a problem.
However, even in its most *basic* version this ESLint rule can help catch some outright bugs; see PR 12891.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-use-before-define
2021-01-23 16:23:19 +01:00
Tim van der Meij
25b84ce84c
Merge pull request #12828 from dhufnagel/feature/annotation_layer_display_fontsize
[api-minor] Set font size and color for text widget annotations
2021-01-23 16:08:07 +01:00
Tim van der Meij
c9a1d8cb2e
Merge pull request #12891 from Snuffleupagus/DefaultAppearanceEvaluator-fixes
Ensure that `parseDefaultAppearance` won't attempt to access a not yet defined variable (PR 12831 follow-up)
2021-01-23 15:46:42 +01:00
Jonas Jenwald
ef1d33a29e Use slightly less verbose font-names in the "Default appearance" unit-tests
The new names are not only less verbose, but also uses a *very* common PDF font-naming convention.
2021-01-23 15:34:22 +01:00
Jonas Jenwald
6bcb4e3ad9 Ensure that parseDefaultAppearance won't attempt to access a not yet defined variable (PR 12831 follow-up)
Note how, in the `if (this.stateManager.stateStack.length !== 0) {` branch, we're attempting to access the not yet defined variable[1] `args`. If this code-path is ever hit, an Error will be thrown and parsing will thus be aborted immediately (likely leading to e.g. rendering bugs).

Note that I found this purely by accident, since I happened to glance at the LGTM report. However, I've since found that the error is also present during the unit-test[2] and with this patch we're actually testing the *intended* thing here.

As part of fixing this, and to avoid re-introducing a similar bug in the future, we'll now instead always reset `args.length` *before* attempting to read the next operator.
Also, we can use the existing `EvaluatorPreprocessor.savedStatesDepth` getter to simplify the save/restore detection a tiny bit.

---
[1] The ESLint rule `no-use-before-define` would have helped catch this problem, but unfortunately we cannot enable that without quite a bit of refactoring all over the code-base.

[2] The unit-test was updated such that it would fail in the `master`-branch.
2021-01-23 15:33:28 +01:00
Dominik Hufnagel
c5083cda02 set font size and color on annotation layer
use the default appearance to set the font size and color of a text
annotation widget
2021-01-22 23:12:14 +01:00
Jonas Jenwald
a2b592f4a2 Add previous/next-page functionality that takes scroll/spread-modes into account (issue 11946)
- For wrapped scrolling, we unfortunately need to do a fair bit of parsing of the *current* page layout. Compared to e.g. the spread-modes, where we can easily tell how the pages are laid out, with wrapped scrolling we cannot tell without actually checking. In particular documents with varying page sizes require some care, since we need to check all pages on the "row" of the current page are visible and that there aren't any "holes" present. Otherwise, in the general case, there's a risk that we'd skip over pages if we'd simply always advance to the previous/next "row" in wrapped scrolling.

 - For horizontal scrolling, this patch simply maintains the current behaviour of advancing *one* page at a time. The reason for this is to prevent inconsistent behaviour for the next and previous cases, since those cannot be handled identically. For the next-case, it'd obviously be simple to advance to the first not completely visible page. However for the previous-case, we'd only be able to go back *one* page since it's not possible to (easily) determine the page layout of non-visible pages (documents with varying page sizes being a particular issue).

 - For vertical scrolling, this patch maintains the current behaviour by default. When spread-modes are being used, we'll now attempt to advance to the next *spread*, rather than just the next page, whenever possible. To prevent skipping over a page, this two-page advance will only apply when both pages of the current spread are visible (to avoid breaking documents with varying page sizes) and when the second page in the current spread is fully visible *horizontally* (to handle larger zoom values).

In order to reduce the performance impact of these changes, note that the previous/next-functionality will only call `getVisibleElements` for the scroll/spread-modes where that's necessary and that "normal" vertical scrolling is thus unaffected by these changes.

To support these changes, the `getVisibleElements` helper function will now also include the `widthPercent` in addition to the existing `percent` property.
The `PDFViewer._updateHelper` method is changed slightly w.r.t. updating the `currentPageNumber` for the non-vertical/spread modes, i.e. won't affect "normal" vertical scrolling, since that helped simplify the overall calculation of the page advance.

Finally, these new `BaseViewer` methods also allow (some) simplification of previous/next-page functionality in various viewer components.

*Please note:* There's one thing that this patch does not attempt to change, namely disabling of the previous/next toolbarButtons respectively the firstPage/lastPage secondaryToolbarButtons. The reason for this is that doing so would add quite a bit of complexity in general, and if for some reason `BaseViewer._getPageAdvance` would get things wrong we could end up incorrectly disabling the buttons. Hence it seemed overall safer to *not* touch this, and accept that the buttons won't be `disabled` despite in some edge-cases no further scrolling being possible.
2021-01-22 21:38:15 +01:00
Tim van der Meij
6ffb6b1c0c
Merge pull request #12885 from Snuffleupagus/worker-tweak-caching
Simplify the `PDFFunctionFactory._localFunctionCache` initialization (PR 12034 follow-up); Fix the `gStateObj` lookup in `TranslatedFont._removeType3ColorOperators` (PR 12718 follow-up)
2021-01-22 20:24:33 +01:00
Tim van der Meij
25d84e4c40
Merge pull request #12887 from Snuffleupagus/keep-logical-assignment-operators
Keep logical assignment operators in `MOZCENTRAL`/`TESTING`-builds
2021-01-22 20:21:40 +01:00
Tim van der Meij
5b675c7bf7
Merge pull request #12886 from Snuffleupagus/_getSaveFieldResources-fontName
Use `_defaultAppearanceData` directly in `WidgetAnnotation._getSaveFieldResources` (PR 12831 follow-up)
2021-01-22 20:08:59 +01:00