Commit Graph

10527 Commits

Author SHA1 Message Date
Tim van der Meij
6ac9e1c5ed
Merge pull request #9249 from MichaelDeBoey/worker-loader-requires-webpack
'worker-loader' requires 'webpack' as peerDependency
2017-12-10 16:57:10 +01:00
Tim van der Meij
095c63cc25
Merge pull request #9260 from Snuffleupagus/rm-JpegStream.getBytes
Attempt to remove the special `JpegStream.getBytes` method and utilize the regular `DecodeStream` one instead
2017-12-10 16:50:50 +01:00
Tim van der Meij
af14620b75
Merge pull request #9256 from timvandermeij/log2
Use native `Math` functions in the custom `log2` function
2017-12-10 16:43:53 +01:00
Tim van der Meij
c35bbd11b0
Use native Math functions in the custom log2 function
It is quite confusing that the custom function is called `log2` while it
actually returns the ceiling value and handles zero and negative values
differently than the native function.

To resolve this, we add a comment that explains these differences and
make the function use the native `Math` functions internally instead of
using our own custom logic. To verify that the function does what we
expect, we add unit tests.

All browsers except for IE support `Math.log2` for quite a long time
already (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2).
For IE, we use the core-js polyfill.

According to the microbenchmark at https://jsperf.com/log2-pdfjs/1,
using the native functions should also be faster, in my testing almost
six times as fast.
2017-12-10 16:35:17 +01:00
Jonas Jenwald
84de1e9a92 Attempt to remove the special JpegStream.getBytes method and utilize the regular DecodeStream one instead
Note that no other image stream implements a special `getBytes` method, which makes `JpegStream` look somewhat odd.

I'm actually not sure what purpose this methods serves, since I successfully ran all tests locally with it commented out. Furhermore, I also ran tests with an added `if (length && length !== this.bufferLength) { throw new Error('length mismatch'); }` check, and didn't get a single test failure in that case either.

Looking at the history, it seems that this code originated back in PR 4528, but as far as I can tell there's no mention in either commit messages nor PR comments of why it was necessary to add a "special" `getBytes` function for the `JpegStream`.
My assumption is that there's a good reason why this method was added, e.g. to address a *specific* regression in one of the reference tests. However, I did check out commit 58f697f977 locally and ran tests with this method commented out, and there didn't seem to be any image-related failures in that case either!?

Hence I'm suggesting that we attempt to simplify this code slightly be removing this special `getBytes` method. However, please note that there's perhaps a *small* risk of regressions in an edge-case where we currently have insufficient test-coverage.
2017-12-10 13:31:08 +01:00
Jonas Jenwald
371ca51402
Merge pull request #9207 from Standard8/use-mozilla-recommended
Switch to using mozilla/recommended configuration for extensions/firefox.
2017-12-08 21:06:49 +01:00
Mark Banner
63c6157bdf Switch to using mozilla/recommended configuration for extensions/firefox. 2017-12-08 18:58:48 +00:00
Brendan Dahl
af1d80d45e
Merge pull request #9230 from Snuffleupagus/issue-9195
Add basic support for non-embedded Calibri fonts (issue 9195)
2017-12-08 10:15:43 -08:00
Jonas Jenwald
a5e3261b48
Merge pull request #9062 from mozilla/no_high
Move char codes from high surrogate pair range into private use.
2017-12-08 12:31:22 +01:00
Michaël De Boey
e3324d45bc
'worker-loader' requires 'webpack' as peerDependency 2017-12-07 23:10:12 +01:00
Tim van der Meij
694c4171d5
Merge pull request #9245 from Snuffleupagus/issue-5215
[api-major] Only create a `StatTimer` for pages when `enableStats == true` (issue 5215)
2017-12-07 21:59:32 +01:00
Brendan Dahl
306999c325 Move char codes from high surrogate pair range into private use.
Fixes #2884
2017-12-07 10:35:50 -08:00
Brendan Dahl
518da6c6a9
Merge pull request #9244 from Snuffleupagus/firefox-DEFAULT_PREFERENCES-eslint-disable-semi
[Firefox addon] Temporarily disable the ESLint `semi` rule, around the `DEFAULT_PREFERENCES` declaration, to prevent mozilla-central test errors
2017-12-07 08:45:22 -08:00
Jonas Jenwald
7c5ba9aad5 [api-major] Only create a StatTimer for pages when enableStats == true (issue 5215)
Unless the debugging tools (i.e. `PDFBug`) are enabled, or the `browsertest` is running, the `PDFPageProxy.stats` aren't actually used for anything.
Rather than initializing unnecessary `StatTimer` instances, we can simply re-use *one* dummy class (with static methods) for every page. Note that by using a dummy `StatTimer` in this way, rather than letting `PDFPageProxy.stats` be undefined, we don't need to guard *every* single stats collection callsite.

Since it wouldn't make much sense to attempt to use `PDFPageProxy.stats` when stat collection is disabled, it was instead changed to a "private" property (i.e. `PDFPageProxy._stats`) and a getter was added for accessing `PDFPageProxy.stats`. This getter will now return `null` when stat collection is disabled, making that case easy to handle.

For benchmarking purposes, the test-suite used to re-create the `StatTimer` after loading/rendering each page. However, modifying properties on various API code from the outside in this way seems very error-prone, and is an anti-pattern that we really should avoid at all cost. Hence the `PDFPageProxy.cleanup` method was modified to accept an optional parameter, which will take care of resetting `this.stats` when necessary, and `test/driver.js` was updated accordingly.

Finally, a tiny bit more validation was added on the viewer side, to ensure that all the code we're attempting to access is defined when handling `PDFPageProxy` stats.
2017-12-06 23:12:25 +01:00
Jonas Jenwald
50b72dec6e Convert StatTimer to an ES6 class 2017-12-06 13:59:03 +01:00
Jonas Jenwald
6b1eda3e12 Move StatTimer from src/shared/util.js to src/display/dom_utils.js
Since the `StatTimer` is not used in the worker, duplicating this code on both the main and worker sides seem completely unnecessary.
2017-12-06 13:51:04 +01:00
Jonas Jenwald
b15de69c52 [Firefox addon] Temporarily disable the ESLint semi rule, around the DEFAULT_PREFERENCES declaration, to prevent mozilla-central test errors
While this doesn't actually fix the underlying issue, it should prevent the ESLint errors and thus make future PDF.js updates easier.
Compared to updating (and testing) the preprocessor, this seems like a reasonable workaround given its simplicity.
2017-12-05 20:52:39 +01:00
Tim van der Meij
f299473697
Merge pull request #9229 from timvandermeij/unit-tests-util
Implement unit tests for utility functions that perform type/value checks
2017-12-04 22:48:24 +01:00
Tim van der Meij
a29c2d9944
Implement unit tests for utility functions that perform type/value checks 2017-12-04 22:36:45 +01:00
Jonas Jenwald
08de655177 Add basic support for non-embedded Calibri fonts (issue 9195)
There's a number of issues with the fonts in the referenced PDF file. First of all, they contain broken `ToUnicode` data (`NUL` bytes all over the place). However even if you skip those, the `ToUnicode` data appears to contain nothing but a `IdentityH` CMap which won't help provide a proper glyph mapping.

The real issue actually turns out to be that the PDF file uses the "Calibri" font[1], but doesn't include any font files. Since that one isn't a standard font, and uses a fairly different CID to GID map compared to the standard fonts, we're not able to render the file even remotely correct.
To work around this, I'm thus proposing that we include a (incomplete) glyph map for Calibri, and fallback to the standard Helvetica font. Obviously this isn't going to look perfect, but it's really the best that we can hope to achieve given that the PDF file is missing the necessary font data.

Finally, please note that none of the PDF readers I've tried (Adobe Reader, PDFium in Chrome) were able to extract the text (which isn't very surprising, given the broken `ToUnicode` data).

Fixes 9195.

---

[1] According to Wikipedia, see https://en.wikipedia.org/wiki/Calibri, Calibri is (primarily) a Windows font.
2017-12-03 17:23:33 +01:00
Tim van der Meij
de0bac727e
Merge pull request #9228 from timvandermeij/unit-tests
Implement unit tests for the utility functions `bytesToString` and `stringToBytes`
2017-12-03 13:01:17 +01:00
Tim van der Meij
70a28ab34f
Implement unit tests for the utility functions bytesToString and stringToBytes 2017-12-03 12:52:16 +01:00
Tim van der Meij
98457d9e92
Merge pull request #9227 from Snuffleupagus/sidebar-resize-left-button
Only resize the sidebar with the left mouse button
2017-12-02 19:42:59 +01:00
Jonas Jenwald
ac4496bcec Only resize the sidebar with the left mouse button 2017-12-02 19:05:17 +01:00
Tim van der Meij
4894518cde
Merge pull request #9214 from SehyunPark/patch-13
Add SehyunPark to AUTHORS
2017-11-30 21:58:46 +01:00
Tim van der Meij
7d5ab905d9
Merge pull request #9218 from SehyunPark/patch-14
Add comma(,) in index.md
2017-11-30 21:54:16 +01:00
Brendan Dahl
bfa227a502
Merge pull request #9215 from Snuffleupagus/lower-MIN_SCALE
Lower the `MIN_SCALE` threshold to `0.10` (i.e. 10%) in the viewer, for better compatibility with documents containing very large pages
2017-11-30 10:19:09 -08:00
Jonas Jenwald
fffd5cb875 Update l10n files 2017-11-30 13:35:00 +01:00
Jonas Jenwald
f3c50fe2f9
Merge pull request #9192 from Snuffleupagus/issue-8229
Build a fallback `ToUnicode` map for simple fonts (issue 8229)
2017-11-30 10:27:32 +01:00
SehyunRyanPark
ac3e26b1a6
Update index.md
adding the appropriate comma(,) in order to make the sentence more understandable to the readers.
2017-11-30 09:50:00 +09:00
Jonas Jenwald
ba73bbc7b4 Lower the MIN_SCALE threshold to 0.10 (i.e. 10%) in the viewer, for better compatibility with documents containing very large pages
For sufficiently large page sizes, always limiting the minimum zoom level to 25% seem a bit too high. One example is pages, e.g. the first one, in:

Hence I think that it makes sense to lower `MIN_SCALE` slightly, since other PDF viewers (e.g. Adobe Reader) isn't limiting the minimum zoom level as aggressively. Obviously this will allow a greater number of pages to be visible at the same time in the viewer, but given that they will be small that shouldn't be an issue.

Note also that e.g. the `page-fit`/`page-width` zoom levels already allow `< MIN_SCALE` values, so I don't see why we shouldn't allow users the same functionality directly.
2017-11-29 14:36:57 +01:00
SehyunRyanPark
7b1c59ca55
Add SehyunPark to AUTHORS
Add SehyunPark to AUTHORS
2017-11-29 22:24:08 +09:00
Brendan Dahl
fbf456f51e
Merge pull request #9201 from ydfzgyj/btoa
Add `btoa` back to domstubs.js
2017-11-28 17:29:16 -08:00
Tim van der Meij
e320243870
Merge pull request #9206 from janpe2/svg-inv-images
Fix inverted 1-bit images in SVG backend
2017-11-28 22:46:43 +01:00
Jonas Jenwald
e78fe842c7
Merge pull request #9090 from janpe2/pattern-text
Fix pattern-filled text (embedded fonts only)
2017-11-28 20:38:58 +01:00
Jani Pehkonen
58b214eab3 Fix inverted 1-bit images in SVG backend 2017-11-28 21:24:27 +02:00
Jani Pehkonen
06d083b04b Fix pattern-filled text 2017-11-28 19:40:22 +02:00
巴里切罗
27a619246f Add btoa back to domstubs.js 2017-11-28 16:34:53 +08:00
Tim van der Meij
3e34eb31d9
Merge pull request #9191 from timvandermeij/pushbuttons
Button widget annotations: implement support for pushbuttons
2017-11-27 22:31:07 +01:00
Jonas Jenwald
61e19bee43 Build a fallback ToUnicode map for simple fonts (issue 8229)
In some fonts, the included `ToUnicode` data is incomplete causing text-selection to not work properly. For simple fonts that contain encoding data, we can manually build a `ToUnicode` map to attempt to improve things.

