Move the fetchBuiltInCMap
method to the PartialEvaluator.prototype
Defining this *inline* in the "constructor" looks slightly weird (I really don't know why I wrote it like that originally), and it can simply be changed to a regular method instead.
This commit is contained in:
parent
c1cb9ee9fc
commit
f0708717a9
@ -116,34 +116,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
this.pdfFunctionFactory = pdfFunctionFactory;
|
this.pdfFunctionFactory = pdfFunctionFactory;
|
||||||
this.parsingType3Font = false;
|
this.parsingType3Font = false;
|
||||||
|
|
||||||
this.fetchBuiltInCMap = async name => {
|
this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
|
||||||
if (this.builtInCMapCache.has(name)) {
|
|
||||||
return this.builtInCMapCache.get(name);
|
|
||||||
}
|
|
||||||
const readableStream = this.handler.sendWithStream("FetchBuiltInCMap", {
|
|
||||||
name,
|
|
||||||
});
|
|
||||||
const reader = readableStream.getReader();
|
|
||||||
|
|
||||||
const data = await new Promise(function (resolve, reject) {
|
|
||||||
function pump() {
|
|
||||||
reader.read().then(function ({ value, done }) {
|
|
||||||
if (done) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(value);
|
|
||||||
pump();
|
|
||||||
}, reject);
|
|
||||||
}
|
|
||||||
pump();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (data.compressionType !== CMapCompressionType.NONE) {
|
|
||||||
// Given the size of uncompressed CMaps, only cache compressed ones.
|
|
||||||
this.builtInCMapCache.set(name, data);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trying to minimize Date.now() usage and check every 100 time
|
// Trying to minimize Date.now() usage and check every 100 time
|
||||||
@ -375,6 +348,36 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async fetchBuiltInCMap(name) {
|
||||||
|
const cachedData = this.builtInCMapCache.get(name);
|
||||||
|
if (cachedData) {
|
||||||
|
return cachedData;
|
||||||
|
}
|
||||||
|
const readableStream = this.handler.sendWithStream("FetchBuiltInCMap", {
|
||||||
|
name,
|
||||||
|
});
|
||||||
|
const reader = readableStream.getReader();
|
||||||
|
|
||||||
|
const data = await new Promise(function (resolve, reject) {
|
||||||
|
function pump() {
|
||||||
|
reader.read().then(function ({ value, done }) {
|
||||||
|
if (done) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(value);
|
||||||
|
pump();
|
||||||
|
}, reject);
|
||||||
|
}
|
||||||
|
pump();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data.compressionType !== CMapCompressionType.NONE) {
|
||||||
|
// Given the size of uncompressed CMaps, only cache compressed ones.
|
||||||
|
this.builtInCMapCache.set(name, data);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
async buildFormXObject(
|
async buildFormXObject(
|
||||||
resources,
|
resources,
|
||||||
xobj,
|
xobj,
|
||||||
@ -2691,7 +2694,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
// from the ASN Web site; see the Bibliography).
|
// from the ASN Web site; see the Bibliography).
|
||||||
return CMapFactory.create({
|
return CMapFactory.create({
|
||||||
encoding: ucs2CMapName,
|
encoding: ucs2CMapName,
|
||||||
fetchBuiltInCMap: this.fetchBuiltInCMap,
|
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
|
||||||
useCMap: null,
|
useCMap: null,
|
||||||
}).then(function (ucs2CMap) {
|
}).then(function (ucs2CMap) {
|
||||||
const cMap = properties.cMap;
|
const cMap = properties.cMap;
|
||||||
@ -2724,7 +2727,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (isName(cmapObj)) {
|
if (isName(cmapObj)) {
|
||||||
return CMapFactory.create({
|
return CMapFactory.create({
|
||||||
encoding: cmapObj,
|
encoding: cmapObj,
|
||||||
fetchBuiltInCMap: this.fetchBuiltInCMap,
|
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
|
||||||
useCMap: null,
|
useCMap: null,
|
||||||
}).then(function (cmap) {
|
}).then(function (cmap) {
|
||||||
if (cmap instanceof IdentityCMap) {
|
if (cmap instanceof IdentityCMap) {
|
||||||
@ -2735,7 +2738,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
} else if (isStream(cmapObj)) {
|
} else if (isStream(cmapObj)) {
|
||||||
return CMapFactory.create({
|
return CMapFactory.create({
|
||||||
encoding: cmapObj,
|
encoding: cmapObj,
|
||||||
fetchBuiltInCMap: this.fetchBuiltInCMap,
|
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
|
||||||
useCMap: null,
|
useCMap: null,
|
||||||
}).then(
|
}).then(
|
||||||
function (cmap) {
|
function (cmap) {
|
||||||
@ -3230,7 +3233,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
cMapPromise = CMapFactory.create({
|
cMapPromise = CMapFactory.create({
|
||||||
encoding: cidEncoding,
|
encoding: cidEncoding,
|
||||||
fetchBuiltInCMap: this.fetchBuiltInCMap,
|
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
|
||||||
useCMap: null,
|
useCMap: null,
|
||||||
}).then(function (cMap) {
|
}).then(function (cMap) {
|
||||||
properties.cMap = cMap;
|
properties.cMap = cMap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user