PDFAnnotationLine.java
17.2 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* 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.ASCoordinate
* com.adobe.internal.pdftoolkit.core.types.ASMatrix
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.annotation;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
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.ASCoordinate;
import com.adobe.internal.pdftoolkit.core.types.ASMatrix;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFRectangle;
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.PDFAnnotationWithIntent;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFLineIntentValue;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFMeasure;
import java.util.ArrayList;
import java.util.List;
public class PDFAnnotationLine
extends PDFAnnotationMarkup
implements PDFAnnotationWithIntent {
private PDFAnnotationLine(CosObject cosObject) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super(cosObject);
}
public static PDFAnnotationLine getInstance(CosObject cosObject) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFAnnotationLine pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFAnnotationLine.class);
if (pdfObject == null) {
pdfObject = new PDFAnnotationLine(cosObject);
}
return pdfObject;
}
private PDFAnnotationLine(PDFDocument pdfDoc) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super(pdfDoc);
this.setSubtype(ASName.k_Line);
}
public static PDFAnnotationLine newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return new PDFAnnotationLine(pdfDocument);
}
public static PDFAnnotationLine newInstance(PDFDocument pdfDocument, List coords) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (coords == null) {
throw new PDFInvalidParameterException("Line Co-ordinates cann't be null");
}
PDFAnnotationLine pdfObject = PDFAnnotationLine.newInstance(pdfDocument);
pdfObject.setLineCoords(coords);
return pdfObject;
}
public double[] getInteriorColor() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFAnnotationUtils.getInteriorColor(this);
}
public void setInteriorColor(double[] color) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFAnnotationUtils.setInteriorColor(color, this);
}
public boolean hasLineCoords() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_L);
}
public double[] getLineCoords() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosLineCoords = this.getDictionaryArrayValue(ASName.k_L);
if (cosLineCoords == null) {
return null;
}
return cosLineCoords.getArrayDouble();
}
public void setLineCoords(List coords) throws PDFInvalidParameterException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryArrayValue(ASName.k_L, coords);
}
private void transformLineCoords(ASMatrix matrix) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (this.hasLineCoords()) {
double[] lineCoords = this.getLineCoords();
ArrayList<Double> newLineCoords = new ArrayList<Double>(lineCoords.length);
for (int i = 0; i < lineCoords.length; i += 2) {
ASCoordinate point = new ASCoordinate(lineCoords[i], lineCoords[i + 1]);
ASCoordinate newPoint = point.transform(matrix);
Double x = new Double(newPoint.x());
Double y = new Double(newPoint.y());
newLineCoords.add(i, x);
newLineCoords.add(i + 1, y);
}
this.setLineCoords(newLineCoords);
}
}
public void setLineCoords(double x1, double y1, double x2, double y2) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = PDFCosObject.newCosArray(this.getPDFDocument());
cosArray.addDouble(x1);
cosArray.addDouble(y1);
cosArray.addDouble(x2);
cosArray.addDouble(y2);
this.setDictionaryArrayValue(ASName.k_L, cosArray);
}
public boolean hasLineEnds() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_LE);
}
public boolean hasLeaderLineExtend() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_LLE);
}
public boolean hasLeaderLine() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_LL);
}
public double getLeaderLineExtend() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
Number value = this.getDictionaryNumericValue(ASName.k_LLE);
if (value == null) {
return 0.0;
}
return value.doubleValue();
}
public double getLeaderLength() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
Number value = this.getDictionaryNumericValue(ASName.k_LL);
if (value == null) {
return 0.0;
}
return value.doubleValue();
}
public void setLeaderLineExtend(double lineExtend) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryDoubleValue(ASName.k_LLE, lineExtend);
}
public void setLeaderLength(double leaderLength) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryDoubleValue(ASName.k_LL, leaderLength);
}
public boolean hasCaption() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Cap);
}
public boolean hasLeaderLineOffset() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.K_LLO);
}
public boolean hasCaptionStyle() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_CSTYLE);
}
public boolean hasMeasure() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_MEASURE);
}
public boolean hasCaptionOffset() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_COFF);
}
public boolean getCaption() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryBooleanValue(ASName.k_Cap);
}
public double getLeaderLineOffset() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
Number value = this.getDictionaryNumericValue(ASName.K_LLO);
if (value == null) {
return 0.0;
}
return value.doubleValue();
}
public String getCaptionStyle() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValueAsString(ASName.k_CSTYLE);
}
public PDFMeasure getMeasure() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFMeasure.getInstance((CosObject)this.getDictionaryDictionaryValue(ASName.k_MEASURE));
}
public double[] getCaptionOffset() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = this.getDictionaryArrayValue(ASName.k_COFF);
double[] captionOffset = new double[]{cosArray.getDouble(0), cosArray.getDouble(1)};
return captionOffset;
}
public void setLeaderLineOffset(double llo) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryDoubleValue(ASName.K_LLO, (long)llo);
}
public void setCaptionStyle(String cs) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_CSTYLE, ASName.create((String)cs));
}
public void setMeasure(PDFMeasure measure) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_MEASURE, measure);
}
public void setCaptionOffset(double[] co) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = PDFCosObject.newCosArray(this.getPDFDocument());
cosArray.addDouble(co[0]);
cosArray.addDouble(co[1]);
this.setDictionaryArrayValue(ASName.k_COFF, cosArray);
}
public LineEnding[] getLineEnds() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = this.getDictionaryArrayValue(ASName.k_LE);
if (cosArray == null) {
return new LineEnding[]{LineEnding.None, LineEnding.None};
}
LineEnding[] lineEndings = new LineEnding[]{LineEnding.getInstance(cosArray.getName(0)), LineEnding.getInstance(cosArray.getName(1))};
return lineEndings;
}
public void setLineEnds(LineEnding[] lineEndings) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = PDFCosObject.newCosArray(this.getPDFDocument());
cosArray.addName(lineEndings[0].getValue());
cosArray.addName(lineEndings[1].getValue());
this.setDictionaryArrayValue(ASName.k_LE, cosArray);
}
public void setCaption(String caption) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(ASName.k_Cap, "yes".equals(caption));
}
public void setCaption(boolean caption) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(ASName.k_Cap, caption);
}
public void transform(ASMatrix matrix, double rotationAngle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
this.transformLineCoords(matrix);
this.transformRect(matrix);
this.transformAppearances(matrix, rotationAngle);
}
protected boolean isIntentTypeValid(String intentType) {
return PDFLineIntentValue.getInstance(intentType) != null;
}
public void setCP(CaptionPosition captionPosition) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (captionPosition == null) {
this.removeValue(ASName.k_CP);
} else {
this.setDictionaryStringValue(ASName.k_CP, captionPosition.toString());
}
}
public CaptionPosition getCP() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASString captionPosition = this.getDictionaryStringValue(ASName.k_CP);
if (captionPosition == null) {
return CaptionPosition.Inline;
}
return CaptionPosition.getInstance(captionPosition.asString());
}
public void applyRotation(PDFRectangle cropBox, int rotationAngle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (rotationAngle == 0) {
rotationAngle = this.getRotation();
}
double height = cropBox.height();
double width = cropBox.width();
double[] transformedRect = null;
double[] transformedCords = null;
double[] transformedPopupRect = null;
PDFAnnotationPopup popup = this.getPopup();
transformedRect = PDFAnnotationUtils.transfromRectangle(this.getRect().getValues(), width, height, rotationAngle);
transformedCords = PDFAnnotationUtils.transfromRectangle(this.getLineCoords(), width, height, rotationAngle);
if (popup != null) {
transformedPopupRect = PDFAnnotationUtils.transfromRectangle(this.getPopup().getRect().getValues(), width, height, rotationAngle);
}
this.setRect(PDFRectangle.newInstance(this.getPDFDocument(), transformedRect[0], transformedRect[1], transformedRect[2], transformedRect[3]));
this.setLineCoords(transformedCords[0], transformedCords[1], transformedCords[2], transformedCords[3]);
if (popup != null) {
this.getPopup().setRect(PDFRectangle.newInstance(this.getPDFDocument(), transformedPopupRect[0], transformedPopupRect[1], transformedPopupRect[2], transformedPopupRect[3]));
}
}
public static final class LineEnding {
private final ASName value;
public static final LineEnding Square = new LineEnding(ASName.create((String)"Square"));
public static final LineEnding Circle = new LineEnding(ASName.create((String)"Circle"));
public static final LineEnding Diamond = new LineEnding(ASName.create((String)"Diamond"));
public static final LineEnding OpenArrow = new LineEnding(ASName.create((String)"OpenArrow"));
public static final LineEnding ClosedArrow = new LineEnding(ASName.create((String)"ClosedArrow"));
public static final LineEnding None = new LineEnding(ASName.create((String)"None"));
public static final LineEnding Butt = new LineEnding(ASName.create((String)"Butt"));
public static final LineEnding ROpenArrow = new LineEnding(ASName.create((String)"ROpenArrow"));
public static final LineEnding RClosedArrow = new LineEnding(ASName.create((String)"RClosedArrow"));
public static final LineEnding Slash = new LineEnding(ASName.create((String)"Slash"));
private LineEnding(ASName value) {
this.value = value;
}
ASName getValue() {
return this.value;
}
public String toString() {
return this.value.asString(true);
}
public static LineEnding getInstance(String lineEnding) {
return LineEnding.getInstance(ASName.create((String)lineEnding));
}
private static LineEnding getInstance(ASName value) {
if (value == Square.getValue()) {
return Square;
}
if (value == Circle.getValue()) {
return Circle;
}
if (value == Diamond.getValue()) {
return Diamond;
}
if (value == OpenArrow.getValue()) {
return OpenArrow;
}
if (value == ClosedArrow.getValue()) {
return ClosedArrow;
}
if (value == None.getValue()) {
return None;
}
if (value == Butt.getValue()) {
return Butt;
}
if (value == ROpenArrow.getValue()) {
return ROpenArrow;
}
if (value == RClosedArrow.getValue()) {
return RClosedArrow;
}
if (value == Slash.getValue()) {
return Slash;
}
return new LineEnding(value);
}
}
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public static enum CaptionPosition {
Inline("Inline"),
Top("Top");
private final String value;
private CaptionPosition(String value) {
this.value = value;
}
public static CaptionPosition getInstance(String value) {
return CaptionPosition.valueOf(value);
}
public String toString() {
return this.value;
}
}
}