More on the font engine
May. 6th, 2010 12:19 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I thought it might be interesting for people to see how I'm going to specify fonts.
In the previous font engine (which was essentially sprite-based), each font was a long, thin image with characters running horizontally in alphabetical order from the exclamation point ('!') to the 127th ASCII character ('}', as it turns out), with the top line of pixels indicating where each character stopped and started.
The font engine would run through this top line, looking for the spaces between the dots or dashes and extract each character, putting each into its own sprite.
This worked very well up until I needed to put a line of characters in front of a row of Tetris blocks, as the sprites were positioned based on screen pixels, and the Tetris rows were based on 3D space coordinates.
(granted, I did figure out how to do a rough conversion, but that wasn't a very good method, and it wouldn't let me do any rotations or scaling, which would be rather handy for extra effects)
However, the line of pixels indicating the extents of each character was something I could readily add, and I really liked how everything that specified a font was in one file.
(unlike some font engines I found...)
So, my next font engine will again use that row of pixels to specify character extents, but as I will use only one image texture for all the characters at the same time (no more texture splitting for now), I'll need to do "character wrapping", which also means that the line of character extents indicating pixels will also need to wrap.
(for some reason, graphics cards happen to like square images instead of long, thin ones)
I've started some work on the new font engine, which also means I've broken all the current font code, which then means the project won't even compile now.
Good incentive to get the new engine done quickly, eh? =^.^=
The one thing I'm not quite sure about, however, is generating the new fonts.
So far I've used The Gimp to create a 256x256 pixel image and paste in all the appropriate characters, tweaking the font sizes and stuff until almost all the space in the image is taken up without having anything overlap anything else, then laboriously putting in all the alignment pixels.
I'm thinking I should write a font generator in Java...
Edit: Just so people have an idea of what I mean, here is a possible font descriptor image for the new font engine:

Note that the strip of pixels indicates how wide each character is by indicating where the spaces are.
In the previous font engine (which was essentially sprite-based), each font was a long, thin image with characters running horizontally in alphabetical order from the exclamation point ('!') to the 127th ASCII character ('}', as it turns out), with the top line of pixels indicating where each character stopped and started.
The font engine would run through this top line, looking for the spaces between the dots or dashes and extract each character, putting each into its own sprite.
This worked very well up until I needed to put a line of characters in front of a row of Tetris blocks, as the sprites were positioned based on screen pixels, and the Tetris rows were based on 3D space coordinates.
(granted, I did figure out how to do a rough conversion, but that wasn't a very good method, and it wouldn't let me do any rotations or scaling, which would be rather handy for extra effects)
However, the line of pixels indicating the extents of each character was something I could readily add, and I really liked how everything that specified a font was in one file.
(unlike some font engines I found...)
So, my next font engine will again use that row of pixels to specify character extents, but as I will use only one image texture for all the characters at the same time (no more texture splitting for now), I'll need to do "character wrapping", which also means that the line of character extents indicating pixels will also need to wrap.
(for some reason, graphics cards happen to like square images instead of long, thin ones)
I've started some work on the new font engine, which also means I've broken all the current font code, which then means the project won't even compile now.
Good incentive to get the new engine done quickly, eh? =^.^=
The one thing I'm not quite sure about, however, is generating the new fonts.
So far I've used The Gimp to create a 256x256 pixel image and paste in all the appropriate characters, tweaking the font sizes and stuff until almost all the space in the image is taken up without having anything overlap anything else, then laboriously putting in all the alignment pixels.
I'm thinking I should write a font generator in Java...
Edit: Just so people have an idea of what I mean, here is a possible font descriptor image for the new font engine:
Note that the strip of pixels indicates how wide each character is by indicating where the spaces are.