mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Catch more weird edge cases where readBits fails on bad QR codes and just return FormatException; remove a deprecated PDF417 method
git-svn-id: https://zxing.googlecode.com/svn/trunk@2542 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
02e0dcece1
commit
cc9a55d1a2
|
@ -22,7 +22,6 @@ import com.google.zxing.Writer;
|
||||||
import com.google.zxing.WriterException;
|
import com.google.zxing.WriterException;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,28 +69,6 @@ public final class PDF417Writer implements Writer {
|
||||||
return encode(contents, format, width, height, null);
|
return encode(contents, format, width, height, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #encode(String, BarcodeFormat, int, int, Map)} instead, with hints to
|
|
||||||
* specify the encoding options.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public BitMatrix encode(String contents,
|
|
||||||
BarcodeFormat format,
|
|
||||||
boolean compact,
|
|
||||||
int width,
|
|
||||||
int height,
|
|
||||||
int minCols,
|
|
||||||
int maxCols,
|
|
||||||
int minRows,
|
|
||||||
int maxRows,
|
|
||||||
Compaction compaction) throws WriterException {
|
|
||||||
Map<EncodeHintType, Object> hints = new EnumMap<EncodeHintType,Object>(EncodeHintType.class);
|
|
||||||
hints.put(EncodeHintType.PDF417_COMPACT, compact);
|
|
||||||
hints.put(EncodeHintType.PDF417_COMPACTION, compaction);
|
|
||||||
hints.put(EncodeHintType.PDF417_DIMENSIONS, new Dimensions(minCols, maxCols, minRows, maxRows));
|
|
||||||
return encode(contents, format, width, height, hints);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes encoder, accounts for width/height, and retrieves bit matrix
|
* Takes encoder, accounts for width/height, and retrieves bit matrix
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -59,9 +59,10 @@ final class DecodedBitStreamParser {
|
||||||
Map<DecodeHintType,?> hints) throws FormatException {
|
Map<DecodeHintType,?> hints) throws FormatException {
|
||||||
BitSource bits = new BitSource(bytes);
|
BitSource bits = new BitSource(bytes);
|
||||||
StringBuilder result = new StringBuilder(50);
|
StringBuilder result = new StringBuilder(50);
|
||||||
|
List<byte[]> byteSegments = new ArrayList<byte[]>(1);
|
||||||
|
try {
|
||||||
CharacterSetECI currentCharacterSetECI = null;
|
CharacterSetECI currentCharacterSetECI = null;
|
||||||
boolean fc1InEffect = false;
|
boolean fc1InEffect = false;
|
||||||
List<byte[]> byteSegments = new ArrayList<byte[]>(1);
|
|
||||||
Mode mode;
|
Mode mode;
|
||||||
do {
|
do {
|
||||||
// While still another segment to read...
|
// While still another segment to read...
|
||||||
|
@ -69,11 +70,7 @@ final class DecodedBitStreamParser {
|
||||||
// OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
|
// OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
|
||||||
mode = Mode.TERMINATOR;
|
mode = Mode.TERMINATOR;
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
|
mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
|
||||||
} catch (IllegalArgumentException iae) {
|
|
||||||
throw FormatException.getFormatInstance();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mode != Mode.TERMINATOR) {
|
if (mode != Mode.TERMINATOR) {
|
||||||
if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
|
if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
|
||||||
|
@ -121,6 +118,10 @@ final class DecodedBitStreamParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (mode != Mode.TERMINATOR);
|
} while (mode != Mode.TERMINATOR);
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
// from readBits() calls
|
||||||
|
throw FormatException.getFormatInstance();
|
||||||
|
}
|
||||||
|
|
||||||
return new DecoderResult(bytes,
|
return new DecoderResult(bytes,
|
||||||
result.toString(),
|
result.toString(),
|
||||||
|
|
Loading…
Reference in a new issue