From 125390661cd9650d2c603a903736cd961a518fe7 Mon Sep 17 00:00:00 2001 From: Tourjmen Souhail <95188930+souhailtourjmen@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:23:28 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20Introduce=20custom=20`charsPerLine`=20p?= =?UTF-8?q?roperty=20for=20enhanced=20ticket=20la=E2=80=A6=20(#198)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Introduce custom `charsPerLine` property for enhanced ticket layout flexibility - Added `charsPerLine` option to the Printer API, allowing custom character width per line. - Enhances layout control for complex ticket templates. - Fixes issue #197: Proposal for custom `charsPerLine` for flexible layouts. * - Cleaned up code formatting by removing an unnecessary space in the parameters list. #197 * style: format code for ESLint best practices #197 --- src/printer/printHelpers/addTextLine.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/printer/printHelpers/addTextLine.ts b/src/printer/printHelpers/addTextLine.ts index f1046e6..297b367 100644 --- a/src/printer/printHelpers/addTextLine.ts +++ b/src/printer/printHelpers/addTextLine.ts @@ -5,19 +5,22 @@ import { PrinterConstants, DEFAULT_PAPER_WIDTH } from '../constants'; export async function addTextLine( printer: Printer, - params: SpaceBetweenParams + params: SpaceBetweenParams, + customCharsPerLine?: number ) { const printerCharsPerLinePerWidth = getFontACharsPerLine(printer.deviceName); const { value: paperWidth } = await printer.getPrinterSetting( PrinterConstants.PRINTER_SETTING_PAPERWIDTH ); - const charsPerLine = - printerCharsPerLinePerWidth[paperWidth || DEFAULT_PAPER_WIDTH]; + const charsPerLine = customCharsPerLine + ? customCharsPerLine + : printerCharsPerLinePerWidth[paperWidth || DEFAULT_PAPER_WIDTH]; const text = spaceBetween( Math.ceil(charsPerLine / printer.currentFontWidth), params ); + await printer.addText(text); }