Please note that since we're currently using the `ToUnicode` data during glyph mapping, in an attempt to avoid rendering regressions, I purposely didn't want to amend to original `ToUnicode` data for this text-selection edge-case.
Instead, I opted for the current solution, which will (hopefully) give slightly better text-extraction results in PDF file with incomplete `ToUnicode` data.

According to the PDF specification, see [section 9.10.2](http://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G8.1873172):

> A conforming reader can use these methods, in the priority given, to map a character code to a Unicode value.
> ...

Reading that paragraph literally, it doesn't seem too unreasonable to use *different* methods for different charcodes.

Fixes 8229.
2017-11-26 14:45:15 +01:00
Tim van der Meij
0fe80df2a7
Button widget annotations: implement support for pushbuttons 2017-11-26 14:09:48 +01:00
Jonas Jenwald
ffbfc3c2a7 Refactor the building of ToUnicode maps for simple fonts a helper method 2017-11-26 13:30:29 +01:00
Tim van der Meij
b32d659dff
Merge pull request #9190 from Snuffleupagus/rm-app-pageRotation
Remove the `pageRotation` getter in `PDFViewerApplication`
2017-11-26 13:05:09 +01:00
Jonas Jenwald
c1f385eda9 Remove the pageRotation getter in PDFViewerApplication
This was added, during the refactoring in PR 8556, to avoid outright breaking third-party users of the default viewer.
With PDF.js version `2.0`, where we're making API changes that aren't backwards compatible, we ought to be able to remove this piece of viewer code as well.
2017-11-26 10:39:24 +01:00
Tim van der Meij
ada47fe373
Merge pull request #9189 from Snuffleupagus/WorkerTransport.getPage-signature
Remove the unused `capability` parameter from the `WorkerTransport.getPage` method
2017-11-25 14:05:04 +01:00
Jonas Jenwald
ab1f76cc37 Remove the unused capability parameter from the WorkerTransport.getPage method
That parameter, originally named `promise`, has been unused for over five years; ever since commit f0687c4d50 in PR 1531.
2017-11-25 11:49:33 +01:00
Jonas Jenwald
343f331b8b
Merge pull request #9095 from Snuffleupagus/WebGLFactory
Split the existing `WebGLUtils` in two classes, a private `WebGLUtils` and a public `WebGLContext`, and utilize the latter in the API to allow various code to access the methods of `WebGLUtils`
2017-11-24 23:25:06 +01:00
Jonas Jenwald
59b5e14301 Split the existing WebGLUtils in two classes, a private WebGLUtils and a public WebGLContext, and utilize the latter in the API to allow various code to access the methods of WebGLUtils
This patch is one (small) step on the way to reduce the general dependency on a global `PDFJS` object, for PDF.js version `2.0`.
2017-11-24 21:54:47 +01:00
Jonas Jenwald
503bc95a2b
Merge pull request #9187 from Standard8/use-services
Update eslint-plugin-mozilla, and enable mozilla/use-services rule.
2017-11-24 18:24:38 +01:00
Mark Banner
3065197cc4 Update eslint-plugin-mozilla, and enable mozilla/use-services rule. 2017-11-24 16:58:36 +00:00