Jump to content
  • Advertisement
  • entries
  • comments
  • views


Sign in to follow this  


Looks like my brother's not going to be finishing my requested art any time soon, so I'm going ahead with out it. There will be a nice juicy entry waiting here for you guys come noon Friday (EST.)

I was working on DFT a little earlier and I realized that my bitmap font system wasn't as finished as I thought it was (word-break formatting hadn't been added.) So, I went through and added it and viola, I have a fully functional bitmap font system. It supports a combination of left, center, right, top, vertical center, bottom, and word-break formatting.

Word-break formatting works pretty simply (done behind the scenes.) BitmapFont::FormatString() takes the string as well as a boolean stating whether or not to do word-break formatting and the width of the bounds. It searches through and adds newlines when needed; if a word is too long to fit into the bounds, then "-\n" is used to split it.

Here's a screenshot of the system in action (this also shows the color-formatting in action as well):

dft::BitmapFont In Action

-Programming Stuff-
For those that are interested, here's my formatting code:

int BitmapFont::FormatString(std::string *Text, bool WordBreak, int BoundsWidth)
return 0;

size_t StartingSize = Text->size();
int Width = 0, WidthSinceLastSpace = 0;
int LastSpace = 0;
for(unsigned int Index = 0; Index < Text->size(); ++Index)
char Character = (*Text)[Index];
case '\t':
// expand tabs
Text->insert(Index + 1, " ");
Text->erase(Index, 1);

case ' ':
// store the position of the last space
LastSpace = Index;
WidthSinceLastSpace = 0;

int CharWidth = Metrics[Character];
if(Width + CharWidth > BoundsWidth) // if we're going to go out of bounds, move to the next line
if(WidthSinceLastSpace < BoundsWidth) // if the word is smaller than the bounds
(*Text)[LastSpace] = '\n';
Width = WidthSinceLastSpace;
else // if the word is larger than the bounds
Text->insert(Index - 1, "-\n");
WidthSinceLastSpace = 0;
Width = 0;
Width += CharWidth;
WidthSinceLastSpace += CharWidth;
return (int)(StartingSize - Text->size());

Here's the code for the example:

// ^# is the color formatting tag.
// The dft::Graphics::Color::Red at the end is the default color.

Tahoma8->Print("This ^1is ^2a ^3test ^4of ^5the ^6bitmap ^7font ^8system^9!!!", -1, 0, 0, dft::Graphics::Color::Red);

dft::Rectangle Bounds(dft::Point(100, 100), 100, 300);
Tahoma8->Print("This ^1is ^2a ^3test ^4of ^5the ^6bitmap ^7font ^8system^9!!!", -1, &Bounds, dft::Graphics::FontFormatting::Center | dft::Graphics::FontFormatting::VCenter | dft::Graphics::FontFormatting::WordBreak, dft::Graphics::Color::Red);

Bounds = dft::Rectangle(dft::Point(300, 100), 100, 300);
Tahoma8->Print("This ^1is ^2a ^3test ^4of ^5the ^6bitmap ^7font ^8system^9!!! OMFGWTFBBQ!!!!!!!!!!!!!!!!!!!", -1, &Bounds, dft::Graphics::FontFormatting::Right | dft::Graphics::FontFormatting::VCenter | dft::Graphics::FontFormatting::WordBreak, dft::Graphics::Color::Red);

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!