From 1cfc5b29899796a18772db07d3f1d103c1140cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Fri, 8 Dec 2023 08:46:23 +0100 Subject: [PATCH] add code39 and qrcode writer based on zxing --- gradle.properties | 2 +- .../src/main/java/module-info.java | 2 +- .../graphics/barcode/render/Code39Writer.java | 31 +++++++++++++------ .../graphics/barcode/render/QRCodeWriter.java | 30 ++++++++++++------ 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/gradle.properties b/gradle.properties index bba1b0a..8b074f5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group = org.xbib.graphics name = graphics -version = 5.3.0 +version = 5.3.1 org.gradle.warning.mode = ALL diff --git a/graphics-barcode/src/main/java/module-info.java b/graphics-barcode/src/main/java/module-info.java index 5251042..ec1dc7f 100644 --- a/graphics-barcode/src/main/java/module-info.java +++ b/graphics-barcode/src/main/java/module-info.java @@ -47,7 +47,7 @@ module org.xbib.graphics.barcode { exports org.xbib.graphics.barcode.util; exports org.xbib.graphics.barcode.render; requires transitive java.desktop; - requires org.xbib.graphics.zxing; + requires transitive org.xbib.graphics.zxing; provides SymbolProvider with AustraliaPost.Provider, AztecCode.Provider, diff --git a/graphics-barcode/src/main/java/org/xbib/graphics/barcode/render/Code39Writer.java b/graphics-barcode/src/main/java/org/xbib/graphics/barcode/render/Code39Writer.java index 5e275cb..c1c548a 100644 --- a/graphics-barcode/src/main/java/org/xbib/graphics/barcode/render/Code39Writer.java +++ b/graphics-barcode/src/main/java/org/xbib/graphics/barcode/render/Code39Writer.java @@ -2,7 +2,6 @@ package org.xbib.graphics.barcode.render; import org.xbib.graphics.zxing.BarcodeFormat; import org.xbib.graphics.zxing.MultiFormatWriter; -import org.xbib.graphics.zxing.NotFoundException; import org.xbib.graphics.zxing.WriterException; import org.xbib.graphics.zxing.common.BitMatrix; @@ -17,21 +16,33 @@ public class Code39Writer { } public void write(String content, Path path, String format, int width, int height) - throws WriterException, IOException, NotFoundException { - BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_39, width, height); - MatrixToImageWriter.writeToPath(matrix, format, path); + throws IOException { + try { + BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_39, width, height); + MatrixToImageWriter.writeToPath(matrix, format, path); + } catch (WriterException e) { + throw new IOException(e); + } } public void write(String content, OutputStream outputStream, String format, int width, int height) - throws WriterException, IOException, NotFoundException { - BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_39, width, height); - MatrixToImageWriter.writeToStream(matrix, format, outputStream); + throws IOException { + try { + BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_39, width, height); + MatrixToImageWriter.writeToStream(matrix, format, outputStream); + } catch (WriterException e) { + throw new IOException(e); + } } public BufferedImage write(String content, int width, int height) - throws WriterException, IOException, NotFoundException { - BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_39, width, height); - return MatrixToImageWriter.toBufferedImage(matrix); + throws IOException { + try { + BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_39, width, height); + return MatrixToImageWriter.toBufferedImage(matrix); + } catch (WriterException e) { + throw new IOException(e); + } } } diff --git a/graphics-barcode/src/main/java/org/xbib/graphics/barcode/render/QRCodeWriter.java b/graphics-barcode/src/main/java/org/xbib/graphics/barcode/render/QRCodeWriter.java index 7e12527..e808cfa 100644 --- a/graphics-barcode/src/main/java/org/xbib/graphics/barcode/render/QRCodeWriter.java +++ b/graphics-barcode/src/main/java/org/xbib/graphics/barcode/render/QRCodeWriter.java @@ -18,20 +18,32 @@ public class QRCodeWriter { } public void write(String content, Path path, String format, int width, int height) - throws WriterException, IOException, NotFoundException { - BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height); - MatrixToImageWriter.writeToPath(matrix, format, path); + throws IOException { + try { + BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height); + MatrixToImageWriter.writeToPath(matrix, format, path); + } catch (WriterException e) { + throw new IOException(e); + } } public void write(String content, OutputStream outputStream, String format, int width, int height) - throws WriterException, IOException, NotFoundException { - BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height); - MatrixToImageWriter.writeToStream(matrix, format, outputStream); + throws IOException { + try { + BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height); + MatrixToImageWriter.writeToStream(matrix, format, outputStream); + } catch (WriterException e) { + throw new IOException(e); + } } public BufferedImage write(String content, int width, int height) - throws WriterException, IOException, NotFoundException { - BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height); - return MatrixToImageWriter.toBufferedImage(matrix); + throws IOException { + try { + BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height); + return MatrixToImageWriter.toBufferedImage(matrix); + } catch (WriterException e) { + throw new IOException(e); + } } }