Browse Source

PDF.js version 1.9.597 - See mozilla/pdf.js@f3987bba237c814b9ed314b904263bc36f83eb5b

master v1.9.597
pdfjsbot 7 years ago
parent
commit
086dd1493b
  1. 2
      bower.json
  2. 12
      build/pdf.combined.js
  3. 2
      build/pdf.combined.js.map
  4. 12
      build/pdf.js
  5. 2
      build/pdf.js.map
  6. 2
      build/pdf.min.js
  7. 4
      build/pdf.worker.js
  8. 2
      build/pdf.worker.js.map
  9. 4
      lib/display/api.js
  10. 4
      lib/display/global.js
  11. 4
      lib/pdf.js
  12. 4
      lib/pdf.worker.js
  13. 6
      lib/web/app.js
  14. 810
      lib/web/base_viewer.js
  15. 171
      lib/web/pdf_single_page_viewer.js
  16. 2
      lib/web/pdf_viewer.component.js
  17. 788
      lib/web/pdf_viewer.js
  18. 9
      lib/web/ui_utils.js
  19. 2
      package.json
  20. 3644
      web/pdf_viewer.js
  21. 2
      web/pdf_viewer.js.map

2
bower.json

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"name": "pdfjs-dist",
"version": "1.9.593",
"version": "1.9.597",
"main": [
"build/pdf.js",
"build/pdf.worker.js"

12
build/pdf.combined.js

@ -13632,8 +13632,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() { @@ -13632,8 +13632,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}();
var version, build;
{
exports.version = version = '1.9.593';
exports.build = build = '10727572';
exports.version = version = '1.9.597';
exports.build = build = 'f3987bba';
}
exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort;
@ -29591,8 +29591,8 @@ exports.SVGGraphics = SVGGraphics; @@ -29591,8 +29591,8 @@ exports.SVGGraphics = SVGGraphics;
"use strict";
var pdfjsVersion = '1.9.593';
var pdfjsBuild = '10727572';
var pdfjsVersion = '1.9.597';
var pdfjsBuild = 'f3987bba';
var pdfjsSharedUtil = __w_pdfjs_require__(0);
var pdfjsDisplayGlobal = __w_pdfjs_require__(98);
var pdfjsDisplayAPI = __w_pdfjs_require__(55);
@ -35454,8 +35454,8 @@ if (!_global_scope2.default.PDFJS) { @@ -35454,8 +35454,8 @@ if (!_global_scope2.default.PDFJS) {
}
var PDFJS = _global_scope2.default.PDFJS;
{
PDFJS.version = '1.9.593';
PDFJS.build = '10727572';
PDFJS.version = '1.9.597';
PDFJS.build = 'f3987bba';
}
PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) {

2
build/pdf.combined.js.map

File diff suppressed because one or more lines are too long

12
build/pdf.js

@ -4335,8 +4335,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() { @@ -4335,8 +4335,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}();
var version, build;
{
exports.version = version = '1.9.593';
exports.build = build = '10727572';
exports.version = version = '1.9.597';
exports.build = build = 'f3987bba';
}
exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort;
@ -7408,8 +7408,8 @@ exports.SVGGraphics = SVGGraphics; @@ -7408,8 +7408,8 @@ exports.SVGGraphics = SVGGraphics;
"use strict";
var pdfjsVersion = '1.9.593';
var pdfjsBuild = '10727572';
var pdfjsVersion = '1.9.597';
var pdfjsBuild = 'f3987bba';
var pdfjsSharedUtil = __w_pdfjs_require__(0);
var pdfjsDisplayGlobal = __w_pdfjs_require__(82);
var pdfjsDisplayAPI = __w_pdfjs_require__(48);
@ -13271,8 +13271,8 @@ if (!_global_scope2.default.PDFJS) { @@ -13271,8 +13271,8 @@ if (!_global_scope2.default.PDFJS) {
}
var PDFJS = _global_scope2.default.PDFJS;
{
PDFJS.version = '1.9.593';
PDFJS.build = '10727572';
PDFJS.version = '1.9.597';
PDFJS.build = 'f3987bba';
}
PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) {

2
build/pdf.js.map

File diff suppressed because one or more lines are too long

2
build/pdf.min.js vendored

File diff suppressed because one or more lines are too long

4
build/pdf.worker.js vendored

@ -24540,8 +24540,8 @@ exports.getUnicodeForGlyph = getUnicodeForGlyph; @@ -24540,8 +24540,8 @@ exports.getUnicodeForGlyph = getUnicodeForGlyph;
"use strict";
var pdfjsVersion = '1.9.593';
var pdfjsBuild = '10727572';
var pdfjsVersion = '1.9.597';
var pdfjsBuild = 'f3987bba';
var pdfjsCoreWorker = __w_pdfjs_require__(62);
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;

2
build/pdf.worker.js.map vendored

File diff suppressed because one or more lines are too long

4
lib/display/api.js

@ -1582,8 +1582,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() { @@ -1582,8 +1582,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}();
var version, build;
{
exports.version = version = '1.9.593';
exports.build = build = '10727572';
exports.version = version = '1.9.597';
exports.build = build = 'f3987bba';
}
exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort;

4
lib/display/global.js

@ -45,8 +45,8 @@ if (!_global_scope2.default.PDFJS) { @@ -45,8 +45,8 @@ if (!_global_scope2.default.PDFJS) {
}
var PDFJS = _global_scope2.default.PDFJS;
{
PDFJS.version = '1.9.593';
PDFJS.build = '10727572';
PDFJS.version = '1.9.597';
PDFJS.build = 'f3987bba';
}
PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) {

4
lib/pdf.js

@ -14,8 +14,8 @@ @@ -14,8 +14,8 @@
*/
'use strict';
var pdfjsVersion = '1.9.593';
var pdfjsBuild = '10727572';
var pdfjsVersion = '1.9.597';
var pdfjsBuild = 'f3987bba';
var pdfjsSharedUtil = require('./shared/util.js');
var pdfjsDisplayGlobal = require('./display/global.js');
var pdfjsDisplayAPI = require('./display/api.js');

4
lib/pdf.worker.js vendored

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
*/
'use strict';
var pdfjsVersion = '1.9.593';
var pdfjsBuild = '10727572';
var pdfjsVersion = '1.9.597';
var pdfjsBuild = 'f3987bba';
var pdfjsCoreWorker = require('./core/worker.js');
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;

6
lib/web/app.js

@ -31,8 +31,6 @@ var _pdf_rendering_queue = require('./pdf_rendering_queue'); @@ -31,8 +31,6 @@ var _pdf_rendering_queue = require('./pdf_rendering_queue');
var _pdf_sidebar = require('./pdf_sidebar');
var _pdf_viewer = require('./pdf_viewer');
var _dom_events = require('./dom_events');
var _overlay_manager = require('./overlay_manager');
@ -57,6 +55,8 @@ var _pdf_presentation_mode = require('./pdf_presentation_mode'); @@ -57,6 +55,8 @@ var _pdf_presentation_mode = require('./pdf_presentation_mode');
var _pdf_thumbnail_viewer = require('./pdf_thumbnail_viewer');
var _pdf_viewer = require('./pdf_viewer');
var _secondary_toolbar = require('./secondary_toolbar');
var _toolbar = require('./toolbar');
@ -1243,7 +1243,7 @@ function webViewerPresentationModeChanged(evt) { @@ -1243,7 +1243,7 @@ function webViewerPresentationModeChanged(evt) {
var active = evt.active,
switchInProgress = evt.switchInProgress;
PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _pdf_viewer.PresentationModeState.CHANGING : active ? _pdf_viewer.PresentationModeState.FULLSCREEN : _pdf_viewer.PresentationModeState.NORMAL;
PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _ui_utils.PresentationModeState.CHANGING : active ? _ui_utils.PresentationModeState.FULLSCREEN : _ui_utils.PresentationModeState.NORMAL;
}
function webViewerSidebarViewChanged(evt) {
PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;

810
lib/web/base_viewer.js

@ -0,0 +1,810 @@ @@ -0,0 +1,810 @@
/* Copyright 2017 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';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BaseViewer = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _pdf = require('../pdf');
var _ui_utils = require('./ui_utils');
var _pdf_rendering_queue = require('./pdf_rendering_queue');
var _annotation_layer_builder = require('./annotation_layer_builder');
var _dom_events = require('./dom_events');
var _pdf_page_view = require('./pdf_page_view');
var _pdf_link_service = require('./pdf_link_service');
var _text_layer_builder = require('./text_layer_builder');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var DEFAULT_CACHE_SIZE = 10;
function PDFPageViewBuffer(size) {
var data = [];
this.push = function (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();
}
};
}
function isSameScale(oldScale, newScale) {
if (newScale === oldScale) {
return true;
}
if (Math.abs(newScale - oldScale) < 1e-15) {
return true;
}
return false;
}
function isPortraitOrientation(size) {
return size.width <= size.height;
}
var BaseViewer = function () {
function BaseViewer(options) {
_classCallCheck(this, BaseViewer);
if (this.constructor === BaseViewer) {
throw new Error('Cannot initialize BaseViewer.');
}
this._name = this.constructor.name;
this.container = options.container;
this.viewer = options.viewer || options.container.firstElementChild;
this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
this.downloadManager = options.downloadManager || null;
this.removePageBorders = options.removePageBorders || false;
this.enhanceTextSelection = options.enhanceTextSelection || false;
this.renderInteractiveForms = options.renderInteractiveForms || false;
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
this.l10n = options.l10n || _ui_utils.NullL10n;
this.defaultRenderingQueue = !options.renderingQueue;
if (this.defaultRenderingQueue) {
this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
this.renderingQueue.setViewer(this);
} else {
this.renderingQueue = options.renderingQueue;
}
this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
this._resetView();
if (this.removePageBorders) {
this.viewer.classList.add('removePageBorders');
}
}
_createClass(BaseViewer, [{
key: 'getPageView',
value: function getPageView(index) {
return this._pages[index];
}
}, {
key: '_setCurrentPageNumber',
value: function _setCurrentPageNumber(val) {
var resetCurrentPageView = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this._currentPageNumber === val) {
if (resetCurrentPageView) {
this._resetCurrentPageView();
}
return;
}
if (!(0 < val && val <= this.pagesCount)) {
console.error(this._name + '._setCurrentPageNumber: "' + val + '" is out of bounds.');
return;
}
var arg = {
source: this,
pageNumber: val,
pageLabel: this._pageLabels && this._pageLabels[val - 1]
};
this._currentPageNumber = val;
this.eventBus.dispatch('pagechanging', arg);
this.eventBus.dispatch('pagechange', arg);
if (resetCurrentPageView) {
this._resetCurrentPageView();
}
}
}, {
key: 'setDocument',
value: function setDocument(pdfDocument) {
var _this = this;
if (this.pdfDocument) {
this._cancelRendering();
this._resetView();
}
this.pdfDocument = pdfDocument;
if (!pdfDocument) {
return;
}
var pagesCount = pdfDocument.numPages;
var pagesCapability = (0, _pdf.createPromiseCapability)();
this.pagesPromise = pagesCapability.promise;
pagesCapability.promise.then(function () {
_this._pageViewsReady = true;
_this.eventBus.dispatch('pagesloaded', {
source: _this,
pagesCount: pagesCount
});
});
var isOnePageRenderedResolved = false;
var onePageRenderedCapability = (0, _pdf.createPromiseCapability)();
this.onePageRendered = onePageRenderedCapability.promise;
var bindOnAfterAndBeforeDraw = function bindOnAfterAndBeforeDraw(pageView) {
pageView.onBeforeDraw = function () {
_this._buffer.push(pageView);
};
pageView.onAfterDraw = function () {
if (!isOnePageRenderedResolved) {
isOnePageRenderedResolved = true;
onePageRenderedCapability.resolve();
}
};
};
var firstPagePromise = pdfDocument.getPage(1);
this.firstPagePromise = firstPagePromise;
firstPagePromise.then(function (pdfPage) {
var scale = _this.currentScale;
var viewport = pdfPage.getViewport(scale * _ui_utils.CSS_UNITS);
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
var textLayerFactory = null;
if (!_pdf.PDFJS.disableTextLayer) {
textLayerFactory = _this;
}
var pageView = new _pdf_page_view.PDFPageView({
container: _this._setDocumentViewerElement,
eventBus: _this.eventBus,
id: pageNum,
scale: scale,
defaultViewport: viewport.clone(),
renderingQueue: _this.renderingQueue,
textLayerFactory: textLayerFactory,
annotationLayerFactory: _this,
enhanceTextSelection: _this.enhanceTextSelection,
renderInteractiveForms: _this.renderInteractiveForms,
renderer: _this.renderer,
l10n: _this.l10n
});
bindOnAfterAndBeforeDraw(pageView);
_this._pages.push(pageView);
}
onePageRenderedCapability.promise.then(function () {
if (_pdf.PDFJS.disableAutoFetch) {
pagesCapability.resolve();
return;
}
var getPagesLeft = pagesCount;
var _loop = function _loop(_pageNum) {
pdfDocument.getPage(_pageNum).then(function (pdfPage) {
var pageView = _this._pages[_pageNum - 1];
if (!pageView.pdfPage) {
pageView.setPdfPage(pdfPage);
}
_this.linkService.cachePageRef(_pageNum, pdfPage.ref);
if (--getPagesLeft === 0) {
pagesCapability.resolve();
}
}, function (reason) {
console.error('Unable to get page ' + _pageNum + ' to initialize viewer', reason);
if (--getPagesLeft === 0) {
pagesCapability.resolve();
}
});
};
for (var _pageNum = 1; _pageNum <= pagesCount; ++_pageNum) {
_loop(_pageNum);
}
});
_this.eventBus.dispatch('pagesinit', { source: _this });
if (_this.defaultRenderingQueue) {
_this.update();
}
if (_this.findController) {
_this.findController.resolveFirstPage();
}
}).catch(function (reason) {
console.error('Unable to initialize viewer', reason);
});
}
}, {
key: 'setPageLabels',
value: function 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(this._name + '.setPageLabels: Invalid page labels.');
} else {
this._pageLabels = labels;
}
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);
}
}
}, {
key: '_resetView',
value: function _resetView() {
this._pages = [];
this._currentPageNumber = 1;
this._currentScale = _ui_utils.UNKNOWN_SCALE;
this._currentScaleValue = null;
this._pageLabels = null;
this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
this._location = null;
this._pagesRotation = 0;
this._pagesRequests = [];
this._pageViewsReady = false;
this.viewer.textContent = '';
}
}, {
key: '_scrollUpdate',
value: function _scrollUpdate() {
if (this.pagesCount === 0) {
return;
}
this.update();
}
}, {
key: '_scrollIntoView',
value: function _scrollIntoView(_ref) {
var pageDiv = _ref.pageDiv,
_ref$pageSpot = _ref.pageSpot,
pageSpot = _ref$pageSpot === undefined ? null : _ref$pageSpot,
_ref$pageNumber = _ref.pageNumber,
pageNumber = _ref$pageNumber === undefined ? null : _ref$pageNumber;
throw new Error('Not implemented: _scrollIntoView');
}
}, {
key: '_setScaleDispatchEvent',
value: function _setScaleDispatchEvent(newScale, newValue) {
var preset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var arg = {
source: this,
scale: newScale,
presetValue: preset ? newValue : undefined
};
this.eventBus.dispatch('scalechanging', arg);
this.eventBus.dispatch('scalechange', arg);
}
}, {
key: '_setScaleUpdatePages',
value: function _setScaleUpdatePages(newScale, newValue) {
var noScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var preset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
this._currentScaleValue = newValue.toString();
if (isSameScale(this._currentScale, newScale)) {
if (preset) {
this._setScaleDispatchEvent(newScale, newValue, true);
}
return;
}
for (var i = 0, ii = this._pages.length; i < ii; i++) {
this._pages[i].update(newScale);
}
this._currentScale = newScale;
if (!noScroll) {
var page = this._currentPageNumber,
dest = void 0;
if (this._location && !_pdf.PDFJS.ignoreCurrentPositionOnZoom && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
page = this._location.pageNumber;
dest = [null, { name: 'XYZ' }, this._location.left, this._location.top, null];
}
this.scrollPageIntoView({
pageNumber: page,
destArray: dest,
allowNegativeOffset: true
});
}
this._setScaleDispatchEvent(newScale, newValue, preset);
if (this.defaultRenderingQueue) {
this.update();
}
}
}, {
key: '_setScale',
value: function _setScale(value) {
var noScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var scale = parseFloat(value);
if (scale > 0) {
this._setScaleUpdatePages(scale, value, noScroll, false);
} else {
var currentPage = this._pages[this._currentPageNumber - 1];
if (!currentPage) {
return;
}
var hPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
var vPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
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;
var horizontalScale = isLandscape ? Math.min(pageHeightScale, pageWidthScale) : pageWidthScale;
scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
break;
default:
console.error(this._name + '._setScale: "' + value + '" is an unknown zoom value.');
return;
}
this._setScaleUpdatePages(scale, value, noScroll, true);
}
}
}, {
key: '_resetCurrentPageView',
value: function _resetCurrentPageView() {
if (this.isInPresentationMode) {
this._setScale(this._currentScaleValue, true);
}
var pageView = this._pages[this._currentPageNumber - 1];
this._scrollIntoView({ pageDiv: pageView.div });
}
}, {
key: 'scrollPageIntoView',
value: function scrollPageIntoView(params) {
if (arguments.length > 1 || typeof params === 'number') {
console.error('Call of scrollPageIntoView() with obsolete signature.');
return;
}
if (!this.pdfDocument) {
return;
}
var pageNumber = params.pageNumber || 0;
var dest = params.destArray || null;
var allowNegativeOffset = params.allowNegativeOffset || false;
if (this.isInPresentationMode || !dest) {
this._setCurrentPageNumber(pageNumber, true);
return;
}
var pageView = this._pages[pageNumber - 1];
if (!pageView) {
console.error(this._name + '.scrollPageIntoView: Invalid "pageNumber" parameter.');
return;
}
var x = 0,
y = 0;
var width = 0,
height = 0,
widthScale = void 0,
heightScale = void 0;
var changeOrientation = pageView.rotation % 180 === 0 ? false : true;
var pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
var pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
var scale = 0;
switch (dest[1].name) {
case 'XYZ':
x = dest[2];
y = dest[3];
scale = dest[4];
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';
if (y === null && this._location) {
x = this._location.left;
y = this._location.top;
}
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;
var hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
var vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
break;
default:
console.error(this._name + '.scrollPageIntoView: "' + dest[1].name + '" ' + 'is not a valid destination type.');
return;
}
if (scale && scale !== this._currentScale) {
this.currentScaleValue = scale;
} else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
}
if (scale === 'page-fit' && !dest[4]) {
this._scrollIntoView({
pageDiv: pageView.div,
pageNumber: pageNumber
});
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]);
if (!allowNegativeOffset) {
left = Math.max(left, 0);
top = Math.max(top, 0);
}
this._scrollIntoView({
pageDiv: pageView.div,
pageSpot: {
left: left,
top: top
},
pageNumber: pageNumber
});
}
}, {
key: '_resizeBuffer',
value: function _resizeBuffer(numVisiblePages) {
var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
this._buffer.resize(suggestedCacheSize);
}
}, {
key: '_updateLocation',
value: function _updateLocation(firstPage) {
var currentScale = this._currentScale;
var currentScaleValue = this._currentScaleValue;
var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
var pageNumber = firstPage.id;
var pdfOpenParams = '#page=' + pageNumber;
pdfOpenParams += '&zoom=' + normalizedScaleValue;
var currentPageView = this._pages[pageNumber - 1];
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;
this._location = {
pageNumber: pageNumber,
scale: normalizedScaleValue,
top: intTop,
left: intLeft,
rotation: this._pagesRotation,
pdfOpenParams: pdfOpenParams
};
}
}, {
key: 'update',
value: function update() {
throw new Error('Not implemented: update');
}
}, {
key: 'containsElement',
value: function containsElement(element) {
return this.container.contains(element);
}
}, {
key: 'focus',
value: function focus() {
this.container.focus();
}
}, {
key: '_getVisiblePages',
value: function _getVisiblePages() {
throw new Error('Not implemented: _getVisiblePages');
}
}, {
key: 'cleanup',
value: function cleanup() {
for (var i = 0, ii = this._pages.length; i < ii; i++) {
if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
this._pages[i].reset();
}
}
}
}, {
key: '_cancelRendering',
value: function _cancelRendering() {
for (var i = 0, ii = this._pages.length; i < ii; i++) {
if (this._pages[i]) {
this._pages[i].cancelRendering();
}
}
}
}, {
key: '_ensurePdfPageLoaded',
value: function _ensurePdfPageLoaded(pageView) {
var _this2 = this;
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) {
if (!pageView.pdfPage) {
pageView.setPdfPage(pdfPage);
}
_this2._pagesRequests[pageNumber] = null;
return pdfPage;
}).catch(function (reason) {
console.error('Unable to get page for page view', reason);
_this2._pagesRequests[pageNumber] = null;
});
this._pagesRequests[pageNumber] = promise;
return promise;
}
}, {
key: 'forceRendering',
value: function forceRendering(currentlyVisiblePages) {
var _this3 = this;
var visiblePages = currentlyVisiblePages || this._getVisiblePages();
var pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, this.scroll.down);
if (pageView) {
this._ensurePdfPageLoaded(pageView).then(function () {
_this3.renderingQueue.renderView(pageView);
});
return true;
}
return false;
}
}, {
key: 'getPageTextContent',
value: function getPageTextContent(pageIndex) {
return this.pdfDocument.getPage(pageIndex + 1).then(function (page) {
return page.getTextContent({ normalizeWhitespace: true });
});
}
}, {
key: 'createTextLayerBuilder',
value: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
return new _text_layer_builder.TextLayerBuilder({
textLayerDiv: textLayerDiv,
eventBus: this.eventBus,
pageIndex: pageIndex,
viewport: viewport,
findController: this.isInPresentationMode ? null : this.findController,
enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
});
}
}, {
key: 'createAnnotationLayerBuilder',
value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
return new _annotation_layer_builder.AnnotationLayerBuilder({
pageDiv: pageDiv,
pdfPage: pdfPage,
renderInteractiveForms: renderInteractiveForms,
linkService: this.linkService,
downloadManager: this.downloadManager,
l10n: l10n
});
}
}, {
key: 'setFindController',
value: function setFindController(findController) {
this.findController = findController;
}
}, {
key: 'getPagesOverview',
value: function getPagesOverview() {
var pagesOverview = this._pages.map(function (pageView) {
var viewport = pageView.pdfPage.getViewport(1);
return {
width: viewport.width,
height: viewport.height,
rotation: viewport.rotation
};
});
if (!this.enablePrintAutoRotate) {
return pagesOverview;
}
var isFirstPagePortrait = isPortraitOrientation(pagesOverview[0]);
return pagesOverview.map(function (size) {
if (isFirstPagePortrait === isPortraitOrientation(size)) {
return size;
}
return {
width: size.height,
height: size.width,
rotation: (size.rotation + 90) % 360
};
});
}
}, {
key: 'pagesCount',
get: function get() {
return this._pages.length;
}
}, {
key: 'pageViewsReady',
get: function get() {
return this._pageViewsReady;
}
}, {
key: 'currentPageNumber',
get: function get() {
return this._currentPageNumber;
},
set: function set(val) {
if (!Number.isInteger(val)) {
throw new Error('Invalid page number.');
}
if (!this.pdfDocument) {
return;
}
this._setCurrentPageNumber(val, true);
}
}, {
key: 'currentPageLabel',
get: function get() {
return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
},
set: function set(val) {
var pageNumber = val | 0;
if (this._pageLabels) {
var i = this._pageLabels.indexOf(val);
if (i >= 0) {
pageNumber = i + 1;
}
}
this.currentPageNumber = pageNumber;
}
}, {
key: 'currentScale',
get: function get() {
return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
},
set: function set(val) {
if (isNaN(val)) {
throw new Error('Invalid numeric scale');
}
if (!this.pdfDocument) {
return;
}
this._setScale(val, false);
}
}, {
key: 'currentScaleValue',
get: function get() {
return this._currentScaleValue;
},
set: function set(val) {
if (!this.pdfDocument) {
return;
}
this._setScale(val, false);
}
}, {
key: 'pagesRotation',
get: function get() {
return this._pagesRotation;
},
set: function set(rotation) {
if (!(0, _ui_utils.isValidRotation)(rotation)) {
throw new Error('Invalid pages rotation angle.');
}
if (!this.pdfDocument) {
return;
}
if (this._pagesRotation === rotation) {
return;
}
this._pagesRotation = rotation;
var pageNumber = this._currentPageNumber;
for (var i = 0, ii = this._pages.length; i < ii; i++) {
var pageView = this._pages[i];
pageView.update(pageView.scale, rotation);
}
if (this._currentScaleValue) {
this._setScale(this._currentScaleValue, true);
}
this.eventBus.dispatch('rotationchanging', {
source: this,
pagesRotation: rotation,
pageNumber: pageNumber
});
if (this.defaultRenderingQueue) {
this.update();
}
}
}, {
key: '_setDocumentViewerElement',
get: function get() {
throw new Error('Not implemented: _setDocumentViewerElement');
}
}, {
key: 'isInPresentationMode',
get: function get() {
return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
}
}, {
key: 'isChangingPresentationMode',
get: function get() {
return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
}
}, {
key: 'isHorizontalScrollbarEnabled',
get: function get() {
return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
}
}, {
key: 'hasEqualPageSizes',
get: function get() {
var firstPageView = this._pages[0];
for (var i = 1, ii = this._pages.length; i < ii; ++i) {
var pageView = this._pages[i];
if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
return false;
}
}
return true;
}
}]);
return BaseViewer;
}();
exports.BaseViewer = BaseViewer;

171
lib/web/pdf_single_page_viewer.js

@ -0,0 +1,171 @@ @@ -0,0 +1,171 @@
/* Copyright 2017 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';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PDFSinglePageViewer = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _base_viewer = require('./base_viewer');
var _ui_utils = require('./ui_utils');
var _pdf = require('../pdf');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var PDFSinglePageViewer = function (_BaseViewer) {
_inherits(PDFSinglePageViewer, _BaseViewer);
function PDFSinglePageViewer(options) {
_classCallCheck(this, PDFSinglePageViewer);
var _this = _possibleConstructorReturn(this, (PDFSinglePageViewer.__proto__ || Object.getPrototypeOf(PDFSinglePageViewer)).call(this, options));
_this.eventBus.on('pagesinit', function (evt) {
_this._ensurePageViewVisible();
});
return _this;
}
_createClass(PDFSinglePageViewer, [{
key: '_resetView',
value: function _resetView() {
_get(PDFSinglePageViewer.prototype.__proto__ || Object.getPrototypeOf(PDFSinglePageViewer.prototype), '_resetView', this).call(this);
this._previousPageNumber = 1;
this._shadowViewer = document.createDocumentFragment();
}
}, {
key: '_ensurePageViewVisible',
value: function _ensurePageViewVisible() {
var pageView = this._pages[this._currentPageNumber - 1];
var previousPageView = this._pages[this._previousPageNumber - 1];
var viewerNodes = this.viewer.childNodes;
switch (viewerNodes.length) {
case 0:
this.viewer.appendChild(pageView.div);
break;
case 1:
if (viewerNodes[0] !== previousPageView.div) {
throw new Error('_ensurePageViewVisible: Unexpected previously visible page.');
}
if (pageView === previousPageView) {
break;
}
this._shadowViewer.appendChild(previousPageView.div);
this.viewer.appendChild(pageView.div);
this.container.scrollTop = 0;
break;
default:
throw new Error('_ensurePageViewVisible: Only one page should be visible at a time.');
}
this._previousPageNumber = this._currentPageNumber;
}
}, {
key: '_scrollUpdate',
value: function _scrollUpdate() {
if (this._updateScrollDown) {
this._updateScrollDown();
}
_get(PDFSinglePageViewer.prototype.__proto__ || Object.getPrototypeOf(PDFSinglePageViewer.prototype), '_scrollUpdate', this).call(this);
}
}, {
key: '_scrollIntoView',
value: function _scrollIntoView(_ref) {
var _this2 = this;
var pageDiv = _ref.pageDiv,
_ref$pageSpot = _ref.pageSpot,
pageSpot = _ref$pageSpot === undefined ? null : _ref$pageSpot,
_ref$pageNumber = _ref.pageNumber,
pageNumber = _ref$pageNumber === undefined ? null : _ref$pageNumber;
if (pageNumber) {
this._setCurrentPageNumber(pageNumber);
}
var scrolledDown = this._currentPageNumber >= this._previousPageNumber;
var previousLocation = this._location;
this._ensurePageViewVisible();
(0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
this._updateScrollDown = function () {
_this2.scroll.down = scrolledDown;
delete _this2._updateScrollDown;
};
setTimeout(function () {
if (_this2._location === previousLocation) {
if (_this2._updateScrollDown) {
_this2._updateScrollDown();
}
_this2.update();
}
}, 0);
}
}, {
key: '_getVisiblePages',
value: function _getVisiblePages() {
if (!this.pagesCount) {
return { views: [] };
}
var pageView = this._pages[this._currentPageNumber - 1];
var element = pageView.div;
var view = {
id: pageView.id,
x: element.offsetLeft + element.clientLeft,
y: element.offsetTop + element.clientTop,
view: pageView
};
return {
first: view,
last: view,
views: [view]
};
}
}, {
key: 'update',
value: function update() {
var visible = this._getVisiblePages();
var visiblePages = visible.views,
numVisiblePages = visiblePages.length;
if (numVisiblePages === 0) {
return;
}
this._resizeBuffer(numVisiblePages);
this.renderingQueue.renderHighestPriority(visible);
this._updateLocation(visible.first);
this.eventBus.dispatch('updateviewarea', {
source: this,
location: this._location
});
}
}, {
key: '_setDocumentViewerElement',
get: function get() {
return (0, _pdf.shadow)(this, '_setDocumentViewerElement', this._shadowViewer);
}
}]);
return PDFSinglePageViewer;
}(_base_viewer.BaseViewer);
exports.PDFSinglePageViewer = PDFSinglePageViewer;

2
lib/web/pdf_viewer.component.js

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
var pdfjsLib = require('./pdfjs.js');
var pdfjsWebPDFViewer = require('./pdf_viewer.js');
var pdfjsWebPDFSinglePageViewer = require('./pdf_single_page_viewer');
var pdfjsWebPDFPageView = require('./pdf_page_view.js');
var pdfjsWebPDFLinkService = require('./pdf_link_service.js');
var pdfjsWebTextLayerBuilder = require('./text_layer_builder.js');
@ -27,6 +28,7 @@ var pdfjsWebDownloadManager = require('./download_manager.js'); @@ -27,6 +28,7 @@ var pdfjsWebDownloadManager = require('./download_manager.js');
var pdfjsWebGenericL10n = require('./genericl10n.js');
var PDFJS = pdfjsLib.PDFJS;
PDFJS.PDFViewer = pdfjsWebPDFViewer.PDFViewer;
PDFJS.PDFSinglePageViewer = pdfjsWebPDFSinglePageViewer.PDFSinglePageViewer;
PDFJS.PDFPageView = pdfjsWebPDFPageView.PDFPageView;
PDFJS.PDFLinkService = pdfjsWebPDFLinkService.PDFLinkService;
PDFJS.SimpleLinkService = pdfjsWebPDFLinkService.SimpleLinkService;

788
lib/web/pdf_viewer.js

@ -17,510 +17,71 @@ @@ -17,510 +17,71 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PDFViewer = exports.PresentationModeState = undefined;
exports.PDFViewer = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _pdf = require('../pdf');
var _ui_utils = require('./ui_utils');
var _pdf_rendering_queue = require('./pdf_rendering_queue');
var _annotation_layer_builder = require('./annotation_layer_builder');
var _dom_events = require('./dom_events');
var _base_viewer = require('./base_viewer');
var _pdf_page_view = require('./pdf_page_view');
var _pdf = require('../pdf');
var _pdf_link_service = require('./pdf_link_service');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _text_layer_builder = require('./text_layer_builder');
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var PresentationModeState = {
UNKNOWN: 0,
NORMAL: 1,
CHANGING: 2,
FULLSCREEN: 3
};
var DEFAULT_CACHE_SIZE = 10;
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();
}
};
}
function isSameScale(oldScale, newScale) {
if (newScale === oldScale) {
return true;
}
if (Math.abs(newScale - oldScale) < 1e-15) {
return true;
}
return false;
}
function isPortraitOrientation(size) {
return size.width <= size.height;
}
var PDFViewer = function (_BaseViewer) {
_inherits(PDFViewer, _BaseViewer);
var PDFViewer = function () {
function PDFViewer(options) {
function PDFViewer() {
_classCallCheck(this, PDFViewer);
this.container = options.container;
this.viewer = options.viewer || options.container.firstElementChild;
this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
this.downloadManager = options.downloadManager || null;
this.removePageBorders = options.removePageBorders || false;
this.enhanceTextSelection = options.enhanceTextSelection || false;
this.renderInteractiveForms = options.renderInteractiveForms || false;
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
this.l10n = options.l10n || _ui_utils.NullL10n;
this.defaultRenderingQueue = !options.renderingQueue;
if (this.defaultRenderingQueue) {
this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
this.renderingQueue.setViewer(this);
} else {
this.renderingQueue = options.renderingQueue;
}
this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
this.presentationModeState = PresentationModeState.UNKNOWN;
this._resetView();
if (this.removePageBorders) {
this.viewer.classList.add('removePageBorders');
}
return _possibleConstructorReturn(this, (PDFViewer.__proto__ || Object.getPrototypeOf(PDFViewer)).apply(this, arguments));
}
_createClass(PDFViewer, [{
key: 'getPageView',
value: function getPageView(index) {
return this._pages[index];
}
}, {
key: '_setCurrentPageNumber',
value: function _setCurrentPageNumber(val) {
var resetCurrentPageView = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this._currentPageNumber === val) {
if (resetCurrentPageView) {
this._resetCurrentPageView();
}
return;
}
if (!(0 < val && val <= this.pagesCount)) {
console.error('PDFViewer._setCurrentPageNumber: "' + val + '" is out of bounds.');
return;
}
var arg = {
source: this,
pageNumber: val,
pageLabel: this._pageLabels && this._pageLabels[val - 1]
};
this._currentPageNumber = val;
this.eventBus.dispatch('pagechanging', arg);
this.eventBus.dispatch('pagechange', arg);
if (resetCurrentPageView) {
this._resetCurrentPageView();
}
}
}, {
key: 'setDocument',
value: function setDocument(pdfDocument) {
var _this = this;
if (this.pdfDocument) {
this._cancelRendering();
this._resetView();
}
this.pdfDocument = pdfDocument;
if (!pdfDocument) {
return;
}
var pagesCount = pdfDocument.numPages;
var pagesCapability = (0, _pdf.createPromiseCapability)();
this.pagesPromise = pagesCapability.promise;
pagesCapability.promise.then(function () {
_this._pageViewsReady = true;
_this.eventBus.dispatch('pagesloaded', {
source: _this,
pagesCount: pagesCount
});
});
var isOnePageRenderedResolved = false;
var onePageRenderedCapability = (0, _pdf.createPromiseCapability)();
this.onePageRendered = onePageRenderedCapability.promise;
var bindOnAfterAndBeforeDraw = function bindOnAfterAndBeforeDraw(pageView) {
pageView.onBeforeDraw = function () {
_this._buffer.push(pageView);
};
pageView.onAfterDraw = function () {
if (!isOnePageRenderedResolved) {
isOnePageRenderedResolved = true;
onePageRenderedCapability.resolve();
}
};
};
var firstPagePromise = pdfDocument.getPage(1);
this.firstPagePromise = firstPagePromise;
firstPagePromise.then(function (pdfPage) {
var scale = _this.currentScale;
var viewport = pdfPage.getViewport(scale * _ui_utils.CSS_UNITS);
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
var textLayerFactory = null;
if (!_pdf.PDFJS.disableTextLayer) {
textLayerFactory = _this;
}
var pageView = new _pdf_page_view.PDFPageView({
container: _this.viewer,
eventBus: _this.eventBus,
id: pageNum,
scale: scale,
defaultViewport: viewport.clone(),
renderingQueue: _this.renderingQueue,
textLayerFactory: textLayerFactory,
annotationLayerFactory: _this,
enhanceTextSelection: _this.enhanceTextSelection,
renderInteractiveForms: _this.renderInteractiveForms,
renderer: _this.renderer,
l10n: _this.l10n
});
bindOnAfterAndBeforeDraw(pageView);
_this._pages.push(pageView);
}
onePageRenderedCapability.promise.then(function () {
if (_pdf.PDFJS.disableAutoFetch) {
pagesCapability.resolve();
return;
}
var getPagesLeft = pagesCount;
var _loop = function _loop(_pageNum) {
pdfDocument.getPage(_pageNum).then(function (pdfPage) {
var pageView = _this._pages[_pageNum - 1];
if (!pageView.pdfPage) {
pageView.setPdfPage(pdfPage);
}
_this.linkService.cachePageRef(_pageNum, pdfPage.ref);
if (--getPagesLeft === 0) {
pagesCapability.resolve();
}
}, function (reason) {
console.error('Unable to get page ' + _pageNum + ' to initialize viewer', reason);
if (--getPagesLeft === 0) {
pagesCapability.resolve();
}
});
};
for (var _pageNum = 1; _pageNum <= pagesCount; ++_pageNum) {
_loop(_pageNum);
}
});
_this.eventBus.dispatch('pagesinit', { source: _this });
if (_this.defaultRenderingQueue) {
_this.update();
}
if (_this.findController) {
_this.findController.resolveFirstPage();
}
}).catch(function (reason) {
console.error('Unable to initialize viewer', reason);
});
}
}, {
key: 'setPageLabels',
value: function 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;
}
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);
}
}
}, {
key: '_resetView',
value: function _resetView() {
this._pages = [];
this._currentPageNumber = 1;
this._currentScale = _ui_utils.UNKNOWN_SCALE;
this._currentScaleValue = null;
this._pageLabels = null;
this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
this._location = null;
this._pagesRotation = 0;
this._pagesRequests = [];
this._pageViewsReady = false;
this.viewer.textContent = '';
}
}, {
key: '_scrollUpdate',
value: function _scrollUpdate() {
if (this.pagesCount === 0) {
return;
}
this.update();
}
}, {
key: '_setScaleDispatchEvent',
value: function _setScaleDispatchEvent(newScale, newValue) {
var preset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var arg = {
source: this,
scale: newScale,
presetValue: preset ? newValue : undefined
};
this.eventBus.dispatch('scalechanging', arg);
this.eventBus.dispatch('scalechange', arg);
}
}, {
key: '_setScaleUpdatePages',
value: function _setScaleUpdatePages(newScale, newValue) {
var noScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var preset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
key: '_scrollIntoView',
value: function _scrollIntoView(_ref) {
var pageDiv = _ref.pageDiv,
_ref$pageSpot = _ref.pageSpot,
pageSpot = _ref$pageSpot === undefined ? null : _ref$pageSpot;
this._currentScaleValue = newValue.toString();
if (isSameScale(this._currentScale, newScale)) {
if (preset) {
this._setScaleDispatchEvent(newScale, newValue, true);
}
return;
}
for (var i = 0, ii = this._pages.length; i < ii; i++) {
this._pages[i].update(newScale);
}
this._currentScale = newScale;
if (!noScroll) {
var page = this._currentPageNumber,
dest = void 0;
if (this._location && !_pdf.PDFJS.ignoreCurrentPositionOnZoom && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
page = this._location.pageNumber;
dest = [null, { name: 'XYZ' }, this._location.left, this._location.top, null];
}
this.scrollPageIntoView({
pageNumber: page,
destArray: dest,
allowNegativeOffset: true
});
}
this._setScaleDispatchEvent(newScale, newValue, preset);
if (this.defaultRenderingQueue) {
this.update();
}
(0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
}
}, {
key: '_setScale',
value: function _setScale(value) {
var noScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var scale = parseFloat(value);
if (scale > 0) {
this._setScaleUpdatePages(scale, value, noScroll, false);
} else {
var currentPage = this._pages[this._currentPageNumber - 1];
if (!currentPage) {
return;
}
var hPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
var vPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
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;
var horizontalScale = isLandscape ? Math.min(pageHeightScale, pageWidthScale) : pageWidthScale;
scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
break;
default:
console.error('PDFViewer._setScale: "' + value + '" is an unknown zoom value.');
return;
}
this._setScaleUpdatePages(scale, value, noScroll, true);
}
}
}, {
key: '_resetCurrentPageView',
value: function _resetCurrentPageView() {
if (this.isInPresentationMode) {
this._setScale(this._currentScaleValue, true);
}
var pageView = this._pages[this._currentPageNumber - 1];
(0, _ui_utils.scrollIntoView)(pageView.div);
}
}, {
key: 'scrollPageIntoView',
value: function scrollPageIntoView(params) {
if (arguments.length > 1 || typeof params === 'number') {
console.error('Call of scrollPageIntoView() with obsolete signature.');
return;
}
if (!this.pdfDocument) {
return;
}
var pageNumber = params.pageNumber || 0;
var dest = params.destArray || null;
var allowNegativeOffset = params.allowNegativeOffset || false;
if (this.isInPresentationMode || !dest) {
this._setCurrentPageNumber(pageNumber, true);
return;
}
var pageView = this._pages[pageNumber - 1];
if (!pageView) {
console.error('PDFViewer.scrollPageIntoView: Invalid "pageNumber" parameter.');
return;
}
var x = 0,
y = 0;
var width = 0,
height = 0,
widthScale = void 0,
heightScale = void 0;
var changeOrientation = pageView.rotation % 180 === 0 ? false : true;
var pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
var pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
var scale = 0;
switch (dest[1].name) {
case 'XYZ':
x = dest[2];
y = dest[3];
scale = dest[4];
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';
if (y === null && this._location) {
x = this._location.left;
y = this._location.top;
}
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;
var hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
var vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
break;
default:
console.error('PDFViewer.scrollPageIntoView: "' + dest[1].name + '" ' + 'is not a valid destination type.');
return;
}
if (scale && scale !== this._currentScale) {
this.currentScaleValue = scale;
} else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
}
if (scale === 'page-fit' && !dest[4]) {
(0, _ui_utils.scrollIntoView)(pageView.div);
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]);
if (!allowNegativeOffset) {
left = Math.max(left, 0);
top = Math.max(top, 0);
key: '_getVisiblePages',
value: function _getVisiblePages() {
if (!this.isInPresentationMode) {
return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true);
}
(0, _ui_utils.scrollIntoView)(pageView.div, {
left: left,
top: top
});
}
}, {
key: '_updateLocation',
value: function _updateLocation(firstPage) {
var currentScale = this._currentScale;
var currentScaleValue = this._currentScaleValue;
var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
var pageNumber = firstPage.id;
var pdfOpenParams = '#page=' + pageNumber;
pdfOpenParams += '&zoom=' + normalizedScaleValue;
var currentPageView = this._pages[pageNumber - 1];
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;
this._location = {
pageNumber: pageNumber,
scale: normalizedScaleValue,
top: intTop,
left: intLeft,
rotation: this._pagesRotation,
pdfOpenParams: pdfOpenParams
var currentPage = this._pages[this._currentPageNumber - 1];
var visible = [{
id: currentPage.id,
view: currentPage
}];
return {
first: currentPage,
last: currentPage,
views: visible
};
}
}, {
key: 'update',
value: function update() {
var visible = this._getVisiblePages();
var visiblePages = visible.views;
if (visiblePages.length === 0) {
var visiblePages = visible.views,
numVisiblePages = visiblePages.length;
if (numVisiblePages === 0) {
return;
}
var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * visiblePages.length + 1);
this._buffer.resize(suggestedCacheSize);
this._resizeBuffer(numVisiblePages);
this.renderingQueue.renderHighestPriority(visible);
var currentId = this._currentPageNumber;
var firstPage = visible.first;
var stillFullyVisible = false;
for (var i = 0, ii = visiblePages.length; i < ii; ++i) {
for (var i = 0; i < numVisiblePages; ++i) {
var page = visiblePages[i];
if (page.percent < 100) {
break;
@ -536,293 +97,20 @@ var PDFViewer = function () { @@ -536,293 +97,20 @@ var PDFViewer = function () {
if (!this.isInPresentationMode) {
this._setCurrentPageNumber(currentId);
}
this._updateLocation(firstPage);
this._updateLocation(visible.first);
this.eventBus.dispatch('updateviewarea', {
source: this,
location: this._location
});
}
}, {
key: 'containsElement',
value: function containsElement(element) {
return this.container.contains(element);
}
}, {
key: 'focus',
value: function focus() {
this.container.focus();
}
}, {
key: '_getVisiblePages',
value: function _getVisiblePages() {
if (!this.isInPresentationMode) {
return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true);
}
var visible = [];
var currentPage = this._pages[this._currentPageNumber - 1];
visible.push({
id: currentPage.id,
view: currentPage
});
return {
first: currentPage,
last: currentPage,
views: visible
};
}
}, {
key: 'cleanup',
value: function cleanup() {
for (var i = 0, ii = this._pages.length; i < ii; i++) {
if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
this._pages[i].reset();
}
}
}
}, {
key: '_cancelRendering',
value: function _cancelRendering() {
for (var i = 0, ii = this._pages.length; i < ii; i++) {
if (this._pages[i]) {
this._pages[i].cancelRendering();
}
}
}
}, {
key: '_ensurePdfPageLoaded',
value: function _ensurePdfPageLoaded(pageView) {
var _this2 = this;
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) {
if (!pageView.pdfPage) {
pageView.setPdfPage(pdfPage);
}
_this2._pagesRequests[pageNumber] = null;
return pdfPage;
}).catch(function (reason) {
console.error('Unable to get page for page view', reason);
_this2._pagesRequests[pageNumber] = null;
});
this._pagesRequests[pageNumber] = promise;
return promise;
}
}, {
key: 'forceRendering',
value: function forceRendering(currentlyVisiblePages) {
var _this3 = this;
var visiblePages = currentlyVisiblePages || this._getVisiblePages();
var pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, this.scroll.down);
if (pageView) {
this._ensurePdfPageLoaded(pageView).then(function () {
_this3.renderingQueue.renderView(pageView);
});
return true;
}
return false;
}
}, {
key: 'getPageTextContent',
value: function getPageTextContent(pageIndex) {
return this.pdfDocument.getPage(pageIndex + 1).then(function (page) {
return page.getTextContent({ normalizeWhitespace: true });
});
}
}, {
key: 'createTextLayerBuilder',
value: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
return new _text_layer_builder.TextLayerBuilder({
textLayerDiv: textLayerDiv,
eventBus: this.eventBus,
pageIndex: pageIndex,
viewport: viewport,
findController: this.isInPresentationMode ? null : this.findController,
enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
});
}
}, {
key: 'createAnnotationLayerBuilder',
value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
return new _annotation_layer_builder.AnnotationLayerBuilder({
pageDiv: pageDiv,
pdfPage: pdfPage,
renderInteractiveForms: renderInteractiveForms,
linkService: this.linkService,
downloadManager: this.downloadManager,
l10n: l10n
});
}
}, {
key: 'setFindController',
value: function setFindController(findController) {
this.findController = findController;
}
}, {
key: 'getPagesOverview',
value: function getPagesOverview() {
var pagesOverview = this._pages.map(function (pageView) {
var viewport = pageView.pdfPage.getViewport(1);
return {
width: viewport.width,
height: viewport.height,
rotation: viewport.rotation
};
});
if (!this.enablePrintAutoRotate) {
return pagesOverview;
}
var isFirstPagePortrait = isPortraitOrientation(pagesOverview[0]);
return pagesOverview.map(function (size) {
if (isFirstPagePortrait === isPortraitOrientation(size)) {
return size;
}
return {
width: size.height,
height: size.width,
rotation: (size.rotation + 90) % 360
};
});
}
}, {
key: 'pagesCount',
get: function get() {
return this._pages.length;
}
}, {
key: 'pageViewsReady',
get: function get() {
return this._pageViewsReady;
}
}, {
key: 'currentPageNumber',
key: '_setDocumentViewerElement',
get: function get() {
return this._currentPageNumber;
},
set: function set(val) {
if (!Number.isInteger(val)) {
throw new Error('Invalid page number.');
}
if (!this.pdfDocument) {
return;
}
this._setCurrentPageNumber(val, true);
}
}, {
key: 'currentPageLabel',
get: function get() {
return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
},
set: function set(val) {
var pageNumber = val | 0;
if (this._pageLabels) {
var i = this._pageLabels.indexOf(val);
if (i >= 0) {
pageNumber = i + 1;
}
}
this.currentPageNumber = pageNumber;
}
}, {
key: 'currentScale',
get: function get() {
return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
},
set: function set(val) {
if (isNaN(val)) {
throw new Error('Invalid numeric scale');
}
if (!this.pdfDocument) {
return;
}
this._setScale(val, false);
}
}, {
key: 'currentScaleValue',
get: function get() {
return this._currentScaleValue;
},
set: function set(val) {
if (!this.pdfDocument) {
return;
}
this._setScale(val, false);
}
}, {
key: 'pagesRotation',
get: function get() {
return this._pagesRotation;
},
set: function set(rotation) {
if (!(0, _ui_utils.isValidRotation)(rotation)) {
throw new Error('Invalid pages rotation angle.');
}
if (!this.pdfDocument) {
return;
}
if (this._pagesRotation === rotation) {
return;
}
this._pagesRotation = rotation;
var pageNumber = this._currentPageNumber;
for (var i = 0, ii = this._pages.length; i < ii; i++) {
var pageView = this._pages[i];
pageView.update(pageView.scale, rotation);
}
if (this._currentScaleValue) {
this._setScale(this._currentScaleValue, true);
}
this.eventBus.dispatch('rotationchanging', {
source: this,
pagesRotation: rotation,
pageNumber: pageNumber
});
if (this.defaultRenderingQueue) {
this.update();
}
}
}, {
key: 'isInPresentationMode',
get: function get() {
return this.presentationModeState === PresentationModeState.FULLSCREEN;
}
}, {
key: 'isChangingPresentationMode',
get: function get() {
return this.presentationModeState === PresentationModeState.CHANGING;
}
}, {
key: 'isHorizontalScrollbarEnabled',
get: function get() {
return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
}
}, {
key: 'hasEqualPageSizes',
get: function get() {
var firstPageView = this._pages[0];
for (var i = 1, ii = this._pages.length; i < ii; ++i) {
var pageView = this._pages[i];
if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
return false;
}
}
return true;
return (0, _pdf.shadow)(this, '_setDocumentViewerElement', this.viewer);
}
}]);
return PDFViewer;
}();
}(_base_viewer.BaseViewer);
exports.PresentationModeState = PresentationModeState;
exports.PDFViewer = PDFViewer;

9
lib/web/ui_utils.js

@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.waitOnEventOrTimeout = exports.WaitOnType = exports.localized = exports.animationStarted = exports.normalizeWheelEventDelta = exports.binarySearchFirstItem = exports.watchScroll = exports.scrollIntoView = exports.getOutputScale = exports.approximateFraction = exports.roundToDivide = exports.getVisibleElements = exports.parseQueryString = exports.noContextMenuHandler = exports.getPDFFileNameFromURL = exports.ProgressBar = exports.EventBus = exports.NullL10n = exports.mozL10n = exports.RendererType = exports.cloneObj = exports.isValidRotation = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = undefined;
exports.waitOnEventOrTimeout = exports.WaitOnType = exports.localized = exports.animationStarted = exports.normalizeWheelEventDelta = exports.binarySearchFirstItem = exports.watchScroll = exports.scrollIntoView = exports.getOutputScale = exports.approximateFraction = exports.roundToDivide = exports.getVisibleElements = exports.parseQueryString = exports.noContextMenuHandler = exports.getPDFFileNameFromURL = exports.ProgressBar = exports.EventBus = exports.NullL10n = exports.mozL10n = exports.RendererType = exports.PresentationModeState = exports.cloneObj = exports.isValidRotation = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@ -36,6 +36,12 @@ var UNKNOWN_SCALE = 0; @@ -36,6 +36,12 @@ var UNKNOWN_SCALE = 0;
var MAX_AUTO_SCALE = 1.25;
var SCROLLBAR_PADDING = 40;
var VERTICAL_PADDING = 5;
var PresentationModeState = {
UNKNOWN: 0,
NORMAL: 1,
CHANGING: 2,
FULLSCREEN: 3
};
var RendererType = {
CANVAS: 'canvas',
SVG: 'svg'
@ -507,6 +513,7 @@ exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING; @@ -507,6 +513,7 @@ exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
exports.VERTICAL_PADDING = VERTICAL_PADDING;
exports.isValidRotation = isValidRotation;
exports.cloneObj = cloneObj;
exports.PresentationModeState = PresentationModeState;
exports.RendererType = RendererType;
exports.mozL10n = mozL10n;
exports.NullL10n = NullL10n;

2
package.json

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"name": "pdfjs-dist",
"version": "1.9.593",
"version": "1.9.597",
"main": "build/pdf.js",
"description": "Generic build of Mozilla's PDF.js library.",
"keywords": [

3644
web/pdf_viewer.js

File diff suppressed because it is too large Load Diff

2
web/pdf_viewer.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save