PDFFontFile.java
8.63 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.fontengine.FontEngineException
* com.adobe.fontengine.font.Font
* com.adobe.fontengine.font.PDFFontDescription
* com.adobe.internal.io.ByteWriterFactory
* com.adobe.internal.io.ByteWriterFactory$Fixed
* com.adobe.internal.io.stream.InputByteStream
* com.adobe.internal.io.stream.OutputByteStream
* com.adobe.internal.io.stream.SkippingOutputStream
* com.adobe.internal.io.stream.StreamManager
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.cos.CosStream
* com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFFontException
* 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.graphics.font;
import com.adobe.fontengine.FontEngineException;
import com.adobe.fontengine.font.Font;
import com.adobe.fontengine.font.PDFFontDescription;
import com.adobe.internal.io.ByteWriterFactory;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.io.stream.OutputByteStream;
import com.adobe.internal.io.stream.SkippingOutputStream;
import com.adobe.internal.io.stream.StreamManager;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.cos.CosStream;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFFontException;
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.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosStream;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.filters.PDFFilter;
import com.adobe.internal.pdftoolkit.pdf.filters.PDFFilterFlate;
import com.adobe.internal.pdftoolkit.pdf.filters.PDFFilterList;
import com.adobe.internal.pdftoolkit.pdf.interchange.metadata.PDFMetadata;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class PDFFontFile
extends PDFCosStream {
public static final ASName k_Type1C = ASName.create((String)"Type1C");
public static final ASName k_CIDFontType0C = ASName.create((String)"CIDFontType0C");
public static final ASName k_OpenType = ASName.create((String)"OpenType");
private PDFFontFile(CosObject cosStream) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super(cosStream);
}
public static PDFFontFile getInstance(CosObject cosObject) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFFontFile pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFFontFile.class);
if (pdfObject == null) {
pdfObject = new PDFFontFile(cosObject);
}
return pdfObject;
}
public static PDFFontFile newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosStream cosObject = PDFCosObject.newCosStream(pdfDocument);
return new PDFFontFile((CosObject)cosObject);
}
public static PDFFontFile newInstance(PDFDocument pdfDocument, InputByteStream stream) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (stream == null) {
return null;
}
PDFFontFile fontFile = PDFFontFile.newInstance(pdfDocument);
try {
fontFile.setStreamData(stream.toInputStream());
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
return fontFile;
}
public static PDFFontFile newInstance(PDFDocument pdfDoc, boolean opentypeOK, Font afeFont) throws PDFFontException, PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
try {
if (!afeFont.canEmbedForEditting()) {
return null;
}
OutputByteStream outStream = pdfDoc.getStreamManager().getOutputByteStreamClearDocument(ByteWriterFactory.Fixed.GROWABLE, -1);
afeFont.getPDFFontDescription().stream((OutputStream)outStream.toOutputStream(), opentypeOK);
InputByteStream fontFileStream = outStream.closeAndConvert();
outStream = null;
PDFFontFile fontFile = PDFFontFile.newInstance(pdfDoc, fontFileStream);
fontFileStream = null;
return fontFile;
}
catch (FontEngineException e) {
throw new PDFFontException((Throwable)e);
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
}
public void setEmbeddedFontType(EmbeddedFontType fontType) throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException, PDFInvalidParameterException {
if (fontType == null) {
super.removeValue(ASName.k_Subtype);
} else {
super.setSubtype(fontType.getName());
}
}
public EmbeddedFontType getEmbeddedFontType() throws PDFCosParseException, PDFIOException, PDFSecurityException {
return EmbeddedFontType.getInstance(super.getSubtype());
}
long getLength1() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosStream().containsKey((Object)ASName.k_Length1)) {
return this.getCosStream().getLong(ASName.k_Length1);
}
return 0;
}
long getLength2() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosStream().containsKey((Object)ASName.k_Length2)) {
return this.getCosStream().getLong(ASName.k_Length2);
}
return 0;
}
long getLength3() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosStream().containsKey((Object)ASName.k_Length3)) {
return this.getCosStream().getLong(ASName.k_Length3);
}
return 0;
}
PDFMetadata getMetaData() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosStream().containsKey((Object)ASName.k_Metadata)) {
return PDFMetadata.getInstance(this.getDictionaryCosObjectValue(ASName.k_Metadata));
}
return null;
}
public void setMetaData(CosStream metadata) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (metadata == null) {
this.getCosStream().remove(ASName.k_Metadata);
} else {
this.setDictionaryValue(ASName.k_Metadata, (CosObject)metadata);
}
}
public InputByteStream getStream() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getCosStream().getStreamDecoded();
}
public void setFilter(PDFFilterFlate filter) throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException {
PDFFilterList filterList = this.procureOutputFilters();
filterList.add(filter);
this.setOutputFilters(filterList);
}
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public static enum EmbeddedFontType {
Type1C(PDFFontFile.k_Type1C),
CIDFontType0C(PDFFontFile.k_CIDFontType0C),
OpenType(PDFFontFile.k_OpenType);
private ASName name;
private EmbeddedFontType(ASName name) {
this.name = name;
}
public static EmbeddedFontType getInstance(ASName fontType) {
if (fontType == PDFFontFile.k_Type1C) {
return Type1C;
}
if (fontType == PDFFontFile.k_CIDFontType0C) {
return CIDFontType0C;
}
if (fontType == PDFFontFile.k_OpenType) {
return OpenType;
}
return null;
}
public String toString() {
return this.name.asString();
}
public ASName getName() {
return this.name;
}
}
}