trouble importing custom bitmap fonts

Former Member
Former Member
Hi, I've having difficulty importing and displaying bitmap fonts.

I can create .png and .fnt files and file them under
/resources/resource/fonts/<myfont>.png
/resources/resource/fonts/<myfont>.fnt

Then I update my resources.xml file as such
<resources>
<fonts>
<font id="id_<myfont>" filename="fonts/<myfont>.fnt" filter="0123456789" />
</fonts>
</resources>

And load the resource
font = Ui.loadResource(Rez.Fonts.id_<myfont>);

But it still won't display when I
dc.drawText((width/2),(width/2),font,"12",Gfx.TEXT_JUSTIFY_CENTER);

Nothing is overlapping. Colors are not the same as the background. I can swap "font" with Gfx.FONT_MEDIUM and it will work just fine.

Any ideas? Am I missing something? How might I best approach debugging this issue? Thanks!
  • Former Member
    Former Member over 10 years ago
    It is funny because I actually have the same problem as you do. Everything in place, the code compiles just fine, but the text simply does not show up. It looks like this:


    Any ideas?
  • Former Member
    Former Member over 10 years ago
    remove the extra resource folder

    /resources/fonts/<myfont>.png

    /resources/fonts/<myfont>.fnt
  • Former Member
    Former Member over 10 years ago
    .. and the extra xml tags

    <resources>
    <font id="id_<myfont>" filename="fonts/<myfont>.fnt" filter="0123456789" />
    </resources>
  • Former Member
    Former Member over 10 years ago
    remove the extra resource folder

    /resources/fonts/<myfont>.png

    /resources/fonts/<myfont>.fnt


    The extra resource folder won't matter as long as the base folder starts with "resource".

    .. and the extra xml tags

    <resources>
    <font id="id_<myfont>" filename="fonts/<myfont>.fnt" filter="0123456789" />
    </resources>


    This is my guess as to why it's not working for you. Does removing the "<" and ">" form your ID get things working?
  • Former Member
    Former Member over 10 years ago
    Are you having Friday drinks?
  • Former Member
    Former Member over 10 years ago
    oops, sorry guys bad example? my actual code doesn't use <myfont>, it's the actual font name.

    As in the Analog sample code, which I modeled after:
    /resources/resource/fonts/blackdiamond_0.png
    /resources/resource/fonts/blackdiamond.fnt

    <resources>
    <font id="id_font_black_diamond" filename="fonts/blackdiamond.fnt" filter="0123456789" />
    </resources>

    but if I use my own font it doesn't work..

    Do the characters in the png need to be in a specific position, size, or format? I would assume the .fnt file specifies all of that for the program..
  • what does your .fnt file look like? It should be a text file.
  • Former Member
    Former Member over 10 years ago
    what does your .fnt file look like? It should be a text file.


    info face="Ubuntu Light" size=10 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=2,2,2,2 spacing=0,0 outline=0
    common lineHeight=11 base=7 scaleW=18 scaleH=93 pages=1 packed=0
    page id=0 file="ubuntu_light.png"
    chars count=10
    char id=49 x=2 y=2 width=5 height=9 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=50 x=2 y=13 width=6 height=9 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=51 x=2 y=24 width=7 height=10 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=52 x=9 y=2 width=7 height=9 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=53 x=10 y=13 width=6 height=9 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=54 x=2 y=36 width=7 height=9 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=55 x=2 y=47 width=7 height=9 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=56 x=2 y=58 width=7 height=10 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=57 x=2 y=70 width=7 height=9 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=48 x=2 y=81 width=7 height=10 xoffset=1 yoffset=0 xadvance=6 page=0 chnl=15
    char id=32 x=0 y=0 width=0 height=0 xoffset=1 yoffset=0 xadvance=2 page=0 chnl=15
    kernings count=0
  • Former Member
    Former Member over 10 years ago
    If I remember rightly you need a minimum of 12 characters, and the char sequence must be in order. So map 48 - 57, change the 32 to 47 or 58, and add 1 more at the end. You can exclude the kernings value. If you don't need all 12 chars then you can still map in less.
  • Former Member
    Former Member over 10 years ago
    Resolved: I have it displaying custom fonts now. Thank you all for your help!

    I added additional chars and reordered the .fnt chars and it still wasn't working/ Once I restarted Eclipse it worked!