CMapObjectImpl.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
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.fontengine.FontEngineException
* com.adobe.internal.io.ByteReader
* com.adobe.internal.io.ByteWriterFactory
* com.adobe.internal.io.ByteWriterFactory$Fixed
* com.adobe.internal.io.InputStreamByteReader
* com.adobe.internal.io.LazyRandomAccessFileByteReader
* com.adobe.internal.io.stream.InputByteStream
* com.adobe.internal.io.stream.OutputByteStream
* com.adobe.internal.io.stream.StreamManager
* 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.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.graphics.font.impl;
import com.adobe.fontengine.FontEngineException;
import com.adobe.internal.io.ByteReader;
import com.adobe.internal.io.ByteWriterFactory;
import com.adobe.internal.io.InputStreamByteReader;
import com.adobe.internal.io.LazyRandomAccessFileByteReader;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.io.stream.OutputByteStream;
import com.adobe.internal.io.stream.StreamManager;
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.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.CMapObject;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.PDFCMap;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.impl.CMapCodesSpace;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.impl.CMapObjectCache;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.impl.CMapResourceBuilder;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.impl.CMapsUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.ObjectInputStream;
import java.io.Reader;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.MissingResourceException;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class CMapObjectImpl
implements CMapObject,
Serializable {
static final long serialVersionUID = 1;
static final String[] cidToUnicodeMapNames = new String[]{"Adobe-CNS1-UCS2", "Adobe-GB1-UCS2", "Adobe-Japan1-UCS2", "Adobe-Korea1-UCS2"};
static HashMap<Long, Integer> spaceCharMap;
static CMapResourceBuilder builder;
static CMapObject[] cidToUnicodeCMaps;
static final boolean usePrebuiltCMaps = false;
String registry;
String ordering;
int supplement;
String writingMode;
String name;
String baseName;
CMapCodesSpace[] codesSpaces;
int minBytesNeeded = 0;
int maxBytesAllowed = 0;
HashMap<Long, Integer> spaceCharCodeMap;
HashMap<Long, Integer> charCodeCIDMap = null;
HashMap<Long, int[]> charCodeCIDMapLong = null;
CMapObjectImpl(String registry2, String ordering2, int supplement2, String writingMode2, String cmapName, String useCMapName, CMapCodesSpace[] codesSpaces2, int minBytes, int maxBytes, HashMap<Long, Integer> spaceCharacterCodeToUnicodeMap, HashMap<Long, Integer> charCodeCIDMap2, HashMap<Long, int[]> charCodeToCIDMapLong2) {
this.registry = registry2;
this.ordering = ordering2;
this.supplement = supplement2;
this.writingMode = writingMode2;
this.name = cmapName;
this.baseName = useCMapName;
this.codesSpaces = codesSpaces2;
this.minBytesNeeded = minBytes;
this.maxBytesAllowed = maxBytes;
this.spaceCharCodeMap = spaceCharacterCodeToUnicodeMap;
this.charCodeCIDMap = charCodeCIDMap2;
this.charCodeCIDMapLong = charCodeToCIDMapLong2;
}
@Override
public int[] getValue(long code) {
int[] values = null;
if (this.baseName != null) {
if (code <= Integer.MAX_VALUE && !this.charCodeCIDMap.isEmpty() && this.charCodeCIDMap.containsKey(code)) {
return new int[]{this.charCodeCIDMap.get(code)};
}
if (!this.charCodeCIDMapLong.isEmpty() && this.charCodeCIDMapLong.containsKey(code)) {
return this.charCodeCIDMapLong.get(code);
}
}
for (int iCodeSpace = 0; iCodeSpace < this.codesSpaces.length; ++iCodeSpace) {
CMapCodesSpace codeSpace = this.codesSpaces[iCodeSpace];
if (!codeSpace.isCodeInCodeSpace(code)) continue;
values = codeSpace.getCodeValue(code);
}
return values;
}
@Override
public void enumerateValues(CMapObject.CMapValueConsumer consumer) throws FontEngineException {
for (int iCodeSpace = 0; iCodeSpace < this.codesSpaces.length; ++iCodeSpace) {
CMapCodesSpace codeSpace = this.codesSpaces[iCodeSpace];
codeSpace.enumerateValues(consumer);
}
}
public static synchronized CMapObject get(String cmapName) throws MissingResourceException {
CMapObject cmapObj = null;
ObjectInputStream objectInputStream = null;
try {
int i;
if (builder == null) {
builder = CMapResourceBuilder.getInstance();
spaceCharMap = new HashMap();
cidToUnicodeCMaps = new CMapObject[cidToUnicodeMapNames.length];
for (i = 0; i < cidToUnicodeMapNames.length; ++i) {
CMapObjectImpl.cidToUnicodeCMaps[i] = builder.parseCMapFile(cidToUnicodeMapNames[i], false, spaceCharMap, false);
}
}
if (cmapName.startsWith("Adobe-")) {
for (i = 0; i < cidToUnicodeMapNames.length; ++i) {
if (!cmapName.equals(cidToUnicodeMapNames[i])) continue;
CMapObject cMapObject = cidToUnicodeCMaps[i];
return cMapObject;
}
}
cmapObj = builder.parseCMapFile(cmapName, false, spaceCharMap, false);
}
catch (Exception e) {
MissingResourceException ee = new MissingResourceException("", "", "");
ee.initCause(e);
throw ee;
}
finally {
if (objectInputStream != null) {
try {
objectInputStream.close();
}
catch (IOException e) {}
}
}
return cmapObj;
}
public static synchronized CMapObject get(InputStream cmapStream, Map<String, InputStream> useCMaps) throws MissingResourceException {
CMapObject cmapObj = null;
BufferedReader lnr = null;
try {
if (builder == null) {
builder = CMapResourceBuilder.getInstance();
spaceCharMap = new HashMap();
cidToUnicodeCMaps = new CMapObject[cidToUnicodeMapNames.length];
for (int i = 0; i < cidToUnicodeMapNames.length; ++i) {
CMapObjectImpl.cidToUnicodeCMaps[i] = builder.parseCMapFile(cidToUnicodeMapNames[i], false, spaceCharMap, false);
}
}
cmapObj = builder.parseCMapFile(new LineNumberReader(new InputStreamReader(cmapStream)), useCMaps, false, spaceCharMap, false);
}
catch (Exception e) {
MissingResourceException ee = new MissingResourceException("", "", "");
ee.initCause(e);
throw ee;
}
finally {
if (cmapStream != null) {
try {
cmapStream.close();
}
catch (IOException e) {}
}
if (lnr != null) {
try {
lnr.close();
}
catch (IOException e) {}
}
}
return cmapObj;
}
@Override
public String getRegistry() {
return this.registry;
}
@Override
public String getOrdering() {
return this.ordering;
}
@Override
public int getSupplement() {
return this.supplement;
}
@Override
public String getWritingMode() {
return this.writingMode;
}
@Override
public String getName() {
return this.name;
}
@Override
public String getBaseName() {
return this.baseName;
}
public void setName(String name) {
this.name = name;
}
public void setOrdering(String ordering) {
this.ordering = ordering;
}
public void setRegistry(String registry) {
this.registry = registry;
}
public void setWritingMode(String writingMode) {
this.writingMode = writingMode;
}
@Override
public CMapCodesSpace[] getCodesSpaces() {
return this.codesSpaces;
}
@Override
public int getMaxBytesAllowed() {
return this.maxBytesAllowed;
}
@Override
public int getMinBytesNeeded() {
return this.minBytesNeeded;
}
@Override
public HashMap<Long, Integer> getSpaceCharCodeMap() {
return this.spaceCharCodeMap;
}
@Override
public boolean hasPrebuiltCMaps() {
return false;
}
@Override
public CosStream getCMapStream(CosDocument cosDoc, boolean allowUseCmapEntry) throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException {
CosStream cmapObj = cosDoc.createCosStream();
try {
cmapObj.put(ASName.k_Type, ASName.k_CMap);
cmapObj.put(ASName.k_CMapName, this.getName());
CosDictionary sysInfo = cosDoc.createDirectCosDictionary();
sysInfo.put(ASName.k_Registry, new ASString(this.getRegistry()));
sysInfo.put(ASName.k_Ordering, new ASString(this.getOrdering()));
sysInfo.put(ASName.k_Supplement, this.getSupplement());
cmapObj.put(ASName.k_CIDSystemInfo, (CosObject)sysInfo);
String wMode = this.getWritingMode();
cmapObj.put(ASName.k_WMode, "1".equals(wMode) ? 1 : 0);
String baseCMap = this.getBaseName();
if (baseCMap != null) {
if (allowUseCmapEntry) {
if ("Identity_H".equals(baseCMap)) {
cmapObj.put(ASName.k_UseCMap, ASName.k_Identity_H);
} else if ("Identity_V".equals(baseCMap)) {
cmapObj.put(ASName.k_UseCMap, ASName.k_Identity_V);
} else {
CMapObject baseCmap = PDFCMap.getCMapObjectForName(baseCMap);
cmapObj.put(ASName.k_UseCMap, (CosObject)baseCmap.getCMapStream(cosDoc, allowUseCmapEntry));
}
} else if (CMapsUtil.isPredefinedCmapPermitted(baseCMap)) {
cmapObj.put(ASName.k_UseCMap, ASName.create((String)baseCMap));
} else {
return null;
}
}
InputStreamByteReader reader = null;
if (this.hasPrebuiltCMaps()) {
File cmapfile = new File("resources/cmaps/" + this.name);
reader = new LazyRandomAccessFileByteReader(cmapfile);
} else {
OutputByteStream cmapTempStream = cosDoc.getStreamManager().getOutputByteStreamClearTemp(ByteWriterFactory.Fixed.GROWABLE, 1024);
InputByteStream cmapStream = CMapObjectCache.getInputStreamForCmap(this.getName(), cmapTempStream);
reader = new InputStreamByteReader(cmapStream.toInputStream());
}
InputByteStream data = cosDoc.getStreamManager().getInputByteStream((ByteReader)reader);
cmapObj.newDataDecoded(data);
cmapObj.put(ASName.k_Filter, ASName.k_FlateDecode);
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
return cmapObj;
}
}