TrueType font Support by FreeType Library

A forum to store posts deemed exceptionally wise and useful
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Bate, which version do you use? Original, mine or Nalin's?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Nalin's latest with FreeType 2.3.11 and Irrlicht 1.6.1.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You should drop your font only once (for the create). The second ref-count comes probably from setting it to the skin, so the skin gets another reference. So I guess it is correct.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

Yes, the skin calls grab() on it. It doesn't look like there is any way to ask a skin to get rid of a font, so if you want to delete it, you will have to modify Irrlicht to let the skin drop it.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Sure, just set another font and the skin will release it's old font. It certainly won't drop as long as it needs it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Alright then. One last thing, loading from the Irrlicht filesystem (tried to load from a zip) doesn't seem to work.

Since I have no idea how to add this feature: would it be a big effort?
Never take advice from someone who likes to give advice, so take my advice and don't take it.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Strange, fonts seem to use the usual filesystem functions. So I would have guessed that they work also with zip's. Don't know how big of an effort, as I'll have to write a test for that first and the do some debugging. Did you try if other files (like textures or meshes) still work with the zip - maybe it just doesn't find your zip-file or something like that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Yes, textures meshes and my font are inside the same zip file. Everything else loads fine.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Oh wait - I think I know the reason for this. Freetype uses normal file-functions ... so this is actually going to be tricky.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

CuteAlien wrote:Oh wait - I think I know the reason for this. Freetype uses normal file-functions ... so this is actually going to be tricky.
Not really. We can use this function:
http://www.freetype.org/freetype2/docs/ ... emory_Face

We could then load the font from the filesystem and throw it through that function. The only issue is that you can't free the memory until you call FT_Done_Face. I'll work on modifying my version of the class to do this tomorrow (if I remember.)
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

Here is a new version of the class that reads via Irrlicht's filesystem, as long as an IFileSystem pointer is passed to CGUITTFace::load().

Normal:
http://nalin.suckerfree.org/public/code ... _Nalin.zip

Unicode:
http://nalin.suckerfree.org/public/code ... _Nalin.zip

Test it out and see if it works.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Thank you Nalin.

It doesn't compile for me

Code: Select all

bool CGUITTFace::load(const io::path& filename, io::IFileSystem* filesystem)
{
	if (!libraryLoaded)
	{
		if (FT_Init_FreeType(&library))
			return false;
		CGUITTFace::libraryLoaded = true;
	}

	if (device) // PROBLEM HERE : "device" unknown
	{
		// Read in the file data.
		io::IReadFile* file = filesystem->createAndOpenFile(filename);
		font_buffer = new FT_Byte[file->getSize()];
		file->read(font_buffer, file->getSize());
		font_size = file->getSize();
		file->drop();

		// Create the face.
		if (FT_New_Memory_Face(library, font_buffer, font_size,  0, &face))
		{
			delete[] font_buffer;
			font_buffer = 0;
			return false;
		}
	}
EDIT:
ah ok, just a typo :) it's meant to be

Code: Select all

if(filesystem)
works like a charm, thanks again.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Hey, very nice :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

Bate wrote:ah ok, just a typo :) it's meant to be

Code: Select all

if(filesystem)
works like a charm, thanks again.
Ha, oops. I fixed it in my unicode version, but forgot to fix it in my normal version. I made the change and re-uploaded it.

-------------

I spent some time today and significantly re-wrote the CGUITTFont class. There has been concerns about licensing issues, so a re-write was necessary. The new class is much easier to use, should have less bugs, and uses a lot less memory.

Ultimately, when this is done, I will include it inside of an internationalization pack along with my unicode string class and UTF-8 XML reader/writer.

Only the unicode version is working at this time, but if anybody wants to check it out so far, you can get it here:
http://nalin.suckerfree.org/public/code ... nt_New.zip

To create a 14-point font:

Code: Select all

gui::CGUITTFont* tt_font = gui::CGUITTFont::createTTFont(device->getGUIEnvironment(), "code2001.ttf", 14);
if (tt_font == 0) { error! }
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Do you think it might be possible to add an option to specify a global spacing value between all letters? It would be useful since lots of custom fonts have arbitrary shapes and overlap if used at the moment. So, that would help a lot. :)
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Post Reply