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

Cyrillic encoding seems not to work #69

Open
vasilevzhivko opened this issue Jan 7, 2021 · 2 comments
Open

Cyrillic encoding seems not to work #69

vasilevzhivko opened this issue Jan 7, 2021 · 2 comments

Comments

@vasilevzhivko
Copy link

Hello,
I am trying to print in Bulgarian language, but the encoding seems not to work.
Here is my code:

var commandsArray = [];
commandsArray.push({appendEncoding: StarPRNT.Encoding.Windows1251});
commandsArray.push({appendAlignment: StarPRNT.AlignmentPosition.Center});
commandsArray.push({append: '* ******** *\n'});
commandsArray.push({append: '* Български *\n'});
commandsArray.push({
  appendCutPaper: StarPRNT.CutPaperAction.PartialCutWithFeed,
});

async function print() {
  try {
    var printResult = await StarPRNT.print(
      'StarPRNT',
      commandsArray,
      'BT:00:15:0E:E6:6E:74',
    );
    console.log(printResult); // Success!
  } catch (e) {
    console.error(e);
  }
}

when I print I only get some strange symbols. Anyone else tried to print in Bulgarian/Russian?

@infoxicator
Copy link
Owner

Take a look at the official Star documentation to see if you can find the correct encoding

@vasilevzhivko
Copy link
Author

vasilevzhivko commented Jan 22, 2021

Take a look at the official Star documentation to see if you can find the correct encoding

Found the solution, if you want I can create a pull request. Its quite simple actually for some printers (for example mine: SM-S230I) the encoding is really specific in my case for Bulgarian language is CP855 and for Russian is CP866.
So what is needed is to add the encodings in types\index.d.ts like so:

    static Encoding: {
        USASCII: string,
        Windows1252: string,
        ShiftJIS: string,
        Windows1251: string,
        GB2312: string,
        Big5: string,
        UTF8: string,
        CP855: string
    };

and also in RNStarPrntModule.java a little modification to the getEncoding function like so:

        else if (encoding.equals("CP855")) {
            try {
                return Charset.forName("CP855"); // Bulgarian
            }
            catch (UnsupportedCharsetException e) { //not supported using UTF-8 Instead
                return Charset.forName("UTF-8");
            }
        }

p.s. I found the encodings here:
Encodings for Java

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

2 participants