PDFAnnotationFreeText.java
14.3 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* 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.ASCoordinate
* com.adobe.internal.pdftoolkit.core.types.ASMatrix
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.annotation;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
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.ASCoordinate;
import com.adobe.internal.pdftoolkit.core.types.ASMatrix;
import com.adobe.internal.pdftoolkit.core.types.ASName;
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.PDFAnnotationLine;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationMarkup;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationPopup;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationUtils;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationWithBorderEffects;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationWithFringe;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationWithIntent;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFBorderEffects;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFFreeTextIntentValue;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFDefaultAppearance;
import com.adobe.internal.pdftoolkit.pdf.interactive.forms.PDFInteractiveForm;
import com.adobe.internal.pdftoolkit.pdf.utils.PDFUtil;
import java.util.List;
public class PDFAnnotationFreeText
extends PDFAnnotationMarkup
implements PDFAnnotationWithFringe,
PDFAnnotationWithIntent,
PDFAnnotationWithBorderEffects {
private PDFAnnotationFreeText(CosObject cosObject) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super(cosObject);
}
public static PDFAnnotationFreeText newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return new PDFAnnotationFreeText(pdfDocument);
}
private PDFAnnotationFreeText(PDFDocument pdfDoc) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super(pdfDoc);
this.setSubtype(ASName.k_FreeText);
}
public static PDFAnnotationFreeText getInstance(CosObject cosObject) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFAnnotationFreeText pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFAnnotationFreeText.class);
if (pdfObject == null) {
pdfObject = new PDFAnnotationFreeText(cosObject);
}
return pdfObject;
}
public String getDefaultAppearance() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_DA);
}
public PDFDefaultAppearance getDefaultFreeTextAppearance() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject cosValue = PDFCosUtils.getInheritableValue(ASName.k_DA, ASName.k_Parent, this);
if (cosValue == null) {
PDFInteractiveForm acroForm = this.getPDFDocument().getInteractiveForm();
if (acroForm == null) {
return null;
}
cosValue = acroForm.getDictionaryCosObjectValue(ASName.k_DA);
if (cosValue == null) {
return null;
}
}
if (cosValue.getType() != 4) {
return null;
}
return PDFDefaultAppearance.getInstance(cosValue);
}
public void setDefaultAppearance(PDFDefaultAppearance pdfDefaultAppearance) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (pdfDefaultAppearance == null) {
return;
}
this.setDictionaryValue(ASName.k_DA, pdfDefaultAppearance);
}
public void setDefaultAppearance(String appearance) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_DA, appearance);
}
public boolean hasJustification() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Q);
}
public int getJustification() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
Number value = this.getDictionaryNumericValue(ASName.k_Q);
return value != null ? value.intValue() : 0;
}
public void setJustification(int justification) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_Q, justification);
}
public String getDefaultStyle() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_DS);
}
public void setDefaultStyle(String style) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(ASName.k_DS, style);
}
public double[] getCalloutLine() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosQuadPoints = this.getDictionaryArrayValue(ASName.k_CL);
if (cosQuadPoints == null) {
return null;
}
return cosQuadPoints.getArrayDouble();
}
public void setCalloutLine(double x1, double y1, double x2, double y2) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosCallout = PDFCosObject.newCosArray(this.getPDFDocument());
cosCallout.addDouble(x1);
cosCallout.addDouble(y1);
cosCallout.addDouble(x2);
cosCallout.addDouble(y2);
this.setDictionaryArrayValue(ASName.k_CL, cosCallout);
}
public void setCalloutLine(double[] callout) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (callout != null) {
if (callout.length == 4) {
this.setCalloutLine(callout[0], callout[1], callout[2], callout[3]);
} else if (callout.length == 6) {
this.setCalloutLine(callout[0], callout[1], callout[2], callout[3], callout[4], callout[5]);
}
}
}
public void setCalloutLine(String points, String separator) throws PDFInvalidDocumentException, PDFIOException, PDFInvalidParameterException, PDFSecurityException {
this.setDictionaryArrayValue(ASName.k_CL, PDFUtil.parseNumbers(points, separator));
}
public void setCalloutLine(double x1, double y1, double x2, double y2, double x3, double y3) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosCallout = PDFCosObject.newCosArray(this.getPDFDocument());
cosCallout.addDouble(x1);
cosCallout.addDouble(y1);
cosCallout.addDouble(x2);
cosCallout.addDouble(y2);
cosCallout.addDouble(x3);
cosCallout.addDouble(y3);
this.setDictionaryArrayValue(ASName.k_CL, cosCallout);
}
protected boolean isIntentTypeValid(String intentType) {
return PDFFreeTextIntentValue.getInstance(intentType) != null;
}
private void transformCalloutLine(ASMatrix matrix) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
double[] calloutLine = this.getCalloutLine();
if (calloutLine != null) {
for (int i = 0; i < calloutLine.length; i += 2) {
ASCoordinate coordinate = new ASCoordinate(calloutLine[i], calloutLine[i + 1]);
ASCoordinate newCoordinate = coordinate.transform(matrix);
calloutLine[i] = newCoordinate.x();
calloutLine[i + 1] = newCoordinate.y();
}
if (calloutLine.length == 4) {
this.setCalloutLine(calloutLine[0], calloutLine[1], calloutLine[2], calloutLine[3]);
} else if (calloutLine.length == 6) {
this.setCalloutLine(calloutLine[0], calloutLine[1], calloutLine[2], calloutLine[3], calloutLine[4], calloutLine[5]);
}
}
}
public PDFBorderEffects getBorderEffects() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFBorderEffects.getInstance(this.getDictionaryCosObjectValue(ASName.k_BE));
}
public void setBorderEffects(PDFBorderEffects borderEffects) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_BE, borderEffects);
}
public double[] getFringe() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFAnnotationWithFringe.FringeGetterSetter.getFringe(this);
}
public void setFringe(String fringe, String separator) throws PDFInvalidDocumentException, PDFIOException, PDFInvalidParameterException, PDFSecurityException {
PDFAnnotationWithFringe.FringeGetterSetter.setFringe(this, fringe, separator);
}
public void setFringe(double[] fringe) throws PDFInvalidDocumentException, PDFIOException, PDFInvalidParameterException, PDFSecurityException {
PDFAnnotationWithFringe.FringeGetterSetter.setFringe(this, fringe);
}
public boolean hasFringe() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_RD);
}
public boolean hasCallout() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_CL);
}
public boolean hasLineEnds() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_LE);
}
public ASName getLineEnds() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASName cosName = this.getDictionaryNameValue(ASName.k_LE);
return cosName != null ? cosName : ASName.k_None;
}
public void setLineEnds(PDFAnnotationLine.LineEnding[] lineEndings) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASName le = ASName.create((String)"none");
for (int i = 0; i < lineEndings.length; ++i) {
if (lineEndings[i].getValue() == null) continue;
le = lineEndings[i].getValue();
}
this.setDictionaryNameValue(ASName.k_LE, le);
}
public void transformFringe(ASMatrix matrix, double rotationAngle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
this.setFringe(PDFAnnotationUtils.transformFringe(this, matrix, rotationAngle, this.getFringe()));
}
public void transform(ASMatrix matrix, double rotationAngle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
this.transformFringe(matrix, rotationAngle);
this.transformCalloutLine(matrix);
int rotation = this.hasRotation() ? (int)Math.toDegrees((Math.toRadians(this.getRotation()) + rotationAngle) % 3.141592653589793) : (int)Math.toDegrees(rotationAngle);
this.setRotation(rotation);
this.transformRect(matrix);
this.transformAppearances(matrix, rotationAngle);
}
public PDFBorderEffects procureBorderEffects() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFBorderEffects borderEffects = this.getBorderEffects();
if (borderEffects == null) {
borderEffects = PDFBorderEffects.newInstance(this.getPDFDocument());
}
return borderEffects;
}
public void applyRotation(PDFRectangle cropBox, int rotationAngle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
double[] calloutLine;
if (rotationAngle == 0) {
rotationAngle = this.getRotation();
}
double height = cropBox.height();
double width = cropBox.width();
double[] transformedRect = null;
double[] transformedFringe = null;
double[] transformedPopupRect = null;
double[] transformedCalloutLine = null;
PDFAnnotationPopup popup = this.getPopup();
transformedRect = PDFAnnotationUtils.transfromRectangle(this.getRect().getValues(), width, height, rotationAngle);
this.setRect(PDFRectangle.newInstance(this.getPDFDocument(), transformedRect[0], transformedRect[1], transformedRect[2], transformedRect[3]).normalized(this.getPDFDocument()));
double[] fringeRectangle = this.getFringe();
if (fringeRectangle != null) {
transformedFringe = PDFAnnotationUtils.transfromRectangle(fringeRectangle, width, height, rotationAngle);
this.setFringe(transformedFringe);
}
if ((calloutLine = this.getCalloutLine()) != null) {
transformedCalloutLine = PDFAnnotationUtils.transfromRectangle(calloutLine, width, height, rotationAngle);
this.setCalloutLine(transformedCalloutLine);
}
if (popup != null) {
transformedPopupRect = PDFAnnotationUtils.transfromRectangle(this.getPopup().getRect().getValues(), width, height, rotationAngle);
this.getPopup().setRect(PDFRectangle.newInstance(this.getPDFDocument(), transformedPopupRect[0], transformedPopupRect[1], transformedPopupRect[2], transformedPopupRect[3]));
}
}
}