184 lines
6.3 KiB
Java
184 lines
6.3 KiB
Java
package com.google.zxing.oned;
|
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
import com.google.zxing.EncodeHintType;
|
|
import com.google.zxing.WriterException;
|
|
import com.google.zxing.common.BitMatrix;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class Code128Writer extends OneDimensionalCodeWriter {
|
|
|
|
private enum CType {
|
|
UNCODABLE,
|
|
ONE_DIGIT,
|
|
TWO_DIGITS,
|
|
FNC_1
|
|
}
|
|
|
|
@Override // com.google.zxing.oned.OneDimensionalCodeWriter, com.google.zxing.Writer
|
|
public BitMatrix a(String str, BarcodeFormat barcodeFormat, int i, int i2, Map<EncodeHintType, ?> map) throws WriterException {
|
|
if (barcodeFormat == BarcodeFormat.CODE_128) {
|
|
return super.a(str, barcodeFormat, i, i2, map);
|
|
}
|
|
throw new IllegalArgumentException("Can only encode CODE_128, but got ".concat(String.valueOf(barcodeFormat)));
|
|
}
|
|
|
|
@Override // com.google.zxing.oned.OneDimensionalCodeWriter
|
|
public boolean[] a(String str) {
|
|
int length = str.length();
|
|
if (length > 0 && length <= 80) {
|
|
int i = 0;
|
|
for (int i2 = 0; i2 < length; i2++) {
|
|
char charAt = str.charAt(i2);
|
|
switch (charAt) {
|
|
case 241:
|
|
case 242:
|
|
case 243:
|
|
case 244:
|
|
break;
|
|
default:
|
|
if (charAt > 127) {
|
|
throw new IllegalArgumentException("Bad character in input: ".concat(String.valueOf(charAt)));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
ArrayList<int[]> arrayList = new ArrayList();
|
|
int i3 = 0;
|
|
int i4 = 0;
|
|
int i5 = 0;
|
|
int i6 = 1;
|
|
while (i3 < length) {
|
|
int a = a(str, i3, i5);
|
|
int i7 = 100;
|
|
if (a == i5) {
|
|
switch (str.charAt(i3)) {
|
|
case 241:
|
|
i7 = 102;
|
|
break;
|
|
case 242:
|
|
i7 = 97;
|
|
break;
|
|
case 243:
|
|
i7 = 96;
|
|
break;
|
|
case 244:
|
|
if (i5 == 101) {
|
|
i7 = 101;
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
if (i5 != 100) {
|
|
if (i5 == 101) {
|
|
i7 = str.charAt(i3) - ' ';
|
|
if (i7 < 0) {
|
|
i7 += 96;
|
|
break;
|
|
}
|
|
} else {
|
|
i7 = Integer.parseInt(str.substring(i3, i3 + 2));
|
|
i3++;
|
|
break;
|
|
}
|
|
} else {
|
|
i7 = str.charAt(i3) - ' ';
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
i3++;
|
|
} else {
|
|
i7 = i5 == 0 ? a != 100 ? a != 101 ? 105 : 103 : 104 : a;
|
|
i5 = a;
|
|
}
|
|
arrayList.add(Code128Reader.a[i7]);
|
|
i4 += i7 * i6;
|
|
if (i3 != 0) {
|
|
i6++;
|
|
}
|
|
}
|
|
arrayList.add(Code128Reader.a[i4 % 103]);
|
|
arrayList.add(Code128Reader.a[106]);
|
|
int i8 = 0;
|
|
for (int[] iArr : arrayList) {
|
|
int i9 = i8;
|
|
for (int i10 : iArr) {
|
|
i9 += i10;
|
|
}
|
|
i8 = i9;
|
|
}
|
|
boolean[] zArr = new boolean[i8];
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
i += OneDimensionalCodeWriter.a(zArr, i, (int[]) it.next(), true);
|
|
}
|
|
return zArr;
|
|
}
|
|
throw new IllegalArgumentException("Contents length should be between 1 and 80 characters, but got ".concat(String.valueOf(length)));
|
|
}
|
|
|
|
private static CType a(CharSequence charSequence, int i) {
|
|
int length = charSequence.length();
|
|
if (i >= length) {
|
|
return CType.UNCODABLE;
|
|
}
|
|
char charAt = charSequence.charAt(i);
|
|
if (charAt == 241) {
|
|
return CType.FNC_1;
|
|
}
|
|
if (charAt < '0' || charAt > '9') {
|
|
return CType.UNCODABLE;
|
|
}
|
|
int i2 = i + 1;
|
|
if (i2 >= length) {
|
|
return CType.ONE_DIGIT;
|
|
}
|
|
char charAt2 = charSequence.charAt(i2);
|
|
if (charAt2 >= '0' && charAt2 <= '9') {
|
|
return CType.TWO_DIGITS;
|
|
}
|
|
return CType.ONE_DIGIT;
|
|
}
|
|
|
|
private static int a(CharSequence charSequence, int i, int i2) {
|
|
CType a;
|
|
CType a2;
|
|
char charAt;
|
|
CType a3 = a(charSequence, i);
|
|
if (a3 == CType.ONE_DIGIT) {
|
|
return 100;
|
|
}
|
|
if (a3 == CType.UNCODABLE) {
|
|
return (i >= charSequence.length() || ((charAt = charSequence.charAt(i)) >= ' ' && (i2 != 101 || charAt >= '`'))) ? 100 : 101;
|
|
}
|
|
if (i2 == 99) {
|
|
return 99;
|
|
}
|
|
if (i2 == 100) {
|
|
if (a3 == CType.FNC_1 || (a = a(charSequence, i + 2)) == CType.UNCODABLE || a == CType.ONE_DIGIT) {
|
|
return 100;
|
|
}
|
|
if (a == CType.FNC_1) {
|
|
return a(charSequence, i + 3) == CType.TWO_DIGITS ? 99 : 100;
|
|
}
|
|
int i3 = i + 4;
|
|
while (true) {
|
|
a2 = a(charSequence, i3);
|
|
if (a2 != CType.TWO_DIGITS) {
|
|
break;
|
|
}
|
|
i3 += 2;
|
|
}
|
|
return a2 == CType.ONE_DIGIT ? 100 : 99;
|
|
}
|
|
if (a3 == CType.FNC_1) {
|
|
a3 = a(charSequence, i + 1);
|
|
}
|
|
return a3 == CType.TWO_DIGITS ? 99 : 100;
|
|
}
|
|
}
|