Fixing some smaller bugs & do some cleanup. viewer_worker.html UI is now
This commit is contained in:
parent
d99dc718c5
commit
4f10e93f8c
3 changed files with 89 additions and 65 deletions
67
worker.js
67
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")
|
Loading…
Add table
Add a link
Reference in a new issue