Commit Graph

9057 Commits

Author SHA1 Message Date
Yury Delendik
160b176109 Adding "proper" message port for fake worker. 2016-09-12 11:17:10 +02:00
Tim van der Meij
6b05cfd1b8 Merge pull request #7622 from timvandermeij/interactive-forms-text
Text widget annotations: implement maximum length and text alignment
2016-09-11 21:42:22 +02:00
Tim van der Meij
be485f59ab Text widget annotations: implement maximum length and text alignment
Moreover, we refactor the code a bit to extract code that is shared
between the two branches and we only apply text alignment (and create
the array) when it is actually defined, since it's optional and left is
already the default.
2016-09-11 20:49:00 +02:00
Tim van der Meij
bf6f5d1cc9 Merge pull request #7621 from Snuffleupagus/more-symbolic-fonts-without-included-encoding-tests
Add a couple more, mostly `text`, reference tests for non-embedded symbolic fonts without included encoding information
2016-09-11 20:44:30 +02:00
Jonas Jenwald
ae2cc9119b Add a couple more, mostly text, reference tests for non-embedded symbolic fonts without included encoding information
I've started to look into how we can fix issue 7580, but quickly became worried that fixing it could easily mean that we'd trade one fixed PDF file for a multitude of broken ones.

Hence I started going through the history of the code that choose the fallback encoding, and noticed that it has been changed a number of times over the years to deal with various cases of weirdness/errors in non-embedded fonts.
To my relief it turned out that almost all the PRs, please see a possibly incomplete [list here], that changed this code actually included `eq` test-cases.

However, in one case it appears that a PR missed to add a test-case. Furthermore since the fallback encoding may also be the only source for creating a `toUnicode` map, changing the encoding could possibly regress only the text-selection despite a PDF file still rendering correctly.
Therefore, this PR adds one new `eq` test, and also a number of additional `text` tests for PDF files already present in the test-suite.

Note that it's obviously possible that there's a certain overlap between the added tests, but I'd be *a whole lot* more concerned with causing regressions.
2016-09-11 16:38:39 +02:00
Jonas Jenwald
1fae435e88 Merge pull request #7546 from Snuffleupagus/issue-7544
Don't duplicate the first entry in the `charCodeToGlyphId` map for CIDFontType2 fonts with a `CIDToGIDMap` that already mapped the first entry to a non-zero `glyphId` (issue 7544)
2016-09-11 15:20:36 +02:00
Jonas Jenwald
0b75f63c03 Don't duplicate the first entry in the charCodeToGlyphId map for CIDFontType2 fonts with a CIDToGIDMap that already mapped the first entry to a non-zero glyphId (issue 7544)
Fixes 7544.
2016-09-09 22:33:41 +02:00
Tim van der Meij
b112f9f9f4 Merge pull request #7600 from Snuffleupagus/issue-7598
Check that Type1C fonts does not actually contain OpenType font files (issue 7598)
2016-09-09 22:02:58 +02:00
Tim van der Meij
22c7ff494a Merge pull request #7609 from Snuffleupagus/enhanceTextSelection-pref-hack
Add a `enhanceTextSelection` preference
2016-09-09 16:38:45 +02:00
Tim van der Meij
23a0264a15 Merge pull request #7619 from Snuffleupagus/SecondaryToolbar-setMaxHeight-events
Only update the `max-height` of the `SecondaryToolbar` when it's actually visible
2016-09-09 16:07:51 +02:00
Jonas Jenwald
be8a69a52c Ensure that we provide the source parameter when dispatching the button click events in SecondaryToolbar (PR 7313 follow-up) 2016-09-09 08:16:10 +02:00
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