Skip to content

Commit aea65f8

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 2c496b6 + 8e50da7 commit aea65f8

File tree

12 files changed

+314
-130
lines changed

12 files changed

+314
-130
lines changed

external/jpgjs/LICENSE

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11

2-
Copyright (C) 2011 by notmasteryet
2+
Copyright (C) 2011 notmasteryet
33

4-
Contributors: Yury Delendik
5-
Brendan Dahl <bdahl@mozilla.com>
4+
Contributors: Yury Delendik <ydelendik@mozilla.com>
5+
Brendan Dahl <bdahl@mozilla.com>
66

7-
Permission is hereby granted, free of charge, to any person obtaining
8-
a copy of this software and associated documentation files (the
9-
"Software"), to deal in the Software without restriction, including
10-
without limitation the rights to use, copy, modify, merge, publish,
11-
distribute, sublicense, and/or sell copies of the Software, and to
12-
permit persons to whom the Software is furnished to do so, subject to
13-
the following conditions:
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
1410

15-
The above copyright notice and this permission notice shall be
16-
included in all copies or substantial portions of the Software.
11+
http://www.apache.org/licenses/LICENSE-2.0
1712

18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.

external/jpgjs/jpg.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
22
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
3+
/*
4+
Copyright 2011 notmasteryet
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
318

419
// - The JPEG specification can be found in the ITU CCITT Recommendation T.81
520
// (www.w3.org/Graphics/JPEG/itu-t81.pdf)
@@ -627,8 +642,9 @@ var JpegImage = (function jpegImage() {
627642
break;
628643

629644
case 0xFFDB: // DQT (Define Quantization Tables)
630-
var quantizationTableCount = Math.floor((readUint16() - 2) / 65);
631-
for (i = 0; i < quantizationTableCount; i++) {
645+
var quantizationTablesLength = readUint16();
646+
var quantizationTablesEnd = quantizationTablesLength + offset - 2;
647+
while (offset < quantizationTablesEnd) {
632648
var quantizationTableSpec = data[offset++];
633649
var tableData = new Int32Array(64);
634650
if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
@@ -721,6 +737,13 @@ var JpegImage = (function jpegImage() {
721737
offset += processed;
722738
break;
723739
default:
740+
if (data[offset - 3] == 0xFF &&
741+
data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
742+
// could be incorrect encoding -- last 0xFF byte of the previous
743+
// block was eaten by the encoder
744+
offset -= 3;
745+
break;
746+
}
724747
throw "unknown JPEG marker " + fileMarker.toString(16);
725748
}
726749
fileMarker = readUint16();

make.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root
66
BUILD_DIR = 'build/',
77
BUILD_TARGET = BUILD_DIR + 'pdf.js',
88
FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/',
9+
CHROME_BUILD_DIR = BUILD_DIR + '/chrome/',
910
EXTENSION_SRC_DIR = 'extensions/',
1011
LOCALE_SRC_DIR = 'l10n/',
1112
GH_PAGES_DIR = BUILD_DIR + 'gh-pages/',
@@ -107,6 +108,8 @@ target.web = function() {
107108
cp('-R', GENERIC_DIR + '/*', GH_PAGES_DIR);
108109
cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf',
109110
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/');
111+
cp(CHROME_BUILD_DIR + '/*.crx', FIREFOX_BUILD_DIR + '/*.rdf',
112+
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chrome/');
110113
cp('web/index.html.template', GH_PAGES_DIR + '/index.html');
111114

112115
cd(GH_PAGES_DIR);
@@ -258,6 +261,7 @@ target.pagesrepo = function() {
258261
mkdir('-p', GH_PAGES_DIR + '/web/images');
259262
mkdir('-p', GH_PAGES_DIR + BUILD_DIR);
260263
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/firefox');
264+
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chrome');
261265
};
262266

263267

@@ -574,6 +578,70 @@ target.chrome = function() {
574578
]
575579
};
576580
builder.build(setup);
581+
582+
// Bundle the files to a Chrome extension file .crx if path to key is set
583+
var pem = env['PDFJS_CHROME_KEY'];
584+
if (!pem) {
585+
return;
586+
}
587+
588+
echo();
589+
echo('### Bundling .crx extension into ' + CHROME_BUILD_DIR);
590+
591+
if (!test('-f', pem)) {
592+
echo('Incorrect PDFJS_CHROME_KEY path');
593+
exit(1);
594+
}
595+
596+
var browserManifest = env['PDF_BROWSERS'] ||
597+
'test/resources/browser_manifests/browser_manifest.json';
598+
599+
if (!test('-f', browserManifest)) {
600+
echo('Browser manifest file ' + browserManifest + ' does not exist.');
601+
echo('Try copying one of the examples in test/resources/browser_manifests');
602+
exit(1);
603+
}
604+
605+
try {
606+
var manifest = JSON.parse(cat(browserManifest));
607+
} catch (e) {
608+
echo('Malformed browser manifest file');
609+
echo(e.message);
610+
exit(1);
611+
}
612+
613+
var executable;
614+
manifest.forEach(function(browser) {
615+
if (browser.name === 'chrome') {
616+
executable = browser.path;
617+
}
618+
});
619+
620+
// If there was no chrome entry in the browser manifest, exit
621+
if (!executable) {
622+
echo('There was no \'chrome\' entry in the browser manifest');
623+
exit(1);
624+
}
625+
626+
// If we're on a Darwin (Mac) OS, then let's check for an .app path
627+
if (process.platform === 'darwin' && executable.indexOf('.app') !== -1) {
628+
executable = executable + '/Contents/MacOS/Google Chrome';
629+
}
630+
631+
// If the chrome executable doesn't exist
632+
if (!test('-f', executable)) {
633+
echo('Incorrect executable path to chrome');
634+
exit(1);
635+
}
636+
637+
// Let chrome pack the extension for us
638+
exec('"' + executable + '"' +
639+
' --no-message-box' +
640+
' "--pack-extension=' + ROOT_DIR + CHROME_BUILD_DIR + '"' +
641+
' "--pack-extension-key=' + pem + '"');
642+
643+
// Rename to pdf.js.crx
644+
mv(BUILD_DIR + 'chrome.crx', CHROME_BUILD_DIR + 'pdf.js.crx');
577645
};
578646

579647

src/api.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,19 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
311311
ensureFonts: function PDFPageProxy_ensureFonts(fonts, callback) {
312312
this.stats.time('Font Loading');
313313
// Convert the font names to the corresponding font obj.
314+
var fontObjs = [];
314315
for (var i = 0, ii = fonts.length; i < ii; i++) {
315-
fonts[i] = this.objs.objs[fonts[i]].data;
316+
var obj = this.objs.objs[fonts[i]].data;
317+
if (obj.error) {
318+
warn('Error during font loading: ' + obj.error);
319+
continue;
320+
}
321+
fontObjs.push(obj);
316322
}
317323

318324
// Load all the fonts
319325
FontLoader.bind(
320-
fonts,
326+
fontObjs,
321327
function pageEnsureFontsFontObjs(fontObjs) {
322328
this.stats.timeEnd('Font Loading');
323329

@@ -565,7 +571,12 @@ var WorkerTransport = (function WorkerTransportClosure() {
565571

566572
// At this point, only the font object is created but the font is
567573
// not yet attached to the DOM. This is done in `FontLoader.bind`.
568-
var font = new Font(name, file, properties);
574+
var font;
575+
try {
576+
font = new Font(name, file, properties);
577+
} catch (e) {
578+
font = new ErrorFont(e);
579+
}
569580
this.objs.resolve(id, font);
570581
break;
571582
default:

0 commit comments

Comments
 (0)