2022-02-17 15:45:42 +00:00
|
|
|
using System.Runtime.Serialization;
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
using ESCPOS_NET.Emitters;
|
|
|
|
|
2022-02-17 17:29:32 +00:00
|
|
|
public class TextInstruction : BaseInstruction
|
2022-02-17 15:45:42 +00:00
|
|
|
{
|
|
|
|
[DataMember(IsRequired = true)]
|
|
|
|
public string? text { get; set; }
|
|
|
|
|
2022-02-17 17:29:32 +00:00
|
|
|
[JsonConverter(typeof(JsonStringEnumConverter))]
|
|
|
|
public Alignment alignment {get; set; } = Alignment.Left;
|
|
|
|
|
2022-02-18 17:48:03 +00:00
|
|
|
public bool underline {get; set; } = false;
|
2022-02-18 18:30:13 +00:00
|
|
|
public bool bold {get; set; } = false;
|
|
|
|
public bool doubleHeight {get; set; } = false;
|
|
|
|
public bool doubleWidth {get; set; } = false;
|
|
|
|
public bool fontB {get; set; } = false;
|
2022-02-28 00:25:55 +00:00
|
|
|
public int lineSpacing {get; set; } = -1;
|
2022-02-18 17:48:03 +00:00
|
|
|
|
2022-02-17 15:45:42 +00:00
|
|
|
public bool newLine { get; set; } = true;
|
2022-02-18 18:30:13 +00:00
|
|
|
|
2022-02-17 15:45:42 +00:00
|
|
|
public override List<byte[]> GetInstructions()
|
|
|
|
{
|
|
|
|
var commands = new List<byte[]>();
|
2022-02-17 17:29:32 +00:00
|
|
|
|
|
|
|
commands.Add(alignmentCommand(alignment));
|
2022-02-17 15:45:42 +00:00
|
|
|
|
2022-02-18 18:30:13 +00:00
|
|
|
commands.AddRange(setStyles());
|
2022-02-18 17:48:03 +00:00
|
|
|
|
2022-02-28 00:25:55 +00:00
|
|
|
if (lineSpacing >= 0){
|
|
|
|
commands.Add(e.SetLineSpacingInDots(lineSpacing));
|
|
|
|
}
|
|
|
|
|
2022-02-17 15:45:42 +00:00
|
|
|
if (newLine)
|
|
|
|
{
|
|
|
|
commands.Add(e.PrintLine(text));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
commands.Add(e.Print(text));
|
|
|
|
}
|
|
|
|
|
2022-02-18 18:30:13 +00:00
|
|
|
if (underline || bold || doubleHeight || doubleWidth || fontB){
|
2022-02-18 17:48:03 +00:00
|
|
|
commands.Add(e.SetStyles(PrintStyle.None));
|
|
|
|
}
|
|
|
|
|
2022-02-28 00:25:55 +00:00
|
|
|
if (lineSpacing >= 0){
|
|
|
|
commands.Add(e.ResetLineSpacing());
|
|
|
|
}
|
|
|
|
|
2022-02-17 15:45:42 +00:00
|
|
|
return commands;
|
|
|
|
}
|
2022-02-18 18:30:13 +00:00
|
|
|
|
|
|
|
private List<byte[]> setStyles(){
|
|
|
|
var commands = new List<byte[]>();
|
|
|
|
if (underline){
|
|
|
|
commands.Add(e.SetStyles(PrintStyle.Underline));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bold){
|
|
|
|
commands.Add(e.SetStyles(PrintStyle.Bold));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doubleHeight){
|
|
|
|
commands.Add(e.SetStyles(PrintStyle.DoubleHeight));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doubleWidth){
|
|
|
|
commands.Add(e.SetStyles(PrintStyle.DoubleWidth));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fontB){
|
|
|
|
commands.Add(e.SetStyles(PrintStyle.FontB));
|
|
|
|
}
|
|
|
|
|
|
|
|
return commands;
|
|
|
|
}
|
2022-02-17 15:45:42 +00:00
|
|
|
}
|