Implements decoding of the ITF format.
* - *"ITF" stands for Interleaved Two of Five. This Reader will scan ITF barcode with 6, 10 or 14 digits. - * The checksum is optional and is not applied by this Reader. The consumer of the decoded value - * will have to apply a checksum if required.
+ *"ITF" stands for Interleaved Two of Five. This Reader will scan ITF barcode with 6, 10 or 14 + * digits. The checksum is optional and is not applied by this Reader. The consumer of the decoded + * value will have to apply a checksum if required.
* *http://en.wikipedia.org/wiki/Interleaved_2_of_5 * is a great reference for Interleaved 2 of 5 information.
@@ -126,7 +126,8 @@ public final class ITFReader extends AbstractOneDReader { * @param resultString {@link StringBuffer} to append decoded chars to * @throws ReaderException if decoding could not complete successfully */ - static void decodeMiddle(BitArray row, int payloadStart, int payloadEnd, StringBuffer resultString) throws ReaderException { + static void decodeMiddle(BitArray row, int payloadStart, int payloadEnd, + StringBuffer resultString) throws ReaderException { // Digits are interleaved in pairs - 5 black lines for one digit, and the // 5 @@ -283,9 +284,8 @@ public final class ITFReader extends AbstractOneDReader { */ static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws ReaderException { - // TODO: This is very similar to implementation in AbstractUPCEANReader. Consider if they can be merged to - // a single method. - + // TODO: This is very similar to implementation in AbstractUPCEANReader. Consider if they can be + // merged to a single method. int patternLength = pattern.length; int[] counters = new int[patternLength]; int width = row.getSize(); diff --git a/core/src/com/google/zxing/qrcode/encoder/Encoder.java b/core/src/com/google/zxing/qrcode/encoder/Encoder.java index c9d64a9a1..8d1308193 100644 --- a/core/src/com/google/zxing/qrcode/encoder/Encoder.java +++ b/core/src/com/google/zxing/qrcode/encoder/Encoder.java @@ -99,12 +99,12 @@ public final class Encoder { encode(content, ecLevel, null, qrCode); } - public static void encode(String content, ErrorCorrectionLevel ecLevel, Hashtable hints, QRCode qrCode) - throws WriterException { + public static void encode(String content, ErrorCorrectionLevel ecLevel, Hashtable hints, + QRCode qrCode) throws WriterException { - String characterEncoding = hints == null ? null : (String) hints.get(EncodeHintType.CHARACTER_SET); - if (characterEncoding == null) { - characterEncoding = DEFAULT_BYTE_MODE_ENCODING; + String encoding = hints == null ? null : (String) hints.get(EncodeHintType.CHARACTER_SET); + if (encoding == null) { + encoding = DEFAULT_BYTE_MODE_ENCODING; } // Step 1: Choose the mode (encoding). @@ -112,7 +112,7 @@ public final class Encoder { // Step 2: Append "bytes" into "dataBits" in appropriate encoding. BitVector dataBits = new BitVector(); - appendBytes(content, mode, dataBits, characterEncoding); + appendBytes(content, mode, dataBits, encoding); // Step 3: Initialize QR code that can contain "dataBits". int numInputBytes = dataBits.sizeInBytes(); initQRCode(numInputBytes, ecLevel, mode, qrCode); @@ -121,9 +121,10 @@ public final class Encoder { BitVector headerAndDataBits = new BitVector(); // Step 4.5: Append ECI message if applicable + // TODO: Why is this commented out? /* - if (mode == Mode.BYTE && !DEFAULT_BYTE_MODE_ENCODING.equals(characterEncoding)) { - CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(characterEncoding); + if (mode == Mode.BYTE && !DEFAULT_BYTE_MODE_ENCODING.equals(encoding)) { + CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding); if (eci != null) { appendECI(eci, headerAndDataBits); } @@ -213,10 +214,11 @@ public final class Encoder { } /** - * Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success, modify "qrCode". + * Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success, + * modify "qrCode". */ - private static void initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, QRCode qrCode) - throws WriterException { + private static void initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, + QRCode qrCode) throws WriterException { qrCode.setECLevel(ecLevel); qrCode.setMode(mode); @@ -257,11 +259,13 @@ public final class Encoder { static void terminateBits(int numDataBytes, BitVector bits) throws WriterException { int capacity = numDataBytes << 3; if (bits.size() > capacity) { - throw new WriterException("data bits cannot fit in the QR Code" + bits.size() + " > " + capacity); + throw new WriterException("data bits cannot fit in the QR Code" + bits.size() + " > " + + capacity); } // Append termination bits. See 8.4.8 of JISX0510:2004 (p.24) for details. - // TODO srowen says we can remove this for loop, since the 4 terminator bits are optional if the last byte - // has less than 4 bits left. So it amounts to padding the last byte with zeroes either way. + // TODO: srowen says we can remove this for loop, since the 4 terminator bits are optional if + // the last byte has less than 4 bits left. So it amounts to padding the last byte with zeroes + // either way. for (int i = 0; i < 4 && bits.size() < capacity; ++i) { bits.appendBit(0); } @@ -405,8 +409,8 @@ public final class Encoder { } } if (numTotalBytes != result.sizeInBytes()) { // Should be same. - throw new WriterException("Interleaving error: " + numTotalBytes + " and " + result.sizeInBytes() + - " differ."); + throw new WriterException("Interleaving error: " + numTotalBytes + " and " + + result.sizeInBytes() + " differ."); } } @@ -436,7 +440,8 @@ public final class Encoder { /** * Append length info. On success, store the result in "bits". */ - static void appendLengthInfo(int numLetters, int version, Mode mode, BitVector bits) throws WriterException { + static void appendLengthInfo(int numLetters, int version, Mode mode, BitVector bits) + throws WriterException { int numBits = mode.getCharacterCountBits(Version.getVersionForNumber(version)); if (numLetters > ((1 << numBits) - 1)) { throw new WriterException(numLetters + "is bigger than" + ((1 << numBits) - 1)); @@ -447,7 +452,8 @@ public final class Encoder { /** * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits". */ - static void appendBytes(String content, Mode mode, BitVector bits, String encoding) throws WriterException { + static void appendBytes(String content, Mode mode, BitVector bits, String encoding) + throws WriterException { if (mode.equals(Mode.NUMERIC)) { appendNumericBytes(content, bits); } else if (mode.equals(Mode.ALPHANUMERIC)) { @@ -509,7 +515,8 @@ public final class Encoder { } } - static void append8BitBytes(String content, BitVector bits, String encoding) throws WriterException { + static void append8BitBytes(String content, BitVector bits, String encoding) + throws WriterException { byte[] bytes; try { bytes = content.getBytes(encoding); @@ -549,7 +556,8 @@ public final class Encoder { static void appendECI(CharacterSetECI eci, BitVector bits) { bits.appendBits(Mode.ECI.getBits(), 4); - bits.appendBits(eci.getValue(), 8); // This is correct for values up to 127, which is all we need now + // This is correct for values up to 127, which is all we need now. + bits.appendBits(eci.getValue(), 8); } } diff --git a/core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java b/core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java index 3efd85782..71565864c 100644 --- a/core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java +++ b/core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java @@ -34,7 +34,8 @@ public final class DecodedBitStreamParserTestCase extends TestCase { builder.write(0xF1, 8); builder.write(0xF2, 8); builder.write(0xF3, 8); - String result = DecodedBitStreamParser.decode(builder.toByteArray(), Version.getVersionForNumber(1)).getText(); + String result = DecodedBitStreamParser.decode(builder.toByteArray(), + Version.getVersionForNumber(1)).getText(); assertEquals("\u00f1\u00f2\u00f3", result); } @@ -45,7 +46,8 @@ public final class DecodedBitStreamParserTestCase extends TestCase { builder.write(0xA1, 8); builder.write(0xA2, 8); builder.write(0xA3, 8); - String result = DecodedBitStreamParser.decode(builder.toByteArray(), Version.getVersionForNumber(1)).getText(); + String result = DecodedBitStreamParser.decode(builder.toByteArray(), + Version.getVersionForNumber(1)).getText(); assertEquals("\uff61\uff62\uff63", result); } @@ -58,10 +60,11 @@ public final class DecodedBitStreamParserTestCase extends TestCase { builder.write(0xA1, 8); builder.write(0xA2, 8); builder.write(0xA3, 8); - String result = DecodedBitStreamParser.decode(builder.toByteArray(), Version.getVersionForNumber(1)).getText(); + String result = DecodedBitStreamParser.decode(builder.toByteArray(), + Version.getVersionForNumber(1)).getText(); assertEquals("\u00ed\u00f3\u00fa", result); } // TODO definitely need more tests here -} \ No newline at end of file +}