2013-08-07 05:19:03 +09:00
|
|
|
/* Copyright 2012 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.
|
|
|
|
*/
|
|
|
|
|
2017-04-15 19:57:54 +09:00
|
|
|
import { createPromiseCapability, RenderingCancelledException } from './pdfjs';
|
2017-04-15 00:32:36 +09:00
|
|
|
import { getOutputScale, mozL10n } from './ui_utils';
|
|
|
|
import { RenderingStates } from './pdf_rendering_queue';
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
var THUMBNAIL_WIDTH = 98; // px
|
|
|
|
var THUMBNAIL_CANVAS_BORDER_WIDTH = 1; // px
|
2014-09-16 05:46:01 +09:00
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
2015-01-25 00:27:31 +09:00
|
|
|
* @typedef {Object} PDFThumbnailViewOptions
|
|
|
|
* @property {HTMLDivElement} container - The viewer element.
|
|
|
|
* @property {number} id - The thumbnail's unique ID (normally its number).
|
|
|
|
* @property {PageViewport} defaultViewport - The page viewport.
|
|
|
|
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
|
|
|
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
2015-09-12 18:32:18 +09:00
|
|
|
* @property {boolean} disableCanvasToImageConversion - (optional) Don't convert
|
|
|
|
* the canvas thumbnails to images. This prevents `toDataURL` calls,
|
|
|
|
* but increases the overall memory usage. The default value is false.
|
2014-09-21 02:21:49 +09:00
|
|
|
*/
|
2013-08-07 05:19:03 +09:00
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
* @implements {IRenderableView}
|
|
|
|
*/
|
|
|
|
var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
2014-06-13 00:28:42 +09:00
|
|
|
function getTempCanvas(width, height) {
|
2015-01-25 00:27:31 +09:00
|
|
|
var tempCanvas = PDFThumbnailView.tempImageCache;
|
2014-06-13 00:28:42 +09:00
|
|
|
if (!tempCanvas) {
|
|
|
|
tempCanvas = document.createElement('canvas');
|
2015-01-25 00:27:31 +09:00
|
|
|
PDFThumbnailView.tempImageCache = tempCanvas;
|
2014-06-13 00:28:42 +09:00
|
|
|
}
|
|
|
|
tempCanvas.width = width;
|
|
|
|
tempCanvas.height = height;
|
2015-01-20 06:01:55 +09:00
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
// Since this is a temporary canvas, we need to fill the canvas with a white
|
2015-09-12 18:32:18 +09:00
|
|
|
// background ourselves. `_getPageDrawContext` uses CSS rules for this.
|
2016-10-15 00:57:53 +09:00
|
|
|
if (typeof PDFJSDev === 'undefined' ||
|
|
|
|
PDFJSDev.test('MOZCENTRAL || FIREFOX || GENERIC')) {
|
|
|
|
tempCanvas.mozOpaque = true;
|
|
|
|
}
|
|
|
|
|
2015-11-17 01:50:02 +09:00
|
|
|
var ctx = tempCanvas.getContext('2d', {alpha: false});
|
2015-01-20 06:01:55 +09:00
|
|
|
ctx.save();
|
|
|
|
ctx.fillStyle = 'rgb(255, 255, 255)';
|
|
|
|
ctx.fillRect(0, 0, width, height);
|
|
|
|
ctx.restore();
|
2014-06-13 00:28:42 +09:00
|
|
|
return tempCanvas;
|
|
|
|
}
|
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
/**
|
|
|
|
* @constructs PDFThumbnailView
|
|
|
|
* @param {PDFThumbnailViewOptions} options
|
|
|
|
*/
|
|
|
|
function PDFThumbnailView(options) {
|
|
|
|
var container = options.container;
|
|
|
|
var id = options.id;
|
|
|
|
var defaultViewport = options.defaultViewport;
|
|
|
|
var linkService = options.linkService;
|
|
|
|
var renderingQueue = options.renderingQueue;
|
2015-09-12 18:32:18 +09:00
|
|
|
var disableCanvasToImageConversion =
|
|
|
|
options.disableCanvasToImageConversion || false;
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
this.id = id;
|
|
|
|
this.renderingId = 'thumbnail' + id;
|
2016-01-27 22:27:01 +09:00
|
|
|
this.pageLabel = null;
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
this.pdfPage = null;
|
|
|
|
this.rotation = 0;
|
2015-01-25 00:27:31 +09:00
|
|
|
this.viewport = defaultViewport;
|
|
|
|
this.pdfPageRotate = defaultViewport.rotation;
|
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
this.linkService = linkService;
|
|
|
|
this.renderingQueue = renderingQueue;
|
|
|
|
|
2016-07-30 03:39:22 +09:00
|
|
|
this.renderTask = null;
|
2015-01-25 21:27:11 +09:00
|
|
|
this.renderingState = RenderingStates.INITIAL;
|
2016-07-30 03:39:22 +09:00
|
|
|
this.resume = null;
|
2015-09-12 18:32:18 +09:00
|
|
|
this.disableCanvasToImageConversion = disableCanvasToImageConversion;
|
2015-01-25 21:27:11 +09:00
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
this.pageWidth = this.viewport.width;
|
|
|
|
this.pageHeight = this.viewport.height;
|
|
|
|
this.pageRatio = this.pageWidth / this.pageHeight;
|
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
this.canvasWidth = THUMBNAIL_WIDTH;
|
2015-01-25 00:27:31 +09:00
|
|
|
this.canvasHeight = (this.canvasWidth / this.pageRatio) | 0;
|
|
|
|
this.scale = this.canvasWidth / this.pageWidth;
|
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
var anchor = document.createElement('a');
|
|
|
|
anchor.href = linkService.getAnchorUrl('#page=' + id);
|
|
|
|
anchor.title = mozL10n.get('thumb_page_title', {page: id}, 'Page {{page}}');
|
|
|
|
anchor.onclick = function stopNavigation() {
|
|
|
|
linkService.page = id;
|
|
|
|
return false;
|
|
|
|
};
|
2016-01-27 22:27:01 +09:00
|
|
|
this.anchor = anchor;
|
2015-01-25 21:27:11 +09:00
|
|
|
|
|
|
|
var div = document.createElement('div');
|
2015-01-25 00:27:31 +09:00
|
|
|
div.className = 'thumbnail';
|
2017-01-19 09:02:11 +09:00
|
|
|
div.setAttribute('data-page-number', this.id);
|
2015-01-25 00:27:31 +09:00
|
|
|
this.div = div;
|
|
|
|
|
|
|
|
if (id === 1) {
|
|
|
|
// Highlight the thumbnail of the first page when no page number is
|
|
|
|
// specified (or exists in cache) when the document is loaded.
|
|
|
|
div.classList.add('selected');
|
2014-09-29 22:11:46 +09:00
|
|
|
}
|
2015-01-25 00:27:31 +09:00
|
|
|
|
|
|
|
var ring = document.createElement('div');
|
|
|
|
ring.className = 'thumbnailSelectionRing';
|
2015-01-25 21:27:11 +09:00
|
|
|
var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
|
|
|
ring.style.width = this.canvasWidth + borderAdjustment + 'px';
|
|
|
|
ring.style.height = this.canvasHeight + borderAdjustment + 'px';
|
2015-01-25 00:27:31 +09:00
|
|
|
this.ring = ring;
|
|
|
|
|
|
|
|
div.appendChild(ring);
|
|
|
|
anchor.appendChild(div);
|
|
|
|
container.appendChild(anchor);
|
|
|
|
}
|
|
|
|
|
|
|
|
PDFThumbnailView.prototype = {
|
|
|
|
setPdfPage: function PDFThumbnailView_setPdfPage(pdfPage) {
|
|
|
|
this.pdfPage = pdfPage;
|
|
|
|
this.pdfPageRotate = pdfPage.rotate;
|
|
|
|
var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
|
|
|
this.viewport = pdfPage.getViewport(1, totalRotation);
|
2015-01-25 21:27:11 +09:00
|
|
|
this.reset();
|
2015-01-25 00:27:31 +09:00
|
|
|
},
|
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
reset: function PDFThumbnailView_reset() {
|
2016-07-30 03:39:22 +09:00
|
|
|
this.cancelRendering();
|
2015-01-25 21:27:11 +09:00
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
this.pageWidth = this.viewport.width;
|
|
|
|
this.pageHeight = this.viewport.height;
|
|
|
|
this.pageRatio = this.pageWidth / this.pageHeight;
|
|
|
|
|
|
|
|
this.canvasHeight = (this.canvasWidth / this.pageRatio) | 0;
|
|
|
|
this.scale = (this.canvasWidth / this.pageWidth);
|
|
|
|
|
|
|
|
this.div.removeAttribute('data-loaded');
|
2015-01-25 21:27:11 +09:00
|
|
|
var ring = this.ring;
|
|
|
|
var childNodes = ring.childNodes;
|
|
|
|
for (var i = childNodes.length - 1; i >= 0; i--) {
|
|
|
|
ring.removeChild(childNodes[i]);
|
|
|
|
}
|
|
|
|
var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
|
|
|
ring.style.width = this.canvasWidth + borderAdjustment + 'px';
|
|
|
|
ring.style.height = this.canvasHeight + borderAdjustment + 'px';
|
|
|
|
|
|
|
|
if (this.canvas) {
|
|
|
|
// Zeroing the width and height causes Firefox to release graphics
|
|
|
|
// resources immediately, which can greatly reduce memory consumption.
|
|
|
|
this.canvas.width = 0;
|
|
|
|
this.canvas.height = 0;
|
|
|
|
delete this.canvas;
|
|
|
|
}
|
2015-09-11 20:42:10 +09:00
|
|
|
if (this.image) {
|
|
|
|
this.image.removeAttribute('src');
|
|
|
|
delete this.image;
|
|
|
|
}
|
2015-01-25 21:27:11 +09:00
|
|
|
},
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
update: function PDFThumbnailView_update(rotation) {
|
|
|
|
if (typeof rotation !== 'undefined') {
|
|
|
|
this.rotation = rotation;
|
|
|
|
}
|
|
|
|
var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
|
|
|
this.viewport = this.viewport.clone({
|
|
|
|
scale: 1,
|
|
|
|
rotation: totalRotation
|
|
|
|
});
|
|
|
|
this.reset();
|
2015-01-25 00:27:31 +09:00
|
|
|
},
|
|
|
|
|
2016-07-30 03:39:22 +09:00
|
|
|
cancelRendering: function PDFThumbnailView_cancelRendering() {
|
|
|
|
if (this.renderTask) {
|
|
|
|
this.renderTask.cancel();
|
|
|
|
this.renderTask = null;
|
|
|
|
}
|
|
|
|
this.renderingState = RenderingStates.INITIAL;
|
|
|
|
this.resume = null;
|
|
|
|
},
|
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2015-05-16 22:18:36 +09:00
|
|
|
_getPageDrawContext:
|
|
|
|
function PDFThumbnailView_getPageDrawContext(noCtxScale) {
|
2015-01-25 00:27:31 +09:00
|
|
|
var canvas = document.createElement('canvas');
|
2015-09-12 18:32:18 +09:00
|
|
|
// Keep the no-thumbnail outline visible, i.e. `data-loaded === false`,
|
|
|
|
// until rendering/image conversion is complete, to avoid display issues.
|
2015-01-25 21:27:11 +09:00
|
|
|
this.canvas = canvas;
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2016-10-15 00:57:53 +09:00
|
|
|
if (typeof PDFJSDev === 'undefined' ||
|
|
|
|
PDFJSDev.test('MOZCENTRAL || FIREFOX || GENERIC')) {
|
|
|
|
canvas.mozOpaque = true;
|
|
|
|
}
|
2015-11-17 01:50:02 +09:00
|
|
|
var ctx = canvas.getContext('2d', {alpha: false});
|
2015-05-16 22:18:36 +09:00
|
|
|
var outputScale = getOutputScale(ctx);
|
2015-09-11 20:11:49 +09:00
|
|
|
|
2015-05-16 22:18:36 +09:00
|
|
|
canvas.width = (this.canvasWidth * outputScale.sx) | 0;
|
|
|
|
canvas.height = (this.canvasHeight * outputScale.sy) | 0;
|
|
|
|
canvas.style.width = this.canvasWidth + 'px';
|
|
|
|
canvas.style.height = this.canvasHeight + 'px';
|
2015-09-11 20:11:49 +09:00
|
|
|
|
2015-05-16 22:18:36 +09:00
|
|
|
if (!noCtxScale && outputScale.scaled) {
|
|
|
|
ctx.scale(outputScale.sx, outputScale.sy);
|
|
|
|
}
|
|
|
|
return ctx;
|
2015-01-25 00:27:31 +09:00
|
|
|
},
|
|
|
|
|
2015-09-11 20:11:49 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_convertCanvasToImage: function PDFThumbnailView_convertCanvasToImage() {
|
2015-09-12 18:51:25 +09:00
|
|
|
if (!this.canvas) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-12 18:32:18 +09:00
|
|
|
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var id = this.renderingId;
|
|
|
|
var className = 'thumbnailImage';
|
2016-01-27 22:27:01 +09:00
|
|
|
var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.pageId },
|
2015-09-12 18:32:18 +09:00
|
|
|
'Thumbnail of Page {{page}}');
|
|
|
|
|
|
|
|
if (this.disableCanvasToImageConversion) {
|
|
|
|
this.canvas.id = id;
|
|
|
|
this.canvas.className = className;
|
|
|
|
this.canvas.setAttribute('aria-label', ariaLabel);
|
|
|
|
|
|
|
|
this.div.setAttribute('data-loaded', true);
|
|
|
|
this.ring.appendChild(this.canvas);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var image = document.createElement('img');
|
|
|
|
image.id = id;
|
|
|
|
image.className = className;
|
|
|
|
image.setAttribute('aria-label', ariaLabel);
|
|
|
|
|
|
|
|
image.style.width = this.canvasWidth + 'px';
|
|
|
|
image.style.height = this.canvasHeight + 'px';
|
|
|
|
|
|
|
|
image.src = this.canvas.toDataURL();
|
|
|
|
this.image = image;
|
2015-09-12 18:51:25 +09:00
|
|
|
|
|
|
|
this.div.setAttribute('data-loaded', true);
|
2015-09-12 18:32:18 +09:00
|
|
|
this.ring.appendChild(image);
|
2015-09-12 18:51:25 +09:00
|
|
|
|
|
|
|
// Zeroing the width and height causes Firefox to release graphics
|
|
|
|
// resources immediately, which can greatly reduce memory consumption.
|
|
|
|
this.canvas.width = 0;
|
|
|
|
this.canvas.height = 0;
|
|
|
|
delete this.canvas;
|
2015-09-11 20:11:49 +09:00
|
|
|
},
|
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
draw: function PDFThumbnailView_draw() {
|
|
|
|
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
|
|
console.error('Must be in new state before drawing');
|
|
|
|
return Promise.resolve(undefined);
|
|
|
|
}
|
2016-02-26 00:47:51 +09:00
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
this.renderingState = RenderingStates.RUNNING;
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2017-04-15 19:57:54 +09:00
|
|
|
var renderCapability = createPromiseCapability();
|
2015-01-25 00:27:31 +09:00
|
|
|
|
|
|
|
var self = this;
|
2015-01-26 00:59:57 +09:00
|
|
|
function thumbnailDrawCallback(error) {
|
|
|
|
// The renderTask may have been replaced by a new one, so only remove
|
|
|
|
// the reference to the renderTask if it matches the one that is
|
|
|
|
// triggering this callback.
|
|
|
|
if (renderTask === self.renderTask) {
|
|
|
|
self.renderTask = null;
|
|
|
|
}
|
2017-04-15 04:06:33 +09:00
|
|
|
|
|
|
|
if (((typeof PDFJSDev === 'undefined' ||
|
|
|
|
!PDFJSDev.test('PDFJS_NEXT')) && error === 'cancelled') ||
|
|
|
|
error instanceof RenderingCancelledException) {
|
2017-04-15 19:57:54 +09:00
|
|
|
renderCapability.resolve(undefined);
|
2015-01-26 00:59:57 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-02-26 00:47:51 +09:00
|
|
|
|
2015-01-26 00:59:57 +09:00
|
|
|
self.renderingState = RenderingStates.FINISHED;
|
2015-09-11 20:11:49 +09:00
|
|
|
self._convertCanvasToImage();
|
2015-01-26 00:59:57 +09:00
|
|
|
|
|
|
|
if (!error) {
|
2017-04-15 19:57:54 +09:00
|
|
|
renderCapability.resolve(undefined);
|
2015-01-26 00:59:57 +09:00
|
|
|
} else {
|
2017-04-15 19:57:54 +09:00
|
|
|
renderCapability.reject(error);
|
2015-01-26 00:59:57 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
var ctx = this._getPageDrawContext();
|
2015-01-25 00:27:31 +09:00
|
|
|
var drawViewport = this.viewport.clone({ scale: this.scale });
|
2015-01-26 00:59:57 +09:00
|
|
|
var renderContinueCallback = function renderContinueCallback(cont) {
|
|
|
|
if (!self.renderingQueue.isHighestPriority(self)) {
|
|
|
|
self.renderingState = RenderingStates.PAUSED;
|
|
|
|
self.resume = function resumeCallback() {
|
|
|
|
self.renderingState = RenderingStates.RUNNING;
|
|
|
|
cont();
|
|
|
|
};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cont();
|
|
|
|
};
|
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
var renderContext = {
|
|
|
|
canvasContext: ctx,
|
2015-10-21 22:54:31 +09:00
|
|
|
viewport: drawViewport
|
2015-01-25 00:27:31 +09:00
|
|
|
};
|
2015-01-26 00:59:57 +09:00
|
|
|
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
|
2015-10-21 22:54:31 +09:00
|
|
|
renderTask.onContinue = renderContinueCallback;
|
2015-01-26 00:59:57 +09:00
|
|
|
|
|
|
|
renderTask.promise.then(
|
2015-01-25 00:27:31 +09:00
|
|
|
function pdfPageRenderCallback() {
|
2015-01-26 00:59:57 +09:00
|
|
|
thumbnailDrawCallback(null);
|
2015-01-25 00:27:31 +09:00
|
|
|
},
|
|
|
|
function pdfPageRenderError(error) {
|
2015-01-26 00:59:57 +09:00
|
|
|
thumbnailDrawCallback(error);
|
2015-01-25 00:27:31 +09:00
|
|
|
}
|
|
|
|
);
|
2017-04-15 19:57:54 +09:00
|
|
|
return renderCapability.promise;
|
2015-01-25 00:27:31 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
setImage: function PDFThumbnailView_setImage(pageView) {
|
2016-02-26 00:47:51 +09:00
|
|
|
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-25 00:27:31 +09:00
|
|
|
var img = pageView.canvas;
|
2016-02-26 00:47:51 +09:00
|
|
|
if (!img) {
|
2015-01-25 00:27:31 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!this.pdfPage) {
|
|
|
|
this.setPdfPage(pageView.pdfPage);
|
|
|
|
}
|
2016-02-26 00:47:51 +09:00
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
2015-01-25 21:27:11 +09:00
|
|
|
|
2015-05-16 22:18:36 +09:00
|
|
|
var ctx = this._getPageDrawContext(true);
|
2015-01-25 00:27:31 +09:00
|
|
|
var canvas = ctx.canvas;
|
|
|
|
|
|
|
|
if (img.width <= 2 * canvas.width) {
|
|
|
|
ctx.drawImage(img, 0, 0, img.width, img.height,
|
|
|
|
0, 0, canvas.width, canvas.height);
|
2015-09-11 20:18:35 +09:00
|
|
|
this._convertCanvasToImage();
|
2015-01-25 21:27:11 +09:00
|
|
|
return;
|
2015-01-25 00:27:31 +09:00
|
|
|
}
|
2015-01-25 21:27:11 +09:00
|
|
|
// drawImage does an awful job of rescaling the image, doing it gradually.
|
|
|
|
var MAX_NUM_SCALING_STEPS = 3;
|
|
|
|
var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
|
|
|
var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
|
|
|
var reducedImage = getTempCanvas(reducedWidth, reducedHeight);
|
|
|
|
var reducedImageCtx = reducedImage.getContext('2d');
|
|
|
|
|
|
|
|
while (reducedWidth > img.width || reducedHeight > img.height) {
|
|
|
|
reducedWidth >>= 1;
|
|
|
|
reducedHeight >>= 1;
|
|
|
|
}
|
|
|
|
reducedImageCtx.drawImage(img, 0, 0, img.width, img.height,
|
|
|
|
0, 0, reducedWidth, reducedHeight);
|
|
|
|
while (reducedWidth > 2 * canvas.width) {
|
|
|
|
reducedImageCtx.drawImage(reducedImage,
|
|
|
|
0, 0, reducedWidth, reducedHeight,
|
|
|
|
0, 0, reducedWidth >> 1, reducedHeight >> 1);
|
|
|
|
reducedWidth >>= 1;
|
|
|
|
reducedHeight >>= 1;
|
|
|
|
}
|
|
|
|
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight,
|
|
|
|
0, 0, canvas.width, canvas.height);
|
2015-09-11 20:11:49 +09:00
|
|
|
this._convertCanvasToImage();
|
2016-01-27 22:27:01 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
get pageId() {
|
|
|
|
return (this.pageLabel !== null ? this.pageLabel : this.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string|null} label
|
|
|
|
*/
|
|
|
|
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
|
|
|
|
this.pageLabel = (typeof label === 'string' ? label : null);
|
|
|
|
|
|
|
|
this.anchor.title = mozL10n.get('thumb_page_title', { page: this.pageId },
|
|
|
|
'Page {{page}}');
|
|
|
|
|
|
|
|
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.pageId },
|
|
|
|
'Thumbnail of Page {{page}}');
|
|
|
|
if (this.image) {
|
|
|
|
this.image.setAttribute('aria-label', ariaLabel);
|
|
|
|
} else if (this.disableCanvasToImageConversion && this.canvas) {
|
|
|
|
this.canvas.setAttribute('aria-label', ariaLabel);
|
|
|
|
}
|
|
|
|
},
|
2013-08-07 05:19:03 +09:00
|
|
|
};
|
2014-06-13 00:28:42 +09:00
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
return PDFThumbnailView;
|
|
|
|
})();
|
|
|
|
|
|
|
|
PDFThumbnailView.tempImageCache = null;
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
export {
|
|
|
|
PDFThumbnailView,
|
|
|
|
};
|