mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-31 11:27:21 +02:00
Reduce duplication when parsing fonts in loadXfaFonts
Currently we repeat virtually the same code when calling the `PartialEvaluator.prototype.handleSetFont` method, which we can avoid by introducing an inline helper function.
This commit is contained in:
parent
2979e23f3c
commit
604153957a
@ -1292,6 +1292,23 @@ class PDFDocument {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parseFont = (fontName, fallbackFontDict, cssFontInfo) =>
|
||||||
|
partialEvaluator
|
||||||
|
.handleSetFont(
|
||||||
|
resources,
|
||||||
|
[Name.get(fontName), 1],
|
||||||
|
/* fontRef = */ null,
|
||||||
|
operatorList,
|
||||||
|
task,
|
||||||
|
initialState,
|
||||||
|
fallbackFontDict,
|
||||||
|
cssFontInfo
|
||||||
|
)
|
||||||
|
.catch(reason => {
|
||||||
|
warn(`loadXfaFonts: "${reason}".`);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
for (const [fontName, font] of fontRes) {
|
for (const [fontName, font] of fontRes) {
|
||||||
const descriptor = font.get("FontDescriptor");
|
const descriptor = font.get("FontDescriptor");
|
||||||
@ -1313,21 +1330,7 @@ class PDFDocument {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
promises.push(
|
promises.push(
|
||||||
partialEvaluator
|
parseFont(fontName, /* fallbackFontDict = */ null, cssFontInfo)
|
||||||
.handleSetFont(
|
|
||||||
resources,
|
|
||||||
[Name.get(fontName), 1],
|
|
||||||
/* fontRef = */ null,
|
|
||||||
operatorList,
|
|
||||||
task,
|
|
||||||
initialState,
|
|
||||||
/* fallbackFontDict = */ null,
|
|
||||||
/* cssFontInfo = */ cssFontInfo
|
|
||||||
)
|
|
||||||
.catch(function (reason) {
|
|
||||||
warn(`loadXfaFonts: "${reason}".`);
|
|
||||||
return null;
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1365,28 +1368,13 @@ class PDFDocument {
|
|||||||
{ name: "BoldItalic", fontWeight: 700, italicAngle: 12 },
|
{ name: "BoldItalic", fontWeight: 700, italicAngle: 12 },
|
||||||
]) {
|
]) {
|
||||||
const name = `${missing}-${fontInfo.name}`;
|
const name = `${missing}-${fontInfo.name}`;
|
||||||
const dict = getXfaFontDict(name);
|
|
||||||
|
|
||||||
promises.push(
|
promises.push(
|
||||||
partialEvaluator
|
parseFont(name, getXfaFontDict(name), {
|
||||||
.handleSetFont(
|
fontFamily: missing,
|
||||||
resources,
|
fontWeight: fontInfo.fontWeight,
|
||||||
[Name.get(name), 1],
|
italicAngle: fontInfo.italicAngle,
|
||||||
/* fontRef = */ null,
|
})
|
||||||
operatorList,
|
|
||||||
task,
|
|
||||||
initialState,
|
|
||||||
/* fallbackFontDict = */ dict,
|
|
||||||
/* cssFontInfo = */ {
|
|
||||||
fontFamily: missing,
|
|
||||||
fontWeight: fontInfo.fontWeight,
|
|
||||||
italicAngle: fontInfo.italicAngle,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.catch(function (reason) {
|
|
||||||
warn(`loadXfaFonts: "${reason}".`);
|
|
||||||
return null;
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user