Merge upstream.
This commit is contained in:
commit
fece736b8a
1
Makefile
1
Makefile
@ -39,6 +39,7 @@ PDF_JS_FILES = \
|
|||||||
../external/jpgjs/jpg.js \
|
../external/jpgjs/jpg.js \
|
||||||
jpx.js \
|
jpx.js \
|
||||||
bidi.js \
|
bidi.js \
|
||||||
|
metadata.js \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
# make server
|
# make server
|
||||||
|
33
README.md
33
README.md
@ -122,41 +122,14 @@ Our Github contributors so far:
|
|||||||
You can add your name to it! :)
|
You can add your name to it! :)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Running the tests
|
# Running the tests
|
||||||
|
|
||||||
pdf.js comes with browser-level regression tests that allow one to probe
|
pdf.js comes with browser-level regression tests that allow one to probe
|
||||||
whether it's able to successfully parse PDFs, as well as compare its output
|
whether it's able to successfully parse PDFs, as well as compare its output
|
||||||
against reference images, pixel-by-pixel.
|
against reference images, pixel-by-pixel.
|
||||||
|
|
||||||
To run the tests, first configure the browser manifest file at:
|
More information about running the tests can be found on the
|
||||||
|
[contributor wiki page](https://github.com/mozilla/pdf.js/wiki/Contributing).
|
||||||
test/resources/browser_manifests/browser_manifest.json
|
|
||||||
|
|
||||||
Sample manifests for different platforms are provided in that directory.
|
|
||||||
|
|
||||||
To run all the bundled tests, type:
|
|
||||||
|
|
||||||
$ make test
|
|
||||||
|
|
||||||
and cross your fingers. Different types of tests are available, see the test
|
|
||||||
manifest file at:
|
|
||||||
|
|
||||||
test/test_manifest.json
|
|
||||||
|
|
||||||
The test type `eq` tests whether the output images are identical to reference
|
|
||||||
images. The test type `load` simply tests whether the file loads without
|
|
||||||
raising any errors.
|
|
||||||
|
|
||||||
|
|
||||||
### Running tests through our bot
|
|
||||||
|
|
||||||
If you are a reviewer, you can use our remote bot to issue comprehensive tests
|
|
||||||
against reference images before merging pull requests.
|
|
||||||
|
|
||||||
See the bot repo for details:
|
|
||||||
|
|
||||||
+ https://github.com/mozilla/pdf.js-bot
|
|
||||||
|
|
||||||
|
|
||||||
# Additional resources
|
# Additional resources
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<em:bootstrap>true</em:bootstrap>
|
<em:bootstrap>true</em:bootstrap>
|
||||||
<em:creator>Mozilla</em:creator>
|
<em:creator>Mozilla</em:creator>
|
||||||
<em:description>Uses HTML5 to display PDF files directly in Firefox.</em:description>
|
<em:description>Uses HTML5 to display PDF files directly in Firefox.</em:description>
|
||||||
<em:homepageURL>http://support.mozilla.org/kb/using-mozilla-pdf-viewer</em:homepageURL>
|
<em:homepageURL>https://support.mozilla.org/kb/Opening%20PDF%20files%20within%20Firefox</em:homepageURL>
|
||||||
<em:type>2</em:type>
|
<em:type>2</em:type>
|
||||||
</Description>
|
</Description>
|
||||||
</RDF>
|
</RDF>
|
||||||
|
22
external/shelljs/ChangeLog
vendored
Normal file
22
external/shelljs/ChangeLog
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
2012.03.22, Version 0.0.4
|
||||||
|
|
||||||
|
* ls() and find() return arrays instead of hashes (Artur Adib)
|
||||||
|
* exec({silent:...}) overrides global silent() state (Artur Adib)
|
||||||
|
|
||||||
|
|
||||||
|
2012.03.21, Version 0.0.3
|
||||||
|
|
||||||
|
* Wildcard bug fix (Artur Adib)
|
||||||
|
* execSync() now uses dummy file I/O op to reduce CPU usage (Artur Adib)
|
||||||
|
* Minor fixes
|
||||||
|
|
||||||
|
|
||||||
|
2012.03.15, Version 0.0.2
|
||||||
|
|
||||||
|
* New methods: find(), test() (Artur Adib)
|
||||||
|
* Deprecated non-Unix methods: exists(), verbose()
|
||||||
|
|
||||||
|
|
||||||
|
2012.03.03, Version 0.0.2pre1
|
||||||
|
|
||||||
|
* First public release
|
66
external/shelljs/README.md
vendored
66
external/shelljs/README.md
vendored
@ -1,6 +1,7 @@
|
|||||||
# ShellJS - Unix shell commands for Node.js [](http://travis-ci.org/arturadib/shelljs)
|
# ShellJS - Unix shell commands for Node.js [](http://travis-ci.org/arturadib/shelljs)
|
||||||
|
|
||||||
_This project is young and experimental. Use at your own risk._
|
+ _This project is young and experimental. Use at your own risk._
|
||||||
|
+ _Major API change as of v0.0.4: `ls()` and `find()` now return arrays._
|
||||||
|
|
||||||
ShellJS is a **portable** (Windows included) implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping its familiar and powerful commands.
|
ShellJS is a **portable** (Windows included) implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping its familiar and powerful commands.
|
||||||
|
|
||||||
@ -18,11 +19,11 @@ cp('-R', 'stuff/*', 'out/Release');
|
|||||||
|
|
||||||
// Replace macros in each .js file
|
// Replace macros in each .js file
|
||||||
cd('lib');
|
cd('lib');
|
||||||
for (file in ls('*.js')) {
|
ls('*.js').forEach(function(file) {
|
||||||
sed('-i', 'BUILD_VERSION', 'v0.1.2', file);
|
sed('-i', 'BUILD_VERSION', 'v0.1.2', file);
|
||||||
sed('-i', /.*REMOVE_THIS_LINE.*\n/, '', file);
|
sed('-i', /.*REMOVE_THIS_LINE.*\n/, '', file);
|
||||||
sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat('macro.js'), file);
|
sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat('macro.js'), file);
|
||||||
}
|
});
|
||||||
cd('..');
|
cd('..');
|
||||||
|
|
||||||
// Run external tool synchronously
|
// Run external tool synchronously
|
||||||
@ -73,11 +74,11 @@ target.docs = function() {
|
|||||||
cd(__dirname);
|
cd(__dirname);
|
||||||
mkdir('docs');
|
mkdir('docs');
|
||||||
cd('lib');
|
cd('lib');
|
||||||
for (file in ls('*.js')) {
|
ls('*.js').forEach(function(file){
|
||||||
var text = grep('//@', file); // extract special comments
|
var text = grep('//@', file); // extract special comments
|
||||||
text.replace('//@', ''); // remove comment tags
|
text.replace('//@', ''); // remove comment tags
|
||||||
text.to('docs/my_docs.md');
|
text.to('docs/my_docs.md');
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -128,9 +129,7 @@ ls('-R', '/users/me', '/tmp');
|
|||||||
ls('-R', ['/users/me', '/tmp']); // same as above
|
ls('-R', ['/users/me', '/tmp']); // same as above
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns list of files in the given path, or in current directory if no path provided.
|
Returns array of files in the given path, or in current directory if no path provided.
|
||||||
For convenient iteration via `for (file in ls())`, the format returned is a hash object:
|
|
||||||
`{ 'file1':null, 'dir1/file2':null, ...}`.
|
|
||||||
|
|
||||||
#### find(path [,path ...])
|
#### find(path [,path ...])
|
||||||
#### find(path_array)
|
#### find(path_array)
|
||||||
@ -139,18 +138,12 @@ Examples:
|
|||||||
```javascript
|
```javascript
|
||||||
find('src', 'lib');
|
find('src', 'lib');
|
||||||
find(['src', 'lib']); // same as above
|
find(['src', 'lib']); // same as above
|
||||||
for (file in find('.')) {
|
find('.').filter(function(file) { return file.match(/\.js$/); });
|
||||||
if (!file.match(/\.js$/))
|
|
||||||
continue;
|
|
||||||
// all files at this point end in '.js'
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns list of all files (however deep) in the given paths. For convenient iteration
|
Returns array of all files (however deep) in the given paths.
|
||||||
via `for (file in find(...))`, the format returned is a hash object:
|
|
||||||
`{ 'file1':null, 'dir1/file2':null, ...}`.
|
|
||||||
|
|
||||||
The main difference with respect to `ls('-R', path)` is that the resulting file names
|
The main difference from `ls('-R', path)` is that the resulting file names
|
||||||
include the base directories, e.g. `lib/resources/file1` instead of just `file1`.
|
include the base directories, e.g. `lib/resources/file1` instead of just `file1`.
|
||||||
|
|
||||||
#### cp('[options ,] source [,source ...], dest')
|
#### cp('[options ,] source [,source ...], dest')
|
||||||
@ -332,6 +325,10 @@ When in synchronous mode returns the object `{ code:..., output:... }`, containi
|
|||||||
`output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the
|
`output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the
|
||||||
arguments `(code, output)`.
|
arguments `(code, output)`.
|
||||||
|
|
||||||
|
**Note:** For long-lived processes, it's best to run `exec()` asynchronously as
|
||||||
|
the current synchronous implementation uses a lot of CPU. This should be getting
|
||||||
|
fixed soon.
|
||||||
|
|
||||||
## Non-Unix commands
|
## Non-Unix commands
|
||||||
|
|
||||||
|
|
||||||
@ -339,16 +336,35 @@ arguments `(code, output)`.
|
|||||||
Searches and returns string containing a writeable, platform-dependent temporary directory.
|
Searches and returns string containing a writeable, platform-dependent temporary directory.
|
||||||
Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
|
Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
|
||||||
|
|
||||||
#### exists(path [, path ...])
|
|
||||||
#### exists(path_array)
|
|
||||||
Returns true if all the given paths exist.
|
|
||||||
|
|
||||||
#### error()
|
#### error()
|
||||||
Tests if error occurred in the last command. Returns `null` if no error occurred,
|
Tests if error occurred in the last command. Returns `null` if no error occurred,
|
||||||
otherwise returns string explaining the error
|
otherwise returns string explaining the error
|
||||||
|
|
||||||
#### verbose()
|
#### silent([state])
|
||||||
Enables all output (default)
|
Example:
|
||||||
|
|
||||||
#### silent()
|
```javascript
|
||||||
Suppresses all output, except for explict `echo()` calls
|
var silentState = silent();
|
||||||
|
silent(true);
|
||||||
|
/* ... */
|
||||||
|
silent(silentState); // restore old silent state
|
||||||
|
```
|
||||||
|
|
||||||
|
Suppresses all command output if `state = true`, except for `echo()` calls.
|
||||||
|
Returns state if no arguments given.
|
||||||
|
|
||||||
|
## Deprecated
|
||||||
|
|
||||||
|
|
||||||
|
#### exists(path [, path ...])
|
||||||
|
#### exists(path_array)
|
||||||
|
|
||||||
|
_This function is being deprecated. Use `test()` instead._
|
||||||
|
|
||||||
|
Returns true if all the given paths exist.
|
||||||
|
|
||||||
|
#### verbose()
|
||||||
|
|
||||||
|
_This function is being deprecated. Use `silent(false) instead.`_
|
||||||
|
|
||||||
|
Enables all output (default)
|
||||||
|
2
external/shelljs/make.js
vendored
2
external/shelljs/make.js
vendored
@ -23,7 +23,7 @@ setTimeout(function() {
|
|||||||
if (oldTarget.done && !force)
|
if (oldTarget.done && !force)
|
||||||
return;
|
return;
|
||||||
oldTarget.done = true;
|
oldTarget.done = true;
|
||||||
return oldTarget(arguments);
|
return oldTarget.apply(oldTarget, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
})(t, target[t]);
|
})(t, target[t]);
|
||||||
|
35
external/shelljs/package.json
vendored
35
external/shelljs/package.json
vendored
@ -1,12 +1,29 @@
|
|||||||
{ "name": "shelljs"
|
{
|
||||||
, "version": "0.0.2pre1"
|
"name": "shelljs",
|
||||||
, "author": "Artur Adib <aadib@mozilla.com>"
|
"version": "0.0.5pre4",
|
||||||
, "description": "Portable Unix shell commands for Node.js"
|
"author": "Artur Adib <aadib@mozilla.com>",
|
||||||
, "keywords": ["unix", "shell", "makefile", "make", "jake", "synchronous"]
|
"description": "Portable Unix shell commands for Node.js",
|
||||||
, "repository": "git://github.com/arturadib/shelljs"
|
"keywords": [
|
||||||
, "homepage": "http://github.com/arturadib/shelljs"
|
"unix",
|
||||||
, "main": "./shell.js"
|
"shell",
|
||||||
, "scripts": {
|
"makefile",
|
||||||
|
"make",
|
||||||
|
"jake",
|
||||||
|
"synchronous"
|
||||||
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/arturadib/shelljs.git"
|
||||||
|
},
|
||||||
|
"homepage": "http://github.com/arturadib/shelljs",
|
||||||
|
"main": "./shell.js",
|
||||||
|
"scripts": {
|
||||||
"test": "node scripts/run-tests"
|
"test": "node scripts/run-tests"
|
||||||
|
},
|
||||||
|
"dependencies": {},
|
||||||
|
"devDependencies": {},
|
||||||
|
"optionalDependencies": {},
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
313
external/shelljs/shell.js
vendored
313
external/shelljs/shell.js
vendored
@ -74,9 +74,7 @@ exports.pwd = wrap('pwd', _pwd);
|
|||||||
//@ ls('-R', ['/users/me', '/tmp']); // same as above
|
//@ ls('-R', ['/users/me', '/tmp']); // same as above
|
||||||
//@ ```
|
//@ ```
|
||||||
//@
|
//@
|
||||||
//@ Returns list of files in the given path, or in current directory if no path provided.
|
//@ Returns array of files in the given path, or in current directory if no path provided.
|
||||||
//@ For convenient iteration via `for (file in ls())`, the format returned is a hash object:
|
|
||||||
//@ `{ 'file1':null, 'dir1/file2':null, ...}`.
|
|
||||||
function _ls(options, paths) {
|
function _ls(options, paths) {
|
||||||
options = parseOptions(options, {
|
options = parseOptions(options, {
|
||||||
'R': 'recursive',
|
'R': 'recursive',
|
||||||
@ -90,24 +88,30 @@ function _ls(options, paths) {
|
|||||||
else if (typeof paths === 'string')
|
else if (typeof paths === 'string')
|
||||||
paths = [].slice.call(arguments, 1);
|
paths = [].slice.call(arguments, 1);
|
||||||
|
|
||||||
var hash = {};
|
var list = [];
|
||||||
|
|
||||||
function pushHash(file, query) {
|
// Conditionally pushes file to list - returns true if pushed, false otherwise
|
||||||
|
// (e.g. prevents hidden files to be included unless explicitly told so)
|
||||||
|
function pushFile(file, query) {
|
||||||
// hidden file?
|
// hidden file?
|
||||||
if (path.basename(file)[0] === '.') {
|
if (path.basename(file)[0] === '.') {
|
||||||
// not explicitly asking for hidden files?
|
// not explicitly asking for hidden files?
|
||||||
if (!options.all && !(path.basename(query)[0] === '.' && path.basename(query).length > 1))
|
if (!options.all && !(path.basename(query)[0] === '.' && path.basename(query).length > 1))
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hash[file] = null;
|
if (platform === 'win')
|
||||||
|
file = file.replace(/\\/g, '/');
|
||||||
|
|
||||||
|
list.push(file);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
paths.forEach(function(p) {
|
paths.forEach(function(p) {
|
||||||
if (fs.existsSync(p)) {
|
if (fs.existsSync(p)) {
|
||||||
// Simple file?
|
// Simple file?
|
||||||
if (fs.statSync(p).isFile()) {
|
if (fs.statSync(p).isFile()) {
|
||||||
pushHash(p, p);
|
pushFile(p, p);
|
||||||
return; // continue
|
return; // continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,14 +119,17 @@ function _ls(options, paths) {
|
|||||||
if (fs.statSync(p).isDirectory()) {
|
if (fs.statSync(p).isDirectory()) {
|
||||||
// Iterate over p contents
|
// Iterate over p contents
|
||||||
fs.readdirSync(p).forEach(function(file) {
|
fs.readdirSync(p).forEach(function(file) {
|
||||||
pushHash(file, p);
|
if (!pushFile(file, p))
|
||||||
|
return;
|
||||||
|
|
||||||
// Recursive
|
// Recursive?
|
||||||
var oldDir = _pwd();
|
if (options.recursive) {
|
||||||
_cd('', p);
|
var oldDir = _pwd();
|
||||||
if (fs.statSync(file).isDirectory() && options.recursive)
|
_cd('', p);
|
||||||
hash = extend(hash, _ls('-R', file+'/*'));
|
if (fs.statSync(file).isDirectory())
|
||||||
_cd('', oldDir);
|
list = list.concat(_ls('-R'+(options.all?'a':''), file+'/*'));
|
||||||
|
_cd('', oldDir);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return; // continue
|
return; // continue
|
||||||
}
|
}
|
||||||
@ -137,17 +144,20 @@ function _ls(options, paths) {
|
|||||||
// Escape special regular expression chars
|
// Escape special regular expression chars
|
||||||
var regexp = basename.replace(/(\^|\$|\(|\)|\<|\>|\[|\]|\{|\}|\.|\+|\?)/g, '\\$1');
|
var regexp = basename.replace(/(\^|\$|\(|\)|\<|\>|\[|\]|\{|\}|\.|\+|\?)/g, '\\$1');
|
||||||
// Translates wildcard into regex
|
// Translates wildcard into regex
|
||||||
regexp = '^' + regexp.replace(/\*/g, '.*');
|
regexp = '^' + regexp.replace(/\*/g, '.*') + '$';
|
||||||
// Iterate over directory contents
|
// Iterate over directory contents
|
||||||
fs.readdirSync(dirname).forEach(function(file) {
|
fs.readdirSync(dirname).forEach(function(file) {
|
||||||
if (file.match(new RegExp(regexp))) {
|
if (file.match(new RegExp(regexp))) {
|
||||||
pushHash(path.normalize(dirname+'/'+file), basename);
|
if (!pushFile(path.normalize(dirname+'/'+file), basename))
|
||||||
|
return;
|
||||||
|
|
||||||
// Recursive
|
// Recursive?
|
||||||
var pp = dirname + '/' + file;
|
if (options.recursive) {
|
||||||
if (fs.statSync(pp).isDirectory() && options.recursive)
|
var pp = dirname + '/' + file;
|
||||||
hash = extend(hash, _ls('-R', pp+'/*'));
|
if (fs.statSync(pp).isDirectory())
|
||||||
}
|
list = list.concat(_ls('-R'+(options.all?'a':''), pp+'/*'));
|
||||||
|
} // recursive
|
||||||
|
} // if file matches
|
||||||
}); // forEach
|
}); // forEach
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -155,7 +165,7 @@ function _ls(options, paths) {
|
|||||||
error('no such file or directory: ' + p, true);
|
error('no such file or directory: ' + p, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
return hash;
|
return list;
|
||||||
};
|
};
|
||||||
exports.ls = wrap('ls', _ls);
|
exports.ls = wrap('ls', _ls);
|
||||||
|
|
||||||
@ -168,16 +178,10 @@ exports.ls = wrap('ls', _ls);
|
|||||||
//@ ```javascript
|
//@ ```javascript
|
||||||
//@ find('src', 'lib');
|
//@ find('src', 'lib');
|
||||||
//@ find(['src', 'lib']); // same as above
|
//@ find(['src', 'lib']); // same as above
|
||||||
//@ for (file in find('.')) {
|
//@ find('.').filter(function(file) { return file.match(/\.js$/); });
|
||||||
//@ if (!file.match(/\.js$/))
|
|
||||||
//@ continue;
|
|
||||||
//@ // all files at this point end in '.js'
|
|
||||||
//@ }
|
|
||||||
//@ ```
|
//@ ```
|
||||||
//@
|
//@
|
||||||
//@ Returns list of all files (however deep) in the given paths. For convenient iteration
|
//@ Returns array of all files (however deep) in the given paths.
|
||||||
//@ via `for (file in find(...))`, the format returned is a hash object:
|
|
||||||
//@ `{ 'file1':null, 'dir1/file2':null, ...}`.
|
|
||||||
//@
|
//@
|
||||||
//@ The main difference from `ls('-R', path)` is that the resulting file names
|
//@ The main difference from `ls('-R', path)` is that the resulting file names
|
||||||
//@ include the base directories, e.g. `lib/resources/file1` instead of just `file1`.
|
//@ include the base directories, e.g. `lib/resources/file1` instead of just `file1`.
|
||||||
@ -189,21 +193,28 @@ function _find(options, paths) {
|
|||||||
else if (typeof paths === 'string')
|
else if (typeof paths === 'string')
|
||||||
paths = [].slice.call(arguments, 1);
|
paths = [].slice.call(arguments, 1);
|
||||||
|
|
||||||
var hash = {};
|
var list = [];
|
||||||
|
|
||||||
|
function pushFile(file) {
|
||||||
|
if (platform === 'win')
|
||||||
|
file = file.replace(/\\/g, '/');
|
||||||
|
list.push(file);
|
||||||
|
}
|
||||||
|
|
||||||
// why not simply do ls('-R', paths)? because the output wouldn't give the base dirs
|
// why not simply do ls('-R', paths)? because the output wouldn't give the base dirs
|
||||||
// to get the base dir in the output, we need instead ls('-R', 'dir/*') for every directory
|
// to get the base dir in the output, we need instead ls('-R', 'dir/*') for every directory
|
||||||
|
|
||||||
paths.forEach(function(file){
|
paths.forEach(function(file) {
|
||||||
hash[file] = null;
|
pushFile(file);
|
||||||
|
|
||||||
if (fs.statSync(file).isDirectory()) {
|
if (fs.statSync(file).isDirectory()) {
|
||||||
for (subfile in _ls('-Ra', file+'/*'))
|
_ls('-Ra', file+'/*').forEach(function(subfile) {
|
||||||
hash[subfile] = null;
|
pushFile(subfile);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return hash;
|
return list;
|
||||||
}
|
}
|
||||||
exports.find = wrap('find', _find);
|
exports.find = wrap('find', _find);
|
||||||
|
|
||||||
@ -347,9 +358,20 @@ function _rm(options, files) {
|
|||||||
|
|
||||||
// Remove simple file
|
// Remove simple file
|
||||||
if (fs.statSync(file).isFile()) {
|
if (fs.statSync(file).isFile()) {
|
||||||
fs.unlinkSync(file);
|
|
||||||
|
// Do not check for file writing permissions
|
||||||
|
if (options.force) {
|
||||||
|
_unlinkSync(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isWriteable(file))
|
||||||
|
_unlinkSync(file);
|
||||||
|
else
|
||||||
|
error('permission denied: '+file, true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} // simple file
|
||||||
|
|
||||||
// Path is an existing directory, but no -r flag given
|
// Path is an existing directory, but no -r flag given
|
||||||
if (fs.statSync(file).isDirectory() && !options.recursive) {
|
if (fs.statSync(file).isDirectory() && !options.recursive) {
|
||||||
@ -359,7 +381,7 @@ function _rm(options, files) {
|
|||||||
|
|
||||||
// Recursively remove existing directory
|
// Recursively remove existing directory
|
||||||
if (fs.statSync(file).isDirectory() && options.recursive) {
|
if (fs.statSync(file).isDirectory() && options.recursive) {
|
||||||
rmdirSyncRecursive(file);
|
rmdirSyncRecursive(file, options.force);
|
||||||
}
|
}
|
||||||
}); // forEach(file)
|
}); // forEach(file)
|
||||||
}; // rm
|
}; // rm
|
||||||
@ -582,7 +604,11 @@ function _to(options, file) {
|
|||||||
if (!fs.existsSync( path.dirname(file) ))
|
if (!fs.existsSync( path.dirname(file) ))
|
||||||
error('no such file or directory: ' + path.dirname(file));
|
error('no such file or directory: ' + path.dirname(file));
|
||||||
|
|
||||||
fs.writeFileSync(file, this.toString(), 'utf8');
|
try {
|
||||||
|
fs.writeFileSync(file, this.toString(), 'utf8');
|
||||||
|
} catch(e) {
|
||||||
|
error('could not write to file (code '+e.code+'): '+file, true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
// In the future, when Proxies are default, we can add methods like `.to()` to primitive strings.
|
// In the future, when Proxies are default, we can add methods like `.to()` to primitive strings.
|
||||||
// For now, this is a dummy function to bookmark places we need such strings
|
// For now, this is a dummy function to bookmark places we need such strings
|
||||||
@ -751,7 +777,7 @@ exports.which = wrap('which', _which);
|
|||||||
//@ like `.to()`.
|
//@ like `.to()`.
|
||||||
function _echo(options) {
|
function _echo(options) {
|
||||||
var messages = [].slice.call(arguments, 1);
|
var messages = [].slice.call(arguments, 1);
|
||||||
log.apply(this, messages);
|
console.log.apply(this, messages);
|
||||||
return ShellString(messages.join(' '));
|
return ShellString(messages.join(' '));
|
||||||
};
|
};
|
||||||
exports.echo = wrap('echo', _echo);
|
exports.echo = wrap('echo', _echo);
|
||||||
@ -783,6 +809,10 @@ exports.env = process.env;
|
|||||||
//@ When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's
|
//@ When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's
|
||||||
//@ `output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the
|
//@ `output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the
|
||||||
//@ arguments `(code, output)`.
|
//@ arguments `(code, output)`.
|
||||||
|
//@
|
||||||
|
//@ **Note:** For long-lived processes, it's best to run `exec()` asynchronously as
|
||||||
|
//@ the current synchronous implementation uses a lot of CPU. This should be getting
|
||||||
|
//@ fixed soon.
|
||||||
function _exec(command, options, callback) {
|
function _exec(command, options, callback) {
|
||||||
if (!command)
|
if (!command)
|
||||||
error('must specify command');
|
error('must specify command');
|
||||||
@ -793,7 +823,7 @@ function _exec(command, options, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
options = extend({
|
options = extend({
|
||||||
silent: false,
|
silent: state.silent,
|
||||||
async: false
|
async: false
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
@ -822,11 +852,53 @@ exports.exec = wrap('exec', _exec, {notUnix:true});
|
|||||||
//@ Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
|
//@ Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
|
||||||
exports.tempdir = wrap('tempdir', tempDir);
|
exports.tempdir = wrap('tempdir', tempDir);
|
||||||
|
|
||||||
|
|
||||||
|
//@
|
||||||
|
//@ #### error()
|
||||||
|
//@ Tests if error occurred in the last command. Returns `null` if no error occurred,
|
||||||
|
//@ otherwise returns string explaining the error
|
||||||
|
exports.error = function() {
|
||||||
|
return state.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
//@
|
||||||
|
//@ #### silent([state])
|
||||||
|
//@ Example:
|
||||||
|
//@
|
||||||
|
//@ ```javascript
|
||||||
|
//@ var silentState = silent();
|
||||||
|
//@ silent(true);
|
||||||
|
//@ /* ... */
|
||||||
|
//@ silent(silentState); // restore old silent state
|
||||||
|
//@ ```
|
||||||
|
//@
|
||||||
|
//@ Suppresses all command output if `state = true`, except for `echo()` calls.
|
||||||
|
//@ Returns state if no arguments given.
|
||||||
|
exports.silent = function(_state) {
|
||||||
|
if (typeof _state !== 'boolean')
|
||||||
|
return state.silent;
|
||||||
|
|
||||||
|
state.silent = _state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//@
|
||||||
|
//@ ## Deprecated
|
||||||
|
//@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//@
|
//@
|
||||||
//@ #### exists(path [, path ...])
|
//@ #### exists(path [, path ...])
|
||||||
//@ #### exists(path_array)
|
//@ #### exists(path_array)
|
||||||
|
//@
|
||||||
|
//@ _This function is being deprecated. Use `test()` instead._
|
||||||
|
//@
|
||||||
//@ Returns true if all the given paths exist.
|
//@ Returns true if all the given paths exist.
|
||||||
function _exists(options, paths) {
|
function _exists(options, paths) {
|
||||||
|
deprecate('exists', 'Use test() instead.');
|
||||||
|
|
||||||
if (!paths)
|
if (!paths)
|
||||||
error('no paths given');
|
error('no paths given');
|
||||||
|
|
||||||
@ -844,32 +916,19 @@ function _exists(options, paths) {
|
|||||||
};
|
};
|
||||||
exports.exists = wrap('exists', _exists);
|
exports.exists = wrap('exists', _exists);
|
||||||
|
|
||||||
//@
|
|
||||||
//@ #### error()
|
|
||||||
//@ Tests if error occurred in the last command. Returns `null` if no error occurred,
|
|
||||||
//@ otherwise returns string explaining the error
|
|
||||||
exports.error = function() {
|
|
||||||
return state.error;
|
|
||||||
}
|
|
||||||
|
|
||||||
//@
|
//@
|
||||||
//@ #### verbose()
|
//@ #### verbose()
|
||||||
|
//@
|
||||||
|
//@ _This function is being deprecated. Use `silent(false) instead.`_
|
||||||
|
//@
|
||||||
//@ Enables all output (default)
|
//@ Enables all output (default)
|
||||||
exports.verbose = function() {
|
exports.verbose = function() {
|
||||||
|
deprecate('verbose', 'Use silent(false) instead.');
|
||||||
|
|
||||||
state.silent = false;
|
state.silent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//@
|
|
||||||
//@ #### silent()
|
|
||||||
//@ Suppresses all output, except for explict `echo()` calls
|
|
||||||
exports.silent = function() {
|
|
||||||
state.silent = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -889,6 +948,10 @@ function log() {
|
|||||||
console.log.apply(this, arguments);
|
console.log.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deprecate(what, msg) {
|
||||||
|
console.log('*** ShellJS.'+what+': This function is deprecated.', msg);
|
||||||
|
}
|
||||||
|
|
||||||
function write(msg) {
|
function write(msg) {
|
||||||
if (!state.silent)
|
if (!state.silent)
|
||||||
process.stdout.write(msg);
|
process.stdout.write(msg);
|
||||||
@ -962,7 +1025,7 @@ function wrap(cmd, fn, options) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!state.error) {
|
if (!state.error) {
|
||||||
// If state.error hasn't been set it's an error thrown by Node, not us - probably a bug...
|
// If state.error hasn't been set it's an error thrown by Node, not us - probably a bug...
|
||||||
console.log('maker.js: internal error');
|
console.log('shell.js: internal error');
|
||||||
console.log(e.stack || e);
|
console.log(e.stack || e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@ -970,7 +1033,7 @@ function wrap(cmd, fn, options) {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.currentCmd = 'maker.js';
|
state.currentCmd = 'shell.js';
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
} // wrap
|
} // wrap
|
||||||
@ -984,10 +1047,22 @@ function copyFileSync(srcFile, destFile) {
|
|||||||
|
|
||||||
var BUF_LENGTH = 64*1024,
|
var BUF_LENGTH = 64*1024,
|
||||||
buf = new Buffer(BUF_LENGTH),
|
buf = new Buffer(BUF_LENGTH),
|
||||||
fdr = fs.openSync(srcFile, 'r'),
|
|
||||||
fdw = fs.openSync(destFile, 'w'),
|
|
||||||
bytesRead = BUF_LENGTH,
|
bytesRead = BUF_LENGTH,
|
||||||
pos = 0;
|
pos = 0,
|
||||||
|
fdr = null,
|
||||||
|
fdw = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fdr = fs.openSync(srcFile, 'r');
|
||||||
|
} catch(e) {
|
||||||
|
error('copyFileSync: could not read src file ('+srcFile+')');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
fdw = fs.openSync(destFile, 'w');
|
||||||
|
} catch(e) {
|
||||||
|
error('copyFileSync: could not write to dest file (code='+e.code+'):'+destFile);
|
||||||
|
}
|
||||||
|
|
||||||
while (bytesRead === BUF_LENGTH) {
|
while (bytesRead === BUF_LENGTH) {
|
||||||
bytesRead = fs.readSync(fdr, buf, 0, BUF_LENGTH, pos);
|
bytesRead = fs.readSync(fdr, buf, 0, BUF_LENGTH, pos);
|
||||||
@ -1050,28 +1125,41 @@ function cpdirSyncRecursive(sourceDir, destDir, opts) {
|
|||||||
//
|
//
|
||||||
// Licensed under the MIT License
|
// Licensed under the MIT License
|
||||||
// http://www.opensource.org/licenses/mit-license.php
|
// http://www.opensource.org/licenses/mit-license.php
|
||||||
function rmdirSyncRecursive(dir) {
|
function rmdirSyncRecursive(dir, force) {
|
||||||
var files;
|
var files;
|
||||||
|
|
||||||
files = fs.readdirSync(dir);
|
files = fs.readdirSync(dir);
|
||||||
|
|
||||||
// Loop through and delete everything in the sub-tree after checking it
|
// Loop through and delete everything in the sub-tree after checking it
|
||||||
for(var i = 0; i < files.length; i++) {
|
for(var i = 0; i < files.length; i++) {
|
||||||
var currFile = fs.lstatSync(dir + "/" + files[i]);
|
var file = dir + "/" + files[i],
|
||||||
|
currFile = fs.lstatSync(file);
|
||||||
|
|
||||||
if(currFile.isDirectory()) // Recursive function back to the beginning
|
if(currFile.isDirectory()) { // Recursive function back to the beginning
|
||||||
rmdirSyncRecursive(dir + "/" + files[i]);
|
rmdirSyncRecursive(file, force);
|
||||||
|
}
|
||||||
|
|
||||||
else if(currFile.isSymbolicLink()) // Unlink symlinks
|
else if(currFile.isSymbolicLink()) { // Unlink symlinks
|
||||||
fs.unlinkSync(dir + "/" + files[i]);
|
if (force || isWriteable(file))
|
||||||
|
_unlinkSync(file);
|
||||||
|
}
|
||||||
|
|
||||||
else // Assume it's a file - perhaps a try/catch belongs here?
|
else // Assume it's a file - perhaps a try/catch belongs here?
|
||||||
fs.unlinkSync(dir + "/" + files[i]);
|
if (force || isWriteable(file))
|
||||||
|
_unlinkSync(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know everything in the sub-tree has been deleted, we can delete the main directory.
|
// Now that we know everything in the sub-tree has been deleted, we can delete the main directory.
|
||||||
// Huzzah for the shopkeep.
|
// Huzzah for the shopkeep.
|
||||||
return fs.rmdirSync(dir);
|
|
||||||
|
var result;
|
||||||
|
try {
|
||||||
|
result = fs.rmdirSync(dir);
|
||||||
|
} catch(e) {
|
||||||
|
error('could not remove directory (code '+e.code+'): ' + dir, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}; // rmdirSyncRecursive
|
}; // rmdirSyncRecursive
|
||||||
|
|
||||||
// Recursively creates 'dir'
|
// Recursively creates 'dir'
|
||||||
@ -1118,7 +1206,7 @@ function writeableDir(dir) {
|
|||||||
var testFile = dir+'/'+randomFileName();
|
var testFile = dir+'/'+randomFileName();
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(testFile, ' ');
|
fs.writeFileSync(testFile, ' ');
|
||||||
fs.unlinkSync(testFile);
|
_unlinkSync(testFile);
|
||||||
return dir;
|
return dir;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
@ -1151,6 +1239,10 @@ function tempDir() {
|
|||||||
// Wrapper around exec() to enable echoing output to console in real time
|
// Wrapper around exec() to enable echoing output to console in real time
|
||||||
function execAsync(cmd, opts, callback) {
|
function execAsync(cmd, opts, callback) {
|
||||||
var output = '';
|
var output = '';
|
||||||
|
|
||||||
|
var options = extend({
|
||||||
|
silent: state.silent
|
||||||
|
}, opts);
|
||||||
|
|
||||||
var c = child.exec(cmd, {env: process.env}, function(err) {
|
var c = child.exec(cmd, {env: process.env}, function(err) {
|
||||||
if (callback)
|
if (callback)
|
||||||
@ -1159,14 +1251,14 @@ function execAsync(cmd, opts, callback) {
|
|||||||
|
|
||||||
c.stdout.on('data', function(data) {
|
c.stdout.on('data', function(data) {
|
||||||
output += data;
|
output += data;
|
||||||
if (!opts.silent)
|
if (!options.silent)
|
||||||
write(data);
|
process.stdout.write(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
c.stderr.on('data', function(data) {
|
c.stderr.on('data', function(data) {
|
||||||
output += data;
|
output += data;
|
||||||
if (!opts.silent)
|
if (!options.silent)
|
||||||
write(data);
|
process.stdout.write(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1178,16 +1270,17 @@ function execAsync(cmd, opts, callback) {
|
|||||||
function execSync(cmd, opts) {
|
function execSync(cmd, opts) {
|
||||||
var stdoutFile = path.resolve(tempDir()+'/'+randomFileName()),
|
var stdoutFile = path.resolve(tempDir()+'/'+randomFileName()),
|
||||||
codeFile = path.resolve(tempDir()+'/'+randomFileName()),
|
codeFile = path.resolve(tempDir()+'/'+randomFileName()),
|
||||||
scriptFile = path.resolve(tempDir()+'/'+randomFileName());
|
scriptFile = path.resolve(tempDir()+'/'+randomFileName()),
|
||||||
|
sleepFile = path.resolve(tempDir()+'/'+randomFileName());
|
||||||
|
|
||||||
var options = extend({
|
var options = extend({
|
||||||
silent: false
|
silent: state.silent
|
||||||
}, opts);
|
}, opts);
|
||||||
|
|
||||||
var previousStdoutContent = '';
|
var previousStdoutContent = '';
|
||||||
// Echoes stdout changes from running process, if not silent
|
// Echoes stdout changes from running process, if not silent
|
||||||
function updateStdout() {
|
function updateStdout() {
|
||||||
if (state.silent || options.silent || !fs.existsSync(stdoutFile))
|
if (options.silent || !fs.existsSync(stdoutFile))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var stdoutContent = fs.readFileSync(stdoutFile, 'utf8');
|
var stdoutContent = fs.readFileSync(stdoutFile, 'utf8');
|
||||||
@ -1214,9 +1307,9 @@ function execSync(cmd, opts) {
|
|||||||
fs.writeFileSync('"+escape(codeFile)+"', err ? err.code.toString() : '0'); \
|
fs.writeFileSync('"+escape(codeFile)+"', err ? err.code.toString() : '0'); \
|
||||||
});";
|
});";
|
||||||
|
|
||||||
if (fs.existsSync(scriptFile)) fs.unlinkSync(scriptFile);
|
if (fs.existsSync(scriptFile)) _unlinkSync(scriptFile);
|
||||||
if (fs.existsSync(stdoutFile)) fs.unlinkSync(stdoutFile);
|
if (fs.existsSync(stdoutFile)) _unlinkSync(stdoutFile);
|
||||||
if (fs.existsSync(codeFile)) fs.unlinkSync(codeFile);
|
if (fs.existsSync(codeFile)) _unlinkSync(codeFile);
|
||||||
|
|
||||||
fs.writeFileSync(scriptFile, script);
|
fs.writeFileSync(scriptFile, script);
|
||||||
child.exec('node '+scriptFile, {
|
child.exec('node '+scriptFile, {
|
||||||
@ -1225,8 +1318,11 @@ function execSync(cmd, opts) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// The wait loop
|
// The wait loop
|
||||||
while (!fs.existsSync(codeFile)) { updateStdout(); };
|
// sleepFile is used as a dummy I/O op to mitigate unnecessary CPU usage
|
||||||
while (!fs.existsSync(stdoutFile)) { updateStdout(); };
|
// (tried many I/O sync ops, writeFileSync() seems to be only one that is effective in reducing
|
||||||
|
// CPU usage, though apparently not so much on Windows)
|
||||||
|
while (!fs.existsSync(codeFile)) { updateStdout(); fs.writeFileSync(sleepFile, 'a'); };
|
||||||
|
while (!fs.existsSync(stdoutFile)) { updateStdout(); fs.writeFileSync(sleepFile, 'a'); };
|
||||||
|
|
||||||
// At this point codeFile exists, but it's not necessarily flushed yet.
|
// At this point codeFile exists, but it's not necessarily flushed yet.
|
||||||
// Keep reading it until it is.
|
// Keep reading it until it is.
|
||||||
@ -1236,10 +1332,12 @@ function execSync(cmd, opts) {
|
|||||||
|
|
||||||
var stdout = fs.readFileSync(stdoutFile, 'utf8');
|
var stdout = fs.readFileSync(stdoutFile, 'utf8');
|
||||||
|
|
||||||
fs.unlinkSync(scriptFile);
|
// No biggie if we can't erase the files now -- they're in a temp dir anyway
|
||||||
fs.unlinkSync(stdoutFile);
|
try { _unlinkSync(scriptFile); } catch(e) {};
|
||||||
fs.unlinkSync(codeFile);
|
try { _unlinkSync(stdoutFile); } catch(e) {};
|
||||||
|
try { _unlinkSync(codeFile); } catch(e) {};
|
||||||
|
try { _unlinkSync(sleepFile); } catch(e) {};
|
||||||
|
|
||||||
// True if successful, false if not
|
// True if successful, false if not
|
||||||
var obj = {
|
var obj = {
|
||||||
code: code,
|
code: code,
|
||||||
@ -1257,8 +1355,9 @@ function expand(list) {
|
|||||||
list.forEach(function(listEl) {
|
list.forEach(function(listEl) {
|
||||||
// Wildcard present?
|
// Wildcard present?
|
||||||
if (listEl.search(/\*/) > -1) {
|
if (listEl.search(/\*/) > -1) {
|
||||||
for (file in _ls('', listEl))
|
_ls('', listEl).forEach(function(file) {
|
||||||
expanded.push(file);
|
expanded.push(file);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
expanded.push(listEl);
|
expanded.push(listEl);
|
||||||
}
|
}
|
||||||
@ -1290,3 +1389,33 @@ function extend(target) {
|
|||||||
|
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalizes _unlinkSync() across platforms to match Unix behavior, i.e.
|
||||||
|
// file can be unlinked even if it's read-only, see joyent/node#3006
|
||||||
|
function _unlinkSync(file) {
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(file);
|
||||||
|
} catch(e) {
|
||||||
|
// Try to override file permission
|
||||||
|
if (e.code === 'EPERM') {
|
||||||
|
fs.chmodSync(file, '0666');
|
||||||
|
fs.unlinkSync(file);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hack to determine if file has write permissions for current user
|
||||||
|
// Avoids having to check user, group, etc, but it's probably slow
|
||||||
|
function isWriteable(file) {
|
||||||
|
var writePermission = true;
|
||||||
|
try {
|
||||||
|
var __fd = fs.openSync(file, 'a');
|
||||||
|
fs.closeSync(__fd);
|
||||||
|
} catch(e) {
|
||||||
|
writePermission = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return writePermission;
|
||||||
|
}
|
||||||
|
61
make.js
61
make.js
@ -97,9 +97,10 @@ target.bundle = function() {
|
|||||||
'worker.js',
|
'worker.js',
|
||||||
'../external/jpgjs/jpg.js',
|
'../external/jpgjs/jpg.js',
|
||||||
'jpx.js',
|
'jpx.js',
|
||||||
'bidi.js'];
|
'bidi.js',
|
||||||
|
'metadata.js'];
|
||||||
|
|
||||||
if (!exists(BUILD_DIR))
|
if (!test('-d', BUILD_DIR))
|
||||||
mkdir(BUILD_DIR);
|
mkdir(BUILD_DIR);
|
||||||
|
|
||||||
cd('src');
|
cd('src');
|
||||||
@ -142,10 +143,10 @@ target.pagesrepo = function() {
|
|||||||
echo();
|
echo();
|
||||||
echo('### Creating fresh clone of gh-pages');
|
echo('### Creating fresh clone of gh-pages');
|
||||||
|
|
||||||
if (!exists(BUILD_DIR))
|
if (!test('-d', BUILD_DIR))
|
||||||
mkdir(BUILD_DIR);
|
mkdir(BUILD_DIR);
|
||||||
|
|
||||||
if (!exists(GH_PAGES_DIR)) {
|
if (!test('-d', GH_PAGES_DIR)) {
|
||||||
echo();
|
echo();
|
||||||
echo('Cloning project repo...');
|
echo('Cloning project repo...');
|
||||||
echo('(This operation can take a while, depending on network conditions)');
|
echo('(This operation can take a while, depending on network conditions)');
|
||||||
@ -277,10 +278,10 @@ target.firefox = function() {
|
|||||||
// We don't need pdf.js anymore since its inlined
|
// We don't need pdf.js anymore since its inlined
|
||||||
rm('-Rf', FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR);
|
rm('-Rf', FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR);
|
||||||
// Remove '.DS_Store' and other hidden files
|
// Remove '.DS_Store' and other hidden files
|
||||||
for (file in find(FIREFOX_BUILD_DIR)) {
|
find(FIREFOX_BUILD_DIR).forEach(function(file) {
|
||||||
if (file.match(/^\./))
|
if (file.match(/^\./))
|
||||||
rm('-f', file);
|
rm('-f', file);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Update the build version number
|
// Update the build version number
|
||||||
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION, FIREFOX_BUILD_DIR + '/install.rdf');
|
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION, FIREFOX_BUILD_DIR + '/install.rdf');
|
||||||
@ -304,10 +305,10 @@ target.firefox = function() {
|
|||||||
// List all files for mozilla-central
|
// List all files for mozilla-central
|
||||||
cd(FIREFOX_BUILD_DIR);
|
cd(FIREFOX_BUILD_DIR);
|
||||||
var extensionFiles = '';
|
var extensionFiles = '';
|
||||||
for (file in find(FIREFOX_MC_EXTENSION_FILES)) {
|
find(FIREFOX_MC_EXTENSION_FILES).forEach(function(file){
|
||||||
if (test('-f', file))
|
if (test('-f', file))
|
||||||
extensionFiles += file+'\n';
|
extensionFiles += file+'\n';
|
||||||
}
|
});
|
||||||
extensionFiles.to('extension-files');
|
extensionFiles.to('extension-files');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -360,10 +361,19 @@ target.test = function() {
|
|||||||
target.unittest();
|
target.unittest();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// make bottest
|
||||||
|
// (Special tests for the Github bot)
|
||||||
|
//
|
||||||
|
target.bottest = function() {
|
||||||
|
target.browsertest({noreftest: true});
|
||||||
|
// target.unittest();
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// make browsertest
|
// make browsertest
|
||||||
//
|
//
|
||||||
target.browsertest = function() {
|
target.browsertest = function(options) {
|
||||||
cd(ROOT_DIR);
|
cd(ROOT_DIR);
|
||||||
echo();
|
echo();
|
||||||
echo('### Running browser tests');
|
echo('### Running browser tests');
|
||||||
@ -371,14 +381,16 @@ target.browsertest = function() {
|
|||||||
var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json',
|
var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json',
|
||||||
PDF_BROWSERS = env['PDF_BROWSERS'] || 'resources/browser_manifests/browser_manifest.json';
|
PDF_BROWSERS = env['PDF_BROWSERS'] || 'resources/browser_manifests/browser_manifest.json';
|
||||||
|
|
||||||
if (!exists('test/' + PDF_BROWSERS)) {
|
if (!test('-f', 'test/' + PDF_BROWSERS)) {
|
||||||
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
|
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
|
||||||
echo('Try copying one of the examples in test/resources/browser_manifests/');
|
echo('Try copying one of the examples in test/resources/browser_manifests/');
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var reftest = (options && options.noreftest) ? '' : '--reftest';
|
||||||
|
|
||||||
cd('test');
|
cd('test');
|
||||||
exec(PYTHON_BIN + ' test.py --reftest --browserManifestFile=' + PDF_BROWSERS +
|
exec(PYTHON_BIN + ' -u test.py '+reftest+' --browserManifestFile=' + PDF_BROWSERS +
|
||||||
' --manifestFile=' + PDF_TEST, {async: true});
|
' --manifestFile=' + PDF_TEST, {async: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -390,10 +402,37 @@ target.unittest = function() {
|
|||||||
echo();
|
echo();
|
||||||
echo('### Running unit tests');
|
echo('### Running unit tests');
|
||||||
|
|
||||||
|
if (!which('make')) {
|
||||||
|
echo('make not found. Skipping unit tests...');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cd('test/unit');
|
cd('test/unit');
|
||||||
exec('make', {async: true});
|
exec('make', {async: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// make botmakeref
|
||||||
|
//
|
||||||
|
target.botmakeref = function() {
|
||||||
|
cd(ROOT_DIR);
|
||||||
|
echo();
|
||||||
|
echo('### Creating reference images');
|
||||||
|
|
||||||
|
var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json',
|
||||||
|
PDF_BROWSERS = env['PDF_BROWSERS'] || 'resources/browser_manifests/browser_manifest.json';
|
||||||
|
|
||||||
|
if (!test('-f', 'test/' + PDF_BROWSERS)) {
|
||||||
|
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
|
||||||
|
echo('Try copying one of the examples in test/resources/browser_manifests/');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cd('test');
|
||||||
|
exec(PYTHON_BIN + ' -u test.py --masterMode --noPrompts --browserManifestFile=' + PDF_BROWSERS,
|
||||||
|
{async: true});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
318
src/canvas.js
318
src/canvas.js
@ -20,56 +20,6 @@ var TextRenderingMode = {
|
|||||||
// Minimal font size that would be used during canvas fillText operations.
|
// Minimal font size that would be used during canvas fillText operations.
|
||||||
var MIN_FONT_SIZE = 1;
|
var MIN_FONT_SIZE = 1;
|
||||||
|
|
||||||
var CanvasExtraState = (function CanvasExtraStateClosure() {
|
|
||||||
function CanvasExtraState(old) {
|
|
||||||
// Are soft masks and alpha values shapes or opacities?
|
|
||||||
this.alphaIsShape = false;
|
|
||||||
this.fontSize = 0;
|
|
||||||
this.fontSizeScale = 1;
|
|
||||||
this.textMatrix = IDENTITY_MATRIX;
|
|
||||||
this.fontMatrix = IDENTITY_MATRIX;
|
|
||||||
this.leading = 0;
|
|
||||||
// Current point (in user coordinates)
|
|
||||||
this.x = 0;
|
|
||||||
this.y = 0;
|
|
||||||
// Start of text line (in text coordinates)
|
|
||||||
this.lineX = 0;
|
|
||||||
this.lineY = 0;
|
|
||||||
// Character and word spacing
|
|
||||||
this.charSpacing = 0;
|
|
||||||
this.wordSpacing = 0;
|
|
||||||
this.textHScale = 1;
|
|
||||||
this.textRenderingMode = TextRenderingMode.FILL;
|
|
||||||
// Color spaces
|
|
||||||
this.fillColorSpace = new DeviceGrayCS();
|
|
||||||
this.fillColorSpaceObj = null;
|
|
||||||
this.strokeColorSpace = new DeviceGrayCS();
|
|
||||||
this.strokeColorSpaceObj = null;
|
|
||||||
this.fillColorObj = null;
|
|
||||||
this.strokeColorObj = null;
|
|
||||||
// Default fore and background colors
|
|
||||||
this.fillColor = '#000000';
|
|
||||||
this.strokeColor = '#000000';
|
|
||||||
// Note: fill alpha applies to all non-stroking operations
|
|
||||||
this.fillAlpha = 1;
|
|
||||||
this.strokeAlpha = 1;
|
|
||||||
this.lineWidth = 1;
|
|
||||||
|
|
||||||
this.old = old;
|
|
||||||
}
|
|
||||||
|
|
||||||
CanvasExtraState.prototype = {
|
|
||||||
clone: function canvasextra_clone() {
|
|
||||||
return Object.create(this);
|
|
||||||
},
|
|
||||||
setCurrentPoint: function canvasextra_setCurrentPoint(x, y) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return CanvasExtraState;
|
|
||||||
})();
|
|
||||||
|
|
||||||
function createScratchCanvas(width, height) {
|
function createScratchCanvas(width, height) {
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
canvas.width = width;
|
canvas.width = width;
|
||||||
@ -187,6 +137,56 @@ function addContextCurrentTransform(ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var CanvasExtraState = (function CanvasExtraStateClosure() {
|
||||||
|
function CanvasExtraState(old) {
|
||||||
|
// Are soft masks and alpha values shapes or opacities?
|
||||||
|
this.alphaIsShape = false;
|
||||||
|
this.fontSize = 0;
|
||||||
|
this.fontSizeScale = 1;
|
||||||
|
this.textMatrix = IDENTITY_MATRIX;
|
||||||
|
this.fontMatrix = IDENTITY_MATRIX;
|
||||||
|
this.leading = 0;
|
||||||
|
// Current point (in user coordinates)
|
||||||
|
this.x = 0;
|
||||||
|
this.y = 0;
|
||||||
|
// Start of text line (in text coordinates)
|
||||||
|
this.lineX = 0;
|
||||||
|
this.lineY = 0;
|
||||||
|
// Character and word spacing
|
||||||
|
this.charSpacing = 0;
|
||||||
|
this.wordSpacing = 0;
|
||||||
|
this.textHScale = 1;
|
||||||
|
this.textRenderingMode = TextRenderingMode.FILL;
|
||||||
|
// Color spaces
|
||||||
|
this.fillColorSpace = new DeviceGrayCS();
|
||||||
|
this.fillColorSpaceObj = null;
|
||||||
|
this.strokeColorSpace = new DeviceGrayCS();
|
||||||
|
this.strokeColorSpaceObj = null;
|
||||||
|
this.fillColorObj = null;
|
||||||
|
this.strokeColorObj = null;
|
||||||
|
// Default fore and background colors
|
||||||
|
this.fillColor = '#000000';
|
||||||
|
this.strokeColor = '#000000';
|
||||||
|
// Note: fill alpha applies to all non-stroking operations
|
||||||
|
this.fillAlpha = 1;
|
||||||
|
this.strokeAlpha = 1;
|
||||||
|
this.lineWidth = 1;
|
||||||
|
|
||||||
|
this.old = old;
|
||||||
|
}
|
||||||
|
|
||||||
|
CanvasExtraState.prototype = {
|
||||||
|
clone: function CanvasExtraState_clone() {
|
||||||
|
return Object.create(this);
|
||||||
|
},
|
||||||
|
setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return CanvasExtraState;
|
||||||
|
})();
|
||||||
|
|
||||||
var CanvasGraphics = (function CanvasGraphicsClosure() {
|
var CanvasGraphics = (function CanvasGraphicsClosure() {
|
||||||
// Defines the time the executeOperatorList is going to be executing
|
// Defines the time the executeOperatorList is going to be executing
|
||||||
// before it stops and shedules a continue of execution.
|
// before it stops and shedules a continue of execution.
|
||||||
@ -241,7 +241,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
'shadingFill': true
|
'shadingFill': true
|
||||||
},
|
},
|
||||||
|
|
||||||
beginDrawing: function canvasGraphicsBeginDrawing(mediaBox) {
|
beginDrawing: function CanvasGraphics_beginDrawing(mediaBox) {
|
||||||
var cw = this.ctx.canvas.width, ch = this.ctx.canvas.height;
|
var cw = this.ctx.canvas.width, ch = this.ctx.canvas.height;
|
||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
switch (mediaBox.rotate) {
|
switch (mediaBox.rotate) {
|
||||||
@ -267,7 +267,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.textLayer.beginLayout();
|
this.textLayer.beginLayout();
|
||||||
},
|
},
|
||||||
|
|
||||||
executeOperatorList: function canvasGraphicsExecuteOperatorList(
|
executeOperatorList: function CanvasGraphics_executeOperatorList(
|
||||||
operatorList,
|
operatorList,
|
||||||
executionStartIdx, continueCallback,
|
executionStartIdx, continueCallback,
|
||||||
stepper) {
|
stepper) {
|
||||||
@ -332,7 +332,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
endDrawing: function canvasGraphicsEndDrawing() {
|
endDrawing: function CanvasGraphics_endDrawing() {
|
||||||
this.ctx.restore();
|
this.ctx.restore();
|
||||||
|
|
||||||
if (this.textLayer)
|
if (this.textLayer)
|
||||||
@ -340,32 +340,32 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Graphics state
|
// Graphics state
|
||||||
setLineWidth: function canvasGraphicsSetLineWidth(width) {
|
setLineWidth: function CanvasGraphics_setLineWidth(width) {
|
||||||
this.current.lineWidth = width;
|
this.current.lineWidth = width;
|
||||||
this.ctx.lineWidth = width;
|
this.ctx.lineWidth = width;
|
||||||
},
|
},
|
||||||
setLineCap: function canvasGraphicsSetLineCap(style) {
|
setLineCap: function CanvasGraphics_setLineCap(style) {
|
||||||
this.ctx.lineCap = LINE_CAP_STYLES[style];
|
this.ctx.lineCap = LINE_CAP_STYLES[style];
|
||||||
},
|
},
|
||||||
setLineJoin: function canvasGraphicsSetLineJoin(style) {
|
setLineJoin: function CanvasGraphics_setLineJoin(style) {
|
||||||
this.ctx.lineJoin = LINE_JOIN_STYLES[style];
|
this.ctx.lineJoin = LINE_JOIN_STYLES[style];
|
||||||
},
|
},
|
||||||
setMiterLimit: function canvasGraphicsSetMiterLimit(limit) {
|
setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
|
||||||
this.ctx.miterLimit = limit;
|
this.ctx.miterLimit = limit;
|
||||||
},
|
},
|
||||||
setDash: function canvasGraphicsSetDash(dashArray, dashPhase) {
|
setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
|
||||||
this.ctx.mozDash = dashArray;
|
this.ctx.mozDash = dashArray;
|
||||||
this.ctx.mozDashOffset = dashPhase;
|
this.ctx.mozDashOffset = dashPhase;
|
||||||
this.ctx.webkitLineDash = dashArray;
|
this.ctx.webkitLineDash = dashArray;
|
||||||
this.ctx.webkitLineDashOffset = dashPhase;
|
this.ctx.webkitLineDashOffset = dashPhase;
|
||||||
},
|
},
|
||||||
setRenderingIntent: function canvasGraphicsSetRenderingIntent(intent) {
|
setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
|
||||||
TODO('set rendering intent: ' + intent);
|
TODO('set rendering intent: ' + intent);
|
||||||
},
|
},
|
||||||
setFlatness: function canvasGraphicsSetFlatness(flatness) {
|
setFlatness: function CanvasGraphics_setFlatness(flatness) {
|
||||||
TODO('set flatness: ' + flatness);
|
TODO('set flatness: ' + flatness);
|
||||||
},
|
},
|
||||||
setGState: function canvasGraphicsSetGState(states) {
|
setGState: function CanvasGraphics_setGState(states) {
|
||||||
for (var i = 0, ii = states.length; i < ii; i++) {
|
for (var i = 0, ii = states.length; i < ii; i++) {
|
||||||
var state = states[i];
|
var state = states[i];
|
||||||
var key = state[0];
|
var key = state[0];
|
||||||
@ -406,52 +406,52 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
save: function canvasGraphicsSave() {
|
save: function CanvasGraphics_save() {
|
||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
var old = this.current;
|
var old = this.current;
|
||||||
this.stateStack.push(old);
|
this.stateStack.push(old);
|
||||||
this.current = old.clone();
|
this.current = old.clone();
|
||||||
},
|
},
|
||||||
restore: function canvasGraphicsRestore() {
|
restore: function CanvasGraphics_restore() {
|
||||||
var prev = this.stateStack.pop();
|
var prev = this.stateStack.pop();
|
||||||
if (prev) {
|
if (prev) {
|
||||||
this.current = prev;
|
this.current = prev;
|
||||||
this.ctx.restore();
|
this.ctx.restore();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
transform: function canvasGraphicsTransform(a, b, c, d, e, f) {
|
transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
|
||||||
this.ctx.transform(a, b, c, d, e, f);
|
this.ctx.transform(a, b, c, d, e, f);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Path
|
// Path
|
||||||
moveTo: function canvasGraphicsMoveTo(x, y) {
|
moveTo: function CanvasGraphics_moveTo(x, y) {
|
||||||
this.ctx.moveTo(x, y);
|
this.ctx.moveTo(x, y);
|
||||||
this.current.setCurrentPoint(x, y);
|
this.current.setCurrentPoint(x, y);
|
||||||
},
|
},
|
||||||
lineTo: function canvasGraphicsLineTo(x, y) {
|
lineTo: function CanvasGraphics_lineTo(x, y) {
|
||||||
this.ctx.lineTo(x, y);
|
this.ctx.lineTo(x, y);
|
||||||
this.current.setCurrentPoint(x, y);
|
this.current.setCurrentPoint(x, y);
|
||||||
},
|
},
|
||||||
curveTo: function canvasGraphicsCurveTo(x1, y1, x2, y2, x3, y3) {
|
curveTo: function CanvasGraphics_curveTo(x1, y1, x2, y2, x3, y3) {
|
||||||
this.ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
|
this.ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
|
||||||
this.current.setCurrentPoint(x3, y3);
|
this.current.setCurrentPoint(x3, y3);
|
||||||
},
|
},
|
||||||
curveTo2: function canvasGraphicsCurveTo2(x2, y2, x3, y3) {
|
curveTo2: function CanvasGraphics_curveTo2(x2, y2, x3, y3) {
|
||||||
var current = this.current;
|
var current = this.current;
|
||||||
this.ctx.bezierCurveTo(current.x, current.y, x2, y2, x3, y3);
|
this.ctx.bezierCurveTo(current.x, current.y, x2, y2, x3, y3);
|
||||||
current.setCurrentPoint(x3, y3);
|
current.setCurrentPoint(x3, y3);
|
||||||
},
|
},
|
||||||
curveTo3: function canvasGraphicsCurveTo3(x1, y1, x3, y3) {
|
curveTo3: function CanvasGraphics_curveTo3(x1, y1, x3, y3) {
|
||||||
this.curveTo(x1, y1, x3, y3, x3, y3);
|
this.curveTo(x1, y1, x3, y3, x3, y3);
|
||||||
this.current.setCurrentPoint(x3, y3);
|
this.current.setCurrentPoint(x3, y3);
|
||||||
},
|
},
|
||||||
closePath: function canvasGraphicsClosePath() {
|
closePath: function CanvasGraphics_closePath() {
|
||||||
this.ctx.closePath();
|
this.ctx.closePath();
|
||||||
},
|
},
|
||||||
rectangle: function canvasGraphicsRectangle(x, y, width, height) {
|
rectangle: function CanvasGraphics_rectangle(x, y, width, height) {
|
||||||
this.ctx.rect(x, y, width, height);
|
this.ctx.rect(x, y, width, height);
|
||||||
},
|
},
|
||||||
stroke: function canvasGraphicsStroke(consumePath) {
|
stroke: function CanvasGraphics_stroke(consumePath) {
|
||||||
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
|
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var strokeColor = this.current.strokeColor;
|
var strokeColor = this.current.strokeColor;
|
||||||
@ -476,11 +476,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
// Restore the global alpha to the fill alpha
|
// Restore the global alpha to the fill alpha
|
||||||
ctx.globalAlpha = this.current.fillAlpha;
|
ctx.globalAlpha = this.current.fillAlpha;
|
||||||
},
|
},
|
||||||
closeStroke: function canvasGraphicsCloseStroke() {
|
closeStroke: function CanvasGraphics_closeStroke() {
|
||||||
this.closePath();
|
this.closePath();
|
||||||
this.stroke();
|
this.stroke();
|
||||||
},
|
},
|
||||||
fill: function canvasGraphicsFill(consumePath) {
|
fill: function CanvasGraphics_fill(consumePath) {
|
||||||
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
|
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var fillColor = this.current.fillColor;
|
var fillColor = this.current.fillColor;
|
||||||
@ -497,65 +497,65 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
if (consumePath)
|
if (consumePath)
|
||||||
this.consumePath();
|
this.consumePath();
|
||||||
},
|
},
|
||||||
eoFill: function canvasGraphicsEoFill() {
|
eoFill: function CanvasGraphics_eoFill() {
|
||||||
var savedFillRule = this.setEOFillRule();
|
var savedFillRule = this.setEOFillRule();
|
||||||
this.fill();
|
this.fill();
|
||||||
this.restoreFillRule(savedFillRule);
|
this.restoreFillRule(savedFillRule);
|
||||||
},
|
},
|
||||||
fillStroke: function canvasGraphicsFillStroke() {
|
fillStroke: function CanvasGraphics_fillStroke() {
|
||||||
this.fill(false);
|
this.fill(false);
|
||||||
this.stroke(false);
|
this.stroke(false);
|
||||||
|
|
||||||
this.consumePath();
|
this.consumePath();
|
||||||
},
|
},
|
||||||
eoFillStroke: function canvasGraphicsEoFillStroke() {
|
eoFillStroke: function CanvasGraphics_eoFillStroke() {
|
||||||
var savedFillRule = this.setEOFillRule();
|
var savedFillRule = this.setEOFillRule();
|
||||||
this.fillStroke();
|
this.fillStroke();
|
||||||
this.restoreFillRule(savedFillRule);
|
this.restoreFillRule(savedFillRule);
|
||||||
},
|
},
|
||||||
closeFillStroke: function canvasGraphicsCloseFillStroke() {
|
closeFillStroke: function CanvasGraphics_closeFillStroke() {
|
||||||
this.closePath();
|
this.closePath();
|
||||||
this.fillStroke();
|
this.fillStroke();
|
||||||
},
|
},
|
||||||
closeEOFillStroke: function canvasGraphicsCloseEOFillStroke() {
|
closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
|
||||||
var savedFillRule = this.setEOFillRule();
|
var savedFillRule = this.setEOFillRule();
|
||||||
this.closePath();
|
this.closePath();
|
||||||
this.fillStroke();
|
this.fillStroke();
|
||||||
this.restoreFillRule(savedFillRule);
|
this.restoreFillRule(savedFillRule);
|
||||||
},
|
},
|
||||||
endPath: function canvasGraphicsEndPath() {
|
endPath: function CanvasGraphics_endPath() {
|
||||||
this.consumePath();
|
this.consumePath();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Clipping
|
// Clipping
|
||||||
clip: function canvasGraphicsClip() {
|
clip: function CanvasGraphics_clip() {
|
||||||
this.pendingClip = NORMAL_CLIP;
|
this.pendingClip = NORMAL_CLIP;
|
||||||
},
|
},
|
||||||
eoClip: function canvasGraphicsEoClip() {
|
eoClip: function CanvasGraphics_eoClip() {
|
||||||
this.pendingClip = EO_CLIP;
|
this.pendingClip = EO_CLIP;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
beginText: function canvasGraphicsBeginText() {
|
beginText: function CanvasGraphics_beginText() {
|
||||||
this.current.textMatrix = IDENTITY_MATRIX;
|
this.current.textMatrix = IDENTITY_MATRIX;
|
||||||
this.current.x = this.current.lineX = 0;
|
this.current.x = this.current.lineX = 0;
|
||||||
this.current.y = this.current.lineY = 0;
|
this.current.y = this.current.lineY = 0;
|
||||||
},
|
},
|
||||||
endText: function canvasGraphicsEndText() {
|
endText: function CanvasGraphics_endText() {
|
||||||
},
|
},
|
||||||
setCharSpacing: function canvasGraphicsSetCharSpacing(spacing) {
|
setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
|
||||||
this.current.charSpacing = spacing;
|
this.current.charSpacing = spacing;
|
||||||
},
|
},
|
||||||
setWordSpacing: function canvasGraphicsSetWordSpacing(spacing) {
|
setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
|
||||||
this.current.wordSpacing = spacing;
|
this.current.wordSpacing = spacing;
|
||||||
},
|
},
|
||||||
setHScale: function canvasGraphicsSetHScale(scale) {
|
setHScale: function CanvasGraphics_setHScale(scale) {
|
||||||
this.current.textHScale = scale / 100;
|
this.current.textHScale = scale / 100;
|
||||||
},
|
},
|
||||||
setLeading: function canvasGraphicsSetLeading(leading) {
|
setLeading: function CanvasGraphics_setLeading(leading) {
|
||||||
this.current.leading = -leading;
|
this.current.leading = -leading;
|
||||||
},
|
},
|
||||||
setFont: function canvasGraphicsSetFont(fontRefName, size) {
|
setFont: function CanvasGraphics_setFont(fontRefName, size) {
|
||||||
var fontObj = this.objs.get(fontRefName);
|
var fontObj = this.objs.get(fontRefName);
|
||||||
var current = this.current;
|
var current = this.current;
|
||||||
|
|
||||||
@ -609,32 +609,32 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
|
var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
|
||||||
this.ctx.font = rule;
|
this.ctx.font = rule;
|
||||||
},
|
},
|
||||||
setTextRenderingMode: function canvasGraphicsSetTextRenderingMode(mode) {
|
setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
|
||||||
if (mode >= TextRenderingMode.FILL_ADD_TO_PATH)
|
if (mode >= TextRenderingMode.FILL_ADD_TO_PATH)
|
||||||
TODO('unsupported text rendering mode: ' + mode);
|
TODO('unsupported text rendering mode: ' + mode);
|
||||||
this.current.textRenderingMode = mode;
|
this.current.textRenderingMode = mode;
|
||||||
},
|
},
|
||||||
setTextRise: function canvasGraphicsSetTextRise(rise) {
|
setTextRise: function CanvasGraphics_setTextRise(rise) {
|
||||||
TODO('text rise: ' + rise);
|
TODO('text rise: ' + rise);
|
||||||
},
|
},
|
||||||
moveText: function canvasGraphicsMoveText(x, y) {
|
moveText: function CanvasGraphics_moveText(x, y) {
|
||||||
this.current.x = this.current.lineX += x;
|
this.current.x = this.current.lineX += x;
|
||||||
this.current.y = this.current.lineY += y;
|
this.current.y = this.current.lineY += y;
|
||||||
},
|
},
|
||||||
setLeadingMoveText: function canvasGraphicsSetLeadingMoveText(x, y) {
|
setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
|
||||||
this.setLeading(-y);
|
this.setLeading(-y);
|
||||||
this.moveText(x, y);
|
this.moveText(x, y);
|
||||||
},
|
},
|
||||||
setTextMatrix: function canvasGraphicsSetTextMatrix(a, b, c, d, e, f) {
|
setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
|
||||||
this.current.textMatrix = [a, b, c, d, e, f];
|
this.current.textMatrix = [a, b, c, d, e, f];
|
||||||
|
|
||||||
this.current.x = this.current.lineX = 0;
|
this.current.x = this.current.lineX = 0;
|
||||||
this.current.y = this.current.lineY = 0;
|
this.current.y = this.current.lineY = 0;
|
||||||
},
|
},
|
||||||
nextLine: function canvasGraphicsNextLine() {
|
nextLine: function CanvasGraphics_nextLine() {
|
||||||
this.moveText(0, this.current.leading);
|
this.moveText(0, this.current.leading);
|
||||||
},
|
},
|
||||||
applyTextTransforms: function canvasApplyTransforms() {
|
applyTextTransforms: function CanvasGraphics_applyTextTransforms() {
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var current = this.current;
|
var current = this.current;
|
||||||
var textHScale = current.textHScale;
|
var textHScale = current.textHScale;
|
||||||
@ -646,7 +646,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
ctx.transform.apply(ctx, fontMatrix);
|
ctx.transform.apply(ctx, fontMatrix);
|
||||||
ctx.scale(textHScale, 1);
|
ctx.scale(textHScale, 1);
|
||||||
},
|
},
|
||||||
getTextGeometry: function canvasGetTextGeometry() {
|
getTextGeometry: function CanvasGraphics_getTextGeometry() {
|
||||||
var geometry = {};
|
var geometry = {};
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var font = this.current.font;
|
var font = this.current.font;
|
||||||
@ -663,7 +663,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
return geometry;
|
return geometry;
|
||||||
},
|
},
|
||||||
|
|
||||||
showText: function canvasGraphicsShowText(str, skipTextSelection) {
|
showText: function CanvasGraphics_showText(str, skipTextSelection) {
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var current = this.current;
|
var current = this.current;
|
||||||
var font = current.font;
|
var font = current.font;
|
||||||
@ -752,28 +752,30 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var char = glyph.fontChar;
|
var character = glyph.fontChar;
|
||||||
var charWidth = glyph.width * fontSize * 0.001 +
|
var charWidth = glyph.width * fontSize * 0.001 +
|
||||||
Util.sign(current.fontMatrix[0]) * charSpacing;
|
Util.sign(current.fontMatrix[0]) * charSpacing;
|
||||||
|
|
||||||
var scaledX = x / fontSizeScale;
|
if (!glyph.disabled) {
|
||||||
switch (textRenderingMode) {
|
var scaledX = x / fontSizeScale;
|
||||||
default: // other unsupported rendering modes
|
switch (textRenderingMode) {
|
||||||
case TextRenderingMode.FILL:
|
default: // other unsupported rendering modes
|
||||||
case TextRenderingMode.FILL_ADD_TO_PATH:
|
case TextRenderingMode.FILL:
|
||||||
ctx.fillText(char, scaledX, 0);
|
case TextRenderingMode.FILL_ADD_TO_PATH:
|
||||||
break;
|
ctx.fillText(character, scaledX, 0);
|
||||||
case TextRenderingMode.STROKE:
|
break;
|
||||||
case TextRenderingMode.STROKE_ADD_TO_PATH:
|
case TextRenderingMode.STROKE:
|
||||||
ctx.strokeText(char, scaledX, 0);
|
case TextRenderingMode.STROKE_ADD_TO_PATH:
|
||||||
break;
|
ctx.strokeText(character, scaledX, 0);
|
||||||
case TextRenderingMode.FILL_STROKE:
|
break;
|
||||||
case TextRenderingMode.FILL_STROKE_ADD_TO_PATH:
|
case TextRenderingMode.FILL_STROKE:
|
||||||
ctx.fillText(char, scaledX, 0);
|
case TextRenderingMode.FILL_STROKE_ADD_TO_PATH:
|
||||||
ctx.strokeText(char, scaledX, 0);
|
ctx.fillText(character, scaledX, 0);
|
||||||
break;
|
ctx.strokeText(character, scaledX, 0);
|
||||||
case TextRenderingMode.INVISIBLE:
|
break;
|
||||||
break;
|
case TextRenderingMode.INVISIBLE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
x += charWidth;
|
x += charWidth;
|
||||||
@ -799,7 +801,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
|
|
||||||
return text;
|
return text;
|
||||||
},
|
},
|
||||||
showSpacedText: function canvasGraphicsShowSpacedText(arr) {
|
showSpacedText: function CanvasGraphics_showSpacedText(arr) {
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var current = this.current;
|
var current = this.current;
|
||||||
var font = current.font;
|
var font = current.font;
|
||||||
@ -863,25 +865,25 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
if (textSelection)
|
if (textSelection)
|
||||||
this.textLayer.appendText(text, font.loadedName, fontSize);
|
this.textLayer.appendText(text, font.loadedName, fontSize);
|
||||||
},
|
},
|
||||||
nextLineShowText: function canvasGraphicsNextLineShowText(text) {
|
nextLineShowText: function CanvasGraphics_nextLineShowText(text) {
|
||||||
this.nextLine();
|
this.nextLine();
|
||||||
this.showText(text);
|
this.showText(text);
|
||||||
},
|
},
|
||||||
nextLineSetSpacingShowText:
|
nextLineSetSpacingShowText:
|
||||||
function canvasGraphicsNextLineSetSpacingShowText(wordSpacing,
|
function CanvasGraphics_nextLineSetSpacingShowText(wordSpacing,
|
||||||
charSpacing,
|
charSpacing,
|
||||||
text) {
|
text) {
|
||||||
this.setWordSpacing(wordSpacing);
|
this.setWordSpacing(wordSpacing);
|
||||||
this.setCharSpacing(charSpacing);
|
this.setCharSpacing(charSpacing);
|
||||||
this.nextLineShowText(text);
|
this.nextLineShowText(text);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Type3 fonts
|
// Type3 fonts
|
||||||
setCharWidth: function canvasGraphicsSetCharWidth(xWidth, yWidth) {
|
setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
|
||||||
// We can safely ignore this since the width should be the same
|
// We can safely ignore this since the width should be the same
|
||||||
// as the width in the Widths array.
|
// as the width in the Widths array.
|
||||||
},
|
},
|
||||||
setCharWidthAndBounds: function canvasGraphicsSetCharWidthAndBounds(xWidth,
|
setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
|
||||||
yWidth,
|
yWidth,
|
||||||
llx,
|
llx,
|
||||||
lly,
|
lly,
|
||||||
@ -895,20 +897,20 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
setStrokeColorSpace: function canvasGraphicsSetStrokeColorSpace(raw) {
|
setStrokeColorSpace: function CanvasGraphics_setStrokeColorSpace(raw) {
|
||||||
this.current.strokeColorSpace = ColorSpace.fromIR(raw);
|
this.current.strokeColorSpace = ColorSpace.fromIR(raw);
|
||||||
},
|
},
|
||||||
setFillColorSpace: function canvasGraphicsSetFillColorSpace(raw) {
|
setFillColorSpace: function CanvasGraphics_setFillColorSpace(raw) {
|
||||||
this.current.fillColorSpace = ColorSpace.fromIR(raw);
|
this.current.fillColorSpace = ColorSpace.fromIR(raw);
|
||||||
},
|
},
|
||||||
setStrokeColor: function canvasGraphicsSetStrokeColor(/*...*/) {
|
setStrokeColor: function CanvasGraphics_setStrokeColor(/*...*/) {
|
||||||
var cs = this.current.strokeColorSpace;
|
var cs = this.current.strokeColorSpace;
|
||||||
var rgbColor = cs.getRgb(arguments);
|
var rgbColor = cs.getRgb(arguments);
|
||||||
var color = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
|
var color = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
|
||||||
this.ctx.strokeStyle = color;
|
this.ctx.strokeStyle = color;
|
||||||
this.current.strokeColor = color;
|
this.current.strokeColor = color;
|
||||||
},
|
},
|
||||||
getColorN_Pattern: function canvasGraphicsGetColorN_Pattern(IR, cs) {
|
getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR, cs) {
|
||||||
if (IR[0] == 'TilingPattern') {
|
if (IR[0] == 'TilingPattern') {
|
||||||
var args = IR[1];
|
var args = IR[1];
|
||||||
var base = cs.base;
|
var base = cs.base;
|
||||||
@ -930,7 +932,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
}
|
}
|
||||||
return pattern;
|
return pattern;
|
||||||
},
|
},
|
||||||
setStrokeColorN: function canvasGraphicsSetStrokeColorN(/*...*/) {
|
setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
|
||||||
var cs = this.current.strokeColorSpace;
|
var cs = this.current.strokeColorSpace;
|
||||||
|
|
||||||
if (cs.name == 'Pattern') {
|
if (cs.name == 'Pattern') {
|
||||||
@ -939,14 +941,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.setStrokeColor.apply(this, arguments);
|
this.setStrokeColor.apply(this, arguments);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setFillColor: function canvasGraphicsSetFillColor(/*...*/) {
|
setFillColor: function CanvasGraphics_setFillColor(/*...*/) {
|
||||||
var cs = this.current.fillColorSpace;
|
var cs = this.current.fillColorSpace;
|
||||||
var rgbColor = cs.getRgb(arguments);
|
var rgbColor = cs.getRgb(arguments);
|
||||||
var color = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
|
var color = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
|
||||||
this.ctx.fillStyle = color;
|
this.ctx.fillStyle = color;
|
||||||
this.current.fillColor = color;
|
this.current.fillColor = color;
|
||||||
},
|
},
|
||||||
setFillColorN: function canvasGraphicsSetFillColorN(/*...*/) {
|
setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
|
||||||
var cs = this.current.fillColorSpace;
|
var cs = this.current.fillColorSpace;
|
||||||
|
|
||||||
if (cs.name == 'Pattern') {
|
if (cs.name == 'Pattern') {
|
||||||
@ -955,7 +957,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.setFillColor.apply(this, arguments);
|
this.setFillColor.apply(this, arguments);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setStrokeGray: function canvasGraphicsSetStrokeGray(gray) {
|
setStrokeGray: function CanvasGraphics_setStrokeGray(gray) {
|
||||||
if (!(this.current.strokeColorSpace instanceof DeviceGrayCS))
|
if (!(this.current.strokeColorSpace instanceof DeviceGrayCS))
|
||||||
this.current.strokeColorSpace = new DeviceGrayCS();
|
this.current.strokeColorSpace = new DeviceGrayCS();
|
||||||
|
|
||||||
@ -963,7 +965,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.ctx.strokeStyle = color;
|
this.ctx.strokeStyle = color;
|
||||||
this.current.strokeColor = color;
|
this.current.strokeColor = color;
|
||||||
},
|
},
|
||||||
setFillGray: function canvasGraphicsSetFillGray(gray) {
|
setFillGray: function CanvasGraphics_setFillGray(gray) {
|
||||||
if (!(this.current.fillColorSpace instanceof DeviceGrayCS))
|
if (!(this.current.fillColorSpace instanceof DeviceGrayCS))
|
||||||
this.current.fillColorSpace = new DeviceGrayCS();
|
this.current.fillColorSpace = new DeviceGrayCS();
|
||||||
|
|
||||||
@ -971,7 +973,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.ctx.fillStyle = color;
|
this.ctx.fillStyle = color;
|
||||||
this.current.fillColor = color;
|
this.current.fillColor = color;
|
||||||
},
|
},
|
||||||
setStrokeRGBColor: function canvasGraphicsSetStrokeRGBColor(r, g, b) {
|
setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
|
||||||
if (!(this.current.strokeColorSpace instanceof DeviceRgbCS))
|
if (!(this.current.strokeColorSpace instanceof DeviceRgbCS))
|
||||||
this.current.strokeColorSpace = new DeviceRgbCS();
|
this.current.strokeColorSpace = new DeviceRgbCS();
|
||||||
|
|
||||||
@ -979,7 +981,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.ctx.strokeStyle = color;
|
this.ctx.strokeStyle = color;
|
||||||
this.current.strokeColor = color;
|
this.current.strokeColor = color;
|
||||||
},
|
},
|
||||||
setFillRGBColor: function canvasGraphicsSetFillRGBColor(r, g, b) {
|
setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
|
||||||
if (!(this.current.fillColorSpace instanceof DeviceRgbCS))
|
if (!(this.current.fillColorSpace instanceof DeviceRgbCS))
|
||||||
this.current.fillColorSpace = new DeviceRgbCS();
|
this.current.fillColorSpace = new DeviceRgbCS();
|
||||||
|
|
||||||
@ -987,7 +989,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.ctx.fillStyle = color;
|
this.ctx.fillStyle = color;
|
||||||
this.current.fillColor = color;
|
this.current.fillColor = color;
|
||||||
},
|
},
|
||||||
setStrokeCMYKColor: function canvasGraphicsSetStrokeCMYKColor(c, m, y, k) {
|
setStrokeCMYKColor: function CanvasGraphics_setStrokeCMYKColor(c, m, y, k) {
|
||||||
if (!(this.current.strokeColorSpace instanceof DeviceCmykCS))
|
if (!(this.current.strokeColorSpace instanceof DeviceCmykCS))
|
||||||
this.current.strokeColorSpace = new DeviceCmykCS();
|
this.current.strokeColorSpace = new DeviceCmykCS();
|
||||||
|
|
||||||
@ -995,7 +997,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.ctx.strokeStyle = color;
|
this.ctx.strokeStyle = color;
|
||||||
this.current.strokeColor = color;
|
this.current.strokeColor = color;
|
||||||
},
|
},
|
||||||
setFillCMYKColor: function canvasGraphicsSetFillCMYKColor(c, m, y, k) {
|
setFillCMYKColor: function CanvasGraphics_setFillCMYKColor(c, m, y, k) {
|
||||||
if (!(this.current.fillColorSpace instanceof DeviceCmykCS))
|
if (!(this.current.fillColorSpace instanceof DeviceCmykCS))
|
||||||
this.current.fillColorSpace = new DeviceCmykCS();
|
this.current.fillColorSpace = new DeviceCmykCS();
|
||||||
|
|
||||||
@ -1004,7 +1006,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.current.fillColor = color;
|
this.current.fillColor = color;
|
||||||
},
|
},
|
||||||
|
|
||||||
shadingFill: function canvasGraphicsShadingFill(patternIR) {
|
shadingFill: function CanvasGraphics_shadingFill(patternIR) {
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
|
|
||||||
this.save();
|
this.save();
|
||||||
@ -1042,14 +1044,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Images
|
// Images
|
||||||
beginInlineImage: function canvasGraphicsBeginInlineImage() {
|
beginInlineImage: function CanvasGraphics_beginInlineImage() {
|
||||||
error('Should not call beginInlineImage');
|
error('Should not call beginInlineImage');
|
||||||
},
|
},
|
||||||
beginImageData: function canvasGraphicsBeginImageData() {
|
beginImageData: function CanvasGraphics_beginImageData() {
|
||||||
error('Should not call beginImageData');
|
error('Should not call beginImageData');
|
||||||
},
|
},
|
||||||
|
|
||||||
paintFormXObjectBegin: function canvasGraphicsPaintFormXObjectBegin(matrix,
|
paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
|
||||||
bbox) {
|
bbox) {
|
||||||
this.save();
|
this.save();
|
||||||
|
|
||||||
@ -1065,11 +1067,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
paintFormXObjectEnd: function canvasGraphicsPaintFormXObjectEnd() {
|
paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
|
||||||
this.restore();
|
this.restore();
|
||||||
},
|
},
|
||||||
|
|
||||||
paintJpegXObject: function canvasGraphicsPaintJpegXObject(objId, w, h) {
|
paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
|
||||||
var domImage = this.objs.get(objId);
|
var domImage = this.objs.get(objId);
|
||||||
if (!domImage) {
|
if (!domImage) {
|
||||||
error('Dependent image isn\'t ready yet');
|
error('Dependent image isn\'t ready yet');
|
||||||
@ -1087,7 +1089,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.restore();
|
this.restore();
|
||||||
},
|
},
|
||||||
|
|
||||||
paintImageMaskXObject: function canvasGraphicsPaintImageMaskXObject(
|
paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(
|
||||||
imgArray, inverseDecode, width, height) {
|
imgArray, inverseDecode, width, height) {
|
||||||
function applyStencilMask(buffer, inverseDecode) {
|
function applyStencilMask(buffer, inverseDecode) {
|
||||||
var imgArrayPos = 0;
|
var imgArrayPos = 0;
|
||||||
@ -1136,7 +1138,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.restore();
|
this.restore();
|
||||||
},
|
},
|
||||||
|
|
||||||
paintImageXObject: function canvasGraphicsPaintImageXObject(objId) {
|
paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
|
||||||
var imgData = this.objs.get(objId);
|
var imgData = this.objs.get(objId);
|
||||||
if (!imgData)
|
if (!imgData)
|
||||||
error('Dependent image isn\'t ready yet');
|
error('Dependent image isn\'t ready yet');
|
||||||
@ -1156,41 +1158,41 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.restore();
|
this.restore();
|
||||||
},
|
},
|
||||||
|
|
||||||
putBinaryImageData: function canvasPutBinaryImageData() {
|
putBinaryImageData: function CanvasGraphics_putBinaryImageData() {
|
||||||
//
|
//
|
||||||
},
|
},
|
||||||
|
|
||||||
// Marked content
|
// Marked content
|
||||||
|
|
||||||
markPoint: function canvasGraphicsMarkPoint(tag) {
|
markPoint: function CanvasGraphics_markPoint(tag) {
|
||||||
TODO('Marked content');
|
TODO('Marked content');
|
||||||
},
|
},
|
||||||
markPointProps: function canvasGraphicsMarkPointProps(tag, properties) {
|
markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
|
||||||
TODO('Marked content');
|
TODO('Marked content');
|
||||||
},
|
},
|
||||||
beginMarkedContent: function canvasGraphicsBeginMarkedContent(tag) {
|
beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
|
||||||
TODO('Marked content');
|
TODO('Marked content');
|
||||||
},
|
},
|
||||||
beginMarkedContentProps:
|
beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
|
||||||
function canvasGraphicsBeginMarkedContentProps(tag, properties) {
|
tag, properties) {
|
||||||
TODO('Marked content');
|
TODO('Marked content');
|
||||||
},
|
},
|
||||||
endMarkedContent: function canvasGraphicsEndMarkedContent() {
|
endMarkedContent: function CanvasGraphics_endMarkedContent() {
|
||||||
TODO('Marked content');
|
TODO('Marked content');
|
||||||
},
|
},
|
||||||
|
|
||||||
// Compatibility
|
// Compatibility
|
||||||
|
|
||||||
beginCompat: function canvasGraphicsBeginCompat() {
|
beginCompat: function CanvasGraphics_beginCompat() {
|
||||||
TODO('ignore undefined operators (should we do that anyway?)');
|
TODO('ignore undefined operators (should we do that anyway?)');
|
||||||
},
|
},
|
||||||
endCompat: function canvasGraphicsEndCompat() {
|
endCompat: function CanvasGraphics_endCompat() {
|
||||||
TODO('stop ignoring undefined operators');
|
TODO('stop ignoring undefined operators');
|
||||||
},
|
},
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
|
||||||
consumePath: function canvasGraphicsConsumePath() {
|
consumePath: function CanvasGraphics_consumePath() {
|
||||||
if (this.pendingClip) {
|
if (this.pendingClip) {
|
||||||
var savedFillRule = null;
|
var savedFillRule = null;
|
||||||
if (this.pendingClip == EO_CLIP)
|
if (this.pendingClip == EO_CLIP)
|
||||||
@ -1207,15 +1209,15 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
// We generally keep the canvas context set for
|
// We generally keep the canvas context set for
|
||||||
// nonzero-winding, and just set evenodd for the operations
|
// nonzero-winding, and just set evenodd for the operations
|
||||||
// that need them.
|
// that need them.
|
||||||
setEOFillRule: function canvasGraphicsSetEOFillRule() {
|
setEOFillRule: function CanvasGraphics_setEOFillRule() {
|
||||||
var savedFillRule = this.ctx.mozFillRule;
|
var savedFillRule = this.ctx.mozFillRule;
|
||||||
this.ctx.mozFillRule = 'evenodd';
|
this.ctx.mozFillRule = 'evenodd';
|
||||||
return savedFillRule;
|
return savedFillRule;
|
||||||
},
|
},
|
||||||
restoreFillRule: function canvasGraphicsRestoreFillRule(rule) {
|
restoreFillRule: function CanvasGraphics_restoreFillRule(rule) {
|
||||||
this.ctx.mozFillRule = rule;
|
this.ctx.mozFillRule = rule;
|
||||||
},
|
},
|
||||||
getSinglePixelWidth: function getSinglePixelWidth(scale) {
|
getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
|
||||||
var inverse = this.ctx.mozCurrentTransformInverse;
|
var inverse = this.ctx.mozCurrentTransformInverse;
|
||||||
return Math.abs(inverse[0] + inverse[2]);
|
return Math.abs(inverse[0] + inverse[2]);
|
||||||
}
|
}
|
||||||
|
@ -12,17 +12,17 @@ var ColorSpace = (function ColorSpaceClosure() {
|
|||||||
ColorSpace.prototype = {
|
ColorSpace.prototype = {
|
||||||
// Input: array of size numComps representing color component values
|
// Input: array of size numComps representing color component values
|
||||||
// Output: array of rgb values, each value ranging from [0.1]
|
// Output: array of rgb values, each value ranging from [0.1]
|
||||||
getRgb: function colorSpaceGetRgb(color) {
|
getRgb: function ColorSpace_getRgb(color) {
|
||||||
error('Should not call ColorSpace.getRgb: ' + color);
|
error('Should not call ColorSpace.getRgb: ' + color);
|
||||||
},
|
},
|
||||||
// Input: Uint8Array of component values, each value scaled to [0,255]
|
// Input: Uint8Array of component values, each value scaled to [0,255]
|
||||||
// Output: Uint8Array of rgb values, each value scaled to [0,255]
|
// Output: Uint8Array of rgb values, each value scaled to [0,255]
|
||||||
getRgbBuffer: function colorSpaceGetRgbBuffer(input) {
|
getRgbBuffer: function ColorSpace_getRgbBuffer(input) {
|
||||||
error('Should not call ColorSpace.getRgbBuffer: ' + input);
|
error('Should not call ColorSpace.getRgbBuffer: ' + input);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ColorSpace.parse = function colorSpaceParse(cs, xref, res) {
|
ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
|
||||||
var IR = ColorSpace.parseToIR(cs, xref, res);
|
var IR = ColorSpace.parseToIR(cs, xref, res);
|
||||||
if (IR instanceof AlternateCS)
|
if (IR instanceof AlternateCS)
|
||||||
return IR;
|
return IR;
|
||||||
@ -30,7 +30,7 @@ var ColorSpace = (function ColorSpaceClosure() {
|
|||||||
return ColorSpace.fromIR(IR);
|
return ColorSpace.fromIR(IR);
|
||||||
};
|
};
|
||||||
|
|
||||||
ColorSpace.fromIR = function colorSpaceFromIR(IR) {
|
ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
|
||||||
var name = isArray(IR) ? IR[0] : IR;
|
var name = isArray(IR) ? IR[0] : IR;
|
||||||
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
@ -68,9 +68,9 @@ var ColorSpace = (function ColorSpaceClosure() {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
ColorSpace.parseToIR = function colorSpaceParseToIR(cs, xref, res) {
|
ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
|
||||||
if (isName(cs)) {
|
if (isName(cs)) {
|
||||||
var colorSpaces = xref.fetchIfRef(res.get('ColorSpace'));
|
var colorSpaces = res.get('ColorSpace');
|
||||||
if (isDict(colorSpaces)) {
|
if (isDict(colorSpaces)) {
|
||||||
var refcs = colorSpaces.get(cs.name);
|
var refcs = colorSpaces.get(cs.name);
|
||||||
if (refcs)
|
if (refcs)
|
||||||
@ -152,7 +152,7 @@ var ColorSpace = (function ColorSpaceClosure() {
|
|||||||
var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
|
var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
|
||||||
return ['AlternateCS', numComps, alt, tintFnIR];
|
return ['AlternateCS', numComps, alt, tintFnIR];
|
||||||
case 'Lab':
|
case 'Lab':
|
||||||
var params = cs[1].map;
|
var params = cs[1].getAll();
|
||||||
return ['LabCS', params];
|
return ['LabCS', params];
|
||||||
default:
|
default:
|
||||||
error('unimplemented color space object "' + mode + '"');
|
error('unimplemented color space object "' + mode + '"');
|
||||||
@ -171,7 +171,7 @@ var ColorSpace = (function ColorSpaceClosure() {
|
|||||||
* @param {Array} decode Decode map (usually from an image).
|
* @param {Array} decode Decode map (usually from an image).
|
||||||
* @param {Number} n Number of components the color space has.
|
* @param {Number} n Number of components the color space has.
|
||||||
*/
|
*/
|
||||||
ColorSpace.isDefaultDecode = function colorSpaceIsDefaultDecode(decode, n) {
|
ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
|
||||||
if (!decode)
|
if (!decode)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -207,11 +207,11 @@ var AlternateCS = (function AlternateCSClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AlternateCS.prototype = {
|
AlternateCS.prototype = {
|
||||||
getRgb: function altcs_getRgb(color) {
|
getRgb: function AlternateCS_getRgb(color) {
|
||||||
var tinted = this.tintFn(color);
|
var tinted = this.tintFn(color);
|
||||||
return this.base.getRgb(tinted);
|
return this.base.getRgb(tinted);
|
||||||
},
|
},
|
||||||
getRgbBuffer: function altcs_getRgbBuffer(input, bits) {
|
getRgbBuffer: function AlternateCS_getRgbBuffer(input, bits) {
|
||||||
var tintFn = this.tintFn;
|
var tintFn = this.tintFn;
|
||||||
var base = this.base;
|
var base = this.base;
|
||||||
var scale = 1 / ((1 << bits) - 1);
|
var scale = 1 / ((1 << bits) - 1);
|
||||||
@ -232,7 +232,7 @@ var AlternateCS = (function AlternateCSClosure() {
|
|||||||
}
|
}
|
||||||
return base.getRgbBuffer(baseBuf, 8);
|
return base.getRgbBuffer(baseBuf, 8);
|
||||||
},
|
},
|
||||||
isDefaultDecode: function altcs_isDefaultDecode(decodeMap) {
|
isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -275,7 +275,7 @@ var IndexedCS = (function IndexedCSClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IndexedCS.prototype = {
|
IndexedCS.prototype = {
|
||||||
getRgb: function indexcs_getRgb(color) {
|
getRgb: function IndexedCS_getRgb(color) {
|
||||||
var numComps = this.base.numComps;
|
var numComps = this.base.numComps;
|
||||||
var start = color[0] * numComps;
|
var start = color[0] * numComps;
|
||||||
var c = [];
|
var c = [];
|
||||||
@ -285,7 +285,7 @@ var IndexedCS = (function IndexedCSClosure() {
|
|||||||
|
|
||||||
return this.base.getRgb(c);
|
return this.base.getRgb(c);
|
||||||
},
|
},
|
||||||
getRgbBuffer: function indexcs_getRgbBuffer(input) {
|
getRgbBuffer: function IndexedCS_getRgbBuffer(input) {
|
||||||
var base = this.base;
|
var base = this.base;
|
||||||
var numComps = base.numComps;
|
var numComps = base.numComps;
|
||||||
var lookup = this.lookup;
|
var lookup = this.lookup;
|
||||||
@ -302,7 +302,7 @@ var IndexedCS = (function IndexedCSClosure() {
|
|||||||
|
|
||||||
return base.getRgbBuffer(baseBuf, 8);
|
return base.getRgbBuffer(baseBuf, 8);
|
||||||
},
|
},
|
||||||
isDefaultDecode: function indexcs_isDefaultDecode(decodeMap) {
|
isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
|
||||||
// indexed color maps shouldn't be changed
|
// indexed color maps shouldn't be changed
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -318,11 +318,11 @@ var DeviceGrayCS = (function DeviceGrayCSClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DeviceGrayCS.prototype = {
|
DeviceGrayCS.prototype = {
|
||||||
getRgb: function graycs_getRgb(color) {
|
getRgb: function DeviceGrayCS_getRgb(color) {
|
||||||
var c = color[0];
|
var c = color[0];
|
||||||
return [c, c, c];
|
return [c, c, c];
|
||||||
},
|
},
|
||||||
getRgbBuffer: function graycs_getRgbBuffer(input, bits) {
|
getRgbBuffer: function DeviceGrayCS_getRgbBuffer(input, bits) {
|
||||||
var scale = 255 / ((1 << bits) - 1);
|
var scale = 255 / ((1 << bits) - 1);
|
||||||
var length = input.length;
|
var length = input.length;
|
||||||
var rgbBuf = new Uint8Array(length * 3);
|
var rgbBuf = new Uint8Array(length * 3);
|
||||||
@ -334,7 +334,7 @@ var DeviceGrayCS = (function DeviceGrayCSClosure() {
|
|||||||
}
|
}
|
||||||
return rgbBuf;
|
return rgbBuf;
|
||||||
},
|
},
|
||||||
isDefaultDecode: function graycs_isDefaultDecode(decodeMap) {
|
isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -348,10 +348,10 @@ var DeviceRgbCS = (function DeviceRgbCSClosure() {
|
|||||||
this.defaultColor = [0, 0, 0];
|
this.defaultColor = [0, 0, 0];
|
||||||
}
|
}
|
||||||
DeviceRgbCS.prototype = {
|
DeviceRgbCS.prototype = {
|
||||||
getRgb: function rgbcs_getRgb(color) {
|
getRgb: function DeviceRgbCS_getRgb(color) {
|
||||||
return color;
|
return color;
|
||||||
},
|
},
|
||||||
getRgbBuffer: function rgbcs_getRgbBuffer(input, bits) {
|
getRgbBuffer: function DeviceRgbCS_getRgbBuffer(input, bits) {
|
||||||
if (bits == 8)
|
if (bits == 8)
|
||||||
return input;
|
return input;
|
||||||
var scale = 255 / ((1 << bits) - 1);
|
var scale = 255 / ((1 << bits) - 1);
|
||||||
@ -361,7 +361,7 @@ var DeviceRgbCS = (function DeviceRgbCSClosure() {
|
|||||||
rgbBuf[i] = (scale * input[i]) | 0;
|
rgbBuf[i] = (scale * input[i]) | 0;
|
||||||
return rgbBuf;
|
return rgbBuf;
|
||||||
},
|
},
|
||||||
isDefaultDecode: function rgbcs_isDefaultDecode(decodeMap) {
|
isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -375,7 +375,7 @@ var DeviceCmykCS = (function DeviceCmykCSClosure() {
|
|||||||
this.defaultColor = [0, 0, 0, 1];
|
this.defaultColor = [0, 0, 0, 1];
|
||||||
}
|
}
|
||||||
DeviceCmykCS.prototype = {
|
DeviceCmykCS.prototype = {
|
||||||
getRgb: function cmykcs_getRgb(color) {
|
getRgb: function DeviceCmykCS_getRgb(color) {
|
||||||
var c = color[0], m = color[1], y = color[2], k = color[3];
|
var c = color[0], m = color[1], y = color[2], k = color[3];
|
||||||
|
|
||||||
// CMYK -> CMY: http://www.easyrgb.com/index.php?X=MATH&H=14#text14
|
// CMYK -> CMY: http://www.easyrgb.com/index.php?X=MATH&H=14#text14
|
||||||
@ -390,7 +390,7 @@ var DeviceCmykCS = (function DeviceCmykCSClosure() {
|
|||||||
|
|
||||||
return [r, g, b];
|
return [r, g, b];
|
||||||
},
|
},
|
||||||
getRgbBuffer: function cmykcs_getRgbBuffer(colorBuf, bits) {
|
getRgbBuffer: function DeviceCmykCS_getRgbBuffer(colorBuf, bits) {
|
||||||
var scale = 1 / ((1 << bits) - 1);
|
var scale = 1 / ((1 << bits) - 1);
|
||||||
var length = colorBuf.length / 4;
|
var length = colorBuf.length / 4;
|
||||||
var rgbBuf = new Uint8Array(length * 3);
|
var rgbBuf = new Uint8Array(length * 3);
|
||||||
@ -409,7 +409,7 @@ var DeviceCmykCS = (function DeviceCmykCSClosure() {
|
|||||||
|
|
||||||
return rgbBuf;
|
return rgbBuf;
|
||||||
},
|
},
|
||||||
isDefaultDecode: function cmykcs_isDefaultDecode(decodeMap) {
|
isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -473,7 +473,7 @@ var LabCS = (function LabCSClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LabCS.prototype = {
|
LabCS.prototype = {
|
||||||
getRgb: function labcs_getRgb(color) {
|
getRgb: function LabCS_getRgb(color) {
|
||||||
// Ls,as,bs <---> L*,a*,b* in the spec
|
// Ls,as,bs <---> L*,a*,b* in the spec
|
||||||
var Ls = color[0], as = color[1], bs = color[2];
|
var Ls = color[0], as = color[1], bs = color[2];
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ var LabCS = (function LabCSClosure() {
|
|||||||
|
|
||||||
return Util.apply3dTransform(XYZtoRGB, [X, Y, Z]);
|
return Util.apply3dTransform(XYZtoRGB, [X, Y, Z]);
|
||||||
},
|
},
|
||||||
getRgbBuffer: function labcs_getRgbBuffer(input, bits) {
|
getRgbBuffer: function LabCS_getRgbBuffer(input, bits) {
|
||||||
if (bits == 8)
|
if (bits == 8)
|
||||||
return input;
|
return input;
|
||||||
var scale = 255 / ((1 << bits) - 1);
|
var scale = 255 / ((1 << bits) - 1);
|
||||||
@ -517,7 +517,7 @@ var LabCS = (function LabCSClosure() {
|
|||||||
|
|
||||||
return rgbBuf;
|
return rgbBuf;
|
||||||
},
|
},
|
||||||
isDefaultDecode: function labcs_isDefaultDecode(decodeMap) {
|
isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
|
||||||
// From Table 90 in Adobe's:
|
// From Table 90 in Adobe's:
|
||||||
// "Document management - Portable document format", 1st ed, 2008
|
// "Document management - Portable document format", 1st ed, 2008
|
||||||
if (decodeMap[0] === 0 && decodeMap[1] === 100 &&
|
if (decodeMap[0] === 0 && decodeMap[1] === 100 &&
|
||||||
|
110
src/core.js
110
src/core.js
@ -72,14 +72,14 @@ var Page = (function PageClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Page.prototype = {
|
Page.prototype = {
|
||||||
getPageProp: function pageGetPageProp(key) {
|
getPageProp: function Page_getPageProp(key) {
|
||||||
return this.xref.fetchIfRef(this.pageDict.get(key));
|
return this.pageDict.get(key);
|
||||||
},
|
},
|
||||||
inheritPageProp: function pageInheritPageProp(key) {
|
inheritPageProp: function Page_inheritPageProp(key) {
|
||||||
var dict = this.pageDict;
|
var dict = this.pageDict;
|
||||||
var obj = dict.get(key);
|
var obj = dict.get(key);
|
||||||
while (obj === undefined) {
|
while (obj === undefined) {
|
||||||
dict = this.xref.fetchIfRef(dict.get('Parent'));
|
dict = dict.get('Parent');
|
||||||
if (!dict)
|
if (!dict)
|
||||||
break;
|
break;
|
||||||
obj = dict.get(key);
|
obj = dict.get(key);
|
||||||
@ -170,8 +170,8 @@ var Page = (function PageClosure() {
|
|||||||
return shadow(this, 'rotate', rotate);
|
return shadow(this, 'rotate', rotate);
|
||||||
},
|
},
|
||||||
|
|
||||||
startRenderingFromOperatorList: function pageStartRenderingFromOperatorList(
|
startRenderingFromOperatorList:
|
||||||
operatorList, fonts) {
|
function Page_startRenderingFromOperatorList(operatorList, fonts) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.operatorList = operatorList;
|
this.operatorList = operatorList;
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ var Page = (function PageClosure() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
getOperatorList: function pageGetOperatorList(handler, dependency) {
|
getOperatorList: function Page_getOperatorList(handler, dependency) {
|
||||||
if (this.operatorList) {
|
if (this.operatorList) {
|
||||||
// content was compiled
|
// content was compiled
|
||||||
return this.operatorList;
|
return this.operatorList;
|
||||||
@ -199,8 +199,8 @@ var Page = (function PageClosure() {
|
|||||||
this.stats.time('Build IR Queue');
|
this.stats.time('Build IR Queue');
|
||||||
|
|
||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
var content = xref.fetchIfRef(this.content);
|
var content = this.content;
|
||||||
var resources = xref.fetchIfRef(this.resources);
|
var resources = this.resources;
|
||||||
if (isArray(content)) {
|
if (isArray(content)) {
|
||||||
// fetching items
|
// fetching items
|
||||||
var i, n = content.length;
|
var i, n = content.length;
|
||||||
@ -220,7 +220,7 @@ var Page = (function PageClosure() {
|
|||||||
return this.operatorList;
|
return this.operatorList;
|
||||||
},
|
},
|
||||||
|
|
||||||
ensureFonts: function pageEnsureFonts(fonts, callback) {
|
ensureFonts: function Page_ensureFonts(fonts, callback) {
|
||||||
this.stats.time('Font Loading');
|
this.stats.time('Font Loading');
|
||||||
// Convert the font names to the corresponding font obj.
|
// Convert the font names to the corresponding font obj.
|
||||||
for (var i = 0, ii = fonts.length; i < ii; i++) {
|
for (var i = 0, ii = fonts.length; i < ii; i++) {
|
||||||
@ -238,12 +238,12 @@ var Page = (function PageClosure() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
display: function pageDisplay(gfx, callback) {
|
display: function Page_display(gfx, callback) {
|
||||||
var stats = this.stats;
|
var stats = this.stats;
|
||||||
stats.time('Rendering');
|
stats.time('Rendering');
|
||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
var resources = xref.fetchIfRef(this.resources);
|
var resources = this.resources;
|
||||||
var mediaBox = xref.fetchIfRef(this.mediaBox);
|
var mediaBox = this.mediaBox;
|
||||||
assertWellFormed(isDict(resources), 'invalid page resources');
|
assertWellFormed(isDict(resources), 'invalid page resources');
|
||||||
|
|
||||||
gfx.xref = xref;
|
gfx.xref = xref;
|
||||||
@ -276,7 +276,7 @@ var Page = (function PageClosure() {
|
|||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
rotatePoint: function pageRotatePoint(x, y, reverse) {
|
rotatePoint: function Page_rotatePoint(x, y, reverse) {
|
||||||
var rotate = reverse ? (360 - this.rotate) : this.rotate;
|
var rotate = reverse ? (360 - this.rotate) : this.rotate;
|
||||||
switch (rotate) {
|
switch (rotate) {
|
||||||
case 180:
|
case 180:
|
||||||
@ -291,7 +291,7 @@ var Page = (function PageClosure() {
|
|||||||
return {x: x, y: this.height - y};
|
return {x: x, y: this.height - y};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getLinks: function pageGetLinks() {
|
getLinks: function Page_getLinks() {
|
||||||
var links = [];
|
var links = [];
|
||||||
var annotations = pageGetAnnotations();
|
var annotations = pageGetAnnotations();
|
||||||
var i, n = annotations.length;
|
var i, n = annotations.length;
|
||||||
@ -302,12 +302,12 @@ var Page = (function PageClosure() {
|
|||||||
}
|
}
|
||||||
return links;
|
return links;
|
||||||
},
|
},
|
||||||
getAnnotations: function pageGetAnnotations() {
|
getAnnotations: function Page_getAnnotations() {
|
||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
function getInheritableProperty(annotation, name) {
|
function getInheritableProperty(annotation, name) {
|
||||||
var item = annotation;
|
var item = annotation;
|
||||||
while (item && !item.has(name)) {
|
while (item && !item.has(name)) {
|
||||||
item = xref.fetchIfRef(item.get('Parent'));
|
item = item.get('Parent');
|
||||||
}
|
}
|
||||||
if (!item)
|
if (!item)
|
||||||
return null;
|
return null;
|
||||||
@ -330,7 +330,7 @@ var Page = (function PageClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var annotations = xref.fetchIfRef(this.annotations) || [];
|
var annotations = this.annotations || [];
|
||||||
var i, n = annotations.length;
|
var i, n = annotations.length;
|
||||||
var items = [];
|
var items = [];
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
@ -353,7 +353,7 @@ var Page = (function PageClosure() {
|
|||||||
item.height = Math.abs(topLeftCorner.y - bottomRightCorner.y);
|
item.height = Math.abs(topLeftCorner.y - bottomRightCorner.y);
|
||||||
switch (subtype.name) {
|
switch (subtype.name) {
|
||||||
case 'Link':
|
case 'Link':
|
||||||
var a = this.xref.fetchIfRef(annotation.get('A'));
|
var a = annotation.get('A');
|
||||||
if (a) {
|
if (a) {
|
||||||
switch (a.get('S').name) {
|
switch (a.get('S').name) {
|
||||||
case 'URI':
|
case 'URI':
|
||||||
@ -386,21 +386,22 @@ var Page = (function PageClosure() {
|
|||||||
var fieldName = [];
|
var fieldName = [];
|
||||||
var namedItem = annotation, ref = annotationRef;
|
var namedItem = annotation, ref = annotationRef;
|
||||||
while (namedItem) {
|
while (namedItem) {
|
||||||
var parentRef = namedItem.get('Parent');
|
var parent = namedItem.get('Parent');
|
||||||
var parent = xref.fetchIfRef(parentRef);
|
var parentRef = namedItem.getRaw('Parent');
|
||||||
var name = namedItem.get('T');
|
var name = namedItem.get('T');
|
||||||
if (name)
|
if (name) {
|
||||||
fieldName.unshift(stringToPDFString(name));
|
fieldName.unshift(stringToPDFString(name));
|
||||||
else {
|
} else {
|
||||||
// The field name is absent, that means more than one field
|
// The field name is absent, that means more than one field
|
||||||
// with the same name may exist. Replacing the empty name
|
// with the same name may exist. Replacing the empty name
|
||||||
// with the '`' plus index in the parent's 'Kids' array.
|
// with the '`' plus index in the parent's 'Kids' array.
|
||||||
// This is not in the PDF spec but necessary to id the
|
// This is not in the PDF spec but necessary to id the
|
||||||
// the input controls.
|
// the input controls.
|
||||||
var kids = xref.fetchIfRef(parent.get('Kids'));
|
var kids = parent.get('Kids');
|
||||||
var j, jj;
|
var j, jj;
|
||||||
for (j = 0, jj = kids.length; j < jj; j++) {
|
for (j = 0, jj = kids.length; j < jj; j++) {
|
||||||
if (kids[j].num == ref.num && kids[j].gen == ref.gen)
|
var kidRef = kids[j];
|
||||||
|
if (kidRef.num == ref.num && kidRef.gen == ref.gen)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fieldName.unshift('`' + j);
|
fieldName.unshift('`' + j);
|
||||||
@ -433,7 +434,7 @@ var Page = (function PageClosure() {
|
|||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
},
|
},
|
||||||
startRendering: function pageStartRendering(ctx, callback, textLayer) {
|
startRendering: function Page_startRendering(ctx, callback, textLayer) {
|
||||||
var stats = this.stats;
|
var stats = this.stats;
|
||||||
stats.time('Overall');
|
stats.time('Overall');
|
||||||
// If there is no displayReadyPromise yet, then the operatorList was never
|
// If there is no displayReadyPromise yet, then the operatorList was never
|
||||||
@ -490,7 +491,7 @@ var PDFDocModel = (function PDFDocModelClosure() {
|
|||||||
assertWellFormed(stream.length > 0, 'stream must have data');
|
assertWellFormed(stream.length > 0, 'stream must have data');
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.setup();
|
this.setup();
|
||||||
this.acroForm = this.xref.fetchIfRef(this.catalog.catDict.get('AcroForm'));
|
this.acroForm = this.catalog.catDict.get('AcroForm');
|
||||||
}
|
}
|
||||||
|
|
||||||
function find(stream, needle, limit, backwards) {
|
function find(stream, needle, limit, backwards) {
|
||||||
@ -570,7 +571,7 @@ var PDFDocModel = (function PDFDocModelClosure() {
|
|||||||
},
|
},
|
||||||
// Find the header, remove leading garbage and setup the stream
|
// Find the header, remove leading garbage and setup the stream
|
||||||
// starting from the header.
|
// starting from the header.
|
||||||
checkHeader: function pdfDocCheckHeader() {
|
checkHeader: function PDFDocModel_checkHeader() {
|
||||||
var stream = this.stream;
|
var stream = this.stream;
|
||||||
stream.reset();
|
stream.reset();
|
||||||
if (find(stream, '%PDF-', 1024)) {
|
if (find(stream, '%PDF-', 1024)) {
|
||||||
@ -580,21 +581,13 @@ var PDFDocModel = (function PDFDocModelClosure() {
|
|||||||
}
|
}
|
||||||
// May not be a PDF file, continue anyway.
|
// May not be a PDF file, continue anyway.
|
||||||
},
|
},
|
||||||
setup: function pdfDocSetup(ownerPassword, userPassword) {
|
setup: function PDFDocModel_setup(ownerPassword, userPassword) {
|
||||||
this.checkHeader();
|
this.checkHeader();
|
||||||
var xref = new XRef(this.stream,
|
var xref = new XRef(this.stream,
|
||||||
this.startXRef,
|
this.startXRef,
|
||||||
this.mainXRefEntriesOffset);
|
this.mainXRefEntriesOffset);
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
this.catalog = new Catalog(xref);
|
this.catalog = new Catalog(xref);
|
||||||
if (xref.trailer && xref.trailer.has('ID')) {
|
|
||||||
var fileID = '';
|
|
||||||
var id = xref.fetchIfRef(xref.trailer.get('ID'))[0];
|
|
||||||
id.split('').forEach(function(el) {
|
|
||||||
fileID += Number(el.charCodeAt(0)).toString(16);
|
|
||||||
});
|
|
||||||
this.fileID = fileID;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
get numPages() {
|
get numPages() {
|
||||||
var linearization = this.linearization;
|
var linearization = this.linearization;
|
||||||
@ -602,23 +595,35 @@ var PDFDocModel = (function PDFDocModelClosure() {
|
|||||||
// shadow the prototype getter
|
// shadow the prototype getter
|
||||||
return shadow(this, 'numPages', num);
|
return shadow(this, 'numPages', num);
|
||||||
},
|
},
|
||||||
getFingerprint: function pdfDocGetFingerprint() {
|
getDocumentInfo: function PDFDocModel_getDocumentInfo() {
|
||||||
if (this.fileID) {
|
var info;
|
||||||
return this.fileID;
|
if (this.xref.trailer.has('Info'))
|
||||||
|
info = this.xref.trailer.get('Info');
|
||||||
|
|
||||||
|
return shadow(this, 'getDocumentInfo', info);
|
||||||
|
},
|
||||||
|
getFingerprint: function PDFDocModel_getFingerprint() {
|
||||||
|
var xref = this.xref, fileID;
|
||||||
|
if (xref.trailer.has('ID')) {
|
||||||
|
fileID = '';
|
||||||
|
var id = xref.trailer.get('ID')[0];
|
||||||
|
id.split('').forEach(function(el) {
|
||||||
|
fileID += Number(el.charCodeAt(0)).toString(16);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// If we got no fileID, then we generate one,
|
// If we got no fileID, then we generate one,
|
||||||
// from the first 100 bytes of PDF
|
// from the first 100 bytes of PDF
|
||||||
var data = this.stream.bytes.subarray(0, 100);
|
var data = this.stream.bytes.subarray(0, 100);
|
||||||
var hash = calculateMD5(data, 0, data.length);
|
var hash = calculateMD5(data, 0, data.length);
|
||||||
var strHash = '';
|
fileID = '';
|
||||||
for (var i = 0, length = hash.length; i < length; i++) {
|
for (var i = 0, length = hash.length; i < length; i++) {
|
||||||
strHash += Number(hash[i]).toString(16);
|
fileID += Number(hash[i]).toString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
return strHash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return shadow(this, 'getFingerprint', fileID);
|
||||||
},
|
},
|
||||||
getPage: function pdfDocGetPage(n) {
|
getPage: function PDFDocModel_getPage(n) {
|
||||||
return this.catalog.getPage(n);
|
return this.catalog.getPage(n);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -645,6 +650,7 @@ var PDFDoc = (function PDFDocClosure() {
|
|||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.pdfModel = new PDFDocModel(stream);
|
this.pdfModel = new PDFDocModel(stream);
|
||||||
this.fingerprint = this.pdfModel.getFingerprint();
|
this.fingerprint = this.pdfModel.getFingerprint();
|
||||||
|
this.info = this.pdfModel.getDocumentInfo();
|
||||||
this.catalog = this.pdfModel.catalog;
|
this.catalog = this.pdfModel.catalog;
|
||||||
this.objs = new PDFObjects();
|
this.objs = new PDFObjects();
|
||||||
|
|
||||||
@ -706,13 +712,13 @@ var PDFDoc = (function PDFDocClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PDFDoc.prototype = {
|
PDFDoc.prototype = {
|
||||||
setupFakeWorker: function() {
|
setupFakeWorker: function PDFDoc_setupFakeWorker() {
|
||||||
// If we don't use a worker, just post/sendMessage to the main thread.
|
// If we don't use a worker, just post/sendMessage to the main thread.
|
||||||
var fakeWorker = {
|
var fakeWorker = {
|
||||||
postMessage: function pdfDocPostMessage(obj) {
|
postMessage: function PDFDoc_postMessage(obj) {
|
||||||
fakeWorker.onmessage({data: obj});
|
fakeWorker.onmessage({data: obj});
|
||||||
},
|
},
|
||||||
terminate: function pdfDocTerminate() {}
|
terminate: function PDFDoc_terminate() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
var messageHandler = new MessageHandler('main', fakeWorker);
|
var messageHandler = new MessageHandler('main', fakeWorker);
|
||||||
@ -724,7 +730,7 @@ var PDFDoc = (function PDFDocClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
setupMessageHandler: function(messageHandler) {
|
setupMessageHandler: function PDFDoc_setupMessageHandler(messageHandler) {
|
||||||
this.messageHandler = messageHandler;
|
this.messageHandler = messageHandler;
|
||||||
|
|
||||||
messageHandler.on('page', function pdfDocPage(data) {
|
messageHandler.on('page', function pdfDocPage(data) {
|
||||||
@ -823,7 +829,7 @@ var PDFDoc = (function PDFDocClosure() {
|
|||||||
return this.pdfModel.numPages;
|
return this.pdfModel.numPages;
|
||||||
},
|
},
|
||||||
|
|
||||||
startRendering: function pdfDocStartRendering(page) {
|
startRendering: function PDFDoc_startRendering(page) {
|
||||||
// The worker might not be ready to receive the page request yet.
|
// The worker might not be ready to receive the page request yet.
|
||||||
this.workerReadyPromise.then(function pdfDocStartRenderingThen() {
|
this.workerReadyPromise.then(function pdfDocStartRenderingThen() {
|
||||||
page.stats.time('Page Request');
|
page.stats.time('Page Request');
|
||||||
@ -831,7 +837,7 @@ var PDFDoc = (function PDFDocClosure() {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
getPage: function pdfDocGetPage(n) {
|
getPage: function PDFDoc_getPage(n) {
|
||||||
if (this.pageCache[n])
|
if (this.pageCache[n])
|
||||||
return this.pageCache[n];
|
return this.pageCache[n];
|
||||||
|
|
||||||
@ -843,7 +849,7 @@ var PDFDoc = (function PDFDocClosure() {
|
|||||||
return (this.pageCache[n] = page);
|
return (this.pageCache[n] = page);
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function pdfDocDestroy() {
|
destroy: function PDFDoc_destroy() {
|
||||||
if (this.worker)
|
if (this.worker)
|
||||||
this.worker.terminate();
|
this.worker.terminate();
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ var ARCFourCipher = (function ARCFourCipherClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ARCFourCipher.prototype = {
|
ARCFourCipher.prototype = {
|
||||||
encryptBlock: function arcFourCipherEncryptBlock(data) {
|
encryptBlock: function ARCFourCipher_encryptBlock(data) {
|
||||||
var i, n = data.length, tmp, tmp2;
|
var i, n = data.length, tmp, tmp2;
|
||||||
var a = this.a, b = this.b, s = this.s;
|
var a = this.a, b = this.b, s = this.s;
|
||||||
var output = new Uint8Array(n);
|
var output = new Uint8Array(n);
|
||||||
@ -133,7 +133,7 @@ var NullCipher = (function NullCipherClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NullCipher.prototype = {
|
NullCipher.prototype = {
|
||||||
decryptBlock: function nullCipherDecryptBlock(data) {
|
decryptBlock: function NullCipher_decryptBlock(data) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -371,7 +371,7 @@ var AES128Cipher = (function AES128CipherClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AES128Cipher.prototype = {
|
AES128Cipher.prototype = {
|
||||||
decryptBlock: function aes128CipherDecryptBlock(data) {
|
decryptBlock: function AES128Cipher_decryptBlock(data) {
|
||||||
var i, sourceLength = data.length;
|
var i, sourceLength = data.length;
|
||||||
var buffer = this.buffer, bufferLength = this.bufferPosition;
|
var buffer = this.buffer, bufferLength = this.bufferPosition;
|
||||||
// waiting for IV values -- they are at the start of the stream
|
// waiting for IV values -- they are at the start of the stream
|
||||||
@ -400,7 +400,7 @@ var CipherTransform = (function CipherTransformClosure() {
|
|||||||
this.streamCipherConstructor = streamCipherConstructor;
|
this.streamCipherConstructor = streamCipherConstructor;
|
||||||
}
|
}
|
||||||
CipherTransform.prototype = {
|
CipherTransform.prototype = {
|
||||||
createStream: function cipherTransformCreateStream(stream) {
|
createStream: function CipherTransform_createStream(stream) {
|
||||||
var cipher = new this.streamCipherConstructor();
|
var cipher = new this.streamCipherConstructor();
|
||||||
return new DecryptStream(stream,
|
return new DecryptStream(stream,
|
||||||
function cipherTransformDecryptStream(data) {
|
function cipherTransformDecryptStream(data) {
|
||||||
@ -408,7 +408,7 @@ var CipherTransform = (function CipherTransformClosure() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
decryptString: function cipherTransformDecryptString(s) {
|
decryptString: function CipherTransform_decryptString(s) {
|
||||||
var cipher = new this.stringCipherConstructor();
|
var cipher = new this.stringCipherConstructor();
|
||||||
var data = stringToBytes(s);
|
var data = stringToBytes(s);
|
||||||
data = cipher.decryptBlock(data);
|
data = cipher.decryptBlock(data);
|
||||||
@ -573,8 +573,8 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CipherTransformFactory.prototype = {
|
CipherTransformFactory.prototype = {
|
||||||
createCipherTransform: function buildCipherCreateCipherTransform(num,
|
createCipherTransform:
|
||||||
gen) {
|
function CipherTransformFactory_createCipherTransform(num, gen) {
|
||||||
if (this.algorithm == 4) {
|
if (this.algorithm == 4) {
|
||||||
return new CipherTransform(
|
return new CipherTransform(
|
||||||
buildCipherConstructor(this.cf, this.stmf,
|
buildCipherConstructor(this.cf, this.stmf,
|
||||||
|
101
src/evaluator.js
101
src/evaluator.js
@ -112,8 +112,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PartialEvaluator.prototype = {
|
PartialEvaluator.prototype = {
|
||||||
getOperatorList: function partialEvaluatorGetOperatorList(stream, resources,
|
getOperatorList: function PartialEvaluator_getOperatorList(stream,
|
||||||
dependency, queue) {
|
resources,
|
||||||
|
dependency,
|
||||||
|
queue) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
@ -131,16 +133,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSetFont(fontName, fontRef) {
|
function handleSetFont(fontName, font) {
|
||||||
var loadedName = null;
|
var loadedName = null;
|
||||||
|
|
||||||
var fontRes = resources.get('Font');
|
var fontRes = resources.get('Font');
|
||||||
|
|
||||||
assert(fontRes, 'fontRes not available');
|
assert(fontRes, 'fontRes not available');
|
||||||
|
|
||||||
fontRes = xref.fetchIfRef(fontRes);
|
font = xref.fetchIfRef(font) || fontRes.get(fontName);
|
||||||
fontRef = fontRef || fontRes.get(fontName);
|
|
||||||
var font = xref.fetchIfRef(fontRef);
|
|
||||||
assertWellFormed(isDict(font));
|
assertWellFormed(isDict(font));
|
||||||
if (!font.translated) {
|
if (!font.translated) {
|
||||||
font.translated = self.translateFont(font, xref, resources,
|
font.translated = self.translateFont(font, xref, resources,
|
||||||
@ -250,10 +250,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var fnArray = queue.fnArray, argsArray = queue.argsArray;
|
var fnArray = queue.fnArray, argsArray = queue.argsArray;
|
||||||
var dependencyArray = dependency || [];
|
var dependencyArray = dependency || [];
|
||||||
|
|
||||||
resources = xref.fetchIfRef(resources) || new Dict();
|
resources = resources || new Dict();
|
||||||
var xobjs = xref.fetchIfRef(resources.get('XObject')) || new Dict();
|
var xobjs = resources.get('XObject') || new Dict();
|
||||||
var patterns = xref.fetchIfRef(resources.get('Pattern')) || new Dict();
|
var patterns = resources.get('Pattern') || new Dict();
|
||||||
var parser = new Parser(new Lexer(stream), false);
|
var parser = new Parser(new Lexer(stream), false, xref);
|
||||||
var res = resources;
|
var res = resources;
|
||||||
var args = [], obj;
|
var args = [], obj;
|
||||||
var getObjBt = function getObjBt() {
|
var getObjBt = function getObjBt() {
|
||||||
@ -285,7 +285,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var patternName = args[args.length - 1];
|
var patternName = args[args.length - 1];
|
||||||
// SCN/scn applies patterns along with normal colors
|
// SCN/scn applies patterns along with normal colors
|
||||||
if (isName(patternName)) {
|
if (isName(patternName)) {
|
||||||
var pattern = xref.fetchIfRef(patterns.get(patternName.name));
|
var pattern = patterns.get(patternName.name);
|
||||||
if (pattern) {
|
if (pattern) {
|
||||||
var dict = isStream(pattern) ? pattern.dict : pattern;
|
var dict = isStream(pattern) ? pattern.dict : pattern;
|
||||||
var typeNum = dict.get('PatternType');
|
var typeNum = dict.get('PatternType');
|
||||||
@ -303,7 +303,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
args = TilingPattern.getIR(operatorList, dict, args);
|
args = TilingPattern.getIR(operatorList, dict, args);
|
||||||
}
|
}
|
||||||
else if (typeNum == SHADING_PATTERN) {
|
else if (typeNum == SHADING_PATTERN) {
|
||||||
var shading = xref.fetchIfRef(dict.get('Shading'));
|
var shading = dict.get('Shading');
|
||||||
var matrix = dict.get('Matrix');
|
var matrix = dict.get('Matrix');
|
||||||
var pattern = Pattern.parseShading(shading, matrix, xref,
|
var pattern = Pattern.parseShading(shading, matrix, xref,
|
||||||
res);
|
res);
|
||||||
@ -318,7 +318,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var name = args[0].name;
|
var name = args[0].name;
|
||||||
var xobj = xobjs.get(name);
|
var xobj = xobjs.get(name);
|
||||||
if (xobj) {
|
if (xobj) {
|
||||||
xobj = xref.fetchIfRef(xobj);
|
|
||||||
assertWellFormed(isStream(xobj), 'XObject should be a stream');
|
assertWellFormed(isStream(xobj), 'XObject should be a stream');
|
||||||
|
|
||||||
var type = xobj.dict.get('Subtype');
|
var type = xobj.dict.get('Subtype');
|
||||||
@ -369,11 +368,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
args = [ColorSpace.parseToIR(args[0], xref, resources)];
|
args = [ColorSpace.parseToIR(args[0], xref, resources)];
|
||||||
break;
|
break;
|
||||||
case 'shadingFill':
|
case 'shadingFill':
|
||||||
var shadingRes = xref.fetchIfRef(res.get('Shading'));
|
var shadingRes = res.get('Shading');
|
||||||
if (!shadingRes)
|
if (!shadingRes)
|
||||||
error('No shading resource found');
|
error('No shading resource found');
|
||||||
|
|
||||||
var shading = xref.fetchIfRef(shadingRes.get(args[0].name));
|
var shading = shadingRes.get(args[0].name);
|
||||||
if (!shading)
|
if (!shading)
|
||||||
error('No shading object found');
|
error('No shading object found');
|
||||||
|
|
||||||
@ -384,12 +383,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
break;
|
break;
|
||||||
case 'setGState':
|
case 'setGState':
|
||||||
var dictName = args[0];
|
var dictName = args[0];
|
||||||
var extGState = xref.fetchIfRef(resources.get('ExtGState'));
|
var extGState = resources.get('ExtGState');
|
||||||
|
|
||||||
if (!isDict(extGState) || !extGState.has(dictName.name))
|
if (!isDict(extGState) || !extGState.has(dictName.name))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
var gsState = xref.fetchIfRef(extGState.get(dictName.name));
|
var gsState = extGState.get(dictName.name);
|
||||||
|
|
||||||
// This array holds the converted/processed state data.
|
// This array holds the converted/processed state data.
|
||||||
var gsStateObj = [];
|
var gsStateObj = [];
|
||||||
@ -468,7 +467,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
if (properties.composite) {
|
if (properties.composite) {
|
||||||
// CIDSystemInfo helps to match CID to glyphs
|
// CIDSystemInfo helps to match CID to glyphs
|
||||||
var cidSystemInfo = xref.fetchIfRef(dict.get('CIDSystemInfo'));
|
var cidSystemInfo = dict.get('CIDSystemInfo');
|
||||||
if (isDict(cidSystemInfo)) {
|
if (isDict(cidSystemInfo)) {
|
||||||
properties.cidSystemInfo = {
|
properties.cidSystemInfo = {
|
||||||
registry: cidSystemInfo.get('Registry'),
|
registry: cidSystemInfo.get('Registry'),
|
||||||
@ -477,7 +476,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var cidToGidMap = xref.fetchIfRef(dict.get('CIDToGIDMap'));
|
var cidToGidMap = dict.get('CIDToGIDMap');
|
||||||
if (isStream(cidToGidMap))
|
if (isStream(cidToGidMap))
|
||||||
properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
|
properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
|
||||||
}
|
}
|
||||||
@ -488,7 +487,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
Encodings.symbolsEncoding : Encodings.StandardEncoding;
|
Encodings.symbolsEncoding : Encodings.StandardEncoding;
|
||||||
var hasEncoding = dict.has('Encoding');
|
var hasEncoding = dict.has('Encoding');
|
||||||
if (hasEncoding) {
|
if (hasEncoding) {
|
||||||
var encoding = xref.fetchIfRef(dict.get('Encoding'));
|
var encoding = dict.get('Encoding');
|
||||||
if (isDict(encoding)) {
|
if (isDict(encoding)) {
|
||||||
var baseName = encoding.get('BaseEncoding');
|
var baseName = encoding.get('BaseEncoding');
|
||||||
if (baseName)
|
if (baseName)
|
||||||
@ -520,9 +519,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
properties.hasEncoding = hasEncoding;
|
properties.hasEncoding = hasEncoding;
|
||||||
},
|
},
|
||||||
|
|
||||||
readToUnicode:
|
readToUnicode: function PartialEvaluator_readToUnicode(toUnicode, xref) {
|
||||||
function partialEvaluatorReadToUnicode(toUnicode, xref) {
|
var cmapObj = toUnicode;
|
||||||
var cmapObj = xref.fetchIfRef(toUnicode);
|
|
||||||
var charToUnicode = [];
|
var charToUnicode = [];
|
||||||
if (isName(cmapObj)) {
|
if (isName(cmapObj)) {
|
||||||
var isIdentityMap = cmapObj.name.substr(0, 9) == 'Identity-';
|
var isIdentityMap = cmapObj.name.substr(0, 9) == 'Identity-';
|
||||||
@ -535,9 +533,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
var cmap = cmapObj.getBytes(cmapObj.length);
|
var cmap = cmapObj.getBytes(cmapObj.length);
|
||||||
for (var i = 0, ii = cmap.length; i < ii; i++) {
|
for (var i = 0, ii = cmap.length; i < ii; i++) {
|
||||||
var byte = cmap[i];
|
var octet = cmap[i];
|
||||||
if (byte == 0x20 || byte == 0x0D || byte == 0x0A ||
|
if (octet == 0x20 || octet == 0x0D || octet == 0x0A ||
|
||||||
byte == 0x3C || byte == 0x5B || byte == 0x5D) {
|
octet == 0x3C || octet == 0x5B || octet == 0x5D) {
|
||||||
switch (token) {
|
switch (token) {
|
||||||
case 'usecmap':
|
case 'usecmap':
|
||||||
error('usecmap is not implemented');
|
error('usecmap is not implemented');
|
||||||
@ -594,7 +592,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
tokens.push(token);
|
tokens.push(token);
|
||||||
token = '';
|
token = '';
|
||||||
}
|
}
|
||||||
switch (byte) {
|
switch (octet) {
|
||||||
case 0x5B:
|
case 0x5B:
|
||||||
// begin list parsing
|
// begin list parsing
|
||||||
tokens.push(beginArrayToken);
|
tokens.push(beginArrayToken);
|
||||||
@ -608,7 +606,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
tokens.push(items);
|
tokens.push(items);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (byte == 0x3E) {
|
} else if (octet == 0x3E) {
|
||||||
if (token.length) {
|
if (token.length) {
|
||||||
if (token.length <= 4) {
|
if (token.length <= 4) {
|
||||||
// parsing hex number
|
// parsing hex number
|
||||||
@ -634,14 +632,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token += String.fromCharCode(byte);
|
token += String.fromCharCode(octet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return charToUnicode;
|
return charToUnicode;
|
||||||
},
|
},
|
||||||
readCidToGidMap:
|
readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
|
||||||
function partialEvaluatorReadCidToGidMap(cidToGidStream) {
|
|
||||||
// Extract the encoding from the CIDToGIDMap
|
// Extract the encoding from the CIDToGIDMap
|
||||||
var glyphsData = cidToGidStream.getBytes();
|
var glyphsData = cidToGidStream.getBytes();
|
||||||
|
|
||||||
@ -658,16 +655,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
extractWidths: function partialEvaluatorWidths(dict,
|
extractWidths: function PartialEvaluator_extractWidths(dict,
|
||||||
xref,
|
xref,
|
||||||
descriptor,
|
descriptor,
|
||||||
properties) {
|
properties) {
|
||||||
var glyphsWidths = [];
|
var glyphsWidths = [];
|
||||||
var defaultWidth = 0;
|
var defaultWidth = 0;
|
||||||
if (properties.composite) {
|
if (properties.composite) {
|
||||||
defaultWidth = xref.fetchIfRef(dict.get('DW')) || 1000;
|
defaultWidth = dict.get('DW') || 1000;
|
||||||
|
|
||||||
var widths = xref.fetchIfRef(dict.get('W'));
|
var widths = dict.get('W');
|
||||||
if (widths) {
|
if (widths) {
|
||||||
var start = 0, end = 0;
|
var start = 0, end = 0;
|
||||||
for (var i = 0, ii = widths.length; i < ii; i++) {
|
for (var i = 0, ii = widths.length; i < ii; i++) {
|
||||||
@ -688,7 +685,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var firstChar = properties.firstChar;
|
var firstChar = properties.firstChar;
|
||||||
var widths = xref.fetchIfRef(dict.get('Widths'));
|
var widths = dict.get('Widths');
|
||||||
if (widths) {
|
if (widths) {
|
||||||
var j = firstChar;
|
var j = firstChar;
|
||||||
for (var i = 0, ii = widths.length; i < ii; i++)
|
for (var i = 0, ii = widths.length; i < ii; i++)
|
||||||
@ -710,7 +707,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
properties.widths = glyphsWidths;
|
properties.widths = glyphsWidths;
|
||||||
},
|
},
|
||||||
|
|
||||||
getBaseFontMetrics: function getBaseFontMetrics(name) {
|
getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
|
||||||
var defaultWidth = 0, widths = [];
|
var defaultWidth = 0, widths = [];
|
||||||
var glyphWidths = Metrics[stdFontMap[name] || name];
|
var glyphWidths = Metrics[stdFontMap[name] || name];
|
||||||
if (isNum(glyphWidths)) {
|
if (isNum(glyphWidths)) {
|
||||||
@ -725,8 +722,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
translateFont: function partialEvaluatorTranslateFont(dict, xref, resources,
|
translateFont: function PartialEvaluator_translateFont(dict,
|
||||||
dependency) {
|
xref,
|
||||||
|
resources,
|
||||||
|
dependency) {
|
||||||
var baseDict = dict;
|
var baseDict = dict;
|
||||||
var type = dict.get('Subtype');
|
var type = dict.get('Subtype');
|
||||||
assertWellFormed(isName(type), 'invalid font Subtype');
|
assertWellFormed(isName(type), 'invalid font Subtype');
|
||||||
@ -741,10 +740,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (!df)
|
if (!df)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (isRef(df))
|
dict = isArray(df) ? xref.fetchIfRef(df[0]) : df;
|
||||||
df = xref.fetch(df);
|
|
||||||
|
|
||||||
dict = xref.fetchIfRef(isRef(df) ? df : df[0]);
|
|
||||||
|
|
||||||
type = dict.get('Subtype');
|
type = dict.get('Subtype');
|
||||||
assertWellFormed(isName(type), 'invalid font Subtype');
|
assertWellFormed(isName(type), 'invalid font Subtype');
|
||||||
@ -752,7 +748,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
var maxCharIndex = composite ? 0xFFFF : 0xFF;
|
var maxCharIndex = composite ? 0xFFFF : 0xFF;
|
||||||
|
|
||||||
var descriptor = xref.fetchIfRef(dict.get('FontDescriptor'));
|
var descriptor = dict.get('FontDescriptor');
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
if (type.name == 'Type3') {
|
if (type.name == 'Type3') {
|
||||||
// FontDescriptor is only required for Type3 fonts when the document
|
// FontDescriptor is only required for Type3 fonts when the document
|
||||||
@ -801,9 +797,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
// to ignore this rule when a variant of a standart font is used.
|
// to ignore this rule when a variant of a standart font is used.
|
||||||
// TODO Fill the width array depending on which of the base font this is
|
// TODO Fill the width array depending on which of the base font this is
|
||||||
// a variant.
|
// a variant.
|
||||||
var firstChar = xref.fetchIfRef(dict.get('FirstChar')) || 0;
|
var firstChar = dict.get('FirstChar') || 0;
|
||||||
var lastChar = xref.fetchIfRef(dict.get('LastChar')) || maxCharIndex;
|
var lastChar = dict.get('LastChar') || maxCharIndex;
|
||||||
var fontName = xref.fetchIfRef(descriptor.get('FontName'));
|
var fontName = descriptor.get('FontName');
|
||||||
// Some bad pdf's have a string as the font name.
|
// Some bad pdf's have a string as the font name.
|
||||||
if (isString(fontName))
|
if (isString(fontName))
|
||||||
fontName = new Name(fontName);
|
fontName = new Name(fontName);
|
||||||
@ -811,19 +807,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
|
var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
|
||||||
if (fontFile) {
|
if (fontFile) {
|
||||||
fontFile = xref.fetchIfRef(fontFile);
|
|
||||||
if (fontFile.dict) {
|
if (fontFile.dict) {
|
||||||
var subtype = fontFile.dict.get('Subtype');
|
var subtype = fontFile.dict.get('Subtype');
|
||||||
if (subtype)
|
if (subtype)
|
||||||
subtype = subtype.name;
|
subtype = subtype.name;
|
||||||
|
|
||||||
var length1 = fontFile.dict.get('Length1');
|
var length1 = fontFile.dict.get('Length1');
|
||||||
if (!isInt(length1))
|
|
||||||
length1 = xref.fetchIfRef(length1);
|
|
||||||
|
|
||||||
var length2 = fontFile.dict.get('Length2');
|
var length2 = fontFile.dict.get('Length2');
|
||||||
if (!isInt(length2))
|
|
||||||
length2 = xref.fetchIfRef(length2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -852,12 +843,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
if (type.name === 'Type3') {
|
if (type.name === 'Type3') {
|
||||||
properties.coded = true;
|
properties.coded = true;
|
||||||
var charProcs = xref.fetchIfRef(dict.get('CharProcs'));
|
var charProcs = dict.get('CharProcs').getAll();
|
||||||
var fontResources = xref.fetchIfRef(dict.get('Resources')) || resources;
|
var fontResources = dict.get('Resources') || resources;
|
||||||
properties.resources = fontResources;
|
properties.resources = fontResources;
|
||||||
properties.charProcOperatorList = {};
|
properties.charProcOperatorList = {};
|
||||||
for (var key in charProcs.map) {
|
for (var key in charProcs) {
|
||||||
var glyphStream = xref.fetchIfRef(charProcs.map[key]);
|
var glyphStream = charProcs[key];
|
||||||
properties.charProcOperatorList[key] =
|
properties.charProcOperatorList[key] =
|
||||||
this.getOperatorList(glyphStream, fontResources, dependency);
|
this.getOperatorList(glyphStream, fontResources, dependency);
|
||||||
}
|
}
|
||||||
|
205
src/fonts.js
205
src/fonts.js
@ -1267,7 +1267,7 @@ var Font = (function FontClosure() {
|
|||||||
mimetype: null,
|
mimetype: null,
|
||||||
encoding: null,
|
encoding: null,
|
||||||
|
|
||||||
checkAndRepair: function font_checkAndRepair(name, font, properties) {
|
checkAndRepair: function Font_checkAndRepair(name, font, properties) {
|
||||||
function readTableEntry(file) {
|
function readTableEntry(file) {
|
||||||
var tag = file.getBytes(4);
|
var tag = file.getBytes(4);
|
||||||
tag = String.fromCharCode(tag[0]) +
|
tag = String.fromCharCode(tag[0]) +
|
||||||
@ -1828,8 +1828,9 @@ var Font = (function FontClosure() {
|
|||||||
readGlyphNameMap(post, properties);
|
readGlyphNameMap(post, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace the old CMAP table with a shiny new one
|
var glyphs, ids;
|
||||||
if (properties.type == 'CIDFontType2') {
|
if (properties.type == 'CIDFontType2') {
|
||||||
|
// Replace the old CMAP table with a shiny new one
|
||||||
// Type2 composite fonts map characters directly to glyphs so the cmap
|
// Type2 composite fonts map characters directly to glyphs so the cmap
|
||||||
// table must be replaced.
|
// table must be replaced.
|
||||||
// canvas fillText will reencode some characters even if the font has a
|
// canvas fillText will reencode some characters even if the font has a
|
||||||
@ -1861,7 +1862,9 @@ var Font = (function FontClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var glyphs = [], ids = [];
|
glyphs = [];
|
||||||
|
ids = [];
|
||||||
|
|
||||||
var usedUnicodes = [];
|
var usedUnicodes = [];
|
||||||
var unassignedUnicodeItems = [];
|
var unassignedUnicodeItems = [];
|
||||||
for (var i = 1; i < numGlyphs; i++) {
|
for (var i = 1; i < numGlyphs; i++) {
|
||||||
@ -1892,11 +1895,12 @@ var Font = (function FontClosure() {
|
|||||||
glyphs.push({ unicode: unicode, code: cid });
|
glyphs.push({ unicode: unicode, code: cid });
|
||||||
ids.push(i);
|
ids.push(i);
|
||||||
}
|
}
|
||||||
cmap.data = createCMapTable(glyphs, ids);
|
|
||||||
} else {
|
} else {
|
||||||
var cmapTable = readCMapTable(cmap, font);
|
var cmapTable = readCMapTable(cmap, font);
|
||||||
var glyphs = cmapTable.glyphs;
|
|
||||||
var ids = cmapTable.ids;
|
glyphs = cmapTable.glyphs;
|
||||||
|
ids = cmapTable.ids;
|
||||||
|
|
||||||
var hasShortCmap = !!cmapTable.hasShortCmap;
|
var hasShortCmap = !!cmapTable.hasShortCmap;
|
||||||
var toFontChar = this.toFontChar;
|
var toFontChar = this.toFontChar;
|
||||||
|
|
||||||
@ -2062,10 +2066,16 @@ var Font = (function FontClosure() {
|
|||||||
|
|
||||||
createGlyphNameMap(glyphs, ids, properties);
|
createGlyphNameMap(glyphs, ids, properties);
|
||||||
this.glyphNameMap = properties.glyphNameMap;
|
this.glyphNameMap = properties.glyphNameMap;
|
||||||
|
|
||||||
cmap.data = createCMapTable(glyphs, ids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Converting glyphs and ids into font's cmap table
|
||||||
|
cmap.data = createCMapTable(glyphs, ids);
|
||||||
|
var unicodeIsEnabled = [];
|
||||||
|
for (var i = 0, ii = glyphs.length; i < ii; i++) {
|
||||||
|
unicodeIsEnabled[glyphs[i].unicode] = true;
|
||||||
|
}
|
||||||
|
this.unicodeIsEnabled = unicodeIsEnabled;
|
||||||
|
|
||||||
// Rewrite the 'post' table if needed
|
// Rewrite the 'post' table if needed
|
||||||
if (requiredTables.indexOf('post') != -1) {
|
if (requiredTables.indexOf('post') != -1) {
|
||||||
tables.push({
|
tables.push({
|
||||||
@ -2112,7 +2122,7 @@ var Font = (function FontClosure() {
|
|||||||
return stringToArray(ttf.file);
|
return stringToArray(ttf.file);
|
||||||
},
|
},
|
||||||
|
|
||||||
convert: function font_convert(fontName, font, properties) {
|
convert: function Font_convert(fontName, font, properties) {
|
||||||
function isFixedPitch(glyphs) {
|
function isFixedPitch(glyphs) {
|
||||||
for (var i = 0, ii = glyphs.length - 1; i < ii; i++) {
|
for (var i = 0, ii = glyphs.length - 1; i < ii; i++) {
|
||||||
if (glyphs[i] != glyphs[i + 1])
|
if (glyphs[i] != glyphs[i + 1])
|
||||||
@ -2254,7 +2264,7 @@ var Font = (function FontClosure() {
|
|||||||
return stringToArray(otf.file);
|
return stringToArray(otf.file);
|
||||||
},
|
},
|
||||||
|
|
||||||
buildToFontChar: function font_buildToFontChar(toUnicode) {
|
buildToFontChar: function Font_buildToFontChar(toUnicode) {
|
||||||
var result = [];
|
var result = [];
|
||||||
var unusedUnicode = kCmapGlyphOffset;
|
var unusedUnicode = kCmapGlyphOffset;
|
||||||
for (var i = 0, ii = toUnicode.length; i < ii; i++) {
|
for (var i = 0, ii = toUnicode.length; i < ii; i++) {
|
||||||
@ -2267,7 +2277,7 @@ var Font = (function FontClosure() {
|
|||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
rebuildToUnicode: function font_rebuildToUnicode(properties) {
|
rebuildToUnicode: function Font_rebuildToUnicode(properties) {
|
||||||
var firstChar = properties.firstChar, lastChar = properties.lastChar;
|
var firstChar = properties.firstChar, lastChar = properties.lastChar;
|
||||||
var map = [];
|
var map = [];
|
||||||
if (properties.composite) {
|
if (properties.composite) {
|
||||||
@ -2289,7 +2299,7 @@ var Font = (function FontClosure() {
|
|||||||
this.toUnicode = map;
|
this.toUnicode = map;
|
||||||
},
|
},
|
||||||
|
|
||||||
loadCidToUnicode: function font_loadCidToUnicode(properties) {
|
loadCidToUnicode: function Font_loadCidToUnicode(properties) {
|
||||||
if (!properties.cidSystemInfo)
|
if (!properties.cidSystemInfo)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -2338,7 +2348,7 @@ var Font = (function FontClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
bindDOM: function font_bindDom(data) {
|
bindDOM: function Font_bindDOM(data) {
|
||||||
var fontName = this.loadedName;
|
var fontName = this.loadedName;
|
||||||
|
|
||||||
// Add the font-face rule to the document
|
// Add the font-face rule to the document
|
||||||
@ -2390,8 +2400,8 @@ var Font = (function FontClosure() {
|
|||||||
return shadow(this, 'spaceWidth', width);
|
return shadow(this, 'spaceWidth', width);
|
||||||
},
|
},
|
||||||
|
|
||||||
charToGlyph: function fonts_charToGlyph(charcode) {
|
charToGlyph: function Font_charToGlyph(charcode) {
|
||||||
var fontCharCode, width, operatorList;
|
var fontCharCode, width, operatorList, disabled;
|
||||||
|
|
||||||
var width = this.widths[charcode];
|
var width = this.widths[charcode];
|
||||||
|
|
||||||
@ -2464,16 +2474,19 @@ var Font = (function FontClosure() {
|
|||||||
unicodeChars = String.fromCharCode(unicodeChars);
|
unicodeChars = String.fromCharCode(unicodeChars);
|
||||||
|
|
||||||
width = (isNum(width) ? width : this.defaultWidth) * this.widthMultiplier;
|
width = (isNum(width) ? width : this.defaultWidth) * this.widthMultiplier;
|
||||||
|
disabled = this.unicodeIsEnabled ?
|
||||||
|
!this.unicodeIsEnabled[fontCharCode] : false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fontChar: String.fromCharCode(fontCharCode),
|
fontChar: String.fromCharCode(fontCharCode),
|
||||||
unicode: unicodeChars,
|
unicode: unicodeChars,
|
||||||
width: width,
|
width: width,
|
||||||
|
disabled: disabled,
|
||||||
operatorList: operatorList
|
operatorList: operatorList
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
charsToGlyphs: function fonts_charsToGlyphs(chars) {
|
charsToGlyphs: function Font_charsToGlyphs(chars) {
|
||||||
var charsCache = this.charsCache;
|
var charsCache = this.charsCache;
|
||||||
var glyphs;
|
var glyphs;
|
||||||
|
|
||||||
@ -2837,7 +2850,7 @@ var Type1Parser = function type1Parser() {
|
|||||||
return c == ' ' || c == '\n' || c == '\x0d';
|
return c == ' ' || c == '\n' || c == '\x0d';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.extractFontProgram = function t1_extractFontProgram(stream) {
|
this.extractFontProgram = function Type1Parser_extractFontProgram(stream) {
|
||||||
var eexec = decrypt(stream, kEexecEncryptionKey, 4);
|
var eexec = decrypt(stream, kEexecEncryptionKey, 4);
|
||||||
var eexecStr = '';
|
var eexecStr = '';
|
||||||
for (var i = 0, ii = eexec.length; i < ii; i++)
|
for (var i = 0, ii = eexec.length; i < ii; i++)
|
||||||
@ -2848,7 +2861,7 @@ var Type1Parser = function type1Parser() {
|
|||||||
subrs: [],
|
subrs: [],
|
||||||
charstrings: [],
|
charstrings: [],
|
||||||
properties: {
|
properties: {
|
||||||
'private': {
|
'privateData': {
|
||||||
'lenIV': 4
|
'lenIV': 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2877,7 +2890,7 @@ var Type1Parser = function type1Parser() {
|
|||||||
(token == 'RD' || token == '-|')) {
|
(token == 'RD' || token == '-|')) {
|
||||||
i++;
|
i++;
|
||||||
var data = eexec.slice(i, i + length);
|
var data = eexec.slice(i, i + length);
|
||||||
var lenIV = program.properties.private['lenIV'];
|
var lenIV = program.properties.privateData['lenIV'];
|
||||||
var encoded = decrypt(data, kCharStringsEncryptionKey, lenIV);
|
var encoded = decrypt(data, kCharStringsEncryptionKey, lenIV);
|
||||||
var str = decodeCharString(encoded);
|
var str = decodeCharString(encoded);
|
||||||
|
|
||||||
@ -2917,7 +2930,7 @@ var Type1Parser = function type1Parser() {
|
|||||||
var length = parseInt(getToken(), 10);
|
var length = parseInt(getToken(), 10);
|
||||||
getToken(); // read in 'RD'
|
getToken(); // read in 'RD'
|
||||||
var data = eexec.slice(i + 1, i + 1 + length);
|
var data = eexec.slice(i + 1, i + 1 + length);
|
||||||
var lenIV = program.properties.private['lenIV'];
|
var lenIV = program.properties.privateData['lenIV'];
|
||||||
var encoded = decrypt(data, kCharStringsEncryptionKey, lenIV);
|
var encoded = decrypt(data, kCharStringsEncryptionKey, lenIV);
|
||||||
var str = decodeCharString(encoded);
|
var str = decodeCharString(encoded);
|
||||||
i = i + 1 + length;
|
i = i + 1 + length;
|
||||||
@ -2933,12 +2946,12 @@ var Type1Parser = function type1Parser() {
|
|||||||
case '/FamilyOtherBlues':
|
case '/FamilyOtherBlues':
|
||||||
case '/StemSnapH':
|
case '/StemSnapH':
|
||||||
case '/StemSnapV':
|
case '/StemSnapV':
|
||||||
program.properties.private[token.substring(1)] =
|
program.properties.privateData[token.substring(1)] =
|
||||||
readNumberArray(eexecStr, i + 1);
|
readNumberArray(eexecStr, i + 1);
|
||||||
break;
|
break;
|
||||||
case '/StdHW':
|
case '/StdHW':
|
||||||
case '/StdVW':
|
case '/StdVW':
|
||||||
program.properties.private[token.substring(1)] =
|
program.properties.privateData[token.substring(1)] =
|
||||||
readNumberArray(eexecStr, i + 2)[0];
|
readNumberArray(eexecStr, i + 2)[0];
|
||||||
break;
|
break;
|
||||||
case '/BlueShift':
|
case '/BlueShift':
|
||||||
@ -2947,7 +2960,7 @@ var Type1Parser = function type1Parser() {
|
|||||||
case '/BlueScale':
|
case '/BlueScale':
|
||||||
case '/LanguageGroup':
|
case '/LanguageGroup':
|
||||||
case '/ExpansionFactor':
|
case '/ExpansionFactor':
|
||||||
program.properties.private[token.substring(1)] =
|
program.properties.privateData[token.substring(1)] =
|
||||||
readNumber(eexecStr, i + 1);
|
readNumber(eexecStr, i + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2962,7 +2975,8 @@ var Type1Parser = function type1Parser() {
|
|||||||
return program;
|
return program;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.extractFontHeader = function t1_extractFontHeader(stream, properties) {
|
this.extractFontHeader = function Type1Parser_extractFontHeader(stream,
|
||||||
|
properties) {
|
||||||
var headerString = '';
|
var headerString = '';
|
||||||
for (var i = 0, ii = stream.length; i < ii; i++)
|
for (var i = 0, ii = stream.length; i < ii; i++)
|
||||||
headerString += String.fromCharCode(stream[i]);
|
headerString += String.fromCharCode(stream[i]);
|
||||||
@ -2971,14 +2985,14 @@ var Type1Parser = function type1Parser() {
|
|||||||
var count = headerString.length;
|
var count = headerString.length;
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var getToken = function getToken() {
|
var getToken = function getToken() {
|
||||||
var char = headerString[i];
|
var character = headerString[i];
|
||||||
while (i < count && (isSeparator(char) || char == '/'))
|
while (i < count && (isSeparator(character) || character == '/'))
|
||||||
char = headerString[++i];
|
character = headerString[++i];
|
||||||
|
|
||||||
var token = '';
|
var token = '';
|
||||||
while (i < count && !(isSeparator(char) || char == '/')) {
|
while (i < count && !(isSeparator(character) || character == '/')) {
|
||||||
token += char;
|
token += character;
|
||||||
char = headerString[++i];
|
character = headerString[++i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
@ -3130,7 +3144,8 @@ var Type1Font = function Type1Font(name, file, properties) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Type1Font.prototype = {
|
Type1Font.prototype = {
|
||||||
createCFFIndexHeader: function createCFFIndexHeader(objects, isByte) {
|
createCFFIndexHeader: function Type1Font_createCFFIndexHeader(objects,
|
||||||
|
isByte) {
|
||||||
// First 2 bytes contains the number of objects contained into this index
|
// First 2 bytes contains the number of objects contained into this index
|
||||||
var count = objects.length;
|
var count = objects.length;
|
||||||
|
|
||||||
@ -3166,7 +3181,7 @@ Type1Font.prototype = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
encodeNumber: function encodeNumber(value) {
|
encodeNumber: function Type1Font_encodeNumber(value) {
|
||||||
// some of the fonts has ouf-of-range values
|
// some of the fonts has ouf-of-range values
|
||||||
// they are just arithmetic overflows
|
// they are just arithmetic overflows
|
||||||
// make sanitizer happy
|
// make sanitizer happy
|
||||||
@ -3184,7 +3199,7 @@ Type1Font.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getOrderedCharStrings: function type1Font_getOrderedCharStrings(glyphs,
|
getOrderedCharStrings: function Type1Font_getOrderedCharStrings(glyphs,
|
||||||
properties) {
|
properties) {
|
||||||
var charstrings = [];
|
var charstrings = [];
|
||||||
var i, length, glyphName;
|
var i, length, glyphName;
|
||||||
@ -3210,7 +3225,8 @@ Type1Font.prototype = {
|
|||||||
return charstrings;
|
return charstrings;
|
||||||
},
|
},
|
||||||
|
|
||||||
getType2Charstrings: function getType2Charstrings(type1Charstrings) {
|
getType2Charstrings: function Type1Font_getType2Charstrings(
|
||||||
|
type1Charstrings) {
|
||||||
var type2Charstrings = [];
|
var type2Charstrings = [];
|
||||||
var count = type1Charstrings.length;
|
var count = type1Charstrings.length;
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
@ -3221,7 +3237,7 @@ Type1Font.prototype = {
|
|||||||
return type2Charstrings;
|
return type2Charstrings;
|
||||||
},
|
},
|
||||||
|
|
||||||
getType2Subrs: function getType2Subrs(type1Subrs) {
|
getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
|
||||||
var bias = 0;
|
var bias = 0;
|
||||||
var count = type1Subrs.length;
|
var count = type1Subrs.length;
|
||||||
if (count < 1240)
|
if (count < 1240)
|
||||||
@ -3273,7 +3289,7 @@ Type1Font.prototype = {
|
|||||||
'hvcurveto': 31
|
'hvcurveto': 31
|
||||||
},
|
},
|
||||||
|
|
||||||
flattenCharstring: function flattenCharstring(charstring, map) {
|
flattenCharstring: function Type1Font_flattenCharstring(charstring, map) {
|
||||||
// charstring changes size - can't cache .length in loop
|
// charstring changes size - can't cache .length in loop
|
||||||
for (var i = 0; i < charstring.length; i++) {
|
for (var i = 0; i < charstring.length; i++) {
|
||||||
var command = charstring[i];
|
var command = charstring[i];
|
||||||
@ -3300,7 +3316,7 @@ Type1Font.prototype = {
|
|||||||
return charstring;
|
return charstring;
|
||||||
},
|
},
|
||||||
|
|
||||||
wrap: function wrap(name, glyphs, charstrings, subrs, properties) {
|
wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
|
||||||
var fields = {
|
var fields = {
|
||||||
// major version, minor version, header size, offset size
|
// major version, minor version, header size, offset size
|
||||||
'header': '\x01\x00\x04\x04',
|
'header': '\x01\x00\x04\x04',
|
||||||
@ -3344,7 +3360,7 @@ Type1Font.prototype = {
|
|||||||
dict += self.encodeNumber(offset) + '\x11'; // Charstrings
|
dict += self.encodeNumber(offset) + '\x11'; // Charstrings
|
||||||
|
|
||||||
offset = offset + fields.charstrings.length;
|
offset = offset + fields.charstrings.length;
|
||||||
dict += self.encodeNumber(fields.private.length);
|
dict += self.encodeNumber(fields.privateData.length);
|
||||||
dict += self.encodeNumber(offset) + '\x12'; // Private
|
dict += self.encodeNumber(offset) + '\x12'; // Private
|
||||||
|
|
||||||
return header + String.fromCharCode(dict.length + 1) + dict;
|
return header + String.fromCharCode(dict.length + 1) + dict;
|
||||||
@ -3385,7 +3401,7 @@ Type1Font.prototype = {
|
|||||||
'charstrings': this.createCFFIndexHeader([[0x8B, 0x0E]].concat(glyphs),
|
'charstrings': this.createCFFIndexHeader([[0x8B, 0x0E]].concat(glyphs),
|
||||||
true),
|
true),
|
||||||
|
|
||||||
'private': (function cffWrapPrivate(self) {
|
'privateData': (function cffWrapPrivate(self) {
|
||||||
var data =
|
var data =
|
||||||
'\x8b\x14' + // defaultWidth
|
'\x8b\x14' + // defaultWidth
|
||||||
'\x8b\x15'; // nominalWidth
|
'\x8b\x15'; // nominalWidth
|
||||||
@ -3403,9 +3419,9 @@ Type1Font.prototype = {
|
|||||||
ExpansionFactor: '\x0c\x18'
|
ExpansionFactor: '\x0c\x18'
|
||||||
};
|
};
|
||||||
for (var field in fieldMap) {
|
for (var field in fieldMap) {
|
||||||
if (!properties.private.hasOwnProperty(field))
|
if (!properties.privateData.hasOwnProperty(field))
|
||||||
continue;
|
continue;
|
||||||
var value = properties.private[field];
|
var value = properties.privateData[field];
|
||||||
|
|
||||||
if (isArray(value)) {
|
if (isArray(value)) {
|
||||||
data += self.encodeNumber(value[0]);
|
data += self.encodeNumber(value[0]);
|
||||||
@ -3457,7 +3473,7 @@ var CFFFont = (function CFFFontClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CFFFont.prototype = {
|
CFFFont.prototype = {
|
||||||
readExtra: function readExtra(cff) {
|
readExtra: function CFFFont_readExtra(cff) {
|
||||||
// charstrings contains info about glyphs (one element per glyph
|
// charstrings contains info about glyphs (one element per glyph
|
||||||
// containing mappings for {unicode, width})
|
// containing mappings for {unicode, width})
|
||||||
var charset = cff.charset.charset;
|
var charset = cff.charset.charset;
|
||||||
@ -3472,7 +3488,7 @@ var CFFFont = (function CFFFontClosure() {
|
|||||||
this.charstrings = charstrings;
|
this.charstrings = charstrings;
|
||||||
this.glyphIds = glyphIds;
|
this.glyphIds = glyphIds;
|
||||||
},
|
},
|
||||||
getCharStrings: function getCharStrings(charsets, encoding) {
|
getCharStrings: function CFFFont_getCharStrings(charsets, encoding) {
|
||||||
var charstrings = [];
|
var charstrings = [];
|
||||||
var unicodeUsed = [];
|
var unicodeUsed = [];
|
||||||
var unassignedUnicodeItems = [];
|
var unassignedUnicodeItems = [];
|
||||||
@ -3534,7 +3550,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
CFFParser.prototype = {
|
CFFParser.prototype = {
|
||||||
parse: function parse() {
|
parse: function CFFParser_parse() {
|
||||||
var properties = this.properties;
|
var properties = this.properties;
|
||||||
var cff = new CFF();
|
var cff = new CFF();
|
||||||
this.cff = cff;
|
this.cff = cff;
|
||||||
@ -3591,7 +3607,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
|
|
||||||
return cff;
|
return cff;
|
||||||
},
|
},
|
||||||
parseHeader: function parseHeader() {
|
parseHeader: function CFFParser_parseHeader() {
|
||||||
var bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
|
|
||||||
@ -3610,7 +3626,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
var header = new CFFHeader(major, minor, hdrSize, offSize);
|
var header = new CFFHeader(major, minor, hdrSize, offSize);
|
||||||
return {obj: header, endPos: hdrSize};
|
return {obj: header, endPos: hdrSize};
|
||||||
},
|
},
|
||||||
parseDict: function parseDict(dict) {
|
parseDict: function CFFParser_parseDict(dict) {
|
||||||
var pos = 0;
|
var pos = 0;
|
||||||
|
|
||||||
function parseOperand() {
|
function parseOperand() {
|
||||||
@ -3680,7 +3696,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
},
|
},
|
||||||
parseIndex: function parseIndex(pos) {
|
parseIndex: function CFFParser_parseIndex(pos) {
|
||||||
var cffIndex = new CFFIndex();
|
var cffIndex = new CFFIndex();
|
||||||
var bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
var count = (bytes[pos++] << 8) | bytes[pos++];
|
var count = (bytes[pos++] << 8) | bytes[pos++];
|
||||||
@ -3710,7 +3726,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
}
|
}
|
||||||
return {obj: cffIndex, endPos: end};
|
return {obj: cffIndex, endPos: end};
|
||||||
},
|
},
|
||||||
parseNameIndex: function parseNameIndex(index) {
|
parseNameIndex: function CFFParser_parseNameIndex(index) {
|
||||||
var names = [];
|
var names = [];
|
||||||
for (var i = 0, ii = index.count; i < ii; ++i) {
|
for (var i = 0, ii = index.count; i < ii; ++i) {
|
||||||
var name = index.get(i);
|
var name = index.get(i);
|
||||||
@ -3737,7 +3753,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
},
|
},
|
||||||
parseStringIndex: function parseStringIndex(index) {
|
parseStringIndex: function CFFParser_parseStringIndex(index) {
|
||||||
var strings = new CFFStrings();
|
var strings = new CFFStrings();
|
||||||
for (var i = 0, ii = index.count; i < ii; ++i) {
|
for (var i = 0, ii = index.count; i < ii; ++i) {
|
||||||
var data = index.get(i);
|
var data = index.get(i);
|
||||||
@ -3745,7 +3761,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
}
|
}
|
||||||
return strings;
|
return strings;
|
||||||
},
|
},
|
||||||
createDict: function createDict(type, dict, strings) {
|
createDict: function CFFParser_createDict(type, dict, strings) {
|
||||||
var cffDict = new type(strings);
|
var cffDict = new type(strings);
|
||||||
var types = cffDict.types;
|
var types = cffDict.types;
|
||||||
|
|
||||||
@ -3757,7 +3773,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
}
|
}
|
||||||
return cffDict;
|
return cffDict;
|
||||||
},
|
},
|
||||||
parseCharStrings: function parseCharStrings(charStringOffset) {
|
parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
|
||||||
var charStrings = this.parseIndex(charStringOffset).obj;
|
var charStrings = this.parseIndex(charStringOffset).obj;
|
||||||
// The CFF specification state that the 'dotsection' command
|
// The CFF specification state that the 'dotsection' command
|
||||||
// (12, 0) is deprecated and treated as a no-op, but all Type2
|
// (12, 0) is deprecated and treated as a no-op, but all Type2
|
||||||
@ -3786,7 +3802,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
}
|
}
|
||||||
return charStrings;
|
return charStrings;
|
||||||
},
|
},
|
||||||
parsePrivateDict: function parsePrivateDict(parentDict) {
|
parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
|
||||||
// no private dict, do nothing
|
// no private dict, do nothing
|
||||||
if (!parentDict.hasName('Private'))
|
if (!parentDict.hasName('Private'))
|
||||||
return;
|
return;
|
||||||
@ -3824,7 +3840,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
var subrsIndex = this.parseIndex(relativeOffset);
|
var subrsIndex = this.parseIndex(relativeOffset);
|
||||||
privateDict.subrsIndex = subrsIndex.obj;
|
privateDict.subrsIndex = subrsIndex.obj;
|
||||||
},
|
},
|
||||||
parseCharsets: function parsecharsets(pos, length, strings, cid) {
|
parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
|
return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
|
||||||
ISOAdobeCharset);
|
ISOAdobeCharset);
|
||||||
@ -3876,7 +3892,10 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
|
|
||||||
return new CFFCharset(false, format, charset, raw);
|
return new CFFCharset(false, format, charset, raw);
|
||||||
},
|
},
|
||||||
parseEncoding: function parseEncoding(pos, properties, strings, charset) {
|
parseEncoding: function CFFParser_parseEncoding(pos,
|
||||||
|
properties,
|
||||||
|
strings,
|
||||||
|
charset) {
|
||||||
var encoding = {};
|
var encoding = {};
|
||||||
var bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
var predefined = false;
|
var predefined = false;
|
||||||
@ -3945,7 +3964,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
format = format & 0x7f;
|
format = format & 0x7f;
|
||||||
return new CFFEncoding(predefined, format, encoding, raw);
|
return new CFFEncoding(predefined, format, encoding, raw);
|
||||||
},
|
},
|
||||||
parseFDSelect: function parseFDSelect(pos, length) {
|
parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
|
||||||
var start = pos;
|
var start = pos;
|
||||||
var bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
var format = bytes[pos++];
|
var format = bytes[pos++];
|
||||||
@ -4017,14 +4036,14 @@ var CFFStrings = (function CFFStringsClosure() {
|
|||||||
this.strings = [];
|
this.strings = [];
|
||||||
}
|
}
|
||||||
CFFStrings.prototype = {
|
CFFStrings.prototype = {
|
||||||
get: function get(index) {
|
get: function CFFStrings_get(index) {
|
||||||
if (index >= 0 && index <= 390)
|
if (index >= 0 && index <= 390)
|
||||||
return CFFStandardStrings[index];
|
return CFFStandardStrings[index];
|
||||||
if (index - 391 <= this.strings.length)
|
if (index - 391 <= this.strings.length)
|
||||||
return this.strings[index - 391];
|
return this.strings[index - 391];
|
||||||
return CFFStandardStrings[0];
|
return CFFStandardStrings[0];
|
||||||
},
|
},
|
||||||
add: function add(value) {
|
add: function CFFStrings_add(value) {
|
||||||
this.strings.push(value);
|
this.strings.push(value);
|
||||||
},
|
},
|
||||||
get count() {
|
get count() {
|
||||||
@ -4040,11 +4059,11 @@ var CFFIndex = (function CFFIndexClosure() {
|
|||||||
this.length = 0;
|
this.length = 0;
|
||||||
}
|
}
|
||||||
CFFIndex.prototype = {
|
CFFIndex.prototype = {
|
||||||
add: function add(data) {
|
add: function CFFIndex_add(data) {
|
||||||
this.length += data.length;
|
this.length += data.length;
|
||||||
this.objects.push(data);
|
this.objects.push(data);
|
||||||
},
|
},
|
||||||
get: function get(index) {
|
get: function CFFIndex_get(index) {
|
||||||
return this.objects[index];
|
return this.objects[index];
|
||||||
},
|
},
|
||||||
get count() {
|
get count() {
|
||||||
@ -4067,7 +4086,7 @@ var CFFDict = (function CFFDictClosure() {
|
|||||||
}
|
}
|
||||||
CFFDict.prototype = {
|
CFFDict.prototype = {
|
||||||
// value should always be an array
|
// value should always be an array
|
||||||
setByKey: function setByKey(key, value) {
|
setByKey: function CFFDict_setByKey(key, value) {
|
||||||
if (!(key in this.keyToNameMap))
|
if (!(key in this.keyToNameMap))
|
||||||
return false;
|
return false;
|
||||||
// ignore empty values
|
// ignore empty values
|
||||||
@ -4080,10 +4099,10 @@ var CFFDict = (function CFFDictClosure() {
|
|||||||
this.values[key] = value;
|
this.values[key] = value;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
hasName: function hasName(name) {
|
hasName: function CFFDict_hasName(name) {
|
||||||
return this.nameToKeyMap[name] in this.values;
|
return this.nameToKeyMap[name] in this.values;
|
||||||
},
|
},
|
||||||
getByName: function getByName(name) {
|
getByName: function CFFDict_getByName(name) {
|
||||||
if (!(name in this.nameToKeyMap))
|
if (!(name in this.nameToKeyMap))
|
||||||
error('Invalid dictionary name "' + name + '"');
|
error('Invalid dictionary name "' + name + '"');
|
||||||
var key = this.nameToKeyMap[name];
|
var key = this.nameToKeyMap[name];
|
||||||
@ -4091,11 +4110,11 @@ var CFFDict = (function CFFDictClosure() {
|
|||||||
return this.defaults[key];
|
return this.defaults[key];
|
||||||
return this.values[key];
|
return this.values[key];
|
||||||
},
|
},
|
||||||
removeByName: function removeByName(name) {
|
removeByName: function CFFDict_removeByName(name) {
|
||||||
delete this.values[this.nameToKeyMap[name]];
|
delete this.values[this.nameToKeyMap[name]];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
CFFDict.createTables = function createTables(layout) {
|
CFFDict.createTables = function CFFDict_createTables(layout) {
|
||||||
var tables = {
|
var tables = {
|
||||||
keyToNameMap: {},
|
keyToNameMap: {},
|
||||||
nameToKeyMap: {},
|
nameToKeyMap: {},
|
||||||
@ -4252,20 +4271,22 @@ var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
|
|||||||
this.offsets = {};
|
this.offsets = {};
|
||||||
}
|
}
|
||||||
CFFOffsetTracker.prototype = {
|
CFFOffsetTracker.prototype = {
|
||||||
isTracking: function isTracking(key) {
|
isTracking: function CFFOffsetTracker_isTracking(key) {
|
||||||
return key in this.offsets;
|
return key in this.offsets;
|
||||||
},
|
},
|
||||||
track: function track(key, location) {
|
track: function CFFOffsetTracker_track(key, location) {
|
||||||
if (key in this.offsets)
|
if (key in this.offsets)
|
||||||
error('Already tracking location of ' + key);
|
error('Already tracking location of ' + key);
|
||||||
this.offsets[key] = location;
|
this.offsets[key] = location;
|
||||||
},
|
},
|
||||||
offset: function offset(value) {
|
offset: function CFFOffsetTracker_offset(value) {
|
||||||
for (var key in this.offsets) {
|
for (var key in this.offsets) {
|
||||||
this.offsets[key] += value;
|
this.offsets[key] += value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setEntryLocation: function setEntryLocation(key, values, output) {
|
setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
|
||||||
|
values,
|
||||||
|
output) {
|
||||||
if (!(key in this.offsets))
|
if (!(key in this.offsets))
|
||||||
error('Not tracking location of ' + key);
|
error('Not tracking location of ' + key);
|
||||||
var data = output.data;
|
var data = output.data;
|
||||||
@ -4306,12 +4327,12 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
this.cff = cff;
|
this.cff = cff;
|
||||||
}
|
}
|
||||||
CFFCompiler.prototype = {
|
CFFCompiler.prototype = {
|
||||||
compile: function compile() {
|
compile: function CFFCompiler_compile() {
|
||||||
var cff = this.cff;
|
var cff = this.cff;
|
||||||
var output = {
|
var output = {
|
||||||
data: [],
|
data: [],
|
||||||
length: 0,
|
length: 0,
|
||||||
add: function add(data) {
|
add: function CFFCompiler_add(data) {
|
||||||
this.data = this.data.concat(data);
|
this.data = this.data.concat(data);
|
||||||
this.length = this.data.length;
|
this.length = this.data.length;
|
||||||
}
|
}
|
||||||
@ -4362,29 +4383,31 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
output.add(charStrings);
|
output.add(charStrings);
|
||||||
|
|
||||||
if (cff.isCIDFont) {
|
if (cff.isCIDFont) {
|
||||||
|
// For some reason FDSelect must be in front of FDArray on windows. OSX
|
||||||
|
// and linux don't seem to care.
|
||||||
|
topDictTracker.setEntryLocation('FDSelect', [output.length], output);
|
||||||
|
var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
|
||||||
|
output.add(fdSelect);
|
||||||
|
|
||||||
var compiled = this.compileTopDicts(cff.fdArray, output.length);
|
var compiled = this.compileTopDicts(cff.fdArray, output.length);
|
||||||
topDictTracker.setEntryLocation('FDArray', [output.length], output);
|
topDictTracker.setEntryLocation('FDArray', [output.length], output);
|
||||||
output.add(compiled.output);
|
output.add(compiled.output);
|
||||||
var fontDictTrackers = compiled.trackers;
|
var fontDictTrackers = compiled.trackers;
|
||||||
|
|
||||||
this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
|
this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
|
||||||
|
|
||||||
topDictTracker.setEntryLocation('FDSelect', [output.length], output);
|
|
||||||
var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
|
|
||||||
output.add(fdSelect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
|
this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
|
||||||
|
|
||||||
return output.data;
|
return output.data;
|
||||||
},
|
},
|
||||||
encodeNumber: function encodeNumber(value) {
|
encodeNumber: function CFFCompiler_encodeNumber(value) {
|
||||||
if (parseFloat(value) == parseInt(value) && !isNaN(value)) // isInt
|
if (parseFloat(value) == parseInt(value) && !isNaN(value)) // isInt
|
||||||
return this.encodeInteger(value);
|
return this.encodeInteger(value);
|
||||||
else
|
else
|
||||||
return this.encodeFloat(value);
|
return this.encodeFloat(value);
|
||||||
},
|
},
|
||||||
encodeFloat: function encodeFloat(value) {
|
encodeFloat: function CFFCompiler_encodeFloat(value) {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
// Strip off the any leading zeros.
|
// Strip off the any leading zeros.
|
||||||
if (value.substr(0, 2) === '0.')
|
if (value.substr(0, 2) === '0.')
|
||||||
@ -4417,7 +4440,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
out.push(nibbles[i] << 4 | nibbles[i + 1]);
|
out.push(nibbles[i] << 4 | nibbles[i + 1]);
|
||||||
return out;
|
return out;
|
||||||
},
|
},
|
||||||
encodeInteger: function encodeInteger(value) {
|
encodeInteger: function CFFCompiler_encodeInteger(value) {
|
||||||
var code;
|
var code;
|
||||||
if (value >= -107 && value <= 107) {
|
if (value >= -107 && value <= 107) {
|
||||||
code = [value + 139];
|
code = [value + 139];
|
||||||
@ -4438,7 +4461,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
},
|
},
|
||||||
compileHeader: function compileHeader(header) {
|
compileHeader: function CFFCompiler_compileHeader(header) {
|
||||||
return [
|
return [
|
||||||
header.major,
|
header.major,
|
||||||
header.minor,
|
header.minor,
|
||||||
@ -4446,13 +4469,13 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
header.offSize
|
header.offSize
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
compileNameIndex: function compileNameIndex(names) {
|
compileNameIndex: function CFFCompiler_compileNameIndex(names) {
|
||||||
var nameIndex = new CFFIndex();
|
var nameIndex = new CFFIndex();
|
||||||
for (var i = 0, ii = names.length; i < ii; ++i)
|
for (var i = 0, ii = names.length; i < ii; ++i)
|
||||||
nameIndex.add(stringToArray(names[i]));
|
nameIndex.add(stringToArray(names[i]));
|
||||||
return this.compileIndex(nameIndex);
|
return this.compileIndex(nameIndex);
|
||||||
},
|
},
|
||||||
compileTopDicts: function compileTopDicts(dicts, length) {
|
compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length) {
|
||||||
var fontDictTrackers = [];
|
var fontDictTrackers = [];
|
||||||
var fdArrayIndex = new CFFIndex();
|
var fdArrayIndex = new CFFIndex();
|
||||||
for (var i = 0, ii = dicts.length; i < ii; ++i) {
|
for (var i = 0, ii = dicts.length; i < ii; ++i) {
|
||||||
@ -4469,7 +4492,9 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
output: fdArrayIndex
|
output: fdArrayIndex
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
compilePrivateDicts: function compilePrivateDicts(dicts, trackers, output) {
|
compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
|
||||||
|
trackers,
|
||||||
|
output) {
|
||||||
for (var i = 0, ii = dicts.length; i < ii; ++i) {
|
for (var i = 0, ii = dicts.length; i < ii; ++i) {
|
||||||
var fontDict = dicts[i];
|
var fontDict = dicts[i];
|
||||||
if (!fontDict.privateDict || !fontDict.hasName('Private'))
|
if (!fontDict.privateDict || !fontDict.hasName('Private'))
|
||||||
@ -4492,7 +4517,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
compileDict: function compileDict(dict, offsetTracker) {
|
compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
|
||||||
var out = [];
|
var out = [];
|
||||||
// The dictionary keys must be in a certain order.
|
// The dictionary keys must be in a certain order.
|
||||||
var order = dict.order;
|
var order = dict.order;
|
||||||
@ -4543,35 +4568,35 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
},
|
},
|
||||||
compileStringIndex: function compileStringIndex(strings) {
|
compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
|
||||||
var stringIndex = new CFFIndex();
|
var stringIndex = new CFFIndex();
|
||||||
for (var i = 0, ii = strings.length; i < ii; ++i)
|
for (var i = 0, ii = strings.length; i < ii; ++i)
|
||||||
stringIndex.add(stringToArray(strings[i]));
|
stringIndex.add(stringToArray(strings[i]));
|
||||||
return this.compileIndex(stringIndex);
|
return this.compileIndex(stringIndex);
|
||||||
},
|
},
|
||||||
compileGlobalSubrIndex: function compileGlobalSubrIndex() {
|
compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
|
||||||
var globalSubrIndex = this.cff.globalSubrIndex;
|
var globalSubrIndex = this.cff.globalSubrIndex;
|
||||||
this.out.writeByteArray(this.compileIndex(globalSubrIndex));
|
this.out.writeByteArray(this.compileIndex(globalSubrIndex));
|
||||||
},
|
},
|
||||||
compileCharStrings: function compileCharStrings(charStrings) {
|
compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
|
||||||
return this.compileIndex(charStrings);
|
return this.compileIndex(charStrings);
|
||||||
},
|
},
|
||||||
compileCharset: function compileCharset(charset) {
|
compileCharset: function CFFCompiler_compileCharset(charset) {
|
||||||
return this.compileTypedArray(charset.raw);
|
return this.compileTypedArray(charset.raw);
|
||||||
},
|
},
|
||||||
compileEncoding: function compileEncoding(encoding) {
|
compileEncoding: function CFFCompiler_compileEncoding(encoding) {
|
||||||
return this.compileTypedArray(encoding.raw);
|
return this.compileTypedArray(encoding.raw);
|
||||||
},
|
},
|
||||||
compileFDSelect: function compileFDSelect(fdSelect) {
|
compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
|
||||||
return this.compileTypedArray(fdSelect);
|
return this.compileTypedArray(fdSelect);
|
||||||
},
|
},
|
||||||
compileTypedArray: function compileTypedArray(data) {
|
compileTypedArray: function CFFCompiler_compileTypedArray(data) {
|
||||||
var out = [];
|
var out = [];
|
||||||
for (var i = 0, ii = data.length; i < ii; ++i)
|
for (var i = 0, ii = data.length; i < ii; ++i)
|
||||||
out[i] = data[i];
|
out[i] = data[i];
|
||||||
return out;
|
return out;
|
||||||
},
|
},
|
||||||
compileIndex: function compileIndex(index, trackers) {
|
compileIndex: function CFFCompiler_compileIndex(index, trackers) {
|
||||||
trackers = trackers || [];
|
trackers = trackers || [];
|
||||||
var objects = index.objects;
|
var objects = index.objects;
|
||||||
// First 2 bytes contains the number of objects contained into this index
|
// First 2 bytes contains the number of objects contained into this index
|
||||||
|
@ -10,7 +10,7 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
var CONSTRUCT_POSTSCRIPT = 4;
|
var CONSTRUCT_POSTSCRIPT = 4;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getSampleArray: function pdfFunctionGetSampleArray(size, outputSize, bps,
|
getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
|
||||||
str) {
|
str) {
|
||||||
var length = 1;
|
var length = 1;
|
||||||
for (var i = 0, ii = size.length; i < ii; i++)
|
for (var i = 0, ii = size.length; i < ii; i++)
|
||||||
@ -38,7 +38,7 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
return array;
|
return array;
|
||||||
},
|
},
|
||||||
|
|
||||||
getIR: function pdfFunctionGetIR(xref, fn) {
|
getIR: function PDFFunction_getIR(xref, fn) {
|
||||||
var dict = fn.dict;
|
var dict = fn.dict;
|
||||||
if (!dict)
|
if (!dict)
|
||||||
dict = fn;
|
dict = fn;
|
||||||
@ -57,7 +57,7 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
return typeFn.call(this, fn, dict, xref);
|
return typeFn.call(this, fn, dict, xref);
|
||||||
},
|
},
|
||||||
|
|
||||||
fromIR: function pdfFunctionFromIR(IR) {
|
fromIR: function PDFFunction_fromIR(IR) {
|
||||||
var type = IR[0];
|
var type = IR[0];
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CONSTRUCT_SAMPLED:
|
case CONSTRUCT_SAMPLED:
|
||||||
@ -72,12 +72,12 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
parse: function pdfFunctionParse(xref, fn) {
|
parse: function PDFFunction_parse(xref, fn) {
|
||||||
var IR = this.getIR(xref, fn);
|
var IR = this.getIR(xref, fn);
|
||||||
return this.fromIR(IR);
|
return this.fromIR(IR);
|
||||||
},
|
},
|
||||||
|
|
||||||
constructSampled: function pdfFunctionConstructSampled(str, dict) {
|
constructSampled: function PDFFunction_constructSampled(str, dict) {
|
||||||
function toMultiArray(arr) {
|
function toMultiArray(arr) {
|
||||||
var inputLength = arr.length;
|
var inputLength = arr.length;
|
||||||
var outputLength = arr.length / 2;
|
var outputLength = arr.length / 2;
|
||||||
@ -133,7 +133,7 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
constructSampledFromIR: function pdfFunctionConstructSampledFromIR(IR) {
|
constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
|
||||||
// See chapter 3, page 109 of the PDF reference
|
// See chapter 3, page 109 of the PDF reference
|
||||||
function interpolate(x, xmin, xmax, ymin, ymax) {
|
function interpolate(x, xmin, xmax, ymin, ymax) {
|
||||||
return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
|
return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
|
||||||
@ -221,8 +221,8 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
constructInterpolated:
|
constructInterpolated: function PDFFunction_constructInterpolated(str,
|
||||||
function pdfFunctionConstructInterpolated(str, dict) {
|
dict) {
|
||||||
var c0 = dict.get('C0') || [0];
|
var c0 = dict.get('C0') || [0];
|
||||||
var c1 = dict.get('C1') || [1];
|
var c1 = dict.get('C1') || [1];
|
||||||
var n = dict.get('N');
|
var n = dict.get('N');
|
||||||
@ -239,7 +239,7 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
constructInterpolatedFromIR:
|
constructInterpolatedFromIR:
|
||||||
function pdfFunctionconstructInterpolatedFromIR(IR) {
|
function PDFFunction_constructInterpolatedFromIR(IR) {
|
||||||
var c0 = IR[1];
|
var c0 = IR[1];
|
||||||
var diff = IR[2];
|
var diff = IR[2];
|
||||||
var n = IR[3];
|
var n = IR[3];
|
||||||
@ -258,7 +258,7 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
constructStiched: function pdfFunctionConstructStiched(fn, dict, xref) {
|
constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
|
||||||
var domain = dict.get('Domain');
|
var domain = dict.get('Domain');
|
||||||
|
|
||||||
if (!domain)
|
if (!domain)
|
||||||
@ -268,18 +268,18 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
if (inputSize != 1)
|
if (inputSize != 1)
|
||||||
error('Bad domain for stiched function');
|
error('Bad domain for stiched function');
|
||||||
|
|
||||||
var fnRefs = xref.fetchIfRef(dict.get('Functions'));
|
var fnRefs = dict.get('Functions');
|
||||||
var fns = [];
|
var fns = [];
|
||||||
for (var i = 0, ii = fnRefs.length; i < ii; ++i)
|
for (var i = 0, ii = fnRefs.length; i < ii; ++i)
|
||||||
fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
|
fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
|
||||||
|
|
||||||
var bounds = xref.fetchIfRef(dict.get('Bounds'));
|
var bounds = dict.get('Bounds');
|
||||||
var encode = xref.fetchIfRef(dict.get('Encode'));
|
var encode = dict.get('Encode');
|
||||||
|
|
||||||
return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
|
return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
|
||||||
},
|
},
|
||||||
|
|
||||||
constructStichedFromIR: function pdfFunctionConstructStichedFromIR(IR) {
|
constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
|
||||||
var domain = IR[1];
|
var domain = IR[1];
|
||||||
var bounds = IR[2];
|
var bounds = IR[2];
|
||||||
var encode = IR[3];
|
var encode = IR[3];
|
||||||
@ -325,7 +325,7 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
constructPostScript: function pdfFunctionConstructPostScript(fn, dict,
|
constructPostScript: function PDFFunction_constructPostScript(fn, dict,
|
||||||
xref) {
|
xref) {
|
||||||
var domain = dict.get('Domain');
|
var domain = dict.get('Domain');
|
||||||
var range = dict.get('Range');
|
var range = dict.get('Range');
|
||||||
@ -343,8 +343,8 @@ var PDFFunction = (function PDFFunctionClosure() {
|
|||||||
return [CONSTRUCT_POSTSCRIPT, domain, range, code];
|
return [CONSTRUCT_POSTSCRIPT, domain, range, code];
|
||||||
},
|
},
|
||||||
|
|
||||||
constructPostScriptFromIR:
|
constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
|
||||||
function pdfFunctionConstructPostScriptFromIR(IR) {
|
IR) {
|
||||||
var domain = IR[1];
|
var domain = IR[1];
|
||||||
var range = IR[2];
|
var range = IR[2];
|
||||||
var code = IR[3];
|
var code = IR[3];
|
||||||
@ -390,13 +390,13 @@ var FunctionCache = (function FunctionCacheClosure() {
|
|||||||
this.total = 0;
|
this.total = 0;
|
||||||
}
|
}
|
||||||
FunctionCache.prototype = {
|
FunctionCache.prototype = {
|
||||||
has: function has(key) {
|
has: function FunctionCache_has(key) {
|
||||||
return key in this.cache;
|
return key in this.cache;
|
||||||
},
|
},
|
||||||
get: function get(key) {
|
get: function FunctionCache_get(key) {
|
||||||
return this.cache[key];
|
return this.cache[key];
|
||||||
},
|
},
|
||||||
set: function set(key, value) {
|
set: function FunctionCache_set(key, value) {
|
||||||
if (this.total < MAX_CACHE_SIZE) {
|
if (this.total < MAX_CACHE_SIZE) {
|
||||||
this.cache[key] = value;
|
this.cache[key] = value;
|
||||||
this.total++;
|
this.total++;
|
||||||
@ -413,28 +413,28 @@ var PostScriptStack = (function PostScriptStackClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PostScriptStack.prototype = {
|
PostScriptStack.prototype = {
|
||||||
push: function push(value) {
|
push: function PostScriptStack_push(value) {
|
||||||
if (this.stack.length >= MAX_STACK_SIZE)
|
if (this.stack.length >= MAX_STACK_SIZE)
|
||||||
error('PostScript function stack overflow.');
|
error('PostScript function stack overflow.');
|
||||||
this.stack.push(value);
|
this.stack.push(value);
|
||||||
},
|
},
|
||||||
pop: function pop() {
|
pop: function PostScriptStack_pop() {
|
||||||
if (this.stack.length <= 0)
|
if (this.stack.length <= 0)
|
||||||
error('PostScript function stack underflow.');
|
error('PostScript function stack underflow.');
|
||||||
return this.stack.pop();
|
return this.stack.pop();
|
||||||
},
|
},
|
||||||
copy: function copy(n) {
|
copy: function PostScriptStack_copy(n) {
|
||||||
if (this.stack.length + n >= MAX_STACK_SIZE)
|
if (this.stack.length + n >= MAX_STACK_SIZE)
|
||||||
error('PostScript function stack overflow.');
|
error('PostScript function stack overflow.');
|
||||||
var stack = this.stack;
|
var stack = this.stack;
|
||||||
for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++)
|
for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++)
|
||||||
stack.push(stack[i]);
|
stack.push(stack[i]);
|
||||||
},
|
},
|
||||||
index: function index(n) {
|
index: function PostScriptStack_index(n) {
|
||||||
this.push(this.stack[this.stack.length - n - 1]);
|
this.push(this.stack[this.stack.length - n - 1]);
|
||||||
},
|
},
|
||||||
// rotate the last n stack elements p times
|
// rotate the last n stack elements p times
|
||||||
roll: function roll(n, p) {
|
roll: function PostScriptStack_roll(n, p) {
|
||||||
var stack = this.stack;
|
var stack = this.stack;
|
||||||
var l = stack.length - n;
|
var l = stack.length - n;
|
||||||
var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
|
var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
|
||||||
@ -457,7 +457,7 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
|
|||||||
this.operands = operands;
|
this.operands = operands;
|
||||||
}
|
}
|
||||||
PostScriptEvaluator.prototype = {
|
PostScriptEvaluator.prototype = {
|
||||||
execute: function execute(initialStack) {
|
execute: function PostScriptEvaluator_execute(initialStack) {
|
||||||
var stack = new PostScriptStack(initialStack);
|
var stack = new PostScriptStack(initialStack);
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
var operators = this.operators;
|
var operators = this.operators;
|
||||||
@ -691,31 +691,31 @@ var PostScriptParser = (function PostScriptParserClosure() {
|
|||||||
this.prev;
|
this.prev;
|
||||||
}
|
}
|
||||||
PostScriptParser.prototype = {
|
PostScriptParser.prototype = {
|
||||||
nextToken: function nextToken() {
|
nextToken: function PostScriptParser_nextToken() {
|
||||||
this.prev = this.token;
|
this.prev = this.token;
|
||||||
this.token = this.lexer.getToken();
|
this.token = this.lexer.getToken();
|
||||||
},
|
},
|
||||||
accept: function accept(type) {
|
accept: function PostScriptParser_accept(type) {
|
||||||
if (this.token.type == type) {
|
if (this.token.type == type) {
|
||||||
this.nextToken();
|
this.nextToken();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
expect: function expect(type) {
|
expect: function PostScriptParser_expect(type) {
|
||||||
if (this.accept(type))
|
if (this.accept(type))
|
||||||
return true;
|
return true;
|
||||||
error('Unexpected symbol: found ' + this.token.type + ' expected ' +
|
error('Unexpected symbol: found ' + this.token.type + ' expected ' +
|
||||||
type + '.');
|
type + '.');
|
||||||
},
|
},
|
||||||
parse: function parse() {
|
parse: function PostScriptParser_parse() {
|
||||||
this.nextToken();
|
this.nextToken();
|
||||||
this.expect(PostScriptTokenTypes.LBRACE);
|
this.expect(PostScriptTokenTypes.LBRACE);
|
||||||
this.parseBlock();
|
this.parseBlock();
|
||||||
this.expect(PostScriptTokenTypes.RBRACE);
|
this.expect(PostScriptTokenTypes.RBRACE);
|
||||||
return this.operators;
|
return this.operators;
|
||||||
},
|
},
|
||||||
parseBlock: function parseBlock() {
|
parseBlock: function PostScriptParser_parseBlock() {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (this.accept(PostScriptTokenTypes.NUMBER)) {
|
if (this.accept(PostScriptTokenTypes.NUMBER)) {
|
||||||
this.operators.push(this.prev.value);
|
this.operators.push(this.prev.value);
|
||||||
@ -728,7 +728,7 @@ var PostScriptParser = (function PostScriptParserClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parseCondition: function parseCondition() {
|
parseCondition: function PostScriptParser_parseCondition() {
|
||||||
// Add two place holders that will be updated later
|
// Add two place holders that will be updated later
|
||||||
var conditionLocation = this.operators.length;
|
var conditionLocation = this.operators.length;
|
||||||
this.operators.push(null, null);
|
this.operators.push(null, null);
|
||||||
@ -779,7 +779,7 @@ var PostScriptToken = (function PostScriptTokenClosure() {
|
|||||||
|
|
||||||
var opCache = {};
|
var opCache = {};
|
||||||
|
|
||||||
PostScriptToken.getOperator = function getOperator(op) {
|
PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
|
||||||
var opValue = opCache[op];
|
var opValue = opCache[op];
|
||||||
if (opValue)
|
if (opValue)
|
||||||
return opValue;
|
return opValue;
|
||||||
@ -802,7 +802,7 @@ var PostScriptLexer = (function PostScriptLexerClosure() {
|
|||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
}
|
}
|
||||||
PostScriptLexer.prototype = {
|
PostScriptLexer.prototype = {
|
||||||
getToken: function getToken() {
|
getToken: function PostScriptLexer_getToken() {
|
||||||
var s = '';
|
var s = '';
|
||||||
var ch;
|
var ch;
|
||||||
var comment = false;
|
var comment = false;
|
||||||
@ -852,7 +852,7 @@ var PostScriptLexer = (function PostScriptLexerClosure() {
|
|||||||
return PostScriptToken.getOperator(str);
|
return PostScriptToken.getOperator(str);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getNumber: function getNumber(ch) {
|
getNumber: function PostScriptLexer_getNumber(ch) {
|
||||||
var str = ch;
|
var str = ch;
|
||||||
var stream = this.stream;
|
var stream = this.stream;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
24
src/image.js
24
src/image.js
@ -94,7 +94,7 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var mask = xref.fetchIfRef(dict.get('Mask'));
|
var mask = dict.get('Mask');
|
||||||
|
|
||||||
if (mask) {
|
if (mask) {
|
||||||
TODO('masked images');
|
TODO('masked images');
|
||||||
@ -106,8 +106,8 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
* Handles processing of image data and calls the callback with an argument
|
* Handles processing of image data and calls the callback with an argument
|
||||||
* of a PDFImage when the image is ready to be used.
|
* of a PDFImage when the image is ready to be used.
|
||||||
*/
|
*/
|
||||||
PDFImage.buildImage = function buildImage(callback, handler, xref, res,
|
PDFImage.buildImage = function PDFImage_buildImage(callback, handler, xref,
|
||||||
image, inline) {
|
res, image, inline) {
|
||||||
var imageDataPromise = new Promise();
|
var imageDataPromise = new Promise();
|
||||||
var smaskPromise = new Promise();
|
var smaskPromise = new Promise();
|
||||||
// The image data and smask data may not be ready yet, wait till both are
|
// The image data and smask data may not be ready yet, wait till both are
|
||||||
@ -120,7 +120,7 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
|
|
||||||
handleImageData(handler, xref, res, image, imageDataPromise);
|
handleImageData(handler, xref, res, image, imageDataPromise);
|
||||||
|
|
||||||
var smask = xref.fetchIfRef(image.dict.get('SMask'));
|
var smask = image.dict.get('SMask');
|
||||||
if (smask)
|
if (smask)
|
||||||
handleImageData(handler, xref, res, smask, smaskPromise);
|
handleImageData(handler, xref, res, smask, smaskPromise);
|
||||||
else
|
else
|
||||||
@ -139,7 +139,8 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
* @param {Number} h2 New height.
|
* @param {Number} h2 New height.
|
||||||
* @return {TypedArray} Resized image data.
|
* @return {TypedArray} Resized image data.
|
||||||
*/
|
*/
|
||||||
PDFImage.resize = function resize(pixels, bpc, components, w1, h1, w2, h2) {
|
PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
|
||||||
|
w1, h1, w2, h2) {
|
||||||
var length = w2 * h2 * components;
|
var length = w2 * h2 * components;
|
||||||
var temp = bpc <= 8 ? new Uint8Array(length) :
|
var temp = bpc <= 8 ? new Uint8Array(length) :
|
||||||
bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
|
bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
|
||||||
@ -177,7 +178,7 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
return this.height;
|
return this.height;
|
||||||
return Math.max(this.height, this.smask.height);
|
return Math.max(this.height, this.smask.height);
|
||||||
},
|
},
|
||||||
getComponents: function getComponents(buffer) {
|
getComponents: function PDFImage_getComponents(buffer) {
|
||||||
var bpc = this.bpc;
|
var bpc = this.bpc;
|
||||||
var needsDecode = this.needsDecode;
|
var needsDecode = this.needsDecode;
|
||||||
var decodeMap = this.decode;
|
var decodeMap = this.decode;
|
||||||
@ -265,7 +266,7 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
getOpacity: function getOpacity(width, height) {
|
getOpacity: function PDFImage_getOpacity(width, height) {
|
||||||
var smask = this.smask;
|
var smask = this.smask;
|
||||||
var originalWidth = this.width;
|
var originalWidth = this.width;
|
||||||
var originalHeight = this.height;
|
var originalHeight = this.height;
|
||||||
@ -285,7 +286,8 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
},
|
},
|
||||||
applyStencilMask: function applyStencilMask(buffer, inverseDecode) {
|
applyStencilMask: function PDFImage_applyStencilMask(buffer,
|
||||||
|
inverseDecode) {
|
||||||
var width = this.width, height = this.height;
|
var width = this.width, height = this.height;
|
||||||
var bitStrideLength = (width + 7) >> 3;
|
var bitStrideLength = (width + 7) >> 3;
|
||||||
var imgArray = this.getImageBytes(bitStrideLength * height);
|
var imgArray = this.getImageBytes(bitStrideLength * height);
|
||||||
@ -308,7 +310,7 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fillRgbaBuffer: function fillRgbaBuffer(buffer, width, height) {
|
fillRgbaBuffer: function PDFImage_fillRgbaBuffer(buffer, width, height) {
|
||||||
var numComps = this.numComps;
|
var numComps = this.numComps;
|
||||||
var originalWidth = this.width;
|
var originalWidth = this.width;
|
||||||
var originalHeight = this.height;
|
var originalHeight = this.height;
|
||||||
@ -335,7 +337,7 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
buffer[i + 3] = opacity[opacityPos++];
|
buffer[i + 3] = opacity[opacityPos++];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fillGrayBuffer: function fillGrayBuffer(buffer) {
|
fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
|
||||||
var numComps = this.numComps;
|
var numComps = this.numComps;
|
||||||
if (numComps != 1)
|
if (numComps != 1)
|
||||||
error('Reading gray scale from a color image: ' + numComps);
|
error('Reading gray scale from a color image: ' + numComps);
|
||||||
@ -355,7 +357,7 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
for (var i = 0; i < length; ++i)
|
for (var i = 0; i < length; ++i)
|
||||||
buffer[i] = (scale * comps[i]) | 0;
|
buffer[i] = (scale * comps[i]) | 0;
|
||||||
},
|
},
|
||||||
getImageBytes: function getImageBytes(length) {
|
getImageBytes: function PDFImage_getImageBytes(length) {
|
||||||
this.image.reset();
|
this.image.reset();
|
||||||
return this.image.getBytes(length);
|
return this.image.getBytes(length);
|
||||||
}
|
}
|
||||||
|
2256
src/jpx.js
2256
src/jpx.js
File diff suppressed because it is too large
Load Diff
66
src/metadata.js
Normal file
66
src/metadata.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var Metadata = PDFJS.Metadata = (function MetadataClosure() {
|
||||||
|
function Metadata(meta) {
|
||||||
|
if (typeof meta === 'string') {
|
||||||
|
var parser = new DOMParser();
|
||||||
|
meta = parser.parseFromString(meta, 'application/xml');
|
||||||
|
} else if (!(meta instanceof Document)) {
|
||||||
|
error('Metadata: Invalid metadata object');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.metaDocument = meta;
|
||||||
|
this.metadata = {};
|
||||||
|
this.parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
Metadata.prototype = {
|
||||||
|
parse: function Metadata_parse() {
|
||||||
|
var doc = this.metaDocument;
|
||||||
|
var rdf = doc.documentElement;
|
||||||
|
|
||||||
|
if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
|
||||||
|
rdf = rdf.firstChild;
|
||||||
|
while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf')
|
||||||
|
rdf = rdf.nextSibling;
|
||||||
|
}
|
||||||
|
|
||||||
|
var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
|
||||||
|
if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var childNodes = rdf.childNodes, desc, namespace, entries, entry;
|
||||||
|
|
||||||
|
for (var i = 0, length = childNodes.length; i < length; i++) {
|
||||||
|
desc = childNodes[i];
|
||||||
|
if (desc.nodeName.toLowerCase() !== 'rdf:description')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
entries = [];
|
||||||
|
for (var ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
|
||||||
|
if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text')
|
||||||
|
entries.push(desc.childNodes[ii]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ii = 0, iLength = entries.length; ii < iLength; ii++) {
|
||||||
|
var entry = entries[ii];
|
||||||
|
var name = entry.nodeName.toLowerCase();
|
||||||
|
this.metadata[name] = entry.textContent.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
get: function Metadata_get(name) {
|
||||||
|
return this.metadata[name] || null;
|
||||||
|
},
|
||||||
|
|
||||||
|
has: function Metadata_has(name) {
|
||||||
|
return typeof this.metadata[name] !== 'undefined';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return Metadata;
|
||||||
|
})();
|
140
src/obj.js
140
src/obj.js
@ -22,7 +22,7 @@ var Cmd = (function CmdClosure() {
|
|||||||
|
|
||||||
var cmdCache = {};
|
var cmdCache = {};
|
||||||
|
|
||||||
Cmd.get = function cmdGet(cmd) {
|
Cmd.get = function Cmd_get(cmd) {
|
||||||
var cmdValue = cmdCache[cmd];
|
var cmdValue = cmdCache[cmd];
|
||||||
if (cmdValue)
|
if (cmdValue)
|
||||||
return cmdValue;
|
return cmdValue;
|
||||||
@ -34,36 +34,52 @@ var Cmd = (function CmdClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
var Dict = (function DictClosure() {
|
var Dict = (function DictClosure() {
|
||||||
function Dict() {
|
// xref is optional
|
||||||
|
function Dict(xref) {
|
||||||
|
// Map should only be used internally, use functions below to access.
|
||||||
this.map = Object.create(null);
|
this.map = Object.create(null);
|
||||||
|
this.xref = xref;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dict.prototype = {
|
Dict.prototype = {
|
||||||
get: function dictGet(key1, key2, key3) {
|
// automatically dereferences Ref objects
|
||||||
|
get: function Dict_get(key1, key2, key3) {
|
||||||
var value;
|
var value;
|
||||||
|
var xref = this.xref;
|
||||||
if (typeof (value = this.map[key1]) != 'undefined' || key1 in this.map ||
|
if (typeof (value = this.map[key1]) != 'undefined' || key1 in this.map ||
|
||||||
typeof key2 == 'undefined') {
|
typeof key2 == 'undefined') {
|
||||||
return value;
|
return xref ? this.xref.fetchIfRef(value) : value;
|
||||||
}
|
}
|
||||||
if (typeof (value = this.map[key2]) != 'undefined' || key2 in this.map ||
|
if (typeof (value = this.map[key2]) != 'undefined' || key2 in this.map ||
|
||||||
typeof key3 == 'undefined') {
|
typeof key3 == 'undefined') {
|
||||||
return value;
|
return xref ? this.xref.fetchIfRef(value) : value;
|
||||||
}
|
}
|
||||||
|
value = this.map[key3] || null;
|
||||||
return this.map[key3] || null;
|
return xref ? this.xref.fetchIfRef(value) : value;
|
||||||
|
},
|
||||||
|
// no dereferencing
|
||||||
|
getRaw: function Dict_getRaw(key) {
|
||||||
|
return this.map[key];
|
||||||
|
},
|
||||||
|
// creates new map and dereferences all Refs
|
||||||
|
getAll: function Dict_getAll() {
|
||||||
|
var all = {};
|
||||||
|
for (var key in this.map)
|
||||||
|
all[key] = this.get(key);
|
||||||
|
return all;
|
||||||
},
|
},
|
||||||
|
|
||||||
set: function dictSet(key, value) {
|
set: function Dict_set(key, value) {
|
||||||
this.map[key] = value;
|
this.map[key] = value;
|
||||||
},
|
},
|
||||||
|
|
||||||
has: function dictHas(key) {
|
has: function Dict_has(key) {
|
||||||
return key in this.map;
|
return key in this.map;
|
||||||
},
|
},
|
||||||
|
|
||||||
forEach: function dictForEach(callback) {
|
forEach: function Dict_forEach(callback) {
|
||||||
for (var key in this.map) {
|
for (var key in this.map) {
|
||||||
callback(key, this.map[key]);
|
callback(key, this.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -90,11 +106,11 @@ var RefSet = (function RefSetClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RefSet.prototype = {
|
RefSet.prototype = {
|
||||||
has: function refSetHas(ref) {
|
has: function RefSet_has(ref) {
|
||||||
return !!this.dict['R' + ref.num + '.' + ref.gen];
|
return !!this.dict['R' + ref.num + '.' + ref.gen];
|
||||||
},
|
},
|
||||||
|
|
||||||
put: function refSetPut(ref) {
|
put: function RefSet_put(ref) {
|
||||||
this.dict['R' + ref.num + '.' + ref.gen] = ref;
|
this.dict['R' + ref.num + '.' + ref.gen] = ref;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -111,20 +127,33 @@ var Catalog = (function CatalogClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Catalog.prototype = {
|
Catalog.prototype = {
|
||||||
|
get metadata() {
|
||||||
|
var stream = this.catDict.get('Metadata');
|
||||||
|
var metadata;
|
||||||
|
if (stream && isDict(stream.dict)) {
|
||||||
|
var type = stream.dict.get('Type');
|
||||||
|
var subtype = stream.dict.get('Subtype');
|
||||||
|
|
||||||
|
if (isName(type) && isName(subtype) &&
|
||||||
|
type.name === 'Metadata' && subtype.name === 'XML') {
|
||||||
|
metadata = stringToPDFString(bytesToString(stream.getBytes()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return shadow(this, 'metadata', metadata);
|
||||||
|
},
|
||||||
get toplevelPagesDict() {
|
get toplevelPagesDict() {
|
||||||
var pagesObj = this.catDict.get('Pages');
|
var pagesObj = this.catDict.get('Pages');
|
||||||
assertWellFormed(isRef(pagesObj), 'invalid top-level pages reference');
|
assertWellFormed(isDict(pagesObj), 'invalid top-level pages dictionary');
|
||||||
var xrefObj = this.xref.fetch(pagesObj);
|
|
||||||
assertWellFormed(isDict(xrefObj), 'invalid top-level pages dictionary');
|
|
||||||
// shadow the prototype getter
|
// shadow the prototype getter
|
||||||
return shadow(this, 'toplevelPagesDict', xrefObj);
|
return shadow(this, 'toplevelPagesDict', pagesObj);
|
||||||
},
|
},
|
||||||
get documentOutline() {
|
get documentOutline() {
|
||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
var obj = xref.fetchIfRef(this.catDict.get('Outlines'));
|
var obj = this.catDict.get('Outlines');
|
||||||
var root = { items: [] };
|
var root = { items: [] };
|
||||||
if (isDict(obj)) {
|
if (isDict(obj)) {
|
||||||
obj = obj.get('First');
|
obj = obj.getRaw('First');
|
||||||
var processed = new RefSet();
|
var processed = new RefSet();
|
||||||
if (isRef(obj)) {
|
if (isRef(obj)) {
|
||||||
var queue = [{obj: obj, parent: root}];
|
var queue = [{obj: obj, parent: root}];
|
||||||
@ -133,20 +162,20 @@ var Catalog = (function CatalogClosure() {
|
|||||||
processed.put(obj);
|
processed.put(obj);
|
||||||
while (queue.length > 0) {
|
while (queue.length > 0) {
|
||||||
var i = queue.shift();
|
var i = queue.shift();
|
||||||
var outlineDict = xref.fetch(i.obj);
|
var outlineDict = xref.fetchIfRef(i.obj);
|
||||||
if (outlineDict === null)
|
if (outlineDict === null)
|
||||||
continue;
|
continue;
|
||||||
if (!outlineDict.has('Title'))
|
if (!outlineDict.has('Title'))
|
||||||
error('Invalid outline item');
|
error('Invalid outline item');
|
||||||
var dest = outlineDict.get('A');
|
var dest = outlineDict.get('A');
|
||||||
if (dest)
|
if (dest)
|
||||||
dest = xref.fetchIfRef(dest).get('D');
|
dest = dest.get('D');
|
||||||
else if (outlineDict.has('Dest')) {
|
else if (outlineDict.has('Dest')) {
|
||||||
dest = outlineDict.get('Dest');
|
dest = outlineDict.getRaw('Dest');
|
||||||
if (isName(dest))
|
if (isName(dest))
|
||||||
dest = dest.name;
|
dest = dest.name;
|
||||||
}
|
}
|
||||||
var title = xref.fetchIfRef(outlineDict.get('Title'));
|
var title = outlineDict.get('Title');
|
||||||
var outlineItem = {
|
var outlineItem = {
|
||||||
dest: dest,
|
dest: dest,
|
||||||
title: stringToPDFString(title),
|
title: stringToPDFString(title),
|
||||||
@ -157,12 +186,12 @@ var Catalog = (function CatalogClosure() {
|
|||||||
items: []
|
items: []
|
||||||
};
|
};
|
||||||
i.parent.items.push(outlineItem);
|
i.parent.items.push(outlineItem);
|
||||||
obj = outlineDict.get('First');
|
obj = outlineDict.getRaw('First');
|
||||||
if (isRef(obj) && !processed.has(obj)) {
|
if (isRef(obj) && !processed.has(obj)) {
|
||||||
queue.push({obj: obj, parent: outlineItem});
|
queue.push({obj: obj, parent: outlineItem});
|
||||||
processed.put(obj);
|
processed.put(obj);
|
||||||
}
|
}
|
||||||
obj = outlineDict.get('Next');
|
obj = outlineDict.getRaw('Next');
|
||||||
if (isRef(obj) && !processed.has(obj)) {
|
if (isRef(obj) && !processed.has(obj)) {
|
||||||
queue.push({obj: obj, parent: i.parent});
|
queue.push({obj: obj, parent: i.parent});
|
||||||
processed.put(obj);
|
processed.put(obj);
|
||||||
@ -182,7 +211,7 @@ var Catalog = (function CatalogClosure() {
|
|||||||
// shadow the prototype getter
|
// shadow the prototype getter
|
||||||
return shadow(this, 'num', obj);
|
return shadow(this, 'num', obj);
|
||||||
},
|
},
|
||||||
traverseKids: function catalogTraverseKids(pagesDict) {
|
traverseKids: function Catalog_traverseKids(pagesDict) {
|
||||||
var pageCache = this.pageCache;
|
var pageCache = this.pageCache;
|
||||||
var kids = pagesDict.get('Kids');
|
var kids = pagesDict.get('Kids');
|
||||||
assertWellFormed(isArray(kids),
|
assertWellFormed(isArray(kids),
|
||||||
@ -190,7 +219,7 @@ var Catalog = (function CatalogClosure() {
|
|||||||
for (var i = 0, ii = kids.length; i < ii; ++i) {
|
for (var i = 0, ii = kids.length; i < ii; ++i) {
|
||||||
var kid = kids[i];
|
var kid = kids[i];
|
||||||
assertWellFormed(isRef(kid),
|
assertWellFormed(isRef(kid),
|
||||||
'page dictionary kid is not a reference');
|
'page dictionary kid is not a reference');
|
||||||
var obj = this.xref.fetch(kid);
|
var obj = this.xref.fetch(kid);
|
||||||
if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
|
if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
|
||||||
pageCache.push(new Page(this.xref, pageCache.length, obj, kid));
|
pageCache.push(new Page(this.xref, pageCache.length, obj, kid));
|
||||||
@ -204,8 +233,7 @@ var Catalog = (function CatalogClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
get destinations() {
|
get destinations() {
|
||||||
function fetchDestination(xref, ref) {
|
function fetchDestination(dest) {
|
||||||
var dest = xref.fetchIfRef(ref);
|
|
||||||
return isDict(dest) ? dest.get('D') : dest;
|
return isDict(dest) ? dest.get('D') : dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,16 +241,16 @@ var Catalog = (function CatalogClosure() {
|
|||||||
var dests = {}, nameTreeRef, nameDictionaryRef;
|
var dests = {}, nameTreeRef, nameDictionaryRef;
|
||||||
var obj = this.catDict.get('Names');
|
var obj = this.catDict.get('Names');
|
||||||
if (obj)
|
if (obj)
|
||||||
nameTreeRef = xref.fetchIfRef(obj).get('Dests');
|
nameTreeRef = obj.getRaw('Dests');
|
||||||
else if (this.catDict.has('Dests'))
|
else if (this.catDict.has('Dests'))
|
||||||
nameDictionaryRef = this.catDict.get('Dests');
|
nameDictionaryRef = this.catDict.get('Dests');
|
||||||
|
|
||||||
if (nameDictionaryRef) {
|
if (nameDictionaryRef) {
|
||||||
// reading simple destination dictionary
|
// reading simple destination dictionary
|
||||||
obj = xref.fetchIfRef(nameDictionaryRef);
|
obj = nameDictionaryRef;
|
||||||
obj.forEach(function catalogForEach(key, value) {
|
obj.forEach(function catalogForEach(key, value) {
|
||||||
if (!value) return;
|
if (!value) return;
|
||||||
dests[key] = fetchDestination(xref, value);
|
dests[key] = fetchDestination(value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (nameTreeRef) {
|
if (nameTreeRef) {
|
||||||
@ -246,13 +274,13 @@ var Catalog = (function CatalogClosure() {
|
|||||||
}
|
}
|
||||||
var names = obj.get('Names');
|
var names = obj.get('Names');
|
||||||
for (i = 0, n = names.length; i < n; i += 2) {
|
for (i = 0, n = names.length; i < n; i += 2) {
|
||||||
dests[names[i]] = fetchDestination(xref, names[i + 1]);
|
dests[names[i]] = fetchDestination(xref.fetchIfRef(names[i + 1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return shadow(this, 'destinations', dests);
|
return shadow(this, 'destinations', dests);
|
||||||
},
|
},
|
||||||
getPage: function catalogGetPage(n) {
|
getPage: function Catalog_getPage(n) {
|
||||||
var pageCache = this.pageCache;
|
var pageCache = this.pageCache;
|
||||||
if (!pageCache) {
|
if (!pageCache) {
|
||||||
pageCache = this.pageCache = [];
|
pageCache = this.pageCache = [];
|
||||||
@ -271,6 +299,7 @@ var XRef = (function XRefClosure() {
|
|||||||
this.entries = [];
|
this.entries = [];
|
||||||
this.xrefstms = {};
|
this.xrefstms = {};
|
||||||
var trailerDict = this.readXRef(startXRef);
|
var trailerDict = this.readXRef(startXRef);
|
||||||
|
trailerDict.xref = this;
|
||||||
this.trailer = trailerDict;
|
this.trailer = trailerDict;
|
||||||
// prepare the XRef cache
|
// prepare the XRef cache
|
||||||
this.cache = [];
|
this.cache = [];
|
||||||
@ -278,17 +307,17 @@ var XRef = (function XRefClosure() {
|
|||||||
var encrypt = trailerDict.get('Encrypt');
|
var encrypt = trailerDict.get('Encrypt');
|
||||||
if (encrypt) {
|
if (encrypt) {
|
||||||
var fileId = trailerDict.get('ID');
|
var fileId = trailerDict.get('ID');
|
||||||
this.encrypt = new CipherTransformFactory(this.fetch(encrypt),
|
this.encrypt = new CipherTransformFactory(encrypt,
|
||||||
fileId[0] /*, password */);
|
fileId[0] /*, password */);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the root dictionary (catalog) object
|
// get the root dictionary (catalog) object
|
||||||
if (!isRef(this.root = trailerDict.get('Root')))
|
if (!(this.root = trailerDict.get('Root')))
|
||||||
error('Invalid root reference');
|
error('Invalid root reference');
|
||||||
}
|
}
|
||||||
|
|
||||||
XRef.prototype = {
|
XRef.prototype = {
|
||||||
readXRefTable: function readXRefTable(parser) {
|
readXRefTable: function XRef_readXRefTable(parser) {
|
||||||
// Example of cross-reference table:
|
// Example of cross-reference table:
|
||||||
// xref
|
// xref
|
||||||
// 0 1 <-- subsection header (first obj #, obj count)
|
// 0 1 <-- subsection header (first obj #, obj count)
|
||||||
@ -355,7 +384,7 @@ var XRef = (function XRefClosure() {
|
|||||||
|
|
||||||
return dict;
|
return dict;
|
||||||
},
|
},
|
||||||
readXRefStream: function readXRefStream(stream) {
|
readXRefStream: function XRef_readXRefStream(stream) {
|
||||||
var streamParameters = stream.parameters;
|
var streamParameters = stream.parameters;
|
||||||
var byteWidths = streamParameters.get('W');
|
var byteWidths = streamParameters.get('W');
|
||||||
var range = streamParameters.get('Index');
|
var range = streamParameters.get('Index');
|
||||||
@ -406,7 +435,7 @@ var XRef = (function XRefClosure() {
|
|||||||
}
|
}
|
||||||
return streamParameters;
|
return streamParameters;
|
||||||
},
|
},
|
||||||
indexObjects: function indexObjects() {
|
indexObjects: function XRef_indexObjects() {
|
||||||
// Simple scan through the PDF content to find objects,
|
// Simple scan through the PDF content to find objects,
|
||||||
// trailers and XRef streams.
|
// trailers and XRef streams.
|
||||||
function readToken(data, offset) {
|
function readToken(data, offset) {
|
||||||
@ -498,7 +527,7 @@ var XRef = (function XRefClosure() {
|
|||||||
var dict;
|
var dict;
|
||||||
for (var i = 0, ii = trailers.length; i < ii; ++i) {
|
for (var i = 0, ii = trailers.length; i < ii; ++i) {
|
||||||
stream.pos = trailers[i];
|
stream.pos = trailers[i];
|
||||||
var parser = new Parser(new Lexer(stream), true);
|
var parser = new Parser(new Lexer(stream), true, null);
|
||||||
var obj = parser.getObj();
|
var obj = parser.getObj();
|
||||||
if (!isCmd(obj, 'trailer'))
|
if (!isCmd(obj, 'trailer'))
|
||||||
continue;
|
continue;
|
||||||
@ -515,12 +544,12 @@ var XRef = (function XRefClosure() {
|
|||||||
// nothing helps
|
// nothing helps
|
||||||
error('Invalid PDF structure');
|
error('Invalid PDF structure');
|
||||||
},
|
},
|
||||||
readXRef: function readXref(startXRef) {
|
readXRef: function XRef_readXRef(startXRef) {
|
||||||
var stream = this.stream;
|
var stream = this.stream;
|
||||||
stream.pos = startXRef;
|
stream.pos = startXRef;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var parser = new Parser(new Lexer(stream), true);
|
var parser = new Parser(new Lexer(stream), true, null);
|
||||||
var obj = parser.getObj();
|
var obj = parser.getObj();
|
||||||
var dict;
|
var dict;
|
||||||
|
|
||||||
@ -568,18 +597,19 @@ var XRef = (function XRefClosure() {
|
|||||||
warn('Indexing all PDF objects');
|
warn('Indexing all PDF objects');
|
||||||
return this.indexObjects();
|
return this.indexObjects();
|
||||||
},
|
},
|
||||||
getEntry: function xRefGetEntry(i) {
|
getEntry: function XRef_getEntry(i) {
|
||||||
var e = this.entries[i];
|
var e = this.entries[i];
|
||||||
if (e === null)
|
if (e === null)
|
||||||
return null;
|
return null;
|
||||||
return e.free ? null : e; // returns null is the entry is free
|
return e.free ? null : e; // returns null is the entry is free
|
||||||
},
|
},
|
||||||
fetchIfRef: function xRefFetchIfRef(obj) {
|
fetchIfRef: function XRef_fetchIfRef(obj) {
|
||||||
if (!isRef(obj))
|
if (!isRef(obj))
|
||||||
return obj;
|
return obj;
|
||||||
return this.fetch(obj);
|
return this.fetch(obj);
|
||||||
},
|
},
|
||||||
fetch: function xRefFetch(ref, suppressEncryption) {
|
fetch: function XRef_fetch(ref, suppressEncryption) {
|
||||||
|
assertWellFormed(isRef(ref), 'ref object is not a reference');
|
||||||
var num = ref.num;
|
var num = ref.num;
|
||||||
if (num in this.cache)
|
if (num in this.cache)
|
||||||
return this.cache[num];
|
return this.cache[num];
|
||||||
@ -641,7 +671,7 @@ var XRef = (function XRefClosure() {
|
|||||||
if (!isInt(first) || !isInt(n)) {
|
if (!isInt(first) || !isInt(n)) {
|
||||||
error('invalid first and n parameters for ObjStm stream');
|
error('invalid first and n parameters for ObjStm stream');
|
||||||
}
|
}
|
||||||
parser = new Parser(new Lexer(stream), false);
|
parser = new Parser(new Lexer(stream), false, this);
|
||||||
var i, entries = [], nums = [];
|
var i, entries = [], nums = [];
|
||||||
// read the object numbers to populate cache
|
// read the object numbers to populate cache
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
@ -666,8 +696,8 @@ var XRef = (function XRefClosure() {
|
|||||||
}
|
}
|
||||||
return e;
|
return e;
|
||||||
},
|
},
|
||||||
getCatalogObj: function xRefGetCatalogObj() {
|
getCatalogObj: function XRef_getCatalogObj() {
|
||||||
return this.fetch(this.root);
|
return this.root;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -693,7 +723,7 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|||||||
* Ensures there is an object defined for `objId`. Stores `data` on the
|
* Ensures there is an object defined for `objId`. Stores `data` on the
|
||||||
* object *if* it is created.
|
* object *if* it is created.
|
||||||
*/
|
*/
|
||||||
ensureObj: function pdfObjectsEnsureObj(objId, data) {
|
ensureObj: function PDFObjects_ensureObj(objId, data) {
|
||||||
if (this.objs[objId])
|
if (this.objs[objId])
|
||||||
return this.objs[objId];
|
return this.objs[objId];
|
||||||
return this.objs[objId] = new Promise(objId, data);
|
return this.objs[objId] = new Promise(objId, data);
|
||||||
@ -708,7 +738,7 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|||||||
* function and the object is already resolved, the callback gets called
|
* function and the object is already resolved, the callback gets called
|
||||||
* right away.
|
* right away.
|
||||||
*/
|
*/
|
||||||
get: function pdfObjectsGet(objId, callback) {
|
get: function PDFObjects_get(objId, callback) {
|
||||||
// If there is a callback, then the get can be async and the object is
|
// If there is a callback, then the get can be async and the object is
|
||||||
// not required to be resolved right now
|
// not required to be resolved right now
|
||||||
if (callback) {
|
if (callback) {
|
||||||
@ -731,7 +761,7 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|||||||
/**
|
/**
|
||||||
* Resolves the object `objId` with optional `data`.
|
* Resolves the object `objId` with optional `data`.
|
||||||
*/
|
*/
|
||||||
resolve: function pdfObjectsResolve(objId, data) {
|
resolve: function PDFObjects_resolve(objId, data) {
|
||||||
var objs = this.objs;
|
var objs = this.objs;
|
||||||
|
|
||||||
// In case there is a promise already on this object, just resolve it.
|
// In case there is a promise already on this object, just resolve it.
|
||||||
@ -742,11 +772,11 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onData: function pdfObjectsOnData(objId, callback) {
|
onData: function PDFObjects_onData(objId, callback) {
|
||||||
this.ensureObj(objId).onData(callback);
|
this.ensureObj(objId).onData(callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
isResolved: function pdfObjectsIsResolved(objId) {
|
isResolved: function PDFObjects_isResolved(objId) {
|
||||||
var objs = this.objs;
|
var objs = this.objs;
|
||||||
if (!objs[objId]) {
|
if (!objs[objId]) {
|
||||||
return false;
|
return false;
|
||||||
@ -755,7 +785,7 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hasData: function pdfObjectsHasData(objId) {
|
hasData: function PDFObjects_hasData(objId) {
|
||||||
var objs = this.objs;
|
var objs = this.objs;
|
||||||
if (!objs[objId]) {
|
if (!objs[objId]) {
|
||||||
return false;
|
return false;
|
||||||
@ -767,7 +797,7 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|||||||
/**
|
/**
|
||||||
* Sets the data of an object but *doesn't* resolve it.
|
* Sets the data of an object but *doesn't* resolve it.
|
||||||
*/
|
*/
|
||||||
setData: function pdfObjectsSetData(objId, data) {
|
setData: function PDFObjects_setData(objId, data) {
|
||||||
// Watchout! If you call `this.ensureObj(objId, data)` you're going to
|
// Watchout! If you call `this.ensureObj(objId, data)` you're going to
|
||||||
// create a *resolved* promise which shouldn't be the case!
|
// create a *resolved* promise which shouldn't be the case!
|
||||||
this.ensureObj(objId).data = data;
|
this.ensureObj(objId).data = data;
|
||||||
|
@ -19,11 +19,11 @@ var Parser = (function ParserClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Parser.prototype = {
|
Parser.prototype = {
|
||||||
refill: function parserRefill() {
|
refill: function Parser_refill() {
|
||||||
this.buf1 = this.lexer.getObj();
|
this.buf1 = this.lexer.getObj();
|
||||||
this.buf2 = this.lexer.getObj();
|
this.buf2 = this.lexer.getObj();
|
||||||
},
|
},
|
||||||
shift: function parserShift() {
|
shift: function Parser_shift() {
|
||||||
if (isCmd(this.buf2, 'ID')) {
|
if (isCmd(this.buf2, 'ID')) {
|
||||||
this.buf1 = this.buf2;
|
this.buf1 = this.buf2;
|
||||||
this.buf2 = null;
|
this.buf2 = null;
|
||||||
@ -34,7 +34,7 @@ var Parser = (function ParserClosure() {
|
|||||||
this.buf2 = this.lexer.getObj();
|
this.buf2 = this.lexer.getObj();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getObj: function parserGetObj(cipherTransform) {
|
getObj: function Parser_getObj(cipherTransform) {
|
||||||
if (isCmd(this.buf1, 'BI')) { // inline image
|
if (isCmd(this.buf1, 'BI')) { // inline image
|
||||||
this.shift();
|
this.shift();
|
||||||
return this.makeInlineImage(cipherTransform);
|
return this.makeInlineImage(cipherTransform);
|
||||||
@ -51,7 +51,7 @@ var Parser = (function ParserClosure() {
|
|||||||
}
|
}
|
||||||
if (isCmd(this.buf1, '<<')) { // dictionary or stream
|
if (isCmd(this.buf1, '<<')) { // dictionary or stream
|
||||||
this.shift();
|
this.shift();
|
||||||
var dict = new Dict();
|
var dict = new Dict(this.xref);
|
||||||
while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
|
while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
|
||||||
if (!isName(this.buf1))
|
if (!isName(this.buf1))
|
||||||
error('Dictionary key must be a name object');
|
error('Dictionary key must be a name object');
|
||||||
@ -98,7 +98,7 @@ var Parser = (function ParserClosure() {
|
|||||||
this.shift();
|
this.shift();
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
makeInlineImage: function parserMakeInlineImage(cipherTransform) {
|
makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
|
||||||
var lexer = this.lexer;
|
var lexer = this.lexer;
|
||||||
var stream = lexer.stream;
|
var stream = lexer.stream;
|
||||||
|
|
||||||
@ -160,11 +160,11 @@ var Parser = (function ParserClosure() {
|
|||||||
|
|
||||||
return imageStream;
|
return imageStream;
|
||||||
},
|
},
|
||||||
fetchIfRef: function parserFetchIfRef(obj) {
|
fetchIfRef: function Parser_fetchIfRef(obj) {
|
||||||
// not relying on the xref.fetchIfRef -- xref might not be set
|
// not relying on the xref.fetchIfRef -- xref might not be set
|
||||||
return isRef(obj) ? this.xref.fetch(obj) : obj;
|
return isRef(obj) ? this.xref.fetch(obj) : obj;
|
||||||
},
|
},
|
||||||
makeStream: function parserMakeStream(dict, cipherTransform) {
|
makeStream: function Parser_makeStream(dict, cipherTransform) {
|
||||||
var lexer = this.lexer;
|
var lexer = this.lexer;
|
||||||
var stream = lexer.stream;
|
var stream = lexer.stream;
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ var Parser = (function ParserClosure() {
|
|||||||
stream.parameters = dict;
|
stream.parameters = dict;
|
||||||
return stream;
|
return stream;
|
||||||
},
|
},
|
||||||
filter: function parserFilter(stream, dict, length) {
|
filter: function Parser_filter(stream, dict, length) {
|
||||||
var filter = this.fetchIfRef(dict.get('Filter', 'F'));
|
var filter = this.fetchIfRef(dict.get('Filter', 'F'));
|
||||||
var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
|
var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
|
||||||
if (isName(filter))
|
if (isName(filter))
|
||||||
@ -215,7 +215,7 @@ var Parser = (function ParserClosure() {
|
|||||||
}
|
}
|
||||||
return stream;
|
return stream;
|
||||||
},
|
},
|
||||||
makeFilter: function parserMakeFilter(stream, name, length, params) {
|
makeFilter: function Parser_makeFilter(stream, name, length, params) {
|
||||||
if (name == 'FlateDecode' || name == 'Fl') {
|
if (name == 'FlateDecode' || name == 'Fl') {
|
||||||
if (params) {
|
if (params) {
|
||||||
return new PredictorStream(new FlateStream(stream), params);
|
return new PredictorStream(new FlateStream(stream), params);
|
||||||
@ -265,7 +265,7 @@ var Lexer = (function LexerClosure() {
|
|||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
Lexer.isSpace = function lexerIsSpace(ch) {
|
Lexer.isSpace = function Lexer_isSpace(ch) {
|
||||||
return ch == ' ' || ch == '\t' || ch == '\x0d' || ch == '\x0a';
|
return ch == ' ' || ch == '\t' || ch == '\x0d' || ch == '\x0a';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -300,7 +300,7 @@ var Lexer = (function LexerClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Lexer.prototype = {
|
Lexer.prototype = {
|
||||||
getNumber: function lexerGetNumber(ch) {
|
getNumber: function Lexer_getNumber(ch) {
|
||||||
var floating = false;
|
var floating = false;
|
||||||
var str = ch;
|
var str = ch;
|
||||||
var stream = this.stream;
|
var stream = this.stream;
|
||||||
@ -328,7 +328,7 @@ var Lexer = (function LexerClosure() {
|
|||||||
error('Invalid floating point number: ' + value);
|
error('Invalid floating point number: ' + value);
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
getString: function lexerGetString() {
|
getString: function Lexer_getString() {
|
||||||
var numParen = 1;
|
var numParen = 1;
|
||||||
var done = false;
|
var done = false;
|
||||||
var str = '';
|
var str = '';
|
||||||
@ -412,7 +412,7 @@ var Lexer = (function LexerClosure() {
|
|||||||
} while (!done);
|
} while (!done);
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
getName: function lexerGetName(ch) {
|
getName: function Lexer_getName(ch) {
|
||||||
var str = '';
|
var str = '';
|
||||||
var stream = this.stream;
|
var stream = this.stream;
|
||||||
while (!!(ch = stream.lookChar()) && !specialChars[ch.charCodeAt(0)]) {
|
while (!!(ch = stream.lookChar()) && !specialChars[ch.charCodeAt(0)]) {
|
||||||
@ -439,7 +439,7 @@ var Lexer = (function LexerClosure() {
|
|||||||
str.length);
|
str.length);
|
||||||
return new Name(str);
|
return new Name(str);
|
||||||
},
|
},
|
||||||
getHexString: function lexerGetHexString(ch) {
|
getHexString: function Lexer_getHexString(ch) {
|
||||||
var str = '';
|
var str = '';
|
||||||
var stream = this.stream;
|
var stream = this.stream;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -468,7 +468,7 @@ var Lexer = (function LexerClosure() {
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
getObj: function lexerGetObj() {
|
getObj: function Lexer_getObj() {
|
||||||
// skip whitespace and comments
|
// skip whitespace and comments
|
||||||
var comment = false;
|
var comment = false;
|
||||||
var stream = this.stream;
|
var stream = this.stream;
|
||||||
@ -541,7 +541,7 @@ var Lexer = (function LexerClosure() {
|
|||||||
return null;
|
return null;
|
||||||
return Cmd.get(str);
|
return Cmd.get(str);
|
||||||
},
|
},
|
||||||
skipToNextLine: function lexerSkipToNextLine() {
|
skipToNextLine: function Lexer_skipToNextLine() {
|
||||||
var stream = this.stream;
|
var stream = this.stream;
|
||||||
while (true) {
|
while (true) {
|
||||||
var ch = stream.getChar();
|
var ch = stream.getChar();
|
||||||
@ -554,7 +554,7 @@ var Lexer = (function LexerClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
skip: function lexerSkip() {
|
skip: function Lexer_skip() {
|
||||||
this.stream.skip();
|
this.stream.skip();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -564,7 +564,7 @@ var Lexer = (function LexerClosure() {
|
|||||||
|
|
||||||
var Linearization = (function LinearizationClosure() {
|
var Linearization = (function LinearizationClosure() {
|
||||||
function Linearization(stream) {
|
function Linearization(stream) {
|
||||||
this.parser = new Parser(new Lexer(stream), false);
|
this.parser = new Parser(new Lexer(stream), false, null);
|
||||||
var obj1 = this.parser.getObj();
|
var obj1 = this.parser.getObj();
|
||||||
var obj2 = this.parser.getObj();
|
var obj2 = this.parser.getObj();
|
||||||
var obj3 = this.parser.getObj();
|
var obj3 = this.parser.getObj();
|
||||||
@ -578,7 +578,7 @@ var Linearization = (function LinearizationClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Linearization.prototype = {
|
Linearization.prototype = {
|
||||||
getInt: function linearizationGetInt(name) {
|
getInt: function Linearization_getInt(name) {
|
||||||
var linDict = this.linDict;
|
var linDict = this.linDict;
|
||||||
var obj;
|
var obj;
|
||||||
if (isDict(linDict) &&
|
if (isDict(linDict) &&
|
||||||
@ -588,7 +588,7 @@ var Linearization = (function LinearizationClosure() {
|
|||||||
}
|
}
|
||||||
error('"' + name + '" field in linearization table is invalid');
|
error('"' + name + '" field in linearization table is invalid');
|
||||||
},
|
},
|
||||||
getHint: function linearizationGetHint(index) {
|
getHint: function Linearization_getHint(index) {
|
||||||
var linDict = this.linDict;
|
var linDict = this.linDict;
|
||||||
var obj1, obj2;
|
var obj1, obj2;
|
||||||
if (isDict(linDict) &&
|
if (isDict(linDict) &&
|
||||||
|
@ -17,16 +17,16 @@ var Pattern = (function PatternClosure() {
|
|||||||
Pattern.prototype = {
|
Pattern.prototype = {
|
||||||
// Input: current Canvas context
|
// Input: current Canvas context
|
||||||
// Output: the appropriate fillStyle or strokeStyle
|
// Output: the appropriate fillStyle or strokeStyle
|
||||||
getPattern: function pattern_getStyle(ctx) {
|
getPattern: function Pattern_getPattern(ctx) {
|
||||||
error('Should not call Pattern.getStyle: ' + ctx);
|
error('Should not call Pattern.getStyle: ' + ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Pattern.shadingFromIR = function pattern_shadingFromIR(raw) {
|
Pattern.shadingFromIR = function Pattern_shadingFromIR(raw) {
|
||||||
return Shadings[raw[0]].fromIR(raw);
|
return Shadings[raw[0]].fromIR(raw);
|
||||||
};
|
};
|
||||||
|
|
||||||
Pattern.parseShading = function pattern_shading(shading, matrix, xref, res) {
|
Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref, res) {
|
||||||
|
|
||||||
var dict = isStream(shading) ? shading.dict : shading;
|
var dict = isStream(shading) ? shading.dict : shading;
|
||||||
var type = dict.get('ShadingType');
|
var type = dict.get('ShadingType');
|
||||||
@ -78,7 +78,6 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
|
|||||||
this.extendEnd = extendEnd;
|
this.extendEnd = extendEnd;
|
||||||
|
|
||||||
var fnObj = dict.get('Function');
|
var fnObj = dict.get('Function');
|
||||||
fnObj = xref.fetchIfRef(fnObj);
|
|
||||||
if (isArray(fnObj))
|
if (isArray(fnObj))
|
||||||
error('No support for array of functions');
|
error('No support for array of functions');
|
||||||
if (!isPDFFunction(fnObj))
|
if (!isPDFFunction(fnObj))
|
||||||
@ -101,7 +100,7 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
|
|||||||
this.colorStops = colorStops;
|
this.colorStops = colorStops;
|
||||||
}
|
}
|
||||||
|
|
||||||
RadialAxial.fromIR = function radialAxialShadingGetIR(raw) {
|
RadialAxial.fromIR = function RadialAxial_fromIR(raw) {
|
||||||
var type = raw[1];
|
var type = raw[1];
|
||||||
var colorStops = raw[2];
|
var colorStops = raw[2];
|
||||||
var p0 = raw[3];
|
var p0 = raw[3];
|
||||||
@ -138,7 +137,7 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RadialAxial.prototype = {
|
RadialAxial.prototype = {
|
||||||
getIR: function radialAxialShadingGetIR() {
|
getIR: function RadialAxial_getIR() {
|
||||||
var coordsArr = this.coordsArr;
|
var coordsArr = this.coordsArr;
|
||||||
var type = this.shadingType;
|
var type = this.shadingType;
|
||||||
if (type == PatternType.AXIAL) {
|
if (type == PatternType.AXIAL) {
|
||||||
@ -173,12 +172,12 @@ Shadings.Dummy = (function DummyClosure() {
|
|||||||
this.type = 'Pattern';
|
this.type = 'Pattern';
|
||||||
}
|
}
|
||||||
|
|
||||||
Dummy.fromIR = function dummyShadingFromIR() {
|
Dummy.fromIR = function Dummy_fromIR() {
|
||||||
return 'hotpink';
|
return 'hotpink';
|
||||||
};
|
};
|
||||||
|
|
||||||
Dummy.prototype = {
|
Dummy.prototype = {
|
||||||
getIR: function dummyShadingGetIR() {
|
getIR: function Dummy_getIR() {
|
||||||
return ['Dummy'];
|
return ['Dummy'];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -267,7 +266,7 @@ var TilingPattern = (function TilingPatternClosure() {
|
|||||||
this.canvas = tmpCanvas;
|
this.canvas = tmpCanvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
TilingPattern.getIR = function tiling_getIR(operatorList, dict, args) {
|
TilingPattern.getIR = function TilingPattern_getIR(operatorList, dict, args) {
|
||||||
var matrix = dict.get('Matrix');
|
var matrix = dict.get('Matrix');
|
||||||
var bbox = dict.get('BBox');
|
var bbox = dict.get('BBox');
|
||||||
var xstep = dict.get('XStep');
|
var xstep = dict.get('XStep');
|
||||||
@ -280,7 +279,7 @@ var TilingPattern = (function TilingPatternClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TilingPattern.prototype = {
|
TilingPattern.prototype = {
|
||||||
getPattern: function tiling_getPattern() {
|
getPattern: function TilingPattern_getPattern() {
|
||||||
var matrix = this.matrix;
|
var matrix = this.matrix;
|
||||||
var curMatrix = this.curMatrix;
|
var curMatrix = this.curMatrix;
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
|
@ -18,14 +18,14 @@ var Stream = (function StreamClosure() {
|
|||||||
get length() {
|
get length() {
|
||||||
return this.end - this.start;
|
return this.end - this.start;
|
||||||
},
|
},
|
||||||
getByte: function stream_getByte() {
|
getByte: function Stream_getByte() {
|
||||||
if (this.pos >= this.end)
|
if (this.pos >= this.end)
|
||||||
return null;
|
return null;
|
||||||
return this.bytes[this.pos++];
|
return this.bytes[this.pos++];
|
||||||
},
|
},
|
||||||
// returns subarray of original buffer
|
// returns subarray of original buffer
|
||||||
// should only be read
|
// should only be read
|
||||||
getBytes: function stream_getBytes(length) {
|
getBytes: function Stream_getBytes(length) {
|
||||||
var bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
var pos = this.pos;
|
var pos = this.pos;
|
||||||
var strEnd = this.end;
|
var strEnd = this.end;
|
||||||
@ -40,28 +40,28 @@ var Stream = (function StreamClosure() {
|
|||||||
this.pos = end;
|
this.pos = end;
|
||||||
return bytes.subarray(pos, end);
|
return bytes.subarray(pos, end);
|
||||||
},
|
},
|
||||||
lookChar: function stream_lookChar() {
|
lookChar: function Stream_lookChar() {
|
||||||
if (this.pos >= this.end)
|
if (this.pos >= this.end)
|
||||||
return null;
|
return null;
|
||||||
return String.fromCharCode(this.bytes[this.pos]);
|
return String.fromCharCode(this.bytes[this.pos]);
|
||||||
},
|
},
|
||||||
getChar: function stream_getChar() {
|
getChar: function Stream_getChar() {
|
||||||
if (this.pos >= this.end)
|
if (this.pos >= this.end)
|
||||||
return null;
|
return null;
|
||||||
return String.fromCharCode(this.bytes[this.pos++]);
|
return String.fromCharCode(this.bytes[this.pos++]);
|
||||||
},
|
},
|
||||||
skip: function stream_skip(n) {
|
skip: function Stream_skip(n) {
|
||||||
if (!n)
|
if (!n)
|
||||||
n = 1;
|
n = 1;
|
||||||
this.pos += n;
|
this.pos += n;
|
||||||
},
|
},
|
||||||
reset: function stream_reset() {
|
reset: function Stream_reset() {
|
||||||
this.pos = this.start;
|
this.pos = this.start;
|
||||||
},
|
},
|
||||||
moveStart: function stream_moveStart() {
|
moveStart: function Stream_moveStart() {
|
||||||
this.start = this.pos;
|
this.start = this.pos;
|
||||||
},
|
},
|
||||||
makeSubStream: function stream_makeSubstream(start, length, dict) {
|
makeSubStream: function Stream_makeSubStream(start, length, dict) {
|
||||||
return new Stream(this.bytes.buffer, start, length, dict);
|
return new Stream(this.bytes.buffer, start, length, dict);
|
||||||
},
|
},
|
||||||
isStream: true
|
isStream: true
|
||||||
@ -94,7 +94,7 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DecodeStream.prototype = {
|
DecodeStream.prototype = {
|
||||||
ensureBuffer: function decodestream_ensureBuffer(requested) {
|
ensureBuffer: function DecodeStream_ensureBuffer(requested) {
|
||||||
var buffer = this.buffer;
|
var buffer = this.buffer;
|
||||||
var current = buffer ? buffer.byteLength : 0;
|
var current = buffer ? buffer.byteLength : 0;
|
||||||
if (requested < current)
|
if (requested < current)
|
||||||
@ -107,7 +107,7 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
buffer2[i] = buffer[i];
|
buffer2[i] = buffer[i];
|
||||||
return (this.buffer = buffer2);
|
return (this.buffer = buffer2);
|
||||||
},
|
},
|
||||||
getByte: function decodestream_getByte() {
|
getByte: function DecodeStream_getByte() {
|
||||||
var pos = this.pos;
|
var pos = this.pos;
|
||||||
while (this.bufferLength <= pos) {
|
while (this.bufferLength <= pos) {
|
||||||
if (this.eof)
|
if (this.eof)
|
||||||
@ -116,7 +116,7 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
}
|
}
|
||||||
return this.buffer[this.pos++];
|
return this.buffer[this.pos++];
|
||||||
},
|
},
|
||||||
getBytes: function decodestream_getBytes(length) {
|
getBytes: function DecodeStream_getBytes(length) {
|
||||||
var end, pos = this.pos;
|
var end, pos = this.pos;
|
||||||
|
|
||||||
if (length) {
|
if (length) {
|
||||||
@ -144,7 +144,7 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
this.pos = end;
|
this.pos = end;
|
||||||
return this.buffer.subarray(pos, end);
|
return this.buffer.subarray(pos, end);
|
||||||
},
|
},
|
||||||
lookChar: function decodestream_lookChar() {
|
lookChar: function DecodeStream_lookChar() {
|
||||||
var pos = this.pos;
|
var pos = this.pos;
|
||||||
while (this.bufferLength <= pos) {
|
while (this.bufferLength <= pos) {
|
||||||
if (this.eof)
|
if (this.eof)
|
||||||
@ -153,7 +153,7 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
}
|
}
|
||||||
return String.fromCharCode(this.buffer[this.pos]);
|
return String.fromCharCode(this.buffer[this.pos]);
|
||||||
},
|
},
|
||||||
getChar: function decodestream_getChar() {
|
getChar: function DecodeStream_getChar() {
|
||||||
var pos = this.pos;
|
var pos = this.pos;
|
||||||
while (this.bufferLength <= pos) {
|
while (this.bufferLength <= pos) {
|
||||||
if (this.eof)
|
if (this.eof)
|
||||||
@ -162,18 +162,18 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
}
|
}
|
||||||
return String.fromCharCode(this.buffer[this.pos++]);
|
return String.fromCharCode(this.buffer[this.pos++]);
|
||||||
},
|
},
|
||||||
makeSubStream: function decodestream_makeSubstream(start, length, dict) {
|
makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
|
||||||
var end = start + length;
|
var end = start + length;
|
||||||
while (this.bufferLength <= end && !this.eof)
|
while (this.bufferLength <= end && !this.eof)
|
||||||
this.readBlock();
|
this.readBlock();
|
||||||
return new Stream(this.buffer, start, length, dict);
|
return new Stream(this.buffer, start, length, dict);
|
||||||
},
|
},
|
||||||
skip: function decodestream_skip(n) {
|
skip: function DecodeStream_skip(n) {
|
||||||
if (!n)
|
if (!n)
|
||||||
n = 1;
|
n = 1;
|
||||||
this.pos += n;
|
this.pos += n;
|
||||||
},
|
},
|
||||||
reset: function decodestream_reset() {
|
reset: function DecodeStream_reset() {
|
||||||
this.pos = 0;
|
this.pos = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -188,14 +188,14 @@ var FakeStream = (function FakeStreamClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FakeStream.prototype = Object.create(DecodeStream.prototype);
|
FakeStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
FakeStream.prototype.readBlock = function fakeStreamReadBlock() {
|
FakeStream.prototype.readBlock = function FakeStream_readBlock() {
|
||||||
var bufferLength = this.bufferLength;
|
var bufferLength = this.bufferLength;
|
||||||
bufferLength += 1024;
|
bufferLength += 1024;
|
||||||
var buffer = this.ensureBuffer(bufferLength);
|
var buffer = this.ensureBuffer(bufferLength);
|
||||||
this.bufferLength = bufferLength;
|
this.bufferLength = bufferLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeStream.prototype.getBytes = function fakeStreamGetBytes(length) {
|
FakeStream.prototype.getBytes = function FakeStream_getBytes(length) {
|
||||||
var end, pos = this.pos;
|
var end, pos = this.pos;
|
||||||
|
|
||||||
if (length) {
|
if (length) {
|
||||||
@ -368,7 +368,7 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
|
|
||||||
FlateStream.prototype = Object.create(DecodeStream.prototype);
|
FlateStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
FlateStream.prototype.getBits = function flateStreamGetBits(bits) {
|
FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
|
||||||
var codeSize = this.codeSize;
|
var codeSize = this.codeSize;
|
||||||
var codeBuf = this.codeBuf;
|
var codeBuf = this.codeBuf;
|
||||||
var bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
@ -388,7 +388,7 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
return b;
|
return b;
|
||||||
};
|
};
|
||||||
|
|
||||||
FlateStream.prototype.getCode = function flateStreamGetCode(table) {
|
FlateStream.prototype.getCode = function FlateStream_getCode(table) {
|
||||||
var codes = table[0];
|
var codes = table[0];
|
||||||
var maxLen = table[1];
|
var maxLen = table[1];
|
||||||
var codeSize = this.codeSize;
|
var codeSize = this.codeSize;
|
||||||
@ -453,7 +453,7 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
return [codes, maxLen];
|
return [codes, maxLen];
|
||||||
};
|
};
|
||||||
|
|
||||||
FlateStream.prototype.readBlock = function flateStreamReadBlock() {
|
FlateStream.prototype.readBlock = function FlateStream_readBlock() {
|
||||||
// read block header
|
// read block header
|
||||||
var hdr = this.getBits(3);
|
var hdr = this.getBits(3);
|
||||||
if (hdr & 1)
|
if (hdr & 1)
|
||||||
@ -823,7 +823,7 @@ var JpegStream = (function JpegStreamClosure() {
|
|||||||
|
|
||||||
JpegStream.prototype = Object.create(DecodeStream.prototype);
|
JpegStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
JpegStream.prototype.ensureBuffer = function jpegStreamEnsureBuffer(req) {
|
JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
|
||||||
if (this.bufferLength)
|
if (this.bufferLength)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
@ -840,18 +840,18 @@ var JpegStream = (function JpegStreamClosure() {
|
|||||||
error('JPEG error: ' + e);
|
error('JPEG error: ' + e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
JpegStream.prototype.getIR = function jpegStreamGetIR() {
|
JpegStream.prototype.getIR = function JpegStream_getIR() {
|
||||||
return bytesToString(this.bytes);
|
return bytesToString(this.bytes);
|
||||||
};
|
};
|
||||||
JpegStream.prototype.getChar = function jpegStreamGetChar() {
|
JpegStream.prototype.getChar = function JpegStream_getChar() {
|
||||||
error('internal error: getChar is not valid on JpegStream');
|
error('internal error: getChar is not valid on JpegStream');
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Checks if the image can be decoded and displayed by the browser without any
|
* Checks if the image can be decoded and displayed by the browser without any
|
||||||
* further processing such as color space conversions.
|
* further processing such as color space conversions.
|
||||||
*/
|
*/
|
||||||
JpegStream.prototype.isNativelySupported = function isNativelySupported(xref,
|
JpegStream.prototype.isNativelySupported =
|
||||||
res) {
|
function JpegStream_isNativelySupported(xref, res) {
|
||||||
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res);
|
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res);
|
||||||
// when bug 674619 lands, let's check if browser can do
|
// when bug 674619 lands, let's check if browser can do
|
||||||
// normal cmyk and then we won't need to decode in JS
|
// normal cmyk and then we won't need to decode in JS
|
||||||
@ -865,8 +865,8 @@ var JpegStream = (function JpegStreamClosure() {
|
|||||||
/**
|
/**
|
||||||
* Checks if the image can be decoded by the browser.
|
* Checks if the image can be decoded by the browser.
|
||||||
*/
|
*/
|
||||||
JpegStream.prototype.isNativelyDecodable = function isNativelyDecodable(xref,
|
JpegStream.prototype.isNativelyDecodable =
|
||||||
res) {
|
function JpegStream_isNativelyDecodable(xref, res) {
|
||||||
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res);
|
var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res);
|
||||||
var numComps = cs.numComps;
|
var numComps = cs.numComps;
|
||||||
if (numComps == 1 || numComps == 3)
|
if (numComps == 1 || numComps == 3)
|
||||||
@ -892,7 +892,7 @@ var JpxStream = (function JpxStreamClosure() {
|
|||||||
|
|
||||||
JpxStream.prototype = Object.create(DecodeStream.prototype);
|
JpxStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
JpxStream.prototype.ensureBuffer = function jpxStreamEnsureBuffer(req) {
|
JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
|
||||||
if (this.bufferLength)
|
if (this.bufferLength)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -972,7 +972,7 @@ var JpxStream = (function JpxStreamClosure() {
|
|||||||
this.buffer = data;
|
this.buffer = data;
|
||||||
this.bufferLength = data.length;
|
this.bufferLength = data.length;
|
||||||
};
|
};
|
||||||
JpxStream.prototype.getChar = function jpxStreamGetChar() {
|
JpxStream.prototype.getChar = function JpxStream_getChar() {
|
||||||
error('internal error: getChar is not valid on JpxStream');
|
error('internal error: getChar is not valid on JpxStream');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -992,7 +992,7 @@ var DecryptStream = (function DecryptStreamClosure() {
|
|||||||
|
|
||||||
DecryptStream.prototype = Object.create(DecodeStream.prototype);
|
DecryptStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
DecryptStream.prototype.readBlock = function decryptStreamReadBlock() {
|
DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
|
||||||
var chunk = this.str.getBytes(chunkSize);
|
var chunk = this.str.getBytes(chunkSize);
|
||||||
if (!chunk || chunk.length == 0) {
|
if (!chunk || chunk.length == 0) {
|
||||||
this.eof = true;
|
this.eof = true;
|
||||||
@ -1023,7 +1023,7 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
|
|||||||
|
|
||||||
Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
|
Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
Ascii85Stream.prototype.readBlock = function ascii85StreamReadBlock() {
|
Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
|
||||||
var tildaCode = '~'.charCodeAt(0);
|
var tildaCode = '~'.charCodeAt(0);
|
||||||
var zCode = 'z'.charCodeAt(0);
|
var zCode = 'z'.charCodeAt(0);
|
||||||
var str = this.str;
|
var str = this.str;
|
||||||
@ -1118,7 +1118,7 @@ var AsciiHexStream = (function AsciiHexStreamClosure() {
|
|||||||
|
|
||||||
AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
|
AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
AsciiHexStream.prototype.readBlock = function asciiHexStreamReadBlock() {
|
AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
|
||||||
var gtCode = '>'.charCodeAt(0), bytes = this.str.getBytes(), c, n,
|
var gtCode = '>'.charCodeAt(0), bytes = this.str.getBytes(), c, n,
|
||||||
decodeLength, buffer, bufferLength, i, length;
|
decodeLength, buffer, bufferLength, i, length;
|
||||||
|
|
||||||
@ -1161,7 +1161,7 @@ var RunLengthStream = (function RunLengthStreamClosure() {
|
|||||||
|
|
||||||
RunLengthStream.prototype = Object.create(DecodeStream.prototype);
|
RunLengthStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
RunLengthStream.prototype.readBlock = function runLengthStreamReadBlock() {
|
RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
|
||||||
// The repeatHeader has following format. The first byte defines type of run
|
// The repeatHeader has following format. The first byte defines type of run
|
||||||
// and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
|
// and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
|
||||||
// (in addition to the second byte from the header), n = 129 through 255 -
|
// (in addition to the second byte from the header), n = 129 through 255 -
|
||||||
@ -1671,7 +1671,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
|
|
||||||
CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
|
CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
CCITTFaxStream.prototype.readBlock = function ccittFaxStreamReadBlock() {
|
CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
|
||||||
while (!this.eof) {
|
while (!this.eof) {
|
||||||
var c = this.lookChar();
|
var c = this.lookChar();
|
||||||
this.buf = EOF;
|
this.buf = EOF;
|
||||||
@ -1729,7 +1729,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
this.codingPos = codingPos;
|
this.codingPos = codingPos;
|
||||||
};
|
};
|
||||||
|
|
||||||
CCITTFaxStream.prototype.lookChar = function ccittFaxStreamLookChar() {
|
CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
|
||||||
if (this.buf != EOF)
|
if (this.buf != EOF)
|
||||||
return this.buf;
|
return this.buf;
|
||||||
|
|
||||||
@ -2140,7 +2140,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
CCITTFaxStream.prototype.lookBits = function ccittFaxStreamLookBits(n) {
|
CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
|
||||||
var c;
|
var c;
|
||||||
while (this.inputBits < n) {
|
while (this.inputBits < n) {
|
||||||
if ((c = this.str.getByte()) == null) {
|
if ((c = this.str.getByte()) == null) {
|
||||||
@ -2155,7 +2155,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
|
return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
|
||||||
};
|
};
|
||||||
|
|
||||||
CCITTFaxStream.prototype.eatBits = function ccittFaxStreamEatBits(n) {
|
CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
|
||||||
if ((this.inputBits -= n) < 0)
|
if ((this.inputBits -= n) < 0)
|
||||||
this.inputBits = 0;
|
this.inputBits = 0;
|
||||||
};
|
};
|
||||||
@ -2192,7 +2192,7 @@ var LZWStream = (function LZWStreamClosure() {
|
|||||||
|
|
||||||
LZWStream.prototype = Object.create(DecodeStream.prototype);
|
LZWStream.prototype = Object.create(DecodeStream.prototype);
|
||||||
|
|
||||||
LZWStream.prototype.readBits = function lzwStreamReadBits(n) {
|
LZWStream.prototype.readBits = function LZWStream_readBits(n) {
|
||||||
var bitsCached = this.bitsCached;
|
var bitsCached = this.bitsCached;
|
||||||
var cachedData = this.cachedData;
|
var cachedData = this.cachedData;
|
||||||
while (bitsCached < n) {
|
while (bitsCached < n) {
|
||||||
@ -2210,7 +2210,7 @@ var LZWStream = (function LZWStreamClosure() {
|
|||||||
return (cachedData >>> bitsCached) & ((1 << n) - 1);
|
return (cachedData >>> bitsCached) & ((1 << n) - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
LZWStream.prototype.readBlock = function lzwStreamReadBlock() {
|
LZWStream.prototype.readBlock = function LZWStream_readBlock() {
|
||||||
var blockSize = 512;
|
var blockSize = 512;
|
||||||
var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
|
var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
|
||||||
var i, j, q;
|
var i, j, q;
|
||||||
|
30
src/util.js
30
src/util.js
@ -79,19 +79,19 @@ var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
|
|||||||
var Util = (function UtilClosure() {
|
var Util = (function UtilClosure() {
|
||||||
function Util() {}
|
function Util() {}
|
||||||
|
|
||||||
Util.makeCssRgb = function makergb(r, g, b) {
|
Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
|
||||||
var ri = (255 * r) | 0, gi = (255 * g) | 0, bi = (255 * b) | 0;
|
var ri = (255 * r) | 0, gi = (255 * g) | 0, bi = (255 * b) | 0;
|
||||||
return 'rgb(' + ri + ',' + gi + ',' + bi + ')';
|
return 'rgb(' + ri + ',' + gi + ',' + bi + ')';
|
||||||
};
|
};
|
||||||
|
|
||||||
Util.makeCssCmyk = function makecmyk(c, m, y, k) {
|
Util.makeCssCmyk = function Util_makeCssCmyk(c, m, y, k) {
|
||||||
c = (new DeviceCmykCS()).getRgb([c, m, y, k]);
|
c = (new DeviceCmykCS()).getRgb([c, m, y, k]);
|
||||||
var ri = (255 * c[0]) | 0, gi = (255 * c[1]) | 0, bi = (255 * c[2]) | 0;
|
var ri = (255 * c[0]) | 0, gi = (255 * c[1]) | 0, bi = (255 * c[2]) | 0;
|
||||||
return 'rgb(' + ri + ',' + gi + ',' + bi + ')';
|
return 'rgb(' + ri + ',' + gi + ',' + bi + ')';
|
||||||
};
|
};
|
||||||
|
|
||||||
// For 2d affine transforms
|
// For 2d affine transforms
|
||||||
Util.applyTransform = function apply(p, m) {
|
Util.applyTransform = function Util_applyTransform(p, m) {
|
||||||
var xt = p[0] * m[0] + p[1] * m[2] + m[4];
|
var xt = p[0] * m[0] + p[1] * m[2] + m[4];
|
||||||
var yt = p[0] * m[1] + p[1] * m[3] + m[5];
|
var yt = p[0] * m[1] + p[1] * m[3] + m[5];
|
||||||
return [xt, yt];
|
return [xt, yt];
|
||||||
@ -103,7 +103,7 @@ var Util = (function UtilClosure() {
|
|||||||
// | g h i | | Z |
|
// | g h i | | Z |
|
||||||
// M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
|
// M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
|
||||||
// with v as [X,Y,Z]
|
// with v as [X,Y,Z]
|
||||||
Util.apply3dTransform = function apply3d(m, v) {
|
Util.apply3dTransform = function Util_apply3dTransform(m, v) {
|
||||||
return [
|
return [
|
||||||
m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
|
m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
|
||||||
m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
|
m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
|
||||||
@ -115,7 +115,7 @@ var Util = (function UtilClosure() {
|
|||||||
// For coordinate systems whose origin lies in the bottom-left, this
|
// For coordinate systems whose origin lies in the bottom-left, this
|
||||||
// means normalization to (BL,TR) ordering. For systems with origin in the
|
// means normalization to (BL,TR) ordering. For systems with origin in the
|
||||||
// top-left, this means (TL,BR) ordering.
|
// top-left, this means (TL,BR) ordering.
|
||||||
Util.normalizeRect = function normalizeRect(rect) {
|
Util.normalizeRect = function Util_normalizeRect(rect) {
|
||||||
var r = rect.slice(0); // clone rect
|
var r = rect.slice(0); // clone rect
|
||||||
if (rect[0] > rect[2]) {
|
if (rect[0] > rect[2]) {
|
||||||
r[0] = rect[2];
|
r[0] = rect[2];
|
||||||
@ -131,7 +131,7 @@ var Util = (function UtilClosure() {
|
|||||||
// Returns a rectangle [x1, y1, x2, y2] corresponding to the
|
// Returns a rectangle [x1, y1, x2, y2] corresponding to the
|
||||||
// intersection of rect1 and rect2. If no intersection, returns 'false'
|
// intersection of rect1 and rect2. If no intersection, returns 'false'
|
||||||
// The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
|
// The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
|
||||||
Util.intersect = function intersect(rect1, rect2) {
|
Util.intersect = function Util_intersect(rect1, rect2) {
|
||||||
function compare(a, b) {
|
function compare(a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
};
|
};
|
||||||
@ -167,7 +167,7 @@ var Util = (function UtilClosure() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Util.sign = function sign(num) {
|
Util.sign = function Util_sign(num) {
|
||||||
return num < 0 ? -1 : 1;
|
return num < 0 ? -1 : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ var Promise = (function PromiseClosure() {
|
|||||||
* @param {Promise[]} promises Array of promises to wait for.
|
* @param {Promise[]} promises Array of promises to wait for.
|
||||||
* @return {Promise} New dependant promise.
|
* @return {Promise} New dependant promise.
|
||||||
*/
|
*/
|
||||||
Promise.all = function(promises) {
|
Promise.all = function Promise_all(promises) {
|
||||||
var deferred = new Promise();
|
var deferred = new Promise();
|
||||||
var unresolved = promises.length;
|
var unresolved = promises.length;
|
||||||
var results = [];
|
var results = [];
|
||||||
@ -351,7 +351,7 @@ var Promise = (function PromiseClosure() {
|
|||||||
return this._data;
|
return this._data;
|
||||||
},
|
},
|
||||||
|
|
||||||
onData: function promiseOnData(callback) {
|
onData: function Promise_onData(callback) {
|
||||||
if (this._data !== EMPTY_PROMISE) {
|
if (this._data !== EMPTY_PROMISE) {
|
||||||
callback(this._data);
|
callback(this._data);
|
||||||
} else {
|
} else {
|
||||||
@ -359,7 +359,7 @@ var Promise = (function PromiseClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
resolve: function promiseResolve(data) {
|
resolve: function Promise_resolve(data) {
|
||||||
if (this.isResolved) {
|
if (this.isResolved) {
|
||||||
error('A Promise can be resolved only once ' + this.name);
|
error('A Promise can be resolved only once ' + this.name);
|
||||||
}
|
}
|
||||||
@ -376,7 +376,7 @@ var Promise = (function PromiseClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
reject: function proimseReject(reason) {
|
reject: function Promise_reject(reason) {
|
||||||
if (this.isRejected) {
|
if (this.isRejected) {
|
||||||
error('A Promise can be rejected only once ' + this.name);
|
error('A Promise can be rejected only once ' + this.name);
|
||||||
}
|
}
|
||||||
@ -393,7 +393,7 @@ var Promise = (function PromiseClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
then: function promiseThen(callback, errback) {
|
then: function Promise_then(callback, errback) {
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
error('Requiring callback' + this.name);
|
error('Requiring callback' + this.name);
|
||||||
}
|
}
|
||||||
@ -428,14 +428,14 @@ var StatTimer = (function StatTimerClosure() {
|
|||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
}
|
}
|
||||||
StatTimer.prototype = {
|
StatTimer.prototype = {
|
||||||
time: function statTimerTime(name) {
|
time: function StatTimer_time(name) {
|
||||||
if (!this.enabled)
|
if (!this.enabled)
|
||||||
return;
|
return;
|
||||||
if (name in this.started)
|
if (name in this.started)
|
||||||
throw 'Timer is already running for ' + name;
|
throw 'Timer is already running for ' + name;
|
||||||
this.started[name] = Date.now();
|
this.started[name] = Date.now();
|
||||||
},
|
},
|
||||||
timeEnd: function statTimerTimeEnd(name) {
|
timeEnd: function StatTimer_timeEnd(name) {
|
||||||
if (!this.enabled)
|
if (!this.enabled)
|
||||||
return;
|
return;
|
||||||
if (!(name in this.started))
|
if (!(name in this.started))
|
||||||
@ -448,7 +448,7 @@ var StatTimer = (function StatTimerClosure() {
|
|||||||
// Remove timer from started so it can be called again.
|
// Remove timer from started so it can be called again.
|
||||||
delete this.started[name];
|
delete this.started[name];
|
||||||
},
|
},
|
||||||
toString: function statTimerToString() {
|
toString: function StatTimer_toString() {
|
||||||
var times = this.times;
|
var times = this.times;
|
||||||
var out = '';
|
var out = '';
|
||||||
// Find the longest name for padding purposes.
|
// Find the longest name for padding purposes.
|
||||||
|
@ -122,9 +122,9 @@ function readFontDictData(aString, aMap) {
|
|||||||
token = '';
|
token = '';
|
||||||
var parsed = false;
|
var parsed = false;
|
||||||
while (!parsed) {
|
while (!parsed) {
|
||||||
var byte = aString[i++];
|
var octet = aString[i++];
|
||||||
|
|
||||||
var nibbles = [parseInt(byte / 16, 10), parseInt(byte % 16, 10)];
|
var nibbles = [parseInt(octet / 16, 10), parseInt(octet % 16, 10)];
|
||||||
for (var j = 0; j < nibbles.length; j++) {
|
for (var j = 0; j < nibbles.length; j++) {
|
||||||
var nibble = nibbles[j];
|
var nibble = nibbles[j];
|
||||||
switch (nibble) {
|
switch (nibble) {
|
||||||
@ -336,7 +336,7 @@ var Type2Parser = function type2Parser(aFilePath) {
|
|||||||
var privateDict = [];
|
var privateDict = [];
|
||||||
for (var i = 0; i < priv.size; i++)
|
for (var i = 0; i < priv.size; i++)
|
||||||
privateDict.push(aStream.getByte());
|
privateDict.push(aStream.getByte());
|
||||||
dump('private:' + privateDict);
|
dump('privateData:' + privateDict);
|
||||||
parseAsToken(privateDict, CFFDictPrivateDataMap);
|
parseAsToken(privateDict, CFFDictPrivateDataMap);
|
||||||
|
|
||||||
for (var p in font.map)
|
for (var p in font.map)
|
||||||
|
@ -248,16 +248,21 @@ function done() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendTaskResult(snapshot, task, failure) {
|
function sendTaskResult(snapshot, task, failure, result) {
|
||||||
var result = { browser: browser,
|
// Optional result argument is for retrying XHR requests - see below
|
||||||
id: task.id,
|
if (!result) {
|
||||||
numPages: task.pdfDoc ?
|
result = JSON.stringify({
|
||||||
(task.pageLimit || task.pdfDoc.numPages) : 0,
|
browser: browser,
|
||||||
failure: failure,
|
id: task.id,
|
||||||
file: task.file,
|
numPages: task.pdfDoc ?
|
||||||
round: task.round,
|
(task.pageLimit || task.pdfDoc.numPages) : 0,
|
||||||
page: task.pageNum,
|
failure: failure,
|
||||||
snapshot: snapshot };
|
file: task.file,
|
||||||
|
round: task.round,
|
||||||
|
page: task.pageNum,
|
||||||
|
snapshot: snapshot
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var r = new XMLHttpRequest();
|
var r = new XMLHttpRequest();
|
||||||
// (The POST URI is ignored atm.)
|
// (The POST URI is ignored atm.)
|
||||||
@ -266,10 +271,13 @@ function sendTaskResult(snapshot, task, failure) {
|
|||||||
r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
|
r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
|
||||||
if (r.readyState == 4) {
|
if (r.readyState == 4) {
|
||||||
inFlightRequests--;
|
inFlightRequests--;
|
||||||
|
// Retry until successful
|
||||||
|
if (r.status !== 200)
|
||||||
|
sendTaskResult(null, null, null, result);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
document.getElementById('inFlightCount').innerHTML = inFlightRequests++;
|
document.getElementById('inFlightCount').innerHTML = inFlightRequests++;
|
||||||
r.send(JSON.stringify(result));
|
r.send(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear(ctx) {
|
function clear(ctx) {
|
||||||
|
@ -1 +1 @@
|
|||||||
http://www.cdc.gov/ncidod/dvbid/westnile/languages/chinese.pdf
|
http://web.archive.org/web/20110623114753/http://www.cdc.gov/ncidod/dvbid/westnile/languages/chinese.pdf
|
||||||
|
@ -391,11 +391,43 @@ canvas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#loading {
|
#loadingBox {
|
||||||
margin: 100px 0;
|
margin: 100px 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#loadingBar {
|
||||||
|
background-color: #333;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid black;
|
||||||
|
clear: both;
|
||||||
|
margin:0px;
|
||||||
|
line-height: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
width: 15em;
|
||||||
|
height: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#loadingBar .progress {
|
||||||
|
background-color: green;
|
||||||
|
display: inline-block;
|
||||||
|
float: left;
|
||||||
|
|
||||||
|
background: #b4e391;
|
||||||
|
background: -moz-linear-gradient(top, #b4e391 0%, #61c419 50%, #b4e391 100%);
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b4e391), color-stop(50%,#61c419), color-stop(100%,#b4e391));
|
||||||
|
background: -webkit-linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
|
||||||
|
background: -o-linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
|
||||||
|
background: -ms-linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
|
||||||
|
background: linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
|
||||||
|
|
||||||
|
border-top-left-radius: 3px;
|
||||||
|
border-bottom-left-radius: 3px;
|
||||||
|
|
||||||
|
width: 0%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
#PDFBug {
|
#PDFBug {
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<!-- PDFJSSCRIPT_INCLUDE_BUILD -->
|
<!-- PDFJSSCRIPT_INCLUDE_BUILD -->
|
||||||
<script type="text/javascript" src="../src/core.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
<script type="text/javascript" src="../src/core.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
||||||
<script type="text/javascript" src="../src/util.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
<script type="text/javascript" src="../src/util.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
||||||
|
<script type="text/javascript" src="../src/metadata.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
||||||
<script type="text/javascript" src="../src/canvas.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
<script type="text/javascript" src="../src/canvas.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
||||||
<script type="text/javascript" src="../src/obj.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
<script type="text/javascript" src="../src/obj.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
||||||
<script type="text/javascript" src="../src/function.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
<script type="text/javascript" src="../src/function.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
|
||||||
@ -142,7 +143,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="loading">Loading... 0%</div>
|
<div id="loadingBox">
|
||||||
|
<div id="loading">Loading... 0%</div>
|
||||||
|
<div id="loadingBar"><div class="progress"></div></div>
|
||||||
|
</div>
|
||||||
<div id="viewer"></div>
|
<div id="viewer"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -15,6 +15,15 @@ var kMaxScale = 4.0;
|
|||||||
var kImageDirectory = './images/';
|
var kImageDirectory = './images/';
|
||||||
var kSettingsMemory = 20;
|
var kSettingsMemory = 20;
|
||||||
|
|
||||||
|
function getFileName(url) {
|
||||||
|
var anchor = url.indexOf('#');
|
||||||
|
var query = url.indexOf('?');
|
||||||
|
var end = Math.min(
|
||||||
|
anchor > 0 ? anchor : url.length,
|
||||||
|
query > 0 ? query : url.length);
|
||||||
|
return url.substring(url.lastIndexOf('/', end) + 1, end);
|
||||||
|
}
|
||||||
|
|
||||||
var Cache = function cacheCache(size) {
|
var Cache = function cacheCache(size) {
|
||||||
var data = [];
|
var data = [];
|
||||||
this.push = function cachePush(view) {
|
this.push = function cachePush(view) {
|
||||||
@ -27,6 +36,48 @@ var Cache = function cacheCache(size) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var ProgressBar = (function ProgressBarClosure() {
|
||||||
|
|
||||||
|
function clamp(v, min, max) {
|
||||||
|
return Math.min(Math.max(v, min), max);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProgressBar(id, opts) {
|
||||||
|
|
||||||
|
// Fetch the sub-elements for later
|
||||||
|
this.div = document.querySelector(id + ' .progress');
|
||||||
|
|
||||||
|
// Get options, with sensible defaults
|
||||||
|
this.height = opts.height || 100;
|
||||||
|
this.width = opts.width || 100;
|
||||||
|
this.units = opts.units || '%';
|
||||||
|
this.percent = opts.percent || 0;
|
||||||
|
|
||||||
|
// Initialize heights
|
||||||
|
this.div.style.height = this.height + this.units;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressBar.prototype = {
|
||||||
|
|
||||||
|
updateBar: function ProgressBar_updateBar() {
|
||||||
|
var progressSize = this.width * this._percent / 100;
|
||||||
|
|
||||||
|
this.div.style.width = progressSize + this.units;
|
||||||
|
},
|
||||||
|
|
||||||
|
get percent() {
|
||||||
|
return this._percent;
|
||||||
|
},
|
||||||
|
|
||||||
|
set percent(val) {
|
||||||
|
this._percent = clamp(val, 0, 100);
|
||||||
|
this.updateBar();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return ProgressBar;
|
||||||
|
})();
|
||||||
|
|
||||||
var RenderingQueue = (function RenderingQueueClosure() {
|
var RenderingQueue = (function RenderingQueueClosure() {
|
||||||
function RenderingQueue() {
|
function RenderingQueue() {
|
||||||
this.items = [];
|
this.items = [];
|
||||||
@ -258,7 +309,13 @@ var PDFView = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
open: function pdfViewOpen(url, scale) {
|
open: function pdfViewOpen(url, scale) {
|
||||||
document.title = this.url = url;
|
this.url = url;
|
||||||
|
|
||||||
|
document.title = decodeURIComponent(getFileName(url)) || url;
|
||||||
|
|
||||||
|
if (!PDFView.loadingBar) {
|
||||||
|
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
|
||||||
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
PDFJS.getPdf(
|
PDFJS.getPdf(
|
||||||
@ -400,6 +457,8 @@ var PDFView = {
|
|||||||
var percent = Math.round(level * 100);
|
var percent = Math.round(level * 100);
|
||||||
var loadingIndicator = document.getElementById('loading');
|
var loadingIndicator = document.getElementById('loading');
|
||||||
loadingIndicator.textContent = 'Loading... ' + percent + '%';
|
loadingIndicator.textContent = 'Loading... ' + percent + '%';
|
||||||
|
|
||||||
|
PDFView.loadingBar.percent = percent;
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function pdfViewLoad(data, scale) {
|
load: function pdfViewLoad(data, scale) {
|
||||||
@ -414,8 +473,8 @@ var PDFView = {
|
|||||||
var errorWrapper = document.getElementById('errorWrapper');
|
var errorWrapper = document.getElementById('errorWrapper');
|
||||||
errorWrapper.setAttribute('hidden', 'true');
|
errorWrapper.setAttribute('hidden', 'true');
|
||||||
|
|
||||||
var loadingIndicator = document.getElementById('loading');
|
var loadingBox = document.getElementById('loadingBox');
|
||||||
loadingIndicator.setAttribute('hidden', 'true');
|
loadingBox.setAttribute('hidden', 'true');
|
||||||
|
|
||||||
var sidebar = document.getElementById('sidebarView');
|
var sidebar = document.getElementById('sidebarView');
|
||||||
sidebar.parentNode.scrollTop = 0;
|
sidebar.parentNode.scrollTop = 0;
|
||||||
@ -499,6 +558,24 @@ var PDFView = {
|
|||||||
// Setting the default one.
|
// Setting the default one.
|
||||||
this.parseScale(kDefaultScale, true);
|
this.parseScale(kDefaultScale, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.metadata = null;
|
||||||
|
var metadata = pdf.catalog.metadata;
|
||||||
|
var info = this.documentInfo = pdf.info;
|
||||||
|
var pdfTitle;
|
||||||
|
|
||||||
|
if (metadata) {
|
||||||
|
this.metadata = metadata = new PDFJS.Metadata(metadata);
|
||||||
|
|
||||||
|
if (metadata.has('dc:title'))
|
||||||
|
pdfTitle = metadata.get('dc:title');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pdfTitle && info && info.has('Title'))
|
||||||
|
pdfTitle = info.get('Title');
|
||||||
|
|
||||||
|
if (pdfTitle)
|
||||||
|
document.title = pdfTitle;
|
||||||
},
|
},
|
||||||
|
|
||||||
setHash: function pdfViewSetHash(hash) {
|
setHash: function pdfViewSetHash(hash) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user