anastaciocintra / escpos-coffee

Java library for ESC/POS printer
https://anastaciocintra.github.io/escpos-coffee
MIT License
277 stars 72 forks source link

Style constructor deactivates paper feeding #61

Closed Martomate closed 3 years ago

Martomate commented 3 years ago

When new Style(style) is used defaultLineSpacing is always set to false. Since lineSpacing starts out as 0 this results in no paper feeding.

This is why: In the Style constructor we have:

defaultLineSpacing = another.defaultLineSpacing;
setLineSpacing(another.lineSpacing);

But in the setLineSpacing method we have:

this.defaultLineSpacing = false;
this.lineSpacing = lineSpacing;

This means that defaultLineSpacing will always be set to false, and since the default value of lineSpacing is 0 the paper will not feed.

anastaciocintra commented 3 years ago

Hi @Martomate ,

thanks to report this problem. I'm trying to reproduce the error on my printer (TM-T20) without success. can you help me?

I wrote this (working well, without bug)

    public void bugLineSpacing(EscPos escpos) throws IOException {

        Style style1 = new Style();
        style1.setLineSpacing(100);
        Style style2 = new Style(style1);
        escpos.write(style1,"hello");
        escpos.feed(style1,1);
        escpos.writeLF(style1,"Line Spacing");
        escpos.writeLF("-------");
        escpos.write(style2,"hello2");
        escpos.feed(style2,1);
        escpos.writeLF(style2,"Line Spacing2");
        escpos.writeLF("-------");
        style2.setLineSpacing(1);
        escpos.write(style2,"hello2");
        escpos.feed(style2,1);
        escpos.writeLF(style2,"Line Spacing2");
        escpos.writeLF("-------");

        escpos.feed(5).cut(EscPos.CutMode.FULL);
        escpos.close();
    }
Martomate commented 3 years ago

Hello, that code works because you set the line spacing manually. I didn't do that in my code.

anastaciocintra commented 3 years ago

Hi @Martomate , If the solution above is good for you, it's all right for me too, otherwise, count on me to find another. ... regardless of this problem, the function feed() need some repair. Some printers doesn't recognize 'ESC d' and in the future(backlog) we need to work on this.

see you

Martomate commented 3 years ago

Sure, that works. It is also possible to call escpos.resetLineSpacing(), or to just change the style given by escpos.getStyle() instead of creating a new one.

Now that you know of this bug you can fix it whenever it suits you. In the meantime these workarounds can be used.

Have a nice day!