[Pkg-javascript-commits] [pdf.js] 71/109: Convert canvas thumbnails to PNG #6299

David Prévot taffit at moszumanska.debian.org
Fri Sep 25 03:04:19 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 161def7f4eb337662dcf0ff53218d5579989fc1f
Author: awang <awang at marinsoftware.com>
Date:   Fri Sep 4 09:58:47 2015 +0800

    Convert canvas thumbnails to PNG #6299
---
 web/pdf_thumbnail_view.js | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index e446b68..0d4752f 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -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);
@@ -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;
     },
 
@@ -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) {
@@ -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;
     }
   };
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list