X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fqrcode%2Fdecoder%2FDecodedBitStreamParser.java;h=55ff636394d173e446e429f7ba751429a6dd5a36;hp=b6efa2b25f41ed2cf02104908bfece154446c393;hb=de6f57f5cfd923b42c2c9665b2db381c3a7a3f53;hpb=d0ff60320c6b6755fbaefa710bdcb25a92c882d8 diff --git a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java index b6efa2b2..55ff6363 100644 --- a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java @@ -16,12 +16,14 @@ package com.google.zxing.qrcode.decoder; +import com.google.zxing.DecodeHintType; import com.google.zxing.ReaderException; import com.google.zxing.common.BitSource; import com.google.zxing.common.CharacterSetECI; import com.google.zxing.common.DecoderResult; import java.io.UnsupportedEncodingException; +import java.util.Hashtable; import java.util.Vector; /** @@ -57,9 +59,10 @@ final class DecodedBitStreamParser { private DecodedBitStreamParser() { } - static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel) throws ReaderException { + static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel, Hashtable hints) + throws ReaderException { BitSource bits = new BitSource(bytes); - StringBuffer result = new StringBuffer(); + StringBuffer result = new StringBuffer(50); CharacterSetECI currentCharacterSetECI = null; boolean fc1InEffect = false; Vector byteSegments = new Vector(1); @@ -99,7 +102,7 @@ final class DecodedBitStreamParser { } else if (mode.equals(Mode.ALPHANUMERIC)) { decodeAlphanumericSegment(bits, result, count, fc1InEffect); } else if (mode.equals(Mode.BYTE)) { - decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments); + decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints); } else if (mode.equals(Mode.KANJI)) { decodeKanjiSegment(bits, result, count); } else { @@ -147,7 +150,8 @@ final class DecodedBitStreamParser { StringBuffer result, int count, CharacterSetECI currentCharacterSetECI, - Vector byteSegments) throws ReaderException { + Vector byteSegments, + Hashtable hints) throws ReaderException { byte[] readBytes = new byte[count]; if (count << 3 > bits.available()) { throw ReaderException.getInstance(); @@ -162,7 +166,7 @@ final class DecodedBitStreamParser { // upon decoding. I have seen ISO-8859-1 used as well as // Shift_JIS -- without anything like an ECI designator to // give a hint. - encoding = guessEncoding(readBytes); + encoding = guessEncoding(readBytes, hints); } else { encoding = currentCharacterSetECI.getEncodingName(); } @@ -240,7 +244,13 @@ final class DecodedBitStreamParser { } } - private static String guessEncoding(byte[] bytes) { + private static String guessEncoding(byte[] bytes, Hashtable hints) { + if (hints != null) { + String characterSet = (String) hints.get(DecodeHintType.CHARACTER_SET); + if (characterSet != null) { + return characterSet; + } + } if (ASSUME_SHIFT_JIS) { return SHIFT_JIS; } @@ -264,7 +274,7 @@ final class DecodedBitStreamParser { boolean lastWasPossibleDoubleByteStart = false; for (int i = 0; i < length && (canBeISO88591 || canBeShiftJIS); i++) { int value = bytes[i] & 0xFF; - if (value == 0xC2 || value == 0xC3 && i < length - 1) { + if ((value == 0xC2 || value == 0xC3) && i < length - 1) { // This is really a poor hack. The slightly more exotic characters people might want to put in // a QR Code, by which I mean the Latin-1 supplement characters (e.g. u-umlaut) have encodings // that start with 0xC2 followed by [0xA0,0xBF], or start with 0xC3 followed by [0x80,0xBF].