Commit Graph

11933 Commits

Author SHA1 Message Date
huzjakd
94171d9d72 Attempt to fallback to a default font, for non-available ones, in PartialEvaluator.loadFont
This handles the two different ways that fonts can be loaded, either by Name (which is the common case) or by Reference.
Furthermore, this also takes the `ignoreErrors` option into account when deciding whether to fallback or Error.
Finally, by creating a minimal but valid Font dictionary, there's no special-cases necessary in any of the font parsing code.

Co-authored-by: huzjakd <huzjakd@gmail.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2019-10-10 16:49:46 +02:00
Tim van der Meij
d2959fc9c9
Merge pull request #11219 from Snuffleupagus/throw-deprecated-methods
[api-minor] Replace all `deprecated` calls with throwing of actual `Error`s
2019-10-09 23:32:22 +02:00
Tim van der Meij
1c0a93aafd
Merge pull request #11222 from Snuffleupagus/rm-unmaintained-locales
Remove locales which are unmaintained and/or not shipping in Nightly (PR 11213 follow-up)
2019-10-09 23:30:50 +02:00
Jonas Jenwald
307a85901d Remove locales which are unmaintained and/or not shipping in Nightly (PR 11213 follow-up)
With the sole exception of `meh`[1], none of the locales removed here have even been updated since the last change was made to the default `en-US` locale.

Please note that if/when these locales would start shipping in Nightly again, they will automatically be re-added in PDF.js as well with the `gulp importl10n` command.

---
[1] The current translation is also somewhat incomplete, to put it mildly.
2019-10-09 10:18:00 +02:00
Jonas Jenwald
ea729ec55c [api-minor] Replace all deprecated calls with throwing of actual Errors
All of these methods have been marked as `deprecated` in *three* releases now, and I'd thus like to (slowly) move towards complete removal.

However rather than just removing the methods right away, which would cause somewhat cryptic failures, this patch tries to implement a hopefully reasonable middle ground by throwing `Error`s with (essentially) the same information as the previous warnings.

While the previous `deprecated` messages could perhaps be seen as optional, with these changes API consumers will now be forced to actually migrate their code.
2019-10-09 09:21:15 +02:00
Tim van der Meij
5191d10dbc
Merge pull request #11209 from tamuratak/square_bracket_for_optional
Use square brackets for optional properties in the JSDoc comments of `src/display/api.js`
2019-10-08 23:25:52 +02:00
Takashi Tamura
d5ee083050 * use square brackets for optional properties in the JSDoc comments of src/display/api.js 2019-10-08 20:34:17 +09:00
Tim van der Meij
cead77ef3a
Merge pull request #11186 from Snuffleupagus/issue-9655
Improve the heuristics, in `PartialEvaluator._buildSimpleFontToUnicode`, for glyphNames of the Cdd{d}/cdd{d} format (issue 9655)
2019-10-06 19:50:43 +02:00
Tim van der Meij
a21f60415d
Merge pull request #11213 from Snuffleupagus/importl10n-fetch-langCodes
Update the `gulp importl10n` command to fetch the active language codes
2019-10-06 19:44:10 +02:00
Tim van der Meij
5fb3eb7728
Merge pull request #11212 from Snuffleupagus/MessageHandler-deleteStreamController
[MessageHandler] Some additional (small) clean-up of the code
2019-10-06 19:23:13 +02:00
Jonas Jenwald
dee3da69d4 Have gulp importl10n list locales which may be candidates for removal
Rather than having the script remove locales automatically, which seems like a heavy-handed approach at least initially, listing these for manual checking seems nice though.
2019-10-06 18:12:29 +02:00
Jonas Jenwald
8d74a9ae7f Update l10n files 2019-10-06 18:12:29 +02:00
Jonas Jenwald
ed71ec3785 Update the gulp importl10n command to fetch the active language codes
Rather than having to manually maintain a static list of language codes, it's much easier to simply fetch the active ones from `mozilla-central` instead.

