1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

XFA -- Load fonts permanently from the pdf

- Different fonts can be used in xfa and some of them are embedded in the pdf.
  - Load all the fonts in window.document.

Update src/core/document.js

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>

Update src/core/worker.js

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>
This commit is contained in:
Calixte Denizet 2021-03-26 09:28:18 +01:00
parent 6cf3070008
commit 7e9579045f
8 changed files with 318 additions and 21 deletions

View file

@ -42,6 +42,7 @@ import {
isName,
isRef,
isStream,
Name,
Ref,
} from "./primitives.js";
import {
@ -49,6 +50,7 @@ import {
getInheritableProperty,
isWhiteSpace,
MissingDataException,
validateCSSFont,
XRefEntryException,
XRefParseException,
} from "./core_utils.js";
@ -854,6 +856,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,