diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..fa2cf816e --- /dev/null +++ b/Makefile @@ -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: +# +# +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 diff --git a/test/pdfs/shavian.pdf.link b/test/pdfs/shavian.pdf.link new file mode 100644 index 000000000..42c438644 --- /dev/null +++ b/test/pdfs/shavian.pdf.link @@ -0,0 +1 @@ +http://www.unicode.org/charts/PDF/U10450.pdf \ No newline at end of file diff --git a/test/test.py b/test/test.py index 00b87f786..3f007a21a 100644 --- a/test/test.py +++ b/test/test.py @@ -17,7 +17,6 @@ TMPDIR = 'tmp' VERBOSE = False SERVER_HOST = "localhost" -SERVER_PORT = 8080 class TestOptions(OptionParser): def __init__(self, **kwargs): @@ -34,6 +33,8 @@ class TestOptions(OptionParser): self.add_option("--reftest", action="store_true", dest="reftest", help="Automatically start reftest showing comparison test failures, if there are any.", default=False) + self.add_option("--port", action="store", dest="port", type="int", + help="The port the HTTP server should listen on.", default=8080) self.set_usage(USAGE_EXAMPLE) def verifyOptions(self, options): @@ -44,7 +45,7 @@ class TestOptions(OptionParser): if options.browser and options.browserManifestFile: print "Warning: ignoring browser argument since manifest file was also supplied" if not options.browser and not options.browserManifestFile: - print "No browser arguments supplied, so just starting server on port %s." % SERVER_PORT + print "Starting server on port %s." % options.port return options def prompt(question): @@ -325,7 +326,7 @@ def startBrowsers(browsers, options): for b in browsers: b.setup() print 'Launching', b.name - host = 'http://%s:%s' % (SERVER_HOST, SERVER_PORT) + host = 'http://%s:%s' % (SERVER_HOST, options.port) path = '/test/test_slave.html?' qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile) qs += '&path=' + b.path @@ -482,8 +483,8 @@ def maybeUpdateRefImages(options, browser): print 'done' -def startReftest(browser): - url = "http://%s:%s" % (SERVER_HOST, SERVER_PORT) +def startReftest(browser, options): + url = "http://%s:%s" % (SERVER_HOST, options.port) url += "/test/resources/reftest-analyzer.xhtml" url += "#web=/test/eq.log" try: @@ -511,7 +512,7 @@ def runTests(options, browsers): maybeUpdateRefImages(options, browsers[0]) elif options.reftest and State.numEqFailures > 0: print "\nStarting reftest harness to examine %d eq test failures." % State.numEqFailures - startReftest(browsers[0]) + startReftest(browsers[0], options) def main(): optionParser = TestOptions() @@ -520,7 +521,7 @@ def main(): if options == None: sys.exit(1) - httpd = TestServer((SERVER_HOST, SERVER_PORT), PDFTestHandler) + httpd = TestServer((SERVER_HOST, options.port), PDFTestHandler) httpd_thread = threading.Thread(target=httpd.serve_forever) httpd_thread.setDaemon(True) httpd_thread.start() @@ -531,8 +532,11 @@ def main(): else: # just run the server print "Running HTTP server. Press Ctrl-C to quit." - while True: - time.sleep(1) + try: + while True: + time.sleep(1) + except (KeyboardInterrupt): + print "\nExiting." if __name__ == '__main__': main() diff --git a/test/test_manifest.json b/test/test_manifest.json index 06787925f..4302e1f6e 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -26,6 +26,12 @@ "rounds": 1, "type": "load" }, + { "id": "shavian-load", + "file": "pdfs/shavian.pdf", + "link": true, + "rounds": 1, + "type": "load" + }, { "id": "sizes", "file": "pdfs/sizes.pdf", "rounds": 1, diff --git a/compressed.tracemonkey-pldi-09.pdf b/web/compressed.tracemonkey-pldi-09.pdf similarity index 100% rename from compressed.tracemonkey-pldi-09.pdf rename to web/compressed.tracemonkey-pldi-09.pdf diff --git a/images/buttons.png b/web/images/buttons.png similarity index 100% rename from images/buttons.png rename to web/images/buttons.png diff --git a/images/source/Buttons.psd.zip b/web/images/source/Buttons.psd.zip similarity index 100% rename from images/source/Buttons.psd.zip rename to web/images/source/Buttons.psd.zip diff --git a/images/source/FileButton.psd.zip b/web/images/source/FileButton.psd.zip similarity index 100% rename from images/source/FileButton.psd.zip rename to web/images/source/FileButton.psd.zip diff --git a/web/index.html.template b/web/index.html.template new file mode 100644 index 000000000..c3086f078 --- /dev/null +++ b/web/index.html.template @@ -0,0 +1,88 @@ + + + + + + andreasgal/pdf.js @ GitHub + + + + + + Fork me on GitHub + +
+ +
+ + + + +
+ +

pdf.js + by andreasgal

+ +
+ PDF Reader in JavaScript +
+ +

Try it out!

+

Live demo lives here.

+ +

Authors

+

Vivien Nicolas (21@vingtetun.org) +
Andreas Gal (andreas.gal@gmail.com) +
Soumya Deb (debloper@gmail.com) +
Chris Jones (jones.chris.g@gmail.com) +
Justin D'Arcangelo (justindarc@gmail.com) +
sbarman (sbarman@eecs.berkeley.edu) +
+

+

Contact

+

(andreas.gal@gmail.com) +

+ + +

Download

+

+ You can download this project in either + zip or + tar formats. +

+

You can also clone the project with Git + by running: +

$ git clone git://github.com/andreasgal/pdf.js
+

+ + + +
+ + + + diff --git a/multi_page_viewer.css b/web/multi_page_viewer.css similarity index 100% rename from multi_page_viewer.css rename to web/multi_page_viewer.css diff --git a/multi_page_viewer.html b/web/multi_page_viewer.html similarity index 86% rename from multi_page_viewer.html rename to web/multi_page_viewer.html index df71d6690..841d2dba9 100644 --- a/multi_page_viewer.html +++ b/web/multi_page_viewer.html @@ -4,10 +4,10 @@ pdf.js Multi-Page Viewer - - - - + + + + diff --git a/multi_page_viewer.js b/web/multi_page_viewer.js similarity index 100% rename from multi_page_viewer.js rename to web/multi_page_viewer.js diff --git a/viewer.css b/web/viewer.css similarity index 100% rename from viewer.css rename to web/viewer.css diff --git a/viewer.html b/web/viewer.html similarity index 72% rename from viewer.html rename to web/viewer.html index c600547f0..a5b553c1f 100644 --- a/viewer.html +++ b/web/viewer.html @@ -4,11 +4,10 @@ - - - - - + + + + diff --git a/viewer.js b/web/viewer.js similarity index 100% rename from viewer.js rename to web/viewer.js diff --git a/viewer_worker.html b/web/viewer_worker.html similarity index 82% rename from viewer_worker.html rename to web/viewer_worker.html index 89fb8a087..21a5be3ca 100644 --- a/viewer_worker.html +++ b/web/viewer_worker.html @@ -1,10 +1,10 @@ Simple pdf.js page worker viewer - - - - + + + +