XFS is a library of font management (FreeType2 based), which allows you to flexibly combine different fonts to display text.
XFS does not use the C runtime library, so it does not matter which version (single-threaded, multi-threaded or multi-threaded DLL) it is linked with.
Depends
FreeType 2 http://freetype.org/
##Usage Example
####1. Initialize and configure
// Initialize
xfs::Initialize();
// Pass the window size
xfs::SetScreenSize(WIDTH, HEIGHT);
// Create a font from a TrueType file, set it size and obtain its handle
HFont hFreeSans_14 = xfs::Create_Font("YourPath/FreeSans.ttf", 14);
// If something went wrong
assert(hFreeSans_14 != INVALID_FONT);
// Adds the character ranges for fonts, using the obtained handle
xfs::AddGlyphSetToFont(hFreeSans_14, BASIC_LATIN);
xfs::AddGlyphSetToFont(hFreeSans_14, CYRILLIC);
// or like this
xfs::AddGlyphSetToFont(hFreeSans_14, 31, 127);
xfs::AddGlyphSetToFont(hFreeSans_14, 1024, 1104);
// Now simply call
xfs::BuildAllFonts();
The resulting texture for these ranges:
####2. Text Rendering
// Unicode text string
const wchar_t wText[] = L"Hello World\nили Здравствуй мир! :)";
// Bind the font handle
xfs::BindFont(hFreeSans_14);
// Sets position for the text in screen space
xfs::SetTextPos(100, 25);
// Sets text color
xfs::SetTextColor(255, 0, 200);
// Pass a string of text and obtain its id
int staticTextID = xfs::SetStaticWText(wText, wcslen(wText));
// then at runtime
while(true)
{
// Bind the shader program, clear all state etc.
xfs::Draw2D_Begin();
// Draw a static text
xfs::PrintStaticText(staticTextID);
// Bind a next font handle
xfs::BindFont(hVerdanaB_11);
xfs::SetTextColor(0, 0, 255);
xfs::SetTextPos(100, 10);
std::string time;
NowTime(time);
// Draw a dynamic text string
xfs::PrintText(time.c_str(), time.length());
xfs::Draw2D_End();
}
As a result:
For any text you can get its bounding box (BBox).
// for example, load any text from a file
std::wstring wstr = ReadWholeFileIntoString("SomeFile.txt");
// pass it and obtain its index (ID)
int textID = FontSystem.SetStaticWText(wstr.c_str(), wstr.lenght());
// obtain its bounding box
BBox_t bbox;
xfs::GetWTextBBox(wstr.c_str(), wstr.lenght(), bbox);
// draws the entire contents of the file
xfs::PrintStaticText(textID);
Result:
##License