TrueType font Support by FreeType Library

A forum to store posts deemed exceptionally wise and useful
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

Bate wrote: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. :)
The setKerningWidth() and setKerningHeight() functions specify the global kerning values. Those add/remove spaces between your letters.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Unfortunately, they don't. If KerningWidth is set to a high value

this

"MAIN MENU"

becomes to this

"_____MAIN MENU" (lots of spaces at the beginning)

but what we want is this

"M A I N M E N U"

Also, isn't Kerning only the spacing between special characters like "VA" "AW" etc?
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

Ah, I see now. It was a bug. It was half fixed in my CGUITTFont re-write. I fixed it across all of my versions, as well as fixed another bug where kerning wasn't being calculated when determining the dimension of a text string (would cause fonts to align improperly).

Pick your version:

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

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

New unicode:
http://nalin.suckerfree.org/public/code ... nt_New.zip
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Ah thank you, works fine now.

There's a tiny pointer bug in the cpp file (line 484)

Code: Select all

previousChar = p;

// is meant to be

previousChar = *p;
Never take advice from someone who likes to give advice, so take my advice and don't take it.
3D Ace
Posts: 66
Joined: Sun Oct 04, 2009 8:47 am
Location: Swakopmund, Namibia
Contact:

Post by 3D Ace »

Thanks man I can really use this for my projects. I'll add u to the credits list. :)
Everything is possible, IF you know how.
Checkout my website for my upcoming game.(Currently on hold!)
http://www.projectbattle360.webege.com
Image
vroad
Posts: 18
Joined: Sun Jan 03, 2010 1:30 pm

Post by vroad »

Is this a bug of CGUITTFONT?

I'm using Irrlicht in Japanese Environment.
Operating System is Windows XP Home Edition.
Compiler is Microsoft Visual C++ 2008 Express Edition.

I took CGUIEnvironment.cpp(& .h) from IrrlichtML-1.5, updated to 1.7, using merge tool.
Then I overwrote CGUITTFont.cpp from CGUITTFont_Nalin.zip.
If I use getFont with small font size (23 or lower),
Font could not be drawn like this picture.

http://vroadhp.web.fc2.com/images/testttfont.png

Previous version(from IrrlichtML-1.5) doesn't have this problem, but has other bugs.
(for example, CGUITTFont::draw 's parameter, "hcenter" and "vcenter" parameter doesn't work correctly.)
I tryed to fix this problem turnning of "AutoHinting" and "FontHinting", but failed.

This bug(?) should happen absolutely if specified font file is
"msgothic.ttc", "msmincho.ttc".
not happen if font file is "meiryo.ttc" or other ascii-letter only fonts.
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

Sorry, your link doesn't work anymore, so I can't see the picture. Did your font appear to be missing some pixels? When testing, I noticed that unifont.ttf had issues with the hinting algorithm. To get it to draw well, I had to turn off hinting, but leave auto-hinting on.

Try messing with the setFontHinting function. Different values give different results. (true, true) looks different than (false, true). Your font may need to be (false, true) in order to look good.
vroad
Posts: 18
Joined: Sun Jan 03, 2010 1:30 pm

Post by vroad »

I'm sorry, try opening this url in a new web browser window(tab).
My homepage space doesn't allow to link from other sites except html file.

Code: Select all

http://vroadhp.web.fc2.com/images/testttfont.png
I could not found setFontHinting in CGUITTFont.cpp, so I added this code before font->attach in CGUIEnvironment::getFont.
But this problem still happen.

Code: Select all

	font->FontHinting = false;
	font->AutoHinting = true;
	if (!font->attach(face->Face,fontsize))
	{
		font->drop();
		return 0;
	}
Otherwise, I found memory leak.
I found that this problem could be fixed by moidfying like this, but I don't know why.

Code: Select all

