Loading src/main/java/org/sw4j/tool/barcode/random/config/CodeType.java +14 −1 Original line number Diff line number Diff line Loading @@ -28,12 +28,25 @@ import java.util.Map; */ public enum CodeType { /** * <p> * Barcode type Aztec Code. * </p> */ AZTEC("aztec", BarcodeFormat.AZTEC), /** * <p> * Barcode type Data Matrix. * </p> */ DATAMATRIX("datamatrix", BarcodeFormat.DATA_MATRIX), /** * <p> * Barcode type QR code. * </p> */ QRCODE("qrcode", BarcodeFormat.QR_CODE); QRCODE("qrcode", BarcodeFormat.QR_CODE), ; /** * <p> Loading src/main/java/org/sw4j/tool/barcode/random/generator/BarcodeWriter.java +8 −1 Original line number Diff line number Diff line Loading @@ -127,8 +127,15 @@ public class BarcodeWriter implements Consumer<RandomIdent> { encodingParameters.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); } break; case AZTEC: if (codeConfig.getErrorCorrection() == null || "".equals(codeConfig.getErrorCorrection())) { encodingParameters.put(EncodeHintType.ERROR_CORRECTION, "25"); } else { encodingParameters.put(EncodeHintType.ERROR_CORRECTION, codeConfig.getErrorCorrection()); } break; default: logger.warning("This point should never be reached."); // No error correction for the remaining codes } } Loading src/site/markdown/configuration.md.vm +4 −2 Original line number Diff line number Diff line Loading @@ -162,9 +162,11 @@ Currently supported encodings: $h4 Barcodes Currently supported barcodes and error corrections (default error correction emphasized): Currently supported barcodes and possible error corrections (default error correction emphasized): * QR-Code (L, M, Q, **H**) * aztec * datamatrix (**25** to 100) * qrcode (L, M, Q, **H**) $h4 Filetypes Loading src/test/java/org/sw4j/tool/barcode/random/generator/BarCodeWriterNGTest.java +110 −8 Original line number Diff line number Diff line Loading @@ -21,13 +21,14 @@ import com.google.zxing.BinaryBitmap; import com.google.zxing.LuminanceSource; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.aztec.AztecReader; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.datamatrix.DataMatrixReader; import com.google.zxing.qrcode.QRCodeReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import javax.imageio.ImageIO; Loading Loading @@ -80,7 +81,7 @@ public class BarCodeWriterNGTest { } @Test(dataProvider = "fileTypes") public void generateQrCodeNoUrlWithDefaultSize(String fileType) throws IOException, ReaderException { public void generateQrCodeNoUrl(String fileType) throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("qrcode") .setEncoding("hex") Loading @@ -96,7 +97,112 @@ public class BarCodeWriterNGTest { barcodeWriter.accept(randomIdent); ByteArrayOutputStream baos = codeData.getOutputs().get(String.format("qrcode-hex-0000.%s", fileType)); BinaryBitmap image = readCode(codeData, "qrcode", fileType); QRCodeReader qrCodeReader = new QRCodeReader(); Result barcodeContent = qrCodeReader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the QR Code."); } @Test public void generateQrCode() throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("qrcode") .setEncoding("hex") .setFiletype("png") .build(); TestCodeData codeData = new TestCodeData(null, null); BarcodeWriter barcodeWriter = new BarcodeWriter(codeConfig, codeData); RandomIdent randomIdent = new RandomIdent("0000", 128, new PredictableRandom(new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), Collections.singleton("hex")); barcodeWriter.accept(randomIdent); BinaryBitmap image = readCode(codeData, "qrcode", "png"); QRCodeReader reader = new QRCodeReader(); Result barcodeContent = reader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the QR Code."); } @Test public void generateDataMatrix() throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("datamatrix") .setEncoding("hex") .setFiletype("png") .build(); TestCodeData codeData = new TestCodeData(null, null); BarcodeWriter barcodeWriter = new BarcodeWriter(codeConfig, codeData); RandomIdent randomIdent = new RandomIdent("0000", 128, new PredictableRandom(new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), Collections.singleton("hex")); barcodeWriter.accept(randomIdent); BinaryBitmap image = readCode(codeData, "datamatrix", "png"); DataMatrixReader reader = new DataMatrixReader(); Result barcodeContent = reader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the Data Matrix."); } @Test public void generateAztec() throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("aztec") .setEncoding("hex") .setFiletype("png") .build(); TestCodeData codeData = new TestCodeData(null, null); BarcodeWriter barcodeWriter = new BarcodeWriter(codeConfig, codeData); RandomIdent randomIdent = new RandomIdent("0000", 128, new PredictableRandom(new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), Collections.singleton("hex")); barcodeWriter.accept(randomIdent); BinaryBitmap image = readCode(codeData, "aztec", "png"); AztecReader reader = new AztecReader(); Result barcodeContent = reader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the Aztec Code."); } @Test public void generateAztecWithErrorCorrection() throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("aztec") .setEncoding("hex") .setErrorCorrection("50") .setFiletype("png") .build(); TestCodeData codeData = new TestCodeData(null, null); BarcodeWriter barcodeWriter = new BarcodeWriter(codeConfig, codeData); RandomIdent randomIdent = new RandomIdent("0000", 128, new PredictableRandom(new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), Collections.singleton("hex")); barcodeWriter.accept(randomIdent); BinaryBitmap image = readCode(codeData, "aztec", "png"); AztecReader reader = new AztecReader(); Result barcodeContent = reader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the Aztec Code."); } private BinaryBitmap readCode(TestCodeData codeData, String codeType, String fileType) throws IOException { ByteArrayOutputStream baos = codeData.getOutputs().get(String.format("%s-hex-0000.%s", codeType, fileType)); assertNotNull(baos, "Expected an OutputStream to be returned."); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ImageInputStream iis = ImageIO.createImageInputStream(bais); Loading @@ -108,14 +214,10 @@ public class BarCodeWriterNGTest { ir.setInput(iis); assertEquals(ir.getWidth(0), 200, "Expected the image to be 200px wide."); assertEquals(ir.getHeight(0), 200, "Expected the image to be 200px high"); LuminanceSource source = new BufferedImageLuminanceSource(ir.read(0)); Binarizer binarizer = new HybridBinarizer(source); BinaryBitmap image = new BinaryBitmap(binarizer); QRCodeReader qrCodeReader = new QRCodeReader(); Result barcodeContent = qrCodeReader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the QR Code."); return image; } } Loading
src/main/java/org/sw4j/tool/barcode/random/config/CodeType.java +14 −1 Original line number Diff line number Diff line Loading @@ -28,12 +28,25 @@ import java.util.Map; */ public enum CodeType { /** * <p> * Barcode type Aztec Code. * </p> */ AZTEC("aztec", BarcodeFormat.AZTEC), /** * <p> * Barcode type Data Matrix. * </p> */ DATAMATRIX("datamatrix", BarcodeFormat.DATA_MATRIX), /** * <p> * Barcode type QR code. * </p> */ QRCODE("qrcode", BarcodeFormat.QR_CODE); QRCODE("qrcode", BarcodeFormat.QR_CODE), ; /** * <p> Loading
src/main/java/org/sw4j/tool/barcode/random/generator/BarcodeWriter.java +8 −1 Original line number Diff line number Diff line Loading @@ -127,8 +127,15 @@ public class BarcodeWriter implements Consumer<RandomIdent> { encodingParameters.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); } break; case AZTEC: if (codeConfig.getErrorCorrection() == null || "".equals(codeConfig.getErrorCorrection())) { encodingParameters.put(EncodeHintType.ERROR_CORRECTION, "25"); } else { encodingParameters.put(EncodeHintType.ERROR_CORRECTION, codeConfig.getErrorCorrection()); } break; default: logger.warning("This point should never be reached."); // No error correction for the remaining codes } } Loading
src/site/markdown/configuration.md.vm +4 −2 Original line number Diff line number Diff line Loading @@ -162,9 +162,11 @@ Currently supported encodings: $h4 Barcodes Currently supported barcodes and error corrections (default error correction emphasized): Currently supported barcodes and possible error corrections (default error correction emphasized): * QR-Code (L, M, Q, **H**) * aztec * datamatrix (**25** to 100) * qrcode (L, M, Q, **H**) $h4 Filetypes Loading
src/test/java/org/sw4j/tool/barcode/random/generator/BarCodeWriterNGTest.java +110 −8 Original line number Diff line number Diff line Loading @@ -21,13 +21,14 @@ import com.google.zxing.BinaryBitmap; import com.google.zxing.LuminanceSource; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.aztec.AztecReader; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.datamatrix.DataMatrixReader; import com.google.zxing.qrcode.QRCodeReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import javax.imageio.ImageIO; Loading Loading @@ -80,7 +81,7 @@ public class BarCodeWriterNGTest { } @Test(dataProvider = "fileTypes") public void generateQrCodeNoUrlWithDefaultSize(String fileType) throws IOException, ReaderException { public void generateQrCodeNoUrl(String fileType) throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("qrcode") .setEncoding("hex") Loading @@ -96,7 +97,112 @@ public class BarCodeWriterNGTest { barcodeWriter.accept(randomIdent); ByteArrayOutputStream baos = codeData.getOutputs().get(String.format("qrcode-hex-0000.%s", fileType)); BinaryBitmap image = readCode(codeData, "qrcode", fileType); QRCodeReader qrCodeReader = new QRCodeReader(); Result barcodeContent = qrCodeReader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the QR Code."); } @Test public void generateQrCode() throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("qrcode") .setEncoding("hex") .setFiletype("png") .build(); TestCodeData codeData = new TestCodeData(null, null); BarcodeWriter barcodeWriter = new BarcodeWriter(codeConfig, codeData); RandomIdent randomIdent = new RandomIdent("0000", 128, new PredictableRandom(new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), Collections.singleton("hex")); barcodeWriter.accept(randomIdent); BinaryBitmap image = readCode(codeData, "qrcode", "png"); QRCodeReader reader = new QRCodeReader(); Result barcodeContent = reader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the QR Code."); } @Test public void generateDataMatrix() throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("datamatrix") .setEncoding("hex") .setFiletype("png") .build(); TestCodeData codeData = new TestCodeData(null, null); BarcodeWriter barcodeWriter = new BarcodeWriter(codeConfig, codeData); RandomIdent randomIdent = new RandomIdent("0000", 128, new PredictableRandom(new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), Collections.singleton("hex")); barcodeWriter.accept(randomIdent); BinaryBitmap image = readCode(codeData, "datamatrix", "png"); DataMatrixReader reader = new DataMatrixReader(); Result barcodeContent = reader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the Data Matrix."); } @Test public void generateAztec() throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("aztec") .setEncoding("hex") .setFiletype("png") .build(); TestCodeData codeData = new TestCodeData(null, null); BarcodeWriter barcodeWriter = new BarcodeWriter(codeConfig, codeData); RandomIdent randomIdent = new RandomIdent("0000", 128, new PredictableRandom(new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), Collections.singleton("hex")); barcodeWriter.accept(randomIdent); BinaryBitmap image = readCode(codeData, "aztec", "png"); AztecReader reader = new AztecReader(); Result barcodeContent = reader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the Aztec Code."); } @Test public void generateAztecWithErrorCorrection() throws IOException, ReaderException { CodeConfig codeConfig = CodeConfig.builder() .setType("aztec") .setEncoding("hex") .setErrorCorrection("50") .setFiletype("png") .build(); TestCodeData codeData = new TestCodeData(null, null); BarcodeWriter barcodeWriter = new BarcodeWriter(codeConfig, codeData); RandomIdent randomIdent = new RandomIdent("0000", 128, new PredictableRandom(new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), Collections.singleton("hex")); barcodeWriter.accept(randomIdent); BinaryBitmap image = readCode(codeData, "aztec", "png"); AztecReader reader = new AztecReader(); Result barcodeContent = reader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the Aztec Code."); } private BinaryBitmap readCode(TestCodeData codeData, String codeType, String fileType) throws IOException { ByteArrayOutputStream baos = codeData.getOutputs().get(String.format("%s-hex-0000.%s", codeType, fileType)); assertNotNull(baos, "Expected an OutputStream to be returned."); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ImageInputStream iis = ImageIO.createImageInputStream(bais); Loading @@ -108,14 +214,10 @@ public class BarCodeWriterNGTest { ir.setInput(iis); assertEquals(ir.getWidth(0), 200, "Expected the image to be 200px wide."); assertEquals(ir.getHeight(0), 200, "Expected the image to be 200px high"); LuminanceSource source = new BufferedImageLuminanceSource(ir.read(0)); Binarizer binarizer = new HybridBinarizer(source); BinaryBitmap image = new BinaryBitmap(binarizer); QRCodeReader qrCodeReader = new QRCodeReader(); Result barcodeContent = qrCodeReader.decode(image); assertEquals(barcodeContent.getText(), "00000000000000000000000000000000", "Expected the result to be encoded in the QR Code."); return image; } }