21 changed files with 540 additions and 261 deletions
@ -0,0 +1,160 @@ |
|||||||
|
REPO = git@github.com:andreasgal/pdf.js.git |
||||||
|
BUILD_DIR := build |
||||||
|
DEFAULT_BROWSERS := test/resources/browser_manifests/browser_manifest.json |
||||||
|
DEFAULT_TESTS := test/test_manifest.json |
||||||
|
|
||||||
|
# JS files needed for pdf.js.
|
||||||
|
# This list doesn't account for the 'worker' directory.
|
||||||
|
PDF_JS_FILES = \
|
||||||
|
pdf.js \
|
||||||
|
crypto.js \
|
||||||
|
fonts.js \
|
||||||
|
glyphlist.js \
|
||||||
|
$(NULL) |
||||||
|
|
||||||
|
# not sure what to do for all yet
|
||||||
|
all: help |
||||||
|
|
||||||
|
# make server
|
||||||
|
#
|
||||||
|
# This target starts a local web server at localhost:8888. This can be
|
||||||
|
# used for testing all browsers.
|
||||||
|
server: |
||||||
|
@cd test; python test.py --port=8888; |
||||||
|
|
||||||
|
test: shell-test browser-test |
||||||
|
|
||||||
|
# make browser-test
|
||||||
|
#
|
||||||
|
# This target runs in-browser tests using two primary arguments: a
|
||||||
|
# test manifest file, and a browser manifest file. Both are simple
|
||||||
|
# JSON formats, and examples can be found in the test/ directory. The
|
||||||
|
# target will inspect the environment for the PDF_TESTS and
|
||||||
|
# PDF_BROWSERS variables, and use those if found. Otherwise, the
|
||||||
|
# defaults at the top of this file are used.
|
||||||
|
ifeq ($(PDF_TESTS),) |
||||||
|
PDF_TESTS := $(DEFAULT_TESTS) |
||||||
|
endif |
||||||
|
ifeq ($(PDF_BROWSERS),) |
||||||
|
PDF_BROWSERS := $(DEFAULT_BROWSERS) |
||||||
|
endif |
||||||
|
|
||||||
|
browser-test: |
||||||
|
@if [ ! "$(PDF_BROWSERS)" ]; then \
|
||||||
|
echo "Browser manifest file $(PDF_BROWSERS) does not exist."; \
|
||||||
|
echo "Try copying one of the examples" \
|
||||||
|
"in test/resources/browser_manifests/"; \
|
||||||
|
exit 1; \
|
||||||
|
fi; |
||||||
|
|
||||||
|
cd test; \
|
||||||
|
python test.py --reftest \
|
||||||
|
--browserManifestFile=$(abspath $(PDF_BROWSERS)) \
|
||||||
|
--manifestFile=$(abspath $(PDF_TESTS)) |
||||||
|
|
||||||
|
# make shell-test
|
||||||
|
#
|
||||||
|
# This target runs all of the tests that can be run in a JS shell.
|
||||||
|
# The shell used is taken from the JS_SHELL environment variable. If
|
||||||
|
# that veriable is not defined, the script will attempt to use the copy
|
||||||
|
# of Rhino that comes with the Closure compiler used for producing the
|
||||||
|
# website.
|
||||||
|
SHELL_TARGET = $(NULL) |
||||||
|
ifeq ($(JS_SHELL),) |
||||||
|
JS_SHELL := "java -cp $(BUILD_DIR)/compiler.jar" |
||||||
|
JS_SHELL += "com.google.javascript.jscomp.mozilla.rhino.tools.shell.Main" |
||||||
|
SHELL_TARGET = compiler |
||||||
|
endif |
||||||
|
|
||||||
|
shell-test: shell-msg $(SHELL_TARGET) font-test |
||||||
|
shell-msg: |
||||||
|
ifeq ($(SHELL_TARGET), compiler) |
||||||
|
@echo "No JS_SHELL env variable present." |
||||||
|
@echo "The default is to find a copy of Rhino and try that." |
||||||
|
endif |
||||||
|
@echo "JS shell command is: $(JS_SHELL)" |
||||||
|
|
||||||
|
font-test: |
||||||
|
@echo "font test stub." |
||||||
|
|
||||||
|
# make lint
|
||||||
|
#
|
||||||
|
# This target runs the Closure Linter on most of our JS files.
|
||||||
|
# To install gjslint, see:
|
||||||
|
#
|
||||||
|
# <http://code.google.com/closure/utilities/docs/linter_howto.html>
|
||||||
|
SRC_DIRS := . utils worker web |
||||||
|
GJSLINT_FILES = $(foreach DIR,$(SRC_DIRS),$(wildcard $(DIR)/*.js)) |
||||||
|
lint: |
||||||
|
gjslint $(GJSLINT_FILES) |
||||||
|
|
||||||
|
# make web
|
||||||
|
#
|
||||||
|
# This target produces the website for the project, by checking out
|
||||||
|
# the gh-pages branch underneath the build directory, and then move
|
||||||
|
# the various viewer files into place.
|
||||||
|
#
|
||||||
|
# TODO: Use the Closure compiler to optimize the pdf.js files.
|
||||||
|
#
|
||||||
|
GH_PAGES = $(BUILD_DIR)/gh-pages |
||||||
|
web: | compiler pages-repo \ |
||||||
|
$(addprefix $(GH_PAGES)/, $(PDF_JS_FILES)) \
|
||||||
|
$(addprefix $(GH_PAGES)/, $(wildcard web/*.*)) \
|
||||||
|
$(addprefix $(GH_PAGES)/, $(wildcard web/images/*.*)) |
||||||
|
|
||||||
|
@cp $(GH_PAGES)/web/index.html.template $(GH_PAGES)/index.html; |
||||||
|
@cd $(GH_PAGES); git add -A; |
||||||
|
@echo "Website built in $(GH_PAGES)." |
||||||
|
|
||||||
|
# make pages-repo
|
||||||
|
#
|
||||||
|
# This target clones the gh-pages repo into the build directory. It
|
||||||
|
# deletes the current contents of the repo, since we overwrite
|
||||||
|
# everything with data from the master repo. The 'make web' target
|
||||||
|
# then uses 'git add -A' to track additions, modifications, moves,
|
||||||
|
# and deletions.
|
||||||
|
pages-repo: | $(BUILD_DIR) |
||||||
|
@if [ ! -d "$(GH_PAGES)" ]; then \
|
||||||
|
git clone -b gh-pages $(REPO) $(GH_PAGES); \
|
||||||
|
rm -rf $(GH_PAGES)/*; \
|
||||||
|
fi; |
||||||
|
@mkdir -p $(GH_PAGES)/web; |
||||||
|
@mkdir -p $(GH_PAGES)/web/images; |
||||||
|
|
||||||
|
$(GH_PAGES)/%.js: %.js |
||||||
|
@cp $< $@ |
||||||
|
|
||||||
|
$(GH_PAGES)/web/%: web/% |
||||||
|
@cp $< $@ |
||||||
|
|
||||||
|
$(GH_PAGES)/web/images/%: web/images/% |
||||||
|
@cp $< $@ |
||||||
|
|
||||||
|
# make compiler
|
||||||
|
#
|
||||||
|
# This target downloads the Closure compiler, and places it in the
|
||||||
|
# build directory. This target is also useful when the user doesn't
|
||||||
|
# have a JS shell available--we can have them use the Rhino shell that
|
||||||
|
# comes with Closure.
|
||||||
|
COMPILER_URL = http://closure-compiler.googlecode.com/files/compiler-latest.zip |
||||||
|
|
||||||
|
compiler: $(BUILD_DIR)/compiler.zip |
||||||
|
$(BUILD_DIR)/compiler.zip: | $(BUILD_DIR) |
||||||
|
curl $(COMPILER_URL) > $(BUILD_DIR)/compiler.zip; |
||||||
|
cd $(BUILD_DIR); unzip compiler.zip compiler.jar; |
||||||
|
|
||||||
|
# Make sure there's a build directory.
|
||||||
|
$(BUILD_DIR): |
||||||
|
mkdir -p $(BUILD_DIR) |
||||||
|
|
||||||
|
clean: |
||||||
|
rm -rf $(BUILD_DIR) |
||||||
|
|
||||||
|
# make help
|
||||||
|
#
|
||||||
|
# This target just prints out a message to read these comments. :)
|
||||||
|
help: |
||||||
|
@echo "Read the comments in the Makefile for guidance."; |
||||||
|
|
||||||
|
.PHONY: all test browser-test font-test shell-test \ |
||||||
|
shell-msg lint clean web compiler help server |
@ -0,0 +1,233 @@ |
|||||||
|
/* |
||||||
|
* A Test Driver for PDF.js |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
var appPath, browser, canvas, currentTaskIdx, manifest, stdout; |
||||||
|
|
||||||
|
function queryParams() { |
||||||
|
var qs = window.location.search.substring(1); |
||||||
|
var kvs = qs.split("&"); |
||||||
|
var params = { }; |
||||||
|
for (var i = 0; i < kvs.length; ++i) { |
||||||
|
var kv = kvs[i].split("="); |
||||||
|
params[unescape(kv[0])] = unescape(kv[1]); |
||||||
|
} |
||||||
|
return params; |
||||||
|
} |
||||||
|
|
||||||
|
function load() { |
||||||
|
var params = queryParams(); |
||||||
|
browser = params.browser; |
||||||
|
manifestFile = params.manifestFile; |
||||||
|
appPath = params.path; |
||||||
|
|
||||||
|
canvas = document.createElement("canvas"); |
||||||
|
canvas.mozOpaque = true; |
||||||
|
stdout = document.getElementById("stdout"); |
||||||
|
|
||||||
|
log("load...\n"); |
||||||
|
|
||||||
|
log("Harness thinks this browser is '"+ browser + "' with path " + appPath + "\n"); |
||||||
|
log("Fetching manifest "+ manifestFile +"..."); |
||||||
|
|
||||||
|
var r = new XMLHttpRequest(); |
||||||
|
r.open("GET", manifestFile, false); |
||||||
|
r.onreadystatechange = function(e) { |
||||||
|
if (r.readyState == 4) { |
||||||
|
log("done\n"); |
||||||
|
manifest = JSON.parse(r.responseText); |
||||||
|
currentTaskIdx = 0, nextTask(); |
||||||
|
} |
||||||
|
}; |
||||||
|
r.send(null); |
||||||
|
} |
||||||
|
window.onload = load; |
||||||
|
|
||||||
|
function nextTask() { |
||||||
|
if (currentTaskIdx == manifest.length) { |
||||||
|
return done(); |
||||||
|
} |
||||||
|
var task = manifest[currentTaskIdx]; |
||||||
|
task.round = 0; |
||||||
|
|
||||||
|
log("Loading file "+ task.file +"\n"); |
||||||
|
|
||||||
|
var r = new XMLHttpRequest(); |
||||||
|
r.open("GET", task.file); |
||||||
|
r.mozResponseType = r.responseType = "arraybuffer"; |
||||||
|
r.onreadystatechange = function() { |
||||||
|
var failure; |
||||||
|
if (r.readyState == 4) { |
||||||
|
var data = r.mozResponseArrayBuffer || r.mozResponse || |
||||||
|
r.responseArrayBuffer || r.response; |
||||||
|
|
||||||
|
try { |
||||||
|
task.pdfDoc = new PDFDoc(new Stream(data)); |
||||||
|
} catch(e) { |
||||||
|
failure = 'load PDF doc: '+ e.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
task.pageNum = 1, nextPage(task, failure); |
||||||
|
} |
||||||
|
}; |
||||||
|
r.send(null); |
||||||
|
} |
||||||
|
|
||||||
|
function isLastPage(task) { |
||||||
|
return (task.pdfDoc && (task.pageNum > task.pdfDoc.numPages)); |
||||||
|
} |
||||||
|
|
||||||
|
function nextPage(task, loadError) { |
||||||
|
if (isLastPage(task)) { |
||||||
|
if (++task.round < task.rounds) { |
||||||
|
log(" Round "+ (1 + task.round) +"\n"); |
||||||
|
task.pageNum = 1; |
||||||
|
} else { |
||||||
|
++currentTaskIdx, nextTask(); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var failure = loadError || ''; |
||||||
|
|
||||||
|
var ctx = null; |
||||||
|
var fonts; |
||||||
|
var gfx = null; |
||||||
|
var page = null; |
||||||
|
|
||||||
|
if (!failure) { |
||||||
|
log(" loading page "+ task.pageNum +"... "); |
||||||
|
ctx = canvas.getContext("2d"); |
||||||
|
fonts = []; |
||||||
|
try { |
||||||
|
gfx = new CanvasGraphics(ctx); |
||||||
|
page = task.pdfDoc.getPage(task.pageNum); |
||||||
|
page.compile(gfx, fonts); |
||||||
|
} catch(e) { |
||||||
|
failure = 'compile: '+ e.toString(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!failure) { |
||||||
|
try { |
||||||
|
var pdfToCssUnitsCoef = 96.0 / 72.0; |
||||||
|
// using mediaBox for the canvas size
|
||||||
|
var pageWidth = (page.mediaBox[2] - page.mediaBox[0]); |
||||||
|
var pageHeight = (page.mediaBox[3] - page.mediaBox[1]); |
||||||
|
canvas.width = pageWidth * pdfToCssUnitsCoef; |
||||||
|
canvas.height = pageHeight * pdfToCssUnitsCoef; |
||||||
|
clear(ctx); |
||||||
|
} catch(e) { |
||||||
|
failure = 'page setup: '+ e.toString(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!failure) { |
||||||
|
try { |
||||||
|
FontLoader.bind(fonts, function() { |
||||||
|
snapshotCurrentPage(gfx, page, task, failure); |
||||||
|
}); |
||||||
|
} catch(e) { |
||||||
|
failure = 'fonts: '+ e.toString(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (failure) { |
||||||
|
// Skip right to snapshotting if there was a failure, since the
|
||||||
|
// fonts might be in an inconsistent state.
|
||||||
|
snapshotCurrentPage(gfx, page, task, failure); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function snapshotCurrentPage(gfx, page, task, failure) { |
||||||
|
log("done, snapshotting... "); |
||||||
|
|
||||||
|
if (!failure) { |
||||||
|
try { |
||||||
|
page.display(gfx); |
||||||
|
} catch(e) { |
||||||
|
failure = 'render: '+ e.toString(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
sendTaskResult(canvas.toDataURL("image/png"), task, failure); |
||||||
|
log("done"+ (failure ? " (failed!: "+ failure +")" : "") +"\n"); |
||||||
|
|
||||||
|
// Set up the next request
|
||||||
|
backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0; |
||||||
|
setTimeout(function() { |
||||||
|
++task.pageNum, nextPage(task); |
||||||
|
}, |
||||||
|
backoff |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
function sendQuitRequest() { |
||||||
|
var r = new XMLHttpRequest(); |
||||||
|
r.open("POST", "/tellMeToQuit?path=" + escape(appPath), false); |
||||||
|
r.send(""); |
||||||
|
} |
||||||
|
|
||||||
|
function quitApp() { |
||||||
|
log("Done!"); |
||||||
|
document.body.innerHTML = "Tests are finished. <h1>CLOSE ME!</h1>"; |
||||||
|
if (window.SpecialPowers) { |
||||||
|
SpecialPowers.quitApplication(); |
||||||
|
} else { |
||||||
|
sendQuitRequest(); |
||||||
|
window.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function done() { |
||||||
|
if (inFlightRequests > 0) { |
||||||
|
document.getElementById("inFlightCount").innerHTML = inFlightRequests; |
||||||
|
setTimeout(done, 100); |
||||||
|
} else { |
||||||
|
setTimeout(quitApp, 100); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var inFlightRequests = 0; |
||||||
|
function sendTaskResult(snapshot, task, failure) { |
||||||
|
var result = { browser: browser, |
||||||
|
id: task.id, |
||||||
|
numPages: task.pdfDoc.numPages, |
||||||
|
failure: failure, |
||||||
|
file: task.file, |
||||||
|
round: task.round, |
||||||
|
page: task.pageNum, |
||||||
|
snapshot: snapshot }; |
||||||
|
|
||||||
|
var r = new XMLHttpRequest(); |
||||||
|
// (The POST URI is ignored atm.)
|
||||||
|
r.open("POST", "/submit_task_results", true); |
||||||
|
r.setRequestHeader("Content-Type", "application/json"); |
||||||
|
r.onreadystatechange = function(e) { |
||||||
|
if (r.readyState == 4) { |
||||||
|
inFlightRequests--; |
||||||
|
} |
||||||
|
} |
||||||
|
document.getElementById("inFlightCount").innerHTML = inFlightRequests++; |
||||||
|
r.send(JSON.stringify(result)); |
||||||
|
} |
||||||
|
|
||||||
|
function clear(ctx) { |
||||||
|
ctx.save(); |
||||||
|
ctx.fillStyle = "rgb(255, 255, 255)"; |
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height); |
||||||
|
ctx.restore(); |
||||||
|
} |
||||||
|
|
||||||
|
/* Auto-scroll if the scrollbar is near the bottom, otherwise do nothing. */ |
||||||
|
function checkScrolling() { |
||||||
|
if ((stdout.scrollHeight - stdout.scrollTop) <= stdout.offsetHeight) { |
||||||
|
stdout.scrollTop = stdout.scrollHeight; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function log(str) { |
||||||
|
stdout.innerHTML += str; |
||||||
|
checkScrolling(); |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
http://www.unicode.org/charts/PDF/U10450.pdf |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
@ -0,0 +1,88 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta charset='utf-8'> |
||||||
|
|
||||||
|
<title>andreasgal/pdf.js @ GitHub</title> |
||||||
|
|
||||||
|
<style type="text/css"> |
||||||
|
body { |
||||||
|
margin-top: 1.0em; |
||||||
|
background-color: #482a30; |
||||||
|
font-family: Helvetica, Arial, FreeSans, san-serif; |
||||||
|
color: #ffffff; |
||||||
|
} |
||||||
|
#container { |
||||||
|
margin: 0 auto; |
||||||
|
width: 700px; |
||||||
|
} |
||||||
|
h1 { font-size: 3.8em; color: #b7d5cf; margin-bottom: 3px; } |
||||||
|
h1 .small { font-size: 0.4em; } |
||||||
|
h1 a { text-decoration: none } |
||||||
|
h2 { font-size: 1.5em; color: #b7d5cf; } |
||||||
|
h3 { text-align: center; color: #b7d5cf; } |
||||||
|
a { color: #b7d5cf; } |
||||||
|
.description { font-size: 1.2em; margin-bottom: 30px; margin-top: 30px; font-style: italic;} |
||||||
|
.download { float: right; } |
||||||
|
pre { background: #000; color: #fff; padding: 15px;} |
||||||
|
hr { border: 0; width: 80%; border-bottom: 1px solid #aaa} |
||||||
|
.footer { text-align:center; padding-top:30px; font-style: italic; } |
||||||
|
</style> |
||||||
|
</head> |
||||||
|
|
||||||
|
<body> |
||||||
|
<a href="http://github.com/andreasgal/pdf.js"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a> |
||||||
|
|
||||||
|
<div id="container"> |
||||||
|
|
||||||
|
<div class="download"> |
||||||
|
<a href="http://github.com/andreasgal/pdf.js/zipball/master"> |
||||||
|
<img border="0" width="90" src="http://github.com/images/modules/download/zip.png"></a> |
||||||
|
<a href="http://github.com/andreasgal/pdf.js/tarball/master"> |
||||||
|
<img border="0" width="90" src="http://github.com/images/modules/download/tar.png"></a> |
||||||
|
</div> |
||||||
|
|
||||||
|
<h1><a href="http://github.com/andreasgal/pdf.js">pdf.js</a> |
||||||
|
<span class="small">by <a href="http://github.com/andreasgal">andreasgal</a></span></h1> |
||||||
|
|
||||||
|
<div class="description"> |
||||||
|
PDF Reader in JavaScript |
||||||
|
</div> |
||||||
|
|
||||||
|
<h2>Try it out!</h2> |
||||||
|
<p>Live <a href="web/multi_page_viewer.html">demo</a> lives here.</p> |
||||||
|
|
||||||
|
<h2>Authors</h2> |
||||||
|
<p>Vivien Nicolas (21@vingtetun.org) |
||||||
|
<br/>Andreas Gal (andreas.gal@gmail.com) |
||||||
|
<br/>Soumya Deb (debloper@gmail.com) |
||||||
|
<br/>Chris Jones (jones.chris.g@gmail.com) |
||||||
|
<br/>Justin D'Arcangelo (justindarc@gmail.com) |
||||||
|
<br/>sbarman (sbarman@eecs.berkeley.edu) |
||||||
|
<br/> |
||||||
|
<br/> </p> |
||||||
|
<h2>Contact</h2> |
||||||
|
<p> (andreas.gal@gmail.com) |
||||||
|
<br/> </p> |
||||||
|
|
||||||
|
|
||||||
|
<h2>Download</h2> |
||||||
|
<p> |
||||||
|
You can download this project in either |
||||||
|
<a href="http://github.com/andreasgal/pdf.js/zipball/master">zip</a> or |
||||||
|
<a href="http://github.com/andreasgal/pdf.js/tarball/master">tar</a> formats. |
||||||
|
</p> |
||||||
|
<p>You can also clone the project with <a href="http://git-scm.com">Git</a> |
||||||
|
by running: |
||||||
|
<pre>$ git clone git://github.com/andreasgal/pdf.js</pre> |
||||||
|
</p> |
||||||
|
|
||||||
|
<div class="footer"> |
||||||
|
get the source code on GitHub : <a href="http://github.com/andreasgal/pdf.js">andreasgal/pdf.js</a> |
||||||
|
</div> |
||||||
|
|
||||||
|
</div> |
||||||
|
|
||||||
|
|
||||||
|
</body> |
||||||
|
</html> |
@ -1,10 +1,10 @@ |
|||||||
<html> |
<html> |
||||||
<head> |
<head> |
||||||
<title>Simple pdf.js page worker viewer</title> |
<title>Simple pdf.js page worker viewer</title> |
||||||
<script type="text/javascript" src="fonts.js"></script> |
<script type="text/javascript" src="../fonts.js"></script> |
||||||
<script type="text/javascript" src="glyphlist.js"></script> |
<script type="text/javascript" src="../glyphlist.js"></script> |
||||||
<script type="text/javascript" src="pdf.js"></script> |
<script type="text/javascript" src="../pdf.js"></script> |
||||||
<script type="text/javascript" src="worker/client.js"></script> |
<script type="text/javascript" src="../worker/client.js"></script> |
||||||
<script> |
<script> |
||||||
|
|
||||||
|
|
Loading…
Reference in new issue