bool CGUITTFont::attach(CGUITTFace *face, u32 size, bool size_is_pixels)
{
	if (!Driver)
		return false;

	tt_face = face;

	//Glyphs.reallocate(tt_face->face->num_glyphs);
	//Glyphs.set_used(tt_face->face->num_glyphs);
	Glyphs.clear();
	for (int i = 0; i < tt_face->face->num_glyphs; i++)
	{
		CGUITTGlyph glyph;
		glyph.Driver = Driver;
		glyph.size = size;
		glyph.size_is_pixels = size_is_pixels;
		glyph.face = &(tt_face->face);
		glyph.cached = false;
		Glyphs.push_back(glyph);
	}
	return true;
}
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

Hmm. I loaded up msgothic.ttc, and it is indeed mangling the characters. I managed to fix the problem by turning on Monochrome drawing. Try enabling monochrome mode for the time being. I'll look into this issue further.

EDIT: From walking through it in my debugger, it looks like the issue is that it only has a monochrome font. The class first tries to load the font as a grayscale font and assumes that if a grayscale version doesn't exist, FT_Load_Glyph will fail, upon which it will try to load the monochrome version as a backup. What actually happens is that FT_Load_Glyph DOESN'T fail, and it tries to load a monochrome font as a 256-color font. That causes the extreme breakage.

EDIT2: I've fixed the issue with my new CGUITTFont class. I don't really work on these older ones anymore, as I have completely re-written the class. setFontHinting is a function in my new class, which is why you couldn't find it. But yeah, my new stuff can be found here:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=37296

The only issue is that my new class requires my ustring class, which these older ones don't.

A workaround for the old classes is to manually specify that you want a monochrome font. That will ensure that it loads correctly.
vroad
Posts: 18
Joined: Sun Jan 03, 2010 1:30 pm

Post by vroad »

I'm sorry for late reply.
I have just tested new CGUITTFont class. It seems that it works no problem, thank you.
Pianist
Posts: 14
Joined: Wed Apr 22, 2009 12:47 pm
Location: Czech Republic

True Type font crashes

Post by Pianist »

Hello,

I'm glad this thread is so live as it is. I'm implementing true type support for my wrapper. I've started with implementation of CGUITTFont, CGUITTGlyph and CGUITTFace classes. I see there is issue in the CGUITTGlyph::cache method. It crashes in the following code section:

Code: Select all

if (!FT_Load_Glyph(*face, idx, loadFlags))
{
 hasDefault = true;
 FT_GlyphSlot glyph = (*face)->glyph;
 FT_Bitmap bits;
 FT_Error err = 0;
		
 if (glyph->format != FT_GLYPH_FORMAT_BITMAP) //crashes
  err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL);

..
..
}


on the if(glyph->format ...) line application crashes with AccessViolationException, Attempt to read or write protected memory.

I have to say the CGUITTFace::load returns true same as CGUITTFont::attach returns true, but I have suspicion on a missloading of ttf-file, because images in glyphs seems to be empty - uninitialized.

Do you have any idea, how to fix this issue? Did anybody observed this issue too?

Thanks a lot.
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

Could you try with my re-written CGUITTFont class? You can find it here:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=37296
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: TrueType font Support by FreeType Library

Post by robmar »

I´m having the same problem, error C2259, CGUITTGlyph : cannot instantiate abstract class.

I think that the problem is related to the base class, IUnknown, version problems I guess.

Is there no update to this project, or a newer one for font support in Irrlicht?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: TrueType font Support by FreeType Library

Post by hybrid »

IUnknown does not exist anymore in Irrlicht, it has been renamed to IReferenceCounted. This was about two years ago.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: TrueType font Support by FreeType Library

Post by robmar »

Thanks for the info.

I changed the references to IReferenceCounted and problem solved!

Its now giving other errors such as, MyEventReceiver : cannot instantiate abstract class!, due to mismatches in defintions of the virtual functions, between the old version of Irrlich and the 1.7.2 version.

I guess it needs some reworking, but is it worth it as perhaps the Font_manager stuff from CuteAlien, does the same.

Does anyone know the current best method to have FreeType or TrueType font support in Irrlicht?
Post Reply