Slick Forums

Some custom font advice
Page 1 of 1

Author:  abcdef [ Thu Aug 08, 2013 6:07 am ]
Post subject:  Some custom font advice


Hi, I was wondering if I could some advice. I can load .TTF fonts in to TWL ok. Its quite easy I just use the theme editor and it creates the necessary .fnt and .png file.

i have also been given some custom fonts files (old ones is a custom format), I'd like to use them. So far I can read the file format. So I have access to most of the information. I plan on cloning the current bitmap font class (which has Glyph's).

The font glyph data looks like this

[GlyphInfo] [id]47 [unknown] 0.0 [xTL]0.19921875 [yTL]0.34375 [xTR]0.22265625 [yTR]0.34375 [xBL]0.19921875 [yBL]0.40234375 [xBR]0.22265625 [yBR]0.40234375 [width]6.0 [height]15.0 [unknown2]0.0 [kerning]-1.0 [ascent]14.0

[GlyphInfo] [id]48 [unknown] 0.0 [xTL]0.16015625 [yTL]0.40234375 [xTR]0.1953125 [yTR]0.40234375 [xBL]0.16015625 [yBL]0.453125 [xBR]0.1953125 [yBR]0.453125 [width]9.0 [height]13.0 [unknown2]0.0 [kerning]-1.0 [ascent]12.0

[GlyphInfo] [id]49 [unknown] 0.0 [xTL]0.1015625 [yTL]0.4609375 [xTR]0.12890625 [yTR]0.4609375 [xBL]0.1015625 [yBL]0.51953125 [xBR]0.12890625 [yBR]0.51953125 [width]7.0 [height]15.0 [unknown2]0.0 [kerning]-1.0 [ascent]14.0

id is the ascii code, both unknowns are always 0, the xTL to yBR is just texture coordinates(between 0 and 1 with texture file being 256x256) so this pretty much maps to x,y,width,height that you have (after some calculations). The width and height seem to map to the pixel width/height in the 256x256 file (same as calculating direct from texture coords). Which leaves the last 2 variables, kerning and ascent. I wasn't sure what these would map to with the other variables you have (xoffset,yoffset, xadvance)

The example font above had point size of 16

    <char id="47" x="175" y="13" width="9" height="12" xoffset="-1" yoffset="-1" xadvance="8" page="0" chnl="0" />
    <char id="48" x="156" y="38" width="6" height="8" xoffset="-1" yoffset="3" xadvance="5" page="0" chnl="0" />
    <char id="49" x="149" y="38" width="6" height="8" xoffset="-2" yoffset="2" xadvance="4" page="0" chnl="0" />

Any advice you can give you be great. Ideally I'd like to use the same glyph drawing you have but with my own custom values in them.

Thanks in advance

Author:  MatthiasM [ Thu Aug 08, 2013 6:52 pm ]
Post subject:  Re: Some custom font advice

That's a really strange format.

Xadvance is the amount of pixels to advance after drawing that glyph, it is different from the width of the glyph.
Kerning is the adjustment to xadvance between a pair of glyphs - eg when you have a 'W' followed by an 'e' you have a negative kerning to move the 'e' closer to the 'W'.

So no idea how that kerning value is usable at all.

Author:  abcdef [ Thu Aug 08, 2013 7:33 pm ]
Post subject:  Re: Some custom font advice

The font can be read in to MyGUI (C++ kind of thing for what you have done)

It seems to map the advance and bearing values from

            code->addAttribute("advance", data[i].width);
            code->addAttribute("bearing", MyGUI::utility::toString(data[i].kerning) + " "+ MyGUI::utility::toString((fontSize-data[i].ascent)));

And kerning seems to map to bearing.left and ascent maps to

3. Bearings and Advances, here describes what FreeType has for bearing and advance ... phs-3.html

I know you use Freetype to generate your data so was wondering if it made sense to you at all?

Author:  MatthiasM [ Thu Aug 08, 2013 7:52 pm ]
Post subject:  Re: Some custom font advice

Kerning is defined like this: (leftGlpyh, rightGlyph) => offset
And that means there can be several values per glyph - so having only a single value per glyph doesn't make any sense to me.

Author:  abcdef [ Thu Aug 08, 2013 9:40 pm ]
Post subject:  Re: Some custom font advice

My current theory is that kerning in an incorrect term (from what you say) with the xoffset = kerning and yoffset = pointsize-ascent (point size = 16 in my example) and there are no official kerning values.

I'll give it a go

Author:  MatthiasM [ Thu Aug 08, 2013 10:29 pm ]
Post subject:  Re: Some custom font advice

Hmm, in that case - might be right. You will have to try it - there are so many different ways to describe glyphs.

Author:  abcdef [ Thu Aug 15, 2013 6:53 pm ]
Post subject:  Re: Some custom font advice


Just to let you know the font loads fine, I created a FontDecoder like the texture decoder and allowed both types to be loaded (new and old one) so it can all still be configured in the theme.xml

Thanks for your help MatthiasM

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group