mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #2557 from mduan/issue2391-invalid-font
Default to a built-in font if an invalid non-embedded font is encountered
This commit is contained in:
commit
45daf4e936
4 changed files with 161 additions and 3 deletions
|
@ -1089,9 +1089,30 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
properties.widths = glyphsWidths;
|
||||
},
|
||||
|
||||
isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
|
||||
|
||||
// Simulating descriptor flags attribute
|
||||
var fontNameWoStyle = baseFontName.split('-')[0];
|
||||
return (fontNameWoStyle in serifFonts) ||
|
||||
(fontNameWoStyle.search(/serif/gi) !== -1);
|
||||
},
|
||||
|
||||
getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
|
||||
var defaultWidth = 0, widths = [], monospace = false;
|
||||
var glyphWidths = Metrics[stdFontMap[name] || name];
|
||||
|
||||
var lookupName = stdFontMap[name] || name;
|
||||
|
||||
if (!(lookupName in Metrics)) {
|
||||
// Use default fonts for looking up font metrics if the passed
|
||||
// font is not a base font
|
||||
if (this.isSerifFont(name)) {
|
||||
lookupName = 'Times-Roman';
|
||||
} else {
|
||||
lookupName = 'Helvetica';
|
||||
}
|
||||
}
|
||||
var glyphWidths = Metrics[lookupName];
|
||||
|
||||
if (isNum(glyphWidths)) {
|
||||
defaultWidth = glyphWidths;
|
||||
monospace = true;
|
||||
|
@ -1153,8 +1174,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
|
||||
// Simulating descriptor flags attribute
|
||||
var fontNameWoStyle = baseFontName.split('-')[0];
|
||||
var flags = (serifFonts[fontNameWoStyle] ||
|
||||
(fontNameWoStyle.search(/serif/gi) != -1) ? FontFlags.Serif : 0) |
|
||||
var flags = (
|
||||
this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
|
||||
(metrics.monospace ? FontFlags.FixedPitch : 0) |
|
||||
(symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
|
||||
FontFlags.Nonsymbolic);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue