Merge pull request #3391 from brendandahl/font-cache
Cache fonts by reference.
This commit is contained in:
commit
07fb66dcb4
@ -48,7 +48,6 @@ var Page = (function PageClosure() {
|
|||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
this.idCounters = {
|
this.idCounters = {
|
||||||
font: 0,
|
|
||||||
obj: 0
|
obj: 0
|
||||||
};
|
};
|
||||||
this.resourcesPromise = null;
|
this.resourcesPromise = null;
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
IDENTITY_MATRIX, info, isArray, isCmd, isDict, isEOF, isName, isNum,
|
IDENTITY_MATRIX, info, isArray, isCmd, isDict, isEOF, isName, isNum,
|
||||||
isStream, isString, JpegStream, Lexer, Metrics, Name, Parser,
|
isStream, isString, JpegStream, Lexer, Metrics, Name, Parser,
|
||||||
Pattern, PDFImage, PDFJS, serifFonts, stdFontMap, symbolsFonts,
|
Pattern, PDFImage, PDFJS, serifFonts, stdFontMap, symbolsFonts,
|
||||||
TilingPattern, TODO, warn, Util, MissingDataException, Promise */
|
TilingPattern, TODO, warn, Util, MissingDataException, Promise,
|
||||||
|
RefSetCache, isRef */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
this.pageIndex = pageIndex;
|
this.pageIndex = pageIndex;
|
||||||
this.uniquePrefix = uniquePrefix;
|
this.uniquePrefix = uniquePrefix;
|
||||||
this.idCounters = idCounters;
|
this.idCounters = idCounters;
|
||||||
|
this.fontCache = new RefSetCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specifies properties for each command
|
// Specifies properties for each command
|
||||||
@ -502,38 +504,45 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
|
loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
|
||||||
resources) {
|
resources) {
|
||||||
var promise = new Promise();
|
function errorFont(promise) {
|
||||||
|
|
||||||
var fontRes = resources.get('Font');
|
|
||||||
if (!fontRes) {
|
|
||||||
warn('fontRes not available');
|
|
||||||
}
|
|
||||||
|
|
||||||
font = xref.fetchIfRef(font) || (fontRes && fontRes.get(fontName));
|
|
||||||
if (!isDict(font)) {
|
|
||||||
++this.idCounters.font;
|
|
||||||
promise.resolve({
|
promise.resolve({
|
||||||
font: {
|
font: {
|
||||||
translated: new ErrorFont('Font ' + fontName + ' is not available'),
|
translated: new ErrorFont('Font ' + fontName + ' is not available'),
|
||||||
loadedName: 'g_font_' + this.uniquePrefix + this.idCounters.obj
|
loadedName: 'g_font_error'
|
||||||
},
|
},
|
||||||
dependencies: {}
|
dependencies: {}
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (font.loaded) {
|
var fontRef;
|
||||||
promise.resolve({
|
if (font) { // Loading by ref.
|
||||||
font: font,
|
assert(isRef(font));
|
||||||
dependencies: {}
|
fontRef = font;
|
||||||
});
|
} else { // Loading by name.
|
||||||
return promise;
|
var fontRes = resources.get('Font');
|
||||||
|
if (fontRes) {
|
||||||
|
fontRef = fontRes.getRaw(fontName);
|
||||||
|
} else {
|
||||||
|
warn('fontRes not available');
|
||||||
|
return errorFont(new Promise());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.fontCache.has(fontRef)) {
|
||||||
|
return this.fontCache.get(fontRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
var promise = new Promise();
|
||||||
|
this.fontCache.put(fontRef, promise);
|
||||||
|
|
||||||
|
font = xref.fetchIfRef(fontRef);
|
||||||
|
if (!isDict(font)) {
|
||||||
|
return errorFont(promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep track of each font we translated so the caller can
|
// keep track of each font we translated so the caller can
|
||||||
// load them asynchronously before calling display on a page
|
// load them asynchronously before calling display on a page
|
||||||
font.loadedName = 'g_font_' + this.uniquePrefix +
|
font.loadedName = 'g_font_' + fontRef.num + '_' + fontRef.gen;
|
||||||
(++this.idCounters.font);
|
|
||||||
|
|
||||||
if (!font.translated) {
|
if (!font.translated) {
|
||||||
var translated;
|
var translated;
|
||||||
|
22
src/obj.js
22
src/obj.js
@ -187,6 +187,28 @@ var RefSet = (function RefSetClosure() {
|
|||||||
return RefSet;
|
return RefSet;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
var RefSetCache = (function RefSetCacheClosure() {
|
||||||
|
function RefSetCache() {
|
||||||
|
this.dict = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
RefSetCache.prototype = {
|
||||||
|
get: function RefSetCache_get(ref) {
|
||||||
|
return this.dict['R' + ref.num + '.' + ref.gen];
|
||||||
|
},
|
||||||
|
|
||||||
|
has: function RefSetCache_has(ref) {
|
||||||
|
return ('R' + ref.num + '.' + ref.gen) in this.dict;
|
||||||
|
},
|
||||||
|
|
||||||
|
put: function RefSetCache_put(ref, obj) {
|
||||||
|
this.dict['R' + ref.num + '.' + ref.gen] = obj;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return RefSetCache;
|
||||||
|
})();
|
||||||
|
|
||||||
var Catalog = (function CatalogClosure() {
|
var Catalog = (function CatalogClosure() {
|
||||||
function Catalog(pdfManager, xref) {
|
function Catalog(pdfManager, xref) {
|
||||||
this.pdfManager = pdfManager;
|
this.pdfManager = pdfManager;
|
||||||
|
2
test/pdfs/issue2984.pdf.link
Normal file
2
test/pdfs/issue2984.pdf.link
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
http://computation.llnl.gov/casc/sapphire/pubs/denoising.pdf
|
||||||
|
|
@ -1088,6 +1088,15 @@
|
|||||||
"type": "eq",
|
"type": "eq",
|
||||||
"about": "Has a 4 bit per component image with mask and decode."
|
"about": "Has a 4 bit per component image with mask and decode."
|
||||||
},
|
},
|
||||||
|
{ "id": "issue2984",
|
||||||
|
"file": "pdfs/issue2984.pdf",
|
||||||
|
"md5": "d41d8cd98f00b204e9800998ecf8427e",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq",
|
||||||
|
"lastPage": 1,
|
||||||
|
"about": "Type3 fonts with lots of switching between them."
|
||||||
|
},
|
||||||
{ "id": "bug808084",
|
{ "id": "bug808084",
|
||||||
"file": "pdfs/bug808084.pdf",
|
"file": "pdfs/bug808084.pdf",
|
||||||
"md5": "b1c400de699af29ea3f1983bb26870ab",
|
"md5": "b1c400de699af29ea3f1983bb26870ab",
|
||||||
|
Loading…
Reference in New Issue
Block a user