Commit Graph

9196 Commits

Author SHA1 Message Date
Jonas Jenwald
6e126b31dc Only update the max-height of the SecondaryToolbar when it's actually visible
There's really no good reason to attempt to adjust the `max-height` of the `SecondaryToolbar` when it's not visible, so let's not do that anymore.
Also, we can listen for the `resize` event in `SecondaryToolbar`, to avoid having to manually call the `max-height` adjust function from various event handlers in `app.js`. Please note that by always adjusting the `max-height` when the toolbar is opened we no longer need the `localized` event, since it was mainly used to set a correct inital `max-height` value.
2016-09-09 08:16:09 +02:00
Jonas Jenwald
e12c48b73f Add a enhanceTextSelection preference
Please note that this is a hack, but I think that it should be OK for now to atleast get the preference landed. Refer to the code comment for further information.

Re: issue 7584 and PR 7586.
2016-09-08 10:22:01 +02:00
Jonas Jenwald
ca61ccc533 Merge pull request #7602 from timvandermeij/interactive-forms
Render interactive form (AcroForm) text widget annotations
2016-09-08 10:13:27 +02:00
Tim van der Meij
e281ce7c73 Enable regression testing for interactive forms 2016-09-07 16:50:44 +02:00
Tim van der Meij
e686db250c Render interactive form (AcroForm) text widget annotations
This patch is the first step towards implementing support for
interactive forms (AcroForms). It makes it possible to render text
widget annotations exactly like Adobe Reader/Acrobat.

Everything we implement for AcroForms is disabled by default using a
preference, mainly because it is not ready to use yet, but has to
implemented in many steps to avoid complexity. The preference allows us
to work with the code while not exposing the behavior by default. Mainly
storing entered values and printing them is still absent, which would be
minimal requirements for enabling this by default.
2016-09-07 15:37:28 +02:00
Jonas Jenwald
8dbb5a7c4a Merge pull request #7596 from timvandermeij/widget-annotation-cleanup
Improve the structure for widget annotations
2016-09-06 13:46:31 +02:00
Jonas Jenwald
44b75c01a1 Check that Type1C fonts does not actually contain OpenType font files (issue 7598)
This patch is yet another instalment in the (never ending) series of patches for PDF files that specify completely incorrect Type/Subtype for its fonts. In this case Type1/Type1C, when in fact OpenType would have been correct.

Fixes 7598.
2016-09-06 10:13:11 +02:00
Tim van der Meij
576f742047 Improve the structure for widget annotations
Currently, we only support text widget annotations (field type 'Tx')
partially. However, the current code does not make this entirely clear
and does not provide a warning when an unsupported field type is
encountered, making it harder to determine why rendering fails.

Moreover, in the display layer we make no distinction between the
various types of widget annotations, causing the code for text widget
annotations to also be executed for other types of widget annotations in
a fallback situation.

This patch improves the structure of the widget annotation code. In the
core layer, we use the same structure we use for non-widget annotations
in the factory and provide a clear warning when an unsupported type is
encountered. In the display layer, we do the same and split the
`WidgetAnnotationElement` class into two classes, namely
`TextWidgetAnnotationElement` for text widget annotations and
`WidgetAnnotationElement` for other unsupported annotations as a
fallback. From this it clear that we only support text widget
annotations and nothing else.
2016-09-06 00:26:05 +02:00
Tim van der Meij
b26af7ee24 Merge pull request #7595 from Snuffleupagus/api-reject-with-Error
In `display/api.js` ensure that we always reject with an `Error` in `JpegDecode`, and adjust a couple of other rejection sites as well
2016-09-05 17:14:44 +02:00
Jonas Jenwald
37998076c9 In display/api.js ensure that we always reject with an Error in JpegDecode, and adjust a couple of other rejection sites as well
In the case where the document was destroyed, we were rejecting the `Promise` in `JpegDecode` with a string instead of an `Error`. The patch also brings the wording more inline with other such rejections.

Use the `isInt` utility function when validating the `pageNumber` parameter in `WorkerTransport_getPage`, to make it more obvious what's actually happening. There's also a couple more unit-tests added, to ensure that we always fail in the expected way.

