From 492c42bc08840a99cd4356f2a694b4b2e59be88d Mon Sep 17 00:00:00 2001 From: Alex Rousseaux Date: Wed, 4 Sep 2024 12:05:50 +1000 Subject: [PATCH] Add quality level to DataMatrix barcodes. --- .../Elements/ZplDataMatrix.cs | 14 ++++++-- .../Elements/ZplElementBase.cs | 21 ++++++++++++ src/BinaryKits.Zpl.Label/QualityLevel.cs | 33 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/BinaryKits.Zpl.Label/QualityLevel.cs diff --git a/src/BinaryKits.Zpl.Label/Elements/ZplDataMatrix.cs b/src/BinaryKits.Zpl.Label/Elements/ZplDataMatrix.cs index 85376eb1..7f9bdddf 100644 --- a/src/BinaryKits.Zpl.Label/Elements/ZplDataMatrix.cs +++ b/src/BinaryKits.Zpl.Label/Elements/ZplDataMatrix.cs @@ -16,25 +16,30 @@ public class ZplDataMatrix : ZplPositionedElementBase, IFormatElement /// /// /// + /// public ZplDataMatrix( string content, int positionX, int positionY, int height = 100, FieldOrientation fieldOrientation = FieldOrientation.Normal, - bool bottomToTop = false + bool bottomToTop = false, + QualityLevel qualityLevel = QualityLevel.ECC0 ) : base(positionX, positionY, bottomToTop) { Content = content; FieldOrientation = fieldOrientation; Height = height; + QualityLevel = qualityLevel; } public int Height { get; protected set; } public FieldOrientation FieldOrientation { get; protected set; } + public QualityLevel QualityLevel { get; protected set; } + public string Content { get; protected set; } protected string RenderFieldOrientation() @@ -42,6 +47,11 @@ protected string RenderFieldOrientation() return RenderFieldOrientation(FieldOrientation); } + protected string RenderQualityLevel() + { + return RenderQualityLevel(QualityLevel); + } + /// public override IEnumerable Render(ZplRenderOptions context) { @@ -50,7 +60,7 @@ public override IEnumerable Render(ZplRenderOptions context) //^FDZEBRA TECHNOLOGIES CORPORATION ^ FS var result = new List(); result.AddRange(RenderPosition(context)); - result.Add($"^BX{RenderFieldOrientation()},{context.Scale(Height)}"); + result.Add($"^BX{RenderFieldOrientation()},{context.Scale(Height)},{RenderQualityLevel()}"); result.Add($"^FD{Content}^FS"); return result; diff --git a/src/BinaryKits.Zpl.Label/Elements/ZplElementBase.cs b/src/BinaryKits.Zpl.Label/Elements/ZplElementBase.cs index a4fa7535..c50a045a 100644 --- a/src/BinaryKits.Zpl.Label/Elements/ZplElementBase.cs +++ b/src/BinaryKits.Zpl.Label/Elements/ZplElementBase.cs @@ -61,6 +61,27 @@ public string RenderFieldOrientation(FieldOrientation fieldOrientation) throw new NotImplementedException("Unknown Field Orientation"); } + public string RenderQualityLevel(QualityLevel qualityLevel) + { + switch (qualityLevel) + { + case QualityLevel.ECC0: + return "0"; + case QualityLevel.ECC50: + return "50"; + case QualityLevel.ECC80: + return "80"; + case QualityLevel.ECC100: + return "100"; + case QualityLevel.ECC140: + return "140"; + case QualityLevel.ECC200: + return "200"; + } + + throw new NotImplementedException("Unknown Quality Level"); + } + public string RenderFieldJustification(FieldJustification fieldJustification) { switch (fieldJustification) diff --git a/src/BinaryKits.Zpl.Label/QualityLevel.cs b/src/BinaryKits.Zpl.Label/QualityLevel.cs new file mode 100644 index 00000000..2dbcfc34 --- /dev/null +++ b/src/BinaryKits.Zpl.Label/QualityLevel.cs @@ -0,0 +1,33 @@ +namespace BinaryKits.Zpl.Label +{ + /// + /// Quality Level + /// + public enum QualityLevel + { + /// + /// ECC Value of 0 + /// + ECC0, + /// + /// ECC Value of 50 + /// + ECC50, + /// + /// ECC Value of 80 + /// + ECC80, + /// + /// ECC Value of 100 + /// + ECC100, + /// + /// ECC Value of 140 + /// + ECC140, + /// + /// ECC Value of 200 + /// + ECC200 + } +}