Commit Graph

13121 Commits

Author SHA1 Message Date
Tim van der Meij
e3851a6765
Merge pull request #12591 from Snuffleupagus/strokeColor-Pattern
Improve the Pattern-detection in `CanvasGraphics.stroke`
2020-11-06 22:16:26 +01:00
Brendan Dahl
018fd43096
Merge pull request #12530 from calixteman/js_utils
JS -- Add 'util' object
2020-11-06 09:59:50 -08:00
Calixte Denizet
f69e848b1c JS -- Add 'util' object
This patch provides an implementation of the util object as described:
 * https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf#page=716
2020-11-06 18:12:29 +01:00
Jonas Jenwald
78de919bf4 Improve the Pattern-detection in CanvasGraphics.stroke
The vast majority of the time, unless a Pattern is active, the `strokeColor`-property contains a "simple" colour value represented by a String. Hence it seems somewhat ridiculous to do a `hasOwnProperty` check on a String, and it's should thus be possible to improve things a tiny bit here.

Unfortunately using a simple `instanceof` check would only work for `TilingPattern`s, but not for the `ShadingIRs` given how they are implemented; see `src/display/pattern_helper.js`. (While that file could probably do with some clean-up, given the age of some of its code, that probably shouldn't happen here.)

Finally, the `this.type = "Pattern"`-property of the various Shadings/TilingPatterns were removed, since I cannot see why it's necessary when we can simply check for a `getPattern` method instead. Note that part of this code even pre-dates the main/worker-thread split, which probably in part explains why it looks the way it does.
2020-11-06 11:46:35 +01:00
Tim van der Meij
be0794cb08
Merge pull request #12564 from hakubo/patch-1
Make sure that Popup is rendered next to trigger for textAnnotation
2020-11-06 00:02:11 +01:00
Tim van der Meij
99ac2d1036
Merge pull request #12583 from Snuffleupagus/nonBlendModesSet
Add global caching, for /Resources without blend modes, and use it to reduce repeated fetching/parsing in `PartialEvaluator.hasBlendModes`
2020-11-05 23:53:39 +01:00
Tim van der Meij
646f895d35
Merge pull request #12568 from calixteman/defaultvalue
[api-minor] JS -- Add default value in annotation data
2020-11-05 22:53:21 +01:00
Jonas Jenwald
082cd8fc6c Add global caching, for /Resources without blend modes, and use it to reduce repeated fetching/parsing in PartialEvaluator.hasBlendModes
The `PartialEvaluator.hasBlendModes` method is necessary to determine if there's any blend modes on a page, which unfortunately requires *synchronous* parsing of the /Resources of each page before its rendering can start (see the "StartRenderPage"-message).
In practice it's not uncommon for certain /Resources-entries to be found on more than one page (referenced via the XRef-table), which thus leads to unnecessary re-fetching/re-parsing of data in `PartialEvaluator.hasBlendModes`.

To improve performance, especially in pathological cases, we can cache /Resources-entries when it's absolutely clear that they do not contain *any* blend modes at all[1]. This way, subsequent `PartialEvaluator.hasBlendModes` calls can be made significantly more efficient.

This patch was tested using the PDF file from issue 6961, i.e. https://github.com/mozilla/pdf.js/files/121712/test.pdf:
```
[
    {  "id": "issue6961",
       "file": "../web/pdfs/issue6961.pdf",
       "md5": "a80e4357a8fda758d96c2c76f2980b03",
       "rounds": 100,
       "type": "eq"
    }
]
```

which gave the following results when comparing this patch against the `master` branch:
```
-- Grouped By browser, page, stat --
browser | page | stat         | Count | Baseline(ms) | Current(ms) |  +/- |     %  | Result(P<.05)
------- | ---- | ------------ | ----- | ------------ | ----------- | ---- | ------ | -------------
firefox | 0    | Overall      |   100 |         1034 |         555 | -480 | -46.39 |        faster
firefox | 0    | Page Request |   100 |          489 |           7 | -482 | -98.67 |        faster
firefox | 0    | Rendering    |   100 |          545 |         548 |    2 |   0.45 |
firefox | 1    | Overall      |   100 |          912 |         428 | -484 | -53.06 |        faster
firefox | 1    | Page Request |   100 |          487 |           1 | -486 | -99.77 |        faster
firefox | 1    | Rendering    |   100 |          425 |         427 |    2 |   0.51 |
```

---
[1] In the case where blend modes *are* found, it becomes a lot more difficult to know if it's generally safe to skip /Resources-entries. Hence we don't cache anything in that case, however note that most document/pages do not utilize blend modes anyway.
2020-11-05 16:59:08 +01:00
Calixte Denizet
39f5954729 JS -- Add default value in annotation data
* these values are used when a form is resetted
2020-11-05 13:44:23 +01:00
Jakub Olek
b642d49108 Make sure that Popup is rendered next to trigger for textAnnotation 2020-11-05 06:45:17 +01:00
Tim van der Meij
8b652d685b
Merge pull request #12572 from Snuffleupagus/getVisibleElements-object
Change the `getVisibleElements` helper function to take a parameter object
2020-11-04 22:57:37 +01:00
Brendan Dahl
1de2bc4816
Merge pull request #12505 from calixteman/12504
Split highlight annotation div into multiple divs
2020-11-04 10:41:28 -08:00
Jonas Jenwald
ba761e42f0 Change the getVisibleElements helper function to take a parameter object
Given the number of parameters, and the fact that many of them are booleans, the call-sites are no longer particularly easy to read and understand. Furthermore, this slightly improves the formatting of the JSDoc-comment, since it needed updating as part of these changes anyway.

Finally, this removes an unnecessary `numViews === 0` check from `getVisibleElements`, since that should be *very* rare and more importantly that the `binarySearchFirstItem` function already has a fast-path for that particular case.
2020-11-04 12:15:04 +01:00
Tim van der Meij
4e13559cb0
Merge pull request #12559 from Snuffleupagus/goToPage-labels
Also update the browser history when the user *manually* change pages using the pageNumber-input (PR 12493 follow-up)
2020-11-03 23:06:49 +01:00
Tim van der Meij
3e52098e29
Merge pull request #12555 from calixteman/color
Replace css color rgb(...) by #...
2020-11-02 23:55:39 +01:00
Tim van der Meij
8550f73b22
Merge pull request #12562 from Snuffleupagus/lgtm-exclude-unused-local-variable
Try adding a very basic `lgtm.yml` file, to prevent LGTM complaining about unused variables (issue 11965)
2020-11-02 23:26:24 +01:00
Jonas Jenwald
322b1072af Use optional chaining in web/pdf_history.js
Since we're now free to use e.g. optional chaining everywhere *except* for the worker, we can thus simplify this code a bit.
2020-11-02 11:36:17 +01:00
Calixte Denizet
9d11b51a3e Replace css color rgb(...) by #...
* it's faster to generate the color code in using a table for components
* it's very likely a way faster to parse (when setting the color in the canvas)
2020-11-02 10:25:04 +01:00
Jonas Jenwald
83a3738379 Try adding a very basic lgtm.yml file, to prevent LGTM complaining about unused variables (issue 11965)
*Please note:* I cannot be sure if this actually helps, since we've not enabled LGTM for the PDF.js repository[1], however I hope that it should stop LGTM reporting things that we're already using ESLint to enforce.

---
[1] In case the patch does nothing, we can simply revert it and move on :-)
2020-11-01 17:00:40 +01:00
Jonas Jenwald
911948c5c0 Also update the browser history when the user *manually* change pages using the pageNumber-input (PR 12493 follow-up)
This patch addresses a review comment, which pointed out that we should *also* handle the pageNumber-input, from PR 12493.

Given that a user *manually* changing pages using the pageNumber-input, on the toolbar, could be regarded as a pretty strong indication of user-intent w.r.t. navigation in the document, hence I suppose that updating the browser history in this case as well probably won't hurt.
2020-11-01 15:37:24 +01:00
Jonas Jenwald
4eaa058c16 Add early returns to a couple of PDFLinkService methods, when there's no active PDF document
All of these methods will, in one way or another, cause e.g. scrolling or zooming to occur and consequently they don't really make sense unless there's an active PDF document. Especially since all of these methods end up calling into a `BaseViewer`-instance, which already contains similar early returns in essentially all of it's methods and setters.
2020-11-01 15:37:24 +01:00
Tim van der Meij
47b3b39a88
Merge pull request #12561 from Snuffleupagus/static-analyzer-warnings
Fix some static static analyzer warnings (issue 11965)
2020-11-01 14:46:20 +01:00
Tim van der Meij
c89f21b9b2
Merge pull request #12560 from Snuffleupagus/update-packages
Update `npm` packages
2020-11-01 14:10:49 +01:00
Jonas Jenwald
a177afc206 Fix some static static analyzer warnings (issue 11965)
This fixes only those warnings, as reported by https://lgtm.com/projects/g/mozilla/pdf.js?mode=list, that make sense (as far as I'm concerned).

