NielsLeenheer / ReceiptPrinterEncoder

Create a set of commands that can be send to any receipt printer that supports ESC/POS, StarLine or StarPRNT
MIT License
185 stars 18 forks source link

WordWrap issue in table #13

Closed madVis closed 2 months ago

madVis commented 4 months ago

I'm trying to print a table and it's not wrapping correctly.

let encoder = new EscPosEncoder({ width: 48, wordWrap: true, imageMode: 'raster' });

const tableHeaderArray = [
  { width: 20, align: 'left' },
  { width: 7, align: 'left' },
  { width: 7, align: 'left' },
  { width: 7, align: 'right' },
  { width: 7, align: 'right' }
];

const tableBodyArray = [
  [
    (encoder) => encoder.bold(true).text('Name').bold(false),
    (encoder) => encoder.bold(true).text('Unit').bold(false),
    (encoder) => encoder.bold(true).text('Qty').bold(false),
    (encoder) => encoder.bold(true).text('Amount').bold(false),
    (encoder) => encoder.bold(true).text('Total').bold(false)
  ],
  [
    'Apple',
    'kilograms',
    '1,555,000',
    '3.00',
    '15.00 Dollars'
  ],
  [
    'Banana',
    'doz',
    '2',
    '1.50',
    '3.00'
  ],
  [
    'Cherry',
    'kg',
    '1',
    '10.00',
    '10.00'
  ]
];
return encoder
  .initialize()
  .table(tableHeaderArray, tableBodyArray)
  .encode();

I've attached the print image. 347008817-ac4d283f-0ab1-4abf-a2bb-9f0eb2c54a0f

If a word exceeds the column width (e.g., the column width is 5 and the word is "Pomegranate"), it isn't wrapping correctly and occupies the space of the next column.

Incorrect wrapping: col1 col2 1 2 3 4 5 6 7 8 9... Po m e g r a n a t e

Ideally, it should wrap like this: col1 col2 1 2 3 4 5 6 7 8 9... Po m e g r a n a t e

madVis commented 3 months ago

Hey @NielsLeenheer , @Wnt , @liangminhua I haven’t seen any updates on this bugs yet. Is there any additional information needed from my side? If possible, could you provide an update on when these issues might be fixed?

NielsLeenheer commented 3 months ago

I'll take a look at it when I get back from my vacation break.

NielsLeenheer commented 2 months ago

It turns out that this issue is bigger than expected. The commit above does improve it, but it isn't a simple bug, but a fundamental issue. In order to properly fix this I need to do a complete rewrite of how lines are composed and how text is wrapped.

madVis commented 2 months ago

Thanks for the update, @NielsLeenheer. I understand it’s a more complex issue than anticipated. If possible, could you share a rough estimate of when the fix might be ready? It would help with planning on my side.

NielsLeenheer commented 2 months ago

As it stands right now, it is fixed, but it is part of a complete rewrite of the whole library. And the rest of the rewrite isn't ready to land just yet. Not sure when it will be, but I'll keep you posted.

NielsLeenheer commented 2 months ago

Transferred this issue to the new rewrite of EscPosEncoder...

NielsLeenheer commented 2 months ago

Confirmed fixed in the upcoming version 3.0