DataMatrixX12Compactor.java
5.81 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.pmp.datamatrixpmp;
import com.adobe.xfa.pmp.datamatrixpmp.DataMatrixBaseCompactor;
import com.adobe.xfa.pmp.datamatrixpmp.DataMatrixInfo;
import com.adobe.xfa.pmp.datamatrixpmp.DataMatrixPadder;
import java.util.ArrayList;
import java.util.List;
class DataMatrixX12Compactor
extends DataMatrixBaseCompactor {
static final CharacterSet[] basicSet = new CharacterSet[]{new CharacterSet(13, 0), new CharacterSet(42, 1), new CharacterSet(62, 2), new CharacterSet(32, 3), new CharacterSet(48, 4), new CharacterSet(49, 5), new CharacterSet(50, 6), new CharacterSet(51, 7), new CharacterSet(52, 8), new CharacterSet(53, 9), new CharacterSet(54, 10), new CharacterSet(55, 11), new CharacterSet(56, 12), new CharacterSet(57, 13), new CharacterSet(65, 14), new CharacterSet(66, 15), new CharacterSet(67, 16), new CharacterSet(68, 17), new CharacterSet(69, 18), new CharacterSet(70, 19), new CharacterSet(71, 20), new CharacterSet(72, 21), new CharacterSet(73, 22), new CharacterSet(74, 23), new CharacterSet(75, 24), new CharacterSet(76, 25), new CharacterSet(77, 26), new CharacterSet(78, 27), new CharacterSet(79, 28), new CharacterSet(80, 29), new CharacterSet(81, 30), new CharacterSet(82, 31), new CharacterSet(83, 32), new CharacterSet(84, 33), new CharacterSet(85, 34), new CharacterSet(86, 35), new CharacterSet(87, 36), new CharacterSet(88, 37), new CharacterSet(89, 38), new CharacterSet(90, 39)};
DataMatrixX12Compactor() {
}
void compact(char[] message) {
int c40End;
int idx;
int jdx;
this.m_codeWords.clear();
this.m_valid = false;
C40Encoding[] c40Encoding = new C40Encoding[message.length];
int messageSize = message.length;
for (idx = 0; idx < messageSize; ++idx) {
int v = message[idx];
boolean found = false;
for (jdx = 0; jdx < basicSet.length && !found; ++jdx) {
if (v != DataMatrixX12Compactor.basicSet[jdx].messageValue) continue;
c40Encoding[idx] = new C40Encoding();
c40Encoding[idx].messageValue = v;
c40Encoding[idx].c40Value.add(DataMatrixX12Compactor.basicSet[jdx].codeValue);
found = true;
}
if (found) continue;
return;
}
ArrayList<Integer> textCodeWords = new ArrayList<Integer>();
for (idx = 0; idx < messageSize; ++idx) {
for (jdx = 0; jdx < c40Encoding[idx].c40Value.size(); ++jdx) {
textCodeWords.add(c40Encoding[idx].c40Value.get(jdx));
}
}
int c40Size = textCodeWords.size();
if (c40Size < 3) {
return;
}
for (c40End = messageSize - 1; c40Size % 3 != 0 && c40End > 0; --c40End) {
c40Size -= c40Encoding[c40End].c40Value.size();
}
if (++c40End > 0) {
this.m_codeWords.add(238);
}
for (idx = 0; idx < c40Size; idx += 3) {
int value16 = (Integer)textCodeWords.get(idx) * 1600 + (Integer)textCodeWords.get(idx + 1) * 40 + (Integer)textCodeWords.get(idx + 2) + 1;
this.m_codeWords.add(value16 / 256);
this.m_codeWords.add(value16 % 256);
}
int tempSymbolSize = this.findSymbolSize(this.m_codeWords.size());
if (tempSymbolSize < 0) {
return;
}
int remainSymbolCodeWords = DataMatrixInfo.DATA_SYMBOLS[tempSymbolSize] - this.m_codeWords.size();
int remainTextCodeWords = 0;
for (idx = c40End; idx < messageSize; ++idx) {
remainTextCodeWords += c40Encoding[idx].c40Value.size();
}
if (remainTextCodeWords == 0) {
if (remainSymbolCodeWords > 0) {
this.m_codeWords.add(254);
DataMatrixPadder.addPadding(this.m_codeWords, tempSymbolSize);
this.m_symbolSize = tempSymbolSize;
this.m_valid = true;
} else {
this.m_symbolSize = tempSymbolSize;
this.m_valid = true;
}
} else if (remainSymbolCodeWords == 1 && remainTextCodeWords == 1) {
if (c40Encoding[c40End].messageValue < 128) {
this.m_codeWords.add(c40Encoding[c40End].messageValue + 1);
this.m_symbolSize = tempSymbolSize;
this.m_valid = true;
} else {
this.m_codeWords.add(254);
this.m_codeWords.add(235);
this.m_codeWords.add(c40Encoding[c40End].messageValue - 127);
this.m_symbolSize = this.findSymbolSize(this.m_codeWords.size());
if (this.m_symbolSize == -1) {
return;
}
DataMatrixPadder.addPadding(this.m_codeWords, this.m_symbolSize);
this.m_valid = true;
}
} else {
this.m_codeWords.add(254);
for (idx = c40End; idx < messageSize; ++idx) {
int v = c40Encoding[idx].messageValue;
if (v > 127) {
v -= 128;
this.m_codeWords.add(235);
}
this.m_codeWords.add(v + 1);
}
this.m_symbolSize = this.findSymbolSize(this.m_codeWords.size());
if (this.m_symbolSize == -1) {
return;
}
DataMatrixPadder.addPadding(this.m_codeWords, this.m_symbolSize);
this.m_valid = true;
}
}
static class CharacterSet {
int messageValue;
int codeValue;
CharacterSet(int messageValue, int codeValue) {
this.messageValue = messageValue;
this.codeValue = codeValue;
}
}
static class C40Encoding {
int messageValue;
List<Integer> c40Value = new ArrayList<Integer>();
C40Encoding() {
}
}
}