Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sfttf - truetype scalable fonts in SFML  (Read 11684 times)

0 Members and 2 Guests are viewing this topic.

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
sfttf - truetype scalable fonts in SFML
« on: December 31, 2008, 09:27:37 pm »
Okay, I finally got around to releasing this thing.
This library provides scalable truetype font support for SFML.
sf::String does this but in a different way, and does not support a few of the features this library provides (yet!).
Right now this has only been tested with the newest SVN!
I'm not sure if it would compile/work with older versions.
This is intended as an alternative to SFML's sf::String until SFML supports outlines, etc.

Screenshots


Features
-Kerning support
-Outlined/stroked text
-Sizeable outlines
-Unicode

Download
I actually set up a Google Code project page for it since it seemed a little large for a wiki (and I wanted SVN).
http://code.google.com/p/sfttf/downloads/list
sfttf-0.2 comes with precompiled libs/test program.

Example
Code: [Select]

sfttf::FontManager FontMgr;
FontMgr.Initialize();
sfttf::Font* Font = FontMgr.loadFont("Font.ttf");

Font->setOutline(true);
Font->setFill(false);
Font->drawString("Hello, World!", 300.0f, 300.0f);

Everything is in the sfttf namespace.
You need a FontManager to load fonts (FontManager::loadFont).
The FontManager will unload all the fonts upon destruction or you can call FontManager::unloadFont.
See the readme/example for more info.

Project files are provided for Windows+Linux (codeblocks/vc2008).

Notes
Right now there are a few simple things that I have not added like rotations.
It only supports horizontal text, it does not support vertical layout.
It probably does not work with languages like Thai that have multiple levels per line.
It does not use exceptions. If something can fail, a boolean is returned.
I removed support for control characters '\r\n\t\v' (etc) at the last second as it complicated a few things.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
sfttf - truetype scalable fonts in SFML
« Reply #1 on: January 02, 2009, 01:05:14 pm »
Thanks a lot!

However in order to compile the source I had to do the following:

Move this to Glyph.hpp from Glyph.cpp:
Code: [Select]
#include <SFML/Graphics/RenderWindow.hpp>
...and change row 301 in Font.cpp from:
Code: [Select]
if (0 != FT_Stroker_New(myFreeType, &myStroker))
to:
Code: [Select]
if (0 != FT_Stroker_New(reinterpret_cast<FT_Memory>(myFreeType), &myStroker))

Also, is the outline drawn on the inside of the character? because using small font sizes the only thing you can see is the outline color. I tried using font size 20 and outline size 1 and the only thing I could see was the white outline.

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
sfttf - truetype scalable fonts in SFML
« Reply #2 on: January 02, 2009, 02:04:42 pm »
Quote from: "dabo"
Thanks a lot!

However in order to compile the source I had to do the following:

Move this to Glyph.hpp from Glyph.cpp:
Code: [Select]
#include <SFML/Graphics/RenderWindow.hpp>

Thanks, not sure why my compiler didn't complain about that.  :oops:

Quote from: "dabo"

...and change row 301 in Font.cpp from:
Code: [Select]
if (0 != FT_Stroker_New(myFreeType, &myStroker))
to:
Code: [Select]
if (0 != FT_Stroker_New(reinterpret_cast<FT_Memory>(myFreeType), &myStroker))

Sorry! I forgot about this!
I posted a feature request here:
http://www.sfml-dev.org/forum/viewtopic.php?t=841
I'm using a newer version of FreeType.
I'll switch it back to the older version and add the reinterpret_cast.

This also made me realize I wasn't calling FT_Stroker_Done too.
So thanks!
Quote from: "dabo"

Also, is the outline drawn on the inside of the character? because using small font sizes the only thing you can see is the outline color. I tried using font size 20 and outline size 1 and the only thing I could see was the white outline.

Yes, this could be a problem.
This is something I'll be looking into.
I'm not really sure how to do this right now.
The whole stroker/outline API in FreeType is a bit confusing to me unfortunately.

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
sfttf - truetype scalable fonts in SFML
« Reply #3 on: January 02, 2009, 03:24:59 pm »
It's looking like outlines need a minimum size of around 30-34 with the fonts I tested.
The ftview freetype demo program is the same way.

I don't think there's really an easy way around this.

It seems the outline is rendered more in the 'middle' than the outside.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
sfttf - truetype scalable fonts in SFML
« Reply #4 on: January 02, 2009, 04:49:30 pm »
How is it drawn on screen? is the fill color and outline color drawn at the same time or are they like separate "layers"?

I don't know much of this nor the terms used :)

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
sfttf - truetype scalable fonts in SFML
« Reply #5 on: January 02, 2009, 05:14:14 pm »
Quote from: "dabo"
How is it drawn on screen? is the fill color and outline color drawn at the same time or are they like separate "layers"?

I don't know much of this nor the terms used :)

They are drawn separately.
The filled layer is drawn on the bottom, the outline on top.

I'm thinking maybe I can use the filled character to create the outline character and xor it so it is only on the 'outside'.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
sfttf - truetype scalable fonts in SFML
« Reply #6 on: January 02, 2009, 07:05:24 pm »
Quote from: "dewyatt"
They are drawn separately.
The filled layer is drawn on the bottom, the outline on top.


What if you reverse the order?

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
sfttf - truetype scalable fonts in SFML
« Reply #7 on: January 02, 2009, 11:35:46 pm »
Quote from: "dabo"
Quote from: "dewyatt"
They are drawn separately.
The filled layer is drawn on the bottom, the outline on top.


What if you reverse the order?

You'd get pretty much the same results, I already tested it.

 

anything