tm220 print mode refactoring

This commit is contained in:
EugeneTes
2026-01-21 09:19:24 +01:00
parent fe18db2642
commit cb231801f1
7 changed files with 64 additions and 30 deletions

View File

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

View File

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

View File

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

View File

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

View File

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