Merge branch 'master' of git://github.com/mozilla/pdf.js.git into loadingbychrome

Conflicts:
	web/viewer.js
This commit is contained in:
Yury Delendik 2012-08-15 10:17:30 -05:00
commit 9cc5fc4e38
30 changed files with 839 additions and 430 deletions

2
.gitignore vendored
View File

@ -2,4 +2,4 @@
local.mk local.mk
build/ build/
tags tags
.DS_Store

View File

@ -61,13 +61,13 @@ You can also view all the test pdf files on the right side serving
+ http://localhost:8888/test/pdfs/?frame + http://localhost:8888/test/pdfs/?frame
### Building pdf.js ### Building pdf.js.
In order to bundle all `src/` files into a final `pdf.js`, issue: In order to bundle all `src/` files into a final `pdf.js` and build the generic viewer, issue:
$ node make bundle $ node make generic
This will generate the file `build/pdf.js` that can be included in your final project. (WARNING: That's a large file! Consider minifying it). This will generate the file `build/generic/build/pdf.js` that can be included in your final project. The pdf.js file is large and should be minified for production. Also, if you would like to support more browsers than firefox you'll also need to include `compatibility.js` from `build/generic/web/`.
# Learning # Learning

View File

@ -281,9 +281,26 @@ ChromeActions.prototype = {
var strings = getLocalizedStrings('chrome.properties'); var strings = getLocalizedStrings('chrome.properties');
var message = getLocalizedString(strings, 'unsupported_feature'); var message = getLocalizedString(strings, 'unsupported_feature');
var win = Services.wm.getMostRecentWindow('navigator:browser'); var notificationBox = null;
var browser = win.gBrowser.getBrowserForDocument(domWindow.top.document); // Multiple browser windows can be opened, finding one for notification box
var notificationBox = win.gBrowser.getNotificationBox(browser); var windowsEnum = Services.wm
.getZOrderDOMWindowEnumerator('navigator:browser', true);
while (windowsEnum.hasMoreElements()) {
var win = windowsEnum.getNext();
if (win.closed)
continue;
var browser = win.gBrowser.getBrowserForDocument(domWindow.top.document);
if (browser) {
// right window/browser is found, getting the notification box
notificationBox = win.gBrowser.getNotificationBox(browser);
break;
}
}
if (!notificationBox) {
log('Unable to get a notification box for the fallback message');
return;
}
// Flag so we don't call the response callback twice, since if the user // Flag so we don't call the response callback twice, since if the user
// clicks open with different viewer both the button callback and // clicks open with different viewer both the button callback and
// eventCallback will be called. // eventCallback will be called.

View File

@ -13,7 +13,7 @@
<em:targetApplication> <em:targetApplication>
<Description> <Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>6.0</em:minVersion> <em:minVersion>10.0</em:minVersion>
<em:maxVersion>15.0a1</em:maxVersion> <em:maxVersion>15.0a1</em:maxVersion>
</Description> </Description>
</em:targetApplication> </em:targetApplication>
@ -22,7 +22,7 @@
<em:targetApplication> <em:targetApplication>
<Description> <Description>
<em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id> <em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id>
<em:minVersion>2.1.*</em:minVersion> <em:minVersion>2.7</em:minVersion>
<em:maxVersion>2.12a1</em:maxVersion> <em:maxVersion>2.12a1</em:maxVersion>
</Description> </Description>
</em:targetApplication> </em:targetApplication>

142
external/builder/builder.js vendored Normal file
View File

@ -0,0 +1,142 @@
require('../shelljs/make');
var fs = require('fs'),
path = require('path'),
vm = require('vm');
/**
* A simple preprocessor that is based on the firefox preprocessor
* see (https://developer.mozilla.org/en/Build/Text_Preprocessor). The main
* difference is that this supports a subset of the commands and it supports
* preproccesor commands in html style comments.
* Currently Supported commands:
* - if
* - else
* - endif
* - include
* - expand
*/
function preprocess(inFilename, outFilename, defines) {
// TODO make this really read line by line.
var lines = fs.readFileSync(inFilename).toString().split('\n');
var totalLines = lines.length;
var out = '';
var i = 0;
function readLine() {
if (i < totalLines) {
return lines[i++];
}
return null;
}
var writeLine = typeof outFilename === 'function' ? outFilename : function(line) {
out += line + '\n';
}
function include(file) {
var realPath = fs.realpathSync(inFilename);
var dir = path.dirname(realPath);
preprocess(path.join(dir, file), writeLine, defines);
}
function expand(line) {
line = line.replace(/__[\w]+__/g, function(variable) {
variable = variable.substring(2, variable.length - 2);
if (variable in defines) {
return defines[variable];
}
return '';
});
writeLine(line);
}
var s, state = 0, stack = [];
var control = /^(?:\/\/|<!--)\s*#(if|else|endif|expand|include)(?:\s+(.*?)(?:-->)?$)?/;
var lineNumber = 0;
while ((s = readLine()) !== null) {
++lineNumber;
var m = control.exec(s);
if (m) {
switch (m[1]) {
case 'if':
stack.push(state);
try {
state = vm.runInNewContext(m[2], defines) ? 3 : 1;
} catch (e) {
console.error('Could not evalute line \'' + m[2] + '\' at ' +
fs.realpathSync(inFilename) + ':' + lineNumber);
throw e;
}
break;
case 'else':
state = state === 1 ? 3 : 2;
break;
case 'endif':
state = stack.pop();
break;
case 'expand':
if (state === 0 || state === 3)
expand(m[2]);
break;
case 'include':
if (state === 0 || state === 3)
include(m[2]);
break;
}
} else {
if (state === 0) {
writeLine(s);
} else if(state === 3) {
writeLine(s.replace(/^\/\/|^<!--|-->/g, " "));
}
}
}
if (state !== 0 || stack.length !== 0)
throw new Error('Missing endif in preprocessor.');
if (typeof outFilename !== 'function')
fs.writeFileSync(outFilename, out);
}
exports.preprocess = preprocess;
/**
* Simplifies common build steps.
* @param setup
* .defines defines for preprocessors
* .copy array of arrays of source and destination pairs of files to copy
* .preprocess array of arrays of source and destination pairs of files
* run through preprocessor
*/
function build(setup) {
var defines = setup.defines;
setup.copy.forEach(function(option) {
var source = option[0];
var destination = option[1];
cp('-R', source, destination);
});
setup.preprocess.forEach(function(option) {
var sources = option[0];
var destination = option[1];
sources = ls('-R', sources);
sources.forEach(function(source) {
// ??? Warn if the source is wildcard and dest is file?
var destWithFolder = destination;
if (test('-d', destination))
destWithFolder += '/' + path.basename(source);
preprocess(source, destWithFolder, defines);
});
});
}
exports.build = build;
/**
* Merge two defines arrays. Values in the second param will override values in
* the first.
*/
function merge(defaults, defines) {
var ret = {};
for (var key in defaults)
ret[key] = defaults[key];
for (key in defines)
ret[key] = defines[key];
return ret;
}
exports.merge = merge;

View File

@ -18,11 +18,13 @@ zoom_in_label=Ampliar
zoom.title=Ampliación zoom.title=Ampliación
print.title=Imprimir print.title=Imprimir
print_label=Imprimir print_label=Imprimir
fullscreen.title=Pantalla completa
fullscreen_label=Pantalla completa
open_file.title=Abrir archivo open_file.title=Abrir archivo
open_file_label=Abrir open_file_label=Abrir
download.title=Descargar download.title=Descargar
download_label=Descargar download_label=Descargar
bookmark.title=Vista actual (copiar o abrir en una ventana nueva) bookmark.title=Vista actual (copie o abra en una ventana nueva)
bookmark_label=Vista actual bookmark_label=Vista actual
# Tooltips and alt text for side panel toolbar buttons # Tooltips and alt text for side panel toolbar buttons
@ -69,7 +71,7 @@ error_stack=Pila: {{stack}}
error_file=Archivo: {{file}} error_file=Archivo: {{file}}
# LOCALIZATION NOTE (error_line): "{{line}}" will be replaced with a line number # LOCALIZATION NOTE (error_line): "{{line}}" will be replaced with a line number
error_line=Línea: {{line}} error_line=Línea: {{line}}
rendering_error=Ocurrió un error al renderizar la página. rendering_error=Ocurrió un error mientras se renderizaba la página.
# Predefined zoom values # Predefined zoom values
page_scale_width=Anchura de página page_scale_width=Anchura de página
@ -79,7 +81,7 @@ page_scale_actual=Tamaño real
# Loading indicator messages # Loading indicator messages
loading_error_indicator=Error loading_error_indicator=Error
loading_error=Ocurrió un error al cargar el PDF. loading_error=Ocurrió un error mientras se cargaba el PDF.
# LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip. # LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip.
# "{{type}}" will be replaced with an annotation type from a list defined in # "{{type}}" will be replaced with an annotation type from a list defined in
@ -87,3 +89,5 @@ loading_error=Ocurrió un error al cargar el PDF.
# Some common types are e.g.: "Check", "Text", "Comment", "Note" # Some common types are e.g.: "Check", "Text", "Comment", "Note"
text_annotation_type=[Anotación {{type}}] text_annotation_type=[Anotación {{type}}]
request_password=El PDF está protegido con una contraseña: request_password=El PDF está protegido con una contraseña:
printing_not_supported=Aviso: La impresión no es compatible totalmente con este navegador.

View File

@ -18,6 +18,8 @@ zoom_in_label=拡大
zoom.title=ズーム zoom.title=ズーム
print.title=印刷 print.title=印刷
print_label=印刷 print_label=印刷
fullscreen.title=全画面表示
fullscreen_label=全画面表示
open_file.title=ファイルを開く open_file.title=ファイルを開く
open_file_label=開く open_file_label=開く
download.title=ダウンロード download.title=ダウンロード

254
make.js
View File

@ -1,5 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
require('./external/shelljs/make'); require('./external/shelljs/make');
var builder = require('./external/builder/builder.js');
var ROOT_DIR = __dirname + '/', // absolute path to project's root var ROOT_DIR = __dirname + '/', // absolute path to project's root
BUILD_DIR = 'build/', BUILD_DIR = 'build/',
@ -8,6 +9,7 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root
EXTENSION_SRC_DIR = 'extensions/', EXTENSION_SRC_DIR = 'extensions/',
LOCALE_SRC_DIR = 'l10n/', LOCALE_SRC_DIR = 'l10n/',
GH_PAGES_DIR = BUILD_DIR + 'gh-pages/', GH_PAGES_DIR = BUILD_DIR + 'gh-pages/',
GENERIC_DIR = BUILD_DIR + 'generic/',
REPO = 'git@github.com:mozilla/pdf.js.git', REPO = 'git@github.com:mozilla/pdf.js.git',
PYTHON_BIN = 'python2.7', PYTHON_BIN = 'python2.7',
MOZCENTRAL_PREF_PREFIX = 'pdfjs', MOZCENTRAL_PREF_PREFIX = 'pdfjs',
@ -15,6 +17,16 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root
MOZCENTRAL_STREAM_CONVERTER_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2291', MOZCENTRAL_STREAM_CONVERTER_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2291',
FIREFOX_STREAM_CONVERTER_ID = '6457a96b-2d68-439a-bcfa-44465fbcdbb1'; FIREFOX_STREAM_CONVERTER_ID = '6457a96b-2d68-439a-bcfa-44465fbcdbb1';
var DEFINES = {
PRODUCTION: true,
// The main build targets:
GENERIC: false,
FIREFOX: false,
MOZCENTRAL: false,
B2G: false,
CHROME: false
};
// //
// make all // make all
// //
@ -31,14 +43,59 @@ target.all = function() {
// Production stuff // Production stuff
// //
// Files that need to be included in every build.
var COMMON_WEB_FILES =
['web/viewer.css',
'web/images',
'web/debugger.js'],
COMMON_WEB_FILES_PREPROCESS =
['web/viewer.js',
'web/viewer.html'];
//
// make generic
// Builds the generic production viewer that should be compatible with most
// modern HTML5 browsers.
//
target.generic = function() {
target.bundle();
target.locale();
cd(ROOT_DIR);
echo();
echo('### Creating generic viewer');
rm('-rf', GENERIC_DIR);
mkdir('-p', GENERIC_DIR);
mkdir('-p', GENERIC_DIR + BUILD_DIR);
mkdir('-p', GENERIC_DIR + '/web');
var defines = builder.merge(DEFINES, {GENERIC: true});
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, GENERIC_DIR + '/web'],
['external/webL10n/l10n.js', GENERIC_DIR + '/web'],
['web/compatibility.js', GENERIC_DIR + '/web'],
['web/compressed.tracemonkey-pldi-09.pdf', GENERIC_DIR + '/web'],
['web/locale.properties', GENERIC_DIR + '/web']
],
preprocess: [
[BUILD_TARGET, GENERIC_DIR + BUILD_TARGET],
[COMMON_WEB_FILES_PREPROCESS, GENERIC_DIR + '/web']
]
};
builder.build(setup);
};
// //
// make web // make web
// Generates the website for the project, by checking out the gh-pages branch underneath // Generates the website for the project, by checking out the gh-pages branch underneath
// the build directory, and then moving the various viewer files into place. // the build directory, and then moving the various viewer files into place.
// //
target.web = function() { target.web = function() {
target.production(); target.generic();
target.locale();
target.extension(); target.extension();
target.pagesrepo(); target.pagesrepo();
@ -46,25 +103,18 @@ target.web = function() {
echo(); echo();
echo('### Creating web site'); echo('### Creating web site');
var GH_PAGES_SRC_FILES = [ cp('-R', GENERIC_DIR + '/*', GH_PAGES_DIR);
'web/*',
'external/webL10n/l10n.js'
];
cp(BUILD_TARGET, GH_PAGES_DIR + BUILD_TARGET);
cp('-R', GH_PAGES_SRC_FILES, GH_PAGES_DIR + '/web');
cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf', cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf',
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/'); GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/');
cp(GH_PAGES_DIR + '/web/index.html.template', GH_PAGES_DIR + '/index.html'); cp('web/index.html.template', GH_PAGES_DIR + '/index.html');
mv('-f', GH_PAGES_DIR + '/web/viewer-production.html',
GH_PAGES_DIR + '/web/viewer.html');
cd(GH_PAGES_DIR); cd(GH_PAGES_DIR);
exec('git add -A'); exec('git add -A');
echo(); echo();
echo("Website built in " + GH_PAGES_DIR); echo("Website built in " + GH_PAGES_DIR);
echo("Don't forget to cd into " + GH_PAGES_DIR + echo("Don't forget to cd into " + GH_PAGES_DIR +
" and issue 'git commit' to push changes."); " and issue 'git commit' to push changes.");
}; };
// //
@ -124,20 +174,10 @@ target.locale = function() {
chromeManifestContent.to(CHROME_MANIFEST_OUTPUT); chromeManifestContent.to(CHROME_MANIFEST_OUTPUT);
}; };
//
// make production
// Creates production output (pdf.js, and corresponding changes to web/ files)
//
target.production = function() {
target.bundle();
target.viewer();
};
// //
// make bundle // make bundle
// Bundles all source files into one wrapper 'pdf.js' file, in the given order. // Bundles all source files into one wrapper 'pdf.js' file, in the given order.
// //
target.bundle = function() { target.bundle = function() {
cd(ROOT_DIR); cd(ROOT_DIR);
echo(); echo();
@ -178,29 +218,12 @@ target.bundle = function() {
bundleVersion = exec('git log --format="%h" -n 1', bundleVersion = exec('git log --format="%h" -n 1',
{silent: true}).output.replace('\n', ''); {silent: true}).output.replace('\n', '');
sed(/.*PDFJSSCRIPT_INCLUDE_ALL.*\n/, bundle, 'pdf.js') // This just preprocesses the empty pdf.js file, we don't actually want to
.to(ROOT_DIR + BUILD_TARGET); // preprocess everything yet since other build targets use this file.
sed('-i', 'PDFJSSCRIPT_BUNDLE_VER', bundleVersion, ROOT_DIR + BUILD_TARGET); builder.preprocess('pdf.js', ROOT_DIR + BUILD_TARGET,
{BUNDLE: bundle, BUNDLE_VERSION: bundleVersion});
}; };
//
// make viewer
// Changes development <script> tags in our web viewer to use only 'pdf.js'.
// Produces 'viewer-production.html'
//
target.viewer = function() {
cd(ROOT_DIR);
echo();
echo('### Generating production-level viewer');
cd('web');
// Remove development lines
sed(/.*PDFJSSCRIPT_REMOVE_CORE.*\n/g, '', 'viewer.html')
.to('viewer-production.html');
// Introduce snippet
sed('-i', /.*PDFJSSCRIPT_INCLUDE_BUILD.*\n/g, cat('viewer-snippet.html'),
'viewer-production.html');
};
// //
// make pagesrepo // make pagesrepo
@ -238,15 +261,7 @@ target.pagesrepo = function() {
// Extension stuff // Extension stuff
// //
var EXTENSION_WEB_FILES = var EXTENSION_BASE_VERSION = 'f0f0418a9c6637981fe1182b9212c2d592774c7d',
['web/debugger.js',
'web/images',
'web/viewer.css',
'web/viewer.js',
'web/viewer.html',
'extensions/firefox/tools/l10n.js',
'web/viewer-production.html'],
EXTENSION_BASE_VERSION = 'f0f0418a9c6637981fe1182b9212c2d592774c7d',
EXTENSION_VERSION_PREFIX = '0.3.', EXTENSION_VERSION_PREFIX = '0.3.',
EXTENSION_BUILD_NUMBER, EXTENSION_BUILD_NUMBER,
EXTENSION_VERSION; EXTENSION_VERSION;
@ -260,7 +275,6 @@ target.extension = function() {
echo('### Building extensions'); echo('### Building extensions');
target.locale(); target.locale();
target.production();
target.firefox(); target.firefox();
target.chrome(); target.chrome();
}; };
@ -287,8 +301,10 @@ target.firefox = function() {
cd(ROOT_DIR); cd(ROOT_DIR);
echo(); echo();
echo('### Building Firefox extension'); echo('### Building Firefox extension');
var defines = builder.merge(DEFINES, {FIREFOX: true});
var FIREFOX_BUILD_CONTENT_DIR = FIREFOX_BUILD_DIR + '/content/', var FIREFOX_BUILD_CONTENT_DIR = FIREFOX_BUILD_DIR + '/content/',
FIREFOX_EXTENSION_DIR = 'extensions/firefox/',
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/', FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/',
FIREFOX_EXTENSION_FILES_TO_COPY = FIREFOX_EXTENSION_FILES_TO_COPY =
['*.js', ['*.js',
@ -313,7 +329,7 @@ target.firefox = function() {
FIREFOX_AMO_EXTENSION_NAME = 'pdf.js.amo.xpi'; FIREFOX_AMO_EXTENSION_NAME = 'pdf.js.amo.xpi';
target.locale(); target.locale();
target.production(); target.bundle();
target.buildnumber(); target.buildnumber();
cd(ROOT_DIR); cd(ROOT_DIR);
@ -328,25 +344,18 @@ target.firefox = function() {
cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY, ROOT_DIR + FIREFOX_BUILD_DIR); cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY, ROOT_DIR + FIREFOX_BUILD_DIR);
cd(ROOT_DIR); cd(ROOT_DIR);
// Copy a standalone version of pdf.js inside the content directory var setup = {
cp(BUILD_TARGET, FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR); defines: defines,
cp('-R', EXTENSION_WEB_FILES, FIREFOX_BUILD_CONTENT_DIR + '/web'); copy: [
rm(FIREFOX_BUILD_CONTENT_DIR + '/web/viewer-production.html'); [COMMON_WEB_FILES, FIREFOX_BUILD_CONTENT_DIR + '/web'],
['extensions/firefox/tools/l10n.js', FIREFOX_BUILD_CONTENT_DIR + '/web']
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web']
]
};
builder.build(setup);
// Copy over the firefox extension snippet so we can inline pdf.js in it
cp('web/viewer-snippet-firefox-extension.html', FIREFOX_BUILD_CONTENT_DIR + '/web');
// Modify the viewer so it does all the extension-only stuff.
cd(FIREFOX_BUILD_CONTENT_DIR + '/web');
sed('-i', /.*PDFJSSCRIPT_INCLUDE_BUNDLE.*\n/, cat(ROOT_DIR + BUILD_TARGET), 'viewer-snippet-firefox-extension.html');
sed('-i', /.*PDFJSSCRIPT_REMOVE_CORE.*\n/g, '', 'viewer.html');
sed('-i', /.*PDFJSSCRIPT_REMOVE_FIREFOX_EXTENSION.*\n/g, '', 'viewer.html');
sed('-i', /.*PDFJSSCRIPT_INCLUDE_FIREFOX_EXTENSION.*\n/, cat('viewer-snippet-firefox-extension.html'), 'viewer.html');
cd(ROOT_DIR);
// We don't need pdf.js anymore since its inlined
rm('-Rf', FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR);
rm(FIREFOX_BUILD_CONTENT_DIR + '/web/viewer-snippet-firefox-extension.html');
// Remove '.DS_Store' and other hidden files // Remove '.DS_Store' and other hidden files
find(FIREFOX_BUILD_DIR).forEach(function(file) { find(FIREFOX_BUILD_DIR).forEach(function(file) {
if (file.match(/^\./)) if (file.match(/^\./))
@ -388,6 +397,7 @@ target.mozcentral = function() {
cd(ROOT_DIR); cd(ROOT_DIR);
echo(); echo();
echo('### Building mozilla-central extension'); echo('### Building mozilla-central extension');
var defines = builder.merge(DEFINES, {MOZCENTRAL: true});
var MOZCENTRAL_DIR = BUILD_DIR + 'mozcentral/', var MOZCENTRAL_DIR = BUILD_DIR + 'mozcentral/',
MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + 'browser/extensions/pdfjs/', MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + 'browser/extensions/pdfjs/',
@ -412,7 +422,7 @@ target.mozcentral = function() {
'content', 'content',
'LICENSE']; 'LICENSE'];
target.production(); target.bundle();
target.buildnumber(); target.buildnumber();
cd(ROOT_DIR); cd(ROOT_DIR);
@ -432,25 +442,18 @@ target.mozcentral = function() {
ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome.manifest') ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome.manifest')
cd(ROOT_DIR); cd(ROOT_DIR);
// Copy a standalone version of pdf.js inside the content directory var setup = {
cp(BUILD_TARGET, MOZCENTRAL_CONTENT_DIR + BUILD_DIR); defines: defines,
cp('-R', EXTENSION_WEB_FILES, MOZCENTRAL_CONTENT_DIR + '/web'); copy: [
rm(MOZCENTRAL_CONTENT_DIR + '/web/viewer-production.html'); [COMMON_WEB_FILES, MOZCENTRAL_CONTENT_DIR + '/web'],
['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web']
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web']
]
};
builder.build(setup);
// Copy over the firefox extension snippet so we can inline pdf.js in it
cp('web/viewer-snippet-firefox-extension.html', MOZCENTRAL_CONTENT_DIR + '/web');
// Modify the viewer so it does all the extension-only stuff.
cd(MOZCENTRAL_CONTENT_DIR + '/web');
sed('-i', /.*PDFJSSCRIPT_INCLUDE_BUNDLE.*\n/, cat(ROOT_DIR + BUILD_TARGET), 'viewer-snippet-firefox-extension.html');
sed('-i', /.*PDFJSSCRIPT_REMOVE_CORE.*\n/g, '', 'viewer.html');
sed('-i', /.*PDFJSSCRIPT_REMOVE_FIREFOX_EXTENSION.*\n/g, '', 'viewer.html');
sed('-i', /.*PDFJSSCRIPT_INCLUDE_FIREFOX_EXTENSION.*\n/, cat('viewer-snippet-firefox-extension.html'), 'viewer.html');
cd(ROOT_DIR);
// We don't need pdf.js anymore since its inlined
rm('-Rf', MOZCENTRAL_CONTENT_DIR + BUILD_DIR);
rm(MOZCENTRAL_CONTENT_DIR + '/web/viewer-snippet-firefox-extension.html');
// Remove '.DS_Store' and other hidden files // Remove '.DS_Store' and other hidden files
find(MOZCENTRAL_DIR).forEach(function(file) { find(MOZCENTRAL_DIR).forEach(function(file) {
if (file.match(/^\./)) if (file.match(/^\./))
@ -482,6 +485,36 @@ target.mozcentral = function() {
cp('-Rf', 'test/mozcentral/*', MOZCENTRAL_TEST_DIR); cp('-Rf', 'test/mozcentral/*', MOZCENTRAL_TEST_DIR);
}; };
target.b2g = function() {
echo();
echo('### Building B2G (Firefox OS App)');
var B2G_BUILD_DIR = BUILD_DIR + '/b2g/',
B2G_BUILD_CONTENT_DIR = B2G_BUILD_DIR + '/content/';
var defines = builder.merge(DEFINES, { B2G: true });
target.bundle();
// Clear out everything in the b2g build directory
cd(ROOT_DIR);
rm('-Rf', B2G_BUILD_DIR);
mkdir('-p', B2G_BUILD_CONTENT_DIR);
mkdir('-p', B2G_BUILD_CONTENT_DIR + BUILD_DIR);
mkdir('-p', B2G_BUILD_CONTENT_DIR + '/web');
var setup = {
defines: defines,
copy: [
[COMMON_WEB_FILES, B2G_BUILD_CONTENT_DIR + '/web'],
['web/locale.properties', B2G_BUILD_CONTENT_DIR + '/web'],
['external/webL10n/l10n.js', B2G_BUILD_CONTENT_DIR + '/web']
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, B2G_BUILD_CONTENT_DIR + '/web'],
[BUILD_TARGET, B2G_BUILD_CONTENT_DIR + BUILD_TARGET]
]
};
builder.build(setup);
};
// //
// make chrome // make chrome
// //
@ -489,15 +522,12 @@ target.chrome = function() {
cd(ROOT_DIR); cd(ROOT_DIR);
echo(); echo();
echo('### Building Chrome extension'); echo('### Building Chrome extension');
var defines = builder.merge(DEFINES, {CHROME: true});
var CHROME_BUILD_DIR = BUILD_DIR + '/chrome/', var CHROME_BUILD_DIR = BUILD_DIR + '/chrome/',
CHROME_CONTENT_DIR = EXTENSION_SRC_DIR + '/chrome/content/', CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR + '/content/';
CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR + '/content/',
CHROME_EXTENSION_FILES =
['extensions/chrome/*.json',
'extensions/chrome/*.html'];
target.production(); target.bundle();
target.buildnumber(); target.buildnumber();
cd(ROOT_DIR); cd(ROOT_DIR);
@ -507,18 +537,20 @@ target.chrome = function() {
mkdir('-p', CHROME_BUILD_CONTENT_DIR + BUILD_DIR); mkdir('-p', CHROME_BUILD_CONTENT_DIR + BUILD_DIR);
mkdir('-p', CHROME_BUILD_CONTENT_DIR + '/web'); mkdir('-p', CHROME_BUILD_CONTENT_DIR + '/web');
// Copy extension files var setup = {
cp('-R', CHROME_EXTENSION_FILES, CHROME_BUILD_DIR); defines: defines,
copy: [
// Copy a standalone version of pdf.js inside the content directory [COMMON_WEB_FILES, CHROME_BUILD_CONTENT_DIR + '/web'],
cp(BUILD_TARGET, CHROME_BUILD_CONTENT_DIR + BUILD_DIR); [['extensions/chrome/*.json', 'extensions/chrome/*.html'], CHROME_BUILD_DIR],
cp('-R', EXTENSION_WEB_FILES, CHROME_BUILD_CONTENT_DIR + '/web'); [BUILD_TARGET, CHROME_BUILD_CONTENT_DIR + BUILD_TARGET],
// Replacing the l10n.js file with regular gh-pages one ['external/webL10n/l10n.js', CHROME_BUILD_CONTENT_DIR + '/web']
rm(CHROME_BUILD_CONTENT_DIR + '/web/l10n.js'); ],
cp('external/webL10n/l10n.js', CHROME_BUILD_CONTENT_DIR + '/web'); preprocess: [
cp('web/locale.properties', CHROME_BUILD_CONTENT_DIR + '/web'); [COMMON_WEB_FILES_PREPROCESS, CHROME_BUILD_CONTENT_DIR + '/web'],
mv('-f', CHROME_BUILD_CONTENT_DIR + '/web/viewer-production.html', ['web/locale.properties', CHROME_BUILD_CONTENT_DIR + '/web']
CHROME_BUILD_CONTENT_DIR + '/web/viewer.html'); ]
};
builder.build(setup);
}; };

View File

@ -430,19 +430,18 @@ var WorkerTransport = (function WorkerTransportClosure() {
try { try {
var worker; var worker;
if (PDFJS.isFirefoxExtension) { //#if !(FIREFOX || MOZCENTRAL)
// The firefox extension can't load the worker from the resource:// // Some versions of FF can't create a worker on localhost, see:
// url so we have to inline the script and then use the blob loader. // https://bugzilla.mozilla.org/show_bug.cgi?id=683280
var bb = new MozBlobBuilder(); worker = new Worker(workerSrc);
bb.append(document.querySelector('#PDFJS_SCRIPT_TAG').textContent); //#else
var blobUrl = window.URL.createObjectURL(bb.getBlob()); // // The firefox extension can't load the worker from the resource://
worker = new Worker(blobUrl); // // url so we have to inline the script and then use the blob loader.
} else { // var bb = new MozBlobBuilder();
// Some versions of FF can't create a worker on localhost, see: // bb.append(document.querySelector('#PDFJS_SCRIPT_TAG').textContent);
// https://bugzilla.mozilla.org/show_bug.cgi?id=683280 // var blobUrl = window.URL.createObjectURL(bb.getBlob());
worker = new Worker(workerSrc); // worker = new Worker(blobUrl);
} //#endif
var messageHandler = new MessageHandler('main', worker); var messageHandler = new MessageHandler('main', worker);
this.messageHandler = messageHandler; this.messageHandler = messageHandler;

View File

@ -157,6 +157,7 @@ var CanvasExtraState = (function CanvasExtraStateClosure() {
this.wordSpacing = 0; this.wordSpacing = 0;
this.textHScale = 1; this.textHScale = 1;
this.textRenderingMode = TextRenderingMode.FILL; this.textRenderingMode = TextRenderingMode.FILL;
this.textRise = 0;
// Color spaces // Color spaces
this.fillColorSpace = new DeviceGrayCS(); this.fillColorSpace = new DeviceGrayCS();
this.fillColorSpaceObj = null; this.fillColorSpaceObj = null;
@ -601,7 +602,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.textRenderingMode = mode; this.current.textRenderingMode = mode;
}, },
setTextRise: function CanvasGraphics_setTextRise(rise) { setTextRise: function CanvasGraphics_setTextRise(rise) {
TODO('text rise: ' + rise); this.current.textRise = rise;
}, },
moveText: function CanvasGraphics_moveText(x, y) { moveText: function CanvasGraphics_moveText(x, y) {
this.current.x = this.current.lineX += x; this.current.x = this.current.lineX += x;
@ -628,7 +629,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
ctx.transform.apply(ctx, current.textMatrix); ctx.transform.apply(ctx, current.textMatrix);
ctx.scale(1, -1); ctx.scale(1, -1);
ctx.translate(current.x, -1 * current.y); ctx.translate(current.x, -current.y - current.textRise);
ctx.transform.apply(ctx, fontMatrix); ctx.transform.apply(ctx, fontMatrix);
ctx.scale(textHScale, 1); ctx.scale(textHScale, 1);
}, },
@ -1257,7 +1258,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
return CanvasGraphics; return CanvasGraphics;
})(); })();
if (!isWorker) { function checkPutBinaryImageDataCompatibility() {
// Feature detection if the browser can use an Uint8Array directly as imgData. // Feature detection if the browser can use an Uint8Array directly as imgData.
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.width = 1; canvas.width = 1;
@ -1278,17 +1279,23 @@ if (!isWorker) {
} catch (e) { } catch (e) {
CanvasGraphics.prototype.putBinaryImageData = CanvasGraphics.prototype.putBinaryImageData =
function CanvasGraphicsPutBinaryImageDataShim(ctx, imgData, w, h) { function CanvasGraphicsPutBinaryImageDataShim(ctx, imgData, w, h) {
var tmpImgData = ctx.getImageData(0, 0, w, h); var tmpImgData = 'createImageData' in ctx ? ctx.createImageData(w, h) :
ctx.getImageData(0, 0, w, h);
// Copy over the imageData pixel by pixel.
var tmpImgDataPixels = tmpImgData.data; var tmpImgDataPixels = tmpImgData.data;
var len = tmpImgDataPixels.length; var data = imgData.data;
if ('set' in tmpImgDataPixels)
while (len--) { tmpImgDataPixels.set(data);
tmpImgDataPixels[len] = imgData.data[len]; else {
// Copy over the imageData pixel by pixel.
for (var i = 0, ii = tmpImgDataPixels.length; i < ii; i++)
tmpImgDataPixels[i] = data[i];
} }
ctx.putImageData(tmpImgData, 0, 0); ctx.putImageData(tmpImgData, 0, 0);
}; };
} }
} }
if (!isWorker) {
checkPutBinaryImageDataCompatibility();
}

View File

@ -29,9 +29,11 @@ function getPdf(arg, callback) {
var params = arg; var params = arg;
if (typeof arg === 'string') if (typeof arg === 'string')
params = { url: arg }; params = { url: arg };
//#if !B2G
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
//#else
//var xhr = new XMLHttpRequest({mozSystem: true});
//#endif
xhr.open('GET', params.url); xhr.open('GET', params.url);
var headers = params.headers; var headers = params.headers;
@ -403,6 +405,24 @@ var PDFDocument = (function PDFDocumentClosure() {
return true; /* found */ return true; /* found */
} }
var DocumentInfoValidators = {
get entries() {
// Lazily build this since all the validation functions below are not
// defined until after this file loads.
return shadow(this, 'entries', {
Title: isString,
Author: isString,
Subject: isString,
Keywords: isString,
Creator: isString,
Producer: isString,
CreationDate: isString,
ModDate: isString,
Trapped: isName
});
}
};
PDFDocument.prototype = { PDFDocument.prototype = {
get linearization() { get linearization() {
var length = this.stream.length; var length = this.stream.length;
@ -495,18 +515,27 @@ var PDFDocument = (function PDFDocumentClosure() {
return shadow(this, 'numPages', num); return shadow(this, 'numPages', num);
}, },
getDocumentInfo: function PDFDocument_getDocumentInfo() { getDocumentInfo: function PDFDocument_getDocumentInfo() {
var info; var docInfo;
if (this.xref.trailer.has('Info')) { if (this.xref.trailer.has('Info')) {
var infoDict = this.xref.trailer.get('Info'); var infoDict = this.xref.trailer.get('Info');
info = {}; docInfo = {};
infoDict.forEach(function(key, value) { var validEntries = DocumentInfoValidators.entries;
info[key] = typeof value !== 'string' ? value : // Only fill the document info with valid entries from the spec.
stringToPDFString(value); for (var key in validEntries) {
}); if (infoDict.has(key)) {
var value = infoDict.get(key);
// Make sure the value conforms to the spec.
if (validEntries[key](value)) {
docInfo[key] = typeof value !== 'string' ? value :
stringToPDFString(value);
} else {
info('Bad value in document info for "' + key + '"');
}
}
}
} }
return shadow(this, 'getDocumentInfo', docInfo);
return shadow(this, 'getDocumentInfo', info);
}, },
getFingerprint: function PDFDocument_getFingerprint() { getFingerprint: function PDFDocument_getFingerprint() {
var xref = this.xref, fileID; var xref = this.xref, fileID;

View File

@ -765,7 +765,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
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++) {
var code = widths[i]; var code = xref.fetchIfRef(widths[i]);
if (isArray(code)) { if (isArray(code)) {
for (var j = 0, jj = code.length; j < jj; j++) for (var j = 0, jj = code.length; j < jj; j++)
glyphsWidths[start++] = code[j]; glyphsWidths[start++] = code[j];

View File

@ -418,7 +418,8 @@ var FontLoader = {
document.documentElement.removeEventListener( document.documentElement.removeEventListener(
'pdfjsFontLoad', checkFontsLoaded, false); 'pdfjsFontLoad', checkFontsLoaded, false);
callback(); // Use timeout to fix chrome intermittent failures on font loading.
setTimeout(callback, 0);
return true; return true;
} }
@ -3292,6 +3293,14 @@ var Font = (function FontClosure() {
return Font; return Font;
})(); })();
var CallothersubrCmd = (function CallothersubrCmdClosure() {
function CallothersubrCmd(index) {
this.index = index;
}
return CallothersubrCmd;
})();
/* /*
* Type1Parser encapsulate the needed code for parsing a Type1 font * Type1Parser encapsulate the needed code for parsing a Type1 font
* program. Some of its logic depends on the Type2 charstrings * program. Some of its logic depends on the Type2 charstrings
@ -3497,6 +3506,10 @@ var Type1Parser = function type1Parser() {
i++; i++;
continue; continue;
} }
assert(argc == 0, 'callothersubr with arguments is not supported');
charstring.push(new CallothersubrCmd(index));
continue;
} else if (escape == 17 || escape == 33) { } else if (escape == 17 || escape == 33) {
// pop or setcurrentpoint commands can be ignored // pop or setcurrentpoint commands can be ignored
// since we are not doing callothersubr // since we are not doing callothersubr
@ -4016,23 +4029,23 @@ Type1Font.prototype = {
}, },
getType2Charstrings: function Type1Font_getType2Charstrings( getType2Charstrings: function Type1Font_getType2Charstrings(
type1Charstrings) { type1Subrs) {
var type2Charstrings = []; var type2Charstrings = [];
var count = type1Charstrings.length; var count = type1Subrs.length;
for (var i = 0; i < count; i++) { var type1Charstrings = [];
var charstring = type1Charstrings[i].charstring; for (var i = 0; i < count; i++)
type2Charstrings.push(this.flattenCharstring(charstring.slice(), type1Charstrings.push(type1Subrs[i].charstring.slice());
this.commandsMap)); for (var i = 0; i < count; i++)
} type2Charstrings.push(this.flattenCharstring(type1Charstrings, i));
return type2Charstrings; return type2Charstrings;
}, },
getType2Subrs: function Type1Font_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 < 1133)
bias = 107; bias = 107;
else if (count < 33900) else if (count < 33769)
bias = 1131; bias = 1131;
else else
bias = 32768; bias = 32768;
@ -4043,11 +4056,7 @@ Type1Font.prototype = {
type2Subrs.push([0x0B]); type2Subrs.push([0x0B]);
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
var subr = type1Subrs[i]; type2Subrs.push(this.flattenCharstring(type1Subrs, i));
if (!subr)
subr = [0x0B];
type2Subrs.push(this.flattenCharstring(subr, this.commandsMap));
} }
return type2Subrs; return type2Subrs;
@ -4079,7 +4088,11 @@ Type1Font.prototype = {
'hvcurveto': 31 'hvcurveto': 31
}, },
flattenCharstring: function Type1Font_flattenCharstring(charstring, map) { flattenCharstring: function Type1Font_flattenCharstring(charstrings, index) {
var charstring = charstrings[index];
if (!charstring)
return [0x0B];
var map = this.commandsMap;
// 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];
@ -4091,6 +4104,17 @@ Type1Font.prototype = {
charstring.splice(i++, 1, cmd[0], cmd[1]); charstring.splice(i++, 1, cmd[0], cmd[1]);
else else
charstring[i] = cmd; charstring[i] = cmd;
} else if (command instanceof CallothersubrCmd) {
var otherSubrCharstring = charstrings[command.index];
if (otherSubrCharstring) {
var lastCommand = otherSubrCharstring.indexOf('return');
if (lastCommand >= 0)
otherSubrCharstring = otherSubrCharstring.slice(0, lastCommand);
charstring.splice.apply(charstring,
[i, 1].concat(otherSubrCharstring));
} else
charstring.splice(i, 1); // ignoring empty subr call
i--;
} else { } else {
// Type1 charstring use a division for number above 32000 // Type1 charstring use a division for number above 32000
if (command > 32000) { if (command > 32000) {

View File

@ -103,11 +103,12 @@ var PDFFunction = (function PDFFunctionClosure() {
var size = dict.get('Size'); var size = dict.get('Size');
var bps = dict.get('BitsPerSample'); var bps = dict.get('BitsPerSample');
var order = dict.get('Order'); var order = dict.get('Order') || 1;
if (!order) if (order !== 1) {
order = 1; // No description how cubic spline interpolation works in PDF32000:2008
if (order !== 1) // As in poppler, ignoring order, linear interpolation may work as good
error('No support for cubic spline interpolation: ' + order); TODO('No support for cubic spline interpolation: ' + order);
}
var encode = dict.get('Encode'); var encode = dict.get('Encode');
if (!encode) { if (!encode) {

View File

@ -624,7 +624,7 @@ var XRef = (function XRefClosure() {
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 || !e.offset ? null : e; // returns null if entry is free
}, },
fetchIfRef: function XRef_fetchIfRef(obj) { fetchIfRef: function XRef_fetchIfRef(obj) {
if (!isRef(obj)) if (!isRef(obj))

View File

@ -7,9 +7,13 @@ var PDFJS = {};
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
'use strict'; 'use strict';
PDFJS.build = 'PDFJSSCRIPT_BUNDLE_VER'; PDFJS.build =
//#if !BUNDLE_VERSION
'PDFJSSCRIPT_BUNDLE_VER';
//#else
//#expand '__BUNDLE_VERSION__';
//#endif
// Files are inserted below - see Makefile //#expand __BUNDLE__
/* PDFJSSCRIPT_INCLUDE_ALL */
}).call((typeof window === 'undefined') ? this : window); }).call((typeof window === 'undefined') ? this : window);

View File

@ -1 +0,0 @@
http://www.myhillsapartment.com/island_club/floorplans/images/links/Island_IC_brochure.pdf

View File

@ -0,0 +1 @@
http://bblum.net/thesis-draft.pdf

View File

@ -0,0 +1 @@
http://www.environmentallights.com/files/documents/ir_light_hazard.pdf

View File

@ -0,0 +1 @@
http://www.mediafire.com/?k8t1he9aa1pt840

View File

@ -1 +0,0 @@
http://www.lfg.com.br/concursodebolsas/lista_preliminar_classificao.pdf

View File

@ -1 +1 @@
http://www.airgid.com/book/wdsg_fitc.pdf http://www.airgid.com/wp-content/uploads/2012/06/wdsg_fitc.pdf

View File

@ -334,14 +334,6 @@
"skipPages": [1], "skipPages": [1],
"type": "eq" "type": "eq"
}, },
{ "id": "lista_preliminar",
"file": "pdfs/lista_preliminar.pdf",
"md5": "4eff251319eeb660ba8a7a5cfac7787d",
"rounds": 1,
"link": true,
"pageLimit": 3,
"type": "eq"
},
{ "id": "issue919", { "id": "issue919",
"file": "pdfs/issue919.pdf", "file": "pdfs/issue919.pdf",
"md5": "3a1716a512aca4d7a8d6106bd4885d14", "md5": "3a1716a512aca4d7a8d6106bd4885d14",
@ -356,13 +348,6 @@
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },
{ "id": "issue1001",
"file": "pdfs/issue1001.pdf",
"md5": "0f1496e80a82a923e91d9e74c55ad94e",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "issue1586", { "id": "issue1586",
"file": "pdfs/pdfjsbad1586.pdf", "file": "pdfs/pdfjsbad1586.pdf",
"md5": "793d0870f0b0c613799b0677d64daca4", "md5": "793d0870f0b0c613799b0677d64daca4",
@ -421,7 +406,7 @@
"file": "pdfs/issue1096.pdf", "file": "pdfs/issue1096.pdf",
"md5": "7f75d2b4b93c78d401ff39e8c1b00612", "md5": "7f75d2b4b93c78d401ff39e8c1b00612",
"rounds": 1, "rounds": 1,
"pageLimit": 10, "pageLimit": 9,
"link": true, "link": true,
"type": "eq" "type": "eq"
}, },
@ -530,6 +515,15 @@
"link": true, "link": true,
"type": "eq" "type": "eq"
}, },
{ "id": "issue1655",
"file": "pdfs/issue1655.pdf",
"md5": "696ef6de6f4f71643771419ef04fc968",
"rounds": 1,
"skipPages": [1, 2, 3, 4, 5, 6, 7, 8],
"pageLimit": 9,
"link": true,
"type": "eq"
},
{ "id": "issue1133", { "id": "issue1133",
"file": "pdfs/issue1133.pdf", "file": "pdfs/issue1133.pdf",
"md5": "d1b61580cb100e3df93d33703af1773a", "md5": "d1b61580cb100e3df93d33703af1773a",
@ -634,6 +628,13 @@
"link": true, "link": true,
"type": "eq" "type": "eq"
}, },
{ "id": "issue845",
"file": "pdfs/issue845.pdf",
"md5": "89ddf9e63cac4fa2dedcfe32a62e5407",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "issue818", { "id": "issue818",
"file": "pdfs/issue818.pdf", "file": "pdfs/issue818.pdf",
"md5": "dd2f8a5bd65164ad74da2b45a6ca90cc", "md5": "dd2f8a5bd65164ad74da2b45a6ca90cc",
@ -641,5 +642,13 @@
"pageLimit": 1, "pageLimit": 1,
"link": true, "link": true,
"type": "eq" "type": "eq"
},
{ "id": "issue1729",
"file": "pdfs/issue1729.pdf",
"md5": "29b0eddc3e1dcb23a44384037032d470",
"rounds": 1,
"pageLimit": 1,
"link": true,
"type": "load"
} }
] ]

View File

@ -124,24 +124,63 @@
}; };
})(); })();
// No readAsArrayBuffer ?
(function checkFileReaderReadAsArrayBuffer() {
if (typeof FileReader === 'undefined')
return; // FileReader is not implemented
var frPrototype = FileReader.prototype;
// Older versions of Firefox might not have readAsArrayBuffer
if ('readAsArrayBuffer' in frPrototype)
return; // readAsArrayBuffer is implemented
Object.defineProperty(frPrototype, 'readAsArrayBuffer', {
value: function fileReaderReadAsArrayBuffer(blob) {
var fileReader = new FileReader();
var originalReader = this;
fileReader.onload = function fileReaderOnload(evt) {
var data = evt.target.result;
var buffer = new ArrayBuffer(data.length);
var uint8Array = new Uint8Array(buffer);
for (var i = 0, ii = data.length; i < ii; i++)
uint8Array[i] = data.charCodeAt(i);
Object.defineProperty(originalReader, 'result', {
value: buffer,
enumerable: true,
writable: false,
configurable: true
});
var event = document.createEvent('HTMLEvents');
event.initEvent('load', false, false);
originalReader.dispatchEvent(event);
};
fileReader.readAsBinaryString(blob);
}
});
})();
// No XMLHttpRequest.response ? // No XMLHttpRequest.response ?
(function checkXMLHttpRequestResponseCompatibility() { (function checkXMLHttpRequestResponseCompatibility() {
var xhrPrototype = XMLHttpRequest.prototype; var xhrPrototype = XMLHttpRequest.prototype;
if (!('overrideMimeType' in xhrPrototype)) {
// IE10 might have response, but not overrideMimeType
Object.defineProperty(xhrPrototype, 'overrideMimeType', {
value: function xmlHttpRequestOverrideMimeType(mimeType) {}
});
}
if ('response' in xhrPrototype || if ('response' in xhrPrototype ||
'mozResponseArrayBuffer' in xhrPrototype || 'mozResponseArrayBuffer' in xhrPrototype ||
'mozResponse' in xhrPrototype || 'mozResponse' in xhrPrototype ||
'responseArrayBuffer' in xhrPrototype) 'responseArrayBuffer' in xhrPrototype)
return; return;
// IE ? // IE9 ?
if (typeof VBArray !== 'undefined') { if (typeof VBArray !== 'undefined') {
Object.defineProperty(xhrPrototype, 'response', { Object.defineProperty(xhrPrototype, 'response', {
get: function xmlHttpRequestResponseGet() { get: function xmlHttpRequestResponseGet() {
return new Uint8Array(new VBArray(this.responseBody).toArray()); return new Uint8Array(new VBArray(this.responseBody).toArray());
} }
}); });
Object.defineProperty(xhrPrototype, 'overrideMimeType', {
value: function xmlHttpRequestOverrideMimeType(mimeType) {}
});
return; return;
} }

View File

@ -44,7 +44,7 @@ var FontInspector = (function FontInspectorClosure() {
} }
} }
return { return {
// Poperties/functions needed by PDFBug. // Properties/functions needed by PDFBug.
id: 'FontInspector', id: 'FontInspector',
name: 'Font Inspector', name: 'Font Inspector',
panel: null, panel: null,
@ -140,7 +140,7 @@ var StepperManager = (function StepperManagerClosure() {
var stepperChooser = null; var stepperChooser = null;
var breakPoints = {}; var breakPoints = {};
return { return {
// Poperties/functions needed by PDFBug. // Properties/functions needed by PDFBug.
id: 'Stepper', id: 'Stepper',
name: 'Stepper', name: 'Stepper',
panel: null, panel: null,
@ -207,7 +207,7 @@ var StepperManager = (function StepperManagerClosure() {
var Stepper = (function StepperClosure() { var Stepper = (function StepperClosure() {
function Stepper(panel, pageIndex, initialBreakPoints) { function Stepper(panel, pageIndex, initialBreakPoints) {
this.panel = panel; this.panel = panel;
this.len; this.len = 0;
this.breakPoint = 0; this.breakPoint = 0;
this.nextBreakPoint = null; this.nextBreakPoint = null;
this.pageIndex = pageIndex; this.pageIndex = pageIndex;
@ -236,6 +236,7 @@ var Stepper = (function StepperClosure() {
headerRow.appendChild(c('th', 'fn')); headerRow.appendChild(c('th', 'fn'));
headerRow.appendChild(c('th', 'args')); headerRow.appendChild(c('th', 'args'));
var self = this;
for (var i = 0; i < IRQueue.fnArray.length; i++) { for (var i = 0; i < IRQueue.fnArray.length; i++) {
var line = c('tr'); var line = c('tr');
line.className = 'line'; line.className = 'line';
@ -249,7 +250,6 @@ var Stepper = (function StepperClosure() {
cbox.type = 'checkbox'; cbox.type = 'checkbox';
cbox.className = 'points'; cbox.className = 'points';
cbox.checked = checked; cbox.checked = checked;
var self = this;
cbox.onclick = (function(x) { cbox.onclick = (function(x) {
return function() { return function() {
if (this.checked) if (this.checked)
@ -298,7 +298,7 @@ var Stepper = (function StepperClosure() {
callback(); callback();
break; break;
} }
} };
dom.addEventListener('keydown', listener, false); dom.addEventListener('keydown', listener, false);
self.goTo(idx); self.goTo(idx);
}, },
@ -331,7 +331,7 @@ var Stats = (function Stats() {
return false; return false;
} }
return { return {
// Poperties/functions needed by PDFBug. // Properties/functions needed by PDFBug.
id: 'Stats', id: 'Stats',
name: 'Stats', name: 'Stats',
panel: null, panel: null,
@ -429,12 +429,12 @@ var PDFBug = (function PDFBugClosure() {
// Initialize all the debugging tools. // Initialize all the debugging tools.
var tools = this.tools; var tools = this.tools;
var self = this;
for (var i = 0; i < tools.length; ++i) { for (var i = 0; i < tools.length; ++i) {
var tool = tools[i]; var tool = tools[i];
var panel = document.createElement('div'); var panel = document.createElement('div');
var panelButton = document.createElement('button'); var panelButton = document.createElement('button');
panelButton.textContent = tool.name; panelButton.textContent = tool.name;
var self = this;
panelButton.addEventListener('click', (function(selected) { panelButton.addEventListener('click', (function(selected) {
return function(event) { return function(event) {
event.preventDefault(); event.preventDefault();

60
web/firefoxcom.js Normal file
View File

@ -0,0 +1,60 @@
var FirefoxCom = (function FirefoxComClosure() {
return {
/**
* Creates an event that the extension is listening for and will
* synchronously respond to.
* NOTE: It is reccomended to use request() instead since one day we may not
* be able to synchronously reply.
* @param {String} action The action to trigger.
* @param {String} data Optional data to send.
* @return {*} The response.
*/
requestSync: function(action, data) {
var request = document.createTextNode('');
request.setUserData('action', action, null);
request.setUserData('data', data, null);
request.setUserData('sync', true, null);
document.documentElement.appendChild(request);
var sender = document.createEvent('Events');
sender.initEvent('pdf.js.message', true, false);
request.dispatchEvent(sender);
var response = request.getUserData('response');
document.documentElement.removeChild(request);
return response;
},
/**
* Creates an event that the extension is listening for and will
* asynchronously respond by calling the callback.
* @param {String} action The action to trigger.
* @param {String} data Optional data to send.
* @param {Function} callback Optional response callback that will be called
* with one data argument.
*/
request: function(action, data, callback) {
var request = document.createTextNode('');
request.setUserData('action', action, null);
request.setUserData('data', data, null);
request.setUserData('sync', false, null);
if (callback) {
request.setUserData('callback', callback, null);
document.addEventListener('pdf.js.response', function listener(event) {
var node = event.target,
callback = node.getUserData('callback'),
response = node.getUserData('response');
document.documentElement.removeChild(node);
document.removeEventListener('pdf.js.response', listener, false);
return callback(response);
}, false);
}
document.documentElement.appendChild(request);
var sender = document.createEvent('HTMLEvents');
sender.initEvent('pdf.js.message', true, false);
return request.dispatchEvent(sender);
}
};
})();

View File

@ -0,0 +1,9 @@
<!-- This snippet is used in b2g, see Makefile -->
<link rel="resource" type="application/l10n" href="locale.properties"/>
<script type="text/javascript" src="l10n.js"></script>
<script type="text/javascript" src="../build/pdf.js"></script>
<script type="text/javascript">
// This specifies the location of the pdf.js file.
PDFJS.workerSrc = "../build/pdf.js";
PDFJS.disableTextLayer = true;
</script>

View File

@ -1,14 +1,11 @@
<!-- This snippet is used in firefox extension, see Makefile --> <!-- This snippet is used in firefox extension, see Makefile -->
<base href="resource://pdf.js/web/" /> <base href="resource://pdf.js/web/" />
<script type="application/l10n">
<!-- PDFJSSCRIPT_LOCALE_DATA -->
</script>
<script type="text/javascript" src="l10n.js"></script> <script type="text/javascript" src="l10n.js"></script>
<script type="text/javascript" id="PDFJS_SCRIPT_TAG"> <script type="text/javascript" id="PDFJS_SCRIPT_TAG">
<!-- <!--
// pdf.js is inlined here because resource:// urls won't work // pdf.js is inlined here because resource:// urls won't work
// for loading workers. // for loading workers.
/* PDFJSSCRIPT_INCLUDE_BUNDLE */ //#include ../build/pdf.js
--> -->
</script> </script>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -4,40 +4,60 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>PDF.js viewer</title> <title>PDF.js viewer</title>
<!-- PDFJSSCRIPT_INCLUDE_FIREFOX_EXTENSION -->
<!--#if FIREFOX || MOZCENTRAL-->
<!--#include viewer-snippet-firefox-extension.html-->
<!--#endif-->
<link rel="stylesheet" href="viewer.css"/> <link rel="stylesheet" href="viewer.css"/>
<link rel="resource" type="application/l10n" href="locale.properties"/><!-- PDFJSSCRIPT_REMOVE_CORE --> <!--#if !PRODUCTION-->
<link rel="resource" type="application/l10n" href="locale.properties"/>
<!--#endif-->
<script type="text/javascript" src="compatibility.js"></script> <!-- PDFJSSCRIPT_REMOVE_FIREFOX_EXTENSION --> <!--#if !(FIREFOX || MOZCENTRAL)-->
<script type="text/javascript" src="../external/webL10n/l10n.js"></script><!-- PDFJSSCRIPT_REMOVE_CORE --> <script type="text/javascript" src="compatibility.js"></script>
<!--#endif-->
<!--#if !PRODUCTION-->
<script type="text/javascript" src="../external/webL10n/l10n.js"></script>
<!--#endif-->
<!--#if !PRODUCTION-->
<script type="text/javascript" src="../src/core.js"></script>
<script type="text/javascript" src="../src/util.js"></script>
<script type="text/javascript" src="../src/api.js"></script>
<script type="text/javascript" src="../src/metadata.js"></script>
<script type="text/javascript" src="../src/canvas.js"></script>
<script type="text/javascript" src="../src/obj.js"></script>
<script type="text/javascript" src="../src/function.js"></script>
<script type="text/javascript" src="../src/charsets.js"></script>
<script type="text/javascript" src="../src/cidmaps.js"></script>
<script type="text/javascript" src="../src/colorspace.js"></script>
<script type="text/javascript" src="../src/crypto.js"></script>
<script type="text/javascript" src="../src/evaluator.js"></script>
<script type="text/javascript" src="../src/fonts.js"></script>
<script type="text/javascript" src="../src/glyphlist.js"></script>
<script type="text/javascript" src="../src/image.js"></script>
<script type="text/javascript" src="../src/metrics.js"></script>
<script type="text/javascript" src="../src/parser.js"></script>
<script type="text/javascript" src="../src/pattern.js"></script>
<script type="text/javascript" src="../src/stream.js"></script>
<script type="text/javascript" src="../src/worker.js"></script>
<script type="text/javascript" src="../external/jpgjs/jpg.js"></script>
<script type="text/javascript" src="../src/jpx.js"></script>
<script type="text/javascript" src="../src/jbig2.js"></script>
<script type="text/javascript" src="../src/bidi.js"></script>
<script type="text/javascript">PDFJS.workerSrc = '../src/worker_loader.js';</script>
<!--#endif-->
<!--#if GENERIC || CHROME-->
<!--#include viewer-snippet.html-->
<!--#endif-->
<!--#if B2G-->
<!--#include viewer-snippet-b2g.html-->
<!--#endif-->
<!-- PDFJSSCRIPT_INCLUDE_BUILD -->
<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/api.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/obj.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/function.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/charsets.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/cidmaps.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/colorspace.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/crypto.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/evaluator.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/fonts.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/glyphlist.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/image.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/metrics.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/parser.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/pattern.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/stream.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/worker.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../external/jpgjs/jpg.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/jpx.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/jbig2.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="../src/bidi.js"></script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript">PDFJS.workerSrc = '../src/worker_loader.js';</script> <!-- PDFJSSCRIPT_REMOVE_CORE -->
<script type="text/javascript" src="debugger.js"></script> <script type="text/javascript" src="debugger.js"></script>
<script type="text/javascript" src="viewer.js"></script> <script type="text/javascript" src="viewer.js"></script>
</head> </head>

View File

@ -90,66 +90,9 @@ var ProgressBar = (function ProgressBarClosure() {
return ProgressBar; return ProgressBar;
})(); })();
var FirefoxCom = (function FirefoxComClosure() { //#if FIREFOX || MOZCENTRAL
return { //#include firefoxcom.js
/** //#endif
* Creates an event that the extension is listening for and will
* synchronously respond to.
* NOTE: It is reccomended to use request() instead since one day we may not
* be able to synchronously reply.
* @param {String} action The action to trigger.
* @param {String} data Optional data to send.
* @return {*} The response.
*/
requestSync: function(action, data) {
var request = document.createTextNode('');
request.setUserData('action', action, null);
request.setUserData('data', data, null);
request.setUserData('sync', true, null);
document.documentElement.appendChild(request);
var sender = document.createEvent('Events');
sender.initEvent('pdf.js.message', true, false);
request.dispatchEvent(sender);
var response = request.getUserData('response');
document.documentElement.removeChild(request);
return response;
},
/**
* Creates an event that the extension is listening for and will
* asynchronously respond by calling the callback.
* @param {String} action The action to trigger.
* @param {String} data Optional data to send.
* @param {Function} callback Optional response callback that will be called
* with one data argument.
*/
request: function(action, data, callback) {
var request = document.createTextNode('');
request.setUserData('action', action, null);
request.setUserData('data', data, null);
request.setUserData('sync', false, null);
if (callback) {
request.setUserData('callback', callback, null);
document.addEventListener('pdf.js.response', function listener(event) {
var node = event.target,
callback = node.getUserData('callback'),
response = node.getUserData('response');
document.documentElement.removeChild(node);
document.removeEventListener('pdf.js.response', listener, false);
return callback(response);
}, false);
}
document.documentElement.appendChild(request);
var sender = document.createEvent('HTMLEvents');
sender.initEvent('pdf.js.message', true, false);
return request.dispatchEvent(sender);
}
};
})();
// Settings Manager - This is a utility for saving settings // Settings Manager - This is a utility for saving settings
// First we see if localStorage is available // First we see if localStorage is available
@ -167,17 +110,17 @@ var Settings = (function SettingsClosure() {
} }
})(); })();
var isFirefoxExtension = PDFJS.isFirefoxExtension;
function Settings(fingerprint) { function Settings(fingerprint) {
var database = null; var database = null;
var index; var index;
if (isFirefoxExtension) //#if !(FIREFOX || MOZCENTRAL)
database = FirefoxCom.requestSync('getDatabase', null) || '{}'; if (isLocalStorageEnabled)
else if (isLocalStorageEnabled)
database = localStorage.getItem('database') || '{}'; database = localStorage.getItem('database') || '{}';
else else
return false; return;
//#else
// database = FirefoxCom.requestSync('getDatabase', null) || '{}';
//#endif
database = JSON.parse(database); database = JSON.parse(database);
if (!('files' in database)) if (!('files' in database))
@ -205,10 +148,12 @@ var Settings = (function SettingsClosure() {
var file = this.file; var file = this.file;
file[name] = val; file[name] = val;
var database = JSON.stringify(this.database); var database = JSON.stringify(this.database);
if (isFirefoxExtension) //#if !(FIREFOX || MOZCENTRAL)
FirefoxCom.requestSync('setDatabase', database); if (isLocalStorageEnabled)
else if (isLocalStorageEnabled)
localStorage.setItem('database', database); localStorage.setItem('database', database);
//#else
// FirefoxCom.requestSync('setDatabase', database);
//#endif
}, },
get: function settingsGet(name, defaultValue) { get: function settingsGet(name, defaultValue) {
@ -351,9 +296,10 @@ var PDFView = {
set page(val) { set page(val) {
var pages = this.pages; var pages = this.pages;
var input = document.getElementById('pageNumber'); var input = document.getElementById('pageNumber');
var event = document.createEvent('UIEvents');
event.initUIEvent('pagechange', false, false, window, 0);
if (!(0 < val && val <= pages.length)) { if (!(0 < val && val <= pages.length)) {
var event = document.createEvent('UIEvents');
event.initUIEvent('pagechange', false, false, window, 0);
event.pageNumber = this.page; event.pageNumber = this.page;
window.dispatchEvent(event); window.dispatchEvent(event);
return; return;
@ -361,8 +307,6 @@ var PDFView = {
pages[val - 1].updateStats(); pages[val - 1].updateStats();
currentPageNumber = val; currentPageNumber = val;
var event = document.createEvent('UIEvents');
event.initUIEvent('pagechange', false, false, window, 0);
event.pageNumber = val; event.pageNumber = val;
window.dispatchEvent(event); window.dispatchEvent(event);
@ -486,52 +430,54 @@ var PDFView = {
} }
var url = this.url.split('#')[0]; var url = this.url.split('#')[0];
if (PDFJS.isFirefoxExtension) { //#if !(FIREFOX || MOZCENTRAL)
// Document isn't ready just try to download with the url. url += '#pdfjs.action=download';
if (!this.pdfDocument) { window.open(url, '_parent');
noData(); //#else
return; // // Document isn't ready just try to download with the url.
} // if (!this.pdfDocument) {
this.pdfDocument.getData().then( // noData();
function getDataSuccess(data) { // return;
var bb = new MozBlobBuilder(); // }
bb.append(data.buffer); // this.pdfDocument.getData().then(
var blobUrl = window.URL.createObjectURL( // function getDataSuccess(data) {
bb.getBlob('application/pdf')); // var bb = new MozBlobBuilder();
// bb.append(data.buffer);
FirefoxCom.request('download', { blobUrl: blobUrl, originalUrl: url }, // var blobUrl = window.URL.createObjectURL(
function response(err) { // bb.getBlob('application/pdf'));
if (err) { //
// This error won't really be helpful because it's likely the // FirefoxCom.request('download', { blobUrl: blobUrl, originalUrl: url },
// fallback won't work either (or is already open). // function response(err) {
PDFView.error('PDF failed to download.'); // if (err) {
} // // This error won't really be helpful because it's likely the
window.URL.revokeObjectURL(blobUrl); // // fallback won't work either (or is already open).
} // PDFView.error('PDF failed to download.');
); // }
}, // window.URL.revokeObjectURL(blobUrl);
noData // Error ocurred try downloading with just the url. // }
); // );
} else { // },
url += '#pdfjs.action=download', '_parent'; // noData // Error occurred try downloading with just the url.
window.open(url, '_parent'); // );
} //#endif
}, },
fallback: function pdfViewFallback() { fallback: function pdfViewFallback() {
if (!PDFJS.isFirefoxExtension) //#if !(FIREFOX || MOZCENTRAL)
return; // return;
// Only trigger the fallback once so we don't spam the user with messages //#else
// for one PDF. // // Only trigger the fallback once so we don't spam the user with messages
if (this.fellback) // // for one PDF.
return; // if (this.fellback)
this.fellback = true; // return;
var url = this.url.split('#')[0]; // this.fellback = true;
FirefoxCom.request('fallback', url, function response(download) { // var url = this.url.split('#')[0];
if (!download) // FirefoxCom.request('fallback', url, function response(download) {
return; // if (!download)
PDFView.download(); // return;
}); // PDFView.download();
// });
//#endif
}, },
navigateTo: function pdfViewNavigateTo(dest) { navigateTo: function pdfViewNavigateTo(dest) {
@ -583,9 +529,11 @@ var PDFView = {
* @param {String} anchor The anchor hash include the #. * @param {String} anchor The anchor hash include the #.
*/ */
getAnchorUrl: function getAnchorUrl(anchor) { getAnchorUrl: function getAnchorUrl(anchor) {
if (PDFJS.isFirefoxExtension) //#if !(FIREFOX || MOZCENTRAL)
return this.url.split('#')[0] + anchor;
return anchor; return anchor;
//#else
// return this.url.split('#')[0] + anchor;
//#endif
}, },
/** /**
@ -619,11 +567,7 @@ var PDFView = {
} }
} }
} }
if (PDFJS.isFirefoxExtension) { //#if !(FIREFOX || MOZCENTRAL)
console.error(message + '\n' + moreInfoText);
this.fallback();
return;
}
var errorWrapper = document.getElementById('errorWrapper'); var errorWrapper = document.getElementById('errorWrapper');
errorWrapper.removeAttribute('hidden'); errorWrapper.removeAttribute('hidden');
@ -653,6 +597,10 @@ var PDFView = {
errorMoreInfo.value = moreInfoText; errorMoreInfo.value = moreInfoText;
errorMoreInfo.rows = moreInfoText.split('\n').length - 1; errorMoreInfo.rows = moreInfoText.split('\n').length - 1;
//#else
// console.error(message + '\n' + moreInfoText);
// this.fallback();
//#endif
}, },
progress: function pdfViewProgress(level) { progress: function pdfViewProgress(level) {
@ -811,7 +759,7 @@ var PDFView = {
} }
}, },
getHighestPriority: function pdfViewGetHighestPriority(visibleViews, views, getHighestPriority: function pdfViewGetHighestPriority(visible, views,
scrolledDown) { scrolledDown) {
// The state has changed figure out which page has the highest priority to // The state has changed figure out which page has the highest priority to
// render next (if any). // render next (if any).
@ -819,9 +767,10 @@ var PDFView = {
// 1 visible pages // 1 visible pages
// 2 if last scrolled down page after the visible pages // 2 if last scrolled down page after the visible pages
// 2 if last scrolled up page before the visible pages // 2 if last scrolled up page before the visible pages
var visibleViews = visible.views;
var numVisible = visibleViews.length; var numVisible = visibleViews.length;
if (numVisible === 0) { if (numVisible === 0) {
info('No visible views.');
return false; return false;
} }
for (var i = 0; i < numVisible; ++i) { for (var i = 0; i < numVisible; ++i) {
@ -832,13 +781,12 @@ var PDFView = {
// All the visible views have rendered, try to render next/previous pages. // All the visible views have rendered, try to render next/previous pages.
if (scrolledDown) { if (scrolledDown) {
var lastVisible = visibleViews[visibleViews.length - 1]; var nextPageIndex = visible.last.id;
var nextPageIndex = lastVisible.id;
// ID's start at 1 so no need to add 1. // ID's start at 1 so no need to add 1.
if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex]))
return views[nextPageIndex]; return views[nextPageIndex];
} else { } else {
var previousPageIndex = visibleViews[0].id - 2; var previousPageIndex = visible.first.id - 2;
if (views[previousPageIndex] && if (views[previousPageIndex] &&
!this.isViewFinished(views[previousPageIndex])) !this.isViewFinished(views[previousPageIndex]))
return views[previousPageIndex]; return views[previousPageIndex];
@ -876,14 +824,14 @@ var PDFView = {
search: function pdfViewStartSearch() { search: function pdfViewStartSearch() {
// Limit this function to run every <SEARCH_TIMEOUT>ms. // Limit this function to run every <SEARCH_TIMEOUT>ms.
var SEARCH_TIMEOUT = 250; var SEARCH_TIMEOUT = 250;
var lastSeach = this.lastSearch; var lastSearch = this.lastSearch;
var now = Date.now(); var now = Date.now();
if (lastSeach && (now - lastSeach) < SEARCH_TIMEOUT) { if (lastSearch && (now - lastSearch) < SEARCH_TIMEOUT) {
if (!this.searchTimer) { if (!this.searchTimer) {
this.searchTimer = setTimeout(function resumeSearch() { this.searchTimer = setTimeout(function resumeSearch() {
PDFView.search(); PDFView.search();
}, },
SEARCH_TIMEOUT - (now - lastSeach) SEARCH_TIMEOUT - (now - lastSearch)
); );
} }
return; return;
@ -952,7 +900,6 @@ var PDFView = {
} }
if ('page' in params) { if ('page' in params) {
var pageNumber = (params.page | 0) || 1; var pageNumber = (params.page | 0) || 1;
this.page = pageNumber;
if ('zoom' in params) { if ('zoom' in params) {
var zoomArgs = params.zoom.split(','); // scale,left,top var zoomArgs = params.zoom.split(','); // scale,left,top
// building destination array // building destination array
@ -968,9 +915,9 @@ var PDFView = {
(zoomArgs[2] | 0), zoomArg]; (zoomArgs[2] | 0), zoomArg];
var currentPage = this.pages[pageNumber - 1]; var currentPage = this.pages[pageNumber - 1];
currentPage.scrollIntoView(dest); currentPage.scrollIntoView(dest);
} else } else {
this.page = params.page; // simple page this.page = pageNumber; // simple page
return; }
} }
} else if (/^\d+$/.test(hash)) // page number } else if (/^\d+$/.test(hash)) // page number
this.page = hash; this.page = hash;
@ -1041,13 +988,13 @@ var PDFView = {
extractPageText(pageIndex + 1); extractPageText(pageIndex + 1);
} }
); );
}; }
extractPageText(0); extractPageText(0);
}, },
getVisiblePages: function pdfViewGetVisiblePages() { getVisiblePages: function pdfViewGetVisiblePages() {
return this.getVisibleElements(this.container, return this.getVisibleElements(this.container,
this.pages); this.pages, true);
}, },
getVisibleThumbs: function pdfViewGetVisibleThumbs() { getVisibleThumbs: function pdfViewGetVisibleThumbs() {
@ -1056,11 +1003,12 @@ var PDFView = {
}, },
// Generic helper to find out what elements are visible within a scroll pane. // Generic helper to find out what elements are visible within a scroll pane.
getVisibleElements: function pdfViewGetVisibleElements(scrollEl, views) { getVisibleElements: function pdfViewGetVisibleElements(
scrollEl, views, sortByVisibility) {
var currentHeight = 0, view; var currentHeight = 0, view;
var top = scrollEl.scrollTop; var top = scrollEl.scrollTop;
for (var i = 1; i <= views.length; ++i) { for (var i = 1, ii = views.length; i <= ii; ++i) {
view = views[i - 1]; view = views[i - 1];
currentHeight = view.el.offsetTop; currentHeight = view.el.offsetTop;
if (currentHeight + view.el.clientHeight > top) if (currentHeight + view.el.clientHeight > top)
@ -1078,19 +1026,38 @@ var PDFView = {
view: currentPage view: currentPage
}); });
return visible; return { first: currentPage, last: currentPage, views: visible};
} }
var bottom = top + scrollEl.clientHeight; var bottom = top + scrollEl.clientHeight;
for (; i <= views.length && currentHeight < bottom; ++i) { var nextHeight, hidden, percent, viewHeight;
for (; i <= ii && currentHeight < bottom; ++i) {
view = views[i - 1]; view = views[i - 1];
viewHeight = view.el.clientHeight;
currentHeight = view.el.offsetTop; currentHeight = view.el.offsetTop;
nextHeight = currentHeight + viewHeight;
hidden = Math.max(0, top - currentHeight) +
Math.max(0, nextHeight - bottom);
percent = Math.floor((viewHeight - hidden) * 100.0 / viewHeight);
visible.push({ id: view.id, y: currentHeight, visible.push({ id: view.id, y: currentHeight,
view: view }); view: view, percent: percent });
currentHeight += view.el.clientHeight; currentHeight = nextHeight;
} }
return visible; var first = visible[0];
var last = visible[visible.length - 1];
if (sortByVisibility) {
visible.sort(function(a, b) {
var pc = a.percent - b.percent;
if (Math.abs(pc) > 0.001)
return -pc;
return a.id - b.id; // ensure stability
});
}
return {first: first, last: last, views: visible};
}, },
// Helper function to parse query string (e.g. ?param1=value&parm2=...). // Helper function to parse query string (e.g. ?param1=value&parm2=...).
@ -1727,13 +1694,13 @@ var CustomStyle = (function CustomStyleClosure() {
//if all fails then set to undefined //if all fails then set to undefined
return (_cache[propName] = 'undefined'); return (_cache[propName] = 'undefined');
} };
CustomStyle.setProp = function set(propName, element, str) { CustomStyle.setProp = function set(propName, element, str) {
var prop = this.getProp(propName); var prop = this.getProp(propName);
if (prop != 'undefined') if (prop != 'undefined')
element.style[prop] = str; element.style[prop] = str;
} };
return CustomStyle; return CustomStyle;
})(); })();
@ -1763,6 +1730,7 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
if (textDivs.length === 0) { if (textDivs.length === 0) {
clearInterval(renderTimer); clearInterval(renderTimer);
renderingDone = true; renderingDone = true;
self.textLayerDiv = textLayerDiv = canvas = ctx = null;
return; return;
} }
var textDiv = textDivs.shift(); var textDiv = textDivs.shift();
@ -1802,7 +1770,7 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
// Resume rendering // Resume rendering
renderTimer = setInterval(renderTextLayer, renderInterval); renderTimer = setInterval(renderTextLayer, renderInterval);
}, resumeInterval); }, resumeInterval);
}; // textLayerOnScroll } // textLayerOnScroll
window.addEventListener('scroll', textLayerOnScroll, false); window.addEventListener('scroll', textLayerOnScroll, false);
}; // endLayout }; // endLayout
@ -1830,15 +1798,21 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
PDFView.initialize(); PDFView.initialize();
var params = PDFView.parseQueryString(document.location.search.substring(1)); var params = PDFView.parseQueryString(document.location.search.substring(1));
var file = PDFJS.isFirefoxExtension ? //#if !(FIREFOX || MOZCENTRAL)
window.location.toString() : params.file || kDefaultURL; var file = params.file || kDefaultURL;
//#else
//var file = window.location.toString()
//#endif
if (PDFJS.isFirefoxExtension || !window.File || !window.FileReader || //#if !(FIREFOX || MOZCENTRAL)
!window.FileList || !window.Blob) { if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
document.getElementById('openFile').setAttribute('hidden', 'true'); document.getElementById('openFile').setAttribute('hidden', 'true');
} else { } else {
document.getElementById('fileInput').value = null; document.getElementById('fileInput').value = null;
} }
//#else
//document.getElementById('openFile').setAttribute('hidden', 'true');
//#endif
// Special debugging flags in the hash section of the URL. // Special debugging flags in the hash section of the URL.
var hash = document.location.hash.substring(1); var hash = document.location.hash.substring(1);
@ -1847,18 +1821,21 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
if ('disableWorker' in hashParams) if ('disableWorker' in hashParams)
PDFJS.disableWorker = (hashParams['disableWorker'] === 'true'); PDFJS.disableWorker = (hashParams['disableWorker'] === 'true');
if (!PDFJS.isFirefoxExtension) { //#if !(FIREFOX || MOZCENTRAL)
var locale = navigator.language; var locale = navigator.language;
if ('locale' in hashParams) if ('locale' in hashParams)
locale = hashParams['locale']; locale = hashParams['locale'];
mozL10n.language.code = locale; mozL10n.language.code = locale;
} //#endif
if ('disableTextLayer' in hashParams) if ('disableTextLayer' in hashParams)
PDFJS.disableTextLayer = (hashParams['disableTextLayer'] === 'true'); PDFJS.disableTextLayer = (hashParams['disableTextLayer'] === 'true');
if ('pdfBug' in hashParams && //#if !(FIREFOX || MOZCENTRAL)
(!PDFJS.isFirefoxExtension || FirefoxCom.requestSync('pdfBugEnabled'))) { if ('pdfBug' in hashParams) {
//#else
//if ('pdfBug' in hashParams && FirefoxCom.requestSync('pdfBugEnabled')) {
//#endif
PDFJS.pdfBug = true; PDFJS.pdfBug = true;
var pdfBug = hashParams['pdfBug']; var pdfBug = hashParams['pdfBug'];
var enabled = pdfBug.split(','); var enabled = pdfBug.split(',');
@ -1866,10 +1843,12 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
PDFBug.init(); PDFBug.init();
} }
if (!PDFJS.isFirefoxExtension || //#if !(FIREFOX || MOZCENTRAL)
(PDFJS.isFirefoxExtension && FirefoxCom.requestSync('searchEnabled'))) { //#else
document.querySelector('#viewSearch').classList.remove('hidden'); //if (FirefoxCom.requestSync('searchEnabled')) {
} // document.querySelector('#viewSearch').classList.remove('hidden');
//}
//#endif
if (!PDFView.supportsPrinting) { if (!PDFView.supportsPrinting) {
document.getElementById('print').classList.add('hidden'); document.getElementById('print').classList.add('hidden');
@ -1907,27 +1886,50 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
PDFView.renderHighestPriority(); PDFView.renderHighestPriority();
}); });
if (PDFJS.isFirefoxExtension && //#if (FIREFOX || MOZCENTRAL)
FirefoxCom.requestSync('getLoadingType') == 'passive') { //if (FirefoxCom.requestSync('getLoadingType') == 'passive') {
PDFView.setTitleUsingUrl(file); // PDFView.setTitleUsingUrl(file);
PDFView.initPassiveLoading(); // PDFView.initPassiveLoading();
} else //}
PDFView.open(file, 0); //#endif
//#if !B2G
PDFView.open(file, 0);
//#endif
}, true); }, true);
function updateViewarea() { function updateViewarea() {
if (!PDFView.initialized) if (!PDFView.initialized)
return; return;
var visiblePages = PDFView.getVisiblePages(); var visible = PDFView.getVisiblePages();
var visiblePages = visible.views;
PDFView.renderHighestPriority(); PDFView.renderHighestPriority();
var currentId = PDFView.page; var currentId = PDFView.page;
var firstPage = visiblePages[0]; var firstPage = visible.first;
for (var i = 0, ii = visiblePages.length, stillFullyVisible = false;
i < ii; ++i) {
var page = visiblePages[i];
if (page.percent < 100)
break;
if (page.id === PDFView.page) {
stillFullyVisible = true;
break;
}
}
if (!stillFullyVisible) {
currentId = visiblePages[0].id;
}
if (!PDFView.isFullscreen) { if (!PDFView.isFullscreen) {
updateViewarea.inProgress = true; // used in "set page" updateViewarea.inProgress = true; // used in "set page"
PDFView.page = firstPage.id; PDFView.page = currentId;
updateViewarea.inProgress = false; updateViewarea.inProgress = false;
} }
@ -1975,20 +1977,13 @@ window.addEventListener('change', function webViewerChange(evt) {
// Read the local file into a Uint8Array. // Read the local file into a Uint8Array.
var fileReader = new FileReader(); var fileReader = new FileReader();
fileReader.onload = function webViewerChangeFileReaderOnload(evt) { fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
var data = evt.target.result; var buffer = evt.target.result;
var buffer = new ArrayBuffer(data.length);
var uint8Array = new Uint8Array(buffer); var uint8Array = new Uint8Array(buffer);
for (var i = 0; i < data.length; i++)
uint8Array[i] = data.charCodeAt(i);
PDFView.open(uint8Array, 0); PDFView.open(uint8Array, 0);
}; };
// Read as a binary string since "readAsArrayBuffer" is not yet
// implemented in Firefox.
var file = files[0]; var file = files[0];
fileReader.readAsBinaryString(file); fileReader.readAsArrayBuffer(file);
PDFView.setTitleUsingUrl(file.name); PDFView.setTitleUsingUrl(file.name);
// URL does not reflect proper document location - hiding some icons. // URL does not reflect proper document location - hiding some icons.
@ -2046,13 +2041,13 @@ window.addEventListener('pagechange', function pagechange(evt) {
var thumbnail = document.getElementById('thumbnailContainer' + page); var thumbnail = document.getElementById('thumbnailContainer' + page);
thumbnail.classList.add('selected'); thumbnail.classList.add('selected');
var visibleThumbs = PDFView.getVisibleThumbs(); var visibleThumbs = PDFView.getVisibleThumbs();
var numVisibleThumbs = visibleThumbs.length; var numVisibleThumbs = visibleThumbs.views.length;
// If the thumbnail isn't currently visible scroll it into view. // If the thumbnail isn't currently visible scroll it into view.
if (numVisibleThumbs > 0) { if (numVisibleThumbs > 0) {
var first = visibleThumbs[0].id; var first = visibleThumbs.first.id;
// Account for only one thumbnail being visible. // Account for only one thumbnail being visible.
var last = numVisibleThumbs > 1 ? var last = numVisibleThumbs > 1 ?
visibleThumbs[numVisibleThumbs - 1].id : first; visibleThumbs.last.id : first;
if (page <= first || page >= last) if (page <= first || page >= last)
thumbnail.scrollIntoView(); thumbnail.scrollIntoView();
} }
@ -2171,3 +2166,21 @@ window.addEventListener('afterprint', function afterPrint(evt) {
window.addEventListener('mozfullscreenchange', fullscreenChange, false); window.addEventListener('mozfullscreenchange', fullscreenChange, false);
window.addEventListener('webkitfullscreenchange', fullscreenChange, false); window.addEventListener('webkitfullscreenchange', fullscreenChange, false);
})(); })();
//#if B2G
//window.navigator.mozSetMessageHandler('activity', function(activity) {
// var url = activity.source.data.url;
// // Temporarily get the data here since the cross domain xhr is broken in
// // the worker currently, see bug 761227.
// var params = {
// url: url,
// error: function(e) {
// PDFView.error(mozL10n.get('loading_error', null,
// 'An error occurred while loading the PDF.'), e);
// }
// };
// PDFJS.getPdf(params, function successCallback(data) {
// PDFView.open(data, 0);
// });
//});
//#endif