Merge with upstream

This commit is contained in:
Vivien Nicolas 2011-07-11 13:49:26 +02:00
commit 068bfa0bfe
37 changed files with 7857 additions and 6844 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*~
pdf.pdf pdf.pdf
intelisa.pdf intelisa.pdf
openweb_tm-PRINT.pdf openweb_tm-PRINT.pdf
local.mk

163
Makefile Normal file
View File

@ -0,0 +1,163 @@
REPO = git@github.com:andreasgal/pdf.js.git
BUILD_DIR := build
DEFAULT_BROWSERS := resources/browser_manifests/browser_manifest.json
DEFAULT_TESTS := test_manifest.json
# Let folks define custom rules for their clones.
-include local.mk
# 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 [ ! -f "test/$(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=$(PDF_BROWSERS) \
--manifestFile=$(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 variable 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

View File

@ -1,7 +1,7 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
"use strict"; 'use strict';
var ARCFourCipher = (function() { var ARCFourCipher = (function() {
function constructor(key) { function constructor(key) {
@ -30,7 +30,7 @@ var ARCFourCipher = (function() {
a = (a + 1) & 0xFF; a = (a + 1) & 0xFF;
tmp = s[a]; tmp = s[a];
b = (b + tmp) & 0xFF; b = (b + tmp) & 0xFF;
tmp2 = s[b] tmp2 = s[b];
s[a] = tmp2; s[a] = tmp2;
s[b] = tmp; s[b] = tmp;
output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF]; output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
@ -50,18 +50,19 @@ var md5 = (function() {
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]); 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
var k = new Int32Array([ var k = new Int32Array([
-680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426, -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
-1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162, -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632, 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
643717713, -373897302, -701558691, 38016083, -660478335, -405537848, 568446438, 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
-1019803690, -187363961, 1163531501, -1444681467, -51403784, 1735328473, 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
-1926607734, -378558, -2022574463, 1839030562, -35309556, -1530992060, 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
1272893353, -155497632, -1094730640, 681279174, -358537222, -722521979, -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
76029189, -640364487, -421815835, 530742520, -995338651, -198630844, 1126891415, -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
-1416354905, -57434055, 1700485571, -1894986606, -1051523, -2054922799, -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
1873313359, -30611744, -1560198380, 1309151649, -145523070, -1120210379, -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
718787259, -343485551]); -145523070, -1120210379, 718787259, -343485551]);
function hash(data, offset, length) { function hash(data, offset, length) {
var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878; var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
@ -87,8 +88,10 @@ var md5 = (function() {
// TODO ArrayBuffer ? // TODO ArrayBuffer ?
var w = new Int32Array(16); var w = new Int32Array(16);
for (i = 0; i < paddedLength;) { for (i = 0; i < paddedLength;) {
for (j = 0; j < 16; ++j, i += 4) for (j = 0; j < 16; ++j, i += 4) {
w[j] = padded[i] | (padded[i + 1] << 8) | (padded[i + 2] << 16) | (padded[i + 3] << 24); w[j] = (padded[i] | (padded[i + 1] << 8) |
(padded[i + 2] << 16) | (padded[i + 3] << 24));
}
var a = h0, b = h1, c = h2, d = h3, f, g; var a = h0, b = h1, c = h2, d = h3, f, g;
for (j = 0; j < 64; ++j) { for (j = 0; j < 64; ++j) {
if (j < 16) { if (j < 16) {
@ -131,7 +134,7 @@ var CipherTransform = (function() {
this.streamCipherConstructor = streamCipherConstructor; this.streamCipherConstructor = streamCipherConstructor;
} }
constructor.prototype = { constructor.prototype = {
createStream: function (stream) { createStream: function(stream) {
var cipher = new this.streamCipherConstructor(); var cipher = new this.streamCipherConstructor();
return new DecryptStream(stream, function(data) { return new DecryptStream(stream, function(data) {
return cipher.encryptBlock(data); return cipher.encryptBlock(data);
@ -139,19 +142,22 @@ var CipherTransform = (function() {
}, },
decryptString: function(s) { decryptString: function(s) {
var cipher = new this.stringCipherConstructor(); var cipher = new this.stringCipherConstructor();
var data = string2bytes(s); var data = stringToBytes(s);
data = cipher.encryptBlock(data); data = cipher.encryptBlock(data);
return bytes2string(data); return bytesToString(data);
} }
}; };
return constructor; return constructor;
})(); })();
var CipherTransformFactory = (function() { var CipherTransformFactory = (function() {
function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength) { function prepareKeyData(fileId, password, ownerPassword, userPassword,
flags, revision, keyLength) {
var defaultPasswordBytes = new Uint8Array([ var defaultPasswordBytes = new Uint8Array([
0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41, 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08, 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80, 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]); 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
var hashData = new Uint8Array(88), i = 0, j, n; var hashData = new Uint8Array(88), i = 0, j, n;
if (password) { if (password) {
n = Math.min(32, password.length); n = Math.min(32, password.length);
@ -183,9 +189,10 @@ var CipherTransformFactory = (function() {
var cipher, checkData; var cipher, checkData;
if (revision >= 3) { if (revision >= 3) {
// padded password in hashData, we can use this array for user password check // padded password in hashData, we can use this array for user
// password check
i = 32; i = 32;
for(j = 0, n = fileId.length; j < n; ++j) for (j = 0, n = fileId.length; j < n; ++j)
hashData[i++] = fileId[j]; hashData[i++] = fileId[j];
cipher = new ARCFourCipher(encryptionKey); cipher = new ARCFourCipher(encryptionKey);
var checkData = cipher.encryptBlock(md5(hashData, 0, i)); var checkData = cipher.encryptBlock(md5(hashData, 0, i));
@ -203,37 +210,38 @@ var CipherTransformFactory = (function() {
} }
for (j = 0, n = checkData.length; j < n; ++j) { for (j = 0, n = checkData.length; j < n; ++j) {
if (userPassword[j] != checkData[j]) if (userPassword[j] != checkData[j])
error("incorrect password"); error('incorrect password');
} }
return encryptionKey; return encryptionKey;
} }
function constructor(dict, fileId, password) { function constructor(dict, fileId, password) {
var filter = dict.get("Filter"); var filter = dict.get('Filter');
if (!IsName(filter) || filter.name != "Standard") if (!IsName(filter) || filter.name != 'Standard')
error("unknown encryption method"); error('unknown encryption method');
this.dict = dict; this.dict = dict;
var algorithm = dict.get("V"); var algorithm = dict.get('V');
if (!IsInt(algorithm) || if (!IsInt(algorithm) ||
(algorithm != 1 && algorithm != 2)) (algorithm != 1 && algorithm != 2))
error("unsupported encryption algorithm"); error('unsupported encryption algorithm');
// TODO support algorithm 4 // TODO support algorithm 4
var keyLength = dict.get("Length") || 40; var keyLength = dict.get('Length') || 40;
if (!IsInt(keyLength) || if (!IsInt(keyLength) ||
keyLength < 40 || (keyLength % 8) != 0) keyLength < 40 || (keyLength % 8) != 0)
error("invalid key length"); error('invalid key length');
// prepare keys // prepare keys
var ownerPassword = stringToBytes(dict.get("O")); var ownerPassword = stringToBytes(dict.get('O'));
var userPassword = stringToBytes(dict.get("U")); var userPassword = stringToBytes(dict.get('U'));
var flags = dict.get("P"); var flags = dict.get('P');
var revision = dict.get("R"); var revision = dict.get('R');
var fileIdBytes = stringToBytes(fileId); var fileIdBytes = stringToBytes(fileId);
var passwordBytes; var passwordBytes;
if (password) if (password)
passwordBytes = stringToBytes(password); passwordBytes = stringToBytes(password);
this.encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, this.encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
ownerPassword, userPassword, flags, revision, keyLength); ownerPassword, userPassword,
flags, revision, keyLength);
} }
constructor.prototype = { constructor.prototype = {

1338
fonts.js Normal file → Executable file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
"use strict"; 'use strict';
var GlyphsUnicode = { var GlyphsUnicode = {
A: 0x0041, A: 0x0041,
@ -2474,8 +2474,8 @@ var GlyphsUnicode = {
lameddageshhebrew: 0xFB3C, lameddageshhebrew: 0xFB3C,
lamedhebrew: 0x05DC, lamedhebrew: 0x05DC,
lamedholam: 0x05DC05B9, lamedholam: 0x05DC05B9,
lamedholamdagesh: "05DC 05B9 05BC", lamedholamdagesh: '05DC 05B9 05BC',
lamedholamdageshhebrew: "05DC 05B9 05BC", lamedholamdageshhebrew: '05DC 05B9 05BC',
lamedholamhebrew: 0x05DC05B9, lamedholamhebrew: 0x05DC05B9,
lamfinalarabic: 0xFEDE, lamfinalarabic: 0xFEDE,
lamhahinitialarabic: 0xFCCA, lamhahinitialarabic: 0xFCCA,
@ -2486,8 +2486,8 @@ var GlyphsUnicode = {
lammedialarabic: 0xFEE0, lammedialarabic: 0xFEE0,
lammeemhahinitialarabic: 0xFD88, lammeemhahinitialarabic: 0xFD88,
lammeeminitialarabic: 0xFCCC, lammeeminitialarabic: 0xFCCC,
lammeemjeeminitialarabic: "FEDF FEE4 FEA0", lammeemjeeminitialarabic: 'FEDF FEE4 FEA0',
lammeemkhahinitialarabic: "FEDF FEE4 FEA8", lammeemkhahinitialarabic: 'FEDF FEE4 FEA8',
largecircle: 0x25EF, largecircle: 0x25EF,
lbar: 0x019A, lbar: 0x019A,
lbelt: 0x026C, lbelt: 0x026C,
@ -3250,7 +3250,7 @@ var GlyphsUnicode = {
reharmenian: 0x0580, reharmenian: 0x0580,
rehfinalarabic: 0xFEAE, rehfinalarabic: 0xFEAE,
rehiragana: 0x308C, rehiragana: 0x308C,
rehyehaleflamarabic: "0631 FEF3 FE8E 0644", rehyehaleflamarabic: '0631 FEF3 FE8E 0644',
rekatakana: 0x30EC, rekatakana: 0x30EC,
rekatakanahalfwidth: 0xFF9A, rekatakanahalfwidth: 0xFF9A,
resh: 0x05E8, resh: 0x05E8,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Binary file not shown.

View File

@ -1,230 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
body {
background-color: #929292;
font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial, Verdana, sans-serif;
margin: 0px;
padding: 0px;
}
canvas {
box-shadow: 0px 4px 10px #000;
-moz-box-shadow: 0px 4px 10px #000;
-webkit-box-shadow: 0px 4px 10px #000;
}
span {
font-size: 0.8em;
}
.control {
display: inline-block;
float: left;
margin: 0px 20px 0px 0px;
padding: 0px 4px 0px 0px;
}
.control > input {
float: left;
border: 1px solid #4d4d4d;
height: 20px;
padding: 0px;
margin: 0px 2px 0px 0px;
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
-moz-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
-webkit-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
}
.control > select {
float: left;
border: 1px solid #4d4d4d;
height: 22px;
padding: 2px 0px 0px;
margin: 0px 0px 1px;
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
-moz-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
-webkit-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25);
}
.control > span {
cursor: default;
float: left;
height: 18px;
margin: 5px 2px 0px;
padding: 0px;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
}
.control .label {
clear: both;
float: left;
font-size: 0.65em;
margin: 2px 0px 0px;
position: relative;
text-align: center;
width: 100%;
}
.thumbnailPageNumber {
color: #fff;
font-size: 0.55em;
text-align: right;
margin: -6px 2px 6px 0px;
width: 102px;
}
.thumbnail {
width: 104px;
height: 134px;
margin: 0px auto 10px;
}
.page {
width: 816px;
height: 1056px;
margin: 10px auto;
}
#controls {
background-color: #eee;
border-bottom: 1px solid #666;
padding: 4px 0px 0px 8px;
position: fixed;
left: 0px;
top: 0px;
height: 40px;
width: 100%;
box-shadow: 0px 2px 8px #000;
-moz-box-shadow: 0px 2px 8px #000;
-webkit-box-shadow: 0px 2px 8px #000;
}
#controls input {
user-select: text;
-moz-user-select: text;
-webkit-user-select: text;
}
#previousPageButton {
background: url('images/buttons.png') no-repeat 0px -23px;
cursor: default;
display: inline-block;
float: left;
margin: 0px;
width: 28px;
height: 23px;
}
#previousPageButton.down {
background: url('images/buttons.png') no-repeat 0px -46px;
}
#previousPageButton.disabled {
background: url('images/buttons.png') no-repeat 0px 0px;
}
#nextPageButton {
background: url('images/buttons.png') no-repeat -28px -23px;
cursor: default;
display: inline-block;
float: left;
margin: 0px;
width: 28px;
height: 23px;
}
#nextPageButton.down {
background: url('images/buttons.png') no-repeat -28px -46px;
}
#nextPageButton.disabled {
background: url('images/buttons.png') no-repeat -28px 0px;
}
#openFileButton {
background: url('images/buttons.png') no-repeat -56px -23px;
cursor: default;
display: inline-block;
float: left;
margin: 0px 0px 0px 3px;
width: 29px;
height: 23px;
}
#openFileButton.down {
background: url('images/buttons.png') no-repeat -56px -46px;
}
#openFileButton.disabled {
background: url('images/buttons.png') no-repeat -56px 0px;
}
#fileInput {
display: none;
}
#pageNumber {
text-align: right;
}
#sidebar {
position: fixed;
width: 200px;
top: 62px;
bottom: 18px;
left: -140px;
transition: left 0.25s ease-in-out 1s;
-moz-transition: left 0.25s ease-in-out 1s;
-webkit-transition: left 0.25s ease-in-out 1s;
}
#sidebar:hover {
left: 0px;
transition: left 0.25s ease-in-out 0s;
-moz-transition: left 0.25s ease-in-out 0s;
-webkit-transition: left 0.25s ease-in-out 0s;
}
#sidebarBox {
background-color: rgba(0, 0, 0, 0.7);
width: 150px;
height: 100%;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
-moz-border-radius-topright: 8px;
-moz-border-radius-bottomright: 8px;
-webkit-border-top-right-radius: 8px;
-webkit-border-bottom-right-radius: 8px;
box-shadow: 0px 2px 8px #000;
-moz-box-shadow: 0px 2px 8px #000;
-webkit-box-shadow: 0px 2px 8px #000;
}
#sidebarScrollView {
position: absolute;
overflow: hidden;
overflow-y: auto;
top: 10px;
bottom: 10px;
left: 10px;
width: 130px;
}
#sidebarContentView {
height: auto;
width: 100px;
}
#viewer {
margin: 44px 0px 0px;
padding: 8px 0px;
}

2634
pdf.js

File diff suppressed because it is too large Load Diff

209
test/driver.js Normal file
View File

@ -0,0 +1,209 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/*
* 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 page = null;
if (!failure) {
try {
log(" loading page "+ task.pageNum +"... ");
ctx = canvas.getContext("2d");
page = task.pdfDoc.getPage(task.pageNum);
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);
page.startRendering(
ctx,
function() { snapshotCurrentPage(page, task, failure); });
} catch(e) {
failure = 'page setup: '+ e.toString();
}
}
if (failure) {
// Skip right to snapshotting if there was a failure, since the
// fonts might be in an inconsistent state.
snapshotCurrentPage(page, task, failure);
}
}
function snapshotCurrentPage(page, task, failure) {
log("done, snapshotting... ");
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();
}

View File

@ -0,0 +1 @@
http://oannis.com/DiwanProfile.pdf

View File

@ -0,0 +1,55 @@
%PDF-1.0
1 0 obj
<<
/Pages 2 0 R
/Type /Catalog
>>
endobj
2 0 obj
<<
/Count 1
/Kids [ 3 0 R ]
/Type /Pages
>>
endobj
3 0 obj
<<
/MediaBox [ 0 0 795 842 ]
/Parent 2 0 R
/Contents 4 0 R
/Resources <<
/Font <<
/F1 <<
/Name /F1
/BaseFont /Helvetica
/Subtype /Type1
/Type /Font
>>
>>
>>
/Type /Page
>>
endobj
4 0 obj
<<
/Filter /ASCIIHexDecode
/Length 111
>>stream