Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Proportional / variable width font/text routine

Reply to topic
Author Message
  • Joined: 03 Aug 2011
  • Posts: 39
  • Location: NW England
Reply with quote
Proportional / variable width font/text routine
Post 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
  View user's profile Send private message
  • Joined: 28 Sep 1999
  • Posts: 1197
Reply with quote
Post 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.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14744
  • Location: London
Reply with quote
Post 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.

  View user's profile Send private message Visit poster's website
  • Joined: 20 Dec 2004
  • Posts: 26
  • Location: Wellington, New Zealand
Reply with quote
Post 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.
proportional font.zip (17.58 KB)

  View user's profile Send private message Visit poster's website
  • Joined: 03 Aug 2011
  • Posts: 39
  • Location: NW England
Reply with quote
Post 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
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!