Only one worker file, bundled in pdf.js
This commit is contained in:
parent
8fbb05613e
commit
21753b9e89
29
Makefile
29
Makefile
@ -1,5 +1,6 @@
|
||||
REPO = git@github.com:andreasgal/pdf.js.git
|
||||
BUILD_DIR := build
|
||||
PDFJS_TARGET := $(BUILD_DIR)/pdf.js
|
||||
DEFAULT_BROWSERS := resources/browser_manifests/browser_manifest.json
|
||||
DEFAULT_TESTS := test_manifest.json
|
||||
|
||||
@ -10,7 +11,6 @@ EXTENSION_NAME := pdf.js.xpi
|
||||
-include local.mk
|
||||
|
||||
# JS files needed for pdf.js.
|
||||
# This list doesn't account for the 'worker' directory.
|
||||
PDF_JS_FILES = \
|
||||
core.js \
|
||||
util.js \
|
||||
@ -30,17 +30,9 @@ PDF_JS_FILES = \
|
||||
parser.js \
|
||||
pattern.js \
|
||||
stream.js \
|
||||
worker/message_handler.js \
|
||||
worker/processor_handler.js \
|
||||
worker.js \
|
||||
$(NULL)
|
||||
|
||||
PDF_WORKER_FILES = \
|
||||
worker/console.js \
|
||||
worker/message_handler.js \
|
||||
worker/pdf_worker_loader.js \
|
||||
worker/processor_handler.js \
|
||||
$(NULL)
|
||||
|
||||
# make server
|
||||
#
|
||||
# This target starts a local web server at localhost:8888. This can be
|
||||
@ -55,10 +47,10 @@ test: pdfjs shell-test browser-test
|
||||
#
|
||||
pdfjs:
|
||||
@echo "Bundling source files..."
|
||||
@mkdir -p build
|
||||
@mkdir -p $(BUILD_DIR)
|
||||
@cd src; \
|
||||
cat $(PDF_JS_FILES) > all_files.tmp; \
|
||||
sed -E '/INSERT_POINT/ r all_files.tmp' pdf.js > ../build/pdf.js; \
|
||||
sed -E '/INSERT_POINT/ r all_files.tmp' pdf.js > ../$(PDFJS_TARGET); \
|
||||
rm -f all_files.tmp; \
|
||||
cd ..
|
||||
|
||||
@ -121,7 +113,7 @@ browser-test:
|
||||
# To install gjslint, see:
|
||||
#
|
||||
# <http://code.google.com/closure/utilities/docs/linter_howto.html>
|
||||
SRC_DIRS := . utils worker web test examples/helloworld extensions/firefox \
|
||||
SRC_DIRS := . utils web test examples/helloworld extensions/firefox \
|
||||
extensions/firefox/components
|
||||
GJSLINT_FILES = $(foreach DIR,$(SRC_DIRS),$(wildcard $(DIR)/*.js))
|
||||
lint:
|
||||
@ -138,7 +130,6 @@ lint:
|
||||
GH_PAGES = $(BUILD_DIR)/gh-pages
|
||||
web: | extension compiler pages-repo \
|
||||
$(addprefix $(GH_PAGES)/, $(PDF_JS_FILES)) \
|
||||
$(addprefix $(GH_PAGES)/, $(PDF_WORKER_FILES)) \
|
||||
$(addprefix $(GH_PAGES)/, $(wildcard web/*.*)) \
|
||||
$(addprefix $(GH_PAGES)/, $(wildcard web/images/*.*)) \
|
||||
$(addprefix $(GH_PAGES)/, $(wildcard $(EXTENSION_SRC)/*.xpi))
|
||||
@ -161,7 +152,6 @@ pages-repo: | $(BUILD_DIR)
|
||||
git clone -b gh-pages $(REPO) $(GH_PAGES); \
|
||||
rm -rf $(GH_PAGES)/*; \
|
||||
fi;
|
||||
@mkdir -p $(GH_PAGES)/worker;
|
||||
@mkdir -p $(GH_PAGES)/web;
|
||||
@mkdir -p $(GH_PAGES)/web/images;
|
||||
@mkdir -p $(GH_PAGES)/$(EXTENSION_SRC);
|
||||
@ -169,9 +159,6 @@ pages-repo: | $(BUILD_DIR)
|
||||
$(GH_PAGES)/%.js: %.js
|
||||
@cp $< $@
|
||||
|
||||
$(GH_PAGES)/worker/%: worker/%
|
||||
@cp $< $@
|
||||
|
||||
$(GH_PAGES)/web/%: web/%
|
||||
@cp $< $@
|
||||
|
||||
@ -206,14 +193,12 @@ PDF_WEB_FILES = \
|
||||
web/viewer.js \
|
||||
web/viewer.html \
|
||||
$(NULL)
|
||||
extension:
|
||||
extension: | pdfjs
|
||||
# Copy a standalone version of pdf.js inside the content directory
|
||||
@rm -Rf $(EXTENSION_SRC)/$(CONTENT_DIR)/
|
||||
@mkdir -p $(EXTENSION_SRC)/$(CONTENT_DIR)/web
|
||||
@mkdir -p $(EXTENSION_SRC)/$(CONTENT_DIR)/worker
|
||||
@cp $(PDF_JS_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/
|
||||
@cp $(PDFJS_TARGET) $(EXTENSION_SRC)/$(CONTENT_DIR)/
|
||||
@cp -r $(PDF_WEB_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/web/
|
||||
@cp -r $(PDF_WORKER_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/worker/
|
||||
|
||||
# Create the xpi
|
||||
@cd $(EXTENSION_SRC); zip -r $(EXTENSION_NAME) *
|
||||
|
@ -4,9 +4,6 @@
|
||||
var ERRORS = 0, WARNINGS = 1, TODOS = 5;
|
||||
var verbosity = WARNINGS;
|
||||
|
||||
// Set this to true if you want to use workers.
|
||||
var useWorker = false;
|
||||
|
||||
//
|
||||
// getPdf()
|
||||
// Convenience function to perform binary Ajax GET
|
||||
@ -463,7 +460,7 @@ var PDFDoc = (function() {
|
||||
this.pageCache = [];
|
||||
|
||||
if (useWorker) {
|
||||
var worker = new Worker('../worker/pdf_worker_loader.js');
|
||||
var worker = new Worker('../build/pdf.js');
|
||||
} else {
|
||||
// If we don't use a worker, just post/sendMessage to the main thread.
|
||||
var worker = {
|
||||
|
28
src/pdf.js
28
src/pdf.js
@ -1,18 +1,32 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
// // TODO: Global namespace
|
||||
// var PDF = {};
|
||||
var PDF = {};
|
||||
|
||||
(function(){
|
||||
(function(globalScope){
|
||||
// Use strict in our context only - users might not want it
|
||||
'use strict';
|
||||
|
||||
// Set this to true if you want to use workers.
|
||||
var useWorker = false;
|
||||
var console;
|
||||
|
||||
// Files are inserted below - see Makefile
|
||||
/* INSERT_POINT */
|
||||
|
||||
// Expose API in global object
|
||||
window.PDFDoc = PDFDoc;
|
||||
window.getPdf = getPdf;
|
||||
// Worker-specific
|
||||
if (typeof window !== 'undefined') {
|
||||
console = window.console;
|
||||
} else {
|
||||
var consoleTimer = {};
|
||||
console = workerConsole;
|
||||
|
||||
// Listen for messages from the main thread.
|
||||
var handler = new MessageHandler('worker_processor', globalScope);
|
||||
WorkerProcessorHandler.setup(handler);
|
||||
}
|
||||
|
||||
})();
|
||||
// Expose API in global object
|
||||
PDF.PDFDoc = PDFDoc;
|
||||
PDF.getPdf = getPdf;
|
||||
})(this);
|
||||
|
@ -1,6 +1,49 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
function MessageHandler(name, comObj) {
|
||||
this.name = name;
|
||||
this.comObj = comObj;
|
||||
var ah = this.actionHandler = {};
|
||||
|
||||
ah['console_log'] = [function(data) {
|
||||
console.log.apply(console, data);
|
||||
}];
|
||||
ah['console_error'] = [function(data) {
|
||||
console.error.apply(console, data);
|
||||
}];
|
||||
|
||||
comObj.onmessage = function(event) {
|
||||
var data = event.data;
|
||||
if (data.action in ah) {
|
||||
var action = ah[data.action];
|
||||
action[0].call(action[1], data.data);
|
||||
} else {
|
||||
throw 'Unkown action from worker: ' + data.action;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
MessageHandler.prototype = {
|
||||
on: function(actionName, handler, scope) {
|
||||
var ah = this.actionHandler;
|
||||
if (ah[actionName]) {
|
||||
throw "There is already an actionName called '" + actionName + "'";
|
||||
}
|
||||
ah[actionName] = [handler, scope];
|
||||
},
|
||||
|
||||
send: function(actionName, data) {
|
||||
this.comObj.postMessage({
|
||||
action: actionName,
|
||||
data: data
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
var WorkerProcessorHandler = {
|
||||
setup: function(handler) {
|
||||
var pdfDoc = null;
|
||||
@ -97,3 +140,33 @@ var WorkerProcessorHandler = {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var workerConsole = {
|
||||
log: function log() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
postMessage({
|
||||
action: 'console_log',
|
||||
data: args
|
||||
});
|
||||
},
|
||||
|
||||
error: function error() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
postMessage({
|
||||
action: 'console_error',
|
||||
data: args
|
||||
});
|
||||
},
|
||||
|
||||
time: function(name) {
|
||||
consoleTimer[name] = Date.now();
|
||||
},
|
||||
|
||||
timeEnd: function(name) {
|
||||
var time = consoleTimer[name];
|
||||
if (time == null) {
|
||||
throw 'Unkown timer name ' + name;
|
||||
}
|
||||
this.log('Timer:', name, Date.now() - time);
|
||||
}
|
||||
};
|
@ -1,34 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
var consoleTimer = {};
|
||||
var console = {
|
||||
log: function log() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
postMessage({
|
||||
action: 'console_log',
|
||||
data: args
|
||||
});
|
||||
},
|
||||
|
||||
error: function error() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
postMessage({
|
||||
action: 'console_error',
|
||||
data: args
|
||||
});
|
||||
},
|
||||
|
||||
time: function(name) {
|
||||
consoleTimer[name] = Date.now();
|
||||
},
|
||||
|
||||
timeEnd: function(name) {
|
||||
var time = consoleTimer[name];
|
||||
if (time == null) {
|
||||
throw 'Unkown timer name ' + name;
|
||||
}
|
||||
this.log('Timer:', name, Date.now() - time);
|
||||
}
|
||||
};
|
||||
|
@ -1,43 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
function MessageHandler(name, comObj) {
|
||||
this.name = name;
|
||||
this.comObj = comObj;
|
||||
var ah = this.actionHandler = {};
|
||||
|
||||
ah['console_log'] = [function(data) {
|
||||
console.log.apply(console, data);
|
||||
}];
|
||||
ah['console_error'] = [function(data) {
|
||||
console.error.apply(console, data);
|
||||
}];
|
||||
|
||||
comObj.onmessage = function(event) {
|
||||
var data = event.data;
|
||||
if (data.action in ah) {
|
||||
var action = ah[data.action];
|
||||
action[0].call(action[1], data.data);
|
||||
} else {
|
||||
throw 'Unkown action from worker: ' + data.action;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
MessageHandler.prototype = {
|
||||
on: function(actionName, handler, scope) {
|
||||
var ah = this.actionHandler;
|
||||
if (ah[actionName]) {
|
||||
throw "There is already an actionName called '" + actionName + "'";
|
||||
}
|
||||
ah[actionName] = [handler, scope];
|
||||
},
|
||||
|
||||
send: function(actionName, data) {
|
||||
this.comObj.postMessage({
|
||||
action: actionName,
|
||||
data: data
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,19 +0,0 @@
|
||||
/* -*- 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('../metrics.js');
|
||||
importScripts('processor_handler.js');
|
||||
|
||||
// Listen for messages from the main thread.
|
||||
var pdfDoc = null;
|
||||
|
||||
var handler = new MessageHandler('worker_processor', this);
|
||||
WorkerProcessorHandler.setup(handler);
|
@ -122,7 +122,7 @@ var PDFView = {
|
||||
document.title = this.url = url;
|
||||
|
||||
var self = this;
|
||||
getPdf(
|
||||
PDF.getPdf(
|
||||
{
|
||||
url: url,
|
||||
progress: function getPdfProgress(evt) {
|
||||
@ -209,7 +209,7 @@ var PDFView = {
|
||||
while (container.hasChildNodes())
|
||||
container.removeChild(container.lastChild);
|
||||
|
||||
var pdf = new PDFDoc(data);
|
||||
var pdf = new PDF.PDFDoc(data);
|
||||
var pagesCount = pdf.numPages;
|
||||
document.getElementById('numPages').innerHTML = pagesCount;
|
||||
document.getElementById('pageNumber').max = pagesCount;
|
||||
|
Loading…
x
Reference in New Issue
Block a user