Skip to content

Commit 8e50da7

Browse files
committed
Merge pull request mozilla#2050 from yurydelendik/issue-2040
Fixes incorrect font type and prevents future this.objs.objs[fonts[i]] ...
2 parents b9777cf + 621686c commit 8e50da7

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

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:

src/fonts.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,13 +1577,19 @@ var Font = (function FontClosure() {
15771577
return;
15781578
}
15791579

1580+
// Some fonts might use wrong font types for Type1C or CIDFontType0C
1581+
var subtype = properties.subtype;
1582+
if (subtype == 'Type1C' && (type != 'Type1' && type != 'MMType1'))
1583+
type = 'Type1';
1584+
if (subtype == 'CIDFontType0C' && type != 'CIDFontType0')
1585+
type = 'CIDFontType0';
1586+
15801587
var data;
15811588
switch (type) {
15821589
case 'Type1':
15831590
case 'CIDFontType0':
15841591
this.mimetype = 'font/opentype';
15851592

1586-
var subtype = properties.subtype;
15871593
var cff = (subtype == 'Type1C' || subtype == 'CIDFontType0C') ?
15881594
new CFFFont(file, properties) : new Type1Font(name, file, properties);
15891595

@@ -3310,6 +3316,20 @@ var Font = (function FontClosure() {
33103316
return Font;
33113317
})();
33123318

3319+
var ErrorFont = (function ErrorFontClosure() {
3320+
function ErrorFont(error) {
3321+
this.error = error;
3322+
}
3323+
3324+
ErrorFont.prototype = {
3325+
charsToGlyphs: function ErrorFont_charsToGlyphs() {
3326+
return [];
3327+
}
3328+
};
3329+
3330+
return ErrorFont;
3331+
})();
3332+
33133333
var CallothersubrCmd = (function CallothersubrCmdClosure() {
33143334
function CallothersubrCmd(index) {
33153335
this.index = index;

0 commit comments

Comments
 (0)