Rabbit-R1/switch port/java/sources/com/google/zxing/oned/EAN13Writer.java

56 lines
2.3 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.FormatException;
import java.util.Collection;
import java.util.Collections;
/* loaded from: classes3.dex */
public final class EAN13Writer extends UPCEANWriter {
private static final int CODE_WIDTH = 95;
@Override // com.google.zxing.oned.OneDimensionalCodeWriter
protected Collection<BarcodeFormat> getSupportedWriteFormats() {
return Collections.singleton(BarcodeFormat.EAN_13);
}
@Override // com.google.zxing.oned.OneDimensionalCodeWriter
public boolean[] encode(String str) {
int length = str.length();
if (length == 12) {
try {
str = str + UPCEANReader.getStandardUPCEANChecksum(str);
} catch (FormatException e) {
throw new IllegalArgumentException(e);
}
} else if (length == 13) {
try {
if (!UPCEANReader.checkStandardUPCEANChecksum(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 12 or 13 digits long, but got ".concat(String.valueOf(length)));
}
checkNumeric(str);
int i = EAN13Reader.FIRST_DIGIT_ENCODINGS[Character.digit(str.charAt(0), 10)];
boolean[] zArr = new boolean[CODE_WIDTH];
int appendPattern = appendPattern(zArr, 0, UPCEANReader.START_END_PATTERN, true);
for (int i2 = 1; i2 <= 6; i2++) {
int digit = Character.digit(str.charAt(i2), 10);
if (((i >> (6 - i2)) & 1) == 1) {
digit += 10;
}
appendPattern += appendPattern(zArr, appendPattern, UPCEANReader.L_AND_G_PATTERNS[digit], false);
}
int appendPattern2 = appendPattern + appendPattern(zArr, appendPattern, UPCEANReader.MIDDLE_PATTERN, false);
for (int i3 = 7; i3 <= 12; i3++) {
appendPattern2 += appendPattern(zArr, appendPattern2, UPCEANReader.L_PATTERNS[Character.digit(str.charAt(i3), 10)], true);
}
appendPattern(zArr, appendPattern2, UPCEANReader.START_END_PATTERN, true);
return zArr;
}
}