1

I have a libgdx project that supports an android and a desktop version. For the fonts I previously used the FreeTypeFontGenerator to generate my fonts. Fonts worked fine, but then I decided to create my BitmapFonts with a .fnt & .png file, to have the option to also support a html project (FreeTypeFontGenerator is not compatible with html)

The Problem: If I launch the android project then there are no special chars like (ü, ñ, etc.) displayed:

--> in android text is displayed like this: ber

--> in desktop text is correctly displayed like this: über

The odd thing is that if I run the desktop version the special characters just work fine, although the desktop version uses the exactly same code (since I create the font in the core project):

font = new BitmapFont(Gdx.files.internal("fonts/gooddog40.fnt"), 
       new TextureRegion(new Texture("fonts/gooddog40.png")));

The .fnt & .png files looks actually good to me (and it works fine in desktop!), since I can see special chars contained there. I create the following using Hiero font generator:

gooddog40.png

enter image description here

gooddog40.fnt

info face="GoodDog" size=40 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=0,0
common lineHeight=42 base=34 scaleW=512 scaleH=512 pages=1 packed=0
page id=0 file="gooddog40.png"
chars count=149
char id=32   x=0     y=0     width=0     height=0     xoffset=0     yoffset=34    xadvance=7     page=0  chnl=0 
char id=106   x=0     y=0     width=19     height=34     xoffset=-5     yoffset=8    xadvance=8     page=0  chnl=0 
char id=116   x=19     y=0     width=18     height=32     xoffset=0     yoffset=10    xadvance=16     page=0  chnl=0 
char id=89   x=37     y=0     width=16     height=31     xoffset=0     yoffset=7    xadvance=14     page=0  chnl=0 
char id=124   x=53     y=0     width=8     height=30     xoffset=1     yoffset=7    xadvance=7     page=0  chnl=0 
char id=125   x=61     y=0     width=14     height=30     xoffset=0     yoffset=7    xadvance=13     page=0  chnl=0 
char id=83   x=75     y=0     width=21     height=30     xoffset=-1     yoffset=7    xadvance=18     page=0  chnl=0 
char id=82   x=96     y=0     width=19     height=30     xoffset=0     yoffset=6    xadvance=16     page=0  chnl=0 
char id=80   x=115     y=0     width=22     height=30     xoffset=-1     yoffset=6    xadvance=19     page=0  chnl=0 
char id=75   x=137     y=0     width=16     height=30     xoffset=0     yoffset=7    xadvance=14     page=0  chnl=0 
char id=92   x=153     y=0     width=20     height=29     xoffset=-1     yoffset=7    xadvance=17     page=0  chnl=0 
char id=64   x=173     y=0     width=22     height=29     xoffset=0     yoffset=7    xadvance=20     page=0  chnl=0 
char id=123   x=195     y=0     width=21     height=29     xoffset=-1     yoffset=7    xadvance=18     page=0  chnl=0 
char id=93   x=216     y=0     width=21     height=29     xoffset=0     yoffset=7    xadvance=18     page=0  chnl=0 
char id=91   x=237     y=0     width=24     height=29     xoffset=0     yoffset=7    xadvance=21     page=0  chnl=0 
char id=33   x=261     y=0     width=11     height=29     xoffset=0     yoffset=7    xadvance=9     page=0  chnl=0 
char id=121   x=272     y=0     width=22     height=29     xoffset=-4     yoffset=13    xadvance=14     page=0  chnl=0 
char id=112   x=294     y=0     width=16     height=29     xoffset=0     yoffset=13    xadvance=14     page=0  chnl=0 
char id=108   x=310     y=0     width=8     height=29     xoffset=0     yoffset=7    xadvance=8     page=0  chnl=0 
char id=107   x=318     y=0     width=18     height=29     xoffset=-1     yoffset=7    xadvance=15     page=0  chnl=0 
char id=103   x=336     y=0     width=15     height=29     xoffset=0     yoffset=13    xadvance=13     page=0  chnl=0 
char id=98   x=351     y=0     width=18     height=29     xoffset=0     yoffset=7    xadvance=16     page=0  chnl=0 
char id=88   x=369     y=0     width=23     height=29     xoffset=-1     yoffset=7    xadvance=20     page=0  chnl=0 
char id=84   x=392     y=0     width=20     height=29     xoffset=-1     yoffset=7    xadvance=17     page=0  chnl=0 
char id=81   x=412     y=0     width=20     height=29     xoffset=0     yoffset=7    xadvance=17     page=0  chnl=0 
char id=77   x=432     y=0     width=27     height=29     xoffset=-1     yoffset=7    xadvance=24     page=0  chnl=0 
char id=193   x=459     y=0     width=18     height=37     xoffset=0     yoffset=0    xadvance=16     page=0  chnl=0 
char id=192   x=477     y=0     width=18     height=37     xoffset=0     yoffset=0    xadvance=16     page=0  chnl=0 
char id=196   x=0     y=37     width=18     height=36     xoffset=0     yoffset=1    xadvance=16     page=0  chnl=0 
char id=195   x=18     y=37     width=20     height=36     xoffset=0     yoffset=1    xadvance=16     page=0  chnl=0 
char id=194   x=38     y=37     width=18     height=36     xoffset=0     yoffset=1    xadvance=16     page=0  chnl=0 
char id=217   x=56     y=37     width=21     height=35     xoffset=0     yoffset=1    xadvance=19     page=0  chnl=0 
char id=203   x=77     y=37     width=16     height=35     xoffset=0     yoffset=0    xadvance=14     page=0  chnl=0 
char id=220   x=93     y=37     width=21     height=34     xoffset=0     yoffset=2    xadvance=19     page=0  chnl=0 
char id=219   x=114     y=37     width=21     height=34     xoffset=0     yoffset=2    xadvance=19     page=0  chnl=0 
char id=218   x=135     y=37     width=21     height=34     xoffset=0     yoffset=2    xadvance=19     page=0  chnl=0 
char id=202   x=156     y=37     width=17     height=34     xoffset=-1     yoffset=1    xadvance=14     page=0  chnl=0 
char id=200   x=173     y=37     width=16     height=34     xoffset=0     yoffset=1    xadvance=14     page=0  chnl=0 
char id=197   x=189     y=37     width=18     height=34     xoffset=0     yoffset=3    xadvance=16     page=0  chnl=0 
char id=251   x=207     y=37     width=16     height=33     xoffset=0     yoffset=4    xadvance=15     page=0  chnl=0 
char id=249   x=223     y=37     width=16     height=33     xoffset=0     yoffset=4    xadvance=15     page=0  chnl=0 
char id=227   x=239     y=37     width=17     height=33     xoffset=0     yoffset=4    xadvance=14     page=0  chnl=0 
char id=209   x=256     y=37     width=17     height=33     xoffset=-1     yoffset=1    xadvance=14     page=0  chnl=0 
char id=207   x=273     y=37     width=19     height=33     xoffset=-3     yoffset=1    xadvance=6     page=0  chnl=0 
char id=206   x=292     y=37     width=19     height=33     xoffset=-3     yoffset=1    xadvance=6     page=0  chnl=0 
char id=204   x=311     y=37     width=9     height=33     xoffset=-1     yoffset=1    xadvance=6     page=0  chnl=0 
char id=201   x=320     y=37     width=16     height=33     xoffset=0     yoffset=2    xadvance=14     page=0  chnl=0 
char id=250   x=336     y=37     width=16     height=32     xoffset=0     yoffset=5    xadvance=15     page=0  chnl=0 
char id=224   x=352     y=37     width=17     height=32     xoffset=0     yoffset=5    xadvance=14     page=0  chnl=0 
char id=205   x=369     y=37     width=13     height=32     xoffset=0     yoffset=2    xadvance=6     page=0  chnl=0 
char id=252   x=382     y=37     width=16     height=31     xoffset=0     yoffset=6    xadvance=15     page=0  chnl=0 
char id=228   x=398     y=37     width=17     height=31     xoffset=0     yoffset=6    xadvance=14     page=0  chnl=0 
char id=226   x=415     y=37     width=17     height=31     xoffset=0     yoffset=6    xadvance=14     page=0  chnl=0 
char id=165   x=432     y=37     width=16     height=31     xoffset=0     yoffset=7    xadvance=14     page=0  chnl=0 
char id=225   x=448     y=37     width=17     height=30     xoffset=0     yoffset=7    xadvance=14     page=0  chnl=0 
char id=213   x=465     y=37     width=19     height=30     xoffset=0     yoffset=4    xadvance=16     page=0  chnl=0 
char id=232   x=484     y=37     width=15     height=29     xoffset=0     yoffset=6    xadvance=14     page=0  chnl=0 
char id=231   x=0     y=73     width=18     height=29     xoffset=-1     yoffset=12    xadvance=15     page=0  chnl=0 
char id=212   x=18     y=73     width=19     height=29     xoffset=0     yoffset=5    xadvance=16     page=0  chnl=0 
char id=211   x=37     y=73     width=19     height=29     xoffset=0     yoffset=5    xadvance=16     page=0  chnl=0 
char id=210   x=56     y=73     width=19     height=29     xoffset=0     yoffset=5    xadvance=16     page=0  chnl=0 
char id=161   x=75     y=73     width=11     height=29     xoffset=0     yoffset=7    xadvance=9     page=0  chnl=0 
char id=76   x=86     y=73     width=20     height=29     xoffset=-1     yoffset=7    xadvance=17     page=0  chnl=0 
char id=72   x=106     y=73     width=17     height=29     xoffset=0     yoffset=8    xadvance=16     page=0  chnl=0 
char id=70   x=123     y=73     width=16     height=29     xoffset=0     yoffset=7    xadvance=14     page=0  chnl=0 
char id=66   x=139     y=73     width=18     height=29     xoffset=0     yoffset=7    xadvance=16     page=0  chnl=0 
char id=65   x=157     y=73     width=18     height=29     xoffset=0     yoffset=8    xadvance=16     page=0  chnl=0 
char id=235   x=175     y=73     width=15     height=28     xoffset=0     yoffset=7    xadvance=14     page=0  chnl=0 
char id=234   x=190     y=73     width=16     height=28     xoffset=-1     yoffset=7    xadvance=14     page=0  chnl=0 
char id=233   x=206     y=73     width=15     height=28     xoffset=0     yoffset=7    xadvance=14     page=0  chnl=0 
char id=229   x=221     y=73     width=17     height=28     xoffset=0     yoffset=9    xadvance=14     page=0  chnl=0 
char id=214   x=238     y=73     width=19     height=28     xoffset=0     yoffset=6    xadvance=16     page=0  chnl=0 
char id=191   x=257     y=73     width=15     height=28     xoffset=0     yoffset=7    xadvance=13     page=0  chnl=0 
char id=38   x=272     y=73     width=13     height=28     xoffset=0     yoffset=8    xadvance=11     page=0  chnl=0 
char id=35   x=285     y=73     width=22     height=28     xoffset=-1     yoffset=8    xadvance=20     page=0  chnl=0 
char id=47   x=307     y=73     width=19     height=28     xoffset=-1     yoffset=8    xadvance=15     page=0  chnl=0 
char id=41   x=326     y=73     width=14     height=28     xoffset=0     yoffset=8    xadvance=12     page=0  chnl=0 
char id=40   x=340     y=73     width=16     height=28     xoffset=-1     yoffset=8    xadvance=13     page=0  chnl=0 
char id=63   x=356     y=73     width=16     height=28     xoffset=-1     yoffset=8    xadvance=13     page=0  chnl=0 
char id=102   x=372     y=73     width=16     height=28     xoffset=0     yoffset=7    xadvance=14     page=0  chnl=0 
char id=90   x=388     y=73     width=25     height=28     xoffset=-1     yoffset=8    xadvance=22     page=0  chnl=0 
char id=86   x=413     y=73     width=18     height=28     xoffset=0     yoffset=7    xadvance=16     page=0  chnl=0 
char id=242   x=431     y=73     width=13     height=27     xoffset=0     yoffset=4    xadvance=11     page=0  chnl=0 
char id=241   x=444     y=73     width=18     height=27     xoffset=0     yoffset=7    xadvance=14     page=0  chnl=0 
char id=199   x=462     y=73     width=20     height=27     xoffset=0     yoffset=14    xadvance=18     page=0  chnl=0 
char id=37   x=482     y=73     width=26     height=27     xoffset=-1     yoffset=9    xadvance=25     page=0  chnl=0 
char id=36   x=0     y=102     width=16     height=27     xoffset=-1     yoffset=9    xadvance=12     page=0  chnl=0 
char id=113   x=16     y=102     width=27     height=27     xoffset=0     yoffset=15    xadvance=15     page=0  chnl=0 
char id=85   x=43     y=102     width=21     height=27     xoffset=0     yoffset=9    xadvance=19     page=0  chnl=0 
char id=245   x=64     y=102     width=19     height=26     xoffset=-1     yoffset=5    xadvance=11     page=0  chnl=0 
char id=244   x=83     y=102     width=14     height=26     xoffset=-1     yoffset=5    xadvance=11     page=0  chnl=0 
char id=239   x=97     y=102     width=18     height=26     xoffset=-2     yoffset=8    xadvance=7     page=0  chnl=0 
char id=238   x=115     y=102     width=18     height=26     xoffset=-3     yoffset=8    xadvance=7     page=0  chnl=0 
char id=237   x=133     y=102     width=10     height=26     xoffset=1     yoffset=8    xadvance=7     page=0  chnl=0 
char id=59   x=143     y=102     width=8     height=26     xoffset=0     yoffset=14    xadvance=6     page=0  chnl=0 
char id=71   x=151     y=102     width=18     height=26     xoffset=0     yoffset=11    xadvance=16     page=0  chnl=0 
char id=69   x=169     y=102     width=16     height=26     xoffset=0     yoffset=9    xadvance=14     page=0  chnl=0 
char id=246   x=185     y=102     width=15     height=25     xoffset=0     yoffset=6    xadvance=11     page=0  chnl=0 
char id=243   x=200     y=102     width=13     height=25     xoffset=0     yoffset=6    xadvance=11     page=0  chnl=0 
char id=236   x=213     y=102     width=10     height=25     xoffset=-1     yoffset=9    xadvance=7     page=0  chnl=0 
char id=100   x=223     y=102     width=16     height=25     xoffset=0     yoffset=11    xadvance=15     page=0  chnl=0 
char id=78   x=239     y=102     width=15     height=25     xoffset=0     yoffset=9    xadvance=14     page=0  chnl=0 
char id=74   x=254     y=102     width=17     height=25     xoffset=0     yoffset=9    xadvance=15     page=0  chnl=0 
char id=56   x=271     y=102     width=19     height=24     xoffset=0     yoffset=12    xadvance=17     page=0  chnl=0 
char id=120   x=290     y=102     width=23     height=24     xoffset=-1     yoffset=15    xadvance=19     page=0  chnl=0 
char id=117   x=313     y=102     width=16     height=24     xoffset=0     yoffset=13    xadvance=15     page=0  chnl=0 
char id=104   x=329     y=102     width=15     height=24     xoffset=0     yoffset=12    xadvance=14     page=0  chnl=0 
char id=97   x=344     y=102     width=17     height=24     xoffset=0     yoffset=13    xadvance=14     page=0  chnl=0 
char id=87   x=361     y=102     width=27     height=24     xoffset=0     yoffset=10    xadvance=24     page=0  chnl=0 
char id=73   x=388     y=102     width=8     height=24     xoffset=0     yoffset=10    xadvance=6     page=0  chnl=0 
char id=68   x=396     y=102     width=19     height=24     xoffset=0     yoffset=10    xadvance=15     page=0  chnl=0 
char id=57   x=415     y=102     width=14     height=23     xoffset=0     yoffset=13    xadvance=12     page=0  chnl=0 
char id=54   x=429     y=102     width=18     height=23     xoffset=-1     yoffset=13    xadvance=15     page=0  chnl=0 
char id=115   x=447     y=102     width=17     height=23     xoffset=-1     yoffset=14    xadvance=14     page=0  chnl=0 
char id=114   x=464     y=102     width=16     height=23     xoffset=-1     yoffset=13    xadvance=13     page=0  chnl=0 
char id=109   x=480     y=102     width=25     height=23     xoffset=0     yoffset=15    xadvance=24     page=0  chnl=0 
char id=105   x=0     y=129     width=8     height=23     xoffset=1     yoffset=11    xadvance=7     page=0  chnl=0 
char id=99   x=8     y=129     width=18     height=23     xoffset=-1     yoffset=12    xadvance=15     page=0  chnl=0 
char id=79   x=26     y=129     width=19     height=23     xoffset=0     yoffset=11    xadvance=16     page=0  chnl=0 
char id=167   x=45     y=129     width=24     height=22     xoffset=0     yoffset=14    xadvance=23     page=0  chnl=0 
char id=58   x=69     y=129     width=8     height=22     xoffset=0     yoffset=14    xadvance=6     page=0  chnl=0 
char id=48   x=77     y=129     width=21     height=22     xoffset=0     yoffset=13    xadvance=17     page=0  chnl=0 
char id=55   x=98     y=129     width=19     height=22     xoffset=-1     yoffset=13    xadvance=16     page=0  chnl=0 
char id=53   x=117     y=129     width=17     height=22     xoffset=0     yoffset=14    xadvance=16     page=0  chnl=0 
char id=52   x=134     y=129     width=19     height=22     xoffset=-1     yoffset=14    xadvance=15     page=0  chnl=0 
char id=50   x=153     y=129     width=18     height=22     xoffset=0     yoffset=14    xadvance=17     page=0  chnl=0 
char id=49   x=171     y=129     width=9     height=22     xoffset=0     yoffset=14    xadvance=7     page=0  chnl=0 
char id=118   x=180     y=129     width=20     height=22     xoffset=-1     yoffset=11    xadvance=17     page=0  chnl=0 
char id=67   x=200     y=129     width=20     height=22     xoffset=0     yoffset=14    xadvance=18     page=0  chnl=0 
char id=42   x=220     y=129     width=19     height=21     xoffset=0     yoffset=8    xadvance=17     page=0  chnl=0 
char id=62   x=239     y=129     width=19     height=21     xoffset=-1     yoffset=11    xadvance=15     page=0  chnl=0 
char id=122   x=258     y=129     width=21     height=21     xoffset=0     yoffset=15    xadvance=19     page=0  chnl=0 
char id=119   x=279     y=129     width=26     height=21     xoffset=0     yoffset=15    xadvance=24     page=0  chnl=0 
char id=60   x=305     y=129     width=20     height=20     xoffset=0     yoffset=12    xadvance=18     page=0  chnl=0 
char id=51   x=325     y=129     width=17     height=20     xoffset=-1     yoffset=14    xadvance=14     page=0  chnl=0 
char id=101   x=342     y=129     width=15     height=20     xoffset=0     yoffset=15    xadvance=14     page=0  chnl=0 
char id=110   x=357     y=129     width=13     height=18     xoffset=1     yoffset=17    xadvance=14     page=0  chnl=0 
char id=111   x=370     y=129     width=13     height=17     xoffset=0     yoffset=14    xadvance=11     page=0  chnl=0 
char id=61   x=383     y=129     width=13     height=16     xoffset=0     yoffset=13    xadvance=11     page=0  chnl=0 
char id=43   x=396     y=129     width=15     height=15     xoffset=0     yoffset=14    xadvance=13     page=0  chnl=0 
char id=34   x=411     y=129     width=13     height=14     xoffset=0     yoffset=7    xadvance=12     page=0  chnl=0 
char id=94   x=424     y=129     width=14     height=13     xoffset=0     yoffset=7    xadvance=12     page=0  chnl=0 
char id=44   x=438     y=129     width=8     height=13     xoffset=0     yoffset=27    xadvance=6     page=0  chnl=0 
char id=39   x=446     y=129     width=7     height=13     xoffset=0     yoffset=7    xadvance=5     page=0  chnl=0 
char id=126   x=453     y=129     width=17     height=11     xoffset=0     yoffset=7    xadvance=15     page=0  chnl=0 
char id=96   x=470     y=129     width=9     height=10     xoffset=0     yoffset=7    xadvance=7     page=0  chnl=0 
char id=180   x=479     y=129     width=8     height=9     xoffset=0     yoffset=8    xadvance=6     page=0  chnl=0 
char id=168   x=487     y=129     width=14     height=9     xoffset=1     yoffset=7    xadvance=13     page=0  chnl=0 
char id=46   x=501     y=129     width=8     height=9     xoffset=0     yoffset=27    xadvance=6     page=0  chnl=0 
char id=45   x=0     y=152     width=16     height=6     xoffset=0     yoffset=21    xadvance=14     page=0  chnl=0 
kernings count=-1

