mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Bump to 3.4.0. Require Java 8. Various code simplifications and plugin / dep updates
This commit is contained in:
parent
39d50c1053
commit
f1683e1f4f
|
@ -7,14 +7,11 @@ script:
|
||||||
- find $HOME/.m2/repository/com/google/zxing -name "*SNAPSHOT" -type d -delete
|
- find $HOME/.m2/repository/com/google/zxing -name "*SNAPSHOT" -type d -delete
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
# Covers Java 7, Open JDK, and code coverage
|
|
||||||
- jdk: openjdk7
|
|
||||||
env: JACOCO=-Pjacoco
|
|
||||||
# Covers Java 8, Android apps
|
|
||||||
- jdk: openjdk8
|
- jdk: openjdk8
|
||||||
env: ANDROID_HOME=$HOME/android-sdk-linux
|
env:
|
||||||
|
- JACOCO=-Pjacoco
|
||||||
|
- ANDROID_HOME=$HOME/android-sdk-linux
|
||||||
before_install: if [ ! -d $HOME/android-sdk-linux/platforms ]; then curl -s https://storage.googleapis.com/zxing-build/android-sdk-linux.tar.bz2 | bunzip2 | tar xf - -C $HOME; else ls -l $HOME/android-sdk-linux; fi
|
before_install: if [ ! -d $HOME/android-sdk-linux/platforms ]; then curl -s https://storage.googleapis.com/zxing-build/android-sdk-linux.tar.bz2 | bunzip2 | tar xf - -C $HOME; else ls -l $HOME/android-sdk-linux; fi
|
||||||
# Covers Java 9
|
|
||||||
- jdk: oraclejdk9
|
- jdk: oraclejdk9
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>android-core</artifactId>
|
<artifactId>android-core</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.google.zxing</groupId>
|
<groupId>com.google.zxing</groupId>
|
||||||
<artifactId>zxing-parent</artifactId>
|
<artifactId>zxing-parent</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<name>ZXing Android Core</name>
|
<name>ZXing Android Core</name>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>android-integration</artifactId>
|
<artifactId>android-integration</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.google.zxing</groupId>
|
<groupId>com.google.zxing</groupId>
|
||||||
<artifactId>zxing-parent</artifactId>
|
<artifactId>zxing-parent</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<name>ZXing Android Integration lib</name>
|
<name>ZXing Android Integration lib</name>
|
||||||
|
|
|
@ -40,7 +40,7 @@ import android.util.Log;
|
||||||
* way to invoke barcode scanning and receive the result, without any need to integrate, modify, or learn the
|
* way to invoke barcode scanning and receive the result, without any need to integrate, modify, or learn the
|
||||||
* project's source code.</p>
|
* project's source code.</p>
|
||||||
*
|
*
|
||||||
* <h2>Initiating a barcode scan</h2>
|
* <h1>Initiating a barcode scan</h1>
|
||||||
*
|
*
|
||||||
* <p>To integrate, create an instance of {@code IntentIntegrator} and call {@link #initiateScan()} and wait
|
* <p>To integrate, create an instance of {@code IntentIntegrator} and call {@link #initiateScan()} and wait
|
||||||
* for the result in your app.</p>
|
* for the result in your app.</p>
|
||||||
|
@ -88,13 +88,13 @@ import android.util.Log;
|
||||||
* do so. The apps that are allowed to response can be set with {@link #setTargetApplications(List)}.
|
* do so. The apps that are allowed to response can be set with {@link #setTargetApplications(List)}.
|
||||||
* For example, set to {@link #TARGET_BARCODE_SCANNER_ONLY} to only target the Barcode Scanner app itself.</p>
|
* For example, set to {@link #TARGET_BARCODE_SCANNER_ONLY} to only target the Barcode Scanner app itself.</p>
|
||||||
*
|
*
|
||||||
* <h2>Sharing text via barcode</h2>
|
* <h1>Sharing text via barcode</h1>
|
||||||
*
|
*
|
||||||
* <p>To share text, encoded as a QR Code on-screen, similarly, see {@link #shareText(CharSequence)}.</p>
|
* <p>To share text, encoded as a QR Code on-screen, similarly, see {@link #shareText(CharSequence)}.</p>
|
||||||
*
|
*
|
||||||
* <p>Some code, particularly download integration, was contributed from the Anobiit application.</p>
|
* <p>Some code, particularly download integration, was contributed from the Anobiit application.</p>
|
||||||
*
|
*
|
||||||
* <h2>Enabling experimental barcode formats</h2>
|
* <h1>Enabling experimental barcode formats</h1>
|
||||||
*
|
*
|
||||||
* <p>Some formats are not enabled by default even when scanning with {@link #ALL_CODE_TYPES}, such as
|
* <p>Some formats are not enabled by default even when scanning with {@link #ALL_CODE_TYPES}, such as
|
||||||
* PDF417. Use {@link #initiateScan(Collection)} with
|
* PDF417. Use {@link #initiateScan(Collection)} with
|
||||||
|
@ -151,7 +151,7 @@ public class IntentIntegrator {
|
||||||
private String buttonYes;
|
private String buttonYes;
|
||||||
private String buttonNo;
|
private String buttonNo;
|
||||||
private List<String> targetApplications;
|
private List<String> targetApplications;
|
||||||
private final Map<String,Object> moreExtras = new HashMap<String,Object>(3);
|
private final Map<String,Object> moreExtras = new HashMap<>(3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param activity {@link Activity} invoking the integration
|
* @param activity {@link Activity} invoking the integration
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.google.zxing</groupId>
|
<groupId>com.google.zxing</groupId>
|
||||||
<artifactId>zxing-parent</artifactId>
|
<artifactId>zxing-parent</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -34,7 +34,7 @@ final class HistoryItemAdapter extends ArrayAdapter<HistoryItem> {
|
||||||
private final Context activity;
|
private final Context activity;
|
||||||
|
|
||||||
HistoryItemAdapter(Context activity) {
|
HistoryItemAdapter(Context activity) {
|
||||||
super(activity, R.layout.history_list_item, new ArrayList<HistoryItem>());
|
super(activity, R.layout.history_list_item, new ArrayList<>());
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>core</artifactId>
|
<artifactId>core</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.google.zxing</groupId>
|
<groupId>com.google.zxing</groupId>
|
||||||
<artifactId>zxing-parent</artifactId>
|
<artifactId>zxing-parent</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<name>ZXing Core</name>
|
<name>ZXing Core</name>
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>biz.aQute.bnd</groupId>
|
<groupId>biz.aQute.bnd</groupId>
|
||||||
<artifactId>bnd-maven-plugin</artifactId>
|
<artifactId>bnd-maven-plugin</artifactId>
|
||||||
<version>3.5.0</version> <!-- 4.0.0 requires Java 8 -->
|
<version>4.2.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -112,13 +112,13 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer {
|
||||||
if (yoffset > maxYOffset) {
|
if (yoffset > maxYOffset) {
|
||||||
yoffset = maxYOffset;
|
yoffset = maxYOffset;
|
||||||
}
|
}
|
||||||
int top = cap(y, 2, subHeight - 3);
|
int top = cap(y, subHeight - 3);
|
||||||
for (int x = 0; x < subWidth; x++) {
|
for (int x = 0; x < subWidth; x++) {
|
||||||
int xoffset = x << BLOCK_SIZE_POWER;
|
int xoffset = x << BLOCK_SIZE_POWER;
|
||||||
if (xoffset > maxXOffset) {
|
if (xoffset > maxXOffset) {
|
||||||
xoffset = maxXOffset;
|
xoffset = maxXOffset;
|
||||||
}
|
}
|
||||||
int left = cap(x, 2, subWidth - 3);
|
int left = cap(x, subWidth - 3);
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int z = -2; z <= 2; z++) {
|
for (int z = -2; z <= 2; z++) {
|
||||||
int[] blackRow = blackPoints[top + z];
|
int[] blackRow = blackPoints[top + z];
|
||||||
|
@ -130,8 +130,8 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int cap(int value, int min, int max) {
|
private static int cap(int value, int max) {
|
||||||
return value < min ? min : value > max ? max : value;
|
return value < 2 ? 2 : value > max ? max : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -166,7 +166,7 @@ public final class StringUtils {
|
||||||
if (canBeUTF8 && (utf8bom || utf2BytesChars + utf3BytesChars + utf4BytesChars > 0)) {
|
if (canBeUTF8 && (utf8bom || utf2BytesChars + utf3BytesChars + utf4BytesChars > 0)) {
|
||||||
return UTF8;
|
return UTF8;
|
||||||
}
|
}
|
||||||
// Easy -- if assuming Shift_JIS or at least 3 valid consecutive not-ascii characters (and no evidence it can't be), done
|
// Easy -- if assuming Shift_JIS or >= 3 valid consecutive not-ascii characters (and no evidence it can't be), done
|
||||||
if (canBeShiftJIS && (ASSUME_SHIFT_JIS || sjisMaxKatakanaWordLength >= 3 || sjisMaxDoubleBytesWordLength >= 3)) {
|
if (canBeShiftJIS && (ASSUME_SHIFT_JIS || sjisMaxKatakanaWordLength >= 3 || sjisMaxDoubleBytesWordLength >= 3)) {
|
||||||
return SHIFT_JIS;
|
return SHIFT_JIS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,13 +87,13 @@ public final class Detector {
|
||||||
return new DetectorResult(bits, new ResultPoint[]{topLeft, bottomLeft, bottomRight, topRight});
|
return new DetectorResult(bits, new ResultPoint[]{topLeft, bottomLeft, bottomRight, topRight});
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResultPoint shiftPoint(ResultPoint point, ResultPoint to, int div) {
|
private static ResultPoint shiftPoint(ResultPoint point, ResultPoint to, int div) {
|
||||||
float x = (to.getX() - point.getX()) / (div + 1);
|
float x = (to.getX() - point.getX()) / (div + 1);
|
||||||
float y = (to.getY() - point.getY()) / (div + 1);
|
float y = (to.getY() - point.getY()) / (div + 1);
|
||||||
return new ResultPoint(point.getX() + x, point.getY() + y);
|
return new ResultPoint(point.getX() + x, point.getY() + y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResultPoint moveAway(ResultPoint point, float fromX, float fromY) {
|
private static ResultPoint moveAway(ResultPoint point, float fromX, float fromY) {
|
||||||
float x = point.getX();
|
float x = point.getX();
|
||||||
float y = point.getY();
|
float y = point.getY();
|
||||||
|
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class DefaultPlacement {
|
||||||
bits[row * numcols + col] = (byte) (bit ? 1 : 0);
|
bits[row * numcols + col] = (byte) (bit ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasBit(int col, int row) {
|
private boolean noBit(int col, int row) {
|
||||||
return bits[row * numcols + col] >= 0;
|
return bits[row * numcols + col] < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void place() {
|
public final void place() {
|
||||||
|
@ -73,7 +73,7 @@ public class DefaultPlacement {
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* repeatedly first check for one of the special corner cases, then... */
|
// repeatedly first check for one of the special corner cases, then...
|
||||||
if ((row == numrows) && (col == 0)) {
|
if ((row == numrows) && (col == 0)) {
|
||||||
corner1(pos++);
|
corner1(pos++);
|
||||||
}
|
}
|
||||||
|
@ -86,9 +86,9 @@ public class DefaultPlacement {
|
||||||
if ((row == numrows + 4) && (col == 2) && ((numcols % 8) == 0)) {
|
if ((row == numrows + 4) && (col == 2) && ((numcols % 8) == 0)) {
|
||||||
corner4(pos++);
|
corner4(pos++);
|
||||||
}
|
}
|
||||||
/* sweep upward diagonally, inserting successive characters... */
|
// sweep upward diagonally, inserting successive characters...
|
||||||
do {
|
do {
|
||||||
if ((row < numrows) && (col >= 0) && !hasBit(col, row)) {
|
if ((row < numrows) && (col >= 0) && noBit(col, row)) {
|
||||||
utah(row, col, pos++);
|
utah(row, col, pos++);
|
||||||
}
|
}
|
||||||
row -= 2;
|
row -= 2;
|
||||||
|
@ -97,9 +97,9 @@ public class DefaultPlacement {
|
||||||
row++;
|
row++;
|
||||||
col += 3;
|
col += 3;
|
||||||
|
|
||||||
/* and then sweep downward diagonally, inserting successive characters, ... */
|
// and then sweep downward diagonally, inserting successive characters, ...
|
||||||
do {
|
do {
|
||||||
if ((row >= 0) && (col < numcols) && !hasBit(col, row)) {
|
if ((row >= 0) && (col < numcols) && noBit(col, row)) {
|
||||||
utah(row, col, pos++);
|
utah(row, col, pos++);
|
||||||
}
|
}
|
||||||
row += 2;
|
row += 2;
|
||||||
|
@ -108,11 +108,11 @@ public class DefaultPlacement {
|
||||||
row += 3;
|
row += 3;
|
||||||
col++;
|
col++;
|
||||||
|
|
||||||
/* ...until the entire array is scanned */
|
// ...until the entire array is scanned
|
||||||
} while ((row < numrows) || (col < numcols));
|
} while ((row < numrows) || (col < numcols));
|
||||||
|
|
||||||
/* Lastly, if the lower righthand corner is untouched, fill in fixed pattern */
|
// Lastly, if the lower right-hand corner is untouched, fill in fixed pattern
|
||||||
if (!hasBit(numcols - 1, numrows - 1)) {
|
if (noBit(numcols - 1, numrows - 1)) {
|
||||||
setBit(numcols - 1, numrows - 1, true);
|
setBit(numcols - 1, numrows - 1, true);
|
||||||
setBit(numcols - 2, numrows - 2, true);
|
setBit(numcols - 2, numrows - 2, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,9 @@ import com.google.zxing.multi.qrcode.detector.MultiDetector;
|
||||||
import com.google.zxing.qrcode.QRCodeReader;
|
import com.google.zxing.qrcode.QRCodeReader;
|
||||||
import com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData;
|
import com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -97,20 +97,6 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Result> processStructuredAppend(List<Result> results) {
|
static List<Result> processStructuredAppend(List<Result> results) {
|
||||||
boolean hasSA = false;
|
|
||||||
|
|
||||||
// first, check, if there is at least on SA result in the list
|
|
||||||
for (Result result : results) {
|
|
||||||
if (result.getResultMetadata().containsKey(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)) {
|
|
||||||
hasSA = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hasSA) {
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
// it is, second, split the lists and built a new result list
|
|
||||||
List<Result> newResults = new ArrayList<>();
|
List<Result> newResults = new ArrayList<>();
|
||||||
List<Result> saResults = new ArrayList<>();
|
List<Result> saResults = new ArrayList<>();
|
||||||
for (Result result : results) {
|
for (Result result : results) {
|
||||||
|
@ -120,45 +106,32 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar
|
||||||
newResults.add(result);
|
newResults.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (saResults.isEmpty()) {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
// sort and concatenate the SA list items
|
// sort and concatenate the SA list items
|
||||||
Collections.sort(saResults, new SAComparator());
|
Collections.sort(saResults, new SAComparator());
|
||||||
StringBuilder concatedText = new StringBuilder();
|
StringBuilder newText = new StringBuilder();
|
||||||
int rawBytesLen = 0;
|
ByteArrayOutputStream newRawBytes = new ByteArrayOutputStream();
|
||||||
int byteSegmentLength = 0;
|
ByteArrayOutputStream newByteSegment = new ByteArrayOutputStream();
|
||||||
for (Result saResult : saResults) {
|
for (Result saResult : saResults) {
|
||||||
concatedText.append(saResult.getText());
|
newText.append(saResult.getText());
|
||||||
rawBytesLen += saResult.getRawBytes().length;
|
byte[] saBytes = saResult.getRawBytes();
|
||||||
if (saResult.getResultMetadata().containsKey(ResultMetadataType.BYTE_SEGMENTS)) {
|
newRawBytes.write(saBytes, 0, saBytes.length);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Iterable<byte[]> byteSegments =
|
Iterable<byte[]> byteSegments =
|
||||||
(Iterable<byte[]>) saResult.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS);
|
(Iterable<byte[]>) saResult.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS);
|
||||||
|
if (byteSegments != null) {
|
||||||
for (byte[] segment : byteSegments) {
|
for (byte[] segment : byteSegments) {
|
||||||
byteSegmentLength += segment.length;
|
newByteSegment.write(segment, 0, segment.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
byte[] newRawBytes = new byte[rawBytesLen];
|
|
||||||
byte[] newByteSegment = new byte[byteSegmentLength];
|
Result newResult = new Result(newText.toString(), newRawBytes.toByteArray(), NO_POINTS, BarcodeFormat.QR_CODE);
|
||||||
int newRawBytesIndex = 0;
|
if (newByteSegment.size() > 0) {
|
||||||
int byteSegmentIndex = 0;
|
newResult.putMetadata(ResultMetadataType.BYTE_SEGMENTS, Collections.singletonList(newByteSegment.toByteArray()));
|
||||||
for (Result saResult : saResults) {
|
|
||||||
System.arraycopy(saResult.getRawBytes(), 0, newRawBytes, newRawBytesIndex, saResult.getRawBytes().length);
|
|
||||||
newRawBytesIndex += saResult.getRawBytes().length;
|
|
||||||
if (saResult.getResultMetadata().containsKey(ResultMetadataType.BYTE_SEGMENTS)) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Iterable<byte[]> byteSegments =
|
|
||||||
(Iterable<byte[]>) saResult.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS);
|
|
||||||
for (byte[] segment : byteSegments) {
|
|
||||||
System.arraycopy(segment, 0, newByteSegment, byteSegmentIndex, segment.length);
|
|
||||||
byteSegmentIndex += segment.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Result newResult = new Result(concatedText.toString(), newRawBytes, NO_POINTS, BarcodeFormat.QR_CODE);
|
|
||||||
if (byteSegmentLength > 0) {
|
|
||||||
Collection<byte[]> byteSegmentList = new ArrayList<>();
|
|
||||||
byteSegmentList.add(newByteSegment);
|
|
||||||
newResult.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegmentList);
|
|
||||||
}
|
}
|
||||||
newResults.add(newResult);
|
newResults.add(newResult);
|
||||||
return newResults;
|
return newResults;
|
||||||
|
|
|
@ -49,6 +49,7 @@ import java.util.Map;
|
||||||
final class MultiFinderPatternFinder extends FinderPatternFinder {
|
final class MultiFinderPatternFinder extends FinderPatternFinder {
|
||||||
|
|
||||||
private static final FinderPatternInfo[] EMPTY_RESULT_ARRAY = new FinderPatternInfo[0];
|
private static final FinderPatternInfo[] EMPTY_RESULT_ARRAY = new FinderPatternInfo[0];
|
||||||
|
private static final FinderPattern[] EMPTY_FP_ARRAY = new FinderPattern[0];
|
||||||
private static final FinderPattern[][] EMPTY_FP_2D_ARRAY = new FinderPattern[0][];
|
private static final FinderPattern[][] EMPTY_FP_2D_ARRAY = new FinderPattern[0][];
|
||||||
|
|
||||||
// TODO MIN_MODULE_COUNT and MAX_MODULE_COUNT would be great hints to ask the user for
|
// TODO MIN_MODULE_COUNT and MAX_MODULE_COUNT would be great hints to ask the user for
|
||||||
|
@ -85,15 +86,6 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Creates a finder that will search the image for three finder patterns.</p>
|
|
||||||
*
|
|
||||||
* @param image image to search
|
|
||||||
*/
|
|
||||||
MultiFinderPatternFinder(BitMatrix image) {
|
|
||||||
super(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
MultiFinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback) {
|
MultiFinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback) {
|
||||||
super(image, resultPointCallback);
|
super(image, resultPointCallback);
|
||||||
}
|
}
|
||||||
|
@ -117,13 +109,7 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
|
||||||
* Begin HE modifications to safely detect multiple codes of equal size
|
* Begin HE modifications to safely detect multiple codes of equal size
|
||||||
*/
|
*/
|
||||||
if (size == 3) {
|
if (size == 3) {
|
||||||
return new FinderPattern[][]{
|
return new FinderPattern[][] { possibleCenters.toArray(EMPTY_FP_ARRAY) };
|
||||||
new FinderPattern[]{
|
|
||||||
possibleCenters.get(0),
|
|
||||||
possibleCenters.get(1),
|
|
||||||
possibleCenters.get(2)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by estimated module size to speed up the upcoming checks
|
// Sort by estimated module size to speed up the upcoming checks
|
||||||
|
|
|
@ -136,7 +136,8 @@ public final class Code39Writer extends OneDimensionalCodeWriter {
|
||||||
extendedContent.append('%');
|
extendedContent.append('%');
|
||||||
extendedContent.append((char) ('P' + (character - 123)));
|
extendedContent.append((char) ('P' + (character - 123)));
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Requested content contains a non-encodable character: '" + contents.charAt(i) + "'");
|
throw new IllegalArgumentException(
|
||||||
|
"Requested content contains a non-encodable character: '" + contents.charAt(i) + "'");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ public final class MultiFormatUPCEANReader extends OneDReader {
|
||||||
boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A);
|
boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A);
|
||||||
|
|
||||||
if (ean13MayBeUPCA && canReturnUPCA) {
|
if (ean13MayBeUPCA && canReturnUPCA) {
|
||||||
// Transfer the metdata across
|
// Transfer the metadata across
|
||||||
Result resultUPCA = new Result(result.getText().substring(1),
|
Result resultUPCA = new Result(result.getText().substring(1),
|
||||||
result.getRawBytes(),
|
result.getRawBytes(),
|
||||||
result.getResultPoints(),
|
result.getResultPoints(),
|
||||||
|
|
|
@ -397,51 +397,56 @@ public final class RSS14Reader extends AbstractRSSReader {
|
||||||
}
|
}
|
||||||
incrementOdd = true;
|
incrementOdd = true;
|
||||||
incrementEven = true;
|
incrementEven = true;
|
||||||
} else */ if (mismatch == 1) {
|
} else */
|
||||||
if (oddParityBad) {
|
switch (mismatch) {
|
||||||
if (evenParityBad) {
|
case 1:
|
||||||
throw NotFoundException.getNotFoundInstance();
|
if (oddParityBad) {
|
||||||
}
|
if (evenParityBad) {
|
||||||
decrementOdd = true;
|
throw NotFoundException.getNotFoundInstance();
|
||||||
} else {
|
}
|
||||||
if (!evenParityBad) {
|
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
|
||||||
decrementEven = true;
|
|
||||||
}
|
|
||||||
} else if (mismatch == -1) {
|
|
||||||
if (oddParityBad) {
|
|
||||||
if (evenParityBad) {
|
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
|
||||||
incrementOdd = true;
|
|
||||||
} else {
|
|
||||||
if (!evenParityBad) {
|
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
|
||||||
incrementEven = true;
|
|
||||||
}
|
|
||||||
} else if (mismatch == 0) {
|
|
||||||
if (oddParityBad) {
|
|
||||||
if (!evenParityBad) {
|
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
|
||||||
// Both bad
|
|
||||||
if (oddSum < evenSum) {
|
|
||||||
incrementOdd = true;
|
|
||||||
decrementEven = true;
|
|
||||||
} else {
|
|
||||||
decrementOdd = true;
|
decrementOdd = true;
|
||||||
|
} else {
|
||||||
|
if (!evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
|
decrementEven = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
if (oddParityBad) {
|
||||||
|
if (evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
|
incrementOdd = true;
|
||||||
|
} else {
|
||||||
|
if (!evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
incrementEven = true;
|
incrementEven = true;
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
if (evenParityBad) {
|
case 0:
|
||||||
throw NotFoundException.getNotFoundInstance();
|
if (oddParityBad) {
|
||||||
|
if (!evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
|
// Both bad
|
||||||
|
if (oddSum < evenSum) {
|
||||||
|
incrementOdd = true;
|
||||||
|
decrementEven = true;
|
||||||
|
} else {
|
||||||
|
decrementOdd = true;
|
||||||
|
incrementEven = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
|
// Nothing to do!
|
||||||
}
|
}
|
||||||
// Nothing to do!
|
break;
|
||||||
}
|
default:
|
||||||
} else {
|
throw NotFoundException.getNotFoundInstance();
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (incrementOdd) {
|
if (incrementOdd) {
|
||||||
|
|
|
@ -21,48 +21,6 @@ public final class RSSUtils {
|
||||||
|
|
||||||
private RSSUtils() {}
|
private RSSUtils() {}
|
||||||
|
|
||||||
/*
|
|
||||||
static int[] getRSSwidths(int val, int n, int elements, int maxWidth, boolean noNarrow) {
|
|
||||||
int[] widths = new int[elements];
|
|
||||||
int bar;
|
|
||||||
int narrowMask = 0;
|
|
||||||
for (bar = 0; bar < elements - 1; bar++) {
|
|
||||||
narrowMask |= 1 << bar;
|
|
||||||
int elmWidth = 1;
|
|
||||||
int subVal;
|
|
||||||
while (true) {
|
|
||||||
subVal = combins(n - elmWidth - 1, elements - bar - 2);
|
|
||||||
if (noNarrow && (narrowMask == 0) &&
|
|
||||||
(n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
|
|
||||||
subVal -= combins(n - elmWidth - (elements - bar), elements - bar - 2);
|
|
||||||
}
|
|
||||||
if (elements - bar - 1 > 1) {
|
|
||||||
int lessVal = 0;
|
|
||||||
for (int mxwElement = n - elmWidth - (elements - bar - 2);
|
|
||||||
mxwElement > maxWidth;
|
|
||||||
mxwElement--) {
|
|
||||||
lessVal += combins(n - elmWidth - mxwElement - 1, elements - bar - 3);
|
|
||||||
}
|
|
||||||
subVal -= lessVal * (elements - 1 - bar);
|
|
||||||
} else if (n - elmWidth > maxWidth) {
|
|
||||||
subVal--;
|
|
||||||
}
|
|
||||||
val -= subVal;
|
|
||||||
if (val < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
elmWidth++;
|
|
||||||
narrowMask &= ~(1 << bar);
|
|
||||||
}
|
|
||||||
val += subVal;
|
|
||||||
n -= elmWidth;
|
|
||||||
widths[bar] = elmWidth;
|
|
||||||
}
|
|
||||||
widths[bar] = n;
|
|
||||||
return widths;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static int getRSSvalue(int[] widths, int maxWidth, boolean noNarrow) {
|
public static int getRSSvalue(int[] widths, int maxWidth, boolean noNarrow) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (int width : widths) {
|
for (int width : widths) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ final class ExpandedPair {
|
||||||
return this.finderPattern;
|
return this.finderPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mustBeLast() {
|
boolean mustBeLast() {
|
||||||
return this.rightChar == null;
|
return this.rightChar == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,6 @@ final class ExpandedRow {
|
||||||
return this.rowNumber;
|
return this.rowNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isReversed() {
|
|
||||||
return this.wasReversed;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isEquivalent(List<ExpandedPair> otherPairs) {
|
boolean isEquivalent(List<ExpandedPair> otherPairs) {
|
||||||
return this.pairs.equals(otherPairs);
|
return this.pairs.equals(otherPairs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import com.google.zxing.oned.rss.RSSUtils;
|
||||||
import com.google.zxing.oned.rss.expanded.decoders.AbstractExpandedDecoder;
|
import com.google.zxing.oned.rss.expanded.decoders.AbstractExpandedDecoder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -197,7 +198,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
|
|
||||||
List<ExpandedPair> ps = null;
|
List<ExpandedPair> ps = null;
|
||||||
try {
|
try {
|
||||||
ps = checkRows(new ArrayList<ExpandedRow>(), 0);
|
ps = checkRows(new ArrayList<>(), 0);
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
// OK
|
// OK
|
||||||
}
|
}
|
||||||
|
@ -220,21 +221,19 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
}
|
}
|
||||||
this.pairs.addAll(row.getPairs());
|
this.pairs.addAll(row.getPairs());
|
||||||
|
|
||||||
if (!isValidSequence(this.pairs)) {
|
if (isValidSequence(this.pairs)) {
|
||||||
continue;
|
if (checkChecksum()) {
|
||||||
}
|
return this.pairs;
|
||||||
|
}
|
||||||
|
|
||||||
if (checkChecksum()) {
|
List<ExpandedRow> rs = new ArrayList<>(collectedRows);
|
||||||
return this.pairs;
|
rs.add(row);
|
||||||
}
|
try {
|
||||||
|
// Recursion: try to add more rows
|
||||||
List<ExpandedRow> rs = new ArrayList<>(collectedRows);
|
return checkRows(rs, i + 1);
|
||||||
rs.add(row);
|
} catch (NotFoundException e) {
|
||||||
try {
|
// We failed, try the next candidate
|
||||||
// Recursion: try to add more rows
|
}
|
||||||
return checkRows(rs, i + 1);
|
|
||||||
} catch (NotFoundException e) {
|
|
||||||
// We failed, try the next candidate
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,21 +244,19 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
// either complete or a prefix
|
// either complete or a prefix
|
||||||
private static boolean isValidSequence(List<ExpandedPair> pairs) {
|
private static boolean isValidSequence(List<ExpandedPair> pairs) {
|
||||||
for (int[] sequence : FINDER_PATTERN_SEQUENCES) {
|
for (int[] sequence : FINDER_PATTERN_SEQUENCES) {
|
||||||
if (pairs.size() > sequence.length) {
|
if (pairs.size() <= sequence.length) {
|
||||||
continue;
|
boolean stop = true;
|
||||||
}
|
for (int j = 0; j < pairs.size(); j++) {
|
||||||
|
if (pairs.get(j).getFinderPattern().getValue() != sequence[j]) {
|
||||||
boolean stop = true;
|
stop = false;
|
||||||
for (int j = 0; j < pairs.size(); j++) {
|
break;
|
||||||
if (pairs.get(j).getFinderPattern().getValue() != sequence[j]) {
|
}
|
||||||
stop = false;
|
}
|
||||||
break;
|
if (stop) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stop) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -287,7 +284,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
// it will prevent us from detecting the barcode.
|
// it will prevent us from detecting the barcode.
|
||||||
// Try to merge partial rows
|
// Try to merge partial rows
|
||||||
|
|
||||||
// Check whether the row is part of an allready detected row
|
// Check whether the row is part of an already detected row
|
||||||
if (isPartialRow(this.pairs, this.rows)) {
|
if (isPartialRow(this.pairs, this.rows)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -298,30 +295,22 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all the rows that contains only specified pairs
|
// Remove all the rows that contains only specified pairs
|
||||||
private static void removePartialRows(List<ExpandedPair> pairs, List<ExpandedRow> rows) {
|
private static void removePartialRows(Collection<ExpandedPair> pairs, Collection<ExpandedRow> rows) {
|
||||||
for (Iterator<ExpandedRow> iterator = rows.iterator(); iterator.hasNext();) {
|
for (Iterator<ExpandedRow> iterator = rows.iterator(); iterator.hasNext();) {
|
||||||
ExpandedRow r = iterator.next();
|
ExpandedRow r = iterator.next();
|
||||||
if (r.getPairs().size() == pairs.size()) {
|
if (r.getPairs().size() != pairs.size()) {
|
||||||
continue;
|
boolean allFound = true;
|
||||||
}
|
for (ExpandedPair p : r.getPairs()) {
|
||||||
boolean allFound = true;
|
if (!pairs.contains(p)) {
|
||||||
for (ExpandedPair p : r.getPairs()) {
|
allFound = false;
|
||||||
boolean found = false;
|
|
||||||
for (ExpandedPair pp : pairs) {
|
|
||||||
if (p.equals(pp)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (allFound) {
|
||||||
allFound = false;
|
// 'pairs' contains all the pairs from the row 'r'
|
||||||
break;
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (allFound) {
|
|
||||||
// 'pairs' contains all the pairs from the row 'r'
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,13 +639,11 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
oddSum += oddCounts[i];
|
oddSum += oddCounts[i];
|
||||||
}
|
}
|
||||||
int evenChecksumPortion = 0;
|
int evenChecksumPortion = 0;
|
||||||
//int evenSum = 0;
|
|
||||||
for (int i = evenCounts.length - 1; i >= 0; i--) {
|
for (int i = evenCounts.length - 1; i >= 0; i--) {
|
||||||
if (isNotA1left(pattern, isOddPattern, leftChar)) {
|
if (isNotA1left(pattern, isOddPattern, leftChar)) {
|
||||||
int weight = WEIGHTS[weightRowNumber][2 * i + 1];
|
int weight = WEIGHTS[weightRowNumber][2 * i + 1];
|
||||||
evenChecksumPortion += evenCounts[i] * weight;
|
evenChecksumPortion += evenCounts[i] * weight;
|
||||||
}
|
}
|
||||||
//evenSum += evenCounts[i];
|
|
||||||
}
|
}
|
||||||
int checksumPortion = oddChecksumPortion + evenChecksumPortion;
|
int checksumPortion = oddChecksumPortion + evenChecksumPortion;
|
||||||
|
|
||||||
|
@ -705,51 +692,55 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
int mismatch = oddSum + evenSum - numModules;
|
int mismatch = oddSum + evenSum - numModules;
|
||||||
boolean oddParityBad = (oddSum & 0x01) == 1;
|
boolean oddParityBad = (oddSum & 0x01) == 1;
|
||||||
boolean evenParityBad = (evenSum & 0x01) == 0;
|
boolean evenParityBad = (evenSum & 0x01) == 0;
|
||||||
if (mismatch == 1) {
|
switch (mismatch) {
|
||||||
if (oddParityBad) {
|
case 1:
|
||||||
if (evenParityBad) {
|
if (oddParityBad) {
|
||||||
throw NotFoundException.getNotFoundInstance();
|
if (evenParityBad) {
|
||||||
}
|
throw NotFoundException.getNotFoundInstance();
|
||||||
decrementOdd = true;
|
}
|
||||||
} else {
|
|
||||||
if (!evenParityBad) {
|
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
|
||||||
decrementEven = true;
|
|
||||||
}
|
|
||||||
} else if (mismatch == -1) {
|
|
||||||
if (oddParityBad) {
|
|
||||||
if (evenParityBad) {
|
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
|
||||||
incrementOdd = true;
|
|
||||||
} else {
|
|
||||||
if (!evenParityBad) {
|
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
|
||||||
incrementEven = true;
|
|
||||||
}
|
|
||||||
} else if (mismatch == 0) {
|
|
||||||
if (oddParityBad) {
|
|
||||||
if (!evenParityBad) {
|
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
|
||||||
// Both bad
|
|
||||||
if (oddSum < evenSum) {
|
|
||||||
incrementOdd = true;
|
|
||||||
decrementEven = true;
|
|
||||||
} else {
|
|
||||||
decrementOdd = true;
|
decrementOdd = true;
|
||||||
|
} else {
|
||||||
|
if (!evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
|
decrementEven = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
if (oddParityBad) {
|
||||||
|
if (evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
|
incrementOdd = true;
|
||||||
|
} else {
|
||||||
|
if (!evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
incrementEven = true;
|
incrementEven = true;
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
if (evenParityBad) {
|
case 0:
|
||||||
throw NotFoundException.getNotFoundInstance();
|
if (oddParityBad) {
|
||||||
|
if (!evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
|
// Both bad
|
||||||
|
if (oddSum < evenSum) {
|
||||||
|
incrementOdd = true;
|
||||||
|
decrementEven = true;
|
||||||
|
} else {
|
||||||
|
decrementOdd = true;
|
||||||
|
incrementEven = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (evenParityBad) {
|
||||||
|
throw NotFoundException.getNotFoundInstance();
|
||||||
|
}
|
||||||
|
// Nothing to do!
|
||||||
}
|
}
|
||||||
// Nothing to do!
|
break;
|
||||||
}
|
default:
|
||||||
} else {
|
throw NotFoundException.getNotFoundInstance();
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (incrementOdd) {
|
if (incrementOdd) {
|
||||||
|
|
|
@ -59,8 +59,8 @@ final class AI01393xDecoder extends AI01decoder {
|
||||||
buf.append(lastAIdigit);
|
buf.append(lastAIdigit);
|
||||||
buf.append(')');
|
buf.append(')');
|
||||||
|
|
||||||
int firstThreeDigits =
|
int firstThreeDigits = this.getGeneralDecoder().extractNumericValueFromBitArray(
|
||||||
this.getGeneralDecoder().extractNumericValueFromBitArray(HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE, FIRST_THREE_DIGITS_SIZE);
|
HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE, FIRST_THREE_DIGITS_SIZE);
|
||||||
if (firstThreeDigits / 100 == 0) {
|
if (firstThreeDigits / 100 == 0) {
|
||||||
buf.append('0');
|
buf.append('0');
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,8 @@ final class AI01393xDecoder extends AI01decoder {
|
||||||
}
|
}
|
||||||
buf.append(firstThreeDigits);
|
buf.append(firstThreeDigits);
|
||||||
|
|
||||||
DecodedInformation generalInformation =
|
DecodedInformation generalInformation = this.getGeneralDecoder().decodeGeneralPurposeField(
|
||||||
this.getGeneralDecoder().decodeGeneralPurposeField(HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE + FIRST_THREE_DIGITS_SIZE, null);
|
HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE + FIRST_THREE_DIGITS_SIZE, null);
|
||||||
buf.append(generalInformation.getNewString());
|
buf.append(generalInformation.getNewString());
|
||||||
|
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
|
|
@ -70,8 +70,4 @@ final class DecodedNumeric extends DecodedObject {
|
||||||
return this.secondDigit == FNC1;
|
return this.secondDigit == FNC1;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAnyFNC1() {
|
|
||||||
return this.firstDigit == FNC1 || this.secondDigit == FNC1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,12 +276,7 @@ final class FieldParser {
|
||||||
private static String processVariableAI(int aiSize, int variableFieldSize, String rawInformation)
|
private static String processVariableAI(int aiSize, int variableFieldSize, String rawInformation)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
String ai = rawInformation.substring(0, aiSize);
|
String ai = rawInformation.substring(0, aiSize);
|
||||||
int maxSize;
|
int maxSize = Math.min(rawInformation.length(), aiSize + variableFieldSize);
|
||||||
if (rawInformation.length() < aiSize + variableFieldSize) {
|
|
||||||
maxSize = rawInformation.length();
|
|
||||||
} else {
|
|
||||||
maxSize = aiSize + variableFieldSize;
|
|
||||||
}
|
|
||||||
String field = rawInformation.substring(aiSize, maxSize);
|
String field = rawInformation.substring(aiSize, maxSize);
|
||||||
String remaining = rawInformation.substring(maxSize);
|
String remaining = rawInformation.substring(maxSize);
|
||||||
String result = '(' + ai + ')' + field;
|
String result = '(' + ai + ')' + field;
|
||||||
|
|
|
@ -126,7 +126,8 @@ final class GeneralAppIdDecoder {
|
||||||
|
|
||||||
DecodedInformation lastDecoded = parseBlocks();
|
DecodedInformation lastDecoded = parseBlocks();
|
||||||
if (lastDecoded != null && lastDecoded.isRemaining()) {
|
if (lastDecoded != null && lastDecoded.isRemaining()) {
|
||||||
return new DecodedInformation(this.current.getPosition(), this.buffer.toString(), lastDecoded.getRemainingValue());
|
return new DecodedInformation(this.current.getPosition(),
|
||||||
|
this.buffer.toString(), lastDecoded.getRemainingValue());
|
||||||
}
|
}
|
||||||
return new DecodedInformation(this.current.getPosition(), this.buffer.toString());
|
return new DecodedInformation(this.current.getPosition(), this.buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,11 +152,10 @@ public final class Version {
|
||||||
for (int x = 0; x < max; x++) {
|
for (int x = 0; x < max; x++) {
|
||||||
int i = alignmentPatternCenters[x] - 2;
|
int i = alignmentPatternCenters[x] - 2;
|
||||||
for (int y = 0; y < max; y++) {
|
for (int y = 0; y < max; y++) {
|
||||||
if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
|
if ((x != 0 || (y != 0 && y != max - 1)) && (x != max - 1 || y != 0)) {
|
||||||
// No alignment patterns near the three finder patterns
|
bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
|
// else no o alignment patterns near the three finder patterns
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ import com.google.zxing.common.BitMatrix;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -614,7 +613,7 @@ public class FinderPatternFinder {
|
||||||
throw NotFoundException.getNotFoundInstance();
|
throw NotFoundException.getNotFoundInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(possibleCenters, moduleComparator);
|
possibleCenters.sort(moduleComparator);
|
||||||
|
|
||||||
double distortion = Double.MAX_VALUE;
|
double distortion = Double.MAX_VALUE;
|
||||||
double[] squares = new double[3];
|
double[] squares = new double[3];
|
||||||
|
@ -665,7 +664,7 @@ public class FinderPatternFinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Orders by {@link FinderPatternFinder#getEstimatedModuleSize()}</p>
|
* <p>Orders by {@link FinderPattern#getEstimatedModuleSize()}</p>
|
||||||
*/
|
*/
|
||||||
private static final class EstimatedModuleComparator implements Comparator<FinderPattern>, Serializable {
|
private static final class EstimatedModuleComparator implements Comparator<FinderPattern>, Serializable {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,11 +19,10 @@ package com.google.zxing.multi.qrcode;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.BinaryBitmap;
|
import com.google.zxing.BinaryBitmap;
|
||||||
|
@ -62,8 +61,7 @@ public final class MultiQRCodeTestCase extends Assert {
|
||||||
for (Result result : results) {
|
for (Result result : results) {
|
||||||
barcodeContents.add(result.getText());
|
barcodeContents.add(result.getText());
|
||||||
assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
|
assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
|
||||||
Map<ResultMetadataType,Object> metadata = result.getResultMetadata();
|
assertNotNull(result.getResultMetadata());
|
||||||
assertNotNull(metadata);
|
|
||||||
}
|
}
|
||||||
Collection<String> expectedContents = new HashSet<>();
|
Collection<String> expectedContents = new HashSet<>();
|
||||||
expectedContents.add("You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!");
|
expectedContents.add("You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!");
|
||||||
|
@ -78,7 +76,7 @@ public final class MultiQRCodeTestCase extends Assert {
|
||||||
Result sa1 = new Result("SA1", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
Result sa1 = new Result("SA1", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||||
Result sa2 = new Result("SA2", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
Result sa2 = new Result("SA2", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||||
Result sa3 = new Result("SA3", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
Result sa3 = new Result("SA3", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||||
sa1.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (0 << 4) + 2);
|
sa1.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, 2);
|
||||||
sa1.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
sa1.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||||
sa2.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (1 << 4) + 2);
|
sa2.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (1 << 4) + 2);
|
||||||
sa2.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
sa2.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||||
|
@ -88,11 +86,7 @@ public final class MultiQRCodeTestCase extends Assert {
|
||||||
Result nsa = new Result("NotSA", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
Result nsa = new Result("NotSA", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||||
nsa.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
nsa.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||||
|
|
||||||
List<Result> inputs = new ArrayList<>();
|
List<Result> inputs = Arrays.asList(sa3, sa1, nsa, sa2);
|
||||||
inputs.add(sa3);
|
|
||||||
inputs.add(sa1);
|
|
||||||
inputs.add(nsa);
|
|
||||||
inputs.add(sa2);
|
|
||||||
|
|
||||||
List<Result> results = QRCodeMultiReader.processStructuredAppend(inputs);
|
List<Result> results = QRCodeMultiReader.processStructuredAppend(inputs);
|
||||||
assertNotNull(results);
|
assertNotNull(results);
|
||||||
|
|
|
@ -69,7 +69,7 @@ public final class RSSExpandedImage2resultTestCase extends Assert {
|
||||||
null, null, null, null, null, null,
|
null, null, null, null, null, null,
|
||||||
"001750",
|
"001750",
|
||||||
ExpandedProductParsedResult.KILOGRAM,
|
ExpandedProductParsedResult.KILOGRAM,
|
||||||
"3", null, null, null, new HashMap<String,String>());
|
"3", null, null, null, new HashMap<>());
|
||||||
|
|
||||||
assertCorrectImage2result("2.png", expected);
|
assertCorrectImage2result("2.png", expected);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -113,14 +112,7 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(results, new Comparator<Result>() {
|
results.sort(Comparator.comparingInt((Result r) -> getMeta(r).getSegmentIndex()));
|
||||||
@Override
|
|
||||||
public int compare(Result arg0, Result arg1) {
|
|
||||||
PDF417ResultMetadata resultMetadata = getMeta(arg0);
|
|
||||||
PDF417ResultMetadata otherResultMetadata = getMeta(arg1);
|
|
||||||
return resultMetadata.getSegmentIndex() - otherResultMetadata.getSegmentIndex();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
StringBuilder resultText = new StringBuilder();
|
StringBuilder resultText = new StringBuilder();
|
||||||
String fileId = null;
|
String fileId = null;
|
||||||
for (Result result : results) {
|
for (Result result : results) {
|
||||||
|
@ -194,11 +186,7 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||||
for (Path file : getImageFiles()) {
|
for (Path file : getImageFiles()) {
|
||||||
String testImageFileName = file.getFileName().toString();
|
String testImageFileName = file.getFileName().toString();
|
||||||
String fileBaseName = testImageFileName.substring(0, testImageFileName.indexOf('-'));
|
String fileBaseName = testImageFileName.substring(0, testImageFileName.indexOf('-'));
|
||||||
List<Path> files = result.get(fileBaseName);
|
List<Path> files = result.computeIfAbsent(fileBaseName, k -> new ArrayList<>());
|
||||||
if (files == null) {
|
|
||||||
files = new ArrayList<>();
|
|
||||||
result.put(fileBaseName, files);
|
|
||||||
}
|
|
||||||
files.add(file);
|
files.add(file);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -27,82 +27,42 @@ public final class DataMaskTestCase extends Assert {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMask0() {
|
public void testMask0() {
|
||||||
testMaskAcrossDimensions(0, new MaskCondition() {
|
testMaskAcrossDimensions(0, (i, j) -> (i + j) % 2 == 0);
|
||||||
@Override
|
|
||||||
public boolean isMasked(int i, int j) {
|
|
||||||
return (i + j) % 2 == 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMask1() {
|
public void testMask1() {
|
||||||
testMaskAcrossDimensions(1, new MaskCondition() {
|
testMaskAcrossDimensions(1, (i, j) -> i % 2 == 0);
|
||||||
@Override
|
|
||||||
public boolean isMasked(int i, int j) {
|
|
||||||
return i % 2 == 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMask2() {
|
public void testMask2() {
|
||||||
testMaskAcrossDimensions(2, new MaskCondition() {
|
testMaskAcrossDimensions(2, (i, j) -> j % 3 == 0);
|
||||||
@Override
|
|
||||||
public boolean isMasked(int i, int j) {
|
|
||||||
return j % 3 == 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMask3() {
|
public void testMask3() {
|
||||||
testMaskAcrossDimensions(3, new MaskCondition() {
|
testMaskAcrossDimensions(3, (i, j) -> (i + j) % 3 == 0);
|
||||||
@Override
|
|
||||||
public boolean isMasked(int i, int j) {
|
|
||||||
return (i + j) % 3 == 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMask4() {
|
public void testMask4() {
|
||||||
testMaskAcrossDimensions(4, new MaskCondition() {
|
testMaskAcrossDimensions(4, (i, j) -> (i / 2 + j / 3) % 2 == 0);
|
||||||
@Override
|
|
||||||
public boolean isMasked(int i, int j) {
|
|
||||||
return (i / 2 + j / 3) % 2 == 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMask5() {
|
public void testMask5() {
|
||||||
testMaskAcrossDimensions(5, new MaskCondition() {
|
testMaskAcrossDimensions(5, (i, j) -> (i * j) % 2 + (i * j) % 3 == 0);
|
||||||
@Override
|
|
||||||
public boolean isMasked(int i, int j) {
|
|
||||||
return (i * j) % 2 + (i * j) % 3 == 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMask6() {
|
public void testMask6() {
|
||||||
testMaskAcrossDimensions(6, new MaskCondition() {
|
testMaskAcrossDimensions(6, (i, j) -> ((i * j) % 2 + (i * j) % 3) % 2 == 0);
|
||||||
@Override
|
|
||||||
public boolean isMasked(int i, int j) {
|
|
||||||
return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMask7() {
|
public void testMask7() {
|
||||||
testMaskAcrossDimensions(7, new MaskCondition() {
|
testMaskAcrossDimensions(7, (i, j) -> ((i + j) % 2 + (i * j) % 3) % 2 == 0);
|
||||||
@Override
|
|
||||||
public boolean isMasked(int i, int j) {
|
|
||||||
return ((i + j) % 2 + (i * j) % 3) % 2 == 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testMaskAcrossDimensions(int reference, MaskCondition condition) {
|
private static void testMaskAcrossDimensions(int reference, MaskCondition condition) {
|
||||||
|
@ -126,6 +86,7 @@ public final class DataMaskTestCase extends Assert {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
private interface MaskCondition {
|
private interface MaskCondition {
|
||||||
boolean isMasked(int i, int j);
|
boolean isMasked(int i, int j);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>javase</artifactId>
|
<artifactId>javase</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.google.zxing</groupId>
|
<groupId>com.google.zxing</groupId>
|
||||||
<artifactId>zxing-parent</artifactId>
|
<artifactId>zxing-parent</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2016 ZXing authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.j2se;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstraction over Base 64 decoding implementations that work across Java versions.
|
|
||||||
*/
|
|
||||||
abstract class Base64Decoder {
|
|
||||||
|
|
||||||
private static final Base64Decoder INSTANCE;
|
|
||||||
static {
|
|
||||||
Base64Decoder instance;
|
|
||||||
try {
|
|
||||||
Class.forName("java.util.Base64");
|
|
||||||
// If succeeds, then:
|
|
||||||
instance = new Java8Base64Decoder();
|
|
||||||
} catch (ClassNotFoundException cnfe) {
|
|
||||||
instance = new JAXBBase64Decoder();
|
|
||||||
}
|
|
||||||
INSTANCE = instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param s Base-64 encoded string
|
|
||||||
* @return bytes that the string encodes
|
|
||||||
*/
|
|
||||||
abstract byte[] decode(String s);
|
|
||||||
|
|
||||||
static Base64Decoder getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -87,13 +87,10 @@ public final class HtmlAssetTranslator {
|
||||||
String languageArg) throws IOException {
|
String languageArg) throws IOException {
|
||||||
if ("all".equals(languageArg)) {
|
if ("all".equals(languageArg)) {
|
||||||
Collection<String> languages = new ArrayList<>();
|
Collection<String> languages = new ArrayList<>();
|
||||||
DirectoryStream.Filter<Path> fileFilter = new DirectoryStream.Filter<Path>() {
|
DirectoryStream.Filter<Path> fileFilter = entry -> {
|
||||||
@Override
|
String fileName = entry.getFileName().toString();
|
||||||
public boolean accept(Path entry) {
|
return Files.isDirectory(entry) && !Files.isSymbolicLink(entry) &&
|
||||||
String fileName = entry.getFileName().toString();
|
fileName.startsWith("html-") && !"html-en".equals(fileName);
|
||||||
return Files.isDirectory(entry) && !Files.isSymbolicLink(entry) &&
|
|
||||||
fileName.startsWith("html-") && !"html-en".equals(fileName);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(assetsDir, fileFilter)) {
|
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(assetsDir, fileFilter)) {
|
||||||
for (Path languageDir : dirs) {
|
for (Path languageDir : dirs) {
|
||||||
|
@ -132,12 +129,9 @@ public final class HtmlAssetTranslator {
|
||||||
String translationTextTranslated =
|
String translationTextTranslated =
|
||||||
StringsResourceTranslator.translateString("Translated by Google Translate.", language);
|
StringsResourceTranslator.translateString("Translated by Google Translate.", language);
|
||||||
|
|
||||||
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
|
DirectoryStream.Filter<Path> filter = entry -> {
|
||||||
@Override
|
String name = entry.getFileName().toString();
|
||||||
public boolean accept(Path entry) {
|
return name.endsWith(".html") && (filesToTranslate.isEmpty() || filesToTranslate.contains(name));
|
||||||
String name = entry.getFileName().toString();
|
|
||||||
return name.endsWith(".html") && (filesToTranslate.isEmpty() || filesToTranslate.contains(name));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
try (DirectoryStream<Path> files = Files.newDirectoryStream(englishHtmlDir, filter)) {
|
try (DirectoryStream<Path> files = Files.newDirectoryStream(englishHtmlDir, filter)) {
|
||||||
for (Path sourceFile : files) {
|
for (Path sourceFile : files) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates reading URIs as images.
|
* Encapsulates reading URIs as images.
|
||||||
|
@ -60,7 +61,7 @@ public final class ImageReader {
|
||||||
throw new IOException("Unsupported data URI encoding");
|
throw new IOException("Unsupported data URI encoding");
|
||||||
}
|
}
|
||||||
String base64Data = uriString.substring(base64Start + BASE64TOKEN.length());
|
String base64Data = uriString.substring(base64Start + BASE64TOKEN.length());
|
||||||
byte[] imageBytes = Base64Decoder.getInstance().decode(base64Data);
|
byte[] imageBytes = Base64.getDecoder().decode(base64Data);
|
||||||
return ImageIO.read(new ByteArrayInputStream(imageBytes));
|
return ImageIO.read(new ByteArrayInputStream(imageBytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2016 ZXing authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.j2se;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses {@code javax.xml.bind.DatatypeConverter}, which is not (necessarily) present
|
|
||||||
* in Java 9.
|
|
||||||
*/
|
|
||||||
final class JAXBBase64Decoder extends Base64Decoder {
|
|
||||||
@Override
|
|
||||||
byte[] decode(String s) {
|
|
||||||
try {
|
|
||||||
return (byte[]) Class.forName("javax.xml.bind.DatatypeConverter")
|
|
||||||
.getMethod("parseBase64Binary", String.class).invoke(null, s);
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException |
|
|
||||||
NoSuchMethodException | ClassNotFoundException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2016 ZXing authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.j2se;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses {@code java.util.Base64}, available in Java 8 and later
|
|
||||||
*/
|
|
||||||
final class Java8Base64Decoder extends Base64Decoder {
|
|
||||||
@Override
|
|
||||||
byte[] decode(String s) {
|
|
||||||
try {
|
|
||||||
Object decoder = Class.forName("java.util.Base64")
|
|
||||||
.getMethod("getDecoder").invoke(null);
|
|
||||||
return (byte[]) Class.forName("java.util.Base64$Decoder")
|
|
||||||
.getMethod("decode", String.class).invoke(decoder, s);
|
|
||||||
} catch (IllegalAccessException | NoSuchMethodException | ClassNotFoundException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
} catch (InvocationTargetException ite) {
|
|
||||||
throw new IllegalStateException(ite.getCause());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -95,13 +95,9 @@ public final class StringsResourceTranslator {
|
||||||
Path stringsFile = valueDir.resolve("strings.xml");
|
Path stringsFile = valueDir.resolve("strings.xml");
|
||||||
Collection<String> forceRetranslation = Arrays.asList(args).subList(1, args.length);
|
Collection<String> forceRetranslation = Arrays.asList(args).subList(1, args.length);
|
||||||
|
|
||||||
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
|
DirectoryStream.Filter<Path> filter = entry ->
|
||||||
@Override
|
Files.isDirectory(entry) && !Files.isSymbolicLink(entry) &&
|
||||||
public boolean accept(Path entry) {
|
VALUES_DIR_PATTERN.matcher(entry.getFileName().toString()).matches();
|
||||||
return Files.isDirectory(entry) && !Files.isSymbolicLink(entry) &&
|
|
||||||
VALUES_DIR_PATTERN.matcher(entry.getFileName().toString()).matches();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(resDir, filter)) {
|
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(resDir, filter)) {
|
||||||
for (Path dir : dirs) {
|
for (Path dir : dirs) {
|
||||||
translate(stringsFile, dir.resolve("strings.xml"), forceRetranslation);
|
translate(stringsFile, dir.resolve("strings.xml"), forceRetranslation);
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2017 ZXing authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.j2se;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link Base64Decoder}.
|
|
||||||
*/
|
|
||||||
public final class Base64DecoderTestCase extends Assert {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncode() {
|
|
||||||
Base64Decoder decoder = Base64Decoder.getInstance();
|
|
||||||
assertArrayEquals("foo".getBytes(StandardCharsets.UTF_8), decoder.decode("Zm9v"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
42
pom.xml
42
pom.xml
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
<groupId>com.google.zxing</groupId>
|
<groupId>com.google.zxing</groupId>
|
||||||
<artifactId>zxing-parent</artifactId>
|
<artifactId>zxing-parent</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>4.13-beta-3</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -81,12 +81,12 @@
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.7</java.version>
|
<java.version>1.8</java.version>
|
||||||
<proguard.version>6.0.3</proguard.version>
|
<proguard.version>6.1.0</proguard.version>
|
||||||
<proguard.plugin.version>2.0.14</proguard.plugin.version>
|
<proguard.plugin.version>2.0.14</proguard.plugin.version>
|
||||||
<slf4j.version>1.7.25</slf4j.version>
|
<slf4j.version>1.8.0-beta4</slf4j.version>
|
||||||
<!-- This can't reference project.version as some subprojects version differently -->
|
<!-- This can't reference project.version as some subprojects version differently -->
|
||||||
<zxing.version>3.3.4-SNAPSHOT</zxing.version>
|
<zxing.version>3.4.0-SNAPSHOT</zxing.version>
|
||||||
<android.platform>22</android.platform>
|
<android.platform>22</android.platform>
|
||||||
<maven.scm.version>1.9.5</maven.scm.version>
|
<maven.scm.version>1.9.5</maven.scm.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -122,6 +122,10 @@
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-enforcer-plugin</artifactId>
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -154,12 +158,13 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${java.version}</source>
|
<source>${java.version}</source>
|
||||||
<target>${java.version}</target>
|
<target>${java.version}</target>
|
||||||
<compilerArgs>
|
<compilerArgs>
|
||||||
<arg>-Xlint:all</arg>
|
<arg>-Xlint:all</arg>
|
||||||
|
<arg>-Xlint:-serial</arg>
|
||||||
</compilerArgs>
|
</compilerArgs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -228,7 +233,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.1.1</version>
|
<version>3.1.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
@ -336,7 +341,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.simpligility.maven.plugins</groupId>
|
<groupId>com.simpligility.maven.plugins</groupId>
|
||||||
<artifactId>android-maven-plugin</artifactId>
|
<artifactId>android-maven-plugin</artifactId>
|
||||||
<version>4.5.0</version>
|
<version>4.6.0</version>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
|
@ -458,7 +463,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.puppycrawl.tools</groupId>
|
<groupId>com.puppycrawl.tools</groupId>
|
||||||
<artifactId>checkstyle</artifactId>
|
<artifactId>checkstyle</artifactId>
|
||||||
<version>8.18</version>
|
<version>8.20</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -521,7 +526,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>0.8.3</version>
|
<version>0.8.4</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
@ -658,6 +663,7 @@
|
||||||
</licenses>
|
</licenses>
|
||||||
<developers>
|
<developers>
|
||||||
<developer>
|
<developer>
|
||||||
|
<id>zxing-authors</id>
|
||||||
<name>ZXing Authors</name>
|
<name>ZXing Authors</name>
|
||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
|
@ -824,20 +830,6 @@
|
||||||
<module>zxing.appspot.com</module>
|
<module>zxing.appspot.com</module>
|
||||||
</modules>
|
</modules>
|
||||||
</profile>
|
</profile>
|
||||||
<profile>
|
|
||||||
<id>checkstyle</id>
|
|
||||||
<activation>
|
|
||||||
<jdk>[1.8,)</jdk> <!-- won't work with JDK 7 -->
|
|
||||||
</activation>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>javadoc-9</id>
|
<id>javadoc-9</id>
|
||||||
<activation>
|
<activation>
|
||||||
|
|
|
@ -59,8 +59,6 @@
|
||||||
|
|
||||||
<module name="TreeWalker">
|
<module name="TreeWalker">
|
||||||
|
|
||||||
<property name="cacheFile" value="${checkstyle.cache.file}"/>
|
|
||||||
|
|
||||||
<!-- required for SuppressWarningsFilter (and other Suppress* rules not used here) -->
|
<!-- required for SuppressWarningsFilter (and other Suppress* rules not used here) -->
|
||||||
<!-- see http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsHolder -->
|
<!-- see http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsHolder -->
|
||||||
<module name="SuppressWarningsHolder"/>
|
<module name="SuppressWarningsHolder"/>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>zxing.appspot.com</artifactId>
|
<artifactId>zxing.appspot.com</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.google.zxing</groupId>
|
<groupId>com.google.zxing</groupId>
|
||||||
<artifactId>zxing-parent</artifactId>
|
<artifactId>zxing-parent</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>zxingorg</artifactId>
|
<artifactId>zxingorg</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -33,13 +33,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax</groupId>
|
<groupId>javax</groupId>
|
||||||
<artifactId>javaee-web-api</artifactId>
|
<artifactId>javaee-web-api</artifactId>
|
||||||
<version>7.0</version>
|
<version>8.0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>26.0-android</version>
|
<version>27.1-android</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
@ -49,13 +49,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
<version>4.3.22.RELEASE</version> <!-- 5.x requires Java 8 -->
|
<version>5.1.7.RELEASE</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>4.0.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.google.zxing</groupId>
|
<groupId>com.google.zxing</groupId>
|
||||||
<artifactId>zxing-parent</artifactId>
|
<artifactId>zxing-parent</artifactId>
|
||||||
<version>3.3.4-SNAPSHOT</version>
|
<version>3.4.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -77,7 +77,7 @@ public final class DoSFilterTestCase extends Assert {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFilter(Filter filter) throws ServletException {
|
private static void initFilter(Filter filter) throws ServletException {
|
||||||
MockFilterConfig config = new MockFilterConfig();
|
MockFilterConfig config = new MockFilterConfig();
|
||||||
config.addInitParameter("maxAccessPerTime", Integer.toString(MAX_ACCESS_PER_TIME));
|
config.addInitParameter("maxAccessPerTime", Integer.toString(MAX_ACCESS_PER_TIME));
|
||||||
config.addInitParameter("accessTimeSec", "60");
|
config.addInitParameter("accessTimeSec", "60");
|
||||||
|
@ -85,7 +85,7 @@ public final class DoSFilterTestCase extends Assert {
|
||||||
filter.init(config);
|
filter.init(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testRequest(Filter filter, String host, String proxy, int expectedStatus)
|
private static void testRequest(Filter filter, String host, String proxy, int expectedStatus)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
request.setRequestURI("/");
|
request.setRequestURI("/");
|
||||||
|
|
Loading…
Reference in a new issue