[SOLVED] Character encoding support in fonts?

Hi :slight_smile:
I have a .fnt + .png files prepared that contains not only latin letters, but also some funny characters used in language other than english (like ł which is unsigned byte value 179 decimal).
I have a text file encoded with Windows-1250 code page that contains characters mentioned above.

I would like to utilize BitmapFont and BitmapText classes in a way that the funny characters from Windows-1250 charset are properly displayed.
Is it possible?
How can I do that?

The BitmapText.setText() method accepts String as argument. Maybe it’s just about proper handling of the data from file, so that the byte numbers don’t get improperly translated when putting it into String, but I failed to do that so far…

Cheers :slight_smile:

Pretty sure you need to convert your characters to the UTF-8 versions and save the file as UTF-8.

1 Like

I managed to achieve my goal:

                byte[] fileBytes = Files.readAllBytes(Paths.get(PATH + "font-test-text.txt"));

                var builder = new StringBuilder();
                for (var b : fileBytes) {
                    char c = (char)((int)b & 0xFF); // signed -> unsigned
                    builder.append(c);
                }

                BitmapFont myFont = assetManager.loadFont("FONT_OLD_20_WHITE.fnt");
                BitmapText hudText2 = new BitmapText(myFont);

                hudText2.setText(builder.toString());

This way I avoid translation from Windows-1250 to Unicode.
So load byte values directly into a string. Just need to converse from signed bytes value that Java uses, to unsigned.
Such a string would look bad when for example System.out.print() due to weird characters it contains, but since my .fnt contains proper mapping for those character values, the graphic text looks good.

2 Likes