Skip to content

Commit 9f3d027

Browse files
committed
add support for pdf417
1 parent 6aa112b commit 9f3d027

File tree

7 files changed

+40
-18
lines changed

7 files changed

+40
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.50.0]
5+
6+
### Added
7+
- Added support for scanning and displaying PDF_417 codes
8+
49
## [0.49.3]
510

611
### Fixed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ allprojects {
3131
}
3232

3333
project.ext {
34-
sdkVersion='0.49.3'
34+
sdkVersion='0.50.0'
3535
versionCode=1
3636

3737
compileSdkVersion=31

core/src/main/java/io/snabble/sdk/BarcodeFormat.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ public enum BarcodeFormat {
77
EAN_13,
88
ITF_14,
99
QR_CODE,
10-
DATA_MATRIX;
10+
DATA_MATRIX,
11+
PDF_417;
1112

1213
public static BarcodeFormat parse(String str) {
1314
switch (str) {
@@ -23,6 +24,8 @@ public static BarcodeFormat parse(String str) {
2324
return ITF_14;
2425
case "datamatrix":
2526
return DATA_MATRIX;
27+
case "pdf417":
28+
return PDF_417;
2629
case "qr":
2730
case "qrCode":
2831
return QR_CODE;

firebase-detector/src/main/java/io/snabble/sdk/firebase/FirebaseBarcodeHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public static int toFirebaseFormat(BarcodeFormat barcodeFormat) {
2020
return Barcode.FORMAT_ITF;
2121
case DATA_MATRIX:
2222
return Barcode.FORMAT_DATA_MATRIX;
23+
case PDF_417:
24+
return Barcode.FORMAT_PDF417;
2325
case QR_CODE:
2426
return Barcode.FORMAT_QR_CODE;
2527
}
@@ -42,6 +44,8 @@ public static BarcodeFormat fromFirebaseFormat(int firebaseVisionBarcode) {
4244
return BarcodeFormat.ITF_14;
4345
case Barcode.FORMAT_DATA_MATRIX:
4446
return BarcodeFormat.DATA_MATRIX;
47+
case Barcode.FORMAT_PDF417:
48+
return BarcodeFormat.PDF_417;
4549
case Barcode.FORMAT_QR_CODE:
4650
return BarcodeFormat.QR_CODE;
4751
}

sample/src/main/res/layout/fragment_home.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
android:layout_height="wrap_content"
88
android:padding="4dp"
99
android:orientation="vertical">
10+
1011
<Spinner
1112
android:layout_width="wrap_content"
1213
android:layout_height="wrap_content"

ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,21 @@ private void generate() {
171171

172172
BitMatrix bm = writer.encode(text, ZXingHelper.toZXingFormat(format), tw, th);
173173
int[] pixels = new int[w * h];
174-
175-
// DATA-MATRIX codes are not scaled
174+
175+
int[] rect = bm.getEnclosingRectangle();
176+
int left = rect[0];
177+
int top = rect[1];
178+
int right = left + rect[2];
179+
int bottom = top + rect[3];
180+
181+
int startX = left - dp2px(8);
182+
int startY = top - dp2px(8);
183+
int endX = right + dp2px(8);
184+
int endY = bottom + dp2px(8);
185+
186+
// DATA-MATRIX and PDF_417 codes are not scaled
176187
// See https://github.com/zxing/zxing/issues/836
177-
if (format == BarcodeFormat.DATA_MATRIX) {
188+
if (format == BarcodeFormat.DATA_MATRIX || format == BarcodeFormat.PDF_417) {
178189
float dw = (float)tw / (float)bm.getWidth();
179190
float dh = (float)th / (float)bm.getHeight();
180191

@@ -184,24 +195,18 @@ private void generate() {
184195

185196
for (int x = 0; x < tw; x++) {
186197
int ax = (int)((float)x/dw);
187-
pixels[x + stride] = bm.get(ax, ay) ? Color.BLACK : backgroundColor;
198+
int bgColor = backgroundColor;
199+
200+
if (ax > startX && ay > startY && ax < endX && ay < endY) {
201+
bgColor = Color.WHITE;
202+
}
203+
204+
pixels[x + stride] = bm.get(ax, ay) ? Color.BLACK : bgColor;
188205
}
189206
}
190207
} else {
191-
int[] rect = bm.getEnclosingRectangle();
192-
int left = rect[0];
193-
int top = rect[1];
194-
int right = left + rect[2];
195-
int bottom = top + rect[3];
196-
197-
int startX = left - dp2px(8);
198-
int startY = top - dp2px(8);
199-
int endX = right + dp2px(8);
200-
int endY = bottom + dp2px(8);
201-
202208
for (int y = 0; y < th; y++) {
203209
final int stride = y * tw;
204-
205210
for (int x = 0; x < tw; x++) {
206211
int bgColor = backgroundColor;
207212

ui/src/main/java/io/snabble/sdk/ui/scanner/ZXingHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public static com.google.zxing.BarcodeFormat toZXingFormat(BarcodeFormat barcode
1717
return com.google.zxing.BarcodeFormat.ITF;
1818
case DATA_MATRIX:
1919
return com.google.zxing.BarcodeFormat.DATA_MATRIX;
20+
case PDF_417:
21+
return com.google.zxing.BarcodeFormat.PDF_417;
2022
case QR_CODE:
2123
return com.google.zxing.BarcodeFormat.QR_CODE;
2224
}
@@ -38,6 +40,8 @@ public static BarcodeFormat fromZXingFormat(com.google.zxing.BarcodeFormat barco
3840
return BarcodeFormat.ITF_14;
3941
case DATA_MATRIX:
4042
return BarcodeFormat.DATA_MATRIX;
43+
case PDF_417:
44+
return BarcodeFormat.PDF_417;
4145
case QR_CODE:
4246
return BarcodeFormat.QR_CODE;
4347
}

0 commit comments

Comments
 (0)