PDFXObjectForm.java
13.8 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.io.stream.InputByteStream
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* com.adobe.internal.pdftoolkit.core.cos.CosCloneMgr
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosDocument
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.cos.CosStream
* 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.ASDate
* com.adobe.internal.pdftoolkit.core.types.ASMatrix
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
package com.adobe.internal.pdftoolkit.pdf.graphics.xobject;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosCloneMgr;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosDocument;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.cos.CosStream;
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.ASDate;
import com.adobe.internal.pdftoolkit.core.types.ASMatrix;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.pdf.document.PDFContents;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.document.PDFResources;
import com.adobe.internal.pdftoolkit.pdf.document.PDFText;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFRectangle;
import com.adobe.internal.pdftoolkit.pdf.graphics.optionalcontent.PDFOCObject;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFGroupAttributes;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFReference;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFXObject;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFMeasure;
import com.adobe.internal.pdftoolkit.pdf.interactive.geospatial.PDFPointData;
import com.adobe.internal.pdftoolkit.pdf.interchange.metadata.PDFMetadata;
import com.adobe.internal.pdftoolkit.pdf.interchange.prepress.PDFOPIVersion;
import com.adobe.internal.pdftoolkit.pdf.page.PDFPagePiece;
import java.io.IOException;
import java.io.InputStream;
public class PDFXObjectForm
extends PDFXObject {
private PDFXObjectForm(CosObject cosStream) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super(cosStream);
}
public static PDFXObjectForm getInstance(CosObject cosObject) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFXObjectForm pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFXObjectForm.class);
if (pdfObject == null) {
pdfObject = new PDFXObjectForm(cosObject);
}
return pdfObject;
}
public static PDFXObjectForm newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosStream cosObject = PDFCosObject.newCosStream(pdfDocument);
PDFXObjectForm xObjForm = new PDFXObjectForm((CosObject)cosObject);
xObjForm.setDictionaryNameValue(ASName.k_Subtype, ASName.k_Form);
xObjForm.setDictionaryNameValue(ASName.k_Type, ASName.k_XObject);
xObjForm.addFlateFilter();
return xObjForm;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public static PDFXObjectForm newInstance(PDFDocument pdfDocument, PDFRectangle bbox, PDFResources pdfResources, InputByteStream contents) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFXObjectForm pdfXObjectForm;
pdfXObjectForm = PDFXObjectForm.newInstance(pdfDocument);
InputStream is = null;
try {
try {
if (contents != null) {
is = contents.toInputStream();
pdfXObjectForm.setStreamData(is);
}
}
finally {
if (is != null) {
is.close();
}
}
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
pdfXObjectForm.setBBox(bbox);
pdfXObjectForm.setResources(pdfResources);
pdfXObjectForm.addFlateFilter();
return pdfXObjectForm;
}
public int getFormType() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryIntValue(ASName.k_FormType);
}
public void setFormType(int formType) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_FormType, formType);
}
public ASName getName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_Name);
}
public void setName(ASName name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_Name, name);
}
public ASDate getLastModified() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryDateValue(ASName.k_LastModified);
}
public void setLastModified(ASDate date) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (date == null) {
this.removeValue(ASName.k_LastModified);
} else {
this.setDictionaryStringValue(ASName.k_LastModified, date.asString());
}
}
public PDFRectangle getBBox() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = this.getDictionaryArrayValue(ASName.k_BBox);
return PDFRectangle.getInstance((CosObject)cosArray);
}
public void setBBox(PDFRectangle rectangle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosCloneMgr mgr = new CosCloneMgr(this.getPDFDocument().getCosDocument());
if (rectangle == null) {
this.removeValue(ASName.k_BBox);
} else {
this.setDictionaryArrayValue(ASName.k_BBox, (CosArray)mgr.clone((CosObject)rectangle.getCosArray()));
}
}
public double[] getMatrix() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
double[] matrix = null;
CosArray cosArray = this.getDictionaryArrayValue(ASName.k_Matrix);
matrix = cosArray != null ? cosArray.getArrayDouble() : ASMatrix.createIdentityMatrix().getValues();
return matrix;
}
public void setMatrix(double[] matrix) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = null;
if (matrix != null) {
cosArray = PDFCosObject.newCosArray(this.getPDFDocument());
for (int i = 0; i < 6; ++i) {
cosArray.addDouble(i, matrix[i]);
}
}
this.setDictionaryArrayValue(ASName.k_Matrix, cosArray);
}
public PDFResources getResources() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFResources.getInstance(this.getDictionaryCosObjectValue(ASName.k_Resources));
}
public void setResources(PDFResources resources) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_Resources, resources);
}
public boolean isGroupXObject() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Group);
}
public PDFGroupAttributes getGroup() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFGroupAttributes.getInstance(this.getDictionaryCosObjectValue(ASName.k_Group));
}
public void setGroupAttributes(PDFGroupAttributes groupAttributes) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_Group, groupAttributes);
}
public boolean isReferenceXObject() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Ref);
}
public PDFReference getReference() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFReference.getInstance(this.getDictionaryCosObjectValue(ASName.k_Ref));
}
public void setReference(PDFReference reference) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_Ref, reference);
}
public PDFMetadata getMetadata() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFMetadata.getInstance(this.getDictionaryCosObjectValue(ASName.k_Metadata));
}
public void setMetadata(PDFMetadata metadata) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_Metadata, metadata);
}
public PDFPagePiece getPieceInfo() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFPagePiece.getInstance(this.getDictionaryCosObjectValue(ASName.k_PieceInfo));
}
public PDFPagePiece procurePieceInfo() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFPagePiece pieceInfo = this.getPieceInfo();
if (pieceInfo == null) {
pieceInfo = PDFPagePiece.newInstance(this.getPDFDocument());
this.setPieceInfo(pieceInfo);
}
return pieceInfo;
}
public void setPieceInfo(PDFPagePiece pieceInfo) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_PieceInfo, pieceInfo);
}
public boolean hasOPIVersion() {
return this.getCosDictionary().containsKey((Object)ASName.k_OPI);
}
public PDFOPIVersion getOPIVersion() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFOPIVersion.getInstance(this.getDictionaryCosObjectValue(ASName.k_OPI));
}
public void setOPIVersion(PDFOPIVersion opiVersion) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_OPI, opiVersion);
}
public PDFOCObject getOCObject() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFOCObject.getInstance(this.getDictionaryCosObjectValue(ASName.k_OC));
}
public void setStream(InputByteStream stream) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.getCosStream().newDataDecoded(stream);
}
public PDFContents getContents() {
try {
return PDFContents.getInstance(this.getCosObject());
}
catch (PDFInvalidDocumentException e) {
return null;
}
}
public void setContents(PDFContents pdfContents) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (pdfContents == null) {
throw new PDFInvalidDocumentException("Invalid Parameter: pdfContents is null");
}
InputByteStream contents = pdfContents.getContents();
try {
if (contents != null) {
this.setStreamData(contents.toInputStream());
}
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
finally {
try {
if (contents != null) {
contents.close();
}
}
catch (IOException e) {}
}
}
public String getMarkStyle() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryTextStringValue(ASName.k_MarkStyle);
}
public void setMarkStyle(String style) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryTextValue(ASName.k_MarkStyle, PDFText.createString(this.getPDFDocument(), style));
}
public ASName getPCM() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_PCM);
}
public void setMeasure(PDFMeasure value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_Measure, value);
}
public boolean hasMeasure() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Measure);
}
public PDFMeasure getMeasure() throws PDFInvalidParameterException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFMeasure.getInstance(this.getDictionaryCosObjectValue(ASName.k_Measure));
}
public PDFPointData getPointData() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFPointData.getInstance(this.getDictionaryCosObjectValue(ASName.k_PtData));
}
public void setPointData(PDFPointData pdfPointData) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
this.setDictionaryValue(ASName.k_PtData, pdfPointData);
}
}