Guess default width for FileFont3 using BaseFont
This commit is contained in:
parent
ba04d850f8
commit
2248690d11
82
pdf.js
82
pdf.js
@ -4483,6 +4483,32 @@ var PartialEvaluator = (function() {
|
|||||||
return glyphs;
|
return glyphs;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getBaseFontMetrics: function(baseFontName) {
|
||||||
|
var map = {};
|
||||||
|
if (/^Symbol(-?(Bold|Italic))*$/.test(baseFontName)) {
|
||||||
|
// special case for symbols
|
||||||
|
var encoding = Encodings.symbolsEncoding;
|
||||||
|
for (var i = 0, n = encoding.length, j; i < n; i++) {
|
||||||
|
if (!(j = encoding[i]))
|
||||||
|
continue;
|
||||||
|
map[i] = GlyphsUnicode[j] || 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultWidth = 0;
|
||||||
|
var widths = Metrics[stdFontMap[baseFontName] || baseFontName];
|
||||||
|
if (IsNum(widths)) {
|
||||||
|
defaultWidth = widths;
|
||||||
|
widths = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
defaultWidth: defaultWidth,
|
||||||
|
widths: widths || [],
|
||||||
|
map: map
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
translateFont: function(dict, xref, resources) {
|
translateFont: function(dict, xref, resources) {
|
||||||
var baseDict = dict;
|
var baseDict = dict;
|
||||||
var type = dict.get('Subtype');
|
var type = dict.get('Subtype');
|
||||||
@ -4518,30 +4544,15 @@ var PartialEvaluator = (function() {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Using base font name as a font name.
|
// Using base font name as a font name.
|
||||||
baseFontName = baseFontName.name;
|
baseFontName = baseFontName.name.replace(/,/g, '_');
|
||||||
var map = {};
|
var metrics = this.getBaseFontMetrics(baseFontName);
|
||||||
if (/^Symbol(-?(Bold|Italic))*$/.test(baseFontName)) {
|
|
||||||
// special case for symbols
|
|
||||||
var encoding = Encodings.symbolsEncoding;
|
|
||||||
for (var i = 0, n = encoding.length, j; i < n; i++) {
|
|
||||||
if (!(j = encoding[i]))
|
|
||||||
continue;
|
|
||||||
map[i] = GlyphsUnicode[j] || 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var defaultWidth = 0;
|
|
||||||
var widths = Metrics[stdFontMap[baseFontName] || baseFontName];
|
|
||||||
if (IsNum(widths)) {
|
|
||||||
defaultWidth = widths;
|
|
||||||
widths = null;
|
|
||||||
}
|
|
||||||
var properties = {
|
var properties = {
|
||||||
type: type.name,
|
type: type.name,
|
||||||
encoding: map,
|
encoding: metrics.map,
|
||||||
differences: [],
|
differences: [],
|
||||||
widths: widths || {},
|
widths: metrics.widths,
|
||||||
defaultWidth: defaultWidth,
|
defaultWidth: metrics.defaultWidth,
|
||||||
firstChar: 0,
|
firstChar: 0,
|
||||||
lastChar: 256
|
lastChar: 256
|
||||||
};
|
};
|
||||||
@ -4561,7 +4572,25 @@ var PartialEvaluator = (function() {
|
|||||||
// a variant.
|
// a variant.
|
||||||
var firstChar = xref.fetchIfRef(dict.get('FirstChar')) || 0;
|
var firstChar = xref.fetchIfRef(dict.get('FirstChar')) || 0;
|
||||||
var lastChar = xref.fetchIfRef(dict.get('LastChar')) || 256;
|
var lastChar = xref.fetchIfRef(dict.get('LastChar')) || 256;
|
||||||
var widths = xref.fetchIfRef(dict.get('Widths')) || [];
|
var defaultWidth = 0;
|
||||||
|
var glyphWidths = {};
|
||||||
|
var encoding = {};
|
||||||
|
var widths = xref.fetchIfRef(dict.get('Widths'));
|
||||||
|
if (widths) {
|
||||||
|
for (var i = 0, j = firstChar; i < widths.length; i++, j++)
|
||||||
|
glyphWidths[j] = widths[i];
|
||||||
|
defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
|
||||||
|
} else {
|
||||||
|
// Trying get the BaseFont metrics (see comment above).
|
||||||
|
var baseFontName = dict.get('BaseFont');
|
||||||
|
if (IsName(baseFontName)) {
|
||||||
|
var metrics = this.getBaseFontMetrics(baseFontName.name);
|
||||||
|
|
||||||
|
glyphWidths = metrics.widths;
|
||||||
|
defaultWidth = metrics.defaultWidth;
|
||||||
|
encoding = metrics.map;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var fontName = xref.fetchIfRef(descriptor.get('FontName'));
|
var fontName = xref.fetchIfRef(descriptor.get('FontName'));
|
||||||
assertWellFormed(IsName(fontName), 'invalid font name');
|
assertWellFormed(IsName(fontName), 'invalid font name');
|
||||||
@ -4600,17 +4629,12 @@ var PartialEvaluator = (function() {
|
|||||||
descent: descriptor.get('Descent'),
|
descent: descriptor.get('Descent'),
|
||||||
xHeight: descriptor.get('XHeight'),
|
xHeight: descriptor.get('XHeight'),
|
||||||
capHeight: descriptor.get('CapHeight'),
|
capHeight: descriptor.get('CapHeight'),
|
||||||
defaultWidth: parseFloat(descriptor.get('MissingWidth')) || 0,
|
defaultWidth: defaultWidth,
|
||||||
flags: descriptor.get('Flags'),
|
flags: descriptor.get('Flags'),
|
||||||
italicAngle: descriptor.get('ItalicAngle'),
|
italicAngle: descriptor.get('ItalicAngle'),
|
||||||
differences: [],
|
differences: [],
|
||||||
widths: (function() {
|
widths: glyphWidths,
|
||||||
var glyphWidths = {};
|
encoding: encoding
|
||||||
for (var i = 0; i < widths.length; i++)
|
|
||||||
glyphWidths[firstChar++] = widths[i];
|
|
||||||
return glyphWidths;
|
|
||||||
})(),
|
|
||||||
encoding: {}
|
|
||||||
};
|
};
|
||||||
properties.glyphs = this.extractEncoding(dict, xref, properties);
|
properties.glyphs = this.extractEncoding(dict, xref, properties);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user