Skip to content

Commit

Permalink
feat: Introduce custom charsPerLine property for enhanced ticket la… (
Browse files Browse the repository at this point in the history
#198)

* 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
  • Loading branch information
souhailtourjmen authored Nov 22, 2024
1 parent f737b08 commit 1253906
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/printer/printHelpers/addTextLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 1253906

Please sign in to comment.