What I tried to debug it:

  1. cleaning project and launching it again
  2. Added a log statement: Gdx.app.log("font", "contains ü: " + font.containsCharacter('ü')); which prints font: contains ü: true for both android and desktop project!! So at some point the android project is aware of the existence of the special char in the font, but why it cannot display it?

What could be the reason why this font doesn't display special chars in android, but in desktop it does?

donfuxx
  • 10,696
  • 6
  • 41
  • 74

1 Answers1

2

Now I identified the root cause of the problem: In the end was an encoding problem.

A bit surprizing to me since I used the same Text resources for desktop & android, but it turns out that the android version didn't like the encoding ISO-8859-1, while desktop was fine with that.

Changing the encoding to utf-8 fixed the display of the special chars in android.


In the end I have the following solution to get the text translations while I keep using the same resource bundle properties (encoded in utf-8) for both projects:

public String get(String key) {
    if(dictBundle.containsKey(key)) {           
        if (isDesktop) {
            try {
                return new String(dictBundle.getString(key).getBytes("ISO-8859-1"), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return dictBundle.getString(key);
    }
    return key;
}

where dictBundle is my ResourceBundle and I set the boolean isDesktop the following way:

isDesktop = Gdx.app.getType().equals(Application.ApplicationType.Desktop);
donfuxx
  • 10,696
  • 6
  • 41
  • 74