Lazify GlyphsUnicode.

This commit is contained in:
Yury Delendik 2016-01-21 14:47:48 -06:00
parent 58329f7f92
commit 4ef20de429
4 changed files with 4455 additions and 4433 deletions

View File

@ -31,7 +31,7 @@ var Util = sharedUtil.Util;
var bytesToString = sharedUtil.bytesToString; var bytesToString = sharedUtil.bytesToString;
var error = sharedUtil.error; var error = sharedUtil.error;
var Stream = coreStream.Stream; var Stream = coreStream.Stream;
var GlyphsUnicode = coreGlyphList.GlyphsUnicode; var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
var coreFonts; // see _setCoreFonts below var coreFonts; // see _setCoreFonts below
var CFFParser; // = coreFonts.CFFParser; var CFFParser; // = coreFonts.CFFParser;
@ -670,7 +670,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
this.gsubrs = cffInfo.gsubrs || []; this.gsubrs = cffInfo.gsubrs || [];
this.subrs = cffInfo.subrs || []; this.subrs = cffInfo.subrs || [];
this.cmap = cmap; this.cmap = cmap;
this.glyphNameMap = glyphNameMap || GlyphsUnicode; this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
this.compiledGlyphs = []; this.compiledGlyphs = [];
this.gsubrsBias = (this.gsubrs.length < 1240 ? this.gsubrsBias = (this.gsubrs.length < 1240 ?

View File

@ -56,8 +56,8 @@ var Stream = coreStream.Stream;
var Lexer = coreParser.Lexer; var Lexer = coreParser.Lexer;
var CMapFactory = coreCMap.CMapFactory; var CMapFactory = coreCMap.CMapFactory;
var IdentityCMap = coreCMap.IdentityCMap; var IdentityCMap = coreCMap.IdentityCMap;
var GlyphsUnicode = coreGlyphList.GlyphsUnicode; var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode; var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
var ISOAdobeCharset = coreCharsets.ISOAdobeCharset; var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
var ExpertCharset = coreCharsets.ExpertCharset; var ExpertCharset = coreCharsets.ExpertCharset;
var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset; var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
@ -2542,7 +2542,7 @@ var Font = (function FontClosure() {
this.vmetrics = properties.vmetrics; this.vmetrics = properties.vmetrics;
this.defaultVMetrics = properties.defaultVMetrics; this.defaultVMetrics = properties.defaultVMetrics;
} }
var glyphsUnicodeMap;
if (!file || file.isEmpty) { if (!file || file.isEmpty) {
if (file) { if (file) {
// Some bad PDF generators will include empty font files, // Some bad PDF generators will include empty font files,
@ -2591,35 +2591,37 @@ var Font = (function FontClosure() {
this.toUnicode = new ToUnicodeMap(map); this.toUnicode = new ToUnicodeMap(map);
} else if (/Symbol/i.test(fontName)) { } else if (/Symbol/i.test(fontName)) {
var symbols = Encodings.SymbolSetEncoding; var symbols = Encodings.SymbolSetEncoding;
glyphsUnicodeMap = getGlyphsUnicode();
for (charCode in symbols) { for (charCode in symbols) {
fontChar = GlyphsUnicode[symbols[charCode]]; fontChar = glyphsUnicodeMap[symbols[charCode]];
if (!fontChar) { if (!fontChar) {
continue; continue;
} }
this.toFontChar[charCode] = fontChar; this.toFontChar[charCode] = fontChar;
} }
for (charCode in properties.differences) { for (charCode in properties.differences) {
fontChar = GlyphsUnicode[properties.differences[charCode]]; fontChar = glyphsUnicodeMap[properties.differences[charCode]];
if (!fontChar) { if (!fontChar) {
continue; continue;
} }
this.toFontChar[charCode] = fontChar; this.toFontChar[charCode] = fontChar;
} }
} else if (/Dingbats/i.test(fontName)) { } else if (/Dingbats/i.test(fontName)) {
glyphsUnicodeMap = getDingbatsGlyphsUnicode();
if (/Wingdings/i.test(name)) { if (/Wingdings/i.test(name)) {
warn('Wingdings font without embedded font file, ' + warn('Wingdings font without embedded font file, ' +
'falling back to the ZapfDingbats encoding.'); 'falling back to the ZapfDingbats encoding.');
} }
var dingbats = Encodings.ZapfDingbatsEncoding; var dingbats = Encodings.ZapfDingbatsEncoding;
for (charCode in dingbats) { for (charCode in dingbats) {
fontChar = DingbatsGlyphsUnicode[dingbats[charCode]]; fontChar = glyphsUnicodeMap[dingbats[charCode]];
if (!fontChar) { if (!fontChar) {
continue; continue;
} }
this.toFontChar[charCode] = fontChar; this.toFontChar[charCode] = fontChar;
} }
for (charCode in properties.differences) { for (charCode in properties.differences) {
fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]]; fontChar = glyphsUnicodeMap[properties.differences[charCode]];
if (!fontChar) { if (!fontChar) {
continue; continue;
} }
@ -2627,18 +2629,20 @@ var Font = (function FontClosure() {
} }
} else if (isStandardFont) { } else if (isStandardFont) {
this.toFontChar = []; this.toFontChar = [];
glyphsUnicodeMap = getGlyphsUnicode();
for (charCode in properties.defaultEncoding) { for (charCode in properties.defaultEncoding) {
glyphName = (properties.differences[charCode] || glyphName = (properties.differences[charCode] ||
properties.defaultEncoding[charCode]); properties.defaultEncoding[charCode]);
this.toFontChar[charCode] = GlyphsUnicode[glyphName]; this.toFontChar[charCode] = glyphsUnicodeMap[glyphName];
} }
} else { } else {
var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1); var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
glyphsUnicodeMap = getGlyphsUnicode();
this.toUnicode.forEach(function(charCode, unicodeCharCode) { this.toUnicode.forEach(function(charCode, unicodeCharCode) {
if (notCidFont) { if (notCidFont) {
glyphName = (properties.differences[charCode] || glyphName = (properties.differences[charCode] ||
properties.defaultEncoding[charCode]); properties.defaultEncoding[charCode]);
unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode); unicodeCharCode = (glyphsUnicodeMap[glyphName] || unicodeCharCode);
} }
this.toFontChar[charCode] = unicodeCharCode; this.toFontChar[charCode] = unicodeCharCode;
}.bind(this)); }.bind(this));
@ -4331,6 +4335,7 @@ var Font = (function FontClosure() {
properties.baseEncodingName === 'WinAnsiEncoding') { properties.baseEncodingName === 'WinAnsiEncoding') {
baseEncoding = Encodings[properties.baseEncodingName]; baseEncoding = Encodings[properties.baseEncodingName];
} }
var glyphsUnicodeMap = getGlyphsUnicode();
for (charCode = 0; charCode < 256; charCode++) { for (charCode = 0; charCode < 256; charCode++) {
var glyphName; var glyphName;
if (this.differences && charCode in this.differences) { if (this.differences && charCode in this.differences) {
@ -4346,7 +4351,7 @@ var Font = (function FontClosure() {
} }
var unicodeOrCharCode, isUnicode = false; var unicodeOrCharCode, isUnicode = false;
if (cmapPlatformId === 3 && cmapEncodingId === 1) { if (cmapPlatformId === 3 && cmapEncodingId === 1) {
unicodeOrCharCode = GlyphsUnicode[glyphName]; unicodeOrCharCode = glyphsUnicodeMap[glyphName];
isUnicode = true; isUnicode = true;
} else if (cmapPlatformId === 1 && cmapEncodingId === 0) { } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
// TODO: the encoding needs to be updated with mac os table. // TODO: the encoding needs to be updated with mac os table.
@ -4652,6 +4657,7 @@ var Font = (function FontClosure() {
for (charcode in differences) { for (charcode in differences) {
encoding[charcode] = differences[charcode]; encoding[charcode] = differences[charcode];
} }
var glyphsUnicodeMap = getGlyphsUnicode();
for (charcode in encoding) { for (charcode in encoding) {
// a) Map the character code to a character name. // a) Map the character code to a character name.
var glyphName = encoding[charcode]; var glyphName = encoding[charcode];
@ -4659,7 +4665,7 @@ var Font = (function FontClosure() {
// Bibliography) to obtain the corresponding Unicode value. // Bibliography) to obtain the corresponding Unicode value.
if (glyphName === '') { if (glyphName === '') {
continue; continue;
} else if (GlyphsUnicode[glyphName] === undefined) { } else if (glyphsUnicodeMap[glyphName] === undefined) {
// (undocumented) c) Few heuristics to recognize unknown glyphs // (undocumented) c) Few heuristics to recognize unknown glyphs
// NOTE: Adobe Reader does not do this step, but OSX Preview does // NOTE: Adobe Reader does not do this step, but OSX Preview does
var code = 0; var code = 0;
@ -4690,7 +4696,7 @@ var Font = (function FontClosure() {
var baseEncoding = Encodings[baseEncodingName]; var baseEncoding = Encodings[baseEncodingName];
if (baseEncoding && (glyphName = baseEncoding[charcode])) { if (baseEncoding && (glyphName = baseEncoding[charcode])) {
toUnicode[charcode] = toUnicode[charcode] =
String.fromCharCode(GlyphsUnicode[glyphName]); String.fromCharCode(glyphsUnicodeMap[glyphName]);
continue; continue;
} }
} }
@ -4698,7 +4704,8 @@ var Font = (function FontClosure() {
} }
continue; continue;
} }
toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]); toUnicode[charcode] =
String.fromCharCode(glyphsUnicodeMap[glyphName]);
} }
return new ToUnicodeMap(toUnicode); return new ToUnicodeMap(toUnicode);
} }
@ -4766,7 +4773,8 @@ var Font = (function FontClosure() {
width = this.widths[glyphName]; width = this.widths[glyphName];
break; break;
} }
var glyphUnicode = GlyphsUnicode[glyphName]; var glyphsUnicodeMap = getGlyphsUnicode();
var glyphUnicode = glyphsUnicodeMap[glyphName];
// finding the charcode via unicodeToCID map // finding the charcode via unicodeToCID map
var charcode = 0; var charcode = 0;
if (this.composite) { if (this.composite) {

File diff suppressed because it is too large Load Diff

View File

@ -347,6 +347,18 @@ function shadow(obj, prop, value) {
} }
PDFJS.shadow = shadow; PDFJS.shadow = shadow;
function getLookupTableFactory(initializer) {
var lookup;
return function () {
if (initializer) {
lookup = Object.create(null);
initializer(lookup);
initializer = null;
}
return lookup;
};
}
var LinkTarget = PDFJS.LinkTarget = { var LinkTarget = PDFJS.LinkTarget = {
NONE: 0, // Default value. NONE: 0, // Default value.
SELF: 1, SELF: 1,
@ -2338,6 +2350,7 @@ exports.combineUrl = combineUrl;
exports.createPromiseCapability = createPromiseCapability; exports.createPromiseCapability = createPromiseCapability;
exports.deprecated = deprecated; exports.deprecated = deprecated;
exports.error = error; exports.error = error;
exports.getLookupTableFactory = getLookupTableFactory;
exports.info = info; exports.info = info;
exports.isArray = isArray; exports.isArray = isArray;
exports.isArrayBuffer = isArrayBuffer; exports.isArrayBuffer = isArrayBuffer;