Compare commits

..

No commits in common. "e06b32c8318026e0c72d478c79e7a94bc8fee524" and "5da507f279b535e44254d05976c2a8ce881f4380" have entirely different histories.

6 changed files with 65 additions and 33 deletions

View File

@ -3488,8 +3488,8 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
// always make the field value an array with zero, one or multiple items.
if (typeof this.data.fieldValue === "string") {
this.data.fieldValue = [this.data.fieldValue];
} else {
this.data.fieldValue ||= [];
} else if (!this.data.fieldValue) {
this.data.fieldValue = [];
}
} else {
// The specs say that we should have an indices array only with

View File

@ -998,7 +998,9 @@ class Catalog {
warn(`Bad value, for key "${key}", in ViewerPreferences: ${value}.`);
continue;
}
prefs ??= Object.create(null);
if (!prefs) {
prefs = Object.create(null);
}
prefs[key] = prefValue;
}
return shadow(this, "viewerPreferences", prefs);
@ -1040,7 +1042,9 @@ class Catalog {
const nameTree = new NameTree(obj.getRaw("EmbeddedFiles"), this.xref);
for (const [key, value] of nameTree.getAll()) {
const fs = new FileSpec(value, this.xref);
attachments ??= Object.create(null);
if (!attachments) {
attachments = Object.create(null);
}
attachments[stringToPDFString(key)] = fs.serializable;
}
}
@ -1054,7 +1058,9 @@ class Catalog {
if (obj instanceof Dict && obj.has("XFAImages")) {
const nameTree = new NameTree(obj.getRaw("XFAImages"), this.xref);
for (const [key, value] of nameTree.getAll()) {
xfaImages ??= new Dict(this.xref);
if (!xfaImages) {
xfaImages = new Dict(this.xref);
}
xfaImages.set(stringToPDFString(key), value);
}
}

View File

@ -1532,7 +1532,9 @@ class PDFDocument {
warn(`Bad value, for custom key "${key}", in Info: ${value}.`);
continue;
}
docInfo.Custom ??= Object.create(null);
if (!docInfo.Custom) {
docInfo.Custom = Object.create(null);
}
docInfo.Custom[key] = customValue;
continue;
}

View File

@ -91,7 +91,9 @@ class XFAParser extends XMLParserBase {
}
} else if (name.startsWith("xmlns:")) {
const prefix = name.substring("xmlns:".length);
prefixes ??= [];
if (!prefixes) {
prefixes = [];
}
prefixes.push({ prefix, value });
} else {
const i = name.indexOf(":");
@ -100,7 +102,10 @@ class XFAParser extends XMLParserBase {
} else {
// Attributes can have their own namespace.
// For example in data, we can have <foo xfa:dataNode="dataGroup"/>
const nsAttrs = (attributeObj[$nsAttributes] ??= Object.create(null));
let nsAttrs = attributeObj[$nsAttributes];
if (!nsAttrs) {
nsAttrs = attributeObj[$nsAttributes] = Object.create(null);
}
const [ns, attrName] = [name.slice(0, i), name.slice(i + 1)];
const attrs = (nsAttrs[ns] ||= Object.create(null));
attrs[attrName] = value;

View File

@ -2462,7 +2462,9 @@ class ExclGroup extends XFAObject {
setAccess(this, attributes.class);
this[$extra] ||= Object.create(null);
if (!this[$extra]) {
this[$extra] = Object.create(null);
}
Object.assign(this[$extra], {
children,
@ -2951,7 +2953,9 @@ class Field extends XFAObject {
}
}
ui.attributes.style ||= Object.create(null);
if (!ui.attributes.style) {
ui.attributes.style = Object.create(null);
}
let aElement = null;
@ -3044,7 +3048,9 @@ class Field extends XFAObject {
caption.attributes.class[0] = "xfaCaptionForCheckButton";
}
ui.attributes.class ||= [];
if (!ui.attributes.class) {
ui.attributes.class = [];
}
ui.children.splice(0, 0, caption);
@ -4061,9 +4067,11 @@ class PageArea extends XFAObject {
}
[$getNextPage]() {
this[$extra] ||= {
numberOfUse: 0,
};
if (!this[$extra]) {
this[$extra] = {
numberOfUse: 0,
};
}
const parent = this[$getParent]();
if (parent.relation === "orderedOccurrence") {
@ -4082,9 +4090,11 @@ class PageArea extends XFAObject {
[$toHTML]() {
// TODO: incomplete.
this[$extra] ||= {
numberOfUse: 1,
};
if (!this[$extra]) {
this[$extra] = {
numberOfUse: 1,
};
}
const children = [];
this[$extra].children = children;
@ -4176,11 +4186,13 @@ class PageSet extends XFAObject {
}
[$getNextPage]() {
this[$extra] ||= {
numberOfUse: 1,
pageIndex: -1,
pageSetIndex: -1,
};
if (!this[$extra]) {
this[$extra] = {
numberOfUse: 1,
pageIndex: -1,
pageSetIndex: -1,
};
}
if (this.relation === "orderedOccurrence") {
if (this[$extra].pageIndex + 1 < this.pageArea.children.length) {
@ -5055,7 +5067,9 @@ class Subform extends XFAObject {
setAccess(this, attributes.class);
this[$extra] ||= Object.create(null);
if (!this[$extra]) {
this[$extra] = Object.create(null);
}
Object.assign(this[$extra], {
children,
@ -5481,7 +5495,9 @@ class Template extends XFAObject {
}
}
pageArea ||= pageAreas[0];
if (!pageArea) {
pageArea = pageAreas[0];
}
pageArea[$extra] = {
numberOfUse: 1,

View File

@ -202,15 +202,18 @@ class App extends PDFObject {
}
get constants() {
return (this._constants ??= Object.freeze({
align: Object.freeze({
left: 0,
center: 1,
right: 2,
top: 3,
bottom: 4,
}),
}));
if (!this._constants) {
this._constants = Object.freeze({
align: Object.freeze({
left: 0,
center: 1,
right: 2,
top: 3,
bottom: 4,
}),
});
}
return this._constants;
}
set constants(_) {