ResaleAI / receipt-components

A library to let you build receipts once and print them anywhere.
MIT License
4 stars 0 forks source link

Layout package not ready for escpos rendering #11

Open FouadRaheb opened 8 months ago

FouadRaheb commented 8 months ago

The layout package currently only renders properly on HTML but not on ESC/POS.

I think the layout package is an essential part of any receipt, without it it's not possible to print lines with both right and left texts which is needed in any receipt type.

zaviermiller commented 8 months ago

I am planning on working on this package today, so good timing! I will update when I have made progress :)

FouadRaheb commented 8 months ago

That's awesome! I built all of my receipt template using row and col nodes, then after printing I noticed it is not ready yet haha

zaviermiller commented 8 months ago

@FouadRaheb I worked on it a bit, but it's been hard to test my changes since I don't have a receipt printer with me and won't for a couple of days so I won't be able to ensure the layout package is working until then. I have the changes I made on the branch for this issue if you want to test and maybe take a stab at getting it working.

My general strategy for getting this working is to do the following:

  1. In the row node, enter page mode
  2. In each col node compute the offset that the col should start at based on the number of cols already in a "line"
  3. Set the starting x position of that col and set the y position to 0 and update the line length for the children context so that line breaks will be placed correctly.
  4. Render children

This approach has gotten me close, and having a colleague test it out gives this result: IMG_1429

As you can see, the two columns are placed on top of each other. After reading the manual, I believe this is because I've set the x position of the second column too high.

FouadRaheb commented 8 months ago

Check this out, I've used this library in the past to generate ESC/POS commands, it uses some sort of table with predefined columns layout.

zaviermiller commented 8 months ago

Awesome! I'll check that out and see if it can help