- Joined: 03 Aug 2011
- Posts: 39
- Location: NW England
|
Proportional / variable width font/text routine
Posted: Mon Aug 29, 2011 8:49 pm
|
Hi All
As per Subject just wondering if anyone has ever written one thats based around a 5x7(ish) size ?
Something similar to what is used in "Golden Axe Warrior" in the 26x5 text window used for conversation dialogs.
If so - do you have any source code you might be willing to share - if not maybe someone has some useful tips/pointers towards writing one.
I'm looking into writing one myself, but don't want to re-invent the wheel if one already exists.
Richard / Sket
|
- Joined: 28 Sep 1999
- Posts: 1197
|
Posted: Mon Aug 29, 2011 10:58 pm
|
Quote If so - do you have any source code you might be willing to share - if not maybe someone has some useful tips/pointers towards writing one.
One of the trickier parts was figuring out how to do the kerning.
I wrote a program that would fit every possible pair of letters together as closely as possible without overlapping, including an additional padding factor, and then save that spacing data to a table. For 48 characters this was a bit over 2K (48*48) which isn't too bad, and as all values could fit in a 4-bit value I could pack the kerning value into a nibble and get the table down to 1K.
I did have to go through and hand-adjust some entries, so letters like W and M don't fit so closely together. It was much easier to implement everything as a Windows application first to work out the kinks, and then move everything over to the target platform later.
|
- Site Admin
- Joined: 19 Oct 1999
- Posts: 14744
- Location: London
|
Posted: Tue Aug 30, 2011 9:19 am
|
I wrote one some years ago. What I did was render out a 1-bit font at 8px height, stored top-to-bottom then left-to-right, so each byte was one column. Then I had a lookup table of the offsets into this data for each character. The renderer would then draw it into the tile from left to right - slow, but even at one column per frame, it was fast enough to read comfortably. I think I used sentinel values for the end of each character.
I didn't worry about kerning at all - I just used 1px every time. This is simplistic but seems to work OK - it may depend on the font you use.
As you can see from the screenshot below, I didn't get much further than that - word wrapping is the next task, which is pretty much just a matter of adding up the width of the whole word before you start rendering. If you're in a position where you'll have interactive text entry, or very long words, it would be harder.
I'm pretty sure I lost the source for this one.
|
- Joined: 20 Dec 2004
- Posts: 26
- Location: Wellington, New Zealand
|
Posted: Fri Sep 02, 2011 12:33 pm
|
Here's some demo code for displaying variable width fonts I did for a project years ago. The font data & character length data was extracted from golden axe warrior, but I ended up writing the code myself.
It was when I first started programming for the sms, I remember hacking at it until I got It to work, A problem it had was with words that exceeded the maximum line width, it would output individual characters of the word on a new line until the rest of the word could fit within a line. But that would have to be a very large word.
|
- Joined: 03 Aug 2011
- Posts: 39
- Location: NW England
|
Posted: Fri Sep 02, 2011 1:11 pm
|
Thanks for the replies all - especially Nick for supplying some source code for me to look at - I shall take a look and see if I can get my head around it.
Richard / Sket
|