mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
397 lines
15 KiB
Java
397 lines
15 KiB
Java
package com.google.zxing.pdf417.encoder;
|
|
|
|
import com.google.common.base.Ascii;
|
|
import com.google.common.primitives.SignedBytes;
|
|
import com.google.zxing.WriterException;
|
|
import com.google.zxing.common.CharacterSetECI;
|
|
import java.math.BigInteger;
|
|
import java.nio.charset.Charset;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.Arrays;
|
|
import kotlin.io.encoding.Base64;
|
|
import okio.Utf8;
|
|
|
|
/* loaded from: classes3.dex */
|
|
final class PDF417HighLevelEncoder {
|
|
private static final int BYTE_COMPACTION = 1;
|
|
private static final int ECI_CHARSET = 927;
|
|
private static final int ECI_GENERAL_PURPOSE = 926;
|
|
private static final int ECI_USER_DEFINED = 925;
|
|
private static final int LATCH_TO_BYTE = 924;
|
|
private static final int LATCH_TO_BYTE_PADDED = 901;
|
|
private static final int LATCH_TO_NUMERIC = 902;
|
|
private static final int LATCH_TO_TEXT = 900;
|
|
private static final byte[] MIXED;
|
|
private static final int NUMERIC_COMPACTION = 2;
|
|
private static final int SHIFT_TO_BYTE = 913;
|
|
private static final int SUBMODE_ALPHA = 0;
|
|
private static final int SUBMODE_LOWER = 1;
|
|
private static final int SUBMODE_MIXED = 2;
|
|
private static final int SUBMODE_PUNCTUATION = 3;
|
|
private static final int TEXT_COMPACTION = 0;
|
|
private static final byte[] TEXT_MIXED_RAW = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 38, Ascii.CR, 9, 44, 58, 35, 45, 46, 36, 47, 43, 37, 42, Base64.padSymbol, 94, 0, 32, 0, 0, 0};
|
|
private static final byte[] TEXT_PUNCTUATION_RAW = {59, 60, 62, SignedBytes.MAX_POWER_OF_TWO, 91, 92, 93, 95, 96, 126, 33, Ascii.CR, 9, 44, 58, 10, 45, 46, 36, 47, 34, 124, 42, 40, 41, Utf8.REPLACEMENT_BYTE, 123, 125, 39, 0};
|
|
private static final byte[] PUNCTUATION = new byte[128];
|
|
private static final Charset DEFAULT_ENCODING = StandardCharsets.ISO_8859_1;
|
|
|
|
private static boolean isAlphaLower(char c) {
|
|
if (c != ' ') {
|
|
return c >= 'a' && c <= 'z';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private static boolean isAlphaUpper(char c) {
|
|
if (c != ' ') {
|
|
return c >= 'A' && c <= 'Z';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private static boolean isDigit(char c) {
|
|
return c >= '0' && c <= '9';
|
|
}
|
|
|
|
private static boolean isText(char c) {
|
|
if (c == '\t' || c == '\n' || c == '\r') {
|
|
return true;
|
|
}
|
|
return c >= ' ' && c <= '~';
|
|
}
|
|
|
|
static {
|
|
byte[] bArr = new byte[128];
|
|
MIXED = bArr;
|
|
Arrays.fill(bArr, (byte) -1);
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (true) {
|
|
byte[] bArr2 = TEXT_MIXED_RAW;
|
|
if (i2 >= bArr2.length) {
|
|
break;
|
|
}
|
|
byte b = bArr2[i2];
|
|
if (b > 0) {
|
|
MIXED[b] = (byte) i2;
|
|
}
|
|
i2++;
|
|
}
|
|
Arrays.fill(PUNCTUATION, (byte) -1);
|
|
while (true) {
|
|
byte[] bArr3 = TEXT_PUNCTUATION_RAW;
|
|
if (i >= bArr3.length) {
|
|
return;
|
|
}
|
|
byte b2 = bArr3[i];
|
|
if (b2 > 0) {
|
|
PUNCTUATION[b2] = (byte) i;
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
|
|
private PDF417HighLevelEncoder() {
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static String encodeHighLevel(String str, Compaction compaction, Charset charset) throws WriterException {
|
|
CharacterSetECI characterSetECIByName;
|
|
StringBuilder sb = new StringBuilder(str.length());
|
|
if (charset == null) {
|
|
charset = DEFAULT_ENCODING;
|
|
} else if (!DEFAULT_ENCODING.equals(charset) && (characterSetECIByName = CharacterSetECI.getCharacterSetECIByName(charset.name())) != null) {
|
|
encodingECI(characterSetECIByName.getValue(), sb);
|
|
}
|
|
int length = str.length();
|
|
int i = AnonymousClass1.$SwitchMap$com$google$zxing$pdf417$encoder$Compaction[compaction.ordinal()];
|
|
if (i == 1) {
|
|
encodeText(str, 0, length, sb, 0);
|
|
} else if (i == 2) {
|
|
byte[] bytes = str.getBytes(charset);
|
|
encodeBinary(bytes, 0, bytes.length, 1, sb);
|
|
} else if (i != 3) {
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
int i4 = 0;
|
|
while (i2 < length) {
|
|
int determineConsecutiveDigitCount = determineConsecutiveDigitCount(str, i2);
|
|
if (determineConsecutiveDigitCount >= 13) {
|
|
sb.append((char) 902);
|
|
encodeNumeric(str, i2, determineConsecutiveDigitCount, sb);
|
|
i2 += determineConsecutiveDigitCount;
|
|
i3 = 0;
|
|
i4 = 2;
|
|
} else {
|
|
int determineConsecutiveTextCount = determineConsecutiveTextCount(str, i2);
|
|
if (determineConsecutiveTextCount >= 5 || determineConsecutiveDigitCount == length) {
|
|
if (i4 != 0) {
|
|
sb.append((char) 900);
|
|
i3 = 0;
|
|
i4 = 0;
|
|
}
|
|
i3 = encodeText(str, i2, determineConsecutiveTextCount, sb, i3);
|
|
i2 += determineConsecutiveTextCount;
|
|
} else {
|
|
int determineConsecutiveBinaryCount = determineConsecutiveBinaryCount(str, i2, charset);
|
|
if (determineConsecutiveBinaryCount == 0) {
|
|
determineConsecutiveBinaryCount = 1;
|
|
}
|
|
int i5 = determineConsecutiveBinaryCount + i2;
|
|
byte[] bytes2 = str.substring(i2, i5).getBytes(charset);
|
|
if (bytes2.length == 1 && i4 == 0) {
|
|
encodeBinary(bytes2, 0, 1, 0, sb);
|
|
} else {
|
|
encodeBinary(bytes2, 0, bytes2.length, i4, sb);
|
|
i4 = 1;
|
|
i3 = 0;
|
|
}
|
|
i2 = i5;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
sb.append((char) 902);
|
|
encodeNumeric(str, 0, length, sb);
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
/* renamed from: com.google.zxing.pdf417.encoder.PDF417HighLevelEncoder$1, reason: invalid class name */
|
|
/* loaded from: classes3.dex */
|
|
static /* synthetic */ class AnonymousClass1 {
|
|
static final /* synthetic */ int[] $SwitchMap$com$google$zxing$pdf417$encoder$Compaction;
|
|
|
|
static {
|
|
int[] iArr = new int[Compaction.values().length];
|
|
$SwitchMap$com$google$zxing$pdf417$encoder$Compaction = iArr;
|
|
try {
|
|
iArr[Compaction.TEXT.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$zxing$pdf417$encoder$Compaction[Compaction.BYTE.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$zxing$pdf417$encoder$Compaction[Compaction.NUMERIC.ordinal()] = 3;
|
|
} catch (NoSuchFieldError unused3) {
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:21:0x00f6 A[EDGE_INSN: B:21:0x00f6->B:22:0x00f6 BREAK A[LOOP:0: B:2:0x000f->B:16:0x000f], SYNTHETIC] */
|
|
/* JADX WARN: Removed duplicated region for block: B:37:0x000f A[SYNTHETIC] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
private static int encodeText(java.lang.CharSequence r16, int r17, int r18, java.lang.StringBuilder r19, int r20) {
|
|
/*
|
|
Method dump skipped, instructions count: 287
|
|
To view this dump add '--comments-level debug' option
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.google.zxing.pdf417.encoder.PDF417HighLevelEncoder.encodeText(java.lang.CharSequence, int, int, java.lang.StringBuilder, int):int");
|
|
}
|
|
|
|
private static void encodeBinary(byte[] bArr, int i, int i2, int i3, StringBuilder sb) {
|
|
int i4;
|
|
if (i2 == 1 && i3 == 0) {
|
|
sb.append((char) 913);
|
|
} else if (i2 % 6 == 0) {
|
|
sb.append((char) 924);
|
|
} else {
|
|
sb.append((char) 901);
|
|
}
|
|
if (i2 >= 6) {
|
|
char[] cArr = new char[5];
|
|
i4 = i;
|
|
while ((i + i2) - i4 >= 6) {
|
|
long j = 0;
|
|
for (int i5 = 0; i5 < 6; i5++) {
|
|
j = (j << 8) + (bArr[i4 + i5] & 255);
|
|
}
|
|
for (int i6 = 0; i6 < 5; i6++) {
|
|
cArr[i6] = (char) (j % 900);
|
|
j /= 900;
|
|
}
|
|
for (int i7 = 4; i7 >= 0; i7--) {
|
|
sb.append(cArr[i7]);
|
|
}
|
|
i4 += 6;
|
|
}
|
|
} else {
|
|
i4 = i;
|
|
}
|
|
while (i4 < i + i2) {
|
|
sb.append((char) (bArr[i4] & 255));
|
|
i4++;
|
|
}
|
|
}
|
|
|
|
private static void encodeNumeric(String str, int i, int i2, StringBuilder sb) {
|
|
StringBuilder sb2 = new StringBuilder((i2 / 3) + 1);
|
|
BigInteger valueOf = BigInteger.valueOf(900L);
|
|
BigInteger valueOf2 = BigInteger.valueOf(0L);
|
|
int i3 = 0;
|
|
while (i3 < i2) {
|
|
sb2.setLength(0);
|
|
int min = Math.min(44, i2 - i3);
|
|
int i4 = i + i3;
|
|
BigInteger bigInteger = new BigInteger("1" + str.substring(i4, i4 + min));
|
|
do {
|
|
sb2.append((char) bigInteger.mod(valueOf).intValue());
|
|
bigInteger = bigInteger.divide(valueOf);
|
|
} while (!bigInteger.equals(valueOf2));
|
|
for (int length = sb2.length() - 1; length >= 0; length--) {
|
|
sb.append(sb2.charAt(length));
|
|
}
|
|
i3 += min;
|
|
}
|
|
}
|
|
|
|
private static boolean isMixed(char c) {
|
|
return MIXED[c] != -1;
|
|
}
|
|
|
|
private static boolean isPunctuation(char c) {
|
|
return PUNCTUATION[c] != -1;
|
|
}
|
|
|
|
private static int determineConsecutiveDigitCount(CharSequence charSequence, int i) {
|
|
int length = charSequence.length();
|
|
int i2 = 0;
|
|
if (i < length) {
|
|
char charAt = charSequence.charAt(i);
|
|
while (isDigit(charAt) && i < length) {
|
|
i2++;
|
|
i++;
|
|
if (i < length) {
|
|
charAt = charSequence.charAt(i);
|
|
}
|
|
}
|
|
}
|
|
return i2;
|
|
}
|
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:32:0x0027, code lost:
|
|
|
|
return (r1 - r7) - r3;
|
|
*/
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
private static int determineConsecutiveTextCount(java.lang.CharSequence r6, int r7) {
|
|
/*
|
|
int r0 = r6.length()
|
|
r1 = r7
|
|
L5:
|
|
if (r1 >= r0) goto L37
|
|
char r2 = r6.charAt(r1)
|
|
r3 = 0
|
|
Lc:
|
|
r4 = 13
|
|
if (r3 >= r4) goto L23
|
|
boolean r5 = isDigit(r2)
|
|
if (r5 == 0) goto L23
|
|
if (r1 >= r0) goto L23
|
|
int r3 = r3 + 1
|
|
int r1 = r1 + 1
|
|
if (r1 >= r0) goto Lc
|
|
char r2 = r6.charAt(r1)
|
|
goto Lc
|
|
L23:
|
|
if (r3 < r4) goto L28
|
|
int r1 = r1 - r7
|
|
int r1 = r1 - r3
|
|
return r1
|
|
L28:
|
|
if (r3 > 0) goto L5
|
|
char r2 = r6.charAt(r1)
|
|
boolean r2 = isText(r2)
|
|
if (r2 == 0) goto L37
|
|
int r1 = r1 + 1
|
|
goto L5
|
|
L37:
|
|
int r1 = r1 - r7
|
|
return r1
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.google.zxing.pdf417.encoder.PDF417HighLevelEncoder.determineConsecutiveTextCount(java.lang.CharSequence, int):int");
|
|
}
|
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:22:0x0028, code lost:
|
|
|
|
return r1 - r6;
|
|
*/
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
private static int determineConsecutiveBinaryCount(java.lang.String r5, int r6, java.nio.charset.Charset r7) throws com.google.zxing.WriterException {
|
|
/*
|
|
java.nio.charset.CharsetEncoder r7 = r7.newEncoder()
|
|
int r0 = r5.length()
|
|
r1 = r6
|
|
L9:
|
|
if (r1 >= r0) goto L5b
|
|
char r2 = r5.charAt(r1)
|
|
r3 = 0
|
|
L10:
|
|
r4 = 13
|
|
if (r3 >= r4) goto L25
|
|
boolean r2 = isDigit(r2)
|
|
if (r2 == 0) goto L25
|
|
int r3 = r3 + 1
|
|
int r2 = r1 + r3
|
|
if (r2 >= r0) goto L25
|
|
char r2 = r5.charAt(r2)
|
|
goto L10
|
|
L25:
|
|
if (r3 < r4) goto L29
|
|
int r1 = r1 - r6
|
|
return r1
|
|
L29:
|
|
char r2 = r5.charAt(r1)
|
|
boolean r3 = r7.canEncode(r2)
|
|
if (r3 == 0) goto L36
|
|
int r1 = r1 + 1
|
|
goto L9
|
|
L36:
|
|
com.google.zxing.WriterException r5 = new com.google.zxing.WriterException
|
|
java.lang.StringBuilder r6 = new java.lang.StringBuilder
|
|
java.lang.String r7 = "Non-encodable character detected: "
|
|
r6.<init>(r7)
|
|
java.lang.StringBuilder r6 = r6.append(r2)
|
|
java.lang.String r7 = " (Unicode: "
|
|
java.lang.StringBuilder r6 = r6.append(r7)
|
|
java.lang.StringBuilder r6 = r6.append(r2)
|
|
r7 = 41
|
|
java.lang.StringBuilder r6 = r6.append(r7)
|
|
java.lang.String r6 = r6.toString()
|
|
r5.<init>(r6)
|
|
throw r5
|
|
L5b:
|
|
int r1 = r1 - r6
|
|
return r1
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.google.zxing.pdf417.encoder.PDF417HighLevelEncoder.determineConsecutiveBinaryCount(java.lang.String, int, java.nio.charset.Charset):int");
|
|
}
|
|
|
|
private static void encodingECI(int i, StringBuilder sb) throws WriterException {
|
|
if (i >= 0 && i < LATCH_TO_TEXT) {
|
|
sb.append((char) 927);
|
|
sb.append((char) i);
|
|
} else if (i < 810900) {
|
|
sb.append((char) 926);
|
|
sb.append((char) ((i / LATCH_TO_TEXT) - 1));
|
|
sb.append((char) (i % LATCH_TO_TEXT));
|
|
} else {
|
|
if (i < 811800) {
|
|
sb.append((char) 925);
|
|
sb.append((char) (810900 - i));
|
|
return;
|
|
}
|
|
throw new WriterException("ECI number not in valid range from 0..811799, but was ".concat(String.valueOf(i)));
|
|
}
|
|
}
|
|
}
|