105 lines
3.9 KiB
Java
105 lines
3.9 KiB
Java
package com.google.zxing.pdf417;
|
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
import com.google.zxing.EncodeHintType;
|
|
import com.google.zxing.Writer;
|
|
import com.google.zxing.WriterException;
|
|
import com.google.zxing.common.BitMatrix;
|
|
import com.google.zxing.pdf417.encoder.Compaction;
|
|
import com.google.zxing.pdf417.encoder.Dimensions;
|
|
import com.google.zxing.pdf417.encoder.PDF417;
|
|
import java.lang.reflect.Array;
|
|
import java.nio.charset.Charset;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class PDF417Writer implements Writer {
|
|
@Override // com.google.zxing.Writer
|
|
public BitMatrix a(String str, BarcodeFormat barcodeFormat, int i, int i2, Map<EncodeHintType, ?> map) throws WriterException {
|
|
int i3;
|
|
int i4;
|
|
if (barcodeFormat != BarcodeFormat.PDF_417) {
|
|
throw new IllegalArgumentException("Can only encode PDF_417, but got ".concat(String.valueOf(barcodeFormat)));
|
|
}
|
|
PDF417 pdf417 = new PDF417();
|
|
if (map != null) {
|
|
if (map.containsKey(EncodeHintType.PDF417_COMPACT)) {
|
|
pdf417.a(Boolean.valueOf(map.get(EncodeHintType.PDF417_COMPACT).toString()).booleanValue());
|
|
}
|
|
if (map.containsKey(EncodeHintType.PDF417_COMPACTION)) {
|
|
pdf417.a(Compaction.valueOf(map.get(EncodeHintType.PDF417_COMPACTION).toString()));
|
|
}
|
|
if (map.containsKey(EncodeHintType.PDF417_DIMENSIONS)) {
|
|
Dimensions dimensions = (Dimensions) map.get(EncodeHintType.PDF417_DIMENSIONS);
|
|
pdf417.a(dimensions.a(), dimensions.c(), dimensions.b(), dimensions.d());
|
|
}
|
|
int parseInt = map.containsKey(EncodeHintType.MARGIN) ? Integer.parseInt(map.get(EncodeHintType.MARGIN).toString()) : 30;
|
|
int parseInt2 = map.containsKey(EncodeHintType.ERROR_CORRECTION) ? Integer.parseInt(map.get(EncodeHintType.ERROR_CORRECTION).toString()) : 2;
|
|
if (map.containsKey(EncodeHintType.CHARACTER_SET)) {
|
|
pdf417.a(Charset.forName(map.get(EncodeHintType.CHARACTER_SET).toString()));
|
|
}
|
|
i4 = parseInt;
|
|
i3 = parseInt2;
|
|
} else {
|
|
i3 = 2;
|
|
i4 = 30;
|
|
}
|
|
return a(pdf417, str, i3, i, i2, i4);
|
|
}
|
|
|
|
private static BitMatrix a(PDF417 pdf417, String str, int i, int i2, int i3, int i4) throws WriterException {
|
|
boolean z;
|
|
pdf417.a(str, i);
|
|
byte[][] a = pdf417.a().a(1, 4);
|
|
if ((i3 > i2) != (a[0].length < a.length)) {
|
|
a = a(a);
|
|
z = true;
|
|
} else {
|
|
z = false;
|
|
}
|
|
int length = i2 / a[0].length;
|
|
int length2 = i3 / a.length;
|
|
if (length >= length2) {
|
|
length = length2;
|
|
}
|
|
if (length > 1) {
|
|
byte[][] a2 = pdf417.a().a(length, length << 2);
|
|
if (z) {
|
|
a2 = a(a2);
|
|
}
|
|
return a(a2, i4);
|
|
}
|
|
return a(a, i4);
|
|
}
|
|
|
|
private static BitMatrix a(byte[][] bArr, int i) {
|
|
int i2 = i * 2;
|
|
BitMatrix bitMatrix = new BitMatrix(bArr[0].length + i2, bArr.length + i2);
|
|
bitMatrix.a();
|
|
int i3 = (bitMatrix.i() - i) - 1;
|
|
int i4 = 0;
|
|
while (i4 < bArr.length) {
|
|
byte[] bArr2 = bArr[i4];
|
|
for (int i5 = 0; i5 < bArr[0].length; i5++) {
|
|
if (bArr2[i5] == 1) {
|
|
bitMatrix.c(i5 + i, i3);
|
|
}
|
|
}
|
|
i4++;
|
|
i3--;
|
|
}
|
|
return bitMatrix;
|
|
}
|
|
|
|
private static byte[][] a(byte[][] bArr) {
|
|
byte[][] bArr2 = (byte[][]) Array.newInstance((Class<?>) byte.class, bArr[0].length, bArr.length);
|
|
for (int i = 0; i < bArr.length; i++) {
|
|
int length = (bArr.length - i) - 1;
|
|
for (int i2 = 0; i2 < bArr[0].length; i2++) {
|
|
bArr2[i2][length] = bArr[i][i2];
|
|
}
|
|
}
|
|
return bArr2;
|
|
}
|
|
}
|