How to get the length of a bitmap text?

Hi all,

maybe anyone already figured that out or has an idea:

If I use a Bitmap font of a true type text I get letters with variable length:


I would like to know if there is a way to get the length of the complete object from beginning of the first letter to the end of the last letter.
a simple fixedLength * len(string) would’t do it as there is no fixed length.

Thanks very much

I’m not sure, but here’s a basic idea - keep a dictionary of how wide each letter is. For example, all letters but i, j, l, and f are pretty much the same size, so you probably can step through the string to determine the total length according to the dictionary.

The problem is, where to get the size data from :D?
I’m pretty sure it is in the bitmap. But there is no access. The idea is, to get it running with any font texture :S.

If you use the BLF module[1], not only do you get anti-aliased true type fonts, but you can also get the size of a given string with blf. dimensions(fontid, “string”), which will return the height and width the given string will have with the given fontid. Unfortunately, blf can be a little weird to use in the BGE (raw OpenGL calls need to be used to line up matrices). I have a blf demo somewhere on these boards if you want to hunt them down. If you’re doing GUIs, I’d take a look at BGUI [2]. It makes GUIs in the BGE a lot easier. The downside to BGUI is that it’s still new and thus the API can be unstable (subject to change).

[1] http://www.blender.org/documentation/250PythonDoc/blf.html
[2] http://stokes.dyndns.org/redmine/projects/bgui/wiki

I saw the BGUI. It is fine

but that is not the plan I have right now. I still go with 2.49 and try with the available resources.
I just discovered that bitmap font characters can be wider than the single plane (e.g. character ‘w’) while ‘i’ is quite short. I might need to go with Joemans16’s idea of storing a width estimation dictionary.

The actual width of each character is stored in that row of dots along the top of the font- but unfortunately I’ve found absolutely no documentation as to how to translate it.