Commit Graph

7972 Commits

Author SHA1 Message Date
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
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
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
Tim van der Meij
9f5abd70d7 Merge pull request #6199 from Snuffleupagus/viewer-setInitialView-simpler-pageNumber-reset
Simplify the code that resets the value of the `pageNumber` element in `PDFViewerApplication.setInitialView`
2015-07-12 18:54:09 +02:00
Jonas Jenwald
dde3e4aaaf Merge pull request #6197 from Rob--W/issue6108
Improve robustness of stream parser (invalid length)
2015-07-12 17:26:31 +02:00
Jonas Jenwald
2608757620 Simplify the code that resets the value of the pageNumber element in PDFViewerApplication.setInitialView
After the creation of `PDFViewer`, its `_resetView` method takes care of resetting, among other things, the page number property. Hence we don't need to set `pdfViewer.currentPageNumber = 1;` here any more, and the comment is no longer accurate either.
2015-07-12 16:24:07 +02:00
Tim van der Meij
535b7c236e Merge pull request #6110 from Snuffleupagus/issue-6056
Refactor viewer code to fix issues with the "pageviewer" components example (issue 6056)
2015-07-12 16:02:37 +02:00
Rob Wu
5cce7377af Use taskkill to stop the browser on Windows 2015-07-11 20:22:53 +02:00
Rob Wu
e211c25f06 Improve robustness of stream parser (invalid length)
When the parser finds a stream, it retrieves the Length from the stream
dictionary and advances the lexer to the offset as specified in Length.
If this Length is incorrect, the lexer could end up anywhere.

When the lexer gets in an invalid state, it could throw errors. For
example, in issue 6108, the lexer ends up inside the stream data. This
stream has the ASCIIHexDecode filter, so all characters are made up from
ASCII characters, and the lexer interprets it as a command token. Tokens
cannot be longer than 127 bytes, so eventually 128 bytes are consumed
and the lexer throws "Command token too long" error.

Another possible error is "Illegal character: 41" when the lexer happens
to end up at a ')' due to the length mismatch.

These problems are solved by catching lexer errors and recovering the
parser via the existing stream length detection branch.
2015-07-11 20:12:49 +02:00
Tim van der Meij
7d4303b7c4 Merge pull request #6194 from Rob--W/recover-mode-start-offset
Subtract start offset for xrefs in recovery mode
2015-07-11 17:22:08 +02:00
Tim van der Meij
d091263b3b Merge pull request #6195 from Snuffleupagus/viewer-remove-updateScaleControls
Remove `PDFViewerApplication.updateScaleControls` (issue 6158)
2015-07-11 16:35:35 +02:00
Jonas Jenwald
5cb15874fa Remove PDFViewerApplication.updateScaleControls (issue 6158)
*With this patch we're getting very close to fixing 6158.*

The only use-case for `PDFViewerApplication.updateScaleControls` is to try and avoid calling `selectScaleOption` from the `scalechange` event handler in viewer.js.
This will *only* happen when the user has manually changed the scale by using the `<select>` dropdown, which means that in reality this is just a micro optimization. Furthermore, `selectScaleOption` is only skipped for the "named" scale values (e.g. `auto`, `page-actual`, `page-fit`, `page-width`), thus further reducing the value of this code.

Also, since we're updating the scale `<select>` dropdown from an event handler, we're currently depending on the event being dispatched (and handled) completely before the next `scalechange` event. Relying on the execution order of the code in this way, even though it currently works, seems unfortunate since it *could* potentially cause the internal scale value and the UI from getting out of sync.
2015-07-11 11:25:32 +02:00
Rob Wu
fd29bb0c57 Subtract start offset for xrefs in recovery mode
Xref offsets are relative to the start of the PDF data, not to the start
of the PDF file. This is clear if you look at the other code:

- In the XRef's readXRefTable and processXRefTable methods of XRef, the
  offset of a xref entry is set to the bytes as given by a PDF file.
  These values are always relative to the start of the PDF file (%PDF-).

- The XRef's readXRef method adds the start offset of the stream to
  Xref entry's offset: "stream.pos = startXRef + stream.start".
  Clearly, this line assumes that the entry offset excludes the start
  offset.

However, when the PDF is parsed in recovery mode, the xref table is
filled with entries whose offset is relative to the start of the stream
rather than the PDF file. This is incorrect, and the fix is to subtract
the start offset of the stream from the entry's byte offset.

The manually created PDF file serves as a regression test. It is a valid
PDF, except:
- The integer to point to the start of the xref table and the %%EOF
  trailer are missing. This will activate recovery mode in PDF.js
- Some junk was added before the start of the PDF file. This exposes the
  bad offset bug.
2015-07-10 23:33:10 +02:00
Tim van der Meij
6c1906fd53 Merge pull request #6193 from Rob--W/long-name-is-warning-not-error
Issue a warning instead of an error for long Names
2015-07-10 22:58:08 +02:00
Tim van der Meij
5af49f8bbb Merge pull request #6166 from Snuffleupagus/issue-5801-2
Add a supplemental glyph map for non-embedded ArialBlack fonts (issue 5801)
2015-07-10 22:29:50 +02:00
Tim van der Meij
c9b6b690ec Merge pull request #6192 from Snuffleupagus/viewer-resize-update-scale
Refactor the 'resize' event handler in viewer.js (issue 6158)
2015-07-10 21:43:06 +02:00
Rob Wu
456ad438d8 Issue a warning instead of an error for long Names
The PDF specification (cited below) specifies a maximum length of a name
in bytes as a minimal architectural limit. This means that PDF *writers*
should not create names that exceed 127 bytes.

It does not forbid PDF *readers* to accept such names though. These
names are only used internally to link PDF objects to other objects. For
these use cases, the lengths of the names do not really matter. Hence I
have changed the implementation to not treat long names as errors, but
warnings.

> (7.3.5) The length of a name shall be subject to an implementation
> limit; see Annex C.
>
> (Annex C.2) Table C.1 describes the minimum architectural limits that
> should be accommodated by conforming readers running on 32-bit
> machines. Because conforming readers may be subject to these limits,
> conforming writers producing PDF files should remain within them.
>
> (Table C.1) name 127 "Maximum length of a name, in bytes."

http://adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf
2015-07-10 16:10:24 +02:00
Jonas Jenwald
35ee1e1b0a Refactor the 'resize' event handler in viewer.js (issue 6158)
*This is the next step towards fixing 6158.*

This patch removes the dependency on the state of the scale `<select>` dropdown from the `resize` event handler, and instead uses the (in `PDFViewer`) stored `currentScaleValue`.
I believe that the way this code is currently written is purely for historical reasons, since originally *only* the numerical scale was stored internally (hence there was no other way to access the scale value).
However, since we now store the scale value, we should use it instead of quering the DOM. This helps ensure that the internally stored scale value is always accurately displayed in the UI (which should be good since, after the creation of `PDFViewer`, the `<select>` DOM element is now updated by an event handler).
2015-07-10 11:50:54 +02:00
Tim van der Meij
ccfafea20b Merge pull request #6182 from Snuffleupagus/remove-PDFViewerApplication-get-currentScaleValue
Remove the `currentScaleValue` getter from `PDFViewerApplication` (issue 6158)
2015-07-09 15:48:08 +02:00
Tim van der Meij
ba38454865 Merge pull request #5460 from Snuffleupagus/limit-internal-scale-values-precision
Prevent re-rendering of pages because of rounding errors when computing the scale value
2015-07-09 14:19:58 +02:00