You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.0 KiB
82 lines
2.0 KiB
14 years ago
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||
|
|
||
14 years ago
|
"use strict";
|
||
|
|
||
14 years ago
|
var timer = null;
|
||
|
function tic() {
|
||
|
timer = Date.now();
|
||
|
}
|
||
|
|
||
|
function toc(msg) {
|
||
|
log(msg + ": " + (Date.now() - timer) + "ms");
|
||
|
timer = null;
|
||
|
}
|
||
|
|
||
14 years ago
|
function log() {
|
||
14 years ago
|
var args = Array.prototype.slice.call(arguments);
|
||
|
postMessage("log");
|
||
|
postMessage(JSON.stringify(args))
|
||
14 years ago
|
}
|
||
|
|
||
|
var console = {
|
||
14 years ago
|
log: log
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
//
|
||
14 years ago
|
importScripts("canvas_proxy.js");
|
||
|
importScripts("pdf.js");
|
||
|
importScripts("fonts.js");
|
||
|
importScripts("glyphlist.js")
|
||
|
|
||
14 years ago
|
// Use the JpegStreamProxy proxy.
|
||
|
JpegStream = JpegStreamProxy;
|
||
|
|
||
14 years ago
|
// Create the WebWorkerProxyCanvas.
|
||
14 years ago
|
var canvas = new CanvasProxy(1224, 1584);
|
||
|
|
||
14 years ago
|
// Listen for messages from the main thread.
|
||
14 years ago
|
var pdfDocument = null;
|
||
14 years ago
|
onmessage = function(event) {
|
||
14 years ago
|
var data = event.data;
|
||
|
// If there is no pdfDocument yet, then the sent data is the PDFDocument.
|
||
|
if (!pdfDocument) {
|
||
|
pdfDocument = new PDFDoc(new Stream(data));
|
||
|
postMessage("pdf_num_page");
|
||
|
postMessage(pdfDocument.numPages)
|
||
|
return;
|
||
|
}
|
||
|
// User requested to render a certain page.
|
||
|
else {
|
||
|
tic();
|
||
14 years ago
|
|
||
14 years ago
|
// Let's try to render the first page...
|
||
|
var page = pdfDocument.getPage(parseInt(data));
|
||
14 years ago
|
|
||
14 years ago
|
// 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.getContext("2d"), CanvasProxy);
|
||
|
page.compile(gfx, fonts);
|
||
14 years ago
|
|
||
14 years ago
|
// 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;
|
||
|
}
|
||
14 years ago
|
|
||
14 years ago
|
// This "builds" the font and sents it over to the main thread.
|
||
|
new Font(font.name, font.file, font.properties);
|
||
14 years ago
|
}
|
||
14 years ago
|
toc("compiled page");
|
||
|
|
||
|
tic()
|
||
|
page.display(gfx);
|
||
|
canvas.flush();
|
||
|
toc("displayed page");
|
||
|
}
|
||
14 years ago
|
}
|