From b20a607d29501e9577c23ac723e4105582b284c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dani=C3=ABl=20van=20der=20Garde?=
<12891775+daanggc@users.noreply.github.com>
Date: Tue, 23 Apr 2024 08:56:32 +0200
Subject: [PATCH] Added: MaxiCode support (#224)
* Added: MaxiCode support
* Improved: Slight finetune on maxicode linux fix
---
.../Elements/ZplMaxiCode.cs | 85 +++++++++
.../BinaryKits.Zpl.Viewer.WebApi.csproj | 6 +
.../Labels/Example/Example12-102x152.zpl2 | 110 ++++++++++++
.../Labels/Test/MaxiCode-102x152.zpl2 | 27 +++
.../BinaryKits.Zpl.Viewer.csproj | 1 +
.../FieldDataZplCommandAnalyzer.cs | 5 +
.../FieldHexadecimalZplCommandAnalyzer.cs | 1 +
.../FieldSeparatorZplCommandAnalyzer.cs | 1 +
.../MaxiCodeBarcodeZplCommandAnalyzer.cs | 43 +++++
.../ElementDrawers/MaxiCodeElementDrawer.cs | 162 ++++++++++++++++++
.../Models/MaxiCodeBarcodeFieldData.cs | 12 ++
src/BinaryKits.Zpl.Viewer/VirtualPrinter.cs | 11 ++
src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs | 1 +
src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs | 1 +
14 files changed, 466 insertions(+)
create mode 100644 src/BinaryKits.Zpl.Label/Elements/ZplMaxiCode.cs
create mode 100644 src/BinaryKits.Zpl.Viewer.WebApi/Labels/Example/Example12-102x152.zpl2
create mode 100644 src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/MaxiCode-102x152.zpl2
create mode 100644 src/BinaryKits.Zpl.Viewer/CommandAnalyzers/MaxiCodeBarcodeZplCommandAnalyzer.cs
create mode 100644 src/BinaryKits.Zpl.Viewer/ElementDrawers/MaxiCodeElementDrawer.cs
create mode 100644 src/BinaryKits.Zpl.Viewer/Models/MaxiCodeBarcodeFieldData.cs
diff --git a/src/BinaryKits.Zpl.Label/Elements/ZplMaxiCode.cs b/src/BinaryKits.Zpl.Label/Elements/ZplMaxiCode.cs
new file mode 100644
index 00000000..41cb728d
--- /dev/null
+++ b/src/BinaryKits.Zpl.Label/Elements/ZplMaxiCode.cs
@@ -0,0 +1,85 @@
+using System.Collections.Generic;
+using System.Text;
+
+namespace BinaryKits.Zpl.Label.Elements
+{
+ public class ZplMaxiCode : ZplPositionedElementBase, IFormatElement
+ {
+ public string Content { get; protected set; }
+
+ public int Mode { get; private set; }
+
+ public int Position { get; private set; }
+
+ public int Total { get; private set; }
+
+ public bool UseHexadecimalIndicator { get; protected set; }
+
+ ///
+ /// Zpl QrCode
+ ///
+ ///
+ ///
+ ///
+ /// 2 (numeric postal code) Default, 3 (alphanumeric postal code), 4 (standard), 5 (full EEC), and 6 (reader programming)
+ /// 1-8, (default: 1)
+ /// 1-8, (default: 1)
+ ///
+ ///
+ public ZplMaxiCode(
+ string content,
+ int positionX,
+ int positionY,
+ int mode = 2,
+ int position = 1,
+ int total = 1,
+ bool useHexadecimalIndicator = false,
+ bool bottomToTop = false)
+ : base(positionX, positionY, bottomToTop)
+ {
+ Content = content;
+ Mode = mode;
+ Position = position;
+ Total = total;
+ UseHexadecimalIndicator = useHexadecimalIndicator;
+ }
+
+ ///
+ public override IEnumerable Render(ZplRenderOptions context)
+ {
+ //^FO100,100
+ //^BD2,1,1
+ //^FH^FD002840100450000_5B)>_1E01_1D961Z00136071_1DUPSN_1D123X56_1D028_1D_1D001/001_1D011_1DN_1D_1DNEW YORK_1DNY_1E_04^FS
+ var result = new List();
+ result.AddRange(RenderPosition(context));
+ result.Add($"^BD{Mode},{Position},{Total}");
+ result.Add(RenderFieldDataSection());
+
+ return result;
+ }
+
+ protected string RenderFieldDataSection()
+ {
+ var sb = new StringBuilder();
+ if (UseHexadecimalIndicator)
+ {
+ sb.Append("^FH");
+ }
+
+ if (Content != null)
+ {
+ sb.Append("^FD");
+ sb.Append(Content);
+ sb.Append("^FS");
+ }
+
+ return sb.ToString();
+ }
+
+ ///
+ public void SetTemplateContent(string content)
+ {
+ Content = content;
+ }
+ }
+}
diff --git a/src/BinaryKits.Zpl.Viewer.WebApi/BinaryKits.Zpl.Viewer.WebApi.csproj b/src/BinaryKits.Zpl.Viewer.WebApi/BinaryKits.Zpl.Viewer.WebApi.csproj
index a356bd39..7305539f 100644
--- a/src/BinaryKits.Zpl.Viewer.WebApi/BinaryKits.Zpl.Viewer.WebApi.csproj
+++ b/src/BinaryKits.Zpl.Viewer.WebApi/BinaryKits.Zpl.Viewer.WebApi.csproj
@@ -126,6 +126,9 @@
PreserveNewest
+
+ PreserveNewest
+
PreserveNewest
@@ -138,6 +141,9 @@
PreserveNewest
+
+ PreserveNewest
+
diff --git a/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Example/Example12-102x152.zpl2 b/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Example/Example12-102x152.zpl2
new file mode 100644
index 00000000..f5de016a
--- /dev/null
+++ b/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Example/Example12-102x152.zpl2
@@ -0,0 +1,110 @@
+^XA
+^LRN
+^MNY
+^MFN,N
+^LH10,12
+^MCY
+^FX POI
+^PW812
+^CI27
+
+^FX Mode 2 Zebra example 1
+^FO20,435
+^BD2^FH^FD002840100450000_5B)>_1E01_1D961Z00136071_1DUPSN_1D123X56_1D028_1D_1D001/001_1D011_1DN_1D_1DNEW YORK_1DNY_1E_04^FS
+
+^FO620,1140
+^GFA,00969,00969,019,FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
+F0000000000001F8000000000000F000000000
+F0000000000001F8000000000000F000000000
+F0000000003F81F83FC000000000F000000000
+F0000000003F81F83FC000000000F000000000
+F000000000FFF9F9FFF000000000F000000000
+F000000000FFF9F9FFF000000000F000000000
+F000000000FFFFFFFFFC00000000F000000000
+F000000000FFFFFFFFFC00000000F000000000
+F000000000F07FFFF0FC00000000F000000000
+F000000000F07FFFF0FC00000000F000000000
+F000000000FC1FFFC3F000000000F000000000
+F000000000FC1FFFC3F000000000F000000000
+F000000000FFFFFFFFF000000000F000000000
+F000000000FFFFFFFFF000000000F000000000
+F0000000003FFFFFFFC000000000F000000000
+F0000000003FFFFFFFC000000000F000000000
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
+F00000000001FFFFF00000000000F000000000
+F00000000001FFFFF00000000000F000000000
+F00000000003FFF9FC0000000000F000000000
+F00000000003FFF9FC0000000000F000000000
+F0000000003FE1F87FC000000000F000000000
+F0000000003FE1F87FC000000000F000000000
+F000000000FF81F83FF000000000F000000000
+F000000000FF81F83FF000000000F000000000
+F000000000FE01F803F000000000F000000000
+F000000000FE01F803F000000000F000000000
+F000000000F001F800F000000000F000000000
+F000000000F001F800F000000000F000000000
+F0000000000001F8000000000000F000000000
+F0000000000001F8000000000000F0FFDC1C00
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF0FFDC1C00
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1E3C00
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1E3C00
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1A2C00
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1B6C00
+FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1B6C00
+0000000000000000000000000000000C1B6C00
+0000000000000000000000000000000C19CC00
+0000000000000000000000000000000C19CC00
+0000000000000000000000000000000C19CC00
+0000000000000000000000000000000C188C00
+00000000000000000000000000000000000000
+00000000000000000000000000000000000000
+00000000000000000000000000000000000000
+^DN
+^FT55,587^A0N,175,220^FVH^FS
+^FT15,23^A0N,20,24^FVBEE CHEW^FS
+^FT15,42^A0N,20,24^FV1234567898 1^FS
+^FT15,61^A0N,20,24^FVABC ASSOCIATES^FS
+^FT15,81^A0N,20,24^FV34 QUEEN ST^FS
+^FT15,100^A0N,20,24^FVTIMONIUM MD 21093^FS
+^FT60,181^A0N,26,30^FVSHIP TO ATTN NAME^FS
+^FT60,208^A0N,26,30^FV1234567890^FS
+^FT60,236^A0N,26,30^FVSUNGJIN^FS
+^FT60,263^A0N,26,30^FV34 QUEEN ST^FS
+^FT60,307^A0N,45,44^FVTIMONIUM MD 21093^FS
+^FT380,30^A0N,30,34^FV102 LBS ^FS
+^FT673,34^A0N,28,32^FV 1 OF 2^FS
+^FT500,69^A0N,22,26^FVDWT: 7,5,2^FS
+^FT500,91^A0N,22,26^FVAH ^FS
+^FT620,736^A0N,100,76^FV ^FS
+^FO677,640^GB123,123,122^FS
+
+^FT300,618^BY3^BCN,103,N,N,,A^FV42021093^FS
+
+^FT290,493^A0N,80,70^FVMD 211 9-65^FS
+^FT10,704^A0N,56,58^FVUPS GROUND^FS
+^FT10,737^A0N,26,30^FVTRACKING #: 1Z RW0 175 03 9990 5329^FS
+^FO0,762^GB800,4,4^FS
+
+^FT790,1039^A0N,22,26^FV ^FS
+^FT10,1035^A0N,22,26^FVBILLING: ^FS
+^FT126,1035^A0N,22,26^FVP/P ^FS
+^FT10,1059^A0N,22,26^FVDESC: Description^FS
+^FT15,153^A0N,28,32^FVSHIP TO: ^FS
+^FO0,637^GB798,14,14^FS
+
+^FO0,997^GB800,14,14^FS
+
+^FO0,416^GB800,4,4^FS
+
+^FO240,416^GB3,221,3^FS
+
+^FT190,1188^A0N,14,20^FVXOL 18.09.09 NV45 06.0A 10/2018^FS
+^FT105,982^BY3^BCN,202,N,N,,A^FV1ZRW01750399905329^FS
+
+^FT273,896^A0N,95,74^FVSAMPLE^FS
+^XZ^XZ
diff --git a/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/MaxiCode-102x152.zpl2 b/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/MaxiCode-102x152.zpl2
new file mode 100644
index 00000000..8786a6cf
--- /dev/null
+++ b/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/MaxiCode-102x152.zpl2
@@ -0,0 +1,27 @@
+^XA
+
+^FX Mode 2 Zebra example 1
+^FO10,10
+^BD2^FH^FD002840100450000_5B)>_1E01_1D961Z00136071_1DUPSN_1D123X56_1D028_1D_1D001/001_1D011_1DN_1D_1DNEW YORK_1DNY_1E_04^FS
+
+^FX Mode 3 Zebra example 2
+^FO250,250
+^BD3^FH^FD066826RS19 _5B)>_1E01_1D961Z00136111_1DUPSN_1D123X56_1D057_1D_1D001/001_1D011_1DN_1D_1DWEST SWINDON_1D_1E_04^FS
+
+^FX Mode 3 Zebra example 3
+^FO500,500
+^BD3^FH^FD00163000901 [)>_1E01_1D961Z00004951_1DUPSN_1D06X610_1D159_1D1234567_1D1/1_1D20_1DY_1D634 ALPHA DR_1DSAN JUAN_1DPR_1E_04^FS
+
+^FX Mode 4
+^FO10,500
+^BD4^FD123456789^FS
+
+^FX Mode 5
+^FO10,700
+^BD5^FD123456789^FS
+
+^FX Mode 6
+^FO10,900
+^BD6^FD123456789^FS
+
+^XZ
\ No newline at end of file
diff --git a/src/BinaryKits.Zpl.Viewer/BinaryKits.Zpl.Viewer.csproj b/src/BinaryKits.Zpl.Viewer/BinaryKits.Zpl.Viewer.csproj
index da5b76d4..2075cfbb 100644
--- a/src/BinaryKits.Zpl.Viewer/BinaryKits.Zpl.Viewer.csproj
+++ b/src/BinaryKits.Zpl.Viewer/BinaryKits.Zpl.Viewer.csproj
@@ -26,6 +26,7 @@
+
diff --git a/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldDataZplCommandAnalyzer.cs b/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldDataZplCommandAnalyzer.cs
index 2e35d1f4..ba6aa0bb 100644
--- a/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldDataZplCommandAnalyzer.cs
+++ b/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldDataZplCommandAnalyzer.cs
@@ -47,6 +47,7 @@ public override ZplElementBase Analyze(string zplCommand)
{
int moduleWidth = this.VirtualPrinter.BarcodeInfo.ModuleWidth;
double wideBarToNarrowBarWidthRatio = this.VirtualPrinter.BarcodeInfo.WideBarToNarrowBarWidthRatio;
+ bool useHexadecimalIndicator = this.VirtualPrinter.NextElementFieldUseHexadecimalIndicator;
if (this.VirtualPrinter.NextElementFieldData is Code39BarcodeFieldData code39)
{
@@ -69,6 +70,10 @@ public override ZplElementBase Analyze(string zplCommand)
{
return new ZplBarcodeInterleaved2of5(text, x, y, interleaved2of5.Height, moduleWidth, wideBarToNarrowBarWidthRatio, interleaved2of5.FieldOrientation, interleaved2of5.PrintInterpretationLine, interleaved2of5.PrintInterpretationLineAboveCode, bottomToTop: bottomToTop);
}
+ if (this.VirtualPrinter.NextElementFieldData is MaxiCodeBarcodeFieldData maxiCode)
+ {
+ return new ZplMaxiCode(text, x, y, maxiCode.Mode, maxiCode.Position, maxiCode.Total, useHexadecimalIndicator, bottomToTop);
+ }
if (this.VirtualPrinter.NextElementFieldData is QrCodeBarcodeFieldData qrCode)
{
(ErrorCorrectionLevel errorCorrection, string parsedText) = ParseQrCodeFieldData(qrCode, text);
diff --git a/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldHexadecimalZplCommandAnalyzer.cs b/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldHexadecimalZplCommandAnalyzer.cs
index fc05a5ca..0565578c 100644
--- a/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldHexadecimalZplCommandAnalyzer.cs
+++ b/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldHexadecimalZplCommandAnalyzer.cs
@@ -10,6 +10,7 @@ public FieldHexadecimalZplCommandAnalyzer(VirtualPrinter virtualPrinter) : base(
///
public override ZplElementBase Analyze(string zplCommand)
{
+ this.VirtualPrinter.SetNextElementFieldUseHexadecimalIndicator();
var zplDataParts = this.SplitCommand(zplCommand);
char Indicator = '_';
diff --git a/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldSeparatorZplCommandAnalyzer.cs b/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldSeparatorZplCommandAnalyzer.cs
index 6e344a85..16f56867 100644
--- a/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldSeparatorZplCommandAnalyzer.cs
+++ b/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldSeparatorZplCommandAnalyzer.cs
@@ -30,6 +30,7 @@ public override ZplElementBase Analyze(string zplCommand)
this.VirtualPrinter.ClearNextElementFieldBlock();
this.VirtualPrinter.ClearNextElementFieldData();
this.VirtualPrinter.ClearNextElementFieldReverse();
+ this.VirtualPrinter.ClearNextElementFieldUseHexadecimalIndicator();
this.VirtualPrinter.ClearNextFont();
this.VirtualPrinter.ClearComments();
diff --git a/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/MaxiCodeBarcodeZplCommandAnalyzer.cs b/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/MaxiCodeBarcodeZplCommandAnalyzer.cs
new file mode 100644
index 00000000..9054094a
--- /dev/null
+++ b/src/BinaryKits.Zpl.Viewer/CommandAnalyzers/MaxiCodeBarcodeZplCommandAnalyzer.cs
@@ -0,0 +1,43 @@
+using BinaryKits.Zpl.Label.Elements;
+using BinaryKits.Zpl.Viewer.Models;
+using System;
+
+namespace BinaryKits.Zpl.Viewer.CommandAnalyzers
+{
+ public class MaxiCodeBarcodeZplCommandAnalyzer : ZplCommandAnalyzerBase
+ {
+ public MaxiCodeBarcodeZplCommandAnalyzer(VirtualPrinter virtualPrinter) : base("^BD", virtualPrinter) { }
+
+ ///
+ public override ZplElementBase Analyze(string zplCommand)
+ {
+ var zplDataParts = this.SplitCommand(zplCommand);
+
+ int mode = 2;
+ int position = 1;
+ int total = 1;
+
+ if (zplDataParts[0] != "")
+ {
+ mode = Int32.Parse(zplDataParts[0]);
+ }
+
+ int tmpint;
+ if (zplDataParts.Length > 1 && int.TryParse(zplDataParts[1], out tmpint))
+ {
+ position = tmpint;
+ }
+
+ if (zplDataParts.Length > 2 && int.TryParse(zplDataParts[2], out tmpint))
+ {
+ total = tmpint;
+ }
+
+ this.VirtualPrinter.SetNextElementFieldData(new MaxiCodeBarcodeFieldData {
+ Mode = mode, Position = position, Total = total,
+ });
+
+ return null;
+ }
+ }
+}
diff --git a/src/BinaryKits.Zpl.Viewer/ElementDrawers/MaxiCodeElementDrawer.cs b/src/BinaryKits.Zpl.Viewer/ElementDrawers/MaxiCodeElementDrawer.cs
new file mode 100644
index 00000000..bc2f934e
--- /dev/null
+++ b/src/BinaryKits.Zpl.Viewer/ElementDrawers/MaxiCodeElementDrawer.cs
@@ -0,0 +1,162 @@
+using BinaryKits.Zpl.Label.Elements;
+using BinaryKits.Zpl.Viewer.Helpers;
+using CoelWu.Zint.Net;
+using System;
+using System.IO;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+
+namespace BinaryKits.Zpl.Viewer.ElementDrawers
+{
+ public class MaxiCodeElementDrawer : BarcodeDrawerBase
+ {
+ ///
+ public override bool CanDraw(ZplElementBase element)
+ {
+ return element is ZplMaxiCode;
+ }
+
+ ///
+ public override void Draw(ZplElementBase element)
+ {
+ if (element is ZplMaxiCode maxiCode)
+ {
+ var maxiBarcode = new ZintNetLib();
+ maxiBarcode.MaxicodeMode = ConvertMaxiCodeMode(maxiCode.Mode);
+ var content = maxiCode.Content;
+
+ try
+ {
+ //replace hex items before mode 2 and mode 3 specific string manipulation
+ if (maxiCode.UseHexadecimalIndicator)
+ {
+ content = content.ReplaceHexEscapes();
+ }
+
+ if (maxiBarcode.MaxicodeMode == MaxicodeMode.Mode2)
+ {
+ //ZPL mode 2:
+ //^FD[aaa][bbb][ccccc][dddd]_5B)>_1E[ee]_1D[ff]1Z
+ //^FD002840100450000_5B)>_1E01_1D961Z
+ // = aaabbbcccccdddd
+ // aaa = three-digit class of service
+ // bbb = three-digit country code
+ // ccccc = five-digit zip code
+ // dddd = four-digit zip code extension (if none exists, four zeros (0000) must be entered)
+ // ee = 01
+ // ff = year number
+ //ZintNetLib structure:
+ //^FD_5B)>_1E[ee]_1D[ff][ccccc][dddd]_1D[bbb]_1D[aaa]_1D1Z
+ //^FD_5B)>_1E01_1D96100450000_1D840_1D002_1D1Z
+ //Note: Country code 630 is not allowed in this library for mode 2
+
+ var replace = content.Substring(0, 24);
+ var aaa = content.Substring(0, 3);
+ var bbb = content.Substring(3, 3);
+ var ccccc = content.Substring(6, 5);
+ var dddd = content.Substring(11, 4);
+ var ee = content.Substring(19, 2);
+ var ff = content.Substring(22, 2);
+ var newString = $"\x5B)>\x1E{ee}\x1D{ff}{ccccc}{dddd}\x1D{bbb}\x1D{aaa}\x1D";
+ content = content.Replace(replace, newString);
+ }
+ else if (maxiBarcode.MaxicodeMode == MaxicodeMode.Mode3)
+ {
+ //ZPL mode 3:
+ //^FD[aaa][bbb][cccccc]_5B)>_1E[ee]_1D[ff]1Z
+ //^FD066826RS19 _5B)>_1E01_1D961Z
+ // = aaabbbcccccc
+ // aaa = three-digit class of service
+ // bbb = three-digit country code
+ // ccccc = six-digit zip code (A through Z or 0 to 9)
+ // ee = 01
+ // ff = year number
+ //ZintNetLib structure:
+ //^FD_5B)>_1E[ee]_1D[ff][cccccc]_1D[bbb]_1D[aaa]_1D1Z
+ //^FD_5B)>_1E01_1D96RS19 _1D826_1D066_1D1Z
+
+ var replace = content.Substring(0, 21);
+ var aaa = content.Substring(0, 3);
+ var bbb = content.Substring(3, 3);
+ var cccccc = content.Substring(6, 6);
+ var ee = content.Substring(16, 2);
+ var ff = content.Substring(19, 2);
+ var newString = $"\x5B)>\x1E{ee}\x1D{ff}{cccccc}\x1D{bbb}\x1D{aaa}\x1D";
+ content = content.Replace(replace, newString);
+ }
+
+ maxiBarcode.CreateBarcode("Maxicode(ISO 16023)", content);
+ }
+ catch (Exception e)
+ {
+ // Do nothing
+ }
+
+ //^BD2,1,1
+ if (maxiBarcode.IsValid)
+ {
+ var bitmap = new Bitmap(1000, 1000);
+ var graphics = Graphics.FromImage(bitmap);
+ graphics.Clear(Color.White);
+
+ maxiBarcode.Rotation = 0;
+ maxiBarcode.Multiplier = 2;
+ //Note: Position and Total are not supported in this MaxiCode library
+ maxiBarcode.DrawBarcode(graphics, new Point(-6, -6));
+
+ //Linux container fix, redraw the circles (variation of: CoelWu.Zint.Net.ZintNetLib.DrawBarcode)
+ graphics.SmoothingMode = SmoothingMode.AntiAlias;
+ float num3 = 13.64f * 7f;
+ float num4 = 13.43f * 7f;
+ float num5 = 0.85f * 7f;
+ float num6 = 2.2f * 7f;
+ float num7 = 3.54f * 7f;
+ Pen pen = new Pen(Color.Black, 0.67f * 7f);
+ graphics.DrawEllipse(pen, new RectangleF(num3 - num5 + 1, num4 - num5 + 1, num5 * 2.12f, num5 * 2.12f));
+ graphics.DrawEllipse(pen, new RectangleF(num3 - num6 + 0.5f, num4 - num6 + 0.5f, num6 * 2.12f, num6 * 2.12f));
+ graphics.DrawEllipse(pen, new RectangleF(num3 - num7, num4 - num7, num7 * 2.12f, num7 * 2.12f));
+
+ Size symbolSize;
+ var section = Rectangle.Empty;
+ symbolSize = maxiBarcode.SymbolSize(graphics);
+ section.Width = symbolSize.Width - 12;
+ section.Height = symbolSize.Height - 12;
+
+ var newBitmap = new Bitmap(section.Width, section.Height);
+ var newGraphics = Graphics.FromImage(newBitmap);
+ newGraphics.DrawImage(bitmap, 0, 0, section, GraphicsUnit.Pixel);
+
+ byte[] data = null;
+ using (MemoryStream ms = new MemoryStream())
+ {
+ newBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
+ data = ms.ToArray();
+
+ this.DrawBarcode(
+ data,
+ section.Width,
+ section.Height,
+ true,
+ maxiCode.PositionX,
+ maxiCode.PositionY,
+ 0,
+ Label.FieldOrientation.Normal
+ );
+ }
+ }
+ }
+ }
+
+ private MaxicodeMode ConvertMaxiCodeMode(int mode)
+ {
+ return mode switch {
+ 2 => MaxicodeMode.Mode2,
+ 3 => MaxicodeMode.Mode3,
+ 4 => MaxicodeMode.Mode4,
+ 5 => MaxicodeMode.Mode5,
+ 6 => MaxicodeMode.Mode6,
+ _ => MaxicodeMode.Mode2,
+ };
+ }
+ }
+}
diff --git a/src/BinaryKits.Zpl.Viewer/Models/MaxiCodeBarcodeFieldData.cs b/src/BinaryKits.Zpl.Viewer/Models/MaxiCodeBarcodeFieldData.cs
new file mode 100644
index 00000000..2675180d
--- /dev/null
+++ b/src/BinaryKits.Zpl.Viewer/Models/MaxiCodeBarcodeFieldData.cs
@@ -0,0 +1,12 @@
+using BinaryKits.Zpl.Label;
+
+namespace BinaryKits.Zpl.Viewer.Models
+{
+ public class MaxiCodeBarcodeFieldData : FieldDataBase
+ {
+ public int Mode { get; set; }
+ public int Position { get; set; }
+ public int Total { get; set; }
+ public bool UseHexadecimalIndicator { get; set; }
+ }
+}
diff --git a/src/BinaryKits.Zpl.Viewer/VirtualPrinter.cs b/src/BinaryKits.Zpl.Viewer/VirtualPrinter.cs
index 0d60da28..2bfe8964 100644
--- a/src/BinaryKits.Zpl.Viewer/VirtualPrinter.cs
+++ b/src/BinaryKits.Zpl.Viewer/VirtualPrinter.cs
@@ -21,6 +21,7 @@ public class VirtualPrinter
public FontInfo NextFont { get; private set; }
public bool NextElementFieldReverse { get; private set; }
+ public bool NextElementFieldUseHexadecimalIndicator { get; private set; }
public bool LabelReverse { get; private set; }
public BarcodeInfo BarcodeInfo { get; private set; }
@@ -82,6 +83,11 @@ public void SetNextElementFieldReverse()
this.NextElementFieldReverse = true;
}
+ public void SetNextElementFieldUseHexadecimalIndicator()
+ {
+ this.NextElementFieldUseHexadecimalIndicator = true;
+ }
+
public void SetLabelReverse(bool reverse)
{
this.LabelReverse = reverse;
@@ -92,6 +98,11 @@ public void ClearNextElementFieldReverse()
this.NextElementFieldReverse = false;
}
+ public void ClearNextElementFieldUseHexadecimalIndicator()
+ {
+ this.NextElementFieldUseHexadecimalIndicator = false;
+ }
+
public void SetFontWidth(int fontWidth)
{
this.FontWidth = fontWidth;
diff --git a/src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs b/src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs
index 7470fe48..602157f8 100644
--- a/src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs
+++ b/src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs
@@ -60,6 +60,7 @@ public AnalyzeInfo Analyze(string zplData)
new Interleaved2of5BarcodeZplCommandAnalyzer(this._virtualPrinter),
new ImageMoveZplCommandAnalyzer(this._virtualPrinter),
new LabelHomeZplCommandAnalyzer(this._virtualPrinter),
+ new MaxiCodeBarcodeZplCommandAnalyzer(this._virtualPrinter),
new QrCodeBarcodeZplCommandAnalyzer(this._virtualPrinter),
new PDF417ZplCommandAnalyzer(this._virtualPrinter),
new RecallFormatCommandAnalyzer(this._virtualPrinter),
diff --git a/src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs b/src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs
index 6ee0d53b..018ea03e 100644
--- a/src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs
+++ b/src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs
@@ -34,6 +34,7 @@ public ZplElementDrawer(IPrinterStorage printerStorage, DrawerOptions drawerOpti
new GraphicFieldElementDrawer(),
new Interleaved2of5BarcodeDrawer(),
new ImageMoveElementDrawer(),
+ new MaxiCodeElementDrawer(),
new QrCodeElementDrawer(),
new Pdf417ElementDrawer(),
new RecallGraphicElementDrawer(),