PDFBorder.java
7.25 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
/*
* 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.PDFCosParseException
* 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
*/
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.PDFCosParseException;
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.pdf.document.PDFCosArrayList;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosNumeric;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObjectContainer;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFDashPattern;
import java.util.ArrayList;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class PDFBorder
extends PDFCosArrayList<PDFCosNumeric> {
private static final double defaultWidth = 1.0;
private static final double defaultHorizCornerRadius = 0.0;
private static final double defaultVertCornerRadius = 0.0;
private PDFBorder(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
@Override
protected PDFCosNumeric itemInstantiator(CosObject cosObject) throws PDFInvalidDocumentException {
return PDFCosNumeric.getInstance(cosObject);
}
public static PDFBorder getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFBorder pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFBorder.class);
if (pdfObject == null) {
pdfObject = new PDFBorder(cosObject);
}
return pdfObject;
}
public static PDFBorder newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosObject = PDFCosObject.newCosArray(pdfDocument);
PDFBorder pdfBorder = new PDFBorder((CosObject)cosObject);
pdfBorder.setHorizontalCornerRadius(0.0);
pdfBorder.setVerticalCornerRadius(0.0);
pdfBorder.setWidth(1.0);
return pdfBorder;
}
public double getWidth() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosArray() != null) {
return this.getCosArray().getDouble(2);
}
throw new PDFInvalidDocumentException("Malformed border array");
}
public void setWidth(double width) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosObj = this.getCosArray();
if (cosObj == null) {
throw new PDFInvalidDocumentException("Malformed border array");
}
this.setValueInArray(cosObj, width, 3);
}
public void setHorizontalCornerRadius(double value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosObj = this.getCosArray();
if (cosObj == null) {
throw new PDFInvalidDocumentException("Malformed border array");
}
this.setValueInArray(cosObj, value, 1);
}
public double getHorizontalCornerRadius() throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException {
if (this.getCosArray() != null) {
return this.getCosArray().getDouble(0);
}
throw new PDFInvalidDocumentException("Malformed border array");
}
public void setVerticalCornerRadius(double value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosObj = this.getCosArray();
if (cosObj == null) {
throw new PDFInvalidDocumentException("Malformed border array");
}
this.setValueInArray(cosObj, value, 2);
}
public double getVerticalCornerRadius() throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException {
if (this.getCosArray() != null) {
return this.getCosArray().getDouble(1);
}
throw new PDFInvalidDocumentException("Malformed border array");
}
public void setDashPattern(PDFDashPattern dashPattern) throws PDFInvalidParameterException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray valueArray = this.convertDashObjtoCosArray(dashPattern);
CosArray cosObj = this.getCosArray();
if (cosObj != null && valueArray != null) {
if (cosObj.size() == 4) {
cosObj.set(3, (CosObject)valueArray);
} else {
cosObj.add((CosObject)valueArray);
}
}
}
public PDFDashPattern getDashPattern() throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException, PDFInvalidParameterException {
try {
CosArray cosDashPattern = null;
if (this.getCosArray() != null && this.getCosArray().size() >= 4) {
cosDashPattern = (CosArray)this.getCosArray().get(3);
}
return this.convertCosArraytoDashObj(cosDashPattern);
}
catch (PDFInvalidParameterException e) {
throw new PDFInvalidDocumentException("The document may have an existing erroneous DashPattern set", (Throwable)e);
}
}
private CosArray convertDashObjtoCosArray(PDFDashPattern dashPattern) throws PDFSecurityException, PDFInvalidParameterException, PDFInvalidDocumentException, PDFIOException {
if (dashPattern == null) {
return null;
}
ArrayList<Object> value = new ArrayList<Object>();
value.add(dashPattern.getPattern());
value.add(dashPattern.getPhase());
return PDFBorder.makeCosArray(this.getPDFDocument(), value);
}
private PDFDashPattern convertCosArraytoDashObj(CosArray cosArray) throws PDFSecurityException, PDFInvalidParameterException, PDFInvalidDocumentException, PDFIOException {
double[] pattern = new double[]{};
int phase = 0;
if (cosArray != null) {
CosArray patternArray = (CosArray)cosArray.get(0);
pattern = patternArray.getArrayDouble();
phase = cosArray.getInt(1);
}
return new PDFDashPattern(pattern, phase);
}
private void setValueInArray(CosArray array, double value, int expectedArraySize) throws PDFCosParseException, PDFIOException, PDFSecurityException {
if (array.size() < expectedArraySize) {
array.addDouble(value);
} else {
array.setDouble(expectedArraySize - 1, value);
}
}
}