PrimaryFeather / Sparrow-Framework

The Open Source Game Engine for iOS
http://www.sparrow-framework.org
Other
538 stars 173 forks source link

Support for Bitmap Font Kerning #1016

Closed ludometrics closed 13 years ago

ludometrics commented 13 years ago

Hi Daniel,

I added support to SPTextField, SPBitmapFont and SPBitmapChar for kerning information for bitmap fonts (I'm a typography dork!), along with an updated demo so you can see it in action. I also provided a way to create text from an SPBitmapFont without applying a color, so that textures can be maintained. The hiero2sparrow conversion script has also been updated.

71Squared recently released Glyph Designer (glyphdesigner.71squared.com) which is a fantastic BMFont tool for OS X. Unfortunately, it has a bug with some fonts where it outputs incorrect kerning information! You'll see this in action with the brush.fnt script (so you probably don't want to include that version of the font in any release).

The one known code issue is that the SPBitmapChar.copy method does not copy the kerning information - I wasn't quite sure how best to do this, but hopefully we can figure it out! As a result, the code in SPBitmapFont does not use charByID when it otherwise should (when grabbing the previous character to get the kerning info).

I also realised that I didn't create a branch for this before I started hacking. Hopefully it's easy enough for you to resolve, but let me know.

I think that's everything, but of course get in touch if you need me to address problems or you have questions.

Thanks for making Sparrow! -David

PrimaryFeather commented 13 years ago

Hi David,

wow, I'm speechless! You've done a great job -- thanks a lot for that contribution! That will definitely become a part of Sparrow. I am already in contact with 71squared, and they promised to add direct support for Sparrow soon, so it will be even simpler to render text beautifully with Sparrow! :-)

I had a look at your changes of the source code, and I think I will be able to add most of the code just as it is (cosmetic changes aside). Well done!

One thing I saw is not necessary, though, or is at least simpler to achieve. The method that allows using a font texture natively (without tinting it in a color) can be achieved already by simply using "white" as the text color. That way, the texture will be used as it is.

I haven't looked at the 'copy' issue yet, but will do so soon. I'm sure we'll figure that out.

Again, thanks A LOT for that pull request! Adding kerning was something that I procrastinated for a long time ... ;-) So I'm glad somebody has tackled this issue!

Best regards, Daniel

ludometrics commented 13 years ago

Hi Daniel,

Superb - glad that it's useful!

I hadn't realised that setting the color to white would show the texture - I think that would be a good tip to add to the docs.

Thanks, -David

PrimaryFeather commented 13 years ago

Hi David,

you're right, that should definitely be added to the docs! It's far from obvious that it can be used that way. I will do so when I incorporate your changes.

Have a nice day! Daniel

ludometrics commented 13 years ago

Oops, just noticed a bug in the hiero2sparrow.rb script - it doesn't handle the case where there's no kerning information available!

On line 81, it should be:

kernings_parent.attributes["count"] = num_kernings unless kernings_parent.nil?

PrimaryFeather commented 13 years ago

I made some small changes, but all in all, your kerning feature is now part of the development branch of Sparrow! Thanks again :-)