From b9ef0c93e978493fc224be1c10dbce25bd9f1b66 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Thu, 17 Feb 2022 18:29:41 +0100 Subject: [PATCH] added alignment --- Instructions/Alignment.cs | 6 ++++++ Instructions/BarcodeInstruction.cs | 5 +++++ Instructions/BaseInstruction.cs | 16 ++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 Instructions/Alignment.cs diff --git a/Instructions/Alignment.cs b/Instructions/Alignment.cs new file mode 100644 index 0000000..b8eaa41 --- /dev/null +++ b/Instructions/Alignment.cs @@ -0,0 +1,6 @@ +public enum Alignment +{ + Right, + Left, + Center +} \ No newline at end of file diff --git a/Instructions/BarcodeInstruction.cs b/Instructions/BarcodeInstruction.cs index 9839c87..70aa78e 100644 --- a/Instructions/BarcodeInstruction.cs +++ b/Instructions/BarcodeInstruction.cs @@ -14,6 +14,9 @@ public class BarcodeInstruction : BaseInstruction [JsonConverter(typeof(JsonStringEnumConverter))] public BarcodeCode barcodeCode { get; set; } = BarcodeCode.CODE_B; + [JsonConverter(typeof(JsonStringEnumConverter))] + public Alignment alignment {get; set; } = Alignment.Left; + // [JsonConverter(typeof(JsonStringEnumConverter))] // public BarWidth width { get; set; } = BarWidth.Default; @@ -29,6 +32,8 @@ public class BarcodeInstruction : BaseInstruction // commands.Add(e.SetBarWidth(width)); // } + commands.Add(alignmentCommand(alignment)); + if (height > 0) { commands.Add(e.SetBarcodeHeightInDots(height)); diff --git a/Instructions/BaseInstruction.cs b/Instructions/BaseInstruction.cs index d7a5d99..0fa2f00 100644 --- a/Instructions/BaseInstruction.cs +++ b/Instructions/BaseInstruction.cs @@ -1,4 +1,5 @@ using System.Runtime.Serialization; +using ESCPOS_NET.Emitters; public abstract class BaseInstruction { @@ -6,4 +7,19 @@ public abstract class BaseInstruction public string? type { get; set; } public abstract List GetInstructions(); + + protected byte[] alignmentCommand(Alignment alignment){ + var e = new EPSON(); + switch (alignment) + { + case Alignment.Center: + return e.CenterAlign(); + case Alignment.Left: + return e.LeftAlign(); + case Alignment.Right: + return e.RightAlign(); + default: + return e.LeftAlign(); + } + } }