2014-09-13 11:27:45 +09:00
|
|
|
/* Copyright 2014 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 02:34:27 +09:00
|
|
|
(function (root, factory) {
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
define('pdfjs-web/pdf_viewer', ['exports', 'pdfjs-web/ui_utils',
|
|
|
|
'pdfjs-web/pdf_page_view', 'pdfjs-web/pdf_rendering_queue',
|
|
|
|
'pdfjs-web/text_layer_builder', 'pdfjs-web/annotation_layer_builder',
|
2016-04-26 07:57:15 +09:00
|
|
|
'pdfjs-web/pdf_link_service', 'pdfjs-web/dom_events', 'pdfjs-web/pdfjs'],
|
|
|
|
factory);
|
2016-04-09 02:34:27 +09:00
|
|
|
} else if (typeof exports !== 'undefined') {
|
|
|
|
factory(exports, require('./ui_utils.js'), require('./pdf_page_view.js'),
|
|
|
|
require('./pdf_rendering_queue.js'), require('./text_layer_builder.js'),
|
|
|
|
require('./annotation_layer_builder.js'),
|
2016-04-26 07:57:15 +09:00
|
|
|
require('./pdf_link_service.js'), require('./dom_events.js'),
|
|
|
|
require('./pdfjs.js'));
|
2016-04-09 02:34:27 +09:00
|
|
|
} else {
|
|
|
|
factory((root.pdfjsWebPDFViewer = {}), root.pdfjsWebUIUtils,
|
|
|
|
root.pdfjsWebPDFPageView, root.pdfjsWebPDFRenderingQueue,
|
|
|
|
root.pdfjsWebTextLayerBuilder, root.pdfjsWebAnnotationLayerBuilder,
|
2016-04-26 07:57:15 +09:00
|
|
|
root.pdfjsWebPDFLinkService, root.pdfjsWebDOMEvents, root.pdfjsWebPDFJS);
|
2016-04-09 02:34:27 +09:00
|
|
|
}
|
|
|
|
}(this, function (exports, uiUtils, pdfPageView, pdfRenderingQueue,
|
2016-04-09 04:15:48 +09:00
|
|
|
textLayerBuilder, annotationLayerBuilder, pdfLinkService,
|
2016-04-26 07:57:15 +09:00
|
|
|
domEvents, pdfjsLib) {
|
2016-04-09 02:34:27 +09:00
|
|
|
|
|
|
|
var UNKNOWN_SCALE = uiUtils.UNKNOWN_SCALE;
|
|
|
|
var SCROLLBAR_PADDING = uiUtils.SCROLLBAR_PADDING;
|
|
|
|
var VERTICAL_PADDING = uiUtils.VERTICAL_PADDING;
|
|
|
|
var MAX_AUTO_SCALE = uiUtils.MAX_AUTO_SCALE;
|
|
|
|
var CSS_UNITS = uiUtils.CSS_UNITS;
|
|
|
|
var DEFAULT_SCALE = uiUtils.DEFAULT_SCALE;
|
|
|
|
var DEFAULT_SCALE_VALUE = uiUtils.DEFAULT_SCALE_VALUE;
|
2016-11-19 04:03:49 +09:00
|
|
|
var RendererType = uiUtils.RendererType;
|
2016-04-09 02:34:27 +09:00
|
|
|
var scrollIntoView = uiUtils.scrollIntoView;
|
|
|
|
var watchScroll = uiUtils.watchScroll;
|
|
|
|
var getVisibleElements = uiUtils.getVisibleElements;
|
|
|
|
var PDFPageView = pdfPageView.PDFPageView;
|
|
|
|
var RenderingStates = pdfRenderingQueue.RenderingStates;
|
|
|
|
var PDFRenderingQueue = pdfRenderingQueue.PDFRenderingQueue;
|
|
|
|
var TextLayerBuilder = textLayerBuilder.TextLayerBuilder;
|
|
|
|
var AnnotationLayerBuilder = annotationLayerBuilder.AnnotationLayerBuilder;
|
|
|
|
var SimpleLinkService = pdfLinkService.SimpleLinkService;
|
|
|
|
|
2014-09-16 02:37:03 +09:00
|
|
|
var PresentationModeState = {
|
|
|
|
UNKNOWN: 0,
|
|
|
|
NORMAL: 1,
|
|
|
|
CHANGING: 2,
|
|
|
|
FULLSCREEN: 3,
|
|
|
|
};
|
|
|
|
|
2014-09-30 01:32:45 +09:00
|
|
|
var DEFAULT_CACHE_SIZE = 10;
|
2014-09-16 05:46:01 +09:00
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} PDFViewerOptions
|
|
|
|
* @property {HTMLDivElement} container - The container for the viewer element.
|
|
|
|
* @property {HTMLDivElement} viewer - (optional) The viewer element.
|
2016-04-26 07:57:15 +09:00
|
|
|
* @property {EventBus} eventBus - The application event bus.
|
2014-09-21 02:21:49 +09:00
|
|
|
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
2016-02-15 04:44:00 +09:00
|
|
|
* @property {DownloadManager} downloadManager - (optional) The download
|
|
|
|
* manager component.
|
2014-09-21 02:21:49 +09:00
|
|
|
* @property {PDFRenderingQueue} renderingQueue - (optional) The rendering
|
|
|
|
* queue object.
|
2015-03-12 04:36:01 +09:00
|
|
|
* @property {boolean} removePageBorders - (optional) Removes the border shadow
|
|
|
|
* around the pages. The default is false.
|
2016-08-17 08:06:35 +09:00
|
|
|
* @property {boolean} enhanceTextSelection - (optional) Enables the improved
|
|
|
|
* text selection behaviour. The default is `false`.
|
2016-09-18 02:44:25 +09:00
|
|
|
* @property {boolean} renderInteractiveForms - (optional) Enables rendering of
|
|
|
|
* interactive form elements. The default is `false`.
|
2016-11-19 04:03:49 +09:00
|
|
|
* @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'.
|
2014-09-21 02:21:49 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple viewer control to display PDF content/pages.
|
|
|
|
* @class
|
|
|
|
* @implements {IRenderableView}
|
|
|
|
*/
|
2014-09-13 11:27:45 +09:00
|
|
|
var PDFViewer = (function pdfViewer() {
|
2014-09-30 01:32:45 +09:00
|
|
|
function PDFPageViewBuffer(size) {
|
|
|
|
var data = [];
|
|
|
|
this.push = function cachePush(view) {
|
|
|
|
var i = data.indexOf(view);
|
|
|
|
if (i >= 0) {
|
|
|
|
data.splice(i, 1);
|
|
|
|
}
|
|
|
|
data.push(view);
|
|
|
|
if (data.length > size) {
|
|
|
|
data.shift().destroy();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.resize = function (newSize) {
|
|
|
|
size = newSize;
|
|
|
|
while (data.length > size) {
|
|
|
|
data.shift().destroy();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-10-30 21:04:01 +09:00
|
|
|
function isSameScale(oldScale, newScale) {
|
|
|
|
if (newScale === oldScale) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Math.abs(newScale - oldScale) < 1e-15) {
|
|
|
|
// Prevent unnecessary re-rendering of all pages when the scale
|
|
|
|
// changes only because of limited numerical precision.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
|
|
|
* @constructs PDFViewer
|
|
|
|
* @param {PDFViewerOptions} options
|
|
|
|
*/
|
2014-09-13 11:27:45 +09:00
|
|
|
function PDFViewer(options) {
|
|
|
|
this.container = options.container;
|
2014-09-16 05:46:01 +09:00
|
|
|
this.viewer = options.viewer || options.container.firstElementChild;
|
2016-04-26 07:57:15 +09:00
|
|
|
this.eventBus = options.eventBus || domEvents.getGlobalEventBus();
|
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-06-12 05:20:04 +09:00
|
|
|
this.linkService = options.linkService || new SimpleLinkService();
|
2016-02-15 04:44:00 +09:00
|
|
|
this.downloadManager = options.downloadManager || null;
|
2015-03-12 04:36:01 +09:00
|
|
|
this.removePageBorders = options.removePageBorders || false;
|
2016-08-17 08:06:35 +09:00
|
|
|
this.enhanceTextSelection = options.enhanceTextSelection || false;
|
2016-09-18 02:44:25 +09:00
|
|
|
this.renderInteractiveForms = options.renderInteractiveForms || false;
|
2016-11-19 04:03:49 +09:00
|
|
|
this.renderer = options.renderer || RendererType.CANVAS;
|
2014-09-13 11:27:45 +09:00
|
|
|
|
2014-09-16 05:46:01 +09:00
|
|
|
this.defaultRenderingQueue = !options.renderingQueue;
|
|
|
|
if (this.defaultRenderingQueue) {
|
|
|
|
// Custom rendering queue is not specified, using default one
|
|
|
|
this.renderingQueue = new PDFRenderingQueue();
|
|
|
|
this.renderingQueue.setViewer(this);
|
|
|
|
} else {
|
|
|
|
this.renderingQueue = options.renderingQueue;
|
|
|
|
}
|
|
|
|
|
2014-09-13 11:27:45 +09:00
|
|
|
this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this));
|
2014-09-16 02:37:03 +09:00
|
|
|
this.presentationModeState = PresentationModeState.UNKNOWN;
|
2014-09-21 02:15:18 +09:00
|
|
|
this._resetView();
|
2015-03-12 04:36:01 +09:00
|
|
|
|
|
|
|
if (this.removePageBorders) {
|
|
|
|
this.viewer.classList.add('removePageBorders');
|
|
|
|
}
|
2014-09-13 11:27:45 +09:00
|
|
|
}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
PDFViewer.prototype = /** @lends PDFViewer.prototype */{
|
2014-09-13 11:27:45 +09:00
|
|
|
get pagesCount() {
|
2015-03-20 21:01:14 +09:00
|
|
|
return this._pages.length;
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
|
|
|
|
2014-09-15 23:49:24 +09:00
|
|
|
getPageView: function (index) {
|
2015-03-20 21:01:14 +09:00
|
|
|
return this._pages[index];
|
2014-09-15 23:49:24 +09:00
|
|
|
},
|
|
|
|
|
2016-10-07 06:46:30 +09:00
|
|
|
/**
|
|
|
|
* @returns {boolean} true if all {PDFPageView} objects are initialized.
|
|
|
|
*/
|
|
|
|
get pageViewsReady() {
|
|
|
|
return this._pageViewsReady;
|
|
|
|
},
|
|
|
|
|
2016-07-14 19:04:16 +09:00
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2014-09-21 02:15:18 +09:00
|
|
|
get currentPageNumber() {
|
|
|
|
return this._currentPageNumber;
|
|
|
|
},
|
|
|
|
|
2016-07-14 19:04:16 +09:00
|
|
|
/**
|
|
|
|
* @param {number} val - The page number.
|
|
|
|
*/
|
2014-09-21 02:15:18 +09:00
|
|
|
set currentPageNumber(val) {
|
Remove the `previousPageNumber` parameter from the `pagechanging`/pagechange` events, and stop dispatching the events if the input is out of bounds
This patch attempts to cleanup a couple of things:
- Remove the `previousPageNumber` paramater. Prior to PR 7289, when the events were dispatched even when the active page didn't change, it made sense to be able to detect that in an event listener. However, now that's no longer the case, and furthermore other similar events (e.g. `scalechanging`/`scalechange`) don't include information about the previous state.
- Don't dispatch the events when the value passed to `set currentPageNumber` is out of bounds. Given that the active page doesn't change in this case, again similar to PR 7289, I don't think that the events should actually be dispatched in this case.
- Ensure that the value passed to `set currentPageNumber` is actually an integer, to avoid any issues (note how e.g. `set currentScale` has similar validation code).
Given that these changes could possibly affect the PDF.js `mochitest` integration tests in mozilla-central, in particular https://dxr.mozilla.org/mozilla-central/source/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js, I ran the tests locally with this patch applied to ensure that they still pass.
2016-07-22 22:32:14 +09:00
|
|
|
if ((val | 0) !== val) { // Ensure that `val` is an integer.
|
|
|
|
throw new Error('Invalid page number.');
|
|
|
|
}
|
2014-09-21 02:15:18 +09:00
|
|
|
if (!this.pdfDocument) {
|
|
|
|
this._currentPageNumber = val;
|
|
|
|
return;
|
|
|
|
}
|
2016-05-05 01:06:07 +09:00
|
|
|
// The intent can be to just reset a scroll position and/or scale.
|
2016-07-14 19:04:16 +09:00
|
|
|
this._setCurrentPageNumber(val, /* resetCurrentPageView = */ true);
|
2016-05-05 01:06:07 +09:00
|
|
|
},
|
2014-09-21 02:15:18 +09:00
|
|
|
|
2016-07-14 19:04:16 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_setCurrentPageNumber:
|
2016-08-07 20:10:50 +09:00
|
|
|
function PDFViewer_setCurrentPageNumber(val, resetCurrentPageView) {
|
2016-05-05 01:06:07 +09:00
|
|
|
if (this._currentPageNumber === val) {
|
2016-07-14 19:04:16 +09:00
|
|
|
if (resetCurrentPageView) {
|
|
|
|
this._resetCurrentPageView();
|
|
|
|
}
|
2016-05-05 01:06:07 +09:00
|
|
|
return;
|
|
|
|
}
|
Remove the `previousPageNumber` parameter from the `pagechanging`/pagechange` events, and stop dispatching the events if the input is out of bounds
This patch attempts to cleanup a couple of things:
- Remove the `previousPageNumber` paramater. Prior to PR 7289, when the events were dispatched even when the active page didn't change, it made sense to be able to detect that in an event listener. However, now that's no longer the case, and furthermore other similar events (e.g. `scalechanging`/`scalechange`) don't include information about the previous state.
- Don't dispatch the events when the value passed to `set currentPageNumber` is out of bounds. Given that the active page doesn't change in this case, again similar to PR 7289, I don't think that the events should actually be dispatched in this case.
- Ensure that the value passed to `set currentPageNumber` is actually an integer, to avoid any issues (note how e.g. `set currentScale` has similar validation code).
Given that these changes could possibly affect the PDF.js `mochitest` integration tests in mozilla-central, in particular https://dxr.mozilla.org/mozilla-central/source/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js, I ran the tests locally with this patch applied to ensure that they still pass.
2016-07-22 22:32:14 +09:00
|
|
|
|
2014-09-13 11:27:45 +09:00
|
|
|
if (!(0 < val && val <= this.pagesCount)) {
|
2016-08-07 20:10:50 +09:00
|
|
|
console.error('PDFViewer_setCurrentPageNumber: "' + val +
|
|
|
|
'" is out of bounds.');
|
2014-09-13 11:27:45 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Remove the `previousPageNumber` parameter from the `pagechanging`/pagechange` events, and stop dispatching the events if the input is out of bounds
This patch attempts to cleanup a couple of things:
- Remove the `previousPageNumber` paramater. Prior to PR 7289, when the events were dispatched even when the active page didn't change, it made sense to be able to detect that in an event listener. However, now that's no longer the case, and furthermore other similar events (e.g. `scalechanging`/`scalechange`) don't include information about the previous state.
- Don't dispatch the events when the value passed to `set currentPageNumber` is out of bounds. Given that the active page doesn't change in this case, again similar to PR 7289, I don't think that the events should actually be dispatched in this case.
- Ensure that the value passed to `set currentPageNumber` is actually an integer, to avoid any issues (note how e.g. `set currentScale` has similar validation code).
Given that these changes could possibly affect the PDF.js `mochitest` integration tests in mozilla-central, in particular https://dxr.mozilla.org/mozilla-central/source/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js, I ran the tests locally with this patch applied to ensure that they still pass.
2016-07-22 22:32:14 +09:00
|
|
|
var arg = {
|
2016-04-26 07:57:15 +09:00
|
|
|
source: this,
|
|
|
|
pageNumber: val,
|
2016-01-23 21:56:56 +09:00
|
|
|
pageLabel: this._pageLabels && this._pageLabels[val - 1],
|
2016-04-30 00:05:04 +09:00
|
|
|
};
|
2014-09-21 02:15:18 +09:00
|
|
|
this._currentPageNumber = val;
|
2016-05-05 01:06:07 +09:00
|
|
|
this.eventBus.dispatch('pagechanging', arg);
|
2016-04-30 00:05:04 +09:00
|
|
|
this.eventBus.dispatch('pagechange', arg);
|
2016-07-14 19:04:16 +09:00
|
|
|
|
|
|
|
if (resetCurrentPageView) {
|
|
|
|
this._resetCurrentPageView();
|
|
|
|
}
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
|
|
|
|
2016-01-23 21:56:56 +09:00
|
|
|
/**
|
|
|
|
* @returns {string|null} Returns the current page label,
|
|
|
|
* or `null` if no page labels exist.
|
|
|
|
*/
|
|
|
|
get currentPageLabel() {
|
|
|
|
return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} val - The page label.
|
|
|
|
*/
|
|
|
|
set currentPageLabel(val) {
|
|
|
|
var pageNumber = val | 0; // Fallback page number.
|
|
|
|
if (this._pageLabels) {
|
|
|
|
var i = this._pageLabels.indexOf(val);
|
|
|
|
if (i >= 0) {
|
|
|
|
pageNumber = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.currentPageNumber = pageNumber;
|
|
|
|
},
|
|
|
|
|
2014-09-21 02:15:18 +09:00
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
get currentScale() {
|
2015-03-15 04:07:17 +09:00
|
|
|
return this._currentScale !== UNKNOWN_SCALE ? this._currentScale :
|
|
|
|
DEFAULT_SCALE;
|
2014-09-21 02:15:18 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} val - Scale of the pages in percents.
|
|
|
|
*/
|
|
|
|
set currentScale(val) {
|
Remove the `previousPageNumber` parameter from the `pagechanging`/pagechange` events, and stop dispatching the events if the input is out of bounds
This patch attempts to cleanup a couple of things:
- Remove the `previousPageNumber` paramater. Prior to PR 7289, when the events were dispatched even when the active page didn't change, it made sense to be able to detect that in an event listener. However, now that's no longer the case, and furthermore other similar events (e.g. `scalechanging`/`scalechange`) don't include information about the previous state.
- Don't dispatch the events when the value passed to `set currentPageNumber` is out of bounds. Given that the active page doesn't change in this case, again similar to PR 7289, I don't think that the events should actually be dispatched in this case.
- Ensure that the value passed to `set currentPageNumber` is actually an integer, to avoid any issues (note how e.g. `set currentScale` has similar validation code).
Given that these changes could possibly affect the PDF.js `mochitest` integration tests in mozilla-central, in particular https://dxr.mozilla.org/mozilla-central/source/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js, I ran the tests locally with this patch applied to ensure that they still pass.
2016-07-22 22:32:14 +09:00
|
|
|
if (isNaN(val)) {
|
2014-09-21 02:15:18 +09:00
|
|
|
throw new Error('Invalid numeric scale');
|
|
|
|
}
|
|
|
|
if (!this.pdfDocument) {
|
|
|
|
this._currentScale = val;
|
2015-03-15 04:07:17 +09:00
|
|
|
this._currentScaleValue = val !== UNKNOWN_SCALE ? val.toString() : null;
|
2014-09-21 02:15:18 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._setScale(val, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
get currentScaleValue() {
|
|
|
|
return this._currentScaleValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param val - The scale of the pages (in percent or predefined value).
|
|
|
|
*/
|
|
|
|
set currentScaleValue(val) {
|
|
|
|
if (!this.pdfDocument) {
|
|
|
|
this._currentScale = isNaN(val) ? UNKNOWN_SCALE : val;
|
2016-06-27 19:32:28 +09:00
|
|
|
this._currentScaleValue = val.toString();
|
2014-09-21 02:15:18 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._setScale(val, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
get pagesRotation() {
|
|
|
|
return this._pagesRotation;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} rotation - The rotation of the pages (0, 90, 180, 270).
|
|
|
|
*/
|
|
|
|
set pagesRotation(rotation) {
|
2016-08-01 22:31:16 +09:00
|
|
|
if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
|
|
|
|
throw new Error('Invalid pages rotation angle.');
|
|
|
|
}
|
2014-09-21 02:15:18 +09:00
|
|
|
this._pagesRotation = rotation;
|
|
|
|
|
2016-08-01 22:31:16 +09:00
|
|
|
if (!this.pdfDocument) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-20 21:01:14 +09:00
|
|
|
for (var i = 0, l = this._pages.length; i < l; i++) {
|
|
|
|
var pageView = this._pages[i];
|
|
|
|
pageView.update(pageView.scale, rotation);
|
2014-09-21 02:15:18 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
this._setScale(this._currentScaleValue, true);
|
2015-07-01 04:49:32 +09:00
|
|
|
|
|
|
|
if (this.defaultRenderingQueue) {
|
|
|
|
this.update();
|
|
|
|
}
|
2014-09-21 02:15:18 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param pdfDocument {PDFDocument}
|
|
|
|
*/
|
2014-09-15 23:49:24 +09:00
|
|
|
setDocument: function (pdfDocument) {
|
|
|
|
if (this.pdfDocument) {
|
2016-07-30 03:39:22 +09:00
|
|
|
this._cancelRendering();
|
2014-09-21 02:15:18 +09:00
|
|
|
this._resetView();
|
2014-09-15 23:49:24 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
this.pdfDocument = pdfDocument;
|
|
|
|
if (!pdfDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var pagesCount = pdfDocument.numPages;
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var resolvePagesPromise;
|
|
|
|
var pagesPromise = new Promise(function (resolve) {
|
|
|
|
resolvePagesPromise = resolve;
|
|
|
|
});
|
|
|
|
this.pagesPromise = pagesPromise;
|
|
|
|
pagesPromise.then(function () {
|
2016-10-07 06:46:30 +09:00
|
|
|
self._pageViewsReady = true;
|
2016-04-26 07:57:15 +09:00
|
|
|
self.eventBus.dispatch('pagesloaded', {
|
|
|
|
source: self,
|
2014-09-15 23:49:24 +09:00
|
|
|
pagesCount: pagesCount
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var isOnePageRenderedResolved = false;
|
|
|
|
var resolveOnePageRendered = null;
|
|
|
|
var onePageRendered = new Promise(function (resolve) {
|
|
|
|
resolveOnePageRendered = resolve;
|
|
|
|
});
|
|
|
|
this.onePageRendered = onePageRendered;
|
|
|
|
|
2014-09-30 01:32:45 +09:00
|
|
|
var bindOnAfterAndBeforeDraw = function (pageView) {
|
|
|
|
pageView.onBeforeDraw = function pdfViewLoadOnBeforeDraw() {
|
|
|
|
// Add the page to the buffer at the start of drawing. That way it can
|
|
|
|
// be evicted from the buffer and destroyed even if we pause its
|
|
|
|
// rendering.
|
|
|
|
self._buffer.push(this);
|
|
|
|
};
|
2014-09-15 23:49:24 +09:00
|
|
|
pageView.onAfterDraw = function pdfViewLoadOnAfterDraw() {
|
|
|
|
if (!isOnePageRenderedResolved) {
|
|
|
|
isOnePageRenderedResolved = true;
|
|
|
|
resolveOnePageRendered();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var firstPagePromise = pdfDocument.getPage(1);
|
|
|
|
this.firstPagePromise = firstPagePromise;
|
|
|
|
|
|
|
|
// Fetch a single page so we can get a viewport that will be the default
|
|
|
|
// viewport for all pages
|
|
|
|
return firstPagePromise.then(function(pdfPage) {
|
2015-03-15 04:07:17 +09:00
|
|
|
var scale = this.currentScale;
|
2014-09-15 23:49:24 +09:00
|
|
|
var viewport = pdfPage.getViewport(scale * CSS_UNITS);
|
|
|
|
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
2014-09-28 23:35:33 +09:00
|
|
|
var textLayerFactory = null;
|
2016-03-29 06:44:27 +09:00
|
|
|
if (!pdfjsLib.PDFJS.disableTextLayer) {
|
2014-09-28 23:35:33 +09:00
|
|
|
textLayerFactory = this;
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
var pageView = new PDFPageView({
|
|
|
|
container: this.viewer,
|
2016-04-26 07:57:15 +09:00
|
|
|
eventBus: this.eventBus,
|
2014-09-28 03:03:28 +09:00
|
|
|
id: pageNum,
|
|
|
|
scale: scale,
|
|
|
|
defaultViewport: viewport.clone(),
|
|
|
|
renderingQueue: this.renderingQueue,
|
2014-09-30 01:05:28 +09:00
|
|
|
textLayerFactory: textLayerFactory,
|
2016-08-17 08:06:35 +09:00
|
|
|
annotationLayerFactory: this,
|
|
|
|
enhanceTextSelection: this.enhanceTextSelection,
|
2016-09-18 02:44:25 +09:00
|
|
|
renderInteractiveForms: this.renderInteractiveForms,
|
2016-11-19 04:03:49 +09:00
|
|
|
renderer: this.renderer,
|
2014-09-28 03:03:28 +09:00
|
|
|
});
|
2014-09-30 01:32:45 +09:00
|
|
|
bindOnAfterAndBeforeDraw(pageView);
|
2015-03-20 21:01:14 +09:00
|
|
|
this._pages.push(pageView);
|
2014-09-15 23:49:24 +09:00
|
|
|
}
|
|
|
|
|
2015-04-28 00:25:32 +09:00
|
|
|
var linkService = this.linkService;
|
|
|
|
|
2014-09-15 23:49:24 +09:00
|
|
|
// Fetch all the pages since the viewport is needed before printing
|
|
|
|
// starts to create the correct size canvas. Wait until one page is
|
|
|
|
// rendered so we don't tie up too many resources early on.
|
|
|
|
onePageRendered.then(function () {
|
2016-03-29 06:44:27 +09:00
|
|
|
if (!pdfjsLib.PDFJS.disableAutoFetch) {
|
2014-09-15 23:49:24 +09:00
|
|
|
var getPagesLeft = pagesCount;
|
|
|
|
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
|
|
|
pdfDocument.getPage(pageNum).then(function (pageNum, pdfPage) {
|
2015-03-20 21:01:14 +09:00
|
|
|
var pageView = self._pages[pageNum - 1];
|
2014-09-15 23:49:24 +09:00
|
|
|
if (!pageView.pdfPage) {
|
|
|
|
pageView.setPdfPage(pdfPage);
|
|
|
|
}
|
2015-04-28 00:25:32 +09:00
|
|
|
linkService.cachePageRef(pageNum, pdfPage.ref);
|
2014-09-15 23:49:24 +09:00
|
|
|
getPagesLeft--;
|
|
|
|
if (!getPagesLeft) {
|
|
|
|
resolvePagesPromise();
|
|
|
|
}
|
|
|
|
}.bind(null, pageNum));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// XXX: Printing is semi-broken with auto fetch disabled.
|
|
|
|
resolvePagesPromise();
|
|
|
|
}
|
|
|
|
});
|
2014-09-16 05:46:01 +09:00
|
|
|
|
2016-04-26 07:57:15 +09:00
|
|
|
self.eventBus.dispatch('pagesinit', {source: self});
|
2014-10-01 02:31:58 +09:00
|
|
|
|
2014-09-16 05:46:01 +09:00
|
|
|
if (this.defaultRenderingQueue) {
|
2014-10-01 02:31:58 +09:00
|
|
|
this.update();
|
2014-09-16 05:46:01 +09:00
|
|
|
}
|
2015-02-11 21:05:04 +09:00
|
|
|
|
|
|
|
if (this.findController) {
|
|
|
|
this.findController.resolveFirstPage();
|
|
|
|
}
|
2014-09-15 23:49:24 +09:00
|
|
|
}.bind(this));
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
|
|
|
|
2016-01-23 21:56:56 +09:00
|
|
|
/**
|
|
|
|
* @param {Array|null} labels
|
|
|
|
*/
|
|
|
|
setPageLabels: function PDFViewer_setPageLabels(labels) {
|
|
|
|
if (!this.pdfDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!labels) {
|
|
|
|
this._pageLabels = null;
|
|
|
|
} else if (!(labels instanceof Array &&
|
|
|
|
this.pdfDocument.numPages === labels.length)) {
|
|
|
|
this._pageLabels = null;
|
|
|
|
console.error('PDFViewer_setPageLabels: Invalid page labels.');
|
|
|
|
} else {
|
|
|
|
this._pageLabels = labels;
|
|
|
|
}
|
2016-01-27 22:27:01 +09:00
|
|
|
// Update all the `PDFPageView` instances.
|
|
|
|
for (var i = 0, ii = this._pages.length; i < ii; i++) {
|
|
|
|
var pageView = this._pages[i];
|
|
|
|
var label = this._pageLabels && this._pageLabels[i];
|
|
|
|
pageView.setPageLabel(label);
|
|
|
|
}
|
2016-01-23 21:56:56 +09:00
|
|
|
},
|
|
|
|
|
2014-09-21 02:15:18 +09:00
|
|
|
_resetView: function () {
|
2015-03-20 21:01:14 +09:00
|
|
|
this._pages = [];
|
2014-09-21 02:15:18 +09:00
|
|
|
this._currentPageNumber = 1;
|
|
|
|
this._currentScale = UNKNOWN_SCALE;
|
|
|
|
this._currentScaleValue = null;
|
2016-01-23 21:56:56 +09:00
|
|
|
this._pageLabels = null;
|
2014-09-30 01:32:45 +09:00
|
|
|
this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
|
2015-05-08 18:48:07 +09:00
|
|
|
this._location = null;
|
2014-09-21 02:15:18 +09:00
|
|
|
this._pagesRotation = 0;
|
2014-09-29 22:11:46 +09:00
|
|
|
this._pagesRequests = [];
|
2016-10-07 06:46:30 +09:00
|
|
|
this._pageViewsReady = false;
|
2014-09-15 23:49:24 +09:00
|
|
|
|
2016-07-30 03:39:22 +09:00
|
|
|
// Remove the pages from the DOM.
|
|
|
|
this.viewer.textContent = '';
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
|
|
|
|
2015-07-01 04:49:32 +09:00
|
|
|
_scrollUpdate: function PDFViewer_scrollUpdate() {
|
2014-09-13 11:27:45 +09:00
|
|
|
if (this.pagesCount === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.update();
|
2015-03-20 21:01:14 +09:00
|
|
|
for (var i = 0, ii = this._pages.length; i < ii; i++) {
|
|
|
|
this._pages[i].updatePosition();
|
2014-12-18 05:12:51 +09:00
|
|
|
}
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
|
|
|
|
2015-02-20 01:30:47 +09:00
|
|
|
_setScaleDispatchEvent: function pdfViewer_setScaleDispatchEvent(
|
|
|
|
newScale, newValue, preset) {
|
2016-04-30 00:05:04 +09:00
|
|
|
var arg = {
|
2016-04-26 07:57:15 +09:00
|
|
|
source: this,
|
|
|
|
scale: newScale,
|
|
|
|
presetValue: preset ? newValue : undefined
|
2016-04-30 00:05:04 +09:00
|
|
|
};
|
|
|
|
this.eventBus.dispatch('scalechanging', arg);
|
|
|
|
this.eventBus.dispatch('scalechange', arg);
|
2015-02-20 01:30:47 +09:00
|
|
|
},
|
|
|
|
|
2014-09-13 11:27:45 +09:00
|
|
|
_setScaleUpdatePages: function pdfViewer_setScaleUpdatePages(
|
2014-09-21 02:15:18 +09:00
|
|
|
newScale, newValue, noScroll, preset) {
|
2016-06-27 19:32:28 +09:00
|
|
|
this._currentScaleValue = newValue.toString();
|
2014-10-30 21:04:01 +09:00
|
|
|
|
|
|
|
if (isSameScale(this._currentScale, newScale)) {
|
2015-02-20 01:30:47 +09:00
|
|
|
if (preset) {
|
|
|
|
this._setScaleDispatchEvent(newScale, newValue, true);
|
|
|
|
}
|
2014-09-13 11:27:45 +09:00
|
|
|
return;
|
|
|
|
}
|
2015-02-20 01:30:47 +09:00
|
|
|
|
2015-03-20 21:01:14 +09:00
|
|
|
for (var i = 0, ii = this._pages.length; i < ii; i++) {
|
|
|
|
this._pages[i].update(newScale);
|
2014-09-13 11:27:45 +09:00
|
|
|
}
|
2014-09-21 02:15:18 +09:00
|
|
|
this._currentScale = newScale;
|
2014-09-13 11:27:45 +09:00
|
|
|
|
|
|
|
if (!noScroll) {
|
2014-09-21 02:15:18 +09:00
|
|
|
var page = this._currentPageNumber, dest;
|
2016-03-29 06:44:27 +09:00
|
|
|
if (this._location && !pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom &&
|
2015-01-29 21:37:49 +09:00
|
|
|
!(this.isInPresentationMode || this.isChangingPresentationMode)) {
|
2015-05-08 18:48:07 +09:00
|
|
|
page = this._location.pageNumber;
|
|
|
|
dest = [null, { name: 'XYZ' }, this._location.left,
|
|
|
|
this._location.top, null];
|
2014-09-13 11:27:45 +09:00
|
|
|
}
|
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.
However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.
Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-06-20 19:30:05 +09:00
|
|
|
this.scrollPageIntoView({
|
|
|
|
pageNumber: page,
|
|
|
|
destArray: dest,
|
|
|
|
allowNegativeOffset: true,
|
|
|
|
});
|
2014-09-13 11:27:45 +09:00
|
|
|
}
|
|
|
|
|
2015-02-20 01:30:47 +09:00
|
|
|
this._setScaleDispatchEvent(newScale, newValue, preset);
|
2015-07-01 04:49:32 +09:00
|
|
|
|
|
|
|
if (this.defaultRenderingQueue) {
|
|
|
|
this.update();
|
|
|
|
}
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
|
|
|
|
2016-08-07 20:10:50 +09:00
|
|
|
_setScale: function PDFViewer_setScale(value, noScroll) {
|
2014-09-13 11:27:45 +09:00
|
|
|
var scale = parseFloat(value);
|
|
|
|
|
|
|
|
if (scale > 0) {
|
2014-09-21 02:15:18 +09:00
|
|
|
this._setScaleUpdatePages(scale, value, noScroll, false);
|
2014-09-13 11:27:45 +09:00
|
|
|
} else {
|
2015-03-20 21:01:14 +09:00
|
|
|
var currentPage = this._pages[this._currentPageNumber - 1];
|
2014-09-13 11:27:45 +09:00
|
|
|
if (!currentPage) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-29 21:37:49 +09:00
|
|
|
var hPadding = (this.isInPresentationMode || this.removePageBorders) ?
|
2015-03-12 04:36:01 +09:00
|
|
|
0 : SCROLLBAR_PADDING;
|
2015-01-29 21:37:49 +09:00
|
|
|
var vPadding = (this.isInPresentationMode || this.removePageBorders) ?
|
2015-03-12 04:36:01 +09:00
|
|
|
0 : VERTICAL_PADDING;
|
2014-09-13 11:27:45 +09:00
|
|
|
var pageWidthScale = (this.container.clientWidth - hPadding) /
|
|
|
|
currentPage.width * currentPage.scale;
|
|
|
|
var pageHeightScale = (this.container.clientHeight - vPadding) /
|
|
|
|
currentPage.height * currentPage.scale;
|
|
|
|
switch (value) {
|
|
|
|
case 'page-actual':
|
|
|
|
scale = 1;
|
|
|
|
break;
|
|
|
|
case 'page-width':
|
|
|
|
scale = pageWidthScale;
|
|
|
|
break;
|
|
|
|
case 'page-height':
|
|
|
|
scale = pageHeightScale;
|
|
|
|
break;
|
|
|
|
case 'page-fit':
|
|
|
|
scale = Math.min(pageWidthScale, pageHeightScale);
|
|
|
|
break;
|
|
|
|
case 'auto':
|
|
|
|
var isLandscape = (currentPage.width > currentPage.height);
|
2014-10-12 09:25:35 +09:00
|
|
|
// For pages in landscape mode, fit the page height to the viewer
|
|
|
|
// *unless* the page would thus become too wide to fit horizontally.
|
|
|
|
var horizontalScale = isLandscape ?
|
|
|
|
Math.min(pageHeightScale, pageWidthScale) : pageWidthScale;
|
2014-09-13 11:27:45 +09:00
|
|
|
scale = Math.min(MAX_AUTO_SCALE, horizontalScale);
|
|
|
|
break;
|
|
|
|
default:
|
2016-08-07 20:10:50 +09:00
|
|
|
console.error('PDFViewer_setScale: "' + value +
|
|
|
|
'" is an unknown zoom value.');
|
2014-09-13 11:27:45 +09:00
|
|
|
return;
|
|
|
|
}
|
2014-09-21 02:15:18 +09:00
|
|
|
this._setScaleUpdatePages(scale, value, noScroll, true);
|
2014-09-13 11:27:45 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-05 01:06:07 +09:00
|
|
|
/**
|
|
|
|
* Refreshes page view: scrolls to the current page and updates the scale.
|
2016-07-14 19:04:16 +09:00
|
|
|
* @private
|
2016-05-05 01:06:07 +09:00
|
|
|
*/
|
|
|
|
_resetCurrentPageView: function () {
|
|
|
|
if (this.isInPresentationMode) {
|
|
|
|
// Fixes the case when PDF has different page sizes.
|
|
|
|
this._setScale(this._currentScaleValue, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
var pageView = this._pages[this._currentPageNumber - 1];
|
|
|
|
scrollIntoView(pageView.div);
|
|
|
|
},
|
|
|
|
|
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.
However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.
Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-06-20 19:30:05 +09:00
|
|
|
/**
|
|
|
|
* @typedef ScrollPageIntoViewParameters
|
2016-10-17 20:04:55 +09:00
|
|
|
* @property {number} pageNumber - The page number.
|
|
|
|
* @property {Array} destArray - (optional) The original PDF destination
|
|
|
|
* array, in the format: <page-ref> </XYZ|/FitXXX> <args..>
|
|
|
|
* @property {boolean} allowNegativeOffset - (optional) Allow negative page
|
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.
However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.
Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-06-20 19:30:05 +09:00
|
|
|
* offsets. The default value is `false`.
|
|
|
|
*/
|
|
|
|
|
2014-09-30 21:13:46 +09:00
|
|
|
/**
|
|
|
|
* Scrolls page into view.
|
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.
However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.
Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-06-20 19:30:05 +09:00
|
|
|
* @param {ScrollPageIntoViewParameters} params
|
2014-09-30 21:13:46 +09:00
|
|
|
*/
|
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.
However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.
Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-06-20 19:30:05 +09:00
|
|
|
scrollPageIntoView: function PDFViewer_scrollPageIntoView(params) {
|
2015-09-14 07:42:53 +09:00
|
|
|
if (!this.pdfDocument) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-15 00:57:53 +09:00
|
|
|
if ((typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) &&
|
|
|
|
(arguments.length > 1 || typeof params === 'number')) {
|
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.
However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.
Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-06-20 19:30:05 +09:00
|
|
|
console.warn('Call of scrollPageIntoView() with obsolete signature.');
|
|
|
|
var paramObj = {};
|
|
|
|
if (typeof params === 'number') {
|
|
|
|
paramObj.pageNumber = params; // pageNumber argument was found.
|
|
|
|
}
|
|
|
|
if (arguments[1] instanceof Array) {
|
|
|
|
paramObj.destArray = arguments[1]; // destArray argument was found.
|
|
|
|
}
|
|
|
|
params = paramObj;
|
|
|
|
}
|
|
|
|
var pageNumber = params.pageNumber || 0;
|
|
|
|
var dest = params.destArray || null;
|
|
|
|
var allowNegativeOffset = params.allowNegativeOffset || false;
|
2015-11-24 00:57:43 +09:00
|
|
|
|
2016-05-05 01:06:07 +09:00
|
|
|
if (this.isInPresentationMode || !dest) {
|
2016-07-14 19:04:16 +09:00
|
|
|
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView */ true);
|
2014-09-30 21:13:46 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-05 01:06:07 +09:00
|
|
|
var pageView = this._pages[pageNumber - 1];
|
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.
However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.
Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-06-20 19:30:05 +09:00
|
|
|
if (!pageView) {
|
|
|
|
console.error('PDFViewer_scrollPageIntoView: ' +
|
|
|
|
'Invalid "pageNumber" parameter.');
|
|
|
|
return;
|
|
|
|
}
|
2014-09-30 21:13:46 +09:00
|
|
|
var x = 0, y = 0;
|
|
|
|
var width = 0, height = 0, widthScale, heightScale;
|
|
|
|
var changeOrientation = (pageView.rotation % 180 === 0 ? false : true);
|
|
|
|
var pageWidth = (changeOrientation ? pageView.height : pageView.width) /
|
|
|
|
pageView.scale / CSS_UNITS;
|
|
|
|
var pageHeight = (changeOrientation ? pageView.width : pageView.height) /
|
|
|
|
pageView.scale / CSS_UNITS;
|
|
|
|
var scale = 0;
|
|
|
|
switch (dest[1].name) {
|
|
|
|
case 'XYZ':
|
|
|
|
x = dest[2];
|
|
|
|
y = dest[3];
|
|
|
|
scale = dest[4];
|
|
|
|
// If x and/or y coordinates are not supplied, default to
|
|
|
|
// _top_ left of the page (not the obvious bottom left,
|
|
|
|
// since aligning the bottom of the intended page with the
|
|
|
|
// top of the window is rarely helpful).
|
|
|
|
x = x !== null ? x : 0;
|
|
|
|
y = y !== null ? y : pageHeight;
|
|
|
|
break;
|
|
|
|
case 'Fit':
|
|
|
|
case 'FitB':
|
|
|
|
scale = 'page-fit';
|
|
|
|
break;
|
|
|
|
case 'FitH':
|
|
|
|
case 'FitBH':
|
|
|
|
y = dest[2];
|
|
|
|
scale = 'page-width';
|
2015-11-10 19:13:44 +09:00
|
|
|
// According to the PDF spec, section 12.3.2.2, a `null` value in the
|
|
|
|
// parameter should maintain the position relative to the new page.
|
|
|
|
if (y === null && this._location) {
|
|
|
|
x = this._location.left;
|
|
|
|
y = this._location.top;
|
|
|
|
}
|
2014-09-30 21:13:46 +09:00
|
|
|
break;
|
|
|
|
case 'FitV':
|
|
|
|
case 'FitBV':
|
|
|
|
x = dest[2];
|
|
|
|
width = pageWidth;
|
|
|
|
height = pageHeight;
|
|
|
|
scale = 'page-height';
|
|
|
|
break;
|
|
|
|
case 'FitR':
|
|
|
|
x = dest[2];
|
|
|
|
y = dest[3];
|
|
|
|
width = dest[4] - x;
|
|
|
|
height = dest[5] - y;
|
2015-03-12 04:36:01 +09:00
|
|
|
var hPadding = this.removePageBorders ? 0 : SCROLLBAR_PADDING;
|
|
|
|
var vPadding = this.removePageBorders ? 0 : VERTICAL_PADDING;
|
|
|
|
|
2015-06-12 05:01:05 +09:00
|
|
|
widthScale = (this.container.clientWidth - hPadding) /
|
2014-09-30 21:13:46 +09:00
|
|
|
width / CSS_UNITS;
|
2015-06-12 05:01:05 +09:00
|
|
|
heightScale = (this.container.clientHeight - vPadding) /
|
2014-09-30 21:13:46 +09:00
|
|
|
height / CSS_UNITS;
|
|
|
|
scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
|
|
|
|
break;
|
|
|
|
default:
|
[api-minor] Let `LinkAnnotation`/`PDFLinkService_getDestinationHash` return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.
Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.
With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.
*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.
- First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.
- Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.
- Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".
---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-15 19:12:47 +09:00
|
|
|
console.error('PDFViewer_scrollPageIntoView: \'' + dest[1].name +
|
|
|
|
'\' is not a valid destination type.');
|
2014-09-30 21:13:46 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-15 04:07:17 +09:00
|
|
|
if (scale && scale !== this._currentScale) {
|
2014-09-30 21:13:46 +09:00
|
|
|
this.currentScaleValue = scale;
|
2015-03-15 04:07:17 +09:00
|
|
|
} else if (this._currentScale === UNKNOWN_SCALE) {
|
|
|
|
this.currentScaleValue = DEFAULT_SCALE_VALUE;
|
2014-09-30 21:13:46 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (scale === 'page-fit' && !dest[4]) {
|
2014-09-28 03:03:28 +09:00
|
|
|
scrollIntoView(pageView.div);
|
2014-09-30 21:13:46 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var boundingRect = [
|
|
|
|
pageView.viewport.convertToViewportPoint(x, y),
|
|
|
|
pageView.viewport.convertToViewportPoint(x + width, y + height)
|
|
|
|
];
|
|
|
|
var left = Math.min(boundingRect[0][0], boundingRect[1][0]);
|
|
|
|
var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
|
|
|
|
|
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.
However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.
Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-06-20 19:30:05 +09:00
|
|
|
if (!allowNegativeOffset) {
|
|
|
|
// Some bad PDF generators will create destinations with e.g. top values
|
|
|
|
// that exceeds the page height. Ensure that offsets are not negative,
|
|
|
|
// to prevent a previous page from becoming visible (fixes bug 874482).
|
|
|
|
left = Math.max(left, 0);
|
|
|
|
top = Math.max(top, 0);
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
scrollIntoView(pageView.div, { left: left, top: top });
|
2014-09-30 21:13:46 +09:00
|
|
|
},
|
|
|
|
|
2014-09-21 02:15:18 +09:00
|
|
|
_updateLocation: function (firstPage) {
|
|
|
|
var currentScale = this._currentScale;
|
|
|
|
var currentScaleValue = this._currentScaleValue;
|
2014-09-13 11:27:45 +09:00
|
|
|
var normalizedScaleValue =
|
|
|
|
parseFloat(currentScaleValue) === currentScale ?
|
|
|
|
Math.round(currentScale * 10000) / 100 : currentScaleValue;
|
|
|
|
|
|
|
|
var pageNumber = firstPage.id;
|
|
|
|
var pdfOpenParams = '#page=' + pageNumber;
|
|
|
|
pdfOpenParams += '&zoom=' + normalizedScaleValue;
|
2015-03-20 21:01:14 +09:00
|
|
|
var currentPageView = this._pages[pageNumber - 1];
|
2014-09-13 11:27:45 +09:00
|
|
|
var container = this.container;
|
|
|
|
var topLeft = currentPageView.getPagePoint(
|
|
|
|
(container.scrollLeft - firstPage.x),
|
|
|
|
(container.scrollTop - firstPage.y));
|
|
|
|
var intLeft = Math.round(topLeft[0]);
|
|
|
|
var intTop = Math.round(topLeft[1]);
|
|
|
|
pdfOpenParams += ',' + intLeft + ',' + intTop;
|
|
|
|
|
2015-05-08 18:48:07 +09:00
|
|
|
this._location = {
|
2014-09-13 11:27:45 +09:00
|
|
|
pageNumber: pageNumber,
|
|
|
|
scale: normalizedScaleValue,
|
|
|
|
top: intTop,
|
|
|
|
left: intLeft,
|
|
|
|
pdfOpenParams: pdfOpenParams
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
Move the page switching code into `set currentPageNumber` in `PDFViewer` instead of placing it in the `pagechange` event handler
The reason that this code can be moved is that the `if (this.loading && page === 1)` check, in the `pagechange` event handler in viewer.js, is never satisfied since `this.loading` is not defined in that scope.
This *could* be considered a regression from PR 5295, since prior to that `this.loading` was using the `PDFViewerApplication` scope (or `PDFView` as it were).
However, I don't think that we need to fix that since we've been shipping this code in no less than *three* Firefox releases (uplifted in https://bugzilla.mozilla.org/show_bug.cgi?id=1084158), without breaking the world.
An explanation of why the `pagechange` code works, despite `this.loading === undefined`, is that `set currentPageNumber` (in `PDFViewer`) returns early whenever `this.pdfDocument` isn't set. This check is, for all intents and purposes, functionally equivalent to checking `PDFViewerApplication.loading`.
Hence we can move the page switching code into `PDFViewer`, and also remove `PDFViewerApplication.loading` since it's not used any more.
(The `this.loading` property was added in PR 686, which was before the current viewer even existed.)
*Note:* The changes in this patch should also be beneficial to the viewer `components`, since requiring every implementer to provide their own `pagechange` event handler just to get `PDFViewer.currentPageNumber` to actually work seems like an unnecessary complication.
2015-06-24 00:16:21 +09:00
|
|
|
update: function PDFViewer_update() {
|
2014-09-21 02:15:18 +09:00
|
|
|
var visible = this._getVisiblePages();
|
2014-09-13 11:27:45 +09:00
|
|
|
var visiblePages = visible.views;
|
|
|
|
if (visiblePages.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE,
|
|
|
|
2 * visiblePages.length + 1);
|
2014-09-30 01:32:45 +09:00
|
|
|
this._buffer.resize(suggestedCacheSize);
|
2014-09-13 11:27:45 +09:00
|
|
|
|
|
|
|
this.renderingQueue.renderHighestPriority(visible);
|
|
|
|
|
Move the page switching code into `set currentPageNumber` in `PDFViewer` instead of placing it in the `pagechange` event handler
The reason that this code can be moved is that the `if (this.loading && page === 1)` check, in the `pagechange` event handler in viewer.js, is never satisfied since `this.loading` is not defined in that scope.
This *could* be considered a regression from PR 5295, since prior to that `this.loading` was using the `PDFViewerApplication` scope (or `PDFView` as it were).
However, I don't think that we need to fix that since we've been shipping this code in no less than *three* Firefox releases (uplifted in https://bugzilla.mozilla.org/show_bug.cgi?id=1084158), without breaking the world.
An explanation of why the `pagechange` code works, despite `this.loading === undefined`, is that `set currentPageNumber` (in `PDFViewer`) returns early whenever `this.pdfDocument` isn't set. This check is, for all intents and purposes, functionally equivalent to checking `PDFViewerApplication.loading`.
Hence we can move the page switching code into `PDFViewer`, and also remove `PDFViewerApplication.loading` since it's not used any more.
(The `this.loading` property was added in PR 686, which was before the current viewer even existed.)
*Note:* The changes in this patch should also be beneficial to the viewer `components`, since requiring every implementer to provide their own `pagechange` event handler just to get `PDFViewer.currentPageNumber` to actually work seems like an unnecessary complication.
2015-06-24 00:16:21 +09:00
|
|
|
var currentId = this._currentPageNumber;
|
2014-09-13 11:27:45 +09:00
|
|
|
var firstPage = visible.first;
|
|
|
|
|
|
|
|
for (var i = 0, ii = visiblePages.length, stillFullyVisible = false;
|
|
|
|
i < ii; ++i) {
|
|
|
|
var page = visiblePages[i];
|
|
|
|
|
|
|
|
if (page.percent < 100) {
|
|
|
|
break;
|
|
|
|
}
|
2014-09-21 02:15:18 +09:00
|
|
|
if (page.id === currentId) {
|
2014-09-13 11:27:45 +09:00
|
|
|
stillFullyVisible = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stillFullyVisible) {
|
|
|
|
currentId = visiblePages[0].id;
|
|
|
|
}
|
|
|
|
|
2015-01-29 21:37:49 +09:00
|
|
|
if (!this.isInPresentationMode) {
|
2016-05-05 01:06:07 +09:00
|
|
|
this._setCurrentPageNumber(currentId);
|
2014-09-13 11:27:45 +09:00
|
|
|
}
|
|
|
|
|
2014-09-21 02:15:18 +09:00
|
|
|
this._updateLocation(firstPage);
|
2014-09-13 11:27:45 +09:00
|
|
|
|
2016-04-26 07:57:15 +09:00
|
|
|
this.eventBus.dispatch('updateviewarea', {
|
|
|
|
source: this,
|
|
|
|
location: this._location
|
|
|
|
});
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
containsElement: function (element) {
|
|
|
|
return this.container.contains(element);
|
|
|
|
},
|
|
|
|
|
|
|
|
focus: function () {
|
|
|
|
this.container.focus();
|
|
|
|
},
|
|
|
|
|
2015-01-29 21:37:49 +09:00
|
|
|
get isInPresentationMode() {
|
|
|
|
return this.presentationModeState === PresentationModeState.FULLSCREEN;
|
|
|
|
},
|
|
|
|
|
|
|
|
get isChangingPresentationMode() {
|
2015-11-13 06:33:34 +09:00
|
|
|
return this.presentationModeState === PresentationModeState.CHANGING;
|
2015-01-29 21:37:49 +09:00
|
|
|
},
|
|
|
|
|
2014-09-13 11:27:45 +09:00
|
|
|
get isHorizontalScrollbarEnabled() {
|
2015-01-29 21:37:49 +09:00
|
|
|
return (this.isInPresentationMode ?
|
2014-09-16 02:37:03 +09:00
|
|
|
false : (this.container.scrollWidth > this.container.clientWidth));
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
|
|
|
|
2014-09-21 02:15:18 +09:00
|
|
|
_getVisiblePages: function () {
|
2015-01-29 21:37:49 +09:00
|
|
|
if (!this.isInPresentationMode) {
|
2015-03-20 21:01:14 +09:00
|
|
|
return getVisibleElements(this.container, this._pages, true);
|
2014-09-13 11:27:45 +09:00
|
|
|
}
|
2016-12-16 21:05:33 +09:00
|
|
|
// The algorithm in getVisibleElements doesn't work in all browsers and
|
|
|
|
// configurations when presentation mode is active.
|
|
|
|
var visible = [];
|
|
|
|
var currentPage = this._pages[this._currentPageNumber - 1];
|
|
|
|
visible.push({ id: currentPage.id, view: currentPage });
|
|
|
|
return { first: currentPage, last: currentPage, views: visible };
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
cleanup: function () {
|
2015-03-20 21:01:14 +09:00
|
|
|
for (var i = 0, ii = this._pages.length; i < ii; i++) {
|
|
|
|
if (this._pages[i] &&
|
|
|
|
this._pages[i].renderingState !== RenderingStates.FINISHED) {
|
|
|
|
this._pages[i].reset();
|
2014-09-13 11:27:45 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-30 03:39:22 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_cancelRendering: function PDFViewer_cancelRendering() {
|
|
|
|
for (var i = 0, ii = this._pages.length; i < ii; i++) {
|
|
|
|
if (this._pages[i]) {
|
|
|
|
this._pages[i].cancelRendering();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-09-29 22:11:46 +09:00
|
|
|
/**
|
|
|
|
* @param {PDFPageView} pageView
|
|
|
|
* @returns {PDFPage}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_ensurePdfPageLoaded: function (pageView) {
|
|
|
|
if (pageView.pdfPage) {
|
|
|
|
return Promise.resolve(pageView.pdfPage);
|
|
|
|
}
|
|
|
|
var pageNumber = pageView.id;
|
|
|
|
if (this._pagesRequests[pageNumber]) {
|
|
|
|
return this._pagesRequests[pageNumber];
|
|
|
|
}
|
|
|
|
var promise = this.pdfDocument.getPage(pageNumber).then(
|
|
|
|
function (pdfPage) {
|
|
|
|
pageView.setPdfPage(pdfPage);
|
|
|
|
this._pagesRequests[pageNumber] = null;
|
|
|
|
return pdfPage;
|
|
|
|
}.bind(this));
|
|
|
|
this._pagesRequests[pageNumber] = promise;
|
|
|
|
return promise;
|
|
|
|
},
|
|
|
|
|
2014-09-13 11:27:45 +09:00
|
|
|
forceRendering: function (currentlyVisiblePages) {
|
2014-09-21 02:15:18 +09:00
|
|
|
var visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
2014-09-13 11:27:45 +09:00
|
|
|
var pageView = this.renderingQueue.getHighestPriority(visiblePages,
|
2015-03-20 21:01:14 +09:00
|
|
|
this._pages,
|
2014-09-13 11:27:45 +09:00
|
|
|
this.scroll.down);
|
|
|
|
if (pageView) {
|
2014-09-29 22:11:46 +09:00
|
|
|
this._ensurePdfPageLoaded(pageView).then(function () {
|
|
|
|
this.renderingQueue.renderView(pageView);
|
|
|
|
}.bind(this));
|
2014-10-02 07:24:01 +09:00
|
|
|
return true;
|
2014-09-13 11:27:45 +09:00
|
|
|
}
|
2014-10-02 07:24:01 +09:00
|
|
|
return false;
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
2014-09-15 23:49:24 +09:00
|
|
|
|
|
|
|
getPageTextContent: function (pageIndex) {
|
|
|
|
return this.pdfDocument.getPage(pageIndex + 1).then(function (page) {
|
2016-07-04 01:29:47 +09:00
|
|
|
return page.getTextContent({
|
|
|
|
normalizeWhitespace: true,
|
|
|
|
});
|
2014-09-15 23:49:24 +09:00
|
|
|
});
|
|
|
|
},
|
2014-09-16 04:57:12 +09:00
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
2014-09-28 23:35:33 +09:00
|
|
|
* @param {HTMLDivElement} textLayerDiv
|
|
|
|
* @param {number} pageIndex
|
|
|
|
* @param {PageViewport} viewport
|
2014-09-21 02:21:49 +09:00
|
|
|
* @returns {TextLayerBuilder}
|
|
|
|
*/
|
2016-08-17 08:06:35 +09:00
|
|
|
createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport,
|
|
|
|
enhanceTextSelection) {
|
2014-09-16 04:57:12 +09:00
|
|
|
return new TextLayerBuilder({
|
|
|
|
textLayerDiv: textLayerDiv,
|
2016-04-26 07:57:15 +09:00
|
|
|
eventBus: this.eventBus,
|
2014-09-16 04:57:12 +09:00
|
|
|
pageIndex: pageIndex,
|
|
|
|
viewport: viewport,
|
2016-08-17 08:06:35 +09:00
|
|
|
findController: this.isInPresentationMode ? null : this.findController,
|
|
|
|
enhanceTextSelection: this.isInPresentationMode ? false :
|
|
|
|
enhanceTextSelection,
|
2014-09-16 04:57:12 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-09-30 01:05:28 +09:00
|
|
|
/**
|
|
|
|
* @param {HTMLDivElement} pageDiv
|
|
|
|
* @param {PDFPage} pdfPage
|
2016-09-18 02:44:25 +09:00
|
|
|
* @param {boolean} renderInteractiveForms
|
2015-12-17 20:54:53 +09:00
|
|
|
* @returns {AnnotationLayerBuilder}
|
2014-09-30 01:05:28 +09:00
|
|
|
*/
|
2016-09-18 02:44:25 +09:00
|
|
|
createAnnotationLayerBuilder: function (pageDiv, pdfPage,
|
|
|
|
renderInteractiveForms) {
|
2015-12-17 20:54:53 +09:00
|
|
|
return new AnnotationLayerBuilder({
|
2014-09-30 01:05:28 +09:00
|
|
|
pageDiv: pageDiv,
|
|
|
|
pdfPage: pdfPage,
|
2016-09-18 02:44:25 +09:00
|
|
|
renderInteractiveForms: renderInteractiveForms,
|
2016-02-15 04:44:00 +09:00
|
|
|
linkService: this.linkService,
|
|
|
|
downloadManager: this.downloadManager
|
2014-09-30 01:05:28 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-09-16 04:57:12 +09:00
|
|
|
setFindController: function (findController) {
|
|
|
|
this.findController = findController;
|
|
|
|
},
|
2016-10-07 06:46:30 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns sizes of the pages.
|
|
|
|
* @returns {Array} Array of objects with width/height fields.
|
|
|
|
*/
|
|
|
|
getPagesOverview: function () {
|
|
|
|
return this._pages.map(function (pageView) {
|
|
|
|
var viewport = pageView.pdfPage.getViewport(1);
|
|
|
|
return {width: viewport.width, height: viewport.height};
|
|
|
|
});
|
|
|
|
},
|
2014-09-13 11:27:45 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
return PDFViewer;
|
|
|
|
})();
|
2014-09-15 23:49:24 +09:00
|
|
|
|
2016-04-09 02:34:27 +09:00
|
|
|
exports.PresentationModeState = PresentationModeState;
|
|
|
|
exports.PDFViewer = PDFViewer;
|
|
|
|
}));
|