|
|
@ -19,14 +19,19 @@ Object.defineProperty(exports, "__esModule", { |
|
|
|
}); |
|
|
|
}); |
|
|
|
exports.PDFThumbnailView = undefined; |
|
|
|
exports.PDFThumbnailView = 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 _pdf = require('../pdf'); |
|
|
|
|
|
|
|
|
|
|
|
var _ui_utils = require('./ui_utils'); |
|
|
|
var _ui_utils = require('./ui_utils'); |
|
|
|
|
|
|
|
|
|
|
|
var _pdf_rendering_queue = require('./pdf_rendering_queue'); |
|
|
|
var _pdf_rendering_queue = require('./pdf_rendering_queue'); |
|
|
|
|
|
|
|
|
|
|
|
var THUMBNAIL_WIDTH = 98; |
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var MAX_NUM_SCALING_STEPS = 3; |
|
|
|
var THUMBNAIL_CANVAS_BORDER_WIDTH = 1; |
|
|
|
var THUMBNAIL_CANVAS_BORDER_WIDTH = 1; |
|
|
|
|
|
|
|
var THUMBNAIL_WIDTH = 98; |
|
|
|
var TempImageFactory = function TempImageFactoryClosure() { |
|
|
|
var TempImageFactory = function TempImageFactoryClosure() { |
|
|
|
var tempCanvasCache = null; |
|
|
|
var tempCanvasCache = null; |
|
|
|
return { |
|
|
|
return { |
|
|
@ -56,14 +61,21 @@ var TempImageFactory = function TempImageFactoryClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
}(); |
|
|
|
}(); |
|
|
|
var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
|
|
|
|
function PDFThumbnailView(options) { |
|
|
|
var PDFThumbnailView = function () { |
|
|
|
var container = options.container; |
|
|
|
function PDFThumbnailView(_ref) { |
|
|
|
var id = options.id; |
|
|
|
var container = _ref.container, |
|
|
|
var defaultViewport = options.defaultViewport; |
|
|
|
id = _ref.id, |
|
|
|
var linkService = options.linkService; |
|
|
|
defaultViewport = _ref.defaultViewport, |
|
|
|
var renderingQueue = options.renderingQueue; |
|
|
|
linkService = _ref.linkService, |
|
|
|
var disableCanvasToImageConversion = options.disableCanvasToImageConversion || false; |
|
|
|
renderingQueue = _ref.renderingQueue, |
|
|
|
|
|
|
|
_ref$disableCanvasToI = _ref.disableCanvasToImageConversion, |
|
|
|
|
|
|
|
disableCanvasToImageConversion = _ref$disableCanvasToI === undefined ? false : _ref$disableCanvasToI, |
|
|
|
|
|
|
|
_ref$l10n = _ref.l10n, |
|
|
|
|
|
|
|
l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_classCallCheck(this, PDFThumbnailView); |
|
|
|
|
|
|
|
|
|
|
|
this.id = id; |
|
|
|
this.id = id; |
|
|
|
this.renderingId = 'thumbnail' + id; |
|
|
|
this.renderingId = 'thumbnail' + id; |
|
|
|
this.pageLabel = null; |
|
|
|
this.pageLabel = null; |
|
|
@ -83,13 +95,13 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
this.canvasWidth = THUMBNAIL_WIDTH; |
|
|
|
this.canvasWidth = THUMBNAIL_WIDTH; |
|
|
|
this.canvasHeight = this.canvasWidth / this.pageRatio | 0; |
|
|
|
this.canvasHeight = this.canvasWidth / this.pageRatio | 0; |
|
|
|
this.scale = this.canvasWidth / this.pageWidth; |
|
|
|
this.scale = this.canvasWidth / this.pageWidth; |
|
|
|
this.l10n = options.l10n || _ui_utils.NullL10n; |
|
|
|
this.l10n = l10n; |
|
|
|
var anchor = document.createElement('a'); |
|
|
|
var anchor = document.createElement('a'); |
|
|
|
anchor.href = linkService.getAnchorUrl('#page=' + id); |
|
|
|
anchor.href = linkService.getAnchorUrl('#page=' + id); |
|
|
|
this.l10n.get('thumb_page_title', { page: id }, 'Page {{page}}').then(function (msg) { |
|
|
|
this.l10n.get('thumb_page_title', { page: id }, 'Page {{page}}').then(function (msg) { |
|
|
|
anchor.title = msg; |
|
|
|
anchor.title = msg; |
|
|
|
}); |
|
|
|
}); |
|
|
|
anchor.onclick = function stopNavigation() { |
|
|
|
anchor.onclick = function () { |
|
|
|
linkService.page = id; |
|
|
|
linkService.page = id; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -111,15 +123,19 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
anchor.appendChild(div); |
|
|
|
anchor.appendChild(div); |
|
|
|
container.appendChild(anchor); |
|
|
|
container.appendChild(anchor); |
|
|
|
} |
|
|
|
} |
|
|
|
PDFThumbnailView.prototype = { |
|
|
|
|
|
|
|
setPdfPage: function PDFThumbnailView_setPdfPage(pdfPage) { |
|
|
|
_createClass(PDFThumbnailView, [{ |
|
|
|
|
|
|
|
key: 'setPdfPage', |
|
|
|
|
|
|
|
value: function setPdfPage(pdfPage) { |
|
|
|
this.pdfPage = pdfPage; |
|
|
|
this.pdfPage = pdfPage; |
|
|
|
this.pdfPageRotate = pdfPage.rotate; |
|
|
|
this.pdfPageRotate = pdfPage.rotate; |
|
|
|
var totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
|
|
|
var totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
|
|
|
this.viewport = pdfPage.getViewport(1, totalRotation); |
|
|
|
this.viewport = pdfPage.getViewport(1, totalRotation); |
|
|
|
this.reset(); |
|
|
|
this.reset(); |
|
|
|
}, |
|
|
|
} |
|
|
|
reset: function PDFThumbnailView_reset() { |
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'reset', |
|
|
|
|
|
|
|
value: function reset() { |
|
|
|
this.cancelRendering(); |
|
|
|
this.cancelRendering(); |
|
|
|
this.pageWidth = this.viewport.width; |
|
|
|
this.pageWidth = this.viewport.width; |
|
|
|
this.pageHeight = this.viewport.height; |
|
|
|
this.pageHeight = this.viewport.height; |
|
|
@ -144,8 +160,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
this.image.removeAttribute('src'); |
|
|
|
this.image.removeAttribute('src'); |
|
|
|
delete this.image; |
|
|
|
delete this.image; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
update: function PDFThumbnailView_update(rotation) { |
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'update', |
|
|
|
|
|
|
|
value: function update(rotation) { |
|
|
|
if (typeof rotation !== 'undefined') { |
|
|
|
if (typeof rotation !== 'undefined') { |
|
|
|
this.rotation = rotation; |
|
|
|
this.rotation = rotation; |
|
|
|
} |
|
|
|
} |
|
|
@ -155,16 +173,22 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
rotation: totalRotation |
|
|
|
rotation: totalRotation |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.reset(); |
|
|
|
this.reset(); |
|
|
|
}, |
|
|
|
} |
|
|
|
cancelRendering: function PDFThumbnailView_cancelRendering() { |
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'cancelRendering', |
|
|
|
|
|
|
|
value: function cancelRendering() { |
|
|
|
if (this.renderTask) { |
|
|
|
if (this.renderTask) { |
|
|
|
this.renderTask.cancel(); |
|
|
|
this.renderTask.cancel(); |
|
|
|
this.renderTask = null; |
|
|
|
this.renderTask = null; |
|
|
|
} |
|
|
|
} |
|
|
|
this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL; |
|
|
|
this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL; |
|
|
|
this.resume = null; |
|
|
|
this.resume = null; |
|
|
|
}, |
|
|
|
} |
|
|
|
_getPageDrawContext: function PDFThumbnailView_getPageDrawContext(noCtxScale) { |
|
|
|
}, { |
|
|
|
|
|
|
|
key: '_getPageDrawContext', |
|
|
|
|
|
|
|
value: function _getPageDrawContext() { |
|
|
|
|
|
|
|
var noCtxScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; |
|
|
|
|
|
|
|
|
|
|
|
var canvas = document.createElement('canvas'); |
|
|
|
var canvas = document.createElement('canvas'); |
|
|
|
this.canvas = canvas; |
|
|
|
this.canvas = canvas; |
|
|
|
canvas.mozOpaque = true; |
|
|
|
canvas.mozOpaque = true; |
|
|
@ -178,8 +202,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
ctx.scale(outputScale.sx, outputScale.sy); |
|
|
|
ctx.scale(outputScale.sx, outputScale.sy); |
|
|
|
} |
|
|
|
} |
|
|
|
return ctx; |
|
|
|
return ctx; |
|
|
|
}, |
|
|
|
} |
|
|
|
_convertCanvasToImage: function PDFThumbnailView_convertCanvasToImage() { |
|
|
|
}, { |
|
|
|
|
|
|
|
key: '_convertCanvasToImage', |
|
|
|
|
|
|
|
value: function _convertCanvasToImage() { |
|
|
|
var _this = this; |
|
|
|
var _this = this; |
|
|
|
|
|
|
|
|
|
|
|
if (!this.canvas) { |
|
|
|
if (!this.canvas) { |
|
|
@ -215,8 +241,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
this.canvas.width = 0; |
|
|
|
this.canvas.width = 0; |
|
|
|
this.canvas.height = 0; |
|
|
|
this.canvas.height = 0; |
|
|
|
delete this.canvas; |
|
|
|
delete this.canvas; |
|
|
|
}, |
|
|
|
} |
|
|
|
draw: function draw() { |
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'draw', |
|
|
|
|
|
|
|
value: function draw() { |
|
|
|
var _this2 = this; |
|
|
|
var _this2 = this; |
|
|
|
|
|
|
|
|
|
|
|
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) { |
|
|
|
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) { |
|
|
@ -266,9 +294,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
finishRenderTask(error); |
|
|
|
finishRenderTask(error); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return renderCapability.promise; |
|
|
|
return renderCapability.promise; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
}, { |
|
|
|
setImage: function PDFThumbnailView_setImage(pageView) { |
|
|
|
key: 'setImage', |
|
|
|
|
|
|
|
value: function setImage(pageView) { |
|
|
|
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) { |
|
|
|
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -287,7 +316,6 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
this._convertCanvasToImage(); |
|
|
|
this._convertCanvasToImage(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var MAX_NUM_SCALING_STEPS = 3; |
|
|
|
|
|
|
|
var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS; |
|
|
|
var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS; |
|
|
|
var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS; |
|
|
|
var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS; |
|
|
|
var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight); |
|
|
|
var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight); |
|
|
@ -304,11 +332,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height); |
|
|
|
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height); |
|
|
|
this._convertCanvasToImage(); |
|
|
|
this._convertCanvasToImage(); |
|
|
|
}, |
|
|
|
} |
|
|
|
get pageId() { |
|
|
|
}, { |
|
|
|
return this.pageLabel !== null ? this.pageLabel : this.id; |
|
|
|
key: 'setPageLabel', |
|
|
|
}, |
|
|
|
value: function setPageLabel(label) { |
|
|
|
setPageLabel: function PDFThumbnailView_setPageLabel(label) { |
|
|
|
|
|
|
|
var _this3 = this; |
|
|
|
var _this3 = this; |
|
|
|
|
|
|
|
|
|
|
|
this.pageLabel = typeof label === 'string' ? label : null; |
|
|
|
this.pageLabel = typeof label === 'string' ? label : null; |
|
|
@ -326,10 +353,19 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}, { |
|
|
|
PDFThumbnailView.cleanup = function () { |
|
|
|
key: 'pageId', |
|
|
|
|
|
|
|
get: function get() { |
|
|
|
|
|
|
|
return this.pageLabel !== null ? this.pageLabel : this.id; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}], [{ |
|
|
|
|
|
|
|
key: 'cleanup', |
|
|
|
|
|
|
|
value: function cleanup() { |
|
|
|
TempImageFactory.destroyCanvas(); |
|
|
|
TempImageFactory.destroyCanvas(); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
}]); |
|
|
|
|
|
|
|
|
|
|
|
return PDFThumbnailView; |
|
|
|
return PDFThumbnailView; |
|
|
|
}(); |
|
|
|
}(); |
|
|
|
|
|
|
|
|
|
|
|
exports.PDFThumbnailView = PDFThumbnailView; |
|
|
|
exports.PDFThumbnailView = PDFThumbnailView; |