commit
d984916380
2
Makefile
2
Makefile
@ -56,7 +56,7 @@ browser-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
|
||||
# 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)
|
||||
|
86
crypto.js
86
crypto.js
@ -1,7 +1,7 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var ARCFourCipher = (function() {
|
||||
function constructor(key) {
|
||||
@ -30,7 +30,7 @@ var ARCFourCipher = (function() {
|
||||
a = (a + 1) & 0xFF;
|
||||
tmp = s[a];
|
||||
b = (b + tmp) & 0xFF;
|
||||
tmp2 = s[b]
|
||||
tmp2 = s[b];
|
||||
s[a] = tmp2;
|
||||
s[b] = tmp;
|
||||
output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
|
||||
@ -47,22 +47,23 @@ var ARCFourCipher = (function() {
|
||||
var md5 = (function() {
|
||||
var r = new Uint8Array([
|
||||
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
|
||||
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,
|
||||
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
|
||||
|
||||
var k = new Int32Array([
|
||||
-680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
|
||||
-1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
|
||||
1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
|
||||
643717713, -373897302, -701558691, 38016083, -660478335, -405537848, 568446438,
|
||||
-1019803690, -187363961, 1163531501, -1444681467, -51403784, 1735328473,
|
||||
-1926607734, -378558, -2022574463, 1839030562, -35309556, -1530992060,
|
||||
1272893353, -155497632, -1094730640, 681279174, -358537222, -722521979,
|
||||
76029189, -640364487, -421815835, 530742520, -995338651, -198630844, 1126891415,
|
||||
-1416354905, -57434055, 1700485571, -1894986606, -1051523, -2054922799,
|
||||
1873313359, -30611744, -1560198380, 1309151649, -145523070, -1120210379,
|
||||
718787259, -343485551]);
|
||||
|
||||
643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
|
||||
568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
|
||||
1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
|
||||
-1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
|
||||
-722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
|
||||
-198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
|
||||
-1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
|
||||
-145523070, -1120210379, 718787259, -343485551]);
|
||||
|
||||
function hash(data, offset, length) {
|
||||
var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
|
||||
// pre-processing
|
||||
@ -76,10 +77,10 @@ var md5 = (function() {
|
||||
for (; i < n; ++i)
|
||||
padded[i] = 0;
|
||||
padded[i++] = (length << 3) & 0xFF;
|
||||
padded[i++] = (length >> 5) & 0xFF;
|
||||
padded[i++] = (length >> 13) & 0xFF;
|
||||
padded[i++] = (length >> 21) & 0xFF;
|
||||
padded[i++] = (length >>> 29) & 0xFF;
|
||||
padded[i++] = (length >> 5) & 0xFF;
|
||||
padded[i++] = (length >> 13) & 0xFF;
|
||||
padded[i++] = (length >> 21) & 0xFF;
|
||||
padded[i++] = (length >>> 29) & 0xFF;
|
||||
padded[i++] = 0;
|
||||
padded[i++] = 0;
|
||||
padded[i++] = 0;
|
||||
@ -87,8 +88,10 @@ var md5 = (function() {
|
||||
// TODO ArrayBuffer ?
|
||||
var w = new Int32Array(16);
|
||||
for (i = 0; i < paddedLength;) {
|
||||
for (j = 0; j < 16; ++j, i += 4)
|
||||
w[j] = padded[i] | (padded[i + 1] << 8) | (padded[i + 2] << 16) | (padded[i + 3] << 24);
|
||||
for (j = 0; j < 16; ++j, i += 4) {
|
||||
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;
|
||||
for (j = 0; j < 64; ++j) {
|
||||
if (j < 16) {
|
||||
@ -131,7 +134,7 @@ var CipherTransform = (function() {
|
||||
this.streamCipherConstructor = streamCipherConstructor;
|
||||
}
|
||||
constructor.prototype = {
|
||||
createStream: function (stream) {
|
||||
createStream: function(stream) {
|
||||
var cipher = new this.streamCipherConstructor();
|
||||
return new DecryptStream(stream, function(data) {
|
||||
return cipher.encryptBlock(data);
|
||||
@ -148,10 +151,13 @@ var CipherTransform = (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([
|
||||
0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41, 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
|
||||
0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80, 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
|
||||
0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
|
||||
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;
|
||||
if (password) {
|
||||
n = Math.min(32, password.length);
|
||||
@ -183,9 +189,10 @@ var CipherTransformFactory = (function() {
|
||||
var cipher, checkData;
|
||||
|
||||
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;
|
||||
for(j = 0, n = fileId.length; j < n; ++j)
|
||||
for (j = 0, n = fileId.length; j < n; ++j)
|
||||
hashData[i++] = fileId[j];
|
||||
cipher = new ARCFourCipher(encryptionKey);
|
||||
var checkData = cipher.encryptBlock(md5(hashData, 0, i));
|
||||
@ -203,37 +210,38 @@ var CipherTransformFactory = (function() {
|
||||
}
|
||||
for (j = 0, n = checkData.length; j < n; ++j) {
|
||||
if (userPassword[j] != checkData[j])
|
||||
error("incorrect password");
|
||||
error('incorrect password');
|
||||
}
|
||||
return encryptionKey;
|
||||
}
|
||||
}
|
||||
|
||||
function constructor(dict, fileId, password) {
|
||||
var filter = dict.get("Filter");
|
||||
if (!IsName(filter) || filter.name != "Standard")
|
||||
error("unknown encryption method");
|
||||
var filter = dict.get('Filter');
|
||||
if (!IsName(filter) || filter.name != 'Standard')
|
||||
error('unknown encryption method');
|
||||
this.dict = dict;
|
||||
var algorithm = dict.get("V");
|
||||
var algorithm = dict.get('V');
|
||||
if (!IsInt(algorithm) ||
|
||||
(algorithm != 1 && algorithm != 2))
|
||||
error("unsupported encryption algorithm");
|
||||
error('unsupported encryption algorithm');
|
||||
// TODO support algorithm 4
|
||||
var keyLength = dict.get("Length") || 40;
|
||||
var keyLength = dict.get('Length') || 40;
|
||||
if (!IsInt(keyLength) ||
|
||||
keyLength < 40 || (keyLength % 8) != 0)
|
||||
error("invalid key length");
|
||||
error('invalid key length');
|
||||
// prepare keys
|
||||
var ownerPassword = stringToBytes(dict.get("O"));
|
||||
var userPassword = stringToBytes(dict.get("U"));
|
||||
var flags = dict.get("P");
|
||||
var revision = dict.get("R");
|
||||
var ownerPassword = stringToBytes(dict.get('O'));
|
||||
var userPassword = stringToBytes(dict.get('U'));
|
||||
var flags = dict.get('P');
|
||||
var revision = dict.get('R');
|
||||
var fileIdBytes = stringToBytes(fileId);
|
||||
var passwordBytes;
|
||||
if (password)
|
||||
passwordBytes = stringToBytes(password);
|
||||
|
||||
this.encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
|
||||
ownerPassword, userPassword, flags, revision, keyLength);
|
||||
this.encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
|
||||
ownerPassword, userPassword,
|
||||
flags, revision, keyLength);
|
||||
}
|
||||
|
||||
constructor.prototype = {
|
||||
|
12
glyphlist.js
12
glyphlist.js
@ -1,7 +1,7 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var GlyphsUnicode = {
|
||||
A: 0x0041,
|
||||
@ -2474,8 +2474,8 @@ var GlyphsUnicode = {
|
||||
lameddageshhebrew: 0xFB3C,
|
||||
lamedhebrew: 0x05DC,
|
||||
lamedholam: 0x05DC05B9,
|
||||
lamedholamdagesh: "05DC 05B9 05BC",
|
||||
lamedholamdageshhebrew: "05DC 05B9 05BC",
|
||||
lamedholamdagesh: '05DC 05B9 05BC',
|
||||
lamedholamdageshhebrew: '05DC 05B9 05BC',
|
||||
lamedholamhebrew: 0x05DC05B9,
|
||||
lamfinalarabic: 0xFEDE,
|
||||
lamhahinitialarabic: 0xFCCA,
|
||||
@ -2486,8 +2486,8 @@ var GlyphsUnicode = {
|
||||
lammedialarabic: 0xFEE0,
|
||||
lammeemhahinitialarabic: 0xFD88,
|
||||
lammeeminitialarabic: 0xFCCC,
|
||||
lammeemjeeminitialarabic: "FEDF FEE4 FEA0",
|
||||
lammeemkhahinitialarabic: "FEDF FEE4 FEA8",
|
||||
lammeemjeeminitialarabic: 'FEDF FEE4 FEA0',
|
||||
lammeemkhahinitialarabic: 'FEDF FEE4 FEA8',
|
||||
largecircle: 0x25EF,
|
||||
lbar: 0x019A,
|
||||
lbelt: 0x026C,
|
||||
@ -3250,7 +3250,7 @@ var GlyphsUnicode = {
|
||||
reharmenian: 0x0580,
|
||||
rehfinalarabic: 0xFEAE,
|
||||
rehiragana: 0x308C,
|
||||
rehyehaleflamarabic: "0631 FEF3 FE8E 0644",
|
||||
rehyehaleflamarabic: '0631 FEF3 FE8E 0644',
|
||||
rekatakana: 0x30EC,
|
||||
rekatakanahalfwidth: 0xFF9A,
|
||||
resh: 0x05E8,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* The Type2 reader code below is only used for debugging purpose since Type2
|
||||
@ -21,7 +21,7 @@ function readCharset(aStream, aCharstrings) {
|
||||
|
||||
var format = aStream.getByte();
|
||||
if (format == 0) {
|
||||
charset[".notdef"] = readCharstringEncoding(aCharstrings[0]);
|
||||
charset['.notdef'] = readCharstringEncoding(aCharstrings[0]);
|
||||
|
||||
var count = aCharstrings.length - 1;
|
||||
for (var i = 1; i < count + 1; i++) {
|
||||
@ -30,13 +30,13 @@ function readCharset(aStream, aCharstrings) {
|
||||
//log(CFFStrings[sid] + "::" + charset[CFFStrings[sid]]);
|
||||
}
|
||||
} else if (format == 1) {
|
||||
error("Charset Range are not supported");
|
||||
error('Charset Range are not supported');
|
||||
} else {
|
||||
error("Invalid charset format");
|
||||
error('Invalid charset format');
|
||||
}
|
||||
|
||||
return charset;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a Type2 binary charstring as input and transform it to a human
|
||||
@ -83,7 +83,7 @@ function readCharstringEncoding(aString) {
|
||||
}
|
||||
|
||||
return charstringTokens;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -105,10 +105,10 @@ function readFontDictData(aString, aMap) {
|
||||
} else if (value == 29) {
|
||||
token = aString[i++] << 24 |
|
||||
aString[i++] << 16 |
|
||||
aString[i++] << 8 |
|
||||
aString[i++] << 8 |
|
||||
aString[i++];
|
||||
} else if (value == 30) {
|
||||
token = "";
|
||||
token = '';
|
||||
var parsed = false;
|
||||
while (!parsed) {
|
||||
var byte = aString[i++];
|
||||
@ -118,18 +118,18 @@ function readFontDictData(aString, aMap) {
|
||||
var nibble = nibbles[j];
|
||||
switch (nibble) {
|
||||
case 0xA:
|
||||
token += ".";
|
||||
token += '.';
|
||||
break;
|
||||
case 0xB:
|
||||
token += "E";
|
||||
token += 'E';
|
||||
break;
|
||||
case 0xC:
|
||||
token += "E-";
|
||||
token += 'E-';
|
||||
break;
|
||||
case 0xD:
|
||||
break;
|
||||
case 0xE:
|
||||
token += "-";
|
||||
token += '-';
|
||||
break;
|
||||
case 0xF:
|
||||
parsed = true;
|
||||
@ -139,7 +139,7 @@ function readFontDictData(aString, aMap) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
token = parseFloat(token);
|
||||
} else if (value <= 31) {
|
||||
token = aMap[value];
|
||||
@ -150,14 +150,14 @@ function readFontDictData(aString, aMap) {
|
||||
} else if (value <= 254) {
|
||||
token = -((value - 251) * 256) - aString[i++] - 108;
|
||||
} else if (value == 255) {
|
||||
error("255 is not a valid DICT command");
|
||||
error('255 is not a valid DICT command');
|
||||
}
|
||||
|
||||
fontDictDataTokens.push(token);
|
||||
}
|
||||
|
||||
return fontDictDataTokens;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -192,7 +192,7 @@ function readFontIndexData(aStream, aIsByte) {
|
||||
return aStream.getByte() << 24 | aStream.getByte() << 16 |
|
||||
aStream.getByte() << 8 | aStream.getByte();
|
||||
}
|
||||
error(offsize + " is not a valid offset size");
|
||||
error(offsize + ' is not a valid offset size');
|
||||
return null;
|
||||
};
|
||||
|
||||
@ -200,7 +200,8 @@ function readFontIndexData(aStream, aIsByte) {
|
||||
for (var i = 0; i < count + 1; i++)
|
||||
offsets.push(getNextOffset());
|
||||
|
||||
log("Found " + count + " objects at offsets :" + offsets + " (offsize: " + offsize + ")");
|
||||
log('Found ' + count + ' objects at offsets :' +
|
||||
offsets + ' (offsize: ' + offsize + ')');
|
||||
|
||||
// Now extract the objects
|
||||
var relativeOffset = aStream.pos;
|
||||
@ -217,15 +218,15 @@ function readFontIndexData(aStream, aIsByte) {
|
||||
}
|
||||
|
||||
return objects;
|
||||
};
|
||||
}
|
||||
|
||||
var Type2Parser = function(aFilePath) {
|
||||
var font = new Dict();
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", aFilePath, false);
|
||||
xhr.mozResponseType = xhr.responseType = "arraybuffer";
|
||||
xhr.expected = (document.URL.indexOf("file:") == 0) ? 0 : 200;
|
||||
xhr.open('GET', aFilePath, false);
|
||||
xhr.mozResponseType = xhr.responseType = 'arraybuffer';
|
||||
xhr.expected = (document.URL.indexOf('file:') == 0) ? 0 : 200;
|
||||
xhr.send(null);
|
||||
this.data = new Stream(xhr.mozResponseArrayBuffer || xhr.mozResponse ||
|
||||
xhr.responseArrayBuffer || xhr.response);
|
||||
@ -249,19 +250,19 @@ var Type2Parser = function(aFilePath) {
|
||||
stack.push(token);
|
||||
} else {
|
||||
switch (token.operand) {
|
||||
case "SID":
|
||||
case 'SID':
|
||||
font.set(token.name, CFFStrings[stack.pop()]);
|
||||
break;
|
||||
case "number number":
|
||||
case 'number number':
|
||||
font.set(token.name, {
|
||||
offset: stack.pop(),
|
||||
size: stack.pop()
|
||||
});
|
||||
break;
|
||||
case "boolean":
|
||||
case 'boolean':
|
||||
font.set(token.name, stack.pop());
|
||||
break;
|
||||
case "delta":
|
||||
case 'delta':
|
||||
font.set(token.name, stack.pop());
|
||||
break;
|
||||
default:
|
||||
@ -280,32 +281,32 @@ var Type2Parser = function(aFilePath) {
|
||||
};
|
||||
|
||||
this.parse = function(aStream) {
|
||||
font.set("major", aStream.getByte());
|
||||
font.set("minor", aStream.getByte());
|
||||
font.set("hdrSize", aStream.getByte());
|
||||
font.set("offsize", aStream.getByte());
|
||||
font.set('major', aStream.getByte());
|
||||
font.set('minor', aStream.getByte());
|
||||
font.set('hdrSize', aStream.getByte());
|
||||
font.set('offsize', aStream.getByte());
|
||||
|
||||
// Move the cursor after the header
|
||||
aStream.skip(font.get("hdrSize") - aStream.pos);
|
||||
aStream.skip(font.get('hdrSize') - aStream.pos);
|
||||
|
||||
// Read the NAME Index
|
||||
dump("Reading Index: Names");
|
||||
font.set("Names", readFontIndexData(aStream));
|
||||
log("Names: " + font.get("Names"));
|
||||
dump('Reading Index: Names');
|
||||
font.set('Names', readFontIndexData(aStream));
|
||||
log('Names: ' + font.get('Names'));
|
||||
|
||||
// Read the Top Dict Index
|
||||
dump("Reading Index: TopDict");
|
||||
dump('Reading Index: TopDict');
|
||||
var topDict = readFontIndexData(aStream, true);
|
||||
log("TopDict: " + topDict);
|
||||
log('TopDict: ' + topDict);
|
||||
|
||||
// Read the String Index
|
||||
dump("Reading Index: Strings");
|
||||
dump('Reading Index: Strings');
|
||||
var strings = readFontIndexData(aStream);
|
||||
log("strings: " + strings);
|
||||
log('strings: ' + strings);
|
||||
|
||||
// Fill up the Strings dictionary with the new unique strings
|
||||
for (var i = 0; i < strings.length; i++)
|
||||
CFFStrings.push(strings[i].join(""));
|
||||
CFFStrings.push(strings[i].join(''));
|
||||
|
||||
// Parse the TopDict operator
|
||||
var objects = [];
|
||||
@ -315,39 +316,40 @@ var Type2Parser = function(aFilePath) {
|
||||
|
||||
// Read the Global Subr Index that comes just after the Strings Index
|
||||
// (cf. "The Compact Font Format Specification" Chapter 16)
|
||||
dump("Reading Global Subr Index");
|
||||
dump('Reading Global Subr Index');
|
||||
var subrs = readFontIndexData(aStream, true);
|
||||
dump(subrs);
|
||||
|
||||
// Reading Private Dict
|
||||
var priv = font.get("Private");
|
||||
log("Reading Private Dict (offset: " + priv.offset + " size: " + priv.size + ")");
|
||||
var priv = font.get('Private');
|
||||
log('Reading Private Dict (offset: ' + priv.offset +
|
||||
' size: ' + priv.size + ')');
|
||||
aStream.pos = priv.offset;
|
||||
|
||||
var privateDict = [];
|
||||
for (var i = 0; i < priv.size; i++)
|
||||
privateDict.push(aStream.getByte());
|
||||
dump("private:" + privateDict);
|
||||
dump('private:' + privateDict);
|
||||
parseAsToken(privateDict, CFFDictPrivateDataMap);
|
||||
|
||||
for (var p in font.map)
|
||||
dump(p + "::" + font.get(p));
|
||||
dump(p + '::' + font.get(p));
|
||||
|
||||
// Read CharStrings Index
|
||||
var charStringsOffset = font.get("CharStrings");
|
||||
dump("Read CharStrings Index (offset: " + charStringsOffset + ")");
|
||||
var charStringsOffset = font.get('CharStrings');
|
||||
dump('Read CharStrings Index (offset: ' + charStringsOffset + ')');
|
||||
aStream.pos = charStringsOffset;
|
||||
var charStrings = readFontIndexData(aStream, true);
|
||||
|
||||
// Read Charset
|
||||
dump("Read Charset for " + charStrings.length + " glyphs");
|
||||
var charsetEntry = font.get("charset");
|
||||
dump('Read Charset for ' + charStrings.length + ' glyphs');
|
||||
var charsetEntry = font.get('charset');
|
||||
if (charsetEntry == 0) {
|
||||
error("Need to support CFFISOAdobeCharset");
|
||||
error('Need to support CFFISOAdobeCharset');
|
||||
} else if (charsetEntry == 1) {
|
||||
error("Need to support CFFExpert");
|
||||
error('Need to support CFFExpert');
|
||||
} else if (charsetEntry == 2) {
|
||||
error("Need to support CFFExpertSubsetCharset");
|
||||
error('Need to support CFFExpertSubsetCharset');
|
||||
} else {
|
||||
aStream.pos = charsetEntry;
|
||||
var charset = readCharset(aStream, charStrings);
|
||||
@ -378,23 +380,23 @@ var Type2Parser = function(aFilePath) {
|
||||
* writeToFile(fontData, "/tmp/pdf.js." + fontCount + ".cff");
|
||||
*/
|
||||
function writeToFile(aBytes, aFilePath) {
|
||||
if (!("netscape" in window))
|
||||
if (!('netscape' in window))
|
||||
return;
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var Cc = Components.classes,
|
||||
Ci = Components.interfaces;
|
||||
var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
|
||||
var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
|
||||
file.initWithPath(aFilePath);
|
||||
|
||||
var stream = Cc["@mozilla.org/network/file-output-stream;1"]
|
||||
var stream = Cc['@mozilla.org/network/file-output-stream;1']
|
||||
.createInstance(Ci.nsIFileOutputStream);
|
||||
stream.init(file, 0x04 | 0x08 | 0x20, 0x180, 0);
|
||||
|
||||
var bos = Cc["@mozilla.org/binaryoutputstream;1"]
|
||||
var bos = Cc['@mozilla.org/binaryoutputstream;1']
|
||||
.createInstance(Ci.nsIBinaryOutputStream);
|
||||
bos.setOutputStream(stream);
|
||||
bos.writeByteArray(aBytes, aBytes.length);
|
||||
stream.close();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
// Checking if the typed arrays are supported
|
||||
(function() {
|
||||
if (typeof Uint8Array !== "undefined")
|
||||
if (typeof Uint8Array !== 'undefined')
|
||||
return;
|
||||
|
||||
function subarray(start, end) {
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
function TypedArray(arg1) {
|
||||
var result;
|
||||
if (typeof arg1 === "number") {
|
||||
if (typeof arg1 === 'number') {
|
||||
result = new Array(arg1);
|
||||
for (var i = 0; i < arg1; ++i)
|
||||
result[i] = 0;
|
||||
@ -28,23 +28,23 @@
|
||||
result.buffer = result;
|
||||
result.byteLength = result.length;
|
||||
result.set = set_;
|
||||
if (typeof arg1 === "object" && arg1.buffer)
|
||||
if (typeof arg1 === 'object' && arg1.buffer)
|
||||
result.buffer = arg1.buffer;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
window.Uint8Array = TypedArray;
|
||||
|
||||
|
||||
// we don't need support for set, byteLength for 32-bit array
|
||||
// so we can use the TypedArray as well
|
||||
// so we can use the TypedArray as well
|
||||
window.Uint32Array = TypedArray;
|
||||
window.Int32Array = TypedArray;
|
||||
})();
|
||||
|
||||
// Object.create() ?
|
||||
(function() {
|
||||
if (typeof Object.create !== "undefined")
|
||||
if (typeof Object.create !== 'undefined')
|
||||
return;
|
||||
|
||||
Object.create = function(proto) {
|
||||
@ -56,16 +56,16 @@
|
||||
|
||||
// Object.defineProperty() ?
|
||||
(function() {
|
||||
if (typeof Object.defineProperty !== "undefined")
|
||||
if (typeof Object.defineProperty !== 'undefined')
|
||||
return;
|
||||
|
||||
Object.defineProperty = function(obj, name, def) {
|
||||
delete obj[name];
|
||||
if ("get" in def)
|
||||
obj.__defineGetter__(name, def["get"]);
|
||||
if ("set" in def)
|
||||
obj.__defineSetter__(name, def["set"]);
|
||||
if ("value" in def) {
|
||||
if ('get' in def)
|
||||
obj.__defineGetter__(name, def['get']);
|
||||
if ('set' in def)
|
||||
obj.__defineSetter__(name, def['set']);
|
||||
if ('value' in def) {
|
||||
obj.__defineSetter__(name, function(value) {
|
||||
this.__defineGetter__(name, function() {
|
||||
return value;
|
||||
@ -80,16 +80,16 @@
|
||||
// No XMLHttpRequest.response ?
|
||||
(function() {
|
||||
var xhrPrototype = XMLHttpRequest.prototype;
|
||||
if ("response" in xhrPrototype ||
|
||||
"mozResponseArrayBuffer" in xhrPrototype ||
|
||||
"mozResponse" in xhrPrototype ||
|
||||
"responseArrayBuffer" in xhrPrototype)
|
||||
if ('response' in xhrPrototype ||
|
||||
'mozResponseArrayBuffer' in xhrPrototype ||
|
||||
'mozResponse' in xhrPrototype ||
|
||||
'responseArrayBuffer' in xhrPrototype)
|
||||
return;
|
||||
// IE ?
|
||||
if (typeof VBArray !== "undefined") {
|
||||
Object.defineProperty(xhrPrototype, "response", {
|
||||
if (typeof VBArray !== 'undefined') {
|
||||
Object.defineProperty(xhrPrototype, 'response', {
|
||||
get: function() {
|
||||
return new Uint8Array( new VBArray(this.responseBody).toArray() );
|
||||
return new Uint8Array(new VBArray(this.responseBody).toArray());
|
||||
}
|
||||
});
|
||||
return;
|
||||
@ -98,10 +98,11 @@
|
||||
// other browsers
|
||||
function responseTypeSetter() {
|
||||
// will be only called to set "arraybuffer"
|
||||
this.overrideMimeType("text/plain; charset=x-user-defined");
|
||||
this.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
}
|
||||
if (typeof xhrPrototype.overrideMimeType === "function") {
|
||||
Object.defineProperty(xhrPrototype, "responseType", { set: responseTypeSetter });
|
||||
if (typeof xhrPrototype.overrideMimeType === 'function') {
|
||||
Object.defineProperty(xhrPrototype, 'responseType',
|
||||
{ set: responseTypeSetter });
|
||||
}
|
||||
function responseGetter() {
|
||||
var text = this.responseText;
|
||||
@ -111,18 +112,19 @@
|
||||
result[i] = text.charCodeAt(i) & 0xFF;
|
||||
return result;
|
||||
}
|
||||
Object.defineProperty(xhrPrototype, "response", { get: responseGetter });
|
||||
Object.defineProperty(xhrPrototype, 'response', { get: responseGetter });
|
||||
})();
|
||||
|
||||
// window.btoa (base64 encode function) ?
|
||||
(function() {
|
||||
if ("btoa" in window)
|
||||
if ('btoa' in window)
|
||||
return;
|
||||
|
||||
var digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
var digits =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
|
||||
window.btoa = function(chars) {
|
||||
var buffer = "";
|
||||
var buffer = '';
|
||||
var i, n;
|
||||
for (i = 0, n = chars.length; i < n; i += 3) {
|
||||
var b1 = chars.charCodeAt(i) & 0xFF;
|
||||
@ -131,15 +133,16 @@
|
||||
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
|
||||
var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
|
||||
var d4 = i + 2 < n ? (b3 & 0x3F) : 64;
|
||||
buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
|
||||
buffer += (digits.charAt(d1) + digits.charAt(d2) +
|
||||
digits.charAt(d3) + digits.charAt(d4));
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
};
|
||||
})();
|
||||
|
||||
// Function.prototype.bind ?
|
||||
(function() {
|
||||
if (typeof Function.prototype.bind !== "undefined")
|
||||
if (typeof Function.prototype.bind !== 'undefined')
|
||||
return;
|
||||
|
||||
Function.prototype.bind = function(obj) {
|
||||
|
@ -1,47 +1,47 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var pageTimeout;
|
||||
|
||||
var PDFViewer = {
|
||||
queryParams: {},
|
||||
|
||||
|
||||
element: null,
|
||||
|
||||
|
||||
sidebarContentView: null,
|
||||
|
||||
|
||||
previousPageButton: null,
|
||||
nextPageButton: null,
|
||||
pageNumberInput: null,
|
||||
scaleSelect: null,
|
||||
fileInput: null,
|
||||
|
||||
|
||||
willJumpToPage: false,
|
||||
|
||||
|
||||
pdf: null,
|
||||
|
||||
|
||||
url: 'compressed.tracemonkey-pldi-09.pdf',
|
||||
pageNumber: 1,
|
||||
numberOfPages: 1,
|
||||
|
||||
|
||||
scale: 1.0,
|
||||
|
||||
|
||||
pageWidth: function(page) {
|
||||
var pdfToCssUnitsCoef = 96.0 / 72.0;
|
||||
var width = (page.mediaBox[2] - page.mediaBox[0]);
|
||||
return width * PDFViewer.scale * pdfToCssUnitsCoef;
|
||||
},
|
||||
|
||||
|
||||
pageHeight: function(page) {
|
||||
var pdfToCssUnitsCoef = 96.0 / 72.0;
|
||||
var height = (page.mediaBox[3] - page.mediaBox[1]);
|
||||
return height * PDFViewer.scale * pdfToCssUnitsCoef;
|
||||
},
|
||||
|
||||
|
||||
lastPagesDrawn: [],
|
||||
|
||||
|
||||
visiblePages: function() {
|
||||
const pageBottomMargin = 10;
|
||||
var windowTop = window.pageYOffset;
|
||||
@ -56,57 +56,57 @@ var PDFViewer = {
|
||||
break;
|
||||
currentHeight += pageHeight;
|
||||
}
|
||||
|
||||
var pages = [];
|
||||
|
||||
var pages = [];
|
||||
for (; i <= n && currentHeight < windowBottom; i++) {
|
||||
var page = PDFViewer.pdf.getPage(i);
|
||||
pageHeight = PDFViewer.pageHeight(page) + pageBottomMargin;
|
||||
currentHeight += pageHeight;
|
||||
pages.push(i);
|
||||
}
|
||||
|
||||
|
||||
return pages;
|
||||
},
|
||||
|
||||
|
||||
createThumbnail: function(num) {
|
||||
if (PDFViewer.sidebarContentView) {
|
||||
var anchor = document.createElement('a');
|
||||
anchor.href = '#' + num;
|
||||
|
||||
|
||||
var containerDiv = document.createElement('div');
|
||||
containerDiv.id = 'thumbnailContainer' + num;
|
||||
containerDiv.className = 'thumbnail';
|
||||
|
||||
|
||||
var pageNumberDiv = document.createElement('div');
|
||||
pageNumberDiv.className = 'thumbnailPageNumber';
|
||||
pageNumberDiv.innerHTML = '' + num;
|
||||
|
||||
|
||||
anchor.appendChild(containerDiv);
|
||||
PDFViewer.sidebarContentView.appendChild(anchor);
|
||||
PDFViewer.sidebarContentView.appendChild(pageNumberDiv);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
removeThumbnail: function(num) {
|
||||
var div = document.getElementById('thumbnailContainer' + num);
|
||||
|
||||
|
||||
if (div) {
|
||||
while (div.hasChildNodes()) {
|
||||
div.removeChild(div.firstChild);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
drawThumbnail: function(num) {
|
||||
if (!PDFViewer.pdf)
|
||||
return;
|
||||
|
||||
var div = document.getElementById('thumbnailContainer' + num);
|
||||
|
||||
|
||||
if (div && !div.hasChildNodes()) {
|
||||
var page = PDFViewer.pdf.getPage(num);
|
||||
var canvas = document.createElement('canvas');
|
||||
|
||||
|
||||
canvas.id = 'thumbnail' + num;
|
||||
canvas.mozOpaque = true;
|
||||
|
||||
@ -133,43 +133,43 @@ var PDFViewer = {
|
||||
FontLoader.bind(fonts, function() { page.display(gfx); });
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
createPage: function(num) {
|
||||
var page = PDFViewer.pdf.getPage(num);
|
||||
|
||||
var anchor = document.createElement('a');
|
||||
anchor.name = '' + num;
|
||||
|
||||
|
||||
var div = document.createElement('div');
|
||||
div.id = 'pageContainer' + num;
|
||||
div.className = 'page';
|
||||
div.style.width = PDFViewer.pageWidth(page) + 'px';
|
||||
div.style.height = PDFViewer.pageHeight(page) + 'px';
|
||||
|
||||
|
||||
PDFViewer.element.appendChild(anchor);
|
||||
PDFViewer.element.appendChild(div);
|
||||
},
|
||||
|
||||
|
||||
removePage: function(num) {
|
||||
var div = document.getElementById('pageContainer' + num);
|
||||
|
||||
|
||||
if (div) {
|
||||
while (div.hasChildNodes()) {
|
||||
div.removeChild(div.firstChild);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
drawPage: function(num) {
|
||||
if (!PDFViewer.pdf)
|
||||
return;
|
||||
|
||||
var div = document.getElementById('pageContainer' + num);
|
||||
|
||||
|
||||
if (div && !div.hasChildNodes()) {
|
||||
var page = PDFViewer.pdf.getPage(num);
|
||||
var canvas = document.createElement('canvas');
|
||||
|
||||
|
||||
canvas.id = 'page' + num;
|
||||
canvas.mozOpaque = true;
|
||||
|
||||
@ -198,20 +198,20 @@ var PDFViewer = {
|
||||
while (PDFViewer.element.hasChildNodes()) {
|
||||
PDFViewer.element.removeChild(PDFViewer.element.firstChild);
|
||||
}
|
||||
|
||||
|
||||
PDFViewer.scale = num / 100;
|
||||
|
||||
|
||||
var i;
|
||||
|
||||
|
||||
if (PDFViewer.pdf) {
|
||||
for (i = 1; i <= PDFViewer.numberOfPages; i++) {
|
||||
PDFViewer.createPage(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < PDFViewer.scaleSelect.childNodes; i++) {
|
||||
var option = PDFViewer.scaleSelect.childNodes[i];
|
||||
|
||||
|
||||
if (option.value == num) {
|
||||
if (!option.selected) {
|
||||
option.selected = 'selected';
|
||||
@ -222,16 +222,16 @@ var PDFViewer = {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PDFViewer.scaleSelect.value = Math.floor(PDFViewer.scale * 100) + '%';
|
||||
|
||||
|
||||
// Clear the array of the last pages drawn to force a redraw.
|
||||
PDFViewer.lastPagesDrawn = [];
|
||||
|
||||
|
||||
// Jump the scroll position to the correct page.
|
||||
PDFViewer.goToPage(PDFViewer.pageNumber);
|
||||
},
|
||||
|
||||
|
||||
goToPage: function(num) {
|
||||
if (1 <= num && num <= PDFViewer.numberOfPages) {
|
||||
PDFViewer.pageNumber = num;
|
||||
@ -242,24 +242,26 @@ var PDFViewer = {
|
||||
// Force a "scroll event" to redraw
|
||||
setTimeout(window.onscroll, 0);
|
||||
document.location.hash = PDFViewer.pageNumber;
|
||||
|
||||
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? 'disabled' : '';
|
||||
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ? 'disabled' : '';
|
||||
|
||||
PDFViewer.previousPageButton.className =
|
||||
(PDFViewer.pageNumber === 1) ? 'disabled' : '';
|
||||
PDFViewer.nextPageButton.className =
|
||||
(PDFViewer.pageNumber === PDFViewer.numberOfPages) ? 'disabled' : '';
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
goToPreviousPage: function() {
|
||||
if (PDFViewer.pageNumber > 1) {
|
||||
PDFViewer.goToPage(--PDFViewer.pageNumber);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
goToNextPage: function() {
|
||||
if (PDFViewer.pageNumber < PDFViewer.numberOfPages) {
|
||||
PDFViewer.goToPage(++PDFViewer.pageNumber);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
openURL: function(url) {
|
||||
PDFViewer.url = url;
|
||||
document.title = url;
|
||||
@ -269,20 +271,21 @@ var PDFViewer = {
|
||||
clearInterval(this.thumbsLoadingInterval);
|
||||
this.thumbsLoadingInterval = null;
|
||||
}
|
||||
|
||||
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('GET', url);
|
||||
req.mozResponseType = req.responseType = 'arraybuffer';
|
||||
req.expected = (document.URL.indexOf('file:') === 0) ? 0 : 200;
|
||||
|
||||
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState === 4 && req.status === req.expected) {
|
||||
var data = req.mozResponseArrayBuffer || req.mozResponse || req.responseArrayBuffer || req.response;
|
||||
|
||||
var data = (req.mozResponseArrayBuffer || req.mozResponse ||
|
||||
req.responseArrayBuffer || req.response);
|
||||
|
||||
PDFViewer.readPDF(data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
req.send(null);
|
||||
},
|
||||
|
||||
@ -292,23 +295,26 @@ var PDFViewer = {
|
||||
while (PDFViewer.element.hasChildNodes()) {
|
||||
PDFViewer.element.removeChild(PDFViewer.element.firstChild);
|
||||
}
|
||||
|
||||
|
||||
while (PDFViewer.sidebarContentView.hasChildNodes()) {
|
||||
PDFViewer.sidebarContentView.removeChild(PDFViewer.sidebarContentView.firstChild);
|
||||
PDFViewer.sidebarContentView.removeChild(
|
||||
PDFViewer.sidebarContentView.firstChild
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
PDFViewer.pdf = new PDFDoc(new Stream(data));
|
||||
PDFViewer.numberOfPages = PDFViewer.pdf.numPages;
|
||||
document.getElementById('numPages').innerHTML = PDFViewer.numberOfPages.toString();
|
||||
|
||||
document.getElementById('numPages').innerHTML =
|
||||
PDFViewer.numberOfPages.toString();
|
||||
|
||||
for (var i = 1; i <= PDFViewer.numberOfPages; i++) {
|
||||
PDFViewer.createPage(i);
|
||||
}
|
||||
|
||||
|
||||
if (PDFViewer.numberOfPages > 0) {
|
||||
PDFViewer.drawPage(1);
|
||||
document.location.hash = 1;
|
||||
|
||||
|
||||
// slowly loading the thumbs (few per second)
|
||||
// first time we are loading more images than subsequent
|
||||
var currentPageIndex = 1, imagesToLoad = 15;
|
||||
@ -326,9 +332,11 @@ var PDFViewer = {
|
||||
imagesToLoad = 3; // next time loading less images
|
||||
}).bind(this), 500);
|
||||
}
|
||||
|
||||
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? 'disabled' : '';
|
||||
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ? 'disabled' : '';
|
||||
|
||||
PDFViewer.previousPageButton.className =
|
||||
(PDFViewer.pageNumber === 1) ? 'disabled' : '';
|
||||
PDFViewer.nextPageButton.className =
|
||||
(PDFViewer.pageNumber === PDFViewer.numberOfPages) ? 'disabled' : '';
|
||||
}
|
||||
};
|
||||
|
||||
@ -338,35 +346,35 @@ window.onload = function() {
|
||||
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;
|
||||
}();
|
||||
|
||||
PDFViewer.element = document.getElementById('viewer');
|
||||
|
||||
|
||||
PDFViewer.sidebarContentView = document.getElementById('sidebarContentView');
|
||||
|
||||
|
||||
PDFViewer.pageNumberInput = document.getElementById('pageNumber');
|
||||
PDFViewer.pageNumberInput.onkeydown = function(evt) {
|
||||
var charCode = evt.charCode || evt.keyCode;
|
||||
|
||||
|
||||
// Up arrow key.
|
||||
if (charCode === 38) {
|
||||
PDFViewer.goToNextPage();
|
||||
this.select();
|
||||
}
|
||||
|
||||
|
||||
// Down arrow key.
|
||||
else if (charCode === 40) {
|
||||
PDFViewer.goToPreviousPage();
|
||||
this.select();
|
||||
}
|
||||
|
||||
|
||||
// All other non-numeric keys (excluding Left arrow, Right arrow,
|
||||
// Backspace, and Delete keys).
|
||||
else if ((charCode < 48 || charCode > 57) &&
|
||||
@ -377,12 +385,12 @@ window.onload = function() {
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
};
|
||||
PDFViewer.pageNumberInput.onkeyup = function(evt) {
|
||||
var charCode = evt.charCode || evt.keyCode;
|
||||
|
||||
|
||||
// All numeric keys, Backspace, and Delete.
|
||||
if ((charCode >= 48 && charCode <= 57) ||
|
||||
charCode === 8 || // Backspace
|
||||
@ -390,10 +398,10 @@ window.onload = function() {
|
||||
) {
|
||||
PDFViewer.goToPage(this.value);
|
||||
}
|
||||
|
||||
|
||||
this.focus();
|
||||
};
|
||||
|
||||
|
||||
PDFViewer.previousPageButton = document.getElementById('previousPageButton');
|
||||
PDFViewer.previousPageButton.onclick = function(evt) {
|
||||
if (this.className.indexOf('disabled') === -1) {
|
||||
@ -406,12 +414,14 @@ window.onload = function() {
|
||||
}
|
||||
};
|
||||
PDFViewer.previousPageButton.onmouseup = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
this.className =
|
||||
(this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
PDFViewer.previousPageButton.onmouseout = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
this.className =
|
||||
(this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
|
||||
|
||||
PDFViewer.nextPageButton = document.getElementById('nextPageButton');
|
||||
PDFViewer.nextPageButton.onclick = function(evt) {
|
||||
if (this.className.indexOf('disabled') === -1) {
|
||||
@ -424,17 +434,19 @@ window.onload = function() {
|
||||
}
|
||||
};
|
||||
PDFViewer.nextPageButton.onmouseup = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
this.className =
|
||||
(this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
PDFViewer.nextPageButton.onmouseout = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
this.className =
|
||||
(this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
|
||||
|
||||
PDFViewer.scaleSelect = document.getElementById('scaleSelect');
|
||||
PDFViewer.scaleSelect.onchange = function(evt) {
|
||||
PDFViewer.changeScale(parseInt(this.value));
|
||||
};
|
||||
|
||||
|
||||
if (window.File && window.FileReader && window.FileList && window.Blob) {
|
||||
var openFileButton = document.getElementById('openFileButton');
|
||||
openFileButton.onclick = function(evt) {
|
||||
@ -448,35 +460,37 @@ window.onload = function() {
|
||||
}
|
||||
};
|
||||
openFileButton.onmouseup = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
this.className =
|
||||
(this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
openFileButton.onmouseout = function(evt) {
|
||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
this.className =
|
||||
(this.className.indexOf('disabled') !== -1) ? 'disabled' : '';
|
||||
};
|
||||
|
||||
|
||||
PDFViewer.fileInput = document.getElementById('fileInput');
|
||||
PDFViewer.fileInput.onchange = function(evt) {
|
||||
var files = evt.target.files;
|
||||
|
||||
|
||||
if (files.length > 0) {
|
||||
var file = files[0];
|
||||
var fileReader = new FileReader();
|
||||
|
||||
|
||||
document.title = file.name;
|
||||
|
||||
|
||||
// Read the local file into a Uint8Array.
|
||||
fileReader.onload = function(evt) {
|
||||
var data = evt.target.result;
|
||||
var buffer = new ArrayBuffer(data.length);
|
||||
var uint8Array = new Uint8Array(buffer);
|
||||
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
uint8Array[i] = data.charCodeAt(i);
|
||||
}
|
||||
|
||||
|
||||
PDFViewer.readPDF(uint8Array);
|
||||
};
|
||||
|
||||
|
||||
// Read as a binary string since "readAsArrayBuffer" is not yet
|
||||
// implemented in Firefox.
|
||||
fileReader.readAsBinaryString(file);
|
||||
@ -486,22 +500,23 @@ window.onload = function() {
|
||||
} else {
|
||||
document.getElementById('fileWrapper').style.display = 'none';
|
||||
}
|
||||
|
||||
PDFViewer.pageNumber = parseInt(PDFViewer.queryParams.page) || PDFViewer.pageNumber;
|
||||
|
||||
PDFViewer.pageNumber =
|
||||
parseInt(PDFViewer.queryParams.page) || PDFViewer.pageNumber;
|
||||
PDFViewer.scale = parseInt(PDFViewer.scaleSelect.value) / 100 || 1.0;
|
||||
|
||||
|
||||
PDFViewer.openURL(PDFViewer.queryParams.file || PDFViewer.url);
|
||||
|
||||
window.onscroll = function(evt) {
|
||||
|
||||
window.onscroll = function(evt) {
|
||||
var lastPagesDrawn = PDFViewer.lastPagesDrawn;
|
||||
var visiblePages = PDFViewer.visiblePages();
|
||||
|
||||
|
||||
var pagesToDraw = [];
|
||||
var pagesToKeep = [];
|
||||
var pagesToRemove = [];
|
||||
|
||||
|
||||
var i;
|
||||
|
||||
|
||||
// Determine which visible pages were not previously drawn.
|
||||
for (i = 0; i < visiblePages.length; i++) {
|
||||
if (lastPagesDrawn.indexOf(visiblePages[i]) === -1) {
|
||||
@ -511,7 +526,7 @@ window.onload = function() {
|
||||
pagesToKeep.push(visiblePages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Determine which previously drawn pages are no longer visible.
|
||||
for (i = 0; i < lastPagesDrawn.length; i++) {
|
||||
if (visiblePages.indexOf(lastPagesDrawn[i]) === -1) {
|
||||
@ -519,14 +534,16 @@ window.onload = function() {
|
||||
PDFViewer.removePage(lastPagesDrawn[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PDFViewer.lastPagesDrawn = pagesToDraw.concat(pagesToKeep);
|
||||
|
||||
|
||||
// Update the page number input with the current page number.
|
||||
if (!PDFViewer.willJumpToPage && visiblePages.length > 0) {
|
||||
PDFViewer.pageNumber = PDFViewer.pageNumberInput.value = visiblePages[0];
|
||||
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? 'disabled' : '';
|
||||
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ? 'disabled' : '';
|
||||
PDFViewer.previousPageButton.className =
|
||||
(PDFViewer.pageNumber === 1) ? 'disabled' : '';
|
||||
PDFViewer.nextPageButton.className =
|
||||
(PDFViewer.pageNumber === PDFViewer.numberOfPages) ? 'disabled' : '';
|
||||
} else {
|
||||
PDFViewer.willJumpToPage = false;
|
||||
}
|
||||
|
148
web/viewer.js
148
web/viewer.js
@ -1,113 +1,113 @@
|
||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- /
|
||||
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var pdfDocument, canvas, pageScale, pageDisplay, pageNum, numPages;
|
||||
function load(userInput) {
|
||||
canvas = document.getElementById("canvas");
|
||||
canvas.mozOpaque = true;
|
||||
pageNum = ("page" in queryParams()) ? parseInt(queryParams().page) : 1;
|
||||
pageScale = ("scale" in queryParams()) ? parseInt(queryParams().scale) : 1.5;
|
||||
var fileName = userInput;
|
||||
if (!userInput) {
|
||||
fileName = queryParams().file || "compressed.tracemonkey-pldi-09.pdf";
|
||||
}
|
||||
open(fileName);
|
||||
canvas = document.getElementById('canvas');
|
||||
canvas.mozOpaque = true;
|
||||
pageNum = ('page' in queryParams()) ? parseInt(queryParams().page) : 1;
|
||||
pageScale = ('scale' in queryParams()) ? parseInt(queryParams().scale) : 1.5;
|
||||
var fileName = userInput;
|
||||
if (!userInput) {
|
||||
fileName = queryParams().file || 'compressed.tracemonkey-pldi-09.pdf';
|
||||
}
|
||||
open(fileName);
|
||||
}
|
||||
|
||||
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;
|
||||
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 open(url) {
|
||||
document.title = url;
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET", url);
|
||||
req.mozResponseType = req.responseType = "arraybuffer";
|
||||
req.expected = (document.URL.indexOf("file:") == 0) ? 0 : 200;
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4 && req.status == req.expected) {
|
||||
var data = req.mozResponseArrayBuffer || req.mozResponse ||
|
||||
req.responseArrayBuffer || req.response;
|
||||
pdfDocument = new PDFDoc(new Stream(data));
|
||||
numPages = pdfDocument.numPages;
|
||||
document.getElementById("numPages").innerHTML = numPages.toString();
|
||||
goToPage(pageNum);
|
||||
}
|
||||
};
|
||||
req.send(null);
|
||||
document.title = url;
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('GET', url);
|
||||
req.mozResponseType = req.responseType = 'arraybuffer';
|
||||
req.expected = (document.URL.indexOf('file:') == 0) ? 0 : 200;
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4 && req.status == req.expected) {
|
||||
var data = (req.mozResponseArrayBuffer || req.mozResponse ||
|
||||
req.responseArrayBuffer || req.response);
|
||||
pdfDocument = new PDFDoc(new Stream(data));
|
||||
numPages = pdfDocument.numPages;
|
||||
document.getElementById('numPages').innerHTML = numPages.toString();
|
||||
goToPage(pageNum);
|
||||
}
|
||||
};
|
||||
req.send(null);
|
||||
}
|
||||
|
||||
function gotoPage(num) {
|
||||
if (0 <= num && num <= numPages)
|
||||
pageNum = num;
|
||||
displayPage(pageNum);
|
||||
if (0 <= num && num <= numPages)
|
||||
pageNum = num;
|
||||
displayPage(pageNum);
|
||||
}
|
||||
|
||||
function displayPage(num) {
|
||||
document.getElementById("pageNumber").value = num;
|
||||
document.getElementById('pageNumber').value = num;
|
||||
|
||||
var t0 = Date.now();
|
||||
var t0 = Date.now();
|
||||
|
||||
var page = pdfDocument.getPage(pageNum = num);
|
||||
var page = pdfDocument.getPage(pageNum = num);
|
||||
|
||||
var pdfToCssUnitsCoef = 96.0 / 72.0;
|
||||
var pageWidth = (page.mediaBox[2] - page.mediaBox[0]);
|
||||
var pageHeight = (page.mediaBox[3] - page.mediaBox[1]);
|
||||
canvas.width = pageScale * pageWidth * pdfToCssUnitsCoef;
|
||||
canvas.height = pageScale * pageHeight * pdfToCssUnitsCoef;
|
||||
var pdfToCssUnitsCoef = 96.0 / 72.0;
|
||||
var pageWidth = (page.mediaBox[2] - page.mediaBox[0]);
|
||||
var pageHeight = (page.mediaBox[3] - page.mediaBox[1]);
|
||||
canvas.width = pageScale * pageWidth * pdfToCssUnitsCoef;
|
||||
canvas.height = pageScale * pageHeight * pdfToCssUnitsCoef;
|
||||
|
||||
var t1 = Date.now();
|
||||
var ctx = canvas.getContext("2d");
|
||||
ctx.save();
|
||||
ctx.fillStyle = "rgb(255, 255, 255)";
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.restore();
|
||||
var t1 = Date.now();
|
||||
var ctx = canvas.getContext('2d');
|
||||
ctx.save();
|
||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.restore();
|
||||
|
||||
var gfx = new CanvasGraphics(ctx);
|
||||
var gfx = new CanvasGraphics(ctx);
|
||||
|
||||
// page.compile will collect all fonts for us, once we have loaded them
|
||||
// we can trigger the actual page rendering with page.display
|
||||
var fonts = [];
|
||||
page.compile(gfx, fonts);
|
||||
var t2 = Date.now();
|
||||
// page.compile will collect all fonts for us, once we have loaded them
|
||||
// we can trigger the actual page rendering with page.display
|
||||
var fonts = [];
|
||||
page.compile(gfx, fonts);
|
||||
var t2 = Date.now();
|
||||
|
||||
function displayPage() {
|
||||
var t3 = Date.now();
|
||||
function displayPage() {
|
||||
var t3 = Date.now();
|
||||
|
||||
page.display(gfx);
|
||||
page.display(gfx);
|
||||
|
||||
var t4 = Date.now();
|
||||
var t4 = Date.now();
|
||||
|
||||
var infoDisplay = document.getElementById("info");
|
||||
infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms";
|
||||
}
|
||||
var infoDisplay = document.getElementById('info');
|
||||
infoDisplay.innerHTML = 'Time to load/compile/fonts/render: ' +
|
||||
(t1 - t0) + '/' + (t2 - t1) + '/' + (t3 - t2) + '/' + (t4 - t3) + ' ms';
|
||||
}
|
||||
|
||||
// Always defer call to displayPage() to work around bug in
|
||||
// Firefox error reporting from XHR callbacks.
|
||||
FontLoader.bind(fonts, function () { setTimeout(displayPage, 0); });
|
||||
// Always defer call to displayPage() to work around bug in
|
||||
// Firefox error reporting from XHR callbacks.
|
||||
FontLoader.bind(fonts, function() { setTimeout(displayPage, 0); });
|
||||
}
|
||||
|
||||
function nextPage() {
|
||||
if (pageNum < pdfDocument.numPages)
|
||||
displayPage(++pageNum);
|
||||
if (pageNum < pdfDocument.numPages)
|
||||
displayPage(++pageNum);
|
||||
}
|
||||
|
||||
function prevPage() {
|
||||
if (pageNum > 1)
|
||||
displayPage(--pageNum);
|
||||
if (pageNum > 1)
|
||||
displayPage(--pageNum);
|
||||
}
|
||||
|
||||
function goToPage(num) {
|
||||
if (0 <= num && num <= numPages)
|
||||
displayPage(pageNum = num);
|
||||
}
|
||||
|
||||
|
169
worker/canvas.js
169
worker/canvas.js
@ -1,7 +1,7 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var JpegStreamProxyCounter = 0;
|
||||
// WebWorker Proxy for JpegStream.
|
||||
@ -12,7 +12,7 @@ var JpegStreamProxy = (function() {
|
||||
|
||||
// Tell the main thread to create an image.
|
||||
postMessage({
|
||||
action: "jpeg_stream",
|
||||
action: 'jpeg_stream',
|
||||
data: {
|
||||
id: this.id,
|
||||
raw: bytesToString(bytes)
|
||||
@ -25,7 +25,7 @@ var JpegStreamProxy = (function() {
|
||||
return this;
|
||||
},
|
||||
getChar: function() {
|
||||
error("internal error: getChar is not valid on JpegStream");
|
||||
error('internal error: getChar is not valid on JpegStream');
|
||||
}
|
||||
};
|
||||
|
||||
@ -36,9 +36,9 @@ var JpegStreamProxy = (function() {
|
||||
// the time, meaning you can't create a gradient, create a second one and then
|
||||
// use the first one again. As this isn't used in pdf.js right now, it's okay.
|
||||
function GradientProxy(cmdQueue, x0, y0, x1, y1) {
|
||||
cmdQueue.push(["$createLinearGradient", [x0, y0, x1, y1]]);
|
||||
cmdQueue.push(['$createLinearGradient', [x0, y0, x1, y1]]);
|
||||
this.addColorStop = function(i, rgba) {
|
||||
cmdQueue.push(["$addColorStop", [i, rgba]]);
|
||||
cmdQueue.push(['$addColorStop', [i, rgba]]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,15 +47,15 @@ var patternProxyCounter = 0;
|
||||
function PatternProxy(cmdQueue, object, kind) {
|
||||
this.id = patternProxyCounter++;
|
||||
|
||||
if (!(object instanceof CanvasProxy) ) {
|
||||
throw "unkown type to createPattern";
|
||||
if (!(object instanceof CanvasProxy)) {
|
||||
throw 'unkown type to createPattern';
|
||||
}
|
||||
|
||||
// Flush the object here to ensure it's available on the main thread.
|
||||
// TODO: Make some kind of dependency management, such that the object
|
||||
// gets flushed only if needed.
|
||||
object.flush();
|
||||
cmdQueue.push(["$createPatternFromCanvas", [this.id, object.id, kind]]);
|
||||
cmdQueue.push(['$createPatternFromCanvas', [this.id, object.id, kind]]);
|
||||
}
|
||||
|
||||
var canvasProxyCounter = 0;
|
||||
@ -68,8 +68,8 @@ function CanvasProxy(width, height) {
|
||||
// Dummy context that gets exposed.
|
||||
var ctx = {};
|
||||
this.getContext = function(type) {
|
||||
if (type != "2d") {
|
||||
throw "CanvasProxy can only provide a 2d context.";
|
||||
if (type != '2d') {
|
||||
throw 'CanvasProxy can only provide a 2d context.';
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
@ -82,45 +82,45 @@ function CanvasProxy(width, height) {
|
||||
|
||||
// Setup function calls to `ctx`.
|
||||
var ctxFunc = [
|
||||
"createRadialGradient",
|
||||
"arcTo",
|
||||
"arc",
|
||||
"fillText",
|
||||
"strokeText",
|
||||
"createImageData",
|
||||
"drawWindow",
|
||||
"save",
|
||||
"restore",
|
||||
"scale",
|
||||
"rotate",
|
||||
"translate",
|
||||
"transform",
|
||||
"setTransform",
|
||||
"clearRect",
|
||||
"fillRect",
|
||||
"strokeRect",
|
||||
"beginPath",
|
||||
"closePath",
|
||||
"moveTo",
|
||||
"lineTo",
|
||||
"quadraticCurveTo",
|
||||
"bezierCurveTo",
|
||||
"rect",
|
||||
"fill",
|
||||
"stroke",
|
||||
"clip",
|
||||
"measureText",
|
||||
"isPointInPath",
|
||||
'createRadialGradient',
|
||||
'arcTo',
|
||||
'arc',
|
||||
'fillText',
|
||||
'strokeText',
|
||||
'createImageData',
|
||||
'drawWindow',
|
||||
'save',
|
||||
'restore',
|
||||
'scale',
|
||||
'rotate',
|
||||
'translate',
|
||||
'transform',
|
||||
'setTransform',
|
||||
'clearRect',
|
||||
'fillRect',
|
||||
'strokeRect',
|
||||
'beginPath',
|
||||
'closePath',
|
||||
'moveTo',
|
||||
'lineTo',
|
||||
'quadraticCurveTo',
|
||||
'bezierCurveTo',
|
||||
'rect',
|
||||
'fill',
|
||||
'stroke',
|
||||
'clip',
|
||||
'measureText',
|
||||
'isPointInPath',
|
||||
|
||||
// These functions are necessary to track the rendering currentX state.
|
||||
// The exact values can be computed on the main thread only, as the
|
||||
// worker has no idea about text width.
|
||||
"$setCurrentX",
|
||||
"$addCurrentX",
|
||||
"$saveCurrentX",
|
||||
"$restoreCurrentX",
|
||||
"$showText",
|
||||
"$setFont"
|
||||
'$setCurrentX',
|
||||
'$addCurrentX',
|
||||
'$saveCurrentX',
|
||||
'$restoreCurrentX',
|
||||
'$showText',
|
||||
'$setFont'
|
||||
];
|
||||
|
||||
function buildFuncCall(name) {
|
||||
@ -154,53 +154,54 @@ function CanvasProxy(width, height) {
|
||||
}
|
||||
|
||||
ctx.putImageData = function(data, x, y, width, height) {
|
||||
cmdQueue.push(["$putImageData", [data, x, y, width, height]]);
|
||||
cmdQueue.push(['$putImageData', [data, x, y, width, height]]);
|
||||
}
|
||||
|
||||
ctx.drawImage = function(image, x, y, width, height, sx, sy, swidth, sheight) {
|
||||
ctx.drawImage = function(image, x, y, width, height,
|
||||
sx, sy, swidth, sheight) {
|
||||
if (image instanceof CanvasProxy) {
|
||||
// Send the image/CanvasProxy to the main thread.
|
||||
image.flush();
|
||||
cmdQueue.push(["$drawCanvas", [image.id, x, y, sx, sy, swidth, sheight]]);
|
||||
} else if(image instanceof JpegStreamProxy) {
|
||||
cmdQueue.push(["$drawImage", [image.id, x, y, sx, sy, swidth, sheight]])
|
||||
cmdQueue.push(['$drawCanvas', [image.id, x, y, sx, sy, swidth, sheight]]);
|
||||
} else if (image instanceof JpegStreamProxy) {
|
||||
cmdQueue.push(['$drawImage', [image.id, x, y, sx, sy, swidth, sheight]]);
|
||||
} else {
|
||||
throw "unkown type to drawImage";
|
||||
throw 'unkown type to drawImage';
|
||||
}
|
||||
}
|
||||
|
||||
// Setup property access to `ctx`.
|
||||
var ctxProp = {
|
||||
// "canvas"
|
||||
"globalAlpha": "1",
|
||||
"globalCompositeOperation": "source-over",
|
||||
"strokeStyle": "#000000",
|
||||
"fillStyle": "#000000",
|
||||
"lineWidth": "1",
|
||||
"lineCap": "butt",
|
||||
"lineJoin": "miter",
|
||||
"miterLimit": "10",
|
||||
"shadowOffsetX": "0",
|
||||
"shadowOffsetY": "0",
|
||||
"shadowBlur": "0",
|
||||
"shadowColor": "rgba(0, 0, 0, 0)",
|
||||
"font": "10px sans-serif",
|
||||
"textAlign": "start",
|
||||
"textBaseline": "alphabetic",
|
||||
"mozTextStyle": "10px sans-serif",
|
||||
"mozImageSmoothingEnabled": "true"
|
||||
}
|
||||
'globalAlpha': '1',
|
||||
'globalCompositeOperation': 'source-over',
|
||||
'strokeStyle': '#000000',
|
||||
'fillStyle': '#000000',
|
||||
'lineWidth': '1',
|
||||
'lineCap': 'butt',
|
||||
'lineJoin': 'miter',
|
||||
'miterLimit': '10',
|
||||
'shadowOffsetX': '0',
|
||||
'shadowOffsetY': '0',
|
||||
'shadowBlur': '0',
|
||||
'shadowColor': 'rgba(0, 0, 0, 0)',
|
||||
'font': '10px sans-serif',
|
||||
'textAlign': 'start',
|
||||
'textBaseline': 'alphabetic',
|
||||
'mozTextStyle': '10px sans-serif',
|
||||
'mozImageSmoothingEnabled': 'true'
|
||||
};
|
||||
|
||||
function buildGetter(name) {
|
||||
return function() {
|
||||
return ctx["$" + name];
|
||||
return ctx['$' + name];
|
||||
}
|
||||
}
|
||||
|
||||
function buildSetter(name) {
|
||||
return function(value) {
|
||||
cmdQueue.push(["$", name, value]);
|
||||
return ctx["$" + name] = value;
|
||||
cmdQueue.push(['$', name, value]);
|
||||
return ctx['$' + name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,23 +210,23 @@ function CanvasProxy(width, height) {
|
||||
function buildSetterStyle(name) {
|
||||
return function(value) {
|
||||
if (value instanceof GradientProxy) {
|
||||
cmdQueue.push(["$" + name + "Gradient"]);
|
||||
cmdQueue.push(['$' + name + 'Gradient']);
|
||||
} else if (value instanceof PatternProxy) {
|
||||
cmdQueue.push(["$" + name + "Pattern", [value.id]]);
|
||||
cmdQueue.push(['$' + name + 'Pattern', [value.id]]);
|
||||
} else {
|
||||
cmdQueue.push(["$", name, value]);
|
||||
return ctx["$" + name] = value;
|
||||
cmdQueue.push(['$', name, value]);
|
||||
return ctx['$' + name] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var name in ctxProp) {
|
||||
ctx["$" + name] = ctxProp[name];
|
||||
ctx['$' + name] = ctxProp[name];
|
||||
ctx.__defineGetter__(name, buildGetter(name));
|
||||
|
||||
// Special treatment for `fillStyle` and `strokeStyle`: The passed style
|
||||
// might be a gradient. Need to check for that.
|
||||
if (name == "fillStyle" || name == "strokeStyle") {
|
||||
if (name == 'fillStyle' || name == 'strokeStyle') {
|
||||
ctx.__defineSetter__(name, buildSetterStyle(name));
|
||||
} else {
|
||||
ctx.__defineSetter__(name, buildSetter(name));
|
||||
@ -239,13 +240,13 @@ function CanvasProxy(width, height) {
|
||||
*/
|
||||
CanvasProxy.prototype.flush = function() {
|
||||
postMessage({
|
||||
action: "canvas_proxy_cmd_queue",
|
||||
action: 'canvas_proxy_cmd_queue',
|
||||
data: {
|
||||
id: this.id,
|
||||
cmdQueue: this.cmdQueue,
|
||||
width: this.width,
|
||||
height: this.height
|
||||
id: this.id,
|
||||
cmdQueue: this.cmdQueue,
|
||||
width: this.width,
|
||||
height: this.height
|
||||
}
|
||||
});
|
||||
this.cmdQueue.length = 0;
|
||||
}
|
||||
};
|
||||
|
174
worker/client.js
174
worker/client.js
@ -1,39 +1,39 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
if (typeof console.time == "undefined") {
|
||||
if (typeof console.time == 'undefined') {
|
||||
var consoleTimer = {};
|
||||
console.time = function(name) {
|
||||
consoleTimer[name] = Date.now();
|
||||
};
|
||||
|
||||
|
||||
console.timeEnd = function(name) {
|
||||
var time = consoleTimer[name];
|
||||
if (time == null) {
|
||||
throw "Unkown timer name " + name;
|
||||
throw 'Unkown timer name ' + name;
|
||||
}
|
||||
this.log("Timer:", name, Date.now() - time);
|
||||
this.log('Timer:', name, Date.now() - time);
|
||||
};
|
||||
}
|
||||
|
||||
function FontWorker() {
|
||||
this.worker = new Worker("worker/font.js");
|
||||
this.worker = new Worker('worker/font.js');
|
||||
this.fontsWaiting = 0;
|
||||
this.fontsWaitingCallbacks = [];
|
||||
|
||||
// Listen to the WebWorker for data and call actionHandler on it.
|
||||
this.worker.onmessage = function(event) {
|
||||
var data = event.data;
|
||||
var actionHandler = this.actionHandler
|
||||
var actionHandler = this.actionHandler;
|
||||
if (data.action in actionHandler) {
|
||||
actionHandler[data.action].call(this, data.data);
|
||||
} else {
|
||||
throw "Unkown action from worker: " + data.action;
|
||||
throw 'Unkown action from worker: ' + data.action;
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
|
||||
this.$handleFontLoadedCallback = this.handleFontLoadedCallback.bind(this);
|
||||
}
|
||||
|
||||
@ -50,22 +50,23 @@ FontWorker.prototype = {
|
||||
this.fontsWaitingCallbacks.length = 0;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
actionHandler: {
|
||||
"log": function(data) {
|
||||
'log': function(data) {
|
||||
console.log.apply(console, data);
|
||||
},
|
||||
|
||||
"fonts": function(data) {
|
||||
|
||||
'fonts': function(data) {
|
||||
// console.log("got processed fonts from worker", Object.keys(data));
|
||||
for (name in data) {
|
||||
// Update the encoding property.
|
||||
var font = Fonts.lookup(name);
|
||||
font.properties = {
|
||||
encoding: data[name].encoding
|
||||
}
|
||||
};
|
||||
|
||||
// Call `Font.prototype.bindDOM` to make the font get loaded on the page.
|
||||
// Call `Font.prototype.bindDOM` to make the font get loaded
|
||||
// on the page.
|
||||
Font.prototype.bindDOM.call(
|
||||
font,
|
||||
data[name].str,
|
||||
@ -84,7 +85,7 @@ FontWorker.prototype = {
|
||||
if (Fonts[font.name]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Register the font but don't pass in any real data. The idea is to
|
||||
// store as less data as possible to reduce memory usage.
|
||||
Fonts.registerFont(font.name, Object.create(null), Object.create(null));
|
||||
@ -94,16 +95,16 @@ FontWorker.prototype = {
|
||||
// Increate the number of fonts to wait for.
|
||||
this.fontsWaiting++;
|
||||
}
|
||||
|
||||
console.time("ensureFonts");
|
||||
|
||||
console.time('ensureFonts');
|
||||
// If there are fonts, that need to get loaded, tell the FontWorker to get
|
||||
// started and push the callback on the waiting-callback-stack.
|
||||
if (notLoaded.length != 0) {
|
||||
console.log("fonts -> FontWorker");
|
||||
console.log('fonts -> FontWorker');
|
||||
// Send the worker the fonts to work on.
|
||||
this.worker.postMessage({
|
||||
action: "fonts",
|
||||
data: notLoaded
|
||||
action: 'fonts',
|
||||
data: notLoaded
|
||||
});
|
||||
if (callback) {
|
||||
this.fontsWaitingCallbacks.push(callback);
|
||||
@ -115,13 +116,13 @@ FontWorker.prototype = {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function WorkerPDFDoc(canvas) {
|
||||
var timer = null
|
||||
var timer = null;
|
||||
|
||||
this.ctx = canvas.getContext("2d");
|
||||
this.ctx = canvas.getContext('2d');
|
||||
this.canvas = canvas;
|
||||
this.worker = new Worker('worker/pdf.js');
|
||||
this.fontWorker = new FontWorker();
|
||||
@ -142,30 +143,30 @@ function WorkerPDFDoc(canvas) {
|
||||
var currentXStack = [];
|
||||
|
||||
var ctxSpecial = {
|
||||
"$setCurrentX": function(value) {
|
||||
'$setCurrentX': function(value) {
|
||||
currentX = value;
|
||||
},
|
||||
|
||||
"$addCurrentX": function(value) {
|
||||
'$addCurrentX': function(value) {
|
||||
currentX += value;
|
||||
},
|
||||
|
||||
"$saveCurrentX": function() {
|
||||
'$saveCurrentX': function() {
|
||||
currentXStack.push(currentX);
|
||||
},
|
||||
|
||||
"$restoreCurrentX": function() {
|
||||
'$restoreCurrentX': function() {
|
||||
currentX = currentXStack.pop();
|
||||
},
|
||||
|
||||
"$showText": function(y, text) {
|
||||
'$showText': function(y, text) {
|
||||
text = Fonts.charsToUnicode(text);
|
||||
this.translate(currentX, -1 * y);
|
||||
this.fillText(text, 0, 0);
|
||||
currentX += this.measureText(text).width;
|
||||
},
|
||||
|
||||
"$putImageData": function(imageData, x, y) {
|
||||
'$putImageData': function(imageData, x, y) {
|
||||
var imgData = this.getImageData(0, 0, imageData.width, imageData.height);
|
||||
|
||||
// Store the .data property to avaid property lookups.
|
||||
@ -175,24 +176,24 @@ function WorkerPDFDoc(canvas) {
|
||||
// Copy over the imageData.
|
||||
var len = imageRealData.length;
|
||||
while (len--)
|
||||
imgRealData[len] = imageRealData[len]
|
||||
imgRealData[len] = imageRealData[len];
|
||||
|
||||
this.putImageData(imgData, x, y);
|
||||
},
|
||||
|
||||
"$drawImage": function(id, x, y, sx, sy, swidth, sheight) {
|
||||
'$drawImage': function(id, x, y, sx, sy, swidth, sheight) {
|
||||
var image = imagesList[id];
|
||||
if (!image) {
|
||||
throw "Image not found: " + id;
|
||||
throw 'Image not found: ' + id;
|
||||
}
|
||||
this.drawImage(image, x, y, image.width, image.height,
|
||||
sx, sy, swidth, sheight);
|
||||
},
|
||||
|
||||
"$drawCanvas": function(id, x, y, sx, sy, swidth, sheight) {
|
||||
'$drawCanvas': function(id, x, y, sx, sy, swidth, sheight) {
|
||||
var canvas = canvasList[id];
|
||||
if (!canvas) {
|
||||
throw "Canvas not found";
|
||||
throw 'Canvas not found';
|
||||
}
|
||||
if (sheight != null) {
|
||||
this.drawImage(canvas, x, y, canvas.width, canvas.height,
|
||||
@ -202,58 +203,58 @@ function WorkerPDFDoc(canvas) {
|
||||
}
|
||||
},
|
||||
|
||||
"$createLinearGradient": function(x0, y0, x1, y1) {
|
||||
'$createLinearGradient': function(x0, y0, x1, y1) {
|
||||
gradient = this.createLinearGradient(x0, y0, x1, y1);
|
||||
},
|
||||
|
||||
"$createPatternFromCanvas": function(patternId, canvasId, kind) {
|
||||
'$createPatternFromCanvas': function(patternId, canvasId, kind) {
|
||||
var canvas = canvasList[canvasId];
|
||||
if (!canvas) {
|
||||
throw "Canvas not found";
|
||||
throw 'Canvas not found';
|
||||
}
|
||||
patternList[patternId] = this.createPattern(canvas, kind);
|
||||
},
|
||||
|
||||
"$addColorStop": function(i, rgba) {
|
||||
'$addColorStop': function(i, rgba) {
|
||||
gradient.addColorStop(i, rgba);
|
||||
},
|
||||
|
||||
"$fillStyleGradient": function() {
|
||||
'$fillStyleGradient': function() {
|
||||
this.fillStyle = gradient;
|
||||
},
|
||||
|
||||
"$fillStylePattern": function(id) {
|
||||
'$fillStylePattern': function(id) {
|
||||
var pattern = patternList[id];
|
||||
if (!pattern) {
|
||||
throw "Pattern not found";
|
||||
throw 'Pattern not found';
|
||||
}
|
||||
this.fillStyle = pattern;
|
||||
},
|
||||
|
||||
"$strokeStyleGradient": function() {
|
||||
'$strokeStyleGradient': function() {
|
||||
this.strokeStyle = gradient;
|
||||
},
|
||||
|
||||
"$strokeStylePattern": function(id) {
|
||||
'$strokeStylePattern': function(id) {
|
||||
var pattern = patternList[id];
|
||||
if (!pattern) {
|
||||
throw "Pattern not found";
|
||||
throw 'Pattern not found';
|
||||
}
|
||||
this.strokeStyle = pattern;
|
||||
},
|
||||
|
||||
"$setFont": function(name, size) {
|
||||
'$setFont': function(name, size) {
|
||||
this.font = size + 'px "' + name + '"';
|
||||
Fonts.setActive(name, size);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function renderProxyCanvas(canvas, cmdQueue) {
|
||||
var ctx = canvas.getContext("2d");
|
||||
var ctx = canvas.getContext('2d');
|
||||
var cmdQueueLength = cmdQueue.length;
|
||||
for (var i = 0; i < cmdQueueLength; i++) {
|
||||
var opp = cmdQueue[i];
|
||||
if (opp[0] == "$") {
|
||||
if (opp[0] == '$') {
|
||||
ctx[opp[1]] = opp[2];
|
||||
} else if (opp[0] in ctxSpecial) {
|
||||
ctxSpecial[opp[0]].apply(ctx, opp[1]);
|
||||
@ -267,44 +268,45 @@ function WorkerPDFDoc(canvas) {
|
||||
* Functions to handle data sent by the WebWorker.
|
||||
*/
|
||||
var actionHandler = {
|
||||
"log": function(data) {
|
||||
'log': function(data) {
|
||||
console.log.apply(console, data);
|
||||
},
|
||||
|
||||
"pdf_num_pages": function(data) {
|
||||
|
||||
'pdf_num_pages': function(data) {
|
||||
this.numPages = parseInt(data);
|
||||
if (this.loadCallback) {
|
||||
this.loadCallback();
|
||||
}
|
||||
},
|
||||
|
||||
"font": function(data) {
|
||||
|
||||
'font': function(data) {
|
||||
var base64 = window.btoa(data.raw);
|
||||
|
||||
// Add the @font-face rule to the document
|
||||
var url = "url(data:" + data.mimetype + ";base64," + base64 + ");";
|
||||
var rule = "@font-face { font-family:'" + data.fontName + "';src:" + url + "}";
|
||||
var url = 'url(data:' + data.mimetype + ';base64,' + base64 + ');';
|
||||
var rule = ("@font-face { font-family:'" + data.fontName +
|
||||
"';src:" + url + '}');
|
||||
var styleSheet = document.styleSheets[0];
|
||||
styleSheet.insertRule(rule, styleSheet.cssRules.length);
|
||||
|
||||
// Just adding the font-face to the DOM doesn't make it load. It
|
||||
// seems it's loaded once Gecko notices it's used. Therefore,
|
||||
// add a div on the page using the loaded font.
|
||||
var div = document.createElement("div");
|
||||
var style = 'font-family:"' + data.fontName +
|
||||
var div = document.createElement('div');
|
||||
var style = 'font-family:"' + data.fontName +
|
||||
'";position: absolute;top:-99999;left:-99999;z-index:-99999';
|
||||
div.setAttribute("style", style);
|
||||
div.setAttribute('style', style);
|
||||
document.body.appendChild(div);
|
||||
},
|
||||
|
||||
"setup_page": function(data) {
|
||||
var size = data.split(",");
|
||||
|
||||
'setup_page': function(data) {
|
||||
var size = data.split(',');
|
||||
var canvas = this.canvas, ctx = this.ctx;
|
||||
canvas.width = parseInt(size[0]);
|
||||
canvas.height = parseInt(size[1]);
|
||||
},
|
||||
|
||||
"fonts": function(data) {
|
||||
'fonts': function(data) {
|
||||
this.waitingForFonts = true;
|
||||
this.fontWorker.ensureFonts(data, function() {
|
||||
this.waitingForFonts = false;
|
||||
@ -316,20 +318,20 @@ function WorkerPDFDoc(canvas) {
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
"jpeg_stream": function(data) {
|
||||
'jpeg_stream': function(data) {
|
||||
var img = new Image();
|
||||
img.src = "data:image/jpeg;base64," + window.btoa(data.raw);
|
||||
img.src = 'data:image/jpeg;base64,' + window.btoa(data.raw);
|
||||
imagesList[data.id] = img;
|
||||
},
|
||||
|
||||
"canvas_proxy_cmd_queue": function(data) {
|
||||
|
||||
'canvas_proxy_cmd_queue': function(data) {
|
||||
var id = data.id;
|
||||
var cmdQueue = data.cmdQueue;
|
||||
|
||||
// Check if there is already a canvas with the given id. If not,
|
||||
// create a new canvas.
|
||||
if (!canvasList[id]) {
|
||||
var newCanvas = document.createElement("canvas");
|
||||
var newCanvas = document.createElement('canvas');
|
||||
newCanvas.width = data.width;
|
||||
newCanvas.height = data.height;
|
||||
canvasList[id] = newCanvas;
|
||||
@ -337,23 +339,23 @@ function WorkerPDFDoc(canvas) {
|
||||
|
||||
var renderData = function() {
|
||||
if (id == 0) {
|
||||
console.time("main canvas rendering");
|
||||
console.time('main canvas rendering');
|
||||
var ctx = this.ctx;
|
||||
ctx.save();
|
||||
ctx.fillStyle = "rgb(255, 255, 255)";
|
||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.restore();
|
||||
}
|
||||
renderProxyCanvas(canvasList[id], cmdQueue);
|
||||
if (id == 0) {
|
||||
console.timeEnd("main canvas rendering");
|
||||
console.timeEnd(">>> total page display time:");
|
||||
console.timeEnd('main canvas rendering');
|
||||
console.timeEnd('>>> total page display time:');
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
if (this.waitingForFonts) {
|
||||
if (id == 0) {
|
||||
console.log("want to render, but not all fonts are there", id);
|
||||
console.log('want to render, but not all fonts are there', id);
|
||||
this.waitingForFontsCallback.push(renderData);
|
||||
} else {
|
||||
// console.log("assume canvas doesn't have fonts", id);
|
||||
@ -363,7 +365,7 @@ function WorkerPDFDoc(canvas) {
|
||||
renderData();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Listen to the WebWorker for data and call actionHandler on it.
|
||||
this.worker.onmessage = function(event) {
|
||||
@ -371,16 +373,16 @@ function WorkerPDFDoc(canvas) {
|
||||
if (data.action in actionHandler) {
|
||||
actionHandler[data.action].call(this, data.data);
|
||||
} else {
|
||||
throw "Unkown action from worker: " + data.action;
|
||||
throw 'Unkown action from worker: ' + data.action;
|
||||
}
|
||||
}.bind(this)
|
||||
}.bind(this);
|
||||
}
|
||||
|
||||
WorkerPDFDoc.prototype.open = function(url, callback) {
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET", url);
|
||||
req.mozResponseType = req.responseType = "arraybuffer";
|
||||
req.expected = (document.URL.indexOf("file:") == 0) ? 0 : 200;
|
||||
req.open('GET', url);
|
||||
req.mozResponseType = req.responseType = 'arraybuffer';
|
||||
req.expected = (document.URL.indexOf('file:') == 0) ? 0 : 200;
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4 && req.status == req.expected) {
|
||||
var data = req.mozResponseArrayBuffer || req.mozResponse ||
|
||||
@ -392,24 +394,24 @@ WorkerPDFDoc.prototype.open = function(url, callback) {
|
||||
}
|
||||
}.bind(this);
|
||||
req.send(null);
|
||||
}
|
||||
};
|
||||
|
||||
WorkerPDFDoc.prototype.showPage = function(numPage) {
|
||||
this.numPage = parseInt(numPage);
|
||||
console.log("=== start rendering page " + numPage + " ===");
|
||||
console.time(">>> total page display time:");
|
||||
console.log('=== start rendering page ' + numPage + ' ===');
|
||||
console.time('>>> total page display time:');
|
||||
this.worker.postMessage(numPage);
|
||||
if (this.onChangePage) {
|
||||
this.onChangePage(numPage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
WorkerPDFDoc.prototype.nextPage = function() {
|
||||
if (this.numPage == this.numPages) return;
|
||||
this.showPage(++this.numPage);
|
||||
}
|
||||
};
|
||||
|
||||
WorkerPDFDoc.prototype.prevPage = function() {
|
||||
if (this.numPage == 1) return;
|
||||
this.showPage(--this.numPage);
|
||||
}
|
||||
};
|
||||
|
@ -1,27 +1,27 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var consoleTimer = {};
|
||||
var console = {
|
||||
log: function log() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
postMessage({
|
||||
action: "log",
|
||||
action: 'log',
|
||||
data: args
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
time: function(name) {
|
||||
consoleTimer[name] = Date.now();
|
||||
},
|
||||
|
||||
|
||||
timeEnd: function(name) {
|
||||
var time = consoleTimer[name];
|
||||
if (time == null) {
|
||||
throw "Unkown timer name " + name;
|
||||
throw 'Unkown timer name ' + name;
|
||||
}
|
||||
this.log("Timer:", name, Date.now() - time);
|
||||
this.log('Timer:', name, Date.now() - time);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,13 +1,13 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
importScripts("console.js");
|
||||
importScripts('console.js');
|
||||
|
||||
importScripts("../pdf.js");
|
||||
importScripts("../fonts.js");
|
||||
importScripts("../glyphlist.js")
|
||||
importScripts('../pdf.js');
|
||||
importScripts('../fonts.js');
|
||||
importScripts('../glyphlist.js');
|
||||
|
||||
function fontDataToString(font) {
|
||||
// Doing postMessage on objects make them lose their "shape". This adds the
|
||||
@ -16,43 +16,44 @@ function fontDataToString(font) {
|
||||
var fontFileDict = new Dict();
|
||||
fontFileDict.map = font.file.dict.map;
|
||||
|
||||
var fontFile = new Stream(font.file.bytes, font.file.start, font.file.end - font.file.start, fontFileDict);
|
||||
var fontFile = new Stream(font.file.bytes, font.file.start,
|
||||
font.file.end - font.file.start, fontFileDict);
|
||||
font.file = new FlateStream(fontFile);
|
||||
|
||||
|
||||
// This will encode the font.
|
||||
var fontObj = new Font(font.name, font.file, font.properties);
|
||||
|
||||
// Create string that is used for css later.
|
||||
var str = "";
|
||||
var str = '';
|
||||
var data = fontObj.data;
|
||||
var length = data.length;
|
||||
for (var j = 0; j < length; j++)
|
||||
str += String.fromCharCode(data[j]);
|
||||
|
||||
|
||||
return {
|
||||
str: str,
|
||||
str: str,
|
||||
encoding: font.properties.encoding
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Functions to handle data sent by the MainThread.
|
||||
*/
|
||||
var actionHandler = {
|
||||
"fonts": function(data) {
|
||||
'fonts': function(data) {
|
||||
var fontData;
|
||||
var result = {};
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
fontData = data[i];
|
||||
result[fontData.name] = fontDataToString(fontData);
|
||||
}
|
||||
|
||||
|
||||
postMessage({
|
||||
action: "fonts",
|
||||
data: result
|
||||
})
|
||||
},
|
||||
}
|
||||
action: 'fonts',
|
||||
data: result
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Listen to the MainThread for data and call actionHandler on it.
|
||||
this.onmessage = function(event) {
|
||||
@ -60,6 +61,6 @@ this.onmessage = function(event) {
|
||||
if (data.action in actionHandler) {
|
||||
actionHandler[data.action].call(this, data.data);
|
||||
} else {
|
||||
throw "Unkown action from worker: " + data.action;
|
||||
throw 'Unkown action from worker: ' + data.action;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,38 +1,38 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var consoleTimer = {};
|
||||
var console = {
|
||||
log: function log() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
postMessage({
|
||||
action: "log",
|
||||
action: 'log',
|
||||
data: args
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
time: function(name) {
|
||||
consoleTimer[name] = Date.now();
|
||||
},
|
||||
|
||||
|
||||
timeEnd: function(name) {
|
||||
var time = consoleTimer[name];
|
||||
if (time == null) {
|
||||
throw "Unkown timer name " + name;
|
||||
throw 'Unkown timer name ' + name;
|
||||
}
|
||||
this.log("Timer:", name, Date.now() - time);
|
||||
this.log('Timer:', name, Date.now() - time);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
importScripts("console.js")
|
||||
importScripts("canvas.js");
|
||||
importScripts("../pdf.js");
|
||||
importScripts("../fonts.js");
|
||||
importScripts("../crypto.js");
|
||||
importScripts("../glyphlist.js")
|
||||
importScripts('console.js');
|
||||
importScripts('canvas.js');
|
||||
importScripts('../pdf.js');
|
||||
importScripts('../fonts.js');
|
||||
importScripts('../crypto.js');
|
||||
importScripts('../glyphlist.js');
|
||||
|
||||
// Use the JpegStreamProxy proxy.
|
||||
JpegStream = JpegStreamProxy;
|
||||
@ -48,14 +48,14 @@ onmessage = function(event) {
|
||||
if (!pdfDocument) {
|
||||
pdfDocument = new PDFDoc(new Stream(data));
|
||||
postMessage({
|
||||
action: "pdf_num_pages",
|
||||
action: 'pdf_num_pages',
|
||||
data: pdfDocument.numPages
|
||||
});
|
||||
return;
|
||||
}
|
||||
// User requested to render a certain page.
|
||||
else {
|
||||
console.time("compile");
|
||||
console.time('compile');
|
||||
|
||||
// Let's try to render the first page...
|
||||
var page = pdfDocument.getPage(parseInt(data));
|
||||
@ -64,8 +64,8 @@ onmessage = function(event) {
|
||||
var pageWidth = (page.mediaBox[2] - page.mediaBox[0]) * pdfToCssUnitsCoef;
|
||||
var pageHeight = (page.mediaBox[3] - page.mediaBox[1]) * pdfToCssUnitsCoef;
|
||||
postMessage({
|
||||
action: "setup_page",
|
||||
data: pageWidth + "," + pageHeight
|
||||
action: 'setup_page',
|
||||
data: pageWidth + ',' + pageHeight
|
||||
});
|
||||
|
||||
// Set canvas size.
|
||||
@ -75,21 +75,21 @@ onmessage = function(event) {
|
||||
// page.compile will collect all fonts for us, once we have loaded them
|
||||
// we can trigger the actual page rendering with page.display
|
||||
var fonts = [];
|
||||
var gfx = new CanvasGraphics(canvas.getContext("2d"), CanvasProxy);
|
||||
var gfx = new CanvasGraphics(canvas.getContext('2d'), CanvasProxy);
|
||||
page.compile(gfx, fonts);
|
||||
console.timeEnd("compile");
|
||||
console.timeEnd('compile');
|
||||
|
||||
// Send fonts to the main thread.
|
||||
console.time("fonts");
|
||||
console.time('fonts');
|
||||
postMessage({
|
||||
action: "fonts",
|
||||
data: fonts
|
||||
action: 'fonts',
|
||||
data: fonts
|
||||
});
|
||||
console.timeEnd("fonts");
|
||||
|
||||
console.time("display");
|
||||
console.timeEnd('fonts');
|
||||
|
||||
console.time('display');
|
||||
page.display(gfx);
|
||||
canvas.flush();
|
||||
console.timeEnd("display");
|
||||
console.timeEnd('display');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user