tm220 print mode refactoring
This commit is contained in:
@@ -35,6 +35,7 @@ kernel.Bind<ILogger>().ToMethod(ctx =>
|
||||
var loggerFactory = LoggerFactory.Create(builder =>
|
||||
{
|
||||
builder.AddConsole();
|
||||
builder.SetMinimumLevel(LogLevel.Trace);
|
||||
});
|
||||
return loggerFactory.CreateLogger("EpsonPrintService");
|
||||
});
|
||||
@@ -48,10 +49,12 @@ kernel.Bind<PrinterDiscoveryBackgroundTask>().ToSelf().InSingletonScope();
|
||||
kernel.Bind<HeartbeatBackgroundTask>().ToSelf().InSingletonScope();
|
||||
|
||||
var printLoop = kernel.Get<PrintLoop>();
|
||||
|
||||
var printServer = kernel.Get<PrintServer>();
|
||||
var discoveryTask = kernel.Get<PrinterDiscoveryBackgroundTask>();
|
||||
var heartbeatTask = kernel.Get<HeartbeatBackgroundTask>();
|
||||
|
||||
//printServer.RegisterPrinter("10.0.20.12");
|
||||
|
||||
|
||||
await printLoop.StartAsync();
|
||||
|
||||
|
||||
@@ -378,12 +378,14 @@ receipt.Gangs[0].Dishes.Add(new Dish(1, "Salmon Taco")
|
||||
|
||||
var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
var deserializedReceipt = JsonSerializer.Deserialize<KitchenReceipt>(serializedReceipt);
|
||||
KitchenReceiptConverter converter = new KitchenReceiptConverter(bigLineWidth: 20, lineWidth: 33);
|
||||
KitchenReceiptConverter converter = new KitchenReceiptConverter(bigLineWidth: 18, lineWidth: 33);
|
||||
var printCommands = converter.ConvertToPrintCommands(deserializedReceipt);
|
||||
|
||||
Console.WriteLine("=== PRINT COMMANDS ===\n");
|
||||
var printer = new HtmlPrinter(@".\test.html", paperWidth: 258);
|
||||
await printer.ConnectAsync("");
|
||||
//var printer = new HtmlPrinter(@".\test.html", paperWidth: 258);
|
||||
//await printer.ConnectAsync("");
|
||||
var printer = new EpsonPrinter();
|
||||
await printer.ConnectAsync("127.0.0.1",8888);
|
||||
await Task.Delay(200);
|
||||
await printer.FeedLinesAsync(1);
|
||||
await printer.SetCustomLineSpacing(22);
|
||||
@@ -395,28 +397,26 @@ foreach (var command in printCommands)
|
||||
if (command.IsRed) attributes += "[RED] ";
|
||||
|
||||
Console.WriteLine($"{attributes}{command.Text}");
|
||||
await printer.SetBiggerFontTM220(command.IsBig);
|
||||
|
||||
if (command.IsBig)
|
||||
{
|
||||
await printer.SetFontSizeAsync(2, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
await printer.SetFontSizeAsync(1, 1);
|
||||
}
|
||||
|
||||
await Task.Delay(200);
|
||||
|
||||
await printer.SetRedColor(command.IsRed);
|
||||
|
||||
//await Task.Delay(200);
|
||||
await Task.Delay(200);
|
||||
|
||||
await printer.SetEmphasized(command.IsBold);
|
||||
//await Task.Delay(200);
|
||||
await Task.Delay(200);
|
||||
|
||||
await printer.PrintTextAsync(command.Text + "\n");
|
||||
//await Task.Delay(200);
|
||||
await Task.Delay(200);
|
||||
|
||||
}
|
||||
|
||||
await printer.FeedLinesAsync(5);
|
||||
await Task.Delay(200*5);
|
||||
await printer.CutAsync();
|
||||
|
||||
//await printer.SetDefaultLineSpacing();
|
||||
//await printer.PrintTextAsync(
|
||||
|
||||
@@ -304,15 +304,27 @@ public class EpsonPrinter : IEpsonPrinter
|
||||
_logger?.LogInformation("Selecting font: {Font}", font);
|
||||
await SendRawAsync(command);
|
||||
}
|
||||
|
||||
public async Task SetBiggerFontTM220(bool enabled)
|
||||
/// <summary>
|
||||
/// Change to bigger font mode for TM-T20/220 printers
|
||||
/// </summary>
|
||||
/// <param name="biggerWidth"></param>
|
||||
/// <param name="biggerHeight"></param>
|
||||
/// <param name="secondaryFont"></param>
|
||||
/// <see cref="https://download4.epson.biz/sec_pubs/pos/reference_en/escpos/esc_exclamation.html"/>
|
||||
public async Task SetBiggerFontTM220(bool biggerWidth, bool biggerHeight=false, bool secondaryFont=true)
|
||||
{
|
||||
_logger?.LogInformation("{Action} bigger font mode for TM-T20/220",
|
||||
enabled ? "Enabling" : "Disabling");
|
||||
if (enabled)
|
||||
await SendRawCommandAsync([0x1b, 0x21, 0x20 + 0x01]);
|
||||
else
|
||||
await SendRawCommandAsync([0x1b, 0x21, 0x00]);
|
||||
_logger?.LogInformation("Setting bigger font mode: Width={BiggerWidth}, Height={BiggerHeight}, SecondaryFont={SecondaryFont}",
|
||||
biggerWidth, biggerHeight, secondaryFont);
|
||||
|
||||
byte value = 0x00;
|
||||
if (biggerWidth)
|
||||
value += 0x10;
|
||||
if (biggerHeight)
|
||||
value += 0x20;
|
||||
if (secondaryFont)
|
||||
value += 0x01;
|
||||
|
||||
await SendRawCommandAsync([0x1b, 0x21, value]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ public class HtmlPrinter : IEpsonPrinter
|
||||
private bool _isEmphasized;
|
||||
private bool _isRedColor;
|
||||
private bool _isQuadrupleMode;
|
||||
private bool _isBiggerFontTM220;
|
||||
private bool _isBiggerFontWidthTM220;
|
||||
private bool _isBiggerFontHeightTM220;
|
||||
private int _lineSpacing = 14; // Default line spacing in pixels (scaled for screen)
|
||||
private int _absolutePosition; // Current X position offset
|
||||
|
||||
@@ -239,10 +240,13 @@ public class HtmlPrinter : IEpsonPrinter
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetBiggerFontTM220(bool enabled)
|
||||
public Task SetBiggerFontTM220(bool biggerWidth, bool biggerHeight = false, bool secondaryFont = true)
|
||||
{
|
||||
_logger?.LogInformation("HtmlPrinter: {Action} bigger font mode for TM-T20/220", enabled ? "Enabling" : "Disabling");
|
||||
_isBiggerFontTM220 = enabled;
|
||||
_logger?.LogInformation("HtmlPrinter: Setting bigger font mode: Width={BiggerWidth}, Height={BiggerHeight}, SecondaryFont={SecondaryFont}",
|
||||
biggerWidth, biggerHeight, secondaryFont);
|
||||
_isBiggerFontWidthTM220 = biggerWidth;
|
||||
_isBiggerFontHeightTM220 = biggerHeight;
|
||||
// Note: secondaryFont is ignored in HTML simulation as it only affects the physical printer's font selection
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -468,7 +472,8 @@ public class HtmlPrinter : IEpsonPrinter
|
||||
_isEmphasized = false;
|
||||
_isRedColor = false;
|
||||
_isQuadrupleMode = false;
|
||||
_isBiggerFontTM220 = false;
|
||||
_isBiggerFontWidthTM220 = false;
|
||||
_isBiggerFontHeightTM220 = false;
|
||||
_lineSpacing = 14;
|
||||
_absolutePosition = 0;
|
||||
}
|
||||
@@ -490,11 +495,16 @@ public class HtmlPrinter : IEpsonPrinter
|
||||
effectiveHeightMultiplier *= 2;
|
||||
}
|
||||
|
||||
if (_isBiggerFontTM220)
|
||||
if (_isBiggerFontWidthTM220)
|
||||
{
|
||||
effectiveWidthMultiplier *= 2;
|
||||
}
|
||||
|
||||
if (_isBiggerFontHeightTM220)
|
||||
{
|
||||
effectiveHeightMultiplier *= 2;
|
||||
}
|
||||
|
||||
int fontSize = baseHeight * effectiveHeightMultiplier;
|
||||
styles.Add($"font-size: {fontSize}px");
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ public interface IEpsonPrinter : IAsyncDisposable
|
||||
/// <summary>
|
||||
/// Enable or disable bigger font mode for TM-T20/220
|
||||
/// </summary>
|
||||
Task SetBiggerFontTM220(bool enabled);
|
||||
Task SetBiggerFontTM220(bool biggerWidth, bool biggerHeight = false, bool secondaryFont = true);
|
||||
|
||||
/// <summary>
|
||||
/// Print text to the printer
|
||||
|
||||
@@ -34,6 +34,8 @@ public class EpsonPrintService: IPrintService
|
||||
|
||||
var printerId = await epsonPrinter.GetPrinterIdAsync();
|
||||
|
||||
_logger.LogInformation("Printer ID({ip}): {PrinterId}", printerIp, printerId);
|
||||
|
||||
var status = await epsonPrinter.GetPrinterStatusAsync();
|
||||
if (!status.IsOnline)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,13 @@ public class TM_T30IIITranslated : IPrinter
|
||||
|
||||
foreach (var command in commands)
|
||||
{
|
||||
if(command.SetLineSpacing.HasValue)
|
||||
{
|
||||
Console.WriteLine($"Setting line spacing to {command.SetLineSpacing.Value}");
|
||||
await _printer.SetCustomLineSpacing(command.SetLineSpacing.Value);
|
||||
Console.WriteLine($"------------------------------------------------------");
|
||||
continue;
|
||||
}
|
||||
if (command.IsBig)
|
||||
{
|
||||
await _printer.SetFontSizeAsync(2, 1);
|
||||
|
||||
Reference in New Issue
Block a user