Slick Forums

Discuss the Slick 2D Library
It is currently Sat Dec 16, 2017 2:50 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Some custom font advice
PostPosted: Thu Aug 08, 2013 6:07 am 
Offline

Joined: Tue Oct 11, 2011 7:30 pm
Posts: 32
MatthiasM

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

Code:
[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

Code:
    <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


Top
 Profile  
 
PostPosted: Thu Aug 08, 2013 6:52 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
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.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Aug 08, 2013 7:33 pm 
Offline

Joined: Tue Oct 11, 2011 7:30 pm
Posts: 32
The font can be read in to MyGUI (C++ kind of thing for what you have done)

http://mygui.info/

It seems to map the advance and bearing values from

Code:
            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 bearing.top

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

http://www.freetype.org/freetype2/docs/ ... phs-3.html

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


Top
 Profile  
 
PostPosted: Thu Aug 08, 2013 7:52 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
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.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Aug 08, 2013 9:40 pm 
Offline

Joined: Tue Oct 11, 2011 7:30 pm
Posts: 32
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


Top
 Profile  
 
PostPosted: Thu Aug 08, 2013 10:29 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
Hmm, in that case - might be right. You will have to try it - there are so many different ways to describe glyphs.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Aug 15, 2013 6:53 pm 
Offline

Joined: Tue Oct 11, 2011 7:30 pm
Posts: 32
Hi

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group