Commit Graph

7989 Commits

Author SHA1 Message Date
Jonas Jenwald
55bc98a8b0 Rename PatternType to ShadingType to avoid confusion
The current name is somewhat confusing, since the specification calls it `ShadingType`, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G7.4044105 and http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G7.3882826.

The real problem, however, is that there is actually another property called `PatternType`, which makes the current code very confusing, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G7.1850929.

Since `ShadingType` is only relevant for shading patterns (i.e. `PatternType === 2`), and *not* for tiling patterns (i.e `PatternType === 1`), this patch should help reduce confusion when reading the code.
2015-07-30 20:03:45 +02:00
Jonas Jenwald
e876dd8123 Merge pull request #6273 from timvandermeij/annotation-factory
Refactor annotation code to use a factory
2015-07-29 16:29:34 +02:00
Tim van der Meij
4f920ad100 Refactor annotation code to use a factory
Currently, `src/core/core.js` uses the `fromRef` method on an `Annotation` object to obtain the right annotation type object (such as `LinkAnnotation` or `TextAnnotation`). That method in turn uses a method `getConstructor` to find out which annotation type object must be returned.

Aside from the fact that there is currently a lot of code to achieve this, these methods should not be part of the base `Annotation` class at all. Creation of annotation object should be done by a factory (as also recommended by @yurydelendik at https://github.com/mozilla/pdf.js/pull/5218#issuecomment-52779659) that handles finding out the correct annotation type object and returning it. This patch implements this separation of concerns.

Doing this allows us to also simplify the code quite a bit and to make it more readable. Additionally, we are now able to get rid of the hardcoded array of supported annotation types. The factory takes care of checking the annotation types and falls back to returning the base annotation type (and issuing a warning, which the current code also does not do well) when an annotation type is unsupported.

I have manually tested this commit with 20 test PDFs with different annotation types, such as /Link, /Text, /Widget, /FileAttachment and /FreeText. All render identically before and after the patch, and unsupported annotation types are now properly indicated with a warning in the console.
2015-07-29 00:31:51 +02:00
Tim van der Meij
d08895d659 Merge pull request #6236 from Rob--W/print-javascript-action
Detect scripted auto-print requests
2015-07-25 19:42:31 +02:00
Tim van der Meij
0c15f8a777 Merge pull request #6268 from Rob--W/text-layer-optimize-access
Optimize text layer: Avoid unneeded .textContent access
2015-07-25 16:33:17 +02:00
Rob Wu
47f2c14723 Optimize text layer: Avoid unneeded .textContent
Built-in DOM properties are slower than plain JS properties.
A few lines before, textContent is assigned as follows:
  textDiv.textContent = geom.str;
So replacing textDiv.textContent.length with geom.str.length slightly
improves performance without side effects.
2015-07-25 10:55:00 +02:00
Tim van der Meij
61f9052233 Merge pull request #6240 from Snuffleupagus/issue-6238
Check if the `Decode` entry is non-default when deciding if JPEG images are natively supported/decodable (issue 6238)
2015-07-23 22:52:49 +02:00
Jonas Jenwald
94d9a27a67 Update l10n files 2015-07-23 16:59:58 +02:00
Jonas Jenwald
45810e0866 Merge pull request #6257 from timvandermeij/viewer-cleanup
Remove unused globals and updateViewarea function from viewer.js
2015-07-23 16:32:11 +02:00
Tim van der Meij
9c510bd6e6 Remove unused globals and updateViewarea function from viewer.js 2015-07-23 16:02:39 +02:00
Tim van der Meij
d162dba85e Merge pull request #6256 from Snuffleupagus/bug-1186842
Ensure that the viewer always receives focus when the HOME/END keys are pressed (bug 1186842)
2015-07-23 14:46:32 +02:00
Tim van der Meij
21053460d7 Merge pull request #6254 from Snuffleupagus/issue-6253
Prevent documents from intermittently opening with the zoom level set to 1% (issue 6253)
2015-07-23 14:09:56 +02:00
Jonas Jenwald
8275dff1b1 Reduce code duplication in the 'keydown' event handler in viewer.js, by re-factoring the code which ensures that the viewerContainer is focused 2015-07-23 13:01:55 +02:00
Jonas Jenwald
d5232f5b5a Ensure that the viewer always receives focus when the HOME/END keys are pressed (bug 1186842)
It appears that I broke this with PR 4941.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1186842.
2015-07-23 12:04:49 +02:00
Jonas Jenwald
fa53cd6ca3 Use DEFAULT_SCALE_VALUE as default when fetching the zoom parameter from PDFViewerApplication.store (i.e. ViewHistory)
Since the zoom value should be in percent, using `PDFViewer.currentScale` will be wrong by a factor of 100, potentially causing the zoom level of the document to become wrong on load.
2015-07-22 23:58:30 +02:00
Jonas Jenwald
299d05eaa5 Prevent documents from intermittently opening with the zoom level set to 1% (issue 6253)
*This fixes a regression from PR 6192.*

Under some circumstances, the `resize` event handler in `viewer.js` is fired before the scale has been set. This can lead to PDF documents being rendered at the wrong zoom level when they are opened.
It seems that a way to reliably trigger this is to, using the Firefox addon, open a PDF file that triggers the `fallback` bar, in a new background tab (i.e. middle clicking on a link, or use the context menu).

Prior to PR 6192, we checked the selected option in the `scaleSelect` dropdown instead. Since `pageAutoOption` is selected by default in `viewer.html`, this should explain why the issue wasn't visible previously.
2015-07-22 23:45:33 +02:00
Jonas Jenwald
385e2e5aaf Check if the Decode entry is non-default when deciding if JPEG images are natively supported/decodable (issue 6238)
Tentatively fixes 6238.
2015-07-21 12:23:07 +02:00
Jonas Jenwald
862342189f Merge pull request #6239 from timvandermeij/annotation-rectangle
Refactor annotation rectangle code and add unit tests
2015-07-20 23:25:49 +02:00
Tim van der Meij
980aa10e04 Refactor annotation rectangle code and add unit tests
This patch refactors the code responsible for setting the annotation's rectangle. Its goal is to:

- Actually check that the input array is actually an array, and if so, that it contains exactly four elements.
- Only call `normalizeRect` if the input array is valid, i.e., we do not call it for the default rectangle anymore.

Unit tests are provided just like with the other patches in this series.
2015-07-20 22:01:47 +02:00
Tim van der Meij
c42613b911 Merge pull request #6235 from Snuffleupagus/move-custom-scale-handling
Move handling of the 'custom' scale value from pdf_viewer.js to viewer.js
2015-07-20 20:53:07 +02:00
Rob Wu
c676ecb5a0 Detect scripted auto-print requests
Fixes #6106

To avoid future regressions, two new unit tests were added:
1. A new PDF based on the report from #6106, which contains an
   OpenAction of type JavaScript and a string "this.print({...}".
2. An existing PDF from https://bugzil.la/1001080 (from #4698).

Although it does not matter, since we don't execute the JavaScript code,
I have also changed "print(true)" to "print({})" since the print method
takes an object (not a boolean). See "Printing PDF documents", page 62:
http://adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_developer_guide.pdf
2015-07-20 18:25:02 +02:00
Jonas Jenwald
93d82e21d5 Move handling of the 'custom' scale value from pdf_viewer.js to viewer.js
The special handling of the 'custom' scale value is only relevant for the `scaleSelect` dropdown in the standard viewer, hence I think that it should be placed in `viewer.js` instead.
2015-07-19 20:02:47 +02:00
Jonas Jenwald
d3e90cf825 Merge pull request #6232 from timvandermeij/annotations-data-passing
Simplify annotation data passing
2015-07-19 18:11:47 +02:00
Jonas Jenwald
a58393fca3 Merge pull request #6189 from Rob--W/improved-build-tools
Improved build tools (preprocessor & postprocessor)
2015-07-19 18:06:33 +02:00
Rob Wu
f8af4d6567 Fix preprocessor: nesting, error & tests
Features / bug fixes in the preprocessor:

- Add word boundary after regex for preprocessor token matching.
  Previously, when you mistakenly used "#ifdef" instead of "#if", the
  line would be parsed as a preprocessor directive (because "#ifdef"
  starts with "#if"), but without condition (because "def" does not
  start with a space). Consequently, the condition would always be false
  and anything between "#ifdef" and "#endif" would not be included.

- Add validation and error reporting everywhere, to aid debugging.

- Support nested comments (by accounting for the whole stack of
  conditions, instead of only the current one).

- Add #elif preprocessor command. Could be used as follows:
  //#if !FEATURE_ENABLED
  //#error FEATURE_ENABLED must be set
  //#endif

- Add #error preprocessor command.

- Add end-of-line word boundary after "-->" in the comment trimmer.
  Otherwise the pattern would also match "-->" in the middle of a line,
  and incorrectly convert something like "while(i-->0)" to "while(i0)".

Code health:

- Add unit tests for the preprocessor (run external/builder/test.js).

- Fix broken link to MDN (resolved to DXR).

- Refactor to use STATE_* names instead of magic numbers (the original
  meaning of the numbers is preserved, with one exception).

- State 3 has been split in two states, to distinguish between being in
  an #if and #else. This is needed to ensure that #else cannot be
  started without an #if.
2015-07-19 14:47:28 +02:00
Rob Wu
1d4e450a79 make.js: Less greedy comment stripping
The previous regex was too greedy, it stripped a significant amount of
code when I put another file after core/murmurhash3.js. This was caused
by the fact that the license header in murmurhash3.js does not contain
"Mozilla Foundation", so the regex continued to match until my new file
(which had the standard license header containing "Mozilla Foundation").
2015-07-19 14:47:28 +02:00
Rob Wu
8ba73cb4de Improve getWorkerSrcFiles (builder.js)
It took a while to figure out why adding comments in worker_loader.js
caused the build to fail, because getWorkerSrcFiles did not print an
error message when it failed to parse the file. These issues have been
resolved as follows:

- Leading comments are stripped.
- The trailing comma is removed from the array.
- Errors are detected and useful error messages are printed.
2015-07-19 14:47:28 +02:00
Tim van der Meij
995c5ba205 Simplify annotation data passing 2015-07-19 14:02:49 +02:00
Tim van der Meij
dbd2ef034f Merge pull request #6196 from Rob--W/run-specific-test
Add --testfilter and -t flags
2015-07-19 13:55:07 +02:00
Rob Wu
b627a1a0d9 Add --testfilter (-t) flag to run a specific test 2015-07-18 17:31:56 +02:00
Tim van der Meij
91ab010829 Merge pull request #6201 from Rob--W/crx-dont-force-no-download
[CRX] Respect download requests in main frame
2015-07-18 15:05:32 +02:00
Jonas Jenwald
7065c1b8e9 Merge pull request #6215 from timvandermeij/annotation-border-fixes
More cleanup regarding annotation border styles
2015-07-17 22:42:10 +02:00
Tim van der Meij
465611a2ff More cleanup regarding annotation border styles 2015-07-17 21:51:24 +02:00
Tim van der Meij
4b6e2724ae Merge pull request #6220 from Snuffleupagus/issue-6218
Ignore double negative in `Lexer_getNumber` (issue 6218)
2015-07-17 21:29:40 +02:00
Tim van der Meij
6dfe19dcf7 Merge pull request #6226 from Snuffleupagus/fonttools
Update fonttools location and version (issue 6223)
2015-07-17 21:03:38 +02:00
Jonas Jenwald
d5772fa3ca Merge pull request #6221 from Thunderforge/{find-toolbar-checkbox-keyboard-accessibility}
Fixing find toolbar checkboxes not being accessible through keyboard
2015-07-17 13:24:08 +02:00
Jonas Jenwald
d68eb153d3 Update fonttools location and version (issue 6223) 2015-07-17 12:51:09 +02:00
Tim van der Meij
b35cbaa32c Merge pull request #6157 from Snuffleupagus/components-update-on-setScale-and-pagesRotation
Make sure that the document is rendered on zooming and rotation for `PDFViewer` instances using the `defaultRenderingQueue`
2015-07-16 23:06:32 +02:00
Will Herrmann
cbc715ed0f Fixing find toolbar checkboxes not being accessible through keyboard navigation 2015-07-16 13:23:14 -05:00
Jonas Jenwald
c718d1ab10 Ignore double negative in Lexer_getNumber (issue 6218)
Basic mathematics would suggest that a double negative should always become positive, but it appears that Adobe Reader simply ignores that case. Hence I think that it makes sense for us to do the same.

Fixes 6218.
2015-07-16 12:11:49 +02:00
Jonas Jenwald
cf6d40f348 Merge pull request #6214 from timvandermeij/annotation-color
Refactor annotation color handling and add unit tests
2015-07-16 09:38:54 +02:00
Tim van der Meij
a2e9845093 Refactor annotation color handling and add unit tests 2015-07-15 18:49:19 +02:00
Tim van der Meij
2817f008c3 Merge pull request #6208 from Snuffleupagus/issue-6204
Fetch all indirect objects (i.e. `Ref`s) in `NameTree_getAll` and `NameTree_get` (issue 6204)
2015-07-14 22:03:03 +02:00
Tim van der Meij
76d225dd3b Merge pull request #6207 from Snuffleupagus/viewer-remove-setScale
Remove `PDFViewerApplication.setScale` and further simplify the `scalechange` event handler (issue 6158)
2015-07-14 21:22:58 +02:00
Jonas Jenwald
28f40b1b58 Fetch all indirect objects (i.e. Refs) in NameTree_getAll and NameTree_get (issue 6204) 2015-07-14 10:56:56 +02:00
Jonas Jenwald
0c08113e39 Remove PDFViewerApplication.setScale and further simplify the scalechange event handler (issue 6158)
This finally fixes 6158.
2015-07-14 10:06:59 +02:00
Brendan Dahl
367794f0c7 Merge pull request #4990 from fkaelberer/refactor_chunked_stream
Minor refactoring of chunked_stream.js
2015-07-13 16:51:35 -07:00
Rob Wu
62cf6536a2 Tests: Resolve -b to full path in webbrowser.js
This allows us to simply use "node test.js -b=firefox" instead of having
to type out the full path.
2015-07-14 00:20:07 +02:00
Tim van der Meij
1416a1b521 Merge pull request #6187 from Snuffleupagus/more-efficient-getDestination
A couple of improvements of `getDestination` (unit-test included)
2015-07-13 23:03:13 +02:00
Brendan Dahl
e498bbce90 Merge pull request #6198 from Rob--W/windows-taskkill
Use taskkill to stop the browser on Windows in tests
2015-07-13 13:30:03 -07:00