This commit is contained in:
Johannes Zillmann 2021-02-20 19:36:43 +01:00
parent 2d14de5167
commit 71fb6a23ff
2 changed files with 11 additions and 10 deletions

View File

@ -67,20 +67,20 @@ export default class PdfParser {
}
private gatherFontObjects(pages: ParsedPage[]): Promise<Map<string, object>> {
let result = Promise.resolve(new Map<string, object>());
const uniqueFontIds = new Set<string>();
pages.forEach((page) => {
const unknownPageFonts: string[] = [];
page.items.forEach((item) => {
return pages.reduce((promise, page) => {
const unknownPageFonts = page.items.reduce((unknowns: string[], item) => {
const fontId = item.data['fontName'];
if (!uniqueFontIds.has(fontId) && fontId.startsWith('g_d')) {
uniqueFontIds.add(fontId);
unknownPageFonts.push(fontId);
unknowns.push(fontId);
}
});
return unknowns;
}, []);
if (unknownPageFonts.length > 0) {
// console.log(`Fetch fonts ${unknownPageFonts} for page ${page.index}`);
result = result.then((fontMap) => {
promise = promise.then((fontMap) => {
return page.pdfjsPage.getOperatorList().then(() => {
unknownPageFonts.forEach((fontId) => {
const fontObject = page.pdfjsPage.commonObjs.get(fontId);
@ -90,8 +90,9 @@ export default class PdfParser {
});
});
}
});
return result;
return promise;
}, Promise.resolve(new Map<string, object>()));
}
private documentInitParameters(src: string | Uint8Array | object): object {

View File

@ -66,7 +66,7 @@ export default class CalculateStatistics extends ItemTransformer {
const mostUsedDistance = parseInt(getMostUsedKey(distanceToOccurrence));
const fontIdToName: string[] = [];
const fontToType = new Map();
const fontToType = new Map<string, FontType>();
context.fontMap.forEach(function (value, key) {
const fontName = value['name'];
fontIdToName.push(`${key} = ${fontName}`);