PDF417TextCompactor.java
7.38 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.pmp.adobepdf417pmp;
import com.adobe.xfa.pmp.adobepdf417pmp.PDF417SpecialCode;
import java.util.ArrayList;
import java.util.List;
class PDF417TextCompactor {
static final String alphaSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
static final String lowerSet = "abcdefghijklmnopqrstuvwxyz ";
static final String mixedSet = "0123456789&\r\t,:#-.$/+%*=^ ";
static final String punctuationSet = ";<>@[\\]_`~!\r\t,:\n-.$/\"|*()?{}'";
PDF417TextCompactor() {
}
static void compact(List<Character> message, List<Integer> compactedMessage) {
ArrayList<Integer> data = new ArrayList<Integer>();
SetType subMode = SetType.ALPHA;
String pCurrentSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
int idx = 0;
block6 : for (idx = 0; idx < message.size(); ++idx) {
char c = message.get(idx).charValue();
int index = pCurrentSet.indexOf(c);
if (index >= 0) {
if (subMode == SetType.MIXED && index == 25) {
index = 26;
}
data.add(index);
continue;
}
SubModeAndIndex subModeAndIndex = PDF417TextCompactor.getSubModeAndIndex(c);
if (subModeAndIndex == null) {
throw new IllegalArgumentException("SubMode and index information can't be found");
}
SetType newSubMode = subModeAndIndex.subMode;
index = subModeAndIndex.index;
List<Integer> subModeSwitch = PDF417TextCompactor.getSubModeSwitch(subMode, newSubMode);
int jdx = 0;
for (jdx = 0; jdx < subModeSwitch.size(); ++jdx) {
int v = subModeSwitch.get(jdx);
data.add(v);
}
data.add(index);
subMode = newSubMode;
switch (subMode) {
case ALPHA: {
pCurrentSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
continue block6;
}
case LOWER: {
pCurrentSet = "abcdefghijklmnopqrstuvwxyz ";
continue block6;
}
case MIXED: {
pCurrentSet = "0123456789&\r\t,:#-.$/+%*=^ ";
continue block6;
}
case PUNCTUATION: {
pCurrentSet = ";<>@[\\]_`~!\r\t,:\n-.$/\"|*()?{}'";
}
}
}
if (data.size() % 2 != 0) {
data.add(29);
}
compactedMessage.add(PDF417SpecialCode.TextCompactionLatch.getValue());
for (idx = 0; idx < data.size(); idx += 2) {
int H = (Integer)data.get(idx);
int L = (Integer)data.get(idx + 1);
int codeWord = 30 * H + L;
compactedMessage.add(codeWord);
}
}
static SubModeAndIndex getSubModeAndIndex(char c) {
SubModeAndIndex subModeAndIndex = new SubModeAndIndex();
int index = "abcdefghijklmnopqrstuvwxyz ".indexOf(c);
if (index >= 0) {
subModeAndIndex.index = index;
subModeAndIndex.subMode = SetType.LOWER;
return subModeAndIndex;
}
index = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ".indexOf(c);
if (index >= 0) {
subModeAndIndex.index = index;
subModeAndIndex.subMode = SetType.ALPHA;
return subModeAndIndex;
}
index = "0123456789&\r\t,:#-.$/+%*=^ ".indexOf(c);
if (index >= 0) {
if (index == 25) {
index = 26;
}
subModeAndIndex.index = index;
subModeAndIndex.subMode = SetType.MIXED;
return subModeAndIndex;
}
index = ";<>@[\\]_`~!\r\t,:\n-.$/\"|*()?{}'".indexOf(c);
if (index >= 0) {
subModeAndIndex.index = index;
subModeAndIndex.subMode = SetType.PUNCTUATION;
return subModeAndIndex;
}
return null;
}
static List<Integer> getSubModeSwitch(SetType subMode, SetType newSubMode) {
ArrayList<Integer> sunModeSwitch = new ArrayList<Integer>();
block0 : switch (subMode) {
case ALPHA: {
switch (newSubMode) {
case ALPHA: {
break block0;
}
case LOWER: {
sunModeSwitch.add(27);
break block0;
}
case MIXED: {
sunModeSwitch.add(28);
break block0;
}
case PUNCTUATION: {
sunModeSwitch.add(28);
sunModeSwitch.add(25);
}
}
break;
}
case LOWER: {
switch (newSubMode) {
case ALPHA: {
sunModeSwitch.add(28);
sunModeSwitch.add(28);
break block0;
}
case LOWER: {
break block0;
}
case MIXED: {
sunModeSwitch.add(28);
break block0;
}
case PUNCTUATION: {
sunModeSwitch.add(28);
sunModeSwitch.add(25);
}
}
break;
}
case MIXED: {
switch (newSubMode) {
case ALPHA: {
sunModeSwitch.add(28);
break block0;
}
case LOWER: {
sunModeSwitch.add(27);
break block0;
}
case MIXED: {
break block0;
}
case PUNCTUATION: {
sunModeSwitch.add(25);
}
}
break;
}
case PUNCTUATION: {
switch (newSubMode) {
case ALPHA: {
sunModeSwitch.add(29);
break block0;
}
case LOWER: {
sunModeSwitch.add(29);
sunModeSwitch.add(27);
break block0;
}
case MIXED: {
sunModeSwitch.add(29);
sunModeSwitch.add(28);
break block0;
}
}
}
}
return sunModeSwitch;
}
static boolean canHandle(char value) {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ ".indexOf(value) >= 0 || "abcdefghijklmnopqrstuvwxyz ".indexOf(value) >= 0 || "0123456789&\r\t,:#-.$/+%*=^ ".indexOf(value) >= 0 || ";<>@[\\]_`~!\r\t,:\n-.$/\"|*()?{}'".indexOf(value) >= 0;
}
static class SubModeAndIndex {
SetType subMode;
int index;
SubModeAndIndex() {
}
}
static enum SetType {
ALPHA(0),
LOWER(1),
MIXED(2),
PUNCTUATION(3);
private int value;
private SetType(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
}