Commit Graph

7940 Commits

Author SHA1 Message Date
Rob Wu
b627a1a0d9 Add --testfilter (-t) flag to run a specific test 2015-07-18 17:31:56 +02: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
Jonas Jenwald
7df78f997e Slightly more efficient getDestination
For named destinations that are contained in a `Dict`, as opposed to a `NameTree`, we currently iterate through the *entire* dictionary just to fetch *one* destination.
This code appears to simply have been copy-pasted from the `get destinations` method, but in its current form it's quite unnecessary/inefficient since can just get the required destination directly instead.
2015-07-08 18:31:51 +02:00
Jonas Jenwald
940bedf75f Add a unit-test that attempts to fetch a non-existent named destination
Doing this helped uncover an issue with the `getDestination` implementation.
Currently if a named destination doesn't exist, the method (in `obj.js`) may return `undefined` which leads to the promise being stuck in a pending state.
*Note:* returning `null` for this case is consistent with other methods, e.g. `getOutline` and `getAttachments`.
2015-07-07 22:05:08 +02:00
Jonas Jenwald
1c0115a7e4 Remove the currentScaleValue getter from PDFViewerApplication (issue 6158)
*The next step towards fixing issue 6158.*

We can just as well access `pdfViewer.currentScaleValue` directly in `PDFViewerApplication`, instead of having a helper function which just acts as a wrapper for it.
2015-07-07 09:17:05 +02:00
Yury Delendik
eb2ad11571 Merge pull request #5918 from Snuffleupagus/remove-fallback-cpow
[Firefox] Replace the CPOW with asynchronous messages for the Fallback bar
2015-07-06 21:31:48 -05:00
Tim van der Meij
31976b9b44 Merge pull request #6181 from Rob--W/test-downloadOnly
Add --downloadOnly flag to test.js
2015-07-06 23:30:01 +02:00
Yury Delendik
8e59528e60 Merge pull request #6175 from Rob--W/font-loading-promises
fontLoadPromises -> fontsToLoad
2015-07-06 16:00:47 -05:00
Jonas Jenwald
e5b7258586 Merge pull request #6180 from timvandermeij/border-regression
Do not draw a border if neither a Border nor a BS entry is present
2015-07-06 18:04:57 +02:00
Jonas Jenwald
5aaf18db12 Merge pull request #6169 from yurydelendik/rm-playpreview
Bug 1179262 - Remove PlayPreview registration from PDF Viewer.
2015-07-06 17:32:29 +02:00
Rob Wu
f9dd7318f7 fontLoadPromises -> fontsToLoad
fontsToLoad is always an empty array, Promise.all should wait for
fontLoadPromises instead of fontsToLoad.
2015-07-06 17:31:42 +02:00
Jonas Jenwald
d0c071a40d Prevent re-rendering of pages because of rounding errors when computing the scale value
Currently if the zoom level is reset multiple times in a row, i.e. by pressing <kbd>Ctrl</kbd>+<kbd>0</kbd>, the pages can be re-rendered each time even though their size shouldn't change. Whether this happens can depend on the size of the viewer, but documents with pages in landscape mode seem to be very susceptible to this. (An example is: https://wiki.mozilla.org/images/5/55/MobileOpportunity.pdf.)
This can also effect documents with pages in portrait mode, when they are displayed in Presentation Mode.

The reason for this unnecessary re-rendering is that due to limited numerical precision, the new scale value may change in *only* the last decimal place.
2015-07-06 17:22:03 +02:00
Rob Wu
c7a5da332c Add --downloadOnly flag to test.js 2015-07-06 17:17:11 +02:00
Jonas Jenwald
d9975ea778 Move annotation related CSS rules from pdf_viewer.css to its own file
This is similar to the already existing, separate, CSS file used for the `textLayer`, and it's necessary in order for the `pageviewer` components example to actually show annotations correctly.
2015-07-06 16:37:33 +02:00
Jonas Jenwald
4364b37e55 Simplify the SimpleLinkService and use it to pass in a linkService instance in DefaultAnnotationsLayerFactory
Considering that most methods of `SimpleLinkService` are complete stubs, or practically "useless" considering what they return, we can actually simplify it even more.

*Note:* This depends on the previous patch, that did a small amount of refactoring of `PDFViewer_scrollPageIntoView`, since `PDFViewer.linkService.page` is no longer accessed.

----------

Currently the `pageviewer` components example doesn't work correctly (an error is printed in the console), since no `linkService` is present when the `AnnotationsLayerBuilder` is created.

*Note:* Given that this uses the `SimpleLinkService`, clicking on e.g. internal links won't actually do anything. However, given that internal links (and similar features) are pretty much useless when only *one* page is loaded the `pageviewer` example, I don't think that really matters.
Also, using the complete `PDFLinkService` would require a `PDFViewer` instance. That would significantly complicate the example, thus making it both less clear and less self contained.
2015-07-06 16:34:55 +02:00
Jonas Jenwald
ac3233bfa4 Use "private" properties in PDFViewer_scrollPageIntoView
Currently in `PDFViewer_scrollPageIntoView`, we're accessing a number of properties in an indirect and overly complicated way. In particular, using `this.linkService.page` is a *very* roundabout way to access `this.currentPageNumber`.

The reason for this appears to be entirely historical, since prior to PR 5361 the code was placed in `PDFPageView` (or `PageView` as it was called at the time).
2015-07-06 16:33:01 +02:00
Jonas Jenwald
9e08737f4e Merge pull request #6178 from timvandermeij/remove-interactive-annotation
Remove InteractiveAnnotation abstraction
2015-07-06 16:29:09 +02:00
Tim van der Meij
3a6eed6248 Do not draw a border if neither a Border nor a BS entry is present
Fixes #6179.
2015-07-06 14:48:59 +02:00
Tim van der Meij
5aa1d9fdfd Remove InteractiveAnnotation abstraction
This became obsolete in bdeca30fbf. All it does is call the Annotation contructor and add hasHtml. This patch lets the Link and Text annotations directly extend the Annotation class and add hasHtml themselves.

This patch also removes an unused global.
2015-07-06 11:58:26 +02:00
Tim van der Meij
56e3a66c16 Merge pull request #6177 from Snuffleupagus/pdfPresentationMode-pdfViewer
Pass in a `PDFViewer` instance to `PDFPresentationMode` and use it to eliminate all references to `PDFViewerApplication`
2015-07-06 11:19:31 +02:00
Jonas Jenwald
6b2810f1f0 Pass in a PDFViewer instance to PDFPresentationMode and use it to eliminate all references to PDFViewerApplication
This patch is the the first step towards to addressing issue 6158, which will be done by refactoring the code for setting/getting the current scale in `viewer.js`.
2015-07-06 09:49:51 +02:00
Jonas Jenwald
7a6a3f10ad Merge pull request #6176 from Rob--W/crx-ignore-embed-6174
[CRX] Ignore PDFs from responses to POST requests
2015-07-05 13:15:52 +02:00
Rob Wu
4367dd5130 [CRX] Ignore PDFs from responses to POST requests
As explained in
https://github.com/mozilla/pdf.js/issues/6174#issuecomment-118502802.

To verify that this patch works:
1. Build the Chrome extension (node make chromium)
2. Load the Chrome extension (at chrome://extensions)
3. Visit https://robwu.nl/pdfjs/issue6174/.
4. Verify that PDF.js is not used to load the PDF. Either Chrome's
   default PDF Viewer is used, or the PDF is offered as a file download.
2015-07-05 01:01:03 +02:00
Tim van der Meij
93bc8ea64c Merge pull request #6173 from Snuffleupagus/pr-6171-tests
Add more reduced test-cases for PR 6171
2015-07-04 21:06:04 +02:00
Yury Delendik
3ffed9d083 Merge pull request #6170 from Rob--W/zoom-at-cursor
Zoom relative to cursor position via mouse wheel
2015-07-03 13:14:11 -05:00
Jonas Jenwald
60fc462bd6 Add more reduced test-cases for PR 6171 2015-07-03 13:14:41 +02:00
Jonas Jenwald
e3b348162d Merge pull request #6171 from yurydelendik/usepua
Adds more characters to the PUA range
2015-07-03 11:22:06 +02:00
Yury Delendik
0787182e6f Adds more characters to the PUA range 2015-07-02 16:47:47 -05:00
Rob Wu
2932f7c676 Zoom relative to cursor position via mouse wheel
Before this patch, zooming in/out via the scroll wheel caused the page
to be zoomed relative to the upper-left corner of the page, i.e. the
upper-left corner of the page stays at a fixed position.

After this patch, the page is zoomed relative to the cursor position,
i.e. after zooming in/out, the part under the cursor 'has not moved'.

This only applies when the page does not fit in the viewport, because
pages smaller than the viewpoer are always centered.
2015-07-02 23:20:37 +02:00
Yury Delendik
0b5330781c Bug 1179262 - Remove PlayPreview registration from PDF Viewer. 2015-07-02 12:59:17 -05:00
Yury Delendik
9ad6af4a3f Merge pull request #5531 from Rob--W/moz-chunked-only-moz
Feature-test moz-chunked-arraybuffer before use
2015-07-02 09:08:08 -05:00