53 lines
2.2 KiB
Java
53 lines
2.2 KiB
Java
package com.google.zxing.oned;
|
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
import com.google.zxing.EncodeHintType;
|
|
import com.google.zxing.FormatException;
|
|
import com.google.zxing.WriterException;
|
|
import com.google.zxing.common.BitMatrix;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class EAN8Writer extends UPCEANWriter {
|
|
@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.EAN_8) {
|
|
return super.a(str, barcodeFormat, i, i2, map);
|
|
}
|
|
throw new IllegalArgumentException("Can only encode EAN_8, but got ".concat(String.valueOf(barcodeFormat)));
|
|
}
|
|
|
|
@Override // com.google.zxing.oned.OneDimensionalCodeWriter
|
|
public boolean[] a(String str) {
|
|
int length = str.length();
|
|
if (length == 7) {
|
|
try {
|
|
str = str + UPCEANReader.b(str);
|
|
} catch (FormatException e) {
|
|
throw new IllegalArgumentException(e);
|
|
}
|
|
} else if (length == 8) {
|
|
try {
|
|
if (!UPCEANReader.a((CharSequence) str)) {
|
|
throw new IllegalArgumentException("Contents do not pass checksum");
|
|
}
|
|
} catch (FormatException unused) {
|
|
throw new IllegalArgumentException("Illegal contents");
|
|
}
|
|
} else {
|
|
throw new IllegalArgumentException("Requested contents should be 8 digits long, but got ".concat(String.valueOf(length)));
|
|
}
|
|
boolean[] zArr = new boolean[67];
|
|
int a = OneDimensionalCodeWriter.a(zArr, 0, UPCEANReader.d, true) + 0;
|
|
for (int i = 0; i <= 3; i++) {
|
|
a += OneDimensionalCodeWriter.a(zArr, a, UPCEANReader.g[Character.digit(str.charAt(i), 10)], false);
|
|
}
|
|
int a2 = a + OneDimensionalCodeWriter.a(zArr, a, UPCEANReader.e, false);
|
|
for (int i2 = 4; i2 <= 7; i2++) {
|
|
a2 += OneDimensionalCodeWriter.a(zArr, a2, UPCEANReader.g[Character.digit(str.charAt(i2), 10)], true);
|
|
}
|
|
OneDimensionalCodeWriter.a(zArr, a2, UPCEANReader.d, true);
|
|
return zArr;
|
|
}
|
|
}
|