-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|391|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Showcase Home -> Apps and Utilities

Created : 12 February 2013
Edited : 30 March 2013
System : Mac
Language : C#


Simple bitmap font generator for OS X

GitHub Repo
sbfgen is a simple bitmap font generator (I was too lazy to even give it a real name) for Mac OS X. Basically, you tell it what characters you want, what font you want, and so on and it spits out PNGs with glyphs and a JSON file for you to work with. This was my solution to paying for a tool that generated bitmap fonts (that is, I didn't want to pay for it).

It's open source, I don't provide binaries, you'll have to build it yourself, etc. It's also licensed under the GPLv3.

To build it, you'll also need to compile libsnow-common and make sure to put it somewhere the compiler can see the headers and lib or provide the appropriate CFLAGS/LDFLAGS.

Once compiled, you can run the program with no arguments or either '-h' or '--help' to see what arguments it takes. There are also a few macros in the source code that you can play with that control how font pages are structured.

In general, the code is small, but it's a bit of a mess since I threw this thing together fairly quickly, so make sure to wear protective clothing - like a lead apron.

Latest Update

March 30, 2013

Tore out the old binpacker_t code for a new image packing class. It's slower, though probably not noticeably (and the way it's built allows it to terminate pretty early if a subimage won't fit in the image), but it produces far better results.


Tweaked the kernings loop to reduce the number of allocations it makes. Improves performance a bit (can shave about half a minute off if working with ~2000 glyphs), though this is negligible since getting the kernings is basically O(N^2), so it's really pretty much a worst case already.

So, it's still going to take a while and spin up fans since it uses as many cores as possible while getting glyph kernings, but it'll use slightly less memory and take slightly less time. In smaller sets of glyphs, it will probably be unnoticeable.



Tuesday, 12 February 2013, 03:59
"Sod paying for that, I can code it!!"
Always a great incentive for coding.
Tuesday, 12 February 2013, 04:04
I sometimes take it too far and code it even if it's free. Hell, my blog is built using my own software and not a standard blog tool thing. That said, if it's easy to make and the alternative is over $5, I'll just code it.
Monday, 04 March 2013, 05:56
Neat, I got it working. What's up with the (seemingly) haphazard arrangement of the resulting characters though? Not that it matters too much.
Tuesday, 05 March 2013, 01:33
It depends partly on the macros set for binpack_t in SnowCommon, but basically it tries to sort them by size and insert them into atlases using a binary tree structure. binpack_t does zero input optimization, however, so it can result in unusual results, like some glyph pages being created when glyphs would fit in others. I have some ideas for improving the results (like sorting all glyphs by width and then height) but haven't had time since I've had some other things to take care of.
Saturday, 30 March 2013, 17:57
I went and replaced the image packing code in sbfgen, so now it should produce .. well, slightly more haphazard character placement, but with much better packing overall. It may be slower in the short term, but I think I've done a decent job of making sure it fails a lot of its tests for whether an image fits early (thanks to the way slot_image_t and slot_mask_t works).