PDFFieldText.java
9.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.forms;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCatalog;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosUtils;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFRectangle;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationWidget;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFDefaultAppearance;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFField;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFFieldNode;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFFieldUtils;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFInteractiveForm;
import com.adobe.internal.pdftoolkit.pdf.page.PDFPage;
import com.adobe.internal.pdftoolkit.pdf.utils.PDFUtil;
public class PDFFieldText
extends PDFField {
public static final int kMultiline = 4096;
public static final int kPassword = 8192;
public static final int kFileSelect = 1048576;
public static final int kDoNotSpellCheck = 4194304;
public static final int kDoNotScroll = 8388608;
public static final int kComb = 16777216;
public static final int kRichText = 33554432;
private static final String DEFAULT_TEXTFIELD_NAME = "Text";
protected PDFFieldText(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public static PDFFieldText getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFFieldText pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFFieldText.class);
if (pdfObject == null) {
pdfObject = new PDFFieldText(cosObject);
}
return pdfObject;
}
public static PDFFieldText newInstance(String qualifiedFieldName, PDFPage page, PDFRectangle annotRect, PDFDefaultAppearance da, boolean combineFieldAnnot) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (page == null) {
throw new PDFInvalidParameterException("A page must be provided for the annotation when creating fields.");
}
if (annotRect == null) {
throw new PDFInvalidParameterException("An annotation rectangle must be specified when creating fields.");
}
CosDictionary cosObject = PDFCosObject.newCosDictionary(page.getPDFDocument());
PDFFieldText field = new PDFFieldText((CosObject)cosObject);
PDFInteractiveForm iform = page.getPDFDocument().requireCatalog().procureInteractiveForm();
PDFFieldNode parent = iform.procureIntermediateFieldNodes(qualifiedFieldName);
String fieldName = PDFFieldUtils.getTerminalFieldName(qualifiedFieldName);
field.init(parent, fieldName, page, annotRect, combineFieldAnnot, da);
return field;
}
public static PDFFieldText newInstance(PDFFieldNode parent, PDFPage page, PDFRectangle annotRect, PDFDefaultAppearance da, boolean combineFieldAnnot) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (parent == null) {
throw new PDFInvalidParameterException("A parent field node must be specified when creating fields.");
}
if (page == null) {
throw new PDFInvalidParameterException("A page must be provided for the annotation when creating fields.");
}
if (annotRect == null) {
throw new PDFInvalidParameterException("An annotation rectangle must be specified when creating fields.");
}
CosDictionary cosObject = PDFCosObject.newCosDictionary(page.getPDFDocument());
PDFFieldText field = new PDFFieldText((CosObject)cosObject);
field.init(parent, null, page, annotRect, combineFieldAnnot, da);
return field;
}
private void init(PDFFieldNode parent, String fieldName, PDFPage page, PDFRectangle annotRect, boolean combineFieldAnnot, PDFDefaultAppearance da) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
this.init(parent, fieldName, "Text", da, false);
this.initWidgetAnnot(page, annotRect, combineFieldAnnot);
this.setDictionaryNameValue(ASName.k_FT, ASName.k_Tx);
}
public boolean hasMaxLen() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject cosValue = PDFCosUtils.getInheritableValue(ASName.k_MaxLen, ASName.k_Parent, this);
return cosValue != null;
}
public int getMaxLen() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject cosValue = PDFCosUtils.getInheritableValue(ASName.k_MaxLen, ASName.k_Parent, this);
if (cosValue == null || cosValue.getType() != 1) {
return 0;
}
Number maxLen = cosValue.numberValue();
return maxLen == null ? 0 : maxLen.intValue();
}
public void setMaxLen(int value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_MaxLen, value);
}
public boolean getMultiline() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return (this.getFlags() & 4096) != 0;
}
public void setMultiline(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (value) {
this.setFlags(this.getFlags() | 4096);
} else {
this.setFlags(this.getFlags() & -4097);
}
}
public boolean getFileSelect() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return (this.getFlags() & 1048576) != 0;
}
public void setFileSelect(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (value) {
int flg = this.getFlags();
this.setFlags(flg |= 1048576);
} else {
int flags = this.getFlags();
int mask = -1048577;
this.setFlags(flags &= mask);
}
}
public boolean getDoNotScroll() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return (this.getFlags() & 8388608) != 0;
}
public boolean getDoNotSpellCheck() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return (this.getFlags() & 4194304) != 0;
}
public boolean isComb() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.hasMaxLen() && (this.getFlags() & 4096) == 0 && (this.getFlags() & 8192) == 0 && (this.getFlags() & 1048576) == 0) {
return (this.getFlags() & 16777216) != 0;
}
return false;
}
public void setComb(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (value) {
this.setFlags(this.getFlags() | 16777216);
} else {
this.setFlags(this.getFlags() & -16777217);
}
}
public boolean isPassword() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return (this.getFlags() & 8192) != 0;
}
public void setPassword(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (value) {
int flg = this.getFlags();
this.setFlags(flg |= 8192);
} else {
int flags = this.getFlags();
int mask = -8193;
this.setFlags(flags &= mask);
}
}
public void setdoNotScroll(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (value) {
this.setFlags(this.getFlags() | 8388608);
} else {
this.setFlags(this.getFlags() & -8388609);
}
}
public void setdoNotSpellCheck(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (value) {
this.setFlags(this.getFlags() | 4194304);
} else {
this.setFlags(this.getFlags() & -4194305);
}
}
public boolean isRichText() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return (this.getFlags() & 33554432) != 0;
}
public void setRichText(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (value) {
this.setFlags(this.getFlags() | 33554432);
} else {
this.setFlags(this.getFlags() & -33554433);
}
}
public String getRichTextForValue() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFUtil.makeRichTextFromString(this.getDictionaryTextStringOrStreamValue(ASName.k_V));
}
}