PDFFont.java
12.4 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.fontengine.font.Font
* com.adobe.fontengine.font.FontData
* com.adobe.fontengine.font.FontImpl
* com.adobe.fontengine.font.FontLoadingException
* com.adobe.fontengine.font.InvalidFontException
* com.adobe.fontengine.font.Rect
* com.adobe.fontengine.font.UnsupportedFontException
* com.adobe.fontengine.fontmanagement.FontLoader
* com.adobe.fontengine.fontmanagement.postscript.PostscriptFontDescription
* com.adobe.internal.io.stream.InputByteStream
* 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.CosOpenOptions
* com.adobe.internal.pdftoolkit.core.cos.CosStream
* com.adobe.internal.pdftoolkit.core.exceptions.PDFException
* 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.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.fontset.PDFFontSet
* com.adobe.internal.pdftoolkit.core.fontset.impl.PDFFontSetImpl
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASRectangle
*/
package com.adobe.internal.pdftoolkit.pdf.graphics.font;
import com.adobe.fontengine.font.Font;
import com.adobe.fontengine.font.FontData;
import com.adobe.fontengine.font.FontImpl;
import com.adobe.fontengine.font.FontLoadingException;
import com.adobe.fontengine.font.InvalidFontException;
import com.adobe.fontengine.font.Rect;
import com.adobe.fontengine.font.UnsupportedFontException;
import com.adobe.fontengine.fontmanagement.FontLoader;
import com.adobe.fontengine.fontmanagement.postscript.PostscriptFontDescription;
import com.adobe.internal.io.stream.InputByteStream;
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.CosOpenOptions;
import com.adobe.internal.pdftoolkit.core.cos.CosStream;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFException;
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.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.fontset.PDFFontSet;
import com.adobe.internal.pdftoolkit.core.fontset.impl.PDFFontSetImpl;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASRectangle;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.PDFCIDFont;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.PDFFontDescriptor;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.PDFFontFile;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.PDFFontType0;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.PDFFontType3;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.PDFToUnicodeCMap;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.PDFWritingMode;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.impl.PDFCMapUtils;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.impl.PDFFontUtils;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;
public abstract class PDFFont
extends PDFCosDictionary {
private Font afeFont = null;
private PDFFontSet mFontSet;
protected PDFFont(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public PDFFont(PDFDocument pdfDoc) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super((CosObject)PDFFont.newCosDictionary(pdfDoc));
this.setDictionaryNameValue(ASName.k_Type, ASName.k_Font);
}
public PDFFont(PDFDocument pdfDoc, Font afeFont) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super((CosObject)PDFFont.newCosDictionary(pdfDoc));
this.setDictionaryNameValue(ASName.k_Type, ASName.k_Font);
this.afeFont = afeFont;
}
public String toString() {
try {
return this.getBaseFont().asString(true);
}
catch (PDFException e) {
return "";
}
}
public ASName getSubtype() throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException {
return this.getDictionaryNameValue(ASName.k_Subtype);
}
public FontData getAFEFontData() throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException {
try {
if (this.afeFont == null) {
this.getAFEFont();
}
if (this.afeFont != null) {
return ((FontImpl)this.afeFont).getFontData();
}
}
catch (InvalidFontException e) {
throw new PDFIOException((Throwable)e);
}
catch (UnsupportedFontException e) {
throw new PDFIOException((Throwable)e);
}
catch (FontLoadingException e) {
throw new PDFIOException((Throwable)e);
}
return null;
}
protected static ASRectangle getRectangleCoords(Rect bbox) {
if (bbox != null) {
double x_left = bbox.xmin;
double y_bottom = bbox.ymin;
double x_right = bbox.xmax;
double y_top = bbox.ymax;
return new ASRectangle(x_left, y_bottom, x_right, y_top);
}
return new ASRectangle(0.0, 0.0, 0.0, 0.0);
}
public ASName getBaseFont() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getCosDictionary().getName(ASName.k_BaseFont);
}
private boolean hasBaseFont() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getCosDictionary().containsKey((Object)ASName.k_BaseFont);
}
public void setBaseFont(ASName baseFont) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_BaseFont, baseFont);
}
public ASName getName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getCosDictionary().getName(ASName.k_Name);
}
public abstract PDFWritingMode getWritingMode() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException;
public abstract double getGlyphWidth(byte[] var1) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException;
public abstract double getGlyphHeight(byte[] var1) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException;
public abstract double getGlyphDisplacement(int var1) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException;
public abstract double getAscent() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException;
public abstract double getDescent() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException;
public abstract ASRectangle getBBox() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException;
public abstract char[] getUnicode(long var1) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException;
public abstract byte[] getSpaceCharCode() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException;
public abstract List getCharCodes(byte[] var1, boolean var2) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException;
public PDFToUnicodeCMap getToUnicodeCMap() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject cosObj = this.getCosDictionary().get(ASName.k_ToUnicode);
if (cosObj != null) {
return PDFToUnicodeCMap.getInstance(cosObj);
}
return null;
}
public void setToUnicodeCMap(PDFToUnicodeCMap unicodeCMap) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (unicodeCMap == null) {
this.removeValue(ASName.k_ToUnicode);
} else {
this.setDictionaryStreamValue(ASName.k_ToUnicode, unicodeCMap.getCosStream());
}
}
public void resetAFEFont() {
this.afeFont = null;
}
public Font getAFEFont() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, FontLoadingException {
return this.getAFEFont(false);
}
public Font getAFEFont(boolean substitute) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, FontLoadingException {
Font font = this.afeFont;
if (font == null) {
PDFFontFile pdfFontFile = PDFFontUtils.getFontFileFromFontDescriptor(PDFFontUtils.getPDFFontDescriptor(this));
if (pdfFontFile != null) {
InputByteStream fontByteStream = null;
InputStream fontStream = null;
try {
fontByteStream = pdfFontFile.getStream();
fontStream = fontByteStream.toInputStream();
long fontStreamLength = fontByteStream.length();
font = new FontLoader().load(fontStream, (int)fontStreamLength, true);
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
finally {
if (fontByteStream != null) {
try {
fontByteStream.close();
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
}
if (fontStream != null) {
try {
fontStream.close();
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
}
}
}
if (!(this instanceof PDFFontType3)) {
try {
String psName = null;
if (this instanceof PDFFontType0) {
psName = ((PDFFontType0)this).getDescendantFont().getBaseFont().asString(true);
} else if (this.hasBaseFont()) {
psName = this.getBaseFont().asString(true);
}
if (psName != null) {
PDFFontSetImpl fontSet = this.mFontSet != null ? (PDFFontSetImpl)this.mFontSet : (PDFFontSetImpl)this.getPDFDocument().getCosDocument().getOptions().getFontSet();
if (fontSet != null) {
Locale docLocale = this.getPDFDocument().getCosDocument().getOptions().getDocLocale();
font = fontSet.getPSFont(new PostscriptFontDescription(psName), docLocale, substitute);
}
}
}
catch (PDFFontException e) {
throw new PDFIOException((Throwable)e);
}
}
this.afeFont = font;
}
return font;
}
public abstract int charCode2gid(int var1) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFFontException;
public abstract PDFFontDescriptor getFontDescriptor() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException;
public void setFontSet(PDFFontSet fontSet) {
this.mFontSet = fontSet;
}
public boolean applyHeuristicsToGetSpaceCharWidth() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!PDFFontUtils.isSubsetFont(this)) {
return false;
}
try {
byte[] bytes = this.getSpaceCharCode();
int charCode = (int)PDFCMapUtils.getCharCode(bytes);
long gid = this.charCode2gid(charCode);
if (gid < 1) {
return true;
}
}
catch (Exception e) {
// empty catch block
}
return false;
}
}