]> git.parisson.com Git - pdf.js.git/commitdiff
Merge pull request #90 from justindarc/master
authorAndreas Gal <andreas.gal@gmail.com>
Mon, 27 Jun 2011 16:55:10 +0000 (09:55 -0700)
committerAndreas Gal <andreas.gal@gmail.com>
Mon, 27 Jun 2011 16:55:10 +0000 (09:55 -0700)
Fixed issue #67: zooming in in the multi-page viewer makes pages disappear. r=gal

1  2 
multi_page_viewer.js

index f46038c9c3e534daf9f0e9b30792b27a952cac42,5a94f12edeef9054eb5765c4ee692a541ad0fcc2..b2c0dc3edeed3c2c0e6d5a23a003292577f80046
@@@ -62,9 -54,79 +64,81 @@@ var PDFViewer = 
      return pages;
    },
    
+   createThumbnail: function(num) {
+     if (PDFViewer.sidebarContentView) {
+       var anchor = document.createElement('a');
+       anchor.href = '#' + num;
+     
+       var containerDiv = document.createElement('div');
+       containerDiv.id = 'thumbnailContainer' + num;
+       containerDiv.className = 'thumbnail';
+     
+       var pageNumberDiv = document.createElement('div');
+       pageNumberDiv.className = 'thumbnailPageNumber';
+       pageNumberDiv.innerHTML = '' + num;
+     
+       anchor.appendChild(containerDiv);
+       PDFViewer.sidebarContentView.appendChild(anchor);
+       PDFViewer.sidebarContentView.appendChild(pageNumberDiv);
+     }
+   },
+   
+   removeThumbnail: function(num) {
+     var div = document.getElementById('thumbnailContainer' + num);
+     
+     if (div) {
+       while (div.hasChildNodes()) {
+         div.removeChild(div.firstChild);
+       }
+     }
+   },
+   
+   drawThumbnail: function(num) {
+     if (!PDFViewer.pdf)
+       return;
+     var div = document.getElementById('thumbnailContainer' + num);
+     
+     if (div && !div.hasChildNodes()) {
+       var page = PDFViewer.pdf.getPage(num);
+       var canvas = document.createElement('canvas');
+       
+       canvas.id = 'thumbnail' + num;
+       canvas.mozOpaque = true;
+       // Canvas dimensions must be specified in CSS pixels. CSS pixels
+       // are always 96 dpi. These dimensions are 8.5in x 11in at 96dpi.
+       canvas.width = 104;
+       canvas.height = 134;
+       div.appendChild(canvas);
+       var ctx = canvas.getContext('2d');
+       ctx.save();
+       ctx.fillStyle = 'rgb(255, 255, 255)';
+       ctx.fillRect(0, 0, canvas.width, canvas.height);
+       ctx.restore();
+       var gfx = new CanvasGraphics(ctx);
+       // page.compile will collect all fonts for us, once we have loaded them
+       // we can trigger the actual page rendering with page.display
+       var fonts = [];
+       page.compile(gfx, fonts);
+       var loadFont = function() {
+         if (!FontLoader.bind(fonts)) {
+           pageTimeout = window.setTimeout(loadFont, 10);
+           return;
+         }
+         page.display(gfx);
+       }
+       loadFont();
+     }
+   },
+   
    createPage: function(num) {
 +    var page = PDFViewer.pdf.getPage(num);
 +
      var anchor = document.createElement('a');
      anchor.name = '' + num;