SFML community forums

General => Feature requests => Topic started by: ecraven on June 26, 2014, 12:39:27 pm

Title: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: ecraven on June 26, 2014, 12:39:27 pm
Hello :)

I've implemented my own BitmapFont class as well as my own Text class. If sf::Font were to be an abstract base class (with all of its functions virtual), I could just have re-used sf::Text. Is this something you are willing to discuss? I'm *not* suggesting any standard form of bitmap font support, just to change sf::Font so that it is possible to re-use sf::Text (which I think is impossible now).

Thanks for any comments!
Title: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: Laurent on June 26, 2014, 01:30:38 pm
It has already been discussed, and as far as I remember, it was more or less agreed.
Title: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: Nexus on June 26, 2014, 11:39:02 pm
Mario mentioned it  (https://github.com/SFML/SFML/pull/624#issuecomment-45644986)two weeks ago, was there another discussion? Because there, it was rather a border notice.

So don't hesitate to come up with some ideas :)
Is your BitmapFont class API very similar to sf::Font, which parts could be potentially reused?
Title: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: Laurent on June 26, 2014, 11:48:37 pm
Quote
was there another discussion?
Although they never mention it explicitly, other threads containing "bitmap font" in the "Feature requests" board suggest that I'm open to the addition of bitmap fonts through a unified interface.
Title: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: ecraven on June 26, 2014, 11:51:43 pm
I just grab a texture which has all the letters. The constructor also takes a "mapping" from characters to indices. Otherwise I mostly copied the interface of sf::Font, returning an sf::Glyph, and not supporting italic/bold/...
I've never looked at other bitmap fonts, but I imagine it would be difficult to find a generic way to support them, but it might be possible to support at least the "letters on one texture" type (with some virtual functions for customisation).
If you are really interested, I could clean the code up some more and then post it. It's really nothing special though :)

For me, the most important point would be the change of making sf::Font a suitable base class to use, so that I can actually implement my own BitmapFont class without having to redo sf::Text and whatnot ;)
Title: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: Haze on June 28, 2014, 11:34:47 pm
I just grab a texture which has all the letters. The constructor also takes a "mapping" from characters to indices. Otherwise I mostly copied the interface of sf::Font, returning an sf::Glyph, and not supporting italic/bold/...

Is your bitmap font a monospace one (all letters have the same width and height) ? If it's the case, your bitmap font class doesn't need to return a glyph, a simple texture sub rectangle is enough, and the API will be much simpler than sf::Font's one. A simple bitmap font is merely a tileset, and your bitmap texts are tilemaps.

Feel free to have a look at my implementation of  BitmapFont/BitmapText (https://github.com/abodelot/sfml-addons/tree/master/modules/BitmapFont) if you want (I closely followed sf::Font/sf::Text semantics). See screenshot (http://s4.postimg.org/hii9ofo5p/sfmlbitmapfont.png).

On a side note, sf::Font also supports bitmap fonts, and rendering at small size has been fixed in the upcoming 2.2 release, making custom BitmapFont classes quite useless (except if you really need an image).
Title: AW: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: eXpl0it3r on June 29, 2014, 01:44:49 am
On a side note, sf::Font also supports bitmap fonts, [...] making custom BitmapFont classes quite useless (except if you really need an image).
What do you mean by that? What kind of bitmap font is supported by sf::Font?
The goal of bitmap fonts is to use well a bitmap = image.
Title: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: Laurent on June 29, 2014, 08:15:20 am
Quote
What do you mean by that? What kind of bitmap font is supported by sf::Font?
Old font formats used by X (PCF, BDF) are bitmap fonts. So technically, yes, we support bitmap fonts since we can load these formats. But I've never seen anyone use these formats for bitmap fonts. I believe they are quite limited due to their age.
Title: Re: AW: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: Haze on June 29, 2014, 02:27:02 pm
What do you mean by that? What kind of bitmap font is supported by sf::Font?
What Laurent said, and there's also bitmap fonts in ttf format (see http://www.dafont.com/fr/bitmap.php).
Many people who use bitmap fonts want a pixel perfect rendering (no hinting/blending/smoothing), something retro-looking which look nice at small size (the exact size designed for the font).
Title: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: Laurent on June 29, 2014, 08:23:16 pm
Quote
there's also bitmap fonts in ttf format (see http://www.dafont.com/fr/bitmap.php).
They just have a bitmap look, but I don't think they are bitmap fonts. TTF is a scalable format.
Title: Re: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts
Post by: Haze on June 29, 2014, 09:16:12 pm
They just have a bitmap look, but I don't think they are bitmap fonts. TTF is a scalable format.
I'm not sure about this. They are rendered "pixel perfect" only if your sf::Text has the same character size the bitmap font was designed for. If you use a different size, the text is scaled and looks blurry.