From: Andreas Gal Date: Mon, 27 Jun 2011 16:55:10 +0000 (-0700) Subject: Merge pull request #90 from justindarc/master X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=4683d38fda9ef5ee65132911551827c47126ec7e;p=pdf.js.git Merge pull request #90 from justindarc/master Fixed issue #67: zooming in in the multi-page viewer makes pages disappear. r=gal --- 4683d38fda9ef5ee65132911551827c47126ec7e diff --cc multi_page_viewer.js index f46038c,5a94f12..b2c0dc3 --- a/multi_page_viewer.js +++ b/multi_page_viewer.js @@@ -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;