Hence this patch leaves the following things unaddressed:
 - The "recommendation"-category, since it only complains about unused variables. However, note that all of those cases are purposely included and that there's thus ESLint-disable comments added to explictly allow them.
 - The "warning"-category, which still contains two complaints. However, as far as I can tell, they are both false positives.

Given first of all the false positives of the LGTM static analyzer, and secondly that we'd need to add (essentially duplicated) disable-comments for the unused variable cases, it's not entirely clear to me if we actually want to work towards including LGTM in the PDF.js project (e.g. running alongside Travis) or if we should just close issue 11965.
2020-11-01 12:08:38 +01:00
Jonas Jenwald
75af932b79 Update npm packages 2020-11-01 10:04:57 +01:00
Tim van der Meij
46e60a266c
Merge pull request #12552 from Snuffleupagus/annotation-fixes
Miscellaneous (small) improvements in `src/core/annotation.js`
2020-10-31 00:41:39 +01:00
Tim van der Meij
e341e6e542
Merge pull request #12525 from brendandahl/mark-info
[api-minor] Implement API to get MarkInfo from the catalog.
2020-10-31 00:05:19 +01:00
Brendan Dahl
8a8b4f9697 Collect telemetry in the viewer on whether a PDF is tagged. 2020-10-30 10:59:45 -07:00
Brendan Dahl
f5c821e9c3 [api-minor] Implement API to get MarkInfo from the catalog. 2020-10-30 10:59:45 -07:00
Jonas Jenwald
fdb6520012 Change the Catalog.openAction getter back to using an Object internally (PR 12543 follow-up)
Given that the `Map`-pattern apparently has undesirable performance characteristics, change this getter back to using an Object instead and check its size before returning it.
2020-10-30 13:27:05 +01:00
Jonas Jenwald
a1e5581a0b Let Annotation._collectActions return null when no actions are present
Rather than returning an *empty* Object[1] we should be returning `null` instead, since that's consistent with existing API-functionality.
To avoid having to *manually* track if the Object is empty, this patch also introduces a small helper function to check its size.
2020-10-30 13:23:05 +01:00
Jonas Jenwald
8540b4cc76 Stop calling Font.charsToGlyphs, in src/core/annotation.js, with unused arguments
As can be seen in `src/core/fonts.js`, this method only accepts *one* parameter, hence it's somewhat difficult to understand what the Annotation-code is actually attempting to do here.
The only possible explanation that I can imagine, is that the intention was initially to call `Font.charToGlyph` *directly* instead. However, note that that'd would not actually have been correct, since that'd ignore one level of font-caching (see `this.charsCache`). Hence the unused arguments are removed, in `src/core/annotation.js`, and the `Font.charToGlyph` method is now marked as "private" as intended.
2020-10-30 13:17:52 +01:00
Tim van der Meij
bf870bd2ac
Merge pull request #12551 from Snuffleupagus/no-useless-escape
Fix *some* errors reported by the ESLint `no-useless-escape` rule
2020-10-29 23:18:51 +01:00
Jonas Jenwald
46e94cad17 Fix *some* errors reported by the ESLint no-useless-escape rule
This patch removes unnecessary escape-sequence in (mostly) strings, as a first step, since the ones in regular expressions probably requires more careful testing (just in case).
The only exception is a regular expression in `src/core/annotation.js`, since we should have both unit- and reference-tests for this code *and* given [this information on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes#Types):
 > Inside a character set, the dot loses its special meaning and matches a literal dot.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-useless-escape
2020-10-29 15:40:40 +01:00
Tim van der Meij
7853d9798b
Merge pull request #12543 from Snuffleupagus/openActionMap
Use a `Map`, rather than an `Object`, internally in the `Catalog.openAction` getter (PR 11644 follow-up)
2020-10-28 22:21:49 +01:00
Tim van der Meij
91ca2674c3
Merge pull request #12542 from Snuffleupagus/murmurhash-slice-test
Add a `MurmurHash3_64.update` unit-test for TypedArrays which share the same underlying ArrayBuffer (PR 12534 follow-up)
2020-10-28 22:15:00 +01:00
Jonas Jenwald
820fb7f969 Update all Object.fromEntries call-sites to ensure that a null prototype is used
Given that `Object.fromEntries` doesn't seem to *guarantee* that a `null` prototype is used, we thus hack around that by using `Object.assign` with `Object.create(null)`.
2020-10-28 14:43:44 +01:00
Jonas Jenwald
9fc7cdcc9d Use a Map, rather than an Object, internally in the Catalog.openAction getter (PR 11644 follow-up)
This provides a work-around to avoid having to conditionally try to initialize the `openAction`-object in multiple places.
Given that `Object.fromEntries` doesn't seem to *guarantee* that a `null` prototype is used, we thus hack around that by using `Object.assign` with `Object.create(null)`.
2020-10-28 14:43:28 +01:00
Jonas Jenwald
852c61ef57 Add a MurmurHash3_64.update unit-test for TypedArrays which share the same underlying ArrayBuffer (PR 12534 follow-up)
This probably ought to have been included in PR 12534, but better late than never I suppose, since it helps to more clearly demonstrate the bug in a way that a reference-test alone just cannot do.

When writing this unit-test I also noticed that it required a certain amount of "luck" to actually trigger the bug, prior to the patch, since it seems that the bug only reproduced for certain *unfortunate* sequences of TypedArray data. (The added unit-test contains one such, purposely simple, example.)
2020-10-28 12:42:04 +01:00
Tim van der Meij
ea4d88a330
Merge pull request #12395 from calixteman/checks
Render not displayed annotations in using normal appearance when printing
2020-10-28 00:11:10 +01:00
Tim van der Meij
08b00c13a7
Merge pull request #12539 from Snuffleupagus/TestReporter-import
Use standard `import` statements more when running the unit-tests
2020-10-27 22:26:37 +01:00
Tim van der Meij
6fae381c57
Merge pull request #12540 from Snuffleupagus/BaseViewer-version-check
Ensure that the same version of PDF.js is used in both the API and the Viewer (PR 8959 follow-up)
2020-10-27 22:22:47 +01:00
Calixte Denizet
6be2f84b4e Render not displayed annotations in using normal appearance when printing 2020-10-27 19:00:31 +01:00
Jonas Jenwald
62b19f7e9a Ensure that the same version of PDF.js is used in both the API and the Viewer (PR 8959 follow-up)
Given that we're now accessing certain API-functionality *directly* in this file, e.g. the AnnotationStorage and Optional Content configuration, ensuring that there's not a version mismatch definitely seem like a good idea to prevent any *subtle* future bugs.
2020-10-27 17:09:42 +01:00
Jonas Jenwald
d8da6afa4c Update the description of the test-case used in the escapeString unit-test
The description *itself* didn't escape the control characters correctly, leading to line-breaks being inserted in the test logs.
2020-10-27 11:47:40 +01:00
Jonas Jenwald
92477333f6 Load the non-test files with standard import statements when running the unit-tests
The unit-test files themselves shouldn't be loaded until Jasmine has been setup/configured, however that doesn't matter for the "normal" PDF.js library files. Hence we can simply `import` them in the standard way.
2020-10-27 11:47:35 +01:00
Jonas Jenwald
8eeb0bcbe4 Import the TestReporter, in the unit and font tests
This way it's no longer necessary to load it as a script in the html-files.
2020-10-27 11:30:15 +01:00
Tim van der Meij
8098102714
Merge pull request #12532 from Snuffleupagus/refactor-font-tests
Modernize, and remove SystemJS usage from, the font-tests
2020-10-27 00:06:47 +01:00
Jonas Jenwald
939af08ee1 Remove SystemJS usage from the font-tests
With these changes, SystemJS is now *only* used to load the worker-file in development mode (pending removal once https://bugzilla.mozilla.org/show_bug.cgi?id=1247687 is fixed).
2020-10-26 23:42:44 +01:00
Jonas Jenwald
15a5f66973 Enable the ESLint no-var rule in the test/font/ folder
This was done automatically, using the `gulp lint --fix` command.
2020-10-26 23:42:44 +01:00