mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Return to ISO-8859-1 as default PDF417 encoding, as per discussion of spec in issue #166
This commit is contained in:
parent
5069917c99
commit
b2f059b07b
|
@ -25,9 +25,7 @@ import com.google.zxing.common.CharacterSetECI;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PDF417 high-level encoder following the algorithm described in ISO/IEC 15438:2001(E) in
|
* PDF417 high-level encoder following the algorithm described in ISO/IEC 15438:2001(E) in
|
||||||
|
@ -127,7 +125,7 @@ final class PDF417HighLevelEncoder {
|
||||||
private static final byte[] MIXED = new byte[128];
|
private static final byte[] MIXED = new byte[128];
|
||||||
private static final byte[] PUNCTUATION = new byte[128];
|
private static final byte[] PUNCTUATION = new byte[128];
|
||||||
|
|
||||||
private static final List<String> DEFAULT_ENCODING_NAMES = Arrays.asList("Cp437", "IBM437");
|
private static final Charset DEFAULT_ENCODING = Charset.forName("ISO-8859-1");
|
||||||
|
|
||||||
private PDF417HighLevelEncoder() {
|
private PDF417HighLevelEncoder() {
|
||||||
}
|
}
|
||||||
|
@ -166,7 +164,9 @@ final class PDF417HighLevelEncoder {
|
||||||
//the codewords 0..928 are encoded as Unicode characters
|
//the codewords 0..928 are encoded as Unicode characters
|
||||||
StringBuilder sb = new StringBuilder(msg.length());
|
StringBuilder sb = new StringBuilder(msg.length());
|
||||||
|
|
||||||
if (encoding != null && !DEFAULT_ENCODING_NAMES.contains(encoding.name())) {
|
if (encoding == null) {
|
||||||
|
encoding = DEFAULT_ENCODING;
|
||||||
|
} else if (!DEFAULT_ENCODING.equals(encoding)) {
|
||||||
CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding.name());
|
CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding.name());
|
||||||
if (eci != null) {
|
if (eci != null) {
|
||||||
encodingECI(eci.getValue(), sb);
|
encodingECI(eci.getValue(), sb);
|
||||||
|
@ -183,7 +183,7 @@ final class PDF417HighLevelEncoder {
|
||||||
encodeText(msg, p, len, sb, textSubMode);
|
encodeText(msg, p, len, sb, textSubMode);
|
||||||
|
|
||||||
} else if (compaction == Compaction.BYTE) {
|
} else if (compaction == Compaction.BYTE) {
|
||||||
bytes = toBytes(msg, encoding);
|
bytes = msg.getBytes(encoding);
|
||||||
encodeBinary(bytes, p, bytes.length, BYTE_COMPACTION, sb);
|
encodeBinary(bytes, p, bytes.length, BYTE_COMPACTION, sb);
|
||||||
|
|
||||||
} else if (compaction == Compaction.NUMERIC) {
|
} else if (compaction == Compaction.NUMERIC) {
|
||||||
|
@ -212,7 +212,7 @@ final class PDF417HighLevelEncoder {
|
||||||
p += t;
|
p += t;
|
||||||
} else {
|
} else {
|
||||||
if (bytes == null) {
|
if (bytes == null) {
|
||||||
bytes = toBytes(msg, encoding);
|
bytes = msg.getBytes(encoding);
|
||||||
}
|
}
|
||||||
int b = determineConsecutiveBinaryCount(msg, bytes, p);
|
int b = determineConsecutiveBinaryCount(msg, bytes, p);
|
||||||
if (b == 0) {
|
if (b == 0) {
|
||||||
|
@ -236,24 +236,6 @@ final class PDF417HighLevelEncoder {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] toBytes(String msg, Charset encoding) throws WriterException {
|
|
||||||
// Defer instantiating default Charset until needed, since it may be for an unsupported
|
|
||||||
// encoding. For example the default of Cp437 doesn't seem to exist on Android.
|
|
||||||
if (encoding == null) {
|
|
||||||
for (String encodingName : DEFAULT_ENCODING_NAMES) {
|
|
||||||
try {
|
|
||||||
encoding = Charset.forName(encodingName);
|
|
||||||
} catch (UnsupportedCharsetException uce) {
|
|
||||||
// continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (encoding == null) {
|
|
||||||
throw new WriterException("No support for any encoding: " + DEFAULT_ENCODING_NAMES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return msg.getBytes(encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode parts of the message using Text Compaction as described in ISO/IEC 15438:2001(E),
|
* Encode parts of the message using Text Compaction as described in ISO/IEC 15438:2001(E),
|
||||||
* chapter 4.4.2.
|
* chapter 4.4.2.
|
||||||
|
|
Loading…
Reference in a new issue