From 52a117d32a1ff11f9e6810053a2988af90f62e58 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Wed, 22 Jun 2011 11:08:30 +0200 Subject: [PATCH] Fixing some smaller bugs & do some cleanup. viewer_worker.html UI is now --- pdf.js | 3 +- viewer_worker.html | 84 +++++++++++++++++++++++++++++++--------------- worker.js | 67 +++++++++++++++++------------------- 3 files changed, 89 insertions(+), 65 deletions(-) diff --git a/pdf.js b/pdf.js index 273550084..61ceb602a 100644 --- a/pdf.js +++ b/pdf.js @@ -2867,7 +2867,7 @@ var CanvasGraphics = (function() { this.ctx.scale(1, -1); if (this.ctx.$showText) { - this.ctx.$showText(this.current.y, Fonts.charsToUnicode(text)); + this.ctx.$showText(this.current.y, text, Fonts.charsToUnicode(text)); } else { text = Fonts.charsToUnicode(text); this.ctx.translate(this.current.x, -1 * this.current.y); @@ -3423,7 +3423,6 @@ var CanvasGraphics = (function() { TODO("Images with "+ numComps + " components per pixel"); } } - console.log("paintImageXObject", w, h); tmpCanvas.putImageData(imgData, 0, 0); ctx.drawImage(tmpCanvas.getCanvas(), 0, -h); this.restore(); diff --git a/viewer_worker.html b/viewer_worker.html index 07623c50c..bba694f21 100644 --- a/viewer_worker.html +++ b/viewer_worker.html @@ -2,6 +2,16 @@ Simple pdf.js page viewer worker @@ -184,7 +214,7 @@ window.onload = function() { -- Can we use JSONP to overcome the same-origin restrictions? --> - -- diff --git a/worker.js b/worker.js index 33b34f350..dcb87a811 100644 --- a/worker.js +++ b/worker.js @@ -26,7 +26,7 @@ function tic() { } function toc(msg) { - log("Took ", (Date.now() - timer)); + log(msg + ": " + (Date.now() - timer) + "ms"); timer = null; } @@ -41,46 +41,41 @@ var canvas = new CanvasProxy(1224, 1584); log("test"); var pageInterval; - +var pdfDocument = null; onmessage = function(event) { var data = event.data; - var pdfDocument = new PDFDoc(new Stream(data)); - var numPages = pdfDocument.numPages; + if (!pdfDocument) { + pdfDocument = new PDFDoc(new Stream(data)); + postMessage("pdf_num_page"); + postMessage(pdfDocument.numPages) + return; + } else { + tic(); - tic(); - // Let's try to render the first page... - var page = pdfDocument.getPage(2); + // Let's try to render the first page... + var page = pdfDocument.getPage(parseInt(data)); - // 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 will collect all fonts for us, once we have loaded them + // we can trigger the actual page rendering with page.display + var fonts = []; + var gfx = new CanvasGraphics(canvas, ImageCanvasProxy); + page.compile(gfx, fonts); - var gfx = new CanvasGraphics(canvas, ImageCanvasProxy); - page.compile(gfx, fonts); - toc("compiled page"); + // Inspect fonts and translate the missing one. + var count = fonts.length; + for (var i = 0; i < count; i++) { + var font = fonts[i]; + if (Fonts[font.name]) { + fontsReady = fontsReady && !Fonts[font.name].loading; + continue; + } + // This "builds" the font and sents it over to the main thread. + new Font(font.name, font.file, font.properties); + } + toc("compiled page"); - page.display(gfx); - canvas.flush(); + page.display(gfx); + canvas.flush(); + } } - -// function open(url) { -// var req = new XMLHttpRequest(); -// req.open("GET", url); -// // req.responseType = "arraybuffer"; -// req.expected = 0;//(document.URL.indexOf("file:") == 0) ? 0 : 200; -// req.onreadystatechange = function() { -// postMessage("loaded"); -// if (req.readyState == 4 && req.status == req.expected) { -// var data = req.mozResponseArrayBuffer || req.mozResponse || -// req.responseArrayBuffer || req.response; -// pdfDocument = new PDFDoc(new Stream(data)); -// numPages = pdfDocument.numPages; -// // document.getElementById("numPages").innerHTML = numPages.toString(); -// // goToPage(pageNum); -// } -// }; -// req.send(null); -// } -// -// open("compressed.tracemonkey-pldi-09.pdf") \ No newline at end of file