added alignment

This commit is contained in:
Djeeberjr 2022-02-17 18:29:41 +01:00
parent 2e9909129b
commit b9ef0c93e9
3 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,6 @@
public enum Alignment
{
Right,
Left,
Center
}

View File

@ -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));

View File

@ -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<byte[]> 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();
}
}
}