Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
/ XFontSys Public
forked from SC0x77/XFontSys

A library of font management, which allows you to flexibly combine different fonts to display text

Notifications You must be signed in to change notification settings

Nedi/XFontSys

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

alt text

####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:

alt text

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:

alt text

##License

GNU Library or Lesser General Public License (LGPL)

About

A library of font management, which allows you to flexibly combine different fonts to display text

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.