CharSetEncoding.java
4.56 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.graphics.font.encodings;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.graphics.font.encodings.Encoding;
public abstract class CharSetEncoding
implements Encoding {
private ASName name;
private char[] toUnicodeMap;
private String[] toGlyphNameMap;
private short[] charIdsWithGlyphNamesSortedMap;
private short[] charIdsWithUnicodeSortedMap;
static final String NOTDEF = ".notdef";
protected CharSetEncoding(ASName name, char[] toUnicodeMap) {
this.name = name;
this.toUnicodeMap = toUnicodeMap;
}
protected CharSetEncoding(ASName name, char[] toUnicodeMap, String[] toGlyphNameMap) {
this(name, toUnicodeMap);
this.toGlyphNameMap = toGlyphNameMap;
}
protected CharSetEncoding(ASName name, char[] toUnicodeMap, String[] toGlyphNameMap, short[] charIdsWithGlyphNamesSortedMap, short[] charIdsWithUnicodeSortedMap) {
this(name, toUnicodeMap, toGlyphNameMap);
this.charIdsWithGlyphNamesSortedMap = charIdsWithGlyphNamesSortedMap;
this.charIdsWithUnicodeSortedMap = charIdsWithUnicodeSortedMap;
}
public ASName getName() {
return this.name;
}
public String toUnicode(ASString string) {
byte[] bytes = string.getBytes();
return this.toUnicode(bytes, 0, bytes.length);
}
public String toUnicode(byte[] bytes, int start, int length) {
if (length > 0 && bytes != null) {
StringBuilder strBuf = new StringBuilder(bytes.length);
for (int index = start; index < length; ++index) {
strBuf.append(this.toUnicode(bytes[index]));
}
return strBuf.toString();
}
return null;
}
public char[] toUnicode(byte charCode) {
char[] unicodeChars = new char[1];
int index = charCode & 255;
unicodeChars[0] = this.toUnicodeMap[index];
return unicodeChars;
}
public char[] toUnicode(byte charCode, ASName fontName) {
return this.toUnicode(charCode);
}
public int fromUnicode(char unicodeChar) {
if (this.charIdsWithUnicodeSortedMap == null) {
for (int i = 0; i < this.toUnicodeMap.length; ++i) {
if (this.toUnicodeMap[i] != unicodeChar) continue;
return i;
}
return 0;
}
int lowerLimit = 0;
int upperLimit = this.charIdsWithUnicodeSortedMap.length - 1;
int lastFoundIndex = 0;
while (lowerLimit <= upperLimit) {
int mid = (lowerLimit + upperLimit) / 2;
if (this.toUnicodeMap[this.charIdsWithUnicodeSortedMap[mid]] == unicodeChar) {
lastFoundIndex = this.charIdsWithUnicodeSortedMap[mid];
upperLimit = mid - 1;
continue;
}
if (this.toUnicodeMap[this.charIdsWithUnicodeSortedMap[mid]] > unicodeChar) {
upperLimit = mid - 1;
continue;
}
lowerLimit = mid + 1;
}
return lastFoundIndex;
}
public int fromGlyphName(String glyphName) {
if (this.charIdsWithGlyphNamesSortedMap == null) {
for (int i = 0; i < this.toGlyphNameMap.length; ++i) {
if (!glyphName.equals(this.toGlyphNameMap[i])) continue;
return i;
}
return 0;
}
int lowerLimit = 0;
int upperLimit = this.charIdsWithGlyphNamesSortedMap.length - 1;
int lastFoundIndex = 0;
while (lowerLimit <= upperLimit) {
int mid = (lowerLimit + upperLimit) / 2;
if (this.toGlyphNameMap[this.charIdsWithGlyphNamesSortedMap[mid]].equals(glyphName)) {
lastFoundIndex = this.charIdsWithGlyphNamesSortedMap[mid];
upperLimit = mid - 1;
continue;
}
if (this.toGlyphNameMap[this.charIdsWithGlyphNamesSortedMap[mid]].compareTo(glyphName) > 0) {
upperLimit = mid - 1;
continue;
}
lowerLimit = mid + 1;
}
return lastFoundIndex;
}
public String getGlyphName(int charCode) {
if (charCode >= this.toGlyphNameMap.length || charCode < 0) {
return null;
}
return this.toGlyphNameMap[charCode];
}
}