News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Question about automatic VWF.  (Read 2600 times)

DougRPG

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Question about automatic VWF.
« on: January 04, 2013, 08:52:27 pm »
Hi, I'm translating a Genesis game and I needed to add some new letters. The original font has variable width, so I thought I'd need to change some width table or something like that, but the size is automatically adapted.

It's common to find these automatic VWF?

Ryusui

  • Hero Member
  • *****
  • Posts: 4989
  • It's the greatest day.
    • View Profile
    • Tumblr
Re: Question about automatic VWF.
« Reply #1 on: January 04, 2013, 11:02:24 pm »
No. Frankly, I'd say you just found yourself a holy grail.
In the event of a firestorm, the salad bar will remain open.

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3512
    • View Profile
    • Aeon Genesis
Re: Question about automatic VWF.
« Reply #2 on: January 05, 2013, 12:11:58 pm »
Not common, no, but not unheard of either. The Aretha games automatically calculate their characters' widths, but of course their text engines are a royal pain in the ass to work with, so any simplification granted by the font is offset by the difficulty in working with the scripts.

From a technical standpoint it's not hard to do: you just OR the individual bytes (for an 8-width-max font) or words (for a 16-width-max font) together, then start shifting bits off until you hit a 0. The number of shifts you had to do is your width.

RedComet

  • Hero Member
  • *****
  • Posts: 3166
    • View Profile
    • Twilight Translations
Re: Question about automatic VWF.
« Reply #3 on: January 05, 2013, 12:19:26 pm »
@Dgdiniz: Just out of curiosity, what game are you working on?
Twilight Translations - More than just Dragonball Z. :P

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6928
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Question about automatic VWF.
« Reply #4 on: January 05, 2013, 12:37:03 pm »
From a technical standpoint it's not hard to do: you just OR the individual bytes (for an 8-width-max font) or words (for a 16-width-max font) together, then start shifting bits off until you hit a 0. The number of shifts you had to do is your width.
Oh. ORing all lines at once sounds like a faster way of doing it.
I was shifting off each row individually to find the widest line and set that as the width.
(though I think you'd likely do (for a monochrome) 0 = blank, 1= draw. Shift right until hitting a 1, giving the rightmost "drawn" pixel. So then (tile length) - (number of shifts needed) = width of character
"My watch says 30 chickens" Google, 2018

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3512
    • View Profile
    • Aeon Genesis
Re: Question about automatic VWF.
« Reply #5 on: January 05, 2013, 12:42:42 pm »
(though I think you'd likely do (for a monochrome) 0 = blank, 1= draw. Shift right until hitting a 1, giving the rightmost "drawn" pixel. So then (tile length) - (number of shifts needed) = width of character

Yeah, my proposal is basically identical; I just shift left instead of right to find the leftmost blank pixel. Thus (number of shifts - 1) = width of character. Both methods have practical applications; yours works better for 8-wide tiles where the majority of characters are likely to fill up more than half of the tile, whereas mine works better for 16-width tiles where the majority of characters are more likely to fill up less than half of the tile. It's a question of optimization.

Edit! Though to be fair, accessing a width table based on index is a constant time operation (instead of a linear time application in looping) and is much, much more efficient. More flexible too if you need characters of nonstandard widths or tiles with a blank in the middle.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6928
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Question about automatic VWF.
« Reply #6 on: January 05, 2013, 03:31:34 pm »
Oh and of course doing an automatic width would require a hard-coded case for a space character.
"My watch says 30 chickens" Google, 2018