receiptline / receiptio

A print application for receipt printers, simple and easy with markdown, printer status support.
Apache License 2.0
67 stars 10 forks source link

Left margin option #5

Open locatellidaniel opened 1 year ago

locatellidaniel commented 1 year ago

Hi,

In the industry I work on it is very common that ticket paper has a color brand stripe to the left side: ticket-stripe

In order for the text not be placed over the stripe, some precautions should be taken.

My solution is to add a "margin" parameter ("-m") to receiptio, and then overwrite the "area" command accordingly:

const transform = async (receiptmd, printer) => {
    // ...
    // ...
    if (printer.leftMargin) {
        printer.command = Object.assign(
            {}, 
            typeof printer.command === 'object' ? printer.command : receiptline.commands[printer.command]
        );

        // overwrite area function
        const a = printer.command.area;
        printer.command.area = (left, width, right) => a(left + printer.leftMargin, width, right - printer.leftMargin);
    }

    return receiptline.transform(receiptmd, printer);
};

Also, the parameter cpl might need to be adjusted. i.e. with a cpl of 48 and a leftMargin of 2, will give a total width of 50, forcing the wrapping of every line.

So, when cpl is not manually provided it should be adjusted: cpl = default - leftMargin

I'm unsure this should be part of the receiptline or the receiptio tool. My implementation is on receiptio, but it might also fit as a general parameter in receiptline. It could also be extended to right margin, of course.

Regards,

receiptline commented 1 year ago

Hi,

Thank you for using ReceiptIO.

In our first meeting of the new year we discussed what the margin specification should be.

The first is the same as your solution, plus a proposal to add margin to ReceiptLine configurations as well.

The second is a proposal to reinstate the margin property, which was omitted when the ReceiptLine specification was developed.

We then decided to adopt the first proposal.

We thought that by considering the color stripe area of the ticket paper as a non-printable area, it would conform to the CPL definition in the ReceipLline specification.

The medium of paper or screen that outputs the image of ReceiptLine is called paper. The number of characters that can be printed in the horizontal direction of the paper is called characters per line (CPL).

We will implement this in the next update.

Thank you!

locatellidaniel commented 1 year ago

Thank you very much. We tried this new feature and it works good across our printers (Epson TM88-V+; Star TSP143)