From 31e9bea5c9de2eef2e1661a20873bedb19ba5d1a Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Wed, 29 Jun 2011 14:26:38 +0200 Subject: [PATCH 1/7] Make worker code work with latest font code changes --- pdf.js | 12 +++++------- worker/client.js | 7 ++++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pdf.js b/pdf.js index 33a21e38c..349589016 100644 --- a/pdf.js +++ b/pdf.js @@ -3807,23 +3807,21 @@ var CanvasGraphics = (function() { if (fontDescriptor && fontDescriptor.num) { var fontDescriptor = this.xref.fetchIfRef(fontDescriptor); fontName = fontDescriptor.get("FontName").name.replace("+", "_"); - Fonts.setActive(fontName, size); } if (!fontName) { // TODO: fontDescriptor is not available, fallback to default font - this.current.fontSize = size; - this.ctx.font = this.current.fontSize + 'px sans-serif'; - Fonts.setActive("sans-serif", this.current.fontSize); - return; + fontName = "sans-serif"; } this.current.fontName = fontName; this.current.fontSize = size; - this.ctx.font = this.current.fontSize + 'px "' + fontName + '"'; if (this.ctx.$setFont) { - this.ctx.$setFont(fontName); + this.ctx.$setFont(fontName, size); + } else { + this.ctx.font = size + 'px "' + fontName + '"'; + Fonts.setActive(fontName, size); } }, setTextRenderingMode: function(mode) { diff --git a/worker/client.js b/worker/client.js index 84e44b94c..960e97496 100644 --- a/worker/client.js +++ b/worker/client.js @@ -250,9 +250,10 @@ function WorkerPDFDoc(canvas) { } this.strokeStyle = pattern; }, - - "$setFont": function(name) { - Fonts.active = name; + + "$setFont": function(name, size) { + this.font = size + 'px "' + name + '"'; + Fonts.setActive(name, size); } } From 57d4053f6275726fb706052b980d17f38d3fe775 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 29 Jun 2011 18:35:00 -0700 Subject: [PATCH 2/7] try to make sidebar a bit more discoverable by leaving a little edge of it sticking out --- multi_page_viewer.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multi_page_viewer.css b/multi_page_viewer.css index 2eaca4870..17b2537be 100644 --- a/multi_page_viewer.css +++ b/multi_page_viewer.css @@ -181,7 +181,7 @@ span { width: 200px; top: 62px; bottom: 18px; - left: -170px; + left: -140px; transition: left 0.25s ease-in-out 1s; -moz-transition: left 0.25s ease-in-out 1s; -webkit-transition: left 0.25s ease-in-out 1s; From ab3bb9726e0bef242c6637cd4771eef75351a48a Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 29 Jun 2011 18:52:27 -0700 Subject: [PATCH 3/7] redraw on zoom changes --- multi_page_viewer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/multi_page_viewer.js b/multi_page_viewer.js index b2c0dc3ed..4e9ca79d5 100644 --- a/multi_page_viewer.js +++ b/multi_page_viewer.js @@ -249,7 +249,10 @@ var PDFViewer = { PDFViewer.pageNumber = num; PDFViewer.pageNumberInput.value = PDFViewer.pageNumber; PDFViewer.willJumpToPage = true; - + + if (document.location.hash.substr(1) == PDFViewer.pageNumber) + // Force a "scroll event" to redraw + setTimeout(window.onscroll, 0); document.location.hash = PDFViewer.pageNumber; PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? 'disabled' : ''; From ca63ad8a4d91c0c445d2abe41365c5b6213d6fc4 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 29 Jun 2011 19:01:43 -0700 Subject: [PATCH 4/7] no need to recreate thumbnails after zooming, thumbnails don't change size --- multi_page_viewer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/multi_page_viewer.js b/multi_page_viewer.js index b2c0dc3ed..1bde03cc6 100644 --- a/multi_page_viewer.js +++ b/multi_page_viewer.js @@ -216,7 +216,6 @@ var PDFViewer = { if (PDFViewer.pdf) { for (i = 1; i <= PDFViewer.numberOfPages; i++) { - PDFViewer.createThumbnail(i); PDFViewer.createPage(i); } } From 5ece4da552533a28827f9a0b9088e14b11f1866c Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Wed, 29 Jun 2011 22:43:59 -0500 Subject: [PATCH 5/7] the "hieght" and the 72dpi<->96dpi fixes --- multi_page_viewer.js | 19 +++++++++++-------- test/test_slave.html | 10 ++++++---- viewer.css | 7 ++++--- viewer.html | 4 +--- viewer.js | 10 +++++----- viewer_worker.html | 5 +---- worker/client.js | 7 +++++++ worker/pdf.js | 13 +++++++++++++ 8 files changed, 48 insertions(+), 27 deletions(-) diff --git a/multi_page_viewer.js b/multi_page_viewer.js index 87e2c8f14..7bd59873f 100644 --- a/multi_page_viewer.js +++ b/multi_page_viewer.js @@ -29,11 +29,15 @@ var PDFViewer = { scale: 1.0, pageWidth: function(page) { - return page.mediaBox[2] * PDFViewer.scale; + var pdfToCssUnitsCoef = 96.0 / 72.0; + var width = (page.mediaBox[2] - page.mediaBox[0]); + return width * PDFViewer.scale * pdfToCssUnitsCoef; }, pageHeight: function(page) { - return page.mediaBox[3] * PDFViewer.scale; + var pdfToCssUnitsCoef = 96.0 / 72.0; + var height = (page.mediaBox[3] - page.mediaBox[1]); + return height * PDFViewer.scale * pdfToCssUnitsCoef; }, lastPagesDrawn: [], @@ -106,10 +110,11 @@ var PDFViewer = { 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; + var pageWidth = PDFViewer.pageWidth(page); + var pageHeight = PDFViewer.pageHeight(page); + var thumbScale = Math.min(104 / pageWidth, 134 / pageHeight); + canvas.width = pageWidth * thumbScale; + canvas.height = pageHeight * thumbScale; div.appendChild(canvas); var ctx = canvas.getContext('2d'); @@ -175,8 +180,6 @@ var PDFViewer = { canvas.id = 'page' + 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 = PDFViewer.pageWidth(page); canvas.height = PDFViewer.pageHeight(page); div.appendChild(canvas); diff --git a/test/test_slave.html b/test/test_slave.html index d70e362af..0a330e703 100644 --- a/test/test_slave.html +++ b/test/test_slave.html @@ -4,6 +4,7 @@ +