Skip to content

Commit b718a36

Browse files
committed
Default to a built-in font if an invalid non-embedded font is encountered
1 parent fa1133f commit b718a36

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/evaluator.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,9 +1089,30 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
10891089
properties.widths = glyphsWidths;
10901090
},
10911091

1092+
isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
1093+
1094+
// Simulating descriptor flags attribute
1095+
var fontNameWoStyle = baseFontName.split('-')[0];
1096+
return (fontNameWoStyle in serifFonts) ||
1097+
(fontNameWoStyle.search(/serif/gi) !== -1);
1098+
},
1099+
10921100
getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
10931101
var defaultWidth = 0, widths = [], monospace = false;
1094-
var glyphWidths = Metrics[stdFontMap[name] || name];
1102+
1103+
var lookupName = stdFontMap[name] || name;
1104+
1105+
if (!(lookupName in Metrics)) {
1106+
// Use default fonts for looking up font metrics if the passed
1107+
// font is not a base font
1108+
if (this.isSerifFont(name)) {
1109+
lookupName = 'Times-Roman';
1110+
} else {
1111+
lookupName = 'Helvetica';
1112+
}
1113+
}
1114+
var glyphWidths = Metrics[lookupName];
1115+
10951116
if (isNum(glyphWidths)) {
10961117
defaultWidth = glyphWidths;
10971118
monospace = true;
@@ -1153,8 +1174,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
11531174

11541175
// Simulating descriptor flags attribute
11551176
var fontNameWoStyle = baseFontName.split('-')[0];
1156-
var flags = (serifFonts[fontNameWoStyle] ||
1157-
(fontNameWoStyle.search(/serif/gi) != -1) ? FontFlags.Serif : 0) |
1177+
var flags = (
1178+
this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
11581179
(metrics.monospace ? FontFlags.FixedPitch : 0) |
11591180
(symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
11601181
FontFlags.Nonsymbolic);

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
!tracemonkey.pdf
44
!issue2391-1.pdf
5+
!issue2391-2.pdf
56
!ArabicCIDTrueType.pdf
67
!ThuluthFeatures.pdf
78
!arial_unicode_ab_cidfont.pdf

test/pdfs/issue2391-2.pdf

2.69 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
"pageLimit": 1,
2525
"type": "load"
2626
},
27+
{ "id": "issue2391-2",
28+
"file": "pdfs/issue2391-2.pdf",
29+
"md5": "7e68756d11021a087383eaac95ba45dd",
30+
"rounds": 1,
31+
"type": "eq"
32+
},
2733
{ "id": "html5-canvas-cheat-sheet-load",
2834
"file": "pdfs/canvas.pdf",
2935
"md5": "59510028561daf62e00bf9f6f066b033",

0 commit comments

Comments
 (0)