Merge pull request #13254 from Snuffleupagus/scripting-misc-fixes
A couple of small scripting/XFA-related tweaks in the worker-code
This commit is contained in:
commit
dd7f04ea2e
@ -865,7 +865,9 @@ class PDFDocument {
|
||||
|
||||
async loadXfaFonts(handler, task) {
|
||||
const acroForm = await this.pdfManager.ensureCatalog("acroForm");
|
||||
|
||||
if (!acroForm) {
|
||||
return;
|
||||
}
|
||||
const resources = await acroForm.getAsync("DR");
|
||||
if (!(resources instanceof Dict)) {
|
||||
return;
|
||||
@ -902,28 +904,34 @@ class PDFDocument {
|
||||
|
||||
for (const [fontName, font] of fonts) {
|
||||
const descriptor = font.get("FontDescriptor");
|
||||
if (descriptor instanceof Dict) {
|
||||
const fontFamily = descriptor.get("FontFamily");
|
||||
const fontWeight = descriptor.get("FontWeight");
|
||||
const italicAngle = descriptor.get("ItalicAngle");
|
||||
const cssFontInfo = { fontFamily, fontWeight, italicAngle };
|
||||
|
||||
if (!validateCSSFont(cssFontInfo)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const promise = partialEvaluator.handleSetFont(
|
||||
resources,
|
||||
[Name.get(fontName), 1],
|
||||
/* fontRef = */ null,
|
||||
operatorList,
|
||||
task,
|
||||
initialState,
|
||||
/* fallbackFontDict = */ null,
|
||||
/* cssFontInfo = */ cssFontInfo
|
||||
);
|
||||
promises.push(promise.catch(() => {}));
|
||||
if (!(descriptor instanceof Dict)) {
|
||||
continue;
|
||||
}
|
||||
const fontFamily = descriptor.get("FontFamily");
|
||||
const fontWeight = descriptor.get("FontWeight");
|
||||
const italicAngle = descriptor.get("ItalicAngle");
|
||||
const cssFontInfo = { fontFamily, fontWeight, italicAngle };
|
||||
|
||||
if (!validateCSSFont(cssFontInfo)) {
|
||||
continue;
|
||||
}
|
||||
promises.push(
|
||||
partialEvaluator
|
||||
.handleSetFont(
|
||||
resources,
|
||||
[Name.get(fontName), 1],
|
||||
/* fontRef = */ null,
|
||||
operatorList,
|
||||
task,
|
||||
initialState,
|
||||
/* fallbackFontDict = */ null,
|
||||
/* cssFontInfo = */ cssFontInfo
|
||||
)
|
||||
.catch(function (reason) {
|
||||
warn(`loadXfaFonts: "${reason}".`);
|
||||
return null;
|
||||
})
|
||||
);
|
||||
}
|
||||
await Promise.all(promises);
|
||||
}
|
||||
@ -1257,7 +1265,7 @@ class PDFDocument {
|
||||
}
|
||||
|
||||
get hasJSActions() {
|
||||
const promise = this.pdfManager.ensure(this, "_parseHasJSActions");
|
||||
const promise = this.pdfManager.ensureDoc("_parseHasJSActions");
|
||||
return shadow(this, "hasJSActions", promise);
|
||||
}
|
||||
|
||||
@ -1267,7 +1275,7 @@ class PDFDocument {
|
||||
async _parseHasJSActions() {
|
||||
const [catalogJsActions, fieldObjects] = await Promise.all([
|
||||
this.pdfManager.ensureCatalog("jsActions"),
|
||||
this.pdfManager.ensure(this, "fieldObjects"),
|
||||
this.pdfManager.ensureDoc("fieldObjects"),
|
||||
]);
|
||||
|
||||
if (catalogJsActions) {
|
||||
|
@ -2966,7 +2966,7 @@ var Font = (function FontClosure() {
|
||||
}
|
||||
|
||||
// When `cssFontInfo` is set, the font is used to render text in the HTML
|
||||
// view (e.g. with Xfa) so nothing must be moved in the private area use.
|
||||
// view (e.g. with Xfa) so nothing must be moved in the private use area.
|
||||
if (!properties.cssFontInfo) {
|
||||
// Converting glyphs and ids into font's cmap table
|
||||
var newMapping = adjustMapping(
|
||||
|
@ -195,7 +195,7 @@ class WorkerMessageHandler {
|
||||
]);
|
||||
|
||||
if (isPureXfa) {
|
||||
const task = new WorkerTask("Load fonts for Xfa");
|
||||
const task = new WorkerTask("loadXfaFonts");
|
||||
startWorkerTask(task);
|
||||
await pdfManager
|
||||
.loadXfaFonts(handler, task)
|
||||
|
@ -53,18 +53,18 @@ describe("document", function () {
|
||||
get docId() {
|
||||
return "d0";
|
||||
},
|
||||
ensureDoc(prop, args) {
|
||||
return pdfManager.ensure(pdfDocument, prop, args);
|
||||
},
|
||||
ensureCatalog(prop, args) {
|
||||
return pdfManager.ensure(catalog, prop, args);
|
||||
},
|
||||
ensure(obj, prop, args) {
|
||||
return new Promise(function (resolve) {
|
||||
const value = obj[prop];
|
||||
if (typeof value === "function") {
|
||||
resolve(value.apply(obj, args));
|
||||
} else {
|
||||
resolve(value);
|
||||
}
|
||||
});
|
||||
async ensure(obj, prop, args) {
|
||||
const value = obj[prop];
|
||||
if (typeof value === "function") {
|
||||
return value.apply(obj, args);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
};
|
||||
const pdfDocument = new PDFDocument(pdfManager, stream);
|
||||
|
Loading…
Reference in New Issue
Block a user