[Form] Don't use field appearances when /NeedAppearances is set to true (bug 1796741)
When a form isn't changed, we used the appearances we had in the file, but when /NeedAppearances is true, all the appearances have to be regenerated whatever they're.
This commit is contained in:
parent
22225a1eaa
commit
9f95a14e91
@ -126,6 +126,8 @@ class AnnotationFactory {
|
||||
let subtype = dict.get("Subtype");
|
||||
subtype = subtype instanceof Name ? subtype.name : null;
|
||||
|
||||
const acroFormDict = acroForm instanceof Dict ? acroForm : Dict.empty;
|
||||
|
||||
// Return the right annotation object based on the subtype and field type.
|
||||
const parameters = {
|
||||
xref,
|
||||
@ -134,10 +136,12 @@ class AnnotationFactory {
|
||||
subtype,
|
||||
id,
|
||||
pdfManager,
|
||||
acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
|
||||
acroForm: acroFormDict,
|
||||
attachments,
|
||||
xfaDatasets,
|
||||
collectFields,
|
||||
needAppearances:
|
||||
!collectFields && acroFormDict.get("NeedAppearances") === true,
|
||||
pageIndex,
|
||||
};
|
||||
|
||||
@ -508,6 +512,7 @@ class Annotation {
|
||||
}
|
||||
|
||||
this._fallbackFontDict = null;
|
||||
this._needAppearances = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1483,6 +1488,7 @@ class WidgetAnnotation extends Annotation {
|
||||
const dict = params.dict;
|
||||
const data = this.data;
|
||||
this.ref = params.ref;
|
||||
this._needAppearances = params.needAppearances;
|
||||
|
||||
data.annotationType = AnnotationType.WIDGET;
|
||||
if (data.fieldName === undefined) {
|
||||
@ -1535,6 +1541,12 @@ class WidgetAnnotation extends Annotation {
|
||||
this._defaultAppearance
|
||||
);
|
||||
|
||||
data.hasAppearance =
|
||||
(this._needAppearances &&
|
||||
data.fieldValue !== undefined &&
|
||||
data.fieldValue !== null) ||
|
||||
data.hasAppearance;
|
||||
|
||||
const fieldType = getInheritableProperty({ dict, key: "FT" });
|
||||
data.fieldType = fieldType instanceof Name ? fieldType.name : null;
|
||||
|
||||
@ -1909,18 +1921,25 @@ class WidgetAnnotation extends Annotation {
|
||||
rotation = storageEntry.rotation;
|
||||
}
|
||||
|
||||
if (rotation === undefined && value === undefined) {
|
||||
if (
|
||||
rotation === undefined &&
|
||||
value === undefined &&
|
||||
!this._needAppearances
|
||||
) {
|
||||
if (!this._hasValueFromXFA || this.appearance) {
|
||||
// The annotation hasn't been rendered so use the appearance.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Empty or it has a trailing whitespace.
|
||||
const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
|
||||
|
||||
if (value === undefined) {
|
||||
// The annotation has its value in XFA datasets but not in the V field.
|
||||
value = this.data.fieldValue;
|
||||
if (!value) {
|
||||
return "";
|
||||
return `/Tx BMC q ${colors}Q EMC`;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1934,7 +1953,7 @@ class WidgetAnnotation extends Annotation {
|
||||
|
||||
if (value === "") {
|
||||
// the field is empty: nothing to render
|
||||
return "";
|
||||
return `/Tx BMC q ${colors}Q EMC`;
|
||||
}
|
||||
|
||||
if (rotation === undefined) {
|
||||
@ -2024,9 +2043,6 @@ class WidgetAnnotation extends Annotation {
|
||||
);
|
||||
}
|
||||
|
||||
// Empty or it has a trailing whitespace.
|
||||
const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
|
||||
|
||||
if (alignment === 0 || alignment > 2) {
|
||||
// Left alignment: nothing to do
|
||||
return (
|
||||
@ -3020,18 +3036,21 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
||||
return super._getAppearance(evaluator, task, annotationStorage);
|
||||
}
|
||||
|
||||
if (!annotationStorage) {
|
||||
return null;
|
||||
let exportedValue, rotation;
|
||||
const storageEntry = annotationStorage
|
||||
? annotationStorage.get(this.data.id)
|
||||
: undefined;
|
||||
|
||||
if (storageEntry) {
|
||||
rotation = storageEntry.rotation;
|
||||
exportedValue = storageEntry.value;
|
||||
}
|
||||
|
||||
const storageEntry = annotationStorage.get(this.data.id);
|
||||
if (!storageEntry) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const rotation = storageEntry.rotation;
|
||||
let exportedValue = storageEntry.value;
|
||||
if (rotation === undefined && exportedValue === undefined) {
|
||||
if (
|
||||
rotation === undefined &&
|
||||
exportedValue === undefined &&
|
||||
!this._needAppearances
|
||||
) {
|
||||
// The annotation hasn't been rendered so use the appearance
|
||||
return null;
|
||||
}
|
||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -548,3 +548,4 @@
|
||||
!issue15340.pdf
|
||||
!bug1795263.pdf
|
||||
!issue15597.pdf
|
||||
!bug1796741.pdf
|
||||
|
BIN
test/pdfs/bug1796741.pdf
Executable file
BIN
test/pdfs/bug1796741.pdf
Executable file
Binary file not shown.
@ -6960,5 +6960,12 @@
|
||||
"md5": "af708acbb22c6c9d268240dcf4a39809",
|
||||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "bug1796741-print",
|
||||
"file": "pdfs/bug1796741.pdf",
|
||||
"md5": "d5167d1b0d1b840c9aa258b98ce4fa62",
|
||||
"rounds": 1,
|
||||
"type": "eq",
|
||||
"print": true
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user