1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Merge pull request #13146 from calixteman/xfa_fonts

XFA -- Load fonts permanently from the pdf
This commit is contained in:
Brendan Dahl 2021-04-16 12:55:12 -07:00 committed by GitHub
commit ac3fa1e3d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 318 additions and 21 deletions

View file

@ -41,6 +41,7 @@ import {
isName,
isRef,
isStream,
Name,
Ref,
} from "./primitives.js";
import {
@ -48,6 +49,7 @@ import {
getInheritableProperty,
isWhiteSpace,
MissingDataException,
validateCSSFont,
XRefEntryException,
XRefParseException,
} from "./core_utils.js";
@ -861,6 +863,71 @@ class PDFDocument {
return this.xfaFactory !== null;
}
async loadXfaFonts(handler, task) {
const acroForm = await this.pdfManager.ensureCatalog("acroForm");
const resources = await acroForm.getAsync("DR");
if (!(resources instanceof Dict)) {
return;
}
const objectLoader = new ObjectLoader(resources, ["Font"], this.xref);
await objectLoader.load();
const fontRes = resources.get("Font");
if (!(fontRes instanceof Dict)) {
return;
}
const partialEvaluator = new PartialEvaluator({
xref: this.xref,
handler,
pageIndex: -1,
idFactory: this._globalIdFactory,
fontCache: this.catalog.fontCache,
builtInCMapCache: this.catalog.builtInCMapCache,
});
const operatorList = new OperatorList();
const initialState = {
font: null,
clone() {
return this;
},
};
const fonts = new Map();
fontRes.forEach((fontName, font) => {
fonts.set(fontName, font);
});
const promises = [];
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(() => {}));
}
}
await Promise.all(promises);
}
get formInfo() {
const formInfo = {
hasFields: false,