A Font Tool

A forum to store posts deemed exceptionally wise and useful
Post Reply
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

A Font Tool

Post by Klunk »

I know there are some nice font tools already created for irrlicht, none of them quite did what i needed of them. So as you do, off to the internet to look for alternatives. Came across this....

http://www.angelcode.com/products/bmfont/

fits the bill, exactly except the output *.fnt format does not work with irrlicht so, created this utility to convert the bmFont ".fnt" font file (xml setting in export options) output to an Irrlicht ".xml" font file.

http://www.mediafire.com/download.php?pad4dr799dqeduz

it takes a single argument <filename>.fnt and creates a file <filename>.xml that should work with irrlicht. It will handle multiple bitmaps too.
All well and good upto now, but hang on bmfont being very clever does a best fit on the font glyphs, to reduce the space used in the bitmaps. But Irrlicht doesn't support variable height font glyphs, Doh ! Well unless you hack the source....

CGUIFont.h

modify SFontArea struct to this

Code: Select all

struct SFontArea
{
        SFontArea() : underhang(0), overhang(0), width(0), spriteno(0), voffset(0) {}
        s32                             underhang;
        s32                             overhang;
        s32                             width;
        s32                             voffset;  
        u32                             spriteno;
};
CGUIFont.cpp

add

Code: Select all

 
a.voffset       = xml->getAttributeValueAsInt(L"v");
to CGUIFont::load after

Code: Select all

a.overhang = xml->getAttributeValueAsInt(L"o");
to CGUIFont::draw add the following

Code: Select all

s32 saveYoffset = offset.Y;
directly after

Code: Select all

core::array<core::position2di> offsets(text.size());
add

Code: Select all

offset.Y = saveYoffset;
before

Code: Select all

wchar_t c = text[i];
and finally add

Code: Select all

offset.Y += area.voffset;
just before

Code: Select all

offset.X += area.underhang;
This code shouldn't have any effect on "traditional" irrlicht fixed height fonts as voffset is initialized to 0 and if the "v" attribute is not present it's ignored as per the "i" texture index attribute. If this code could be added to svn by someone who knows what they are doing that would be all well and dandy :)

anyway use it, don't use it, have a cup tea, whatever :)

a quick addendum:

though both bmfont & irrlicht font tool use px to define font size the following formula will match sizes

irrlicht = bmfont * 72 / 96

the 72/96 is generalized, if you have wacky screen settings it probably won't work.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: A Font Tool

Post by REDDemon »

fnt loading capability for irrlicht would be great :)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply