Skip to content

Commit 348421a

Browse files
committed
improvements
1 parent 69bccce commit 348421a

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

src/modules/acroform.js

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,18 @@ var calculateAppearanceStream = function(formObject) {
171171
return formObject.appearanceStreamContent;
172172
}
173173

174-
// fixme test what happens with AcroFormTextFieldParent if no value is set
175-
if (!formObject.V && !formObject.DV) {
176-
return;
174+
var text;
175+
if (formObject instanceof AcroFormTextFieldChild) {
176+
text = formObject.Parent._V || formObject.Parent.DV;
177+
} else {
178+
text = formObject._V || formObject.DV;
177179
}
178180

179-
// I don't think I need to do this. I need to find where conditionals are used on _V and skip those if instanceof AcroFormTextFieldParent
180-
if (formObject instanceof AcroFormTextFieldParent){
181-
var appearanceStreamContent = createFormXObject(formObject);
182-
appearanceStreamContent.scope = formObject.scope;
183-
// appearanceStreamContent.stream = stream.join("\n");
184-
return appearanceStreamContent;
181+
if (!text) {
182+
return;
185183
}
186184

187-
// else calculate it
188-
189185
var stream = [];
190-
var text = formObject._V || formObject.DV;
191186
var calcRes = calculateX(formObject, text);
192187
var fontKey = formObject.scope.internal.getFont(
193188
formObject.fontName,
@@ -597,7 +592,6 @@ var createFieldCallback = function(fieldArray, scope) {
597592
) {
598593
// Calculate Appearance
599594
var appearance = calculateAppearanceStream(fieldObject);
600-
// fixme maybe probably don't want this to happen for acroformtextparents
601595
keyValueList.push({ key: "AP", value: "<</N " + appearance + ">>" });
602596

603597
scope.internal.acroformPlugin.xForms.push(appearance);
@@ -1201,17 +1195,21 @@ var AcroFormField = function() {
12011195
configurable: false,
12021196
get: function() {
12031197
if (!_T || _T.length < 1) {
1204-
// In case of a Child from a Radio´Group, you don't need a FieldName
1205-
if (this instanceof AcroFormChildClass ||
1198+
// In case of a Child, you don't need a FieldName
1199+
if (
1200+
this instanceof AcroFormChildClass || // Radio Group Child
12061201
this instanceof AcroFormTextFieldChild
12071202
) {
12081203
return undefined;
12091204
}
1205+
12101206
_T = "FieldObject" + AcroFormField.FieldNum++;
12111207
}
1208+
12121209
var encryptor = function(data) {
12131210
return data;
12141211
};
1212+
12151213
if (this.scope) encryptor = this.scope.internal.getEncryptor(this.objId);
12161214
return "(" + pdfEscape(encryptor(_T)) + ")";
12171215
},
@@ -1348,9 +1346,7 @@ var AcroFormField = function() {
13481346
if (
13491347
!_DA ||
13501348
this instanceof AcroFormChildClass ||
1351-
this instanceof AcroFormTextField &&
1352-
!(this instanceof AcroFormTextFieldParent)
1353-
// fixme does the textfieldparent actually need a default appearance?
1349+
this instanceof AcroFormTextField
13541350
) {
13551351
return undefined;
13561352
}
@@ -1530,8 +1526,7 @@ var AcroFormField = function() {
15301526
return _hasAppearanceStream;
15311527
},
15321528
set: function(value) {
1533-
value = Boolean(value);
1534-
_hasAppearanceStream = value;
1529+
_hasAppearanceStream = Boolean(value);
15351530
}
15361531
});
15371532

@@ -2627,19 +2622,15 @@ var AcroFormTextField = function() {
26272622
enumerable: true,
26282623
configurable: true,
26292624
get: function() {
2630-
return this.V || this.DV;
2625+
return Boolean(this.V || this.DV);
26312626
}
26322627
});
26332628
};
26342629
inherit(AcroFormTextField, AcroFormField);
26352630

2636-
var AcroFormTextFieldParent = function () {
2631+
var AcroFormTextFieldParent = function() {
26372632
AcroFormTextField.call(this);
2638-
// fixme try this. see if any other properties need to be nullified
2639-
// this.F = null;
2640-
// this.MK = null;
2641-
// this.Type = null;
2642-
// this.Subtype = null;
2633+
this.F = null;
26432634

26442635
var _Kids = [];
26452636
Object.defineProperty(this, "Kids", {
@@ -2656,7 +2647,15 @@ var AcroFormTextFieldParent = function () {
26562647
}
26572648
}
26582649
});
2659-
}
2650+
2651+
Object.defineProperty(this, "hasAppearanceStream", {
2652+
enumerable: true,
2653+
configurable: true,
2654+
get: function() {
2655+
return false;
2656+
}
2657+
});
2658+
};
26602659
inherit(AcroFormTextFieldParent, AcroFormTextField);
26612660

26622661
var AcroFormTextFieldChild = function() {
@@ -2674,6 +2673,13 @@ var AcroFormTextFieldChild = function() {
26742673
}
26752674
});
26762675

2676+
Object.defineProperty(this, "hasAppearanceStream", {
2677+
enumerable: true,
2678+
configurable: true,
2679+
get: function() {
2680+
return Boolean(this.Parent.V || this.Parent.DV);
2681+
}
2682+
});
26772683
};
26782684
inherit(AcroFormTextFieldChild, AcroFormTextField);
26792685

@@ -2684,8 +2690,7 @@ AcroFormTextFieldParent.prototype.createChild = function() {
26842690
addField.call(this.scope, child);
26852691

26862692
return child;
2687-
}
2688-
2693+
};
26892694

26902695
/**
26912696
* @class AcroFormPasswordField

0 commit comments

Comments
 (0)