|
|
@ -160,6 +160,10 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() { |
|
|
|
this.canvas.height = 0; |
|
|
|
this.canvas.height = 0; |
|
|
|
delete this.canvas; |
|
|
|
delete this.canvas; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this.image) { |
|
|
|
|
|
|
|
this.image.removeAttribute('src'); |
|
|
|
|
|
|
|
delete this.image; |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
update: function PDFThumbnailView_update(rotation) { |
|
|
|
update: function PDFThumbnailView_update(rotation) { |
|
|
@ -186,24 +190,48 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() { |
|
|
|
|
|
|
|
|
|
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
var outputScale = getOutputScale(ctx); |
|
|
|
var outputScale = getOutputScale(ctx); |
|
|
|
|
|
|
|
|
|
|
|
canvas.width = (this.canvasWidth * outputScale.sx) | 0; |
|
|
|
canvas.width = (this.canvasWidth * outputScale.sx) | 0; |
|
|
|
canvas.height = (this.canvasHeight * outputScale.sy) | 0; |
|
|
|
canvas.height = (this.canvasHeight * outputScale.sy) | 0; |
|
|
|
canvas.style.width = this.canvasWidth + 'px'; |
|
|
|
canvas.style.width = this.canvasWidth + 'px'; |
|
|
|
canvas.style.height = this.canvasHeight + 'px'; |
|
|
|
canvas.style.height = this.canvasHeight + 'px'; |
|
|
|
|
|
|
|
|
|
|
|
if (!noCtxScale && outputScale.scaled) { |
|
|
|
if (!noCtxScale && outputScale.scaled) { |
|
|
|
ctx.scale(outputScale.sx, outputScale.sy); |
|
|
|
ctx.scale(outputScale.sx, outputScale.sy); |
|
|
|
} |
|
|
|
} |
|
|
|
this.image = document.createElement('img'); |
|
|
|
|
|
|
|
this.image.id = this.renderingId; |
|
|
|
var image = document.createElement('img'); |
|
|
|
this.image.style.height = canvas.style.height; |
|
|
|
image.id = this.renderingId; |
|
|
|
this.image.style.width = canvas.style.width; |
|
|
|
|
|
|
|
this.image.className = 'thumbnailImage'; |
|
|
|
image.className = 'thumbnailImage'; |
|
|
|
this.image.setAttribute('aria-label', mozL10n.get('thumb_page_canvas', |
|
|
|
image.setAttribute('aria-label', mozL10n.get('thumb_page_canvas', |
|
|
|
{ page: this.id }, 'Thumbnail of Page {{page}}')); |
|
|
|
{ page: this.id }, 'Thumbnail of Page {{page}}')); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image.style.width = canvas.style.width; |
|
|
|
|
|
|
|
image.style.height = canvas.style.height; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.image = image; |
|
|
|
this.ring.appendChild(this.image); |
|
|
|
this.ring.appendChild(this.image); |
|
|
|
|
|
|
|
|
|
|
|
return ctx; |
|
|
|
return ctx; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @private |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
_convertCanvasToImage: function PDFThumbnailView_convertCanvasToImage() { |
|
|
|
|
|
|
|
if (!this.canvas) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.image.src = this.canvas.toDataURL(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
draw: function PDFThumbnailView_draw() { |
|
|
|
draw: function PDFThumbnailView_draw() { |
|
|
|
if (this.renderingState !== RenderingStates.INITIAL) { |
|
|
|
if (this.renderingState !== RenderingStates.INITIAL) { |
|
|
|
console.error('Must be in new state before drawing'); |
|
|
|
console.error('Must be in new state before drawing'); |
|
|
@ -232,12 +260,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() { |
|
|
|
rejectRenderPromise(error); |
|
|
|
rejectRenderPromise(error); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.image.src = self.canvas.toDataURL(); |
|
|
|
|
|
|
|
self.canvas.width = 0; |
|
|
|
|
|
|
|
self.canvas.height = 0; |
|
|
|
|
|
|
|
delete self.canvas; |
|
|
|
|
|
|
|
self.renderingState = RenderingStates.FINISHED; |
|
|
|
self.renderingState = RenderingStates.FINISHED; |
|
|
|
|
|
|
|
self._convertCanvasToImage(); |
|
|
|
|
|
|
|
|
|
|
|
if (!error) { |
|
|
|
if (!error) { |
|
|
|
resolveRenderPromise(undefined); |
|
|
|
resolveRenderPromise(undefined); |
|
|
@ -295,6 +319,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() { |
|
|
|
if (img.width <= 2 * canvas.width) { |
|
|
|
if (img.width <= 2 * canvas.width) { |
|
|
|
ctx.drawImage(img, 0, 0, img.width, img.height, |
|
|
|
ctx.drawImage(img, 0, 0, img.width, img.height, |
|
|
|
0, 0, canvas.width, canvas.height); |
|
|
|
0, 0, canvas.width, canvas.height); |
|
|
|
|
|
|
|
this._convertCanvasToImage(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// drawImage does an awful job of rescaling the image, doing it gradually.
|
|
|
|
// drawImage does an awful job of rescaling the image, doing it gradually.
|
|
|
@ -319,10 +344,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, |
|
|
|
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, |
|
|
|
0, 0, canvas.width, canvas.height); |
|
|
|
0, 0, canvas.width, canvas.height); |
|
|
|
this.image.src = canvas.toDataURL(); |
|
|
|
this._convertCanvasToImage(); |
|
|
|
this.canvas.width = 0; |
|
|
|
|
|
|
|
this.canvas.height = 0; |
|
|
|
|
|
|
|
delete this.canvas; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|