As part of this the code in `external/importL10n/locales.js` was modernized slightly, by using Promises/async functions to get rid of a bunch of annoying callbacks (which shouldn't be a problem for reasonably modern Node.js versions).
2019-10-06 18:12:27 +02:00
Jonas Jenwald
eabedab38e [MessageHandler] Add a non-PRODUCTION/TESTING check to ensure that wrapReason is called with a valid reason
There shouldn't be any situation where `reason` isn't either an `Error`, or a cloned "Error" sent via `postMessage`.
2019-10-06 14:15:13 +02:00
Jonas Jenwald
9201c8dad4 [MessageHandler] Convert the deleteStreamController helper function to a "private" method instead 2019-10-06 14:15:02 +02:00
Jonas Jenwald
f5be2d62a3 Improve the heuristics, in PartialEvaluator._buildSimpleFontToUnicode, for glyphNames of the Cdd{d}/cdd{d} format (issue 9655)
*Please note:* I've been thinking about possible ways of addressing this issue for a while now, but all of the solutions I came up with became too complicated and thus hurt readability of the code.
However, it occured to me that we're essentially trying to add a heuristic *on top* of another heuristic, and that it shouldn't matter how efficient the code is as long as it works.

In the PDF file in the issue the Encoding contains glyphNames of the `Cdd` format, which our existing heuristics will treat as base 10 values. However, in this particular file they actually contain base 16 values, which we thus attempt to detect and fix such that text-selection works.
2019-10-06 10:47:29 +02:00
Tim van der Meij
0786363b7c
Merge pull request #11198 from Snuffleupagus/PDFSidebarResizer-fixes
[PDFSidebarResizer] Add a couple of (small) readability improvements in the code
2019-10-05 19:00:04 +02:00
Tim van der Meij
4a1fc62d6c
Merge pull request #11202 from timvandermeij/bump
Bump versions in `pdfjs.config`
2019-10-03 23:54:14 +02:00
Tim van der Meij
117daf0280
Bump versions in pdfjs.config 2019-10-03 23:49:48 +02:00
Jonas Jenwald
32d16ab5f6 [PDFSidebarResizer] Re-factor the resize event listener to improve readability
I've absolutely no idea why I wrote the code that way originally, since the nested `if`s are not really helping readability one bit.
Hence this patch which changes things to use early `return`s instead, to help readability.
2019-10-03 12:24:19 +02:00
Jonas Jenwald
9e4552d792 [PDFSidebarResizer] Refactor the clamping in _updateWidth
Rather than manually clamping the `width` here, we can just `export` an already existing helper function from `ui_utils.js` instead.

(Hopefully it will eventually be possible to replace this helper function with a native `Math.clamp` function, given that there exists a "Stage 1 Proposal" for adding such a thing to the ECMAScript specification.)
2019-10-03 12:03:45 +02:00
Jonas Jenwald
c1cfe2881b [PDFSidebarResizer] Skip the CSS.supports checks for MOZCENTRAL builds
Since CSS variable support cannot be disabled any more in Firefox, the run-time checks are of no using for MOZCENTRAL builds.
2019-10-03 11:55:13 +02:00
Tim van der Meij
4ae3f9fcf6
Merge pull request #11187 from Snuffleupagus/image-Error-classes
Convert the various image decoder `...Error`s to classes extending `BaseException` (PR 11185 follow-up)
2019-10-01 23:24:58 +02:00
Jonas Jenwald
572abdcb4a Convert the various image decoder ...Errors to classes extending BaseException (PR 11185 follow-up)
Somehow I missed these in PR 11185, but there's no good reason not to convert them as well.
2019-10-01 13:10:14 +02:00
Tim van der Meij
8c4f4b5eec
Merge pull request #11182 from Snuffleupagus/disableWorker-disable-Dict-postMessage
Forbid sending of `Dict`s and `Stream`s, with `postMessage`, when workers are disabled
2019-09-29 15:09:42 +02:00
Tim van der Meij
06e4eb4714
Merge pull request #11185 from Snuffleupagus/Exception-classes
Convert the various `...Exception`s to proper classes, to reduce code duplication
2019-09-29 15:06:22 +02:00
Jonas Jenwald
5d93fda4f2 Convert the various ...Exceptions to proper classes, to reduce code duplication
By utilizing a base "class", things become significantly simpler. Unfortunately the new `BaseException` cannot be a proper ES6 class and just extend `Error`, since the SystemJS dependency doesn't seem to play well with that.
Note also that we (generally) need to keep the `name` property on the actual `...Exception` object, rather than on its prototype, since the property will otherwise be dropped during the structured cloning used with `postMessage`.
2019-09-29 10:16:20 +02:00
Jonas Jenwald
3f8fee371b Forbid sending of Dicts and Streams, with postMessage, when workers are disabled
By default, i.e. with workers enabled, it's *purposely* not possible to send `Dict`s and `Stream`s from the worker-thread. This is achieved by defining a `function` on every `Dict` instance, since that ensures that [the structured clone algoritm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) will throw an Error on `postMessage`.

However, with workers *disabled* we fall-back to the `LoopbackPort` implementation which just ignores any `function`s, thus incorrectly allowing sending of data which *should* be unclonable.
2019-09-26 16:16:13 +02:00
Tim van der Meij
cd909c531f
Merge pull request #11169 from Snuffleupagus/Dict-inline-Ref-checks
Reduce the number of function calls in the `Dict` class
2019-09-24 23:33:37 +02:00
Tim van der Meij
f762d59ad2
Merge pull request #11173 from Snuffleupagus/ReadableStream-polyfill
Replace the bundled `ReadableStream` polyfill with the `web-streams-polyfill` npm package (issue 11157)
2019-09-24 23:22:17 +02:00
Jonas Jenwald
2cac68467f Reduce the number of function calls in the Dict class
The following changes were made:
 - Remove unnecessary `typeof` checks in the `get`/`getAsync` methods.
 - Reduce unnecessary code duplication in the `get`/`getAsync` methods.
 - Inline the `Ref` checks in the `get`/`getAsync`/`getArray` methods, since it helps avoid many unnecessary functions calls. I.e. this way it's possible to directly call `XRef.{fetch, fetchAsync)` only when necessary, rather than always having to call `XRef.{fetchIfRef, fetchIfRefAsync)`.

This patch was tested using the PDF file from issue 2618, i.e. http://bugzilla-attachments.gnome.org/attachment.cgi?id=226471, using the following manifest file:
```
[
    {  "id": "issue2618",
       "file": "../web/pdfs/issue2618.pdf",
       "md5": "",
       "rounds": 250,
       "type": "eq"
    }
]
```
This gave the following results when comparing this patch against the `master` branch:
```
-- Grouped By browser, stat --
browser | stat         | Count | Baseline(ms) | Current(ms) | +/- |    %  | Result(P<.05)
------- | ------------ | ----- | ------------ | ----------- | --- | ----- | -------------
Firefox | Overall      |   250 |         2821 |        2790 | -32 | -1.12 |        faster
Firefox | Page Request |   250 |            2 |           2 |   0 |  6.68 |
Firefox | Rendering    |   250 |         2820 |        2788 | -32 | -1.13 |        faster
```
2019-09-24 08:31:39 +02:00
Tim van der Meij
44f4cd529d
Merge pull request #11171 from Snuffleupagus/Dict-get-consistent-return-type
Fix the inconsistent return types for `Dict.{get, getAsync}`
2019-09-23 22:51:17 +02:00
Jonas Jenwald
0ee373f9cc Replace the bundled ReadableStream polyfill with the web-streams-polyfill npm package (issue 11157)
Compared to the recently replaced `URL` polyfill, the new `ReadableStream` polyfill isn't being exported globally for two reasons:
 - We're currently checking for the existence of a global `ReadableStream` implementation when determining if the Fetch API will be used; please see `isFetchSupported` in the src/display/display_utils.js file.
 - Given that it's much newer functionality (compared to `URL`) and that not all browsers may implement all parts of the specification yet, not exposing the `ReadableStream` globally seems safer for now.
2019-09-23 22:16:59 +02:00
Jonas Jenwald
7f18c57c12 Fix the inconsistent return types for Dict.{get, getAsync}
Having these methods fallback to returning `null` in only *one* particular case seems outright wrong, since a "falsy" value will thus be handled incorrectly.
The only reason that this hasn't caused issues in practice is that there's only one call-site passing in three keys, and in that case we're trying to read a font file where falling back to `null` isn't a problem.
2019-09-23 11:41:19 +02:00
Tim van der Meij
9596d702a9
Merge pull request #11168 from timvandermeij/updates
Remove unmaintained localizations and update translations and packages
2019-09-21 14:05:14 +02:00
Tim van der Meij
27dee5e911
Update translations and packages 2019-09-21 13:42:27 +02:00
Tim van der Meij
bdd28fd717
Remove unmaintained localizations
Fixes #11167.
2019-09-21 13:31:42 +02:00
Tim van der Meij
e91836f832
Merge pull request #11165 from Snuffleupagus/eslint-return-rules
Enable a couple of `return` related ESLint rules
2019-09-20 21:59:25 +02:00
Jonas Jenwald
b822356c03 Enable a couple of return related ESLint rules
Please find additional details at:
 - https://eslint.org/docs/rules/no-return-await
 - https://eslint.org/docs/rules/no-useless-return
2019-09-20 14:30:03 +02:00
Tim van der Meij
c289f3a969
Merge pull request #11146 from timvandermeij/core-js
Replace our `URL` polyfill with the one from `core-js`
2019-09-19 23:30:08 +02:00
Tim van der Meij
a03727892e
Merge pull request #11163 from stof/patch-1
Fix the link in the doc website
2019-09-19 23:26:02 +02:00
Christophe Coevoet
4e79404d4b
Fix the link in the doc website
Markdown syntax is not parsed inside an HTML table.
2019-09-19 18:03:40 +02:00
Tim van der Meij
1f5ebfbf0c
Replace our URL polyfill with the one from core-js
`core-js` polyfills have proven to be of good quality and using them
prevents us from having to maintain them ourselves.
2019-09-19 14:09:51 +02:00
Tim van der Meij
c71a291317
Upgrade core-js to version 3.2.1
This only required changing the import paths. The `es` folder contains
all polyfills we need now. If we want to import everything, we need to
explicitly require the `index` file.
2019-09-19 13:58:36 +02:00
Tim van der Meij
3da680cdfc
Merge pull request #11158 from janpe2/gradient-stops
Avoid floating point inaccuracy in gradient color stops
2019-09-19 13:15:11 +02:00
Tim van der Meij
58e5f36666
Merge pull request #11159 from Snuffleupagus/issue-11150
For Type1 fonts, replace missing font dictionary /Widths entries with ones from the font data (issue 11150)
2019-09-19 13:14:27 +02:00
Tim van der Meij
7af66c8c12
Merge pull request #11155 from Snuffleupagus/MessageHandler-misc-cleanup
Miscellaneous (small) clean-up of the `MessageHandler` code
2019-09-18 23:51:53 +02:00
Jonas Jenwald
af22dc9b0c For Type1 fonts, replace missing font dictionary /Widths entries with ones from the font data (issue 11150)
Hopefully this patch makes sense, and in order to reduce the regression risk the implementation ensures that only completely missing widths are being replaced.
2019-09-18 10:15:09 +02:00
Jani Pehkonen
911df237f3 Avoid floating point inaccuracy in gradient color stops 2019-09-17 21:01:17 +03:00
Jonas Jenwald
4bd79ec4b3 Inline the resolveOrReject helper function at its call-sites in MessageHandler, and rename an error key to reason
Given that there's only a couple of call-sites, and that the helper function is really simple, it doesn't seem entirely necessary to keep it around. While fewer function calls is always a good thing, in this case the performance impact is small enough to be unmeasurable.

With *one* single exception the code in `MessageHandler` is using `reason` when passing around various Errors, hence this patch also renames an `error` key for consistency.
2019-09-17 14:22:24 +02:00