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;
/**
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);
} 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 {
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();
// 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();
}
}
}
- 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;
}
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].