Finally, we can simplify the rejection handling in `WorkerTransport_getPageIndexByRef` somewhat. (Note that the only reason for using `catch` here is that since the promise is rejected on the worker side, the `reason` becomes a string instead of an `Error` which is why we "re-reject" on the display side.)
2016-09-05 16:35:32 +02:00
Jonas Jenwald
38c85039d1 Merge pull request #7588 from timvandermeij/text-layer-weakmap
Use a `WeakMap` in `src/display/text_layer.js`
2016-09-04 21:25:48 +02:00
Tim van der Meij
96593571eb Optimize scale calculation in text_layer.js
This patch avoids having to calculate the scale twice by saving it in
the properties object.

Moreover, we remove a temporary variable and place parentheses around a
calculation inside a string concatenation.
2016-09-04 20:19:31 +02:00
Tim van der Meij
7db1983d64 Merge pull request #7591 from Snuffleupagus/jpeg-error
Change `src/core/jpg.js` to use the `error` utility function instead of `throw`ing
2016-09-04 20:11:09 +02:00
Jonas Jenwald
a35773ec8c Change src/core/jpg.js to use the error utility function instead of throwing
This allows us to remove the `try/catch` statements used in `src/core/stream.js` when parsing JPEG images.
As far as I can tell, the only reason for the current usage of plain `throw` is that `jpg.js` originally was external code. Given that this code now lives in our repo, this patch brings the JPEG code more in line with e.g. `src/core/jpx.js` and `src/core/jbig2.js`.
2016-09-04 16:28:23 +02:00
Tim van der Meij
d03651efff Merge pull request #7407 from Snuffleupagus/issue-7406
Assign the `quantizationTables` after parsing the entire JPEG image, to prevent issues when the DQT (Define Quantization Tables) marker is encountered after SOF{n} (Start of Frame) markers (issue 7406)
2016-09-04 14:49:01 +02:00
Tim van der Meij
31f6180a08 Merge pull request #7592 from timvandermeij/revert
Revert the commits from pull request #7586 for causing addon issues
2016-09-03 20:42:21 +02:00
Tim van der Meij
eb2ba3287a Revert "Move the Preferences initialization/fetching code to the top of PDFViewerApplication.initialize, to enable using them when initializing the viewer components"
This reverts commit ffb876fdf4.
2016-09-03 20:27:01 +02:00
Tim van der Meij
a2525a8ba3 Revert "Add a enhanceTextSelection preference to the viewer"
This reverts commit 15e45d772f.
2016-09-03 20:26:46 +02:00
Tim van der Meij
b3818d5c36 Replace div.dataset with a WeakMap in text_layer.js
This patch improves performance by avoiding unnecessary type
conversions, which also help the JIT for optimizations.

Moreover, this patch fixes issues with the div expansion code where
`textScale` would be undefined in a division. Because of the `dataset`
usage, other comparisons evaluated to `true` while `false` would have
been correct. This makes the expansion mode now work correctly for cases
with, for example, each glyph in one div.

The polyfill for `WeakMap` has been provided by @yurydelendik.
2016-09-03 20:06:42 +02:00
Tim van der Meij
461a18a74a Merge pull request #7586 from Snuffleupagus/viewer-initialize-Preferences-earlier
Move the `Preferences` initialization/fetching code to the top of `PDFViewerApplication.initialize`, and add a `enhanceTextSelection` preference to the viewer
2016-09-03 18:55:24 +02:00
Tim van der Meij
b10add14f3 Refactor text_layer.js to pass the task as a parameter
We pass many parameters to `appendText` while we might as well pass the
`task` object that contains them. This saves a few lines of code and
makes the signature of `appendText` more clear. We do the same for
`expand`, which is useful for the next commit in which we replace
`div.dataset` with a `WeakMap`.

Furthermore, this patch adds a missing parameter to a comment block to
make it clear which parameters remain.
2016-09-02 20:46:36 +02:00
Jonas Jenwald
15e45d772f Add a enhanceTextSelection preference to the viewer 2016-09-02 14:38:51 +02:00
Jonas Jenwald
ffb876fdf4 Move the Preferences initialization/fetching code to the top of PDFViewerApplication.initialize, to enable using them when initializing the viewer components 2016-09-02 14:38:48 +02:00
Tim van der Meij
8522625da2 Merge pull request #7585 from timvandermeij/text-selection-code-fixes
Minor code style improvements after #7539
2016-09-01 18:48:04 +02:00
Tim van der Meij
7c961b6b7a Minor code style improvements after #7539 2016-09-01 18:07:12 +02:00
Tim van der Meij
6bb95e3129 Merge pull request #7539 from jeremypress/fairexpand
[api-minor] Expanding divs to improve selection
2016-09-01 17:43:31 +02:00
Tim van der Meij
61a576c41f Merge pull request #7583 from Snuffleupagus/Named-Action-GoToPage-select
Change the `GoToPage` Named Action to select the contents of the `pageNumber` input, rather than just focusing the element
2016-09-01 15:38:37 +02:00
Jonas Jenwald
0db76dc58c Change the GoToPage Named Action to select the contents of the pageNumber input, rather than just focusing the element
When clicking on the `pageNumber` input, or when using the keyboard shortcut <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>G</kbd>, the element isn't just focused but its contents is actually *selected* so that the user doesn't need to clear the input before entering a new `pageNumber`.
However, the `GoToPage` named action is only using `focus`, so let's change this to be consistent.

The following document can be used for testing: http://www2.informatik.uni-freiburg.de/~frank/ENG/beamer/example/Beamer-class-example1.pdf#zoom=page-fit

[screeenshot]
2016-09-01 13:48:49 +02:00
Jeremy Press
1ceeb4d17b added text enhancement regression tests 2016-08-31 09:54:52 -07:00
Jeremy Press
6faa84abdb Continuing fairexpand #6663
1. Expanding divs to improve text selection. (Yury)
2. Adding enhanceTextSelection as an option.
3. Moving feature functionality from text_layer_builder.js to text_layer.js.
4. Added expandTextDivs method to only load expanded divs on first click, and only show on subsequent clicks
2016-08-31 09:54:52 -07:00
Jonas Jenwald
3ac23200ba Add a reduced test-case for issue 7406
The PDF file contains an image that we're allowed to use, since it's just the PDF.js logo.
The logo image was simply inverted (so that it requires a /Decode entry in the image dictionary that triggers the use of `jpg.js` instead of the browser), converted to JPEG, and finally edited by hand to change the order of the DQT/SOF{n} markers.
2016-08-31 18:42:07 +02:00
Jonas Jenwald
1bbc694ac3 Assign the quantizationTables after parsing the entire JPEG image, to prevent issues when the DQT (Define Quantization Tables) marker is encountered after SOF{n} (Start of Frame) markers (issue 7406)
This is a tentative patch that fixes 7406.
2016-08-31 18:42:05 +02:00
Tim van der Meij
23b13d368e Merge pull request #7579 from Snuffleupagus/updateUIToolbar-correctly-disable-zoom-buttons
Ensure that the zoom buttons are disabled correctly if the `scale` is smaller/larger than `MIN_SCALE/MAX_SCALE` in `PDFViewerApplication._updateUIToolbar`
2016-08-31 15:33:49 +02:00
Jonas Jenwald
f3b7fa091d Ensure that the zoom buttons are disabled correctly if the scale is smaller/larger than MIN_SCALE/MAX_SCALE in PDFViewerApplication._updateUIToolbar
In the `zoom{In, Out}` functions in `PDFViewerApplication`, we prevent the zoom value from becoming smaller/larger than `MIN_SCALE/MAX_SCALE`.
However, if the user sets the zoom level through the hash parameter the zoom buttons might not be correctly disabled; try http://mozilla.github.io/pdf.js/web/viewer.html#zoom=10.

Note that this issue has been present since "forever", but given that the solution is so simple I think that we should just fix this. (I'm also fixing a stupid typo I previously made in the JSDoc comment.)
2016-08-31 13:28:38 +02:00
Yury Delendik
ffa99397ad Merge pull request #7387 from Snuffleupagus/issue-5808
Attempt to ignore multiple identical Tf (setFont) commands in `PartialEvaluator_getTextContent` (issue 5808)
2016-08-30 15:21:41 -05:00
Tim van der Meij
a75b020423 Merge pull request #7575 from timvandermeij/update-l10n
Update translations
2016-08-28 16:20:21 +02:00
Tim van der Meij
d1ca5c11ec Update translations 2016-08-28 16:14:03 +02:00
Tim van der Meij
b0a0bef267 Merge pull request #7440 from Snuffleupagus/bug-874482
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
2016-08-28 15:47:40 +02:00
Tim van der Meij
f520616e00 Merge pull request #7570 from Snuffleupagus/issue-7569
Create a fallback annotation `id` for entries in `Annots` dictionaries that are not indirect objects (issue 7569)
2016-08-28 00:23:59 +02:00
Tim van der Meij
fb6fde9d00 Merge pull request #7574 from timvandermeij/unit-test-font-cleanup
Remove unused globals from fonts unit test file
2016-08-27 23:29:06 +02:00
Tim van der Meij
b81d661556 Remove unused globals from fonts unit test file 2016-08-27 23:20:03 +02:00
Tim van der Meij
d944c320b4 Merge pull request #7540 from Snuffleupagus/ProblematicCharRanges-unit-test
Add a unit-test to check that `ProblematicCharRanges` contains valid entries
2016-08-27 23:14:55 +02:00
Tim van der Meij
8aa9b790be Merge pull request #7573 from Snuffleupagus/mobile-viewer-async-open/close
[mobile-viewer] Add an async `close` method to the example, and change `open` to also be async (issue 7571)
2016-08-27 22:45:42 +02:00
Jonas Jenwald
65e9ff68aa [mobile-viewer] Add an async close method to the example, and change open to also be async (issue 7571)
Since the `mobile-viewer` example is based on the old FirefoxOS/B2G PDF viewer, it didn't need to have the same kind of `open/close` methods as the default viewer.
However, now that it has been re-purposed as a simple `mobile-viewer` example, it seems like a good idea to ensure that it has proper asynchronous `open/close` methods.

Fixes 7571.
2016-08-27 12:57:34 +02:00
Jonas Jenwald
088ce6c009 Add a unit-test to check that ProblematicCharRanges contains valid entries
When adding new entries to `ProblematicCharRanges`, you have to be careful to not make any mistakes since that could cause glyph mapping issues.
Currently the existing reference tests should probably help catch any errors, but based on experience I think that having a unit-test which specifically checks `ProblematicCharRanges` would be both helpful and timesaving when modifying/reviewing changes to this code.

Hence this patch which adds a function (and unit-test) that is used to validate the entries in `ProblematicCharRanges`, and also checks that we don't accidentally add more character ranges than the Private Use Area can actually contain.
The way that the validation code, and thus the unit-test, is implemented also means that we have an easy way to tell how much of the Private Use Area is potentially utilized by re-mapped characters.
2016-08-27 11:56:00 +02:00
Jonas Jenwald
78889646c8 Create a fallback annotation id for entries in Annots dictionaries that are not indirect objects (issue 7569)
According to the PDF specification, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#page=86, entries in `Annots` dictionaries should be indirect objects, but obviously there're PDF generators that ignore this.

Fixes 7569.
2016-08-27 10:56:16 +02:00
Brendan Dahl
0e20d44fef Merge pull request #7563 from brendandahl/upstream-l10n
Upstream l10n changes from Bug 1259859.
2016-08-24 09:49:17 -07:00
Brendan Dahl
8cf32cde6c Upstream l10n changes from Bug 1259859. 2016-08-24 09:47:36 -07:00
Jonas Jenwald
e5baf7ec36 Merge pull request #7330 from Snuffleupagus/issue-7188
Try to prevent `CanvasGraphics_getSinglePixelWidth` from intermittently returning incorrect values in Firefox (issue 7188)
2016-08-22 20:36:54 +02:00
Jonas Jenwald
5379749d4b Try to prevent CanvasGraphics_getSinglePixelWidth from intermittently returning incorrect values in Firefox (issue 7188)
Fixes 7188.
2016-08-22 20:00:24 +02:00