Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert canvas thumbnails to PNG #6299

Merged
merged 1 commit into from
Sep 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions web/pdf_thumbnail_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,9 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
_getPageDrawContext:
function PDFThumbnailView_getPageDrawContext(noCtxScale) {
var canvas = document.createElement('canvas');
canvas.id = this.renderingId;

canvas.className = 'thumbnailImage';
canvas.setAttribute('aria-label', mozL10n.get('thumb_page_canvas',
{page: this.id}, 'Thumbnail of Page {{page}}'));

this.canvas = canvas;
this.div.setAttribute('data-loaded', true);
this.ring.appendChild(canvas);

var ctx = canvas.getContext('2d');
var outputScale = getOutputScale(ctx);
Expand All @@ -199,6 +193,14 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
if (!noCtxScale && outputScale.scaled) {
ctx.scale(outputScale.sx, outputScale.sy);
}
this.image = document.createElement('img');
this.image.id = this.renderingId;
this.image.style.height = canvas.style.height;
this.image.style.width = canvas.style.width;
this.image.className = 'thumbnailImage';
this.image.setAttribute('aria-label', mozL10n.get('thumb_page_canvas',
{ page: this.id }, 'Thumbnail of Page {{page}}'));
this.ring.appendChild(this.image);
return ctx;
},

Expand Down Expand Up @@ -230,6 +232,11 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
rejectRenderPromise(error);
return;
}

self.image.src = self.canvas.toDataURL();
self.canvas.width = 0;
self.canvas.height = 0;
delete self.canvas;
self.renderingState = RenderingStates.FINISHED;

if (!error) {
Expand Down Expand Up @@ -312,6 +319,10 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
}
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight,
0, 0, canvas.width, canvas.height);
this.image.src = canvas.toDataURL();
this.canvas.width = 0;
this.canvas.height = 0;
delete this.canvas;
}
};

Expand Down