Add project files.
This commit is contained in:
118
Inspectron.Epson/PrintServer/Printers/TM-T30IIITranslated.cs
Normal file
118
Inspectron.Epson/PrintServer/Printers/TM-T30IIITranslated.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System.Text.Json;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe;
|
||||
using Inspectron.Epson.PrintServer.PrintServices;
|
||||
|
||||
namespace Inspectron.Epson.PrintServer.Printers;
|
||||
|
||||
public class TM_T30IIITranslated:IPrinter
|
||||
{
|
||||
private readonly EpsonPrinter _printer;
|
||||
|
||||
public TM_T30IIITranslated(EpsonPrinter printer)
|
||||
{
|
||||
_printer = printer;
|
||||
}
|
||||
|
||||
public Task InitAsync()
|
||||
{
|
||||
return _printer.InitAsync();
|
||||
}
|
||||
|
||||
public async Task PrintImageAsync(string path)
|
||||
{
|
||||
await _printer.SetAbsolutePrintPosition(100);
|
||||
await _printer.LoadImageAsync(Path.Combine("logos", path), 384);
|
||||
await Task.Delay(100);
|
||||
await _printer.FeedLinesAsync(1);
|
||||
await _printer.SetAbsolutePrintPosition(0);
|
||||
}
|
||||
|
||||
public async Task SetFontSizeAsync(int fontSize)
|
||||
{
|
||||
//await _printer.SetFontSizeAsync(fontSize, fontSize);
|
||||
}
|
||||
|
||||
public async Task PrintTextAsync(string text)
|
||||
{
|
||||
Receipt? receipt;
|
||||
try
|
||||
{
|
||||
receipt = JsonSerializer.Deserialize<Receipt>(text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback to kitchen receipt
|
||||
await PrintKitchen(text);
|
||||
return;
|
||||
}
|
||||
var converter = new ReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
var printCommands = converter.ConvertToPrintCommands(receipt);
|
||||
await _printer.FeedLinesAsync(1);
|
||||
await _printer.SetCustomLineSpacing(22);
|
||||
|
||||
foreach (var command in printCommands)
|
||||
{
|
||||
string attributes = "";
|
||||
if (command.IsBig) attributes += "[BIG]\n";
|
||||
if (command.IsBold) attributes += "[BOLD]\n";
|
||||
|
||||
Console.WriteLine($"{attributes}{command.Text}");
|
||||
|
||||
if (command.IsBig)
|
||||
{
|
||||
await _printer.SetFontSizeAsync(2, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _printer.SetFontSizeAsync(1, 1);
|
||||
}
|
||||
|
||||
await _printer.SetEmphasized(command.IsBold);
|
||||
|
||||
await _printer.PrintTextAsync(command.Text + "\n");
|
||||
|
||||
}
|
||||
|
||||
await _printer.SetDefaultLineSpacing();
|
||||
await _printer.FeedLinesAsync(10);
|
||||
await Task.Delay(200);
|
||||
}
|
||||
|
||||
private async Task PrintKitchen(string text)
|
||||
{
|
||||
ReceiptTranslator translator = new ReceiptTranslator();
|
||||
var ast = translator.ParseReceipt(text);
|
||||
KitchenReceiptPrinter printer = new KitchenReceiptPrinter(lineWidth: 33, 21);
|
||||
var commands = printer.ConvertToCommands((KitchenReceipt)ast);
|
||||
foreach (KitchenPrintCommand command in commands)
|
||||
{
|
||||
if (command.IsBig)
|
||||
{
|
||||
await _printer.SetFontSizeAsync(2,2);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _printer.SetFontSizeAsync(1, 1);
|
||||
}
|
||||
|
||||
|
||||
await Task.Delay(200);
|
||||
await _printer.SetRedColor(command.IsRed);
|
||||
await Task.Delay(200);
|
||||
await _printer.SetEmphasized(command.IsBold);
|
||||
await Task.Delay(200);
|
||||
await _printer.PrintTextAsync(command.Text + "\n");
|
||||
await Task.Delay(200);
|
||||
}
|
||||
|
||||
await _printer.FeedLinesAsync(10);
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
public async Task Cut()
|
||||
{
|
||||
await _printer.CutAsync();
|
||||
await Task.Delay(200);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user