diff --git a/barcode/pom.xml b/barcode/pom.xml index ab083c4f..083c6a50 100644 --- a/barcode/pom.xml +++ b/barcode/pom.xml @@ -14,14 +14,9 @@ quarkus-core - com.google.zxing - core - ${zxing.version} - - - com.google.zxing - javase - ${zxing.version} + io.quarkiverse.barcode + quarkus-zxing + ${quarkiverse.zxing.version} ${project.groupId} diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/Barcode.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/Barcode.java deleted file mode 100644 index 7123a797..00000000 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/Barcode.java +++ /dev/null @@ -1,139 +0,0 @@ -package io.quarkiverse.renarde.barcode; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Base64; -import java.util.Map; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.EncodeHintType; -import com.google.zxing.WriterException; -import com.google.zxing.client.j2se.MatrixToImageWriter; -import com.google.zxing.common.BitMatrix; -import com.google.zxing.datamatrix.DataMatrixWriter; -import com.google.zxing.oned.Code128Writer; -import com.google.zxing.oned.Code39Writer; -import com.google.zxing.oned.Code93Writer; -import com.google.zxing.oned.EAN13Writer; -import com.google.zxing.oned.EAN8Writer; -import com.google.zxing.oned.UPCAWriter; -import com.google.zxing.oned.UPCEWriter; -import com.google.zxing.qrcode.QRCodeWriter; - -public class Barcode { - - public static BitMatrix code128(String value, int width, int height) { - Code128Writer writer = new Code128Writer(); - return writer.encode(value, BarcodeFormat.CODE_128, width, height, getHints()); - } - - public static String code128Img(String value, int width, int height) { - return dataUriImg(code128(value, width, height)); - } - - public static BitMatrix code39(String value, int width, int height) { - Code39Writer writer = new Code39Writer(); - return writer.encode(value, BarcodeFormat.CODE_39, width, height, getHints()); - } - - public static String code39Img(String value, int width, int height) { - return dataUriImg(code39(value, width, height)); - } - - public static BitMatrix code93(String value, int width, int height) { - Code93Writer writer = new Code93Writer(); - return writer.encode(value, BarcodeFormat.CODE_93, width, height, getHints()); - } - - public static String code93Img(String value, int width, int height) { - return dataUriImg(code93(value, width, height)); - } - - public static BitMatrix ean13(String value, int width, int height) { - EAN13Writer writer = new EAN13Writer(); - return writer.encode(value, BarcodeFormat.EAN_13, width, height, getHints()); - } - - public static String ean13Img(String value, int width, int height) { - return dataUriImg(ean13(value, width, height)); - } - - public static BitMatrix ean8(String value, int width, int height) { - EAN8Writer writer = new EAN8Writer(); - return writer.encode(value, BarcodeFormat.EAN_8, width, height, getHints()); - } - - public static String ean8Img(String value, int width, int height) { - return dataUriImg(ean8(value, width, height)); - } - - public static BitMatrix upcA(String value, int width, int height) { - UPCAWriter writer = new UPCAWriter(); - return writer.encode(value, BarcodeFormat.UPC_A, width, height, getHints()); - } - - public static String upcAImg(String value, int width, int height) { - return dataUriImg(upcA(value, width, height)); - } - - public static BitMatrix upcE(String value, int width, int height) { - UPCEWriter writer = new UPCEWriter(); - return writer.encode(value, BarcodeFormat.UPC_E, width, height, getHints()); - } - - public static String upcEImg(String value, int width, int height) { - return dataUriImg(upcE(value, width, height)); - } - - public static BitMatrix qrCode(String value, int width, int height) { - QRCodeWriter writer = new QRCodeWriter(); - try { - return writer.encode(value, BarcodeFormat.QR_CODE, width, height, getHints()); - } catch (WriterException e) { - throw new RuntimeException(e); - } - } - - public static String qrCodeImg(String value, int width, int height) { - return dataUriImg(qrCode(value, width, height)); - } - - public static BitMatrix dataMatrix(String value, int width, int height) { - DataMatrixWriter writer = new DataMatrixWriter(); - return writer.encode(value, BarcodeFormat.DATA_MATRIX, width, height, getHints()); - } - - public static String dataMatrixImg(String value, int width, int height) { - return dataUriImg(dataMatrix(value, width, height)); - } - - public static String dataUriImg(BitMatrix encoded) { - return dataUriImg(base64ToDataUri(pngToBase64(barcodetoPng(encoded)))); - } - - public static byte[] barcodetoPng(BitMatrix encoded) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - MatrixToImageWriter.writeToStream(encoded, "png", out); - } catch (IOException e) { - throw new RuntimeException(e); - } - return out.toByteArray(); - } - - public static String pngToBase64(byte[] png) { - return Base64.getEncoder().encodeToString(png); - } - - public static String base64ToDataUri(String base64) { - return "data:image/png;base64," + base64; - } - - public static String dataUriImg(String dataUri) { - return ""; - } - - private static Map getHints() { - return Map.of(EncodeHintType.CHARACTER_SET, "UTF-8"); - } -} diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode128Code.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode128Code.java index cbab07b8..618f09c5 100644 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode128Code.java +++ b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode128Code.java @@ -1,6 +1,6 @@ package io.quarkiverse.renarde.barcode.runtime; -import io.quarkiverse.renarde.barcode.Barcode; +import io.quarkiverse.barcode.zxing.ZebraCrossing; import io.quarkus.qute.EngineConfiguration; import io.quarkus.qute.SectionHelperFactory; @@ -8,6 +8,6 @@ public class QuteCode128Code extends QuteBarCode implements SectionHelperFactory { public QuteCode128Code() { - super("code128", Barcode::code128Img); + super("code128", ZebraCrossing::code128Img); } } \ No newline at end of file diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode39Code.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode39Code.java index 6b8bb3af..bd39de40 100644 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode39Code.java +++ b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode39Code.java @@ -1,6 +1,6 @@ package io.quarkiverse.renarde.barcode.runtime; -import io.quarkiverse.renarde.barcode.Barcode; +import io.quarkiverse.barcode.zxing.ZebraCrossing; import io.quarkus.qute.EngineConfiguration; import io.quarkus.qute.SectionHelperFactory; @@ -8,6 +8,6 @@ public class QuteCode39Code extends QuteBarCode implements SectionHelperFactory { public QuteCode39Code() { - super("code39", Barcode::code39Img); + super("code39", ZebraCrossing::code39Img); } } \ No newline at end of file diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode93Code.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode93Code.java index 83da23a3..9c3c8e69 100644 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode93Code.java +++ b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteCode93Code.java @@ -1,6 +1,6 @@ package io.quarkiverse.renarde.barcode.runtime; -import io.quarkiverse.renarde.barcode.Barcode; +import io.quarkiverse.barcode.zxing.ZebraCrossing; import io.quarkus.qute.EngineConfiguration; import io.quarkus.qute.SectionHelperFactory; @@ -8,6 +8,6 @@ public class QuteCode93Code extends QuteBarCode implements SectionHelperFactory { public QuteCode93Code() { - super("code93", Barcode::code93Img); + super("code93", ZebraCrossing::code93Img); } } \ No newline at end of file diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteDataMatrix.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteDataMatrix.java index e67970e9..a83eacd1 100644 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteDataMatrix.java +++ b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteDataMatrix.java @@ -1,6 +1,6 @@ package io.quarkiverse.renarde.barcode.runtime; -import io.quarkiverse.renarde.barcode.Barcode; +import io.quarkiverse.barcode.zxing.ZebraCrossing; import io.quarkus.qute.EngineConfiguration; import io.quarkus.qute.SectionHelperFactory; @@ -8,6 +8,6 @@ public class QuteDataMatrix extends QuteBarCode implements SectionHelperFactory { public QuteDataMatrix() { - super("datamatrix", Barcode::dataMatrixImg); + super("datamatrix", ZebraCrossing::dataMatrixImg); } } \ No newline at end of file diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteEan13Code.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteEan13Code.java index 2768640d..594a1213 100644 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteEan13Code.java +++ b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteEan13Code.java @@ -1,6 +1,6 @@ package io.quarkiverse.renarde.barcode.runtime; -import io.quarkiverse.renarde.barcode.Barcode; +import io.quarkiverse.barcode.zxing.ZebraCrossing; import io.quarkus.qute.EngineConfiguration; import io.quarkus.qute.SectionHelperFactory; @@ -8,6 +8,6 @@ public class QuteEan13Code extends QuteBarCode implements SectionHelperFactory { public QuteEan13Code() { - super("ean13", Barcode::ean13Img); + super("ean13", ZebraCrossing::ean13Img); } } \ No newline at end of file diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteEan8Code.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteEan8Code.java index 013856ff..99c54b40 100644 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteEan8Code.java +++ b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteEan8Code.java @@ -1,6 +1,6 @@ package io.quarkiverse.renarde.barcode.runtime; -import io.quarkiverse.renarde.barcode.Barcode; +import io.quarkiverse.barcode.zxing.ZebraCrossing; import io.quarkus.qute.EngineConfiguration; import io.quarkus.qute.SectionHelperFactory; @@ -8,6 +8,6 @@ public class QuteEan8Code extends QuteBarCode implements SectionHelperFactory { public QuteEan8Code() { - super("ean8", Barcode::ean8Img); + super("ean8", ZebraCrossing::ean8Img); } } \ No newline at end of file diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteQrCode.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteQrCode.java index 0ee7ba59..f1c37d3b 100644 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteQrCode.java +++ b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteQrCode.java @@ -1,6 +1,6 @@ package io.quarkiverse.renarde.barcode.runtime; -import io.quarkiverse.renarde.barcode.Barcode; +import io.quarkiverse.barcode.zxing.ZebraCrossing; import io.quarkus.qute.EngineConfiguration; import io.quarkus.qute.SectionHelperFactory; @@ -8,6 +8,6 @@ public class QuteQrCode extends QuteBarCode implements SectionHelperFactory { public QuteQrCode() { - super("qrcode", Barcode::qrCodeImg); + super("qrcode", ZebraCrossing::qrCodeImg); } } \ No newline at end of file diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteUpcACode.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteUpcACode.java index 546927cc..2b4ef606 100644 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteUpcACode.java +++ b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteUpcACode.java @@ -1,6 +1,6 @@ package io.quarkiverse.renarde.barcode.runtime; -import io.quarkiverse.renarde.barcode.Barcode; +import io.quarkiverse.barcode.zxing.ZebraCrossing; import io.quarkus.qute.EngineConfiguration; import io.quarkus.qute.SectionHelperFactory; @@ -8,6 +8,6 @@ public class QuteUpcACode extends QuteBarCode implements SectionHelperFactory { public QuteUpcACode() { - super("upca", Barcode::upcAImg); + super("upca", ZebraCrossing::upcAImg); } } \ No newline at end of file diff --git a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteUpcECode.java b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteUpcECode.java index e2943a88..5c81daa1 100644 --- a/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteUpcECode.java +++ b/barcode/src/main/java/io/quarkiverse/renarde/barcode/runtime/QuteUpcECode.java @@ -1,6 +1,6 @@ package io.quarkiverse.renarde.barcode.runtime; -import io.quarkiverse.renarde.barcode.Barcode; +import io.quarkiverse.barcode.zxing.ZebraCrossing; import io.quarkus.qute.EngineConfiguration; import io.quarkus.qute.SectionHelperFactory; @@ -8,6 +8,6 @@ public class QuteUpcECode extends QuteBarCode implements SectionHelperFactory { public QuteUpcECode() { - super("upce", Barcode::upcEImg); + super("upce", ZebraCrossing::upcEImg); } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4123ea33..f9676e3c 100644 --- a/pom.xml +++ b/pom.xml @@ -38,8 +38,8 @@ UTF-8 3.15.0.CR1 1.1.16 - 3.5.1 1.0.0 + 0.0.2