Skip to content

Commit

Permalink
Added: MaxiCode support (#224)
Browse files Browse the repository at this point in the history
* Added: MaxiCode support

* Improved: Slight finetune on maxicode linux fix
  • Loading branch information
daanggc authored Apr 23, 2024
1 parent 5dd11da commit b20a607
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/BinaryKits.Zpl.Label/Elements/ZplMaxiCode.cs
Original file line number Diff line number Diff line change
@@ -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; }

/// <summary>
/// Zpl QrCode
/// </summary>
/// <param name="content"></param>
/// <param name="positionX"></param>
/// <param name="positionY"></param>
/// <param name="mode">2 (numeric postal code) Default, 3 (alphanumeric postal code), 4 (standard), 5 (full EEC), and 6 (reader programming)</param>
/// <param name="position">1-8, (default: 1)</param>
/// <param name="total">1-8, (default: 1)</param>
/// <param name="useHexadecimalIndicator"></param>
/// <param name="bottomToTop"></param>
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;
}

///<inheritdoc/>
public override IEnumerable<string> 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<string>();
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();
}

/// <inheritdoc />
public void SetTemplateContent(string content)
{
Content = content;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<None Update="Labels\Test\TextRotation2-102x152.zpl2">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Labels\Test\MaxiCode-102x152.zpl2">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Labels\Test\BarcodePDF417-102x152.zpl2">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -138,6 +141,9 @@
<None Update="Labels\Example\Example11-102x152.zpl2">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Labels\Example\Example12-102x152.zpl2">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
110 changes: 110 additions & 0 deletions src/BinaryKits.Zpl.Viewer.WebApi/Labels/Example/Example12-102x152.zpl2
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/MaxiCode-102x152.zpl2
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/BinaryKits.Zpl.Viewer/BinaryKits.Zpl.Viewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.8" />
<PackageReference Include="ZXing.Net" Version="0.16.9" />
<PackageReference Include="CoelWu.Zint.Net" Version="1.0.0" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public FieldHexadecimalZplCommandAnalyzer(VirtualPrinter virtualPrinter) : base(
///<inheritdoc/>
public override ZplElementBase Analyze(string zplCommand)
{
this.VirtualPrinter.SetNextElementFieldUseHexadecimalIndicator();
var zplDataParts = this.SplitCommand(zplCommand);

char Indicator = '_';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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) { }

///<inheritdoc/>
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;
}
}
}
Loading

0 comments on commit b20a607

Please sign in to comment.