• entries
707
1173
• views
436451

# ...

105 views

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){	if(!Text)		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];		switch(Character)		{		case '\t':			{				// expand tabs				--StartingSize;				Text->insert(Index + 1, "    ");				Text->erase(Index, 1);				break;			}		case ' ':			{				// store the position of the last space				LastSpace = Index;				WidthSinceLastSpace = 0;				break;			}		}		if(WordBreak)		{			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());}

-edit-
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->PreRender();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);Tahoma8->PostRender();

There are no comments to display.

## Create an account

Register a new account