Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"5" character before line when .style('bu') #93

Open
andernunes opened this issue May 21, 2024 · 2 comments
Open

"5" character before line when .style('bu') #93

andernunes opened this issue May 21, 2024 · 2 comments

Comments

@andernunes
Copy link

A character "5" is printed before every line when use .style('bu).

Ex:
printer
.font('A')
.size(0, 1)
.style("bu")
.tableCustom([
{ text: item.qtd.toFixed(1), align: "LEFT", width: 0.1 },
{ text: item.produto.toUpperCase().trim(), align: "LEFT", width: 0.9 },
]);`

PRINT: "51.0 PRODUCTNAME 1.00 1.00"
EXPECTED: "1.0 PRODUCTNAME 1.00 1.00"

Copy link

dosubot bot commented May 21, 2024

The issue of a "5" character being printed before every line when using the .style('bu') method is due to the incorrect handling of the style string in the _getStyle method. Specifically, the method is returning the string "5" for the "BU" style, which is then written to the buffer.

To fix this issue, you need to correct the _getStyle method to return the appropriate ESC/POS commands for the "BU" style. Here is the corrected _getStyle method:

_getStyle(boldOrString: boolean | StyleString, italic?: boolean, underline?: boolean | 0 | 1 | 2) {
  if (typeof boldOrString === "string") {
    switch (utils.upperCase(boldOrString)) {
      case "B":
        return this._getStyle(true, false, 0);
      case "I":
        return this._getStyle(false, true, 0);
      case "U":
        return this._getStyle(false, false, 1);
      case "U2":
        return this._getStyle(false, false, 2);
      case "BI":
        return this._getStyle(true, true, 0);
      case "BIU":
        return this._getStyle(true, true, 1);
      case "BIU2":
        return this._getStyle(true, true, 2);
      case "BU":
        return this._getStyle(true, false, 1);
      case "BU2":
        return this._getStyle(true, false, 2);
      case "IU":
        return this._getStyle(false, true, 1);
      case "IU2":
        return this._getStyle(false, true, 2);
      case "NORMAL":
      default:
        return this._getStyle(false, false, 0);
    }
  } else {
    let styled = `${
      boldOrString ? _.TEXT_FORMAT.TXT_BOLD_ON : _.TEXT_FORMAT.TXT_BOLD_OFF
    }${
      italic ? _.TEXT_FORMAT.TXT_ITALIC_ON : _.TEXT_FORMAT.TXT_ITALIC_OFF
    }`;
    if (underline === 0 || underline === false) styled += _.TEXT_FORMAT.TXT_UNDERL_OFF;
    else if (underline === 1 || underline === true) styled += _.TEXT_FORMAT.TXT_UNDERL_ON;
    else if (underline === 2) styled += _.TEXT_FORMAT.TXT_UNDERL2_ON;
    return styled;
  }
}

This change ensures that the correct ESC/POS commands are returned for the "BU" style, preventing the "5" character from being printed before every line. The output will be as expected:

"1.0 PRODUCTNAME   1.00    1.00"

If you need further assistance or have any other questions, feel free to ask!

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@andernunes
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant