From 8a044058f3c4ec47abf1ce1b2e8e00d76583f412 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 26 Jun 2011 09:15:33 -0500 Subject: [PATCH] Support for multi-size page PDFs --- multi_page_viewer.js | 42 ++++++++++++++++++++++++++-------------- test/pdfs/sizes.pdf | Bin 0 -> 13739 bytes test/test_manifest.json | 5 +++++ test/test_slave.html | 14 +++++++++----- viewer.js | 4 ++++ 5 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 test/pdfs/sizes.pdf diff --git a/multi_page_viewer.js b/multi_page_viewer.js index f262734d3..f46038c9c 100644 --- a/multi_page_viewer.js +++ b/multi_page_viewer.js @@ -26,41 +26,53 @@ var PDFViewer = { scale: 1.0, - pageWidth: function() { - return 816 * PDFViewer.scale; + pageWidth: function(page) { + return page.mediaBox[2] * PDFViewer.scale; }, - pageHeight: function() { - return 1056 * PDFViewer.scale; + pageHeight: function(page) { + return page.mediaBox[3] * PDFViewer.scale; }, lastPagesDrawn: [], - visiblePages: function() { - var pageHeight = PDFViewer.pageHeight() + 20; // Add 20 for the margins. + visiblePages: function() { + const pageBottomMargin = 20; var windowTop = window.pageYOffset; var windowBottom = window.pageYOffset + window.innerHeight; - var pageStartIndex = Math.floor(windowTop / pageHeight); - var pageStopIndex = Math.ceil(windowBottom / pageHeight); + + var pageHeight, page; + var i, n = PDFViewer.numberOfPages, currentHeight = 0; + for (i = 1; i <= n; i++) { + var page = PDFViewer.pdf.getPage(i); + pageHeight = PDFViewer.pageHeight(page) + pageBottomMargin; + if (currentHeight + pageHeight > windowTop) + break; + currentHeight += pageHeight; + } var pages = []; - - for (var i = pageStartIndex; i <= pageStopIndex; i++) { - pages.push(i + 1); + for (; i <= n && currentHeight < windowBottom; i++) { + var page = PDFViewer.pdf.getPage(i); + pageHeight = PDFViewer.pageHeight(page) + pageBottomMargin; + currentHeight += pageHeight; + pages.push(i); } return pages; }, createPage: function(num) { + var page = PDFViewer.pdf.getPage(num); + var anchor = document.createElement('a'); anchor.name = '' + num; var div = document.createElement('div'); div.id = 'pageContainer' + num; div.className = 'page'; - div.style.width = PDFViewer.pageWidth() + 'px'; - div.style.height = PDFViewer.pageHeight() + 'px'; + div.style.width = PDFViewer.pageWidth(page) + 'px'; + div.style.height = PDFViewer.pageHeight(page) + 'px'; PDFViewer.element.appendChild(anchor); PDFViewer.element.appendChild(div); @@ -91,8 +103,8 @@ var PDFViewer = { // 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 = PDFViewer.pageWidth(); - canvas.height = PDFViewer.pageHeight(); + canvas.width = PDFViewer.pageWidth(page); + canvas.height = PDFViewer.pageHeight(page); div.appendChild(canvas); var ctx = canvas.getContext('2d'); diff --git a/test/pdfs/sizes.pdf b/test/pdfs/sizes.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f621f821e9bb28c8b0cf9bdfac9b895d33d23c9e GIT binary patch literal 13739 zcmbVz1yq#l+O~?K3`%z>-7p11gLHRy4&6f|ASKcz-AW3Gv`BY%hjf=99m+p=_WsV^ zXP>pc^?&c0mwBH1sXMOwe%BhVmsU|!oE6N*4xnwzX{&FmZp#EfC_ohU##R76KA_qcUQ@c)Y?cRK#I z1pIGHxc*@Y_y3P2_k@vAc!Z3`KO<3?oDt+-81mOZSpK%5;ie){WmcE0X8rNn3J0u z_E%`_zw*#kotn8t3^ur(tz-1D^f&7!8NEamyDt{qE%s9GEiVZOONbbbH{)mtvoU6; zk+WGavn8qE@Y;FZ{$A?iz?B*JDo^SPX8T^Me-_8qx6qOx>73gfwS#@X^!w)dW+}pB z@G=9DQNcfi$UqFbbY^^7z)H%(e5g2OW3$tZfHU1YWV$D%Sy3nfZpd^c1IOl>*>-)6 zsQISmg#G#x*2}9`db^WV270$e)b|JkU-r_nX6J1zx(${;Fg1v^|_q4!eN3JJB(JGqOn0vvL z7YYt9Y3I=rTNDf*TNu)A=%ULU#ei<<+wsZ$`Mx|>bH*eSUkFH zYFhIqQK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o@X@wwCcvc`sj^igvTm{qSXVe~)L!x^ zhVq1_;j^eqI<$s2_p+C`&#>d8eE2m`&aZVPPQmz?WJ$1Mh zv|jzOqpPX)D(4IHd@StnI?}azD|C^Qa3(VCzv1UEbnpKG3Q)zx*!d1Ms!lHO-%?>C z1pF>w|HO->6T(@y^8}!5 zxVw?)ld&{K=uq4-@s%m=+^tOUJFIs@BK9uGxI_PX-e2B1`0W4@BV?ttH%DRwdF~$& z0RR;o;C4bL&X)FeI{(@jsHvq*Vdr9F^RGW3F5GS%sb0XUikN{Fc4^`GY={dZTF{=OE%^$)**A>4Om_0M_EPDaRQwbNZ5saSf#ks$&q+uI|H-tUY9 z0Hy5A>?!VofGo2>DNza?3O;czC>SEl4HAdIz+9X#VGgheCm77d0pb9Qf`vdL0)YR0 z%3YR;+M9@2z)h?XF18dvQ6Z#SFqnuqSQvuDBvgzYECLo0hlz1;frPj@#P3oC;cVpO T{2NMOC>Y8CprsX45C{A}>P(JG literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index 9b9d5e333..4c5e912f6 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -25,5 +25,10 @@ "link": true, "rounds": 1, "type": "load" + }, + { "id": "sizes", + "file": "pdfs/sizes.pdf", + "rounds": 1, + "type": "eq" } ] diff --git a/test/test_slave.html b/test/test_slave.html index 32076d075..7dfbfeb87 100644 --- a/test/test_slave.html +++ b/test/test_slave.html @@ -25,9 +25,6 @@ function load() { manifestFile = params.manifestFile; canvas = document.createElement("canvas"); - // 8.5x11in @ 100% ... XXX need something better here - canvas.width = 816; - canvas.height = 1056; canvas.mozOpaque = true; stdout = document.getElementById("stdout"); @@ -93,7 +90,6 @@ function nextPage() { log(" loading page "+ currentTask.pageNum +"... "); var ctx = canvas.getContext("2d"); - clear(ctx); var fonts = []; var gfx = null; @@ -105,6 +101,15 @@ function nextPage() { failure = 'compile: '+ e.toString(); } + try { + // using mediaBox for the canvas size + canvas.width = currentPage.mediaBox[2]; + canvas.height = currentPage.mediaBox[3]; + clear(ctx); + } catch(e) { + failure = 'page setup: '+ e.toString(); + } + var fontLoaderTimer = null; function checkFontsLoaded() { try { @@ -193,7 +198,6 @@ function sendTaskResult(snapshot) { } function clear(ctx) { - var ctx = canvas.getContext("2d"); ctx.save(); ctx.fillStyle = "rgb(255, 255, 255)"; ctx.fillRect(0, 0, canvas.width, canvas.height); diff --git a/viewer.js b/viewer.js index c7be739bc..3dffa8144 100644 --- a/viewer.js +++ b/viewer.js @@ -60,6 +60,10 @@ function displayPage(num) { var page = pdfDocument.getPage(pageNum = num); + // scale canvas by 2 + canvas.width = 2 * page.mediaBox[2]; + canvas.hieght = 2 * page.mediaBox[3]; + var t1 = Date.now(); var ctx = canvas.getContext("2d"); ctx.save();