Rename some stuff and add missing font_handler.js
This commit is contained in:
parent
921f8bd669
commit
00290b9ff4
@ -10,7 +10,8 @@
|
||||
<script type="text/javascript" src="driver.js"></script>
|
||||
<script type="text/javascript" src="../worker.js"></script>
|
||||
<script type="text/javascript" src="../worker/message_handler.js"></script>
|
||||
<script type="text/javascript" src="../worker/handler.js"></script>
|
||||
<script type="text/javascript" src="../worker/processor_handler.js"></script>
|
||||
<script type="text/javascript" src="../worker/font_handler.js"></script>
|
||||
</head>
|
||||
|
||||
<body onload="load();">
|
||||
|
@ -13,7 +13,8 @@
|
||||
<script type="text/javascript" src="../metrics.js"></script>
|
||||
<script type="text/javascript" src="../worker.js"></script>
|
||||
<script type="text/javascript" src="../worker/message_handler.js"></script>
|
||||
<script type="text/javascript" src="../worker/handler.js"></script>
|
||||
<script type="text/javascript" src="../worker/processor_handler.js"></script>
|
||||
<script type="text/javascript" src="../worker/font_handler.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
31
worker.js
31
worker.js
@ -3,6 +3,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
// Set this to true if you want to use workers.
|
||||
var useWorker = false;
|
||||
|
||||
var WorkerPage = (function() {
|
||||
function constructor(workerPDF, page) {
|
||||
this.workerPDF = workerPDF;
|
||||
@ -179,10 +182,9 @@ var WorkerPDFDoc = (function() {
|
||||
|
||||
this.pageCache = [];
|
||||
|
||||
var useWorker = true;
|
||||
|
||||
if (useWorker) {
|
||||
var worker = this.worker = new Worker("../worker/boot_processor.js");
|
||||
var worker = this.worker = new Worker("../worker/processor_boot.js");
|
||||
var fontWorker = this.fontWorker = new Worker('../worker/font_boot.js');
|
||||
} else {
|
||||
// If we don't use a worker, just post/sendMessage to the main thread.
|
||||
var worker = {
|
||||
@ -190,21 +192,22 @@ var WorkerPDFDoc = (function() {
|
||||
worker.onmessage({data: obj});
|
||||
}
|
||||
}
|
||||
var fontWorker = {
|
||||
postMessage: function(obj) {
|
||||
fontWorker.onmessage({data: obj});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var fontWorker = new Worker('../worker/boot_font.js');
|
||||
var fontHandler = this.fontHandler = new MessageHandler('font', fontWorker);
|
||||
|
||||
var handler = this.handler = new MessageHandler("main", worker);
|
||||
handler.on("page", function(data) {
|
||||
var processorHandler = this.processorHandler = new MessageHandler("main", worker);
|
||||
processorHandler.on("page", function(data) {
|
||||
var pageNum = data.pageNum;
|
||||
var page = this.pageCache[pageNum];
|
||||
|
||||
|
||||
page.startRenderingFromIRQueue(data.IRQueue, data.fonts);
|
||||
}, this);
|
||||
|
||||
handler.on("obj", function(data) {
|
||||
processorHandler.on("obj", function(data) {
|
||||
var objId = data[0];
|
||||
var objType = data[1];
|
||||
|
||||
@ -225,6 +228,7 @@ var WorkerPDFDoc = (function() {
|
||||
}
|
||||
}, this);
|
||||
|
||||
var fontHandler = this.fontHandler = new MessageHandler('font', fontWorker);
|
||||
fontHandler.on('font_ready', function(data) {
|
||||
var objId = data[0];
|
||||
var fontObj = new FontShape(data[1]);
|
||||
@ -240,10 +244,11 @@ var WorkerPDFDoc = (function() {
|
||||
if (!useWorker) {
|
||||
// If the main thread is our worker, setup the handling for the messages
|
||||
// the main thread sends to it self.
|
||||
WorkerHandler.setup(handler);
|
||||
WorkerProcessorHandler.setup(processorHandler);
|
||||
WorkerFontHandler.setup(fontHandler);
|
||||
}
|
||||
|
||||
handler.send("doc", data);
|
||||
processorHandler.send("doc", data);
|
||||
}
|
||||
|
||||
constructor.prototype = {
|
||||
@ -252,7 +257,7 @@ var WorkerPDFDoc = (function() {
|
||||
},
|
||||
|
||||
startRendering: function(page) {
|
||||
this.handler.send("page_request", page.page.pageNumber + 1);
|
||||
this.processorHandler.send("page_request", page.page.pageNumber + 1);
|
||||
},
|
||||
|
||||
getPage: function(n) {
|
||||
|
16
worker/font_boot.js
Normal file
16
worker/font_boot.js
Normal file
@ -0,0 +1,16 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
'use strict';
|
||||
|
||||
importScripts('console.js');
|
||||
importScripts('message_handler.js');
|
||||
importScripts('../pdf.js');
|
||||
importScripts('../fonts.js');
|
||||
importScripts('../crypto.js');
|
||||
importScripts('../glyphlist.js');
|
||||
importScripts('font_handler.js');
|
||||
|
||||
|
||||
var handler = new MessageHandler("worker_font", this);
|
||||
WorkerFontHandler.setup(handler);
|
52
worker/font_handler.js
Normal file
52
worker/font_handler.js
Normal file
@ -0,0 +1,52 @@
|
||||
var WorkerFontHandler = {
|
||||
setup: function(handler) {
|
||||
handler.on("font", function(data) {
|
||||
var objId = data[0];
|
||||
var name = data[1];
|
||||
var file = data[2];
|
||||
var properties = data[3];
|
||||
|
||||
var font = {
|
||||
name: name,
|
||||
file: file,
|
||||
properties: properties
|
||||
};
|
||||
|
||||
// Some fonts don't have a file, e.g. the build in ones like Arial.
|
||||
if (file) {
|
||||
var fontFileDict = new Dict();
|
||||
fontFileDict.map = file.dict.map;
|
||||
|
||||
var fontFile = new Stream(file.bytes, file.start,
|
||||
file.end - file.start, fontFileDict);
|
||||
|
||||
// Check if this is a FlateStream. Otherwise just use the created
|
||||
// Stream one. This makes complex_ttf_font.pdf work.
|
||||
var cmf = file.bytes[0];
|
||||
if ((cmf & 0x0f) == 0x08) {
|
||||
font.file = new FlateStream(fontFile);
|
||||
} else {
|
||||
font.file = fontFile;
|
||||
}
|
||||
}
|
||||
|
||||
var obj = new Font(font.name, font.file, font.properties);
|
||||
|
||||
var str = '';
|
||||
var data = obj.data;
|
||||
if (data) {
|
||||
var length = data.length;
|
||||
for (var j = 0; j < length; j++)
|
||||
str += String.fromCharCode(data[j]);
|
||||
}
|
||||
|
||||
obj.str = str;
|
||||
|
||||
// Remove the data array form the font object, as it's not needed
|
||||
// anymore as we sent over the ready str.
|
||||
delete obj.data;
|
||||
|
||||
handler.send("font_ready", [objId, obj]);
|
||||
});
|
||||
}
|
||||
}
|
@ -10,10 +10,10 @@ importScripts('../fonts.js');
|
||||
importScripts('../crypto.js');
|
||||
importScripts('../glyphlist.js');
|
||||
importScripts('../metrics.js');
|
||||
importScripts('handler.js');
|
||||
importScripts('processor_handler.js');
|
||||
|
||||
// Listen for messages from the main thread.
|
||||
var pdfDoc = null;
|
||||
|
||||
var handler = new MessageHandler("worker", this);
|
||||
WorkerHandler.setup(handler);
|
||||
var handler = new MessageHandler("worker_processor", this);
|
||||
WorkerProcessorHandler.setup(handler);
|
@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var WorkerHandler = {
|
||||
var WorkerProcessorHandler = {
|
||||
setup: function(handler) {
|
||||
var pdfDoc = null;
|
||||
|
Loading…
Reference in New Issue
Block a user