printer-api/Instructions/TextInstruction.cs

42 lines
854 B
C#

using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using ESCPOS_NET.Emitters;
public class TextInstruction : BaseInstruction
{
[DataMember(IsRequired = true)]
public string? text { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public Alignment alignment {get; set; } = Alignment.Left;
public bool underline {get; set; } = false;
public bool newLine { get; set; } = true;
public override List<byte[]> GetInstructions()
{
var e = new EPSON();
var commands = new List<byte[]>();
commands.Add(alignmentCommand(alignment));
if (underline){
commands.Add(e.SetStyles(PrintStyle.Underline));
}
if (newLine)
{
commands.Add(e.PrintLine(text));
}
else
{
commands.Add(e.Print(text));
}
if (underline){
commands.Add(e.SetStyles(PrintStyle.None));
}
return commands;
}
}