NFont
by Jonny D
NFont is a bitmap font class (C++) and a struct
(C) for
SDL.
With it,
you're able to make really neat fonts to appear in your applications.
NFont is easy to use and has nice features like support for
the
newline character ('\n'), animation, and extended ASCII
support (codes 33-126 and 161-255). Use the font
metric functions like getHeight(), getWidth(), and getAscent(), which
all handle multi-line text, and the control of letter spacing and line
spacing for a ton of utility. You can even load TrueType
fonts
when you use SDL_ttf (just #define NFONT_USE_TTF and link with
SDL_ttf). Text-block alignment is
provided through three simple functions: draw(), drawCenter(), and
drawRight(). If you need to be more specific with the
position of your text or you want to animate the characters, use
drawPos(), which accepts a function that you write to
control the output positions of each character. If that's not
enough, you can replace the
whole process with drawAll().
NFont uses the very relaxed MIT
License so you can feel free to use it in any sort of project,
statically linked or not.
The latest version is v2.0.0. This version
represents some
conceptual cleaning and focuses on the NFont interface. I was
prepared to go off the deep end and make NFont work for both SDL and
OpenGL (by way of textures), but I've decided that it needs to stay
simple in order to remain and become even more useful for the SDL 2D
framebuffer. I might make a new library that handles OpenGL
text.
We'll see :). Either way, NFont's interface has
changed
toward simplicity. The NFont class acts now like a namespace,
holding independent functions as static methods. NFontAnim
has
been merged with the NFont class and there's a single static animation
data structure. The drawing commands all return the dirty
rect,
for use with Sprig's dirty rect management or your own.
Memory
management has been simplified. NFont no longer frees any
surfaces automatically, so you don't have to worry about who owns a
particular surface (you always own it). Loading an NFont is
now
done through one of the constructors or the overloaded load() function.
The documentation is still in the works. It'll be out soon
enough. Plans for the future also include better international
support (really unicode, perhaps?) and I might try to add an
interface for specifying the bitmap font format for compatibility with
other bitmap font formats.
Sample Fonts
Example usage:
-------------------------
#include "NFont.h"
// in main()
NFont myFont;
myFont.load(screen, SDL_LoadBMP("myFontPic.bmp"));
int x = 50, y = 100;
myFont.draw(x, y, "Here's %s text!", "some");
// flip screen
-------------------------
| NFont |
A complete and very
simple
to use C++ bitmap font class with text-block alignment, full
newline support, few function arguments, font metrics,
TrueType font support (through SDL_ttf),
extended ASCII support (i.e. international characters) and even color
changing and animation. Everything you need to
create an NFont is in the links to the right. See the example
for some more free code. |
SDL
|
Latest
[Google Code]
v2.0.0
2/4/10
[Download]
[NFont
example source]
[Making
an NFont]
[the Gimp script]
[NFont
Maker
binary]
[NFont
Maker source]
(This is outdated)
[NFontAnim
example binary]
v1.71
2/11/09
[Download]
|
MIT
|
| NFontC |
This is a port of NFont to the C language.
It has a slightly different style to make it easy and
comfortable. |
SDL |
Latest
[Google Code]
v1.71
2/11/09
[Download] |
MIT |