Irrlicht i18n (Unicode, FreeType, etc.)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

zillion42 wrote:could I do square roots huge brackets greek alphabet and such things with this ?
No, you can't do square roots and huge brackets with this. This will just render whatever glyphs are in a font. This is the best you can do for square root:
http://www.fileformat.info/info/unicode ... /index.htm

If you want stylized square roots and brackets like you would find in a program like Mathematica, you will have to render those yourself.

On the other hand, you could easily do the greek alphabet.
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

thx...

I wonder why there aren't any good math fonts around, shouldnt be too much of a hassle to create one.

And yes, I use Mathematica and quite often I export 'traditional form' bmp's of formulas for for pdf's I needed to (or should I say was forced to) create, so I actually already have all I need I guess. Doing it with a font would be handy though.
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

Not much, but I just thought I should let anybody know who is using my patches:

New version of ustring:
  • Added a second split() method that takes a ustring of characters to split, instead of a uchar32_t* and length. It is just a helper function.
New version of CGUITTFont (svn trunk):
  • Removed a function deprecated for Irrlicht 1.9.
EDIT:

I actually did some more work on ustring, so I've uploaded a new version.
  • Added the ability to directly send a string to a std::ostream/std::wostream. (Lets you use it with std::cout.)
  • Added a bunch of operator overloads to ustring::access to make it easier to modify characters via an iterator.
The changes to ustring::access let you do things like this: (increments every character by 1)

Code: Select all

ustring test("This is a test \xEF\xBF\xBD");
std::cout << test << std::endl;
std::for_each(test.begin(), test.end(), [](ustring::access& c) { ++c; });
std::cout << test << std::endl;
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

New version of ustring:
  • Added a string hashing algorithm so a ustring can be used in containers like unordered_map.
I also updated the xml_io.patch for the SVN trunk to a working version. Sorry about that.
Loaden
Posts: 3
Joined: Mon Aug 25, 2008 2:34 am

Nice work!!

Post by Loaden »

Nice work!
Many thanks!!

Here is a patch can fix linker error if built in Irrlicht.

Code: Select all

//! Class representing a TrueType font.
	class CGUITTFont : public IGUIFont
	{
		public:
			//! Creates a new TrueType font and returns a pointer to it.  The pointer must be drop()'ed when finished.
			//! \param env The IGUIEnvironment the font loads out of.
			//! \param filename The filename of the font.
			//! \param size The size of the font glyphs in pixels.  Since this is the size of the individual glyphs, the true height of the font may change depending on the characters used.
			//! \param antialias set the use_monochrome (opposite to antialias) flag
			//! \param transparency set the use_transparency flag
			//! \return Returns a pointer to a CGUITTFont.  Will return 0 if the font failed to load.
			IRRLICHT_API static CGUITTFont* createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
			IRRLICHT_API static CGUITTFont* create(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
Need add 'IRRLICHT_API ' before the two static interface.
Tested in Win7 x86 and XPSP3 x64.
Loaden
Posts: 3
Joined: Mon Aug 25, 2008 2:34 am

Avoid compile warning of irrUString

Post by Loaden »

In irrUString.h, there are some compiler warning.
That's occured converted _int64 to u32.

e.g.

Code: Select all

_Iter& operator+=(const difference_type v)
			{
				if (v == 0) return *this;
				if (v < 0) return operator-=(v * -1);

				if (pos >= ref->size_raw())
					return *this;

				// Go to the appropriate position.
				u32 i = (u32)v; // PATCH HERE
				u32 sr = ref->size_raw();
				const uchar16_t* a = ref->c_str();
				while (i != 0 && pos < sr)
				{
					if (UTF16_IS_SURROGATE_HI(a[pos]))
						pos += 2;
					else ++pos;
					--i;
				}
				if (pos > sr)
					pos = sr;

				return *this;
			}

Code: Select all

//! Go back a specified number of full characters in the string.
			//! \return Myself.
			_Iter& operator-=(const difference_type v)
			{
				if (v == 0) return *this;
				if (v > 0) return operator+=(v * -1);

				if (pos == 0)
					return *this;

				// Go to the appropriate position.
				u32 i = (u32)v; // PATCH HERE
				const uchar16_t* a = ref->c_str();
				while (i != 0 && pos != 0)
				{
					--pos;
					if (UTF16_IS_SURROGATE_LO(a[pos]) != 0 && pos != 0)
						--pos;
					--i;
				}

				return *this;
			}
And:

Code: Select all

class hash : public std::unary_function<core::ustring, size_t>
{
	public:
		size_t operator()(const core::ustring& s) const
		{
			size_t ret = 2166136261U;
			size_t index = 0;
			size_t stride = 1 + s.size_raw() / 10;

			core::ustring::const_iterator i = s.begin();
			while (i != s.end())
			{
				ret = 16777619U * ret ^ (size_t)s[(u32)index]; // PATCH HERE
				index += stride;
				i += stride;
			}
			return (ret);
		}
};
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Re: Avoid compile warning of irrUString

Post by Nalin »

Loaden wrote:Need add 'IRRLICHT_API ' before the two static interface.
Tested in Win7 x86 and XPSP3 x64.
That patch causes issues if you don't integrate it with Irrlicht. The normal method of using CGUITTFont is to integrate it into your project instead of into Irrlicht, so I won't apply that patch. Unless you can figure out some way to prevent IRRLICHT_API from being defined when you add the code to your project instead of into Irrlicht.
Loaden wrote:In irrUString.h, there are some compiler warning.
That's occured converted _int64 to u32.
Patch added. Thank you.
---

New version of ustring:
  • Added patch by Loaden to fix some issues when compiling in 64-bit.
Loaden
Posts: 3
Joined: Mon Aug 25, 2008 2:34 am

Re: Avoid compile warning of irrUString

Post by Loaden »

Nalin wrote: That patch causes issues if you don't integrate it with Irrlicht. The normal method of using CGUITTFont is to integrate it into your project instead of into Irrlicht, so I won't apply that patch. Unless you can figure out some way to prevent IRRLICHT_API from being defined when you add the code to your project instead of into Irrlicht.
Thanks reply!
What about this patch?

part 1

Code: Select all

#include <irrlicht.h>
#include <ft2build.h>
#include "irrUString.h"
#include FT_FREETYPE_H

#ifdef _IRR_INTEGRATE_IN_TTFONT
#define TTFONT_API IRRLICHT_API
#else
#define TTFONT_API
#endif

namespace irr
{
namespace gui
{
part 2

Code: Select all

            TTFONT_API static CGUITTFont* createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
            TTFONT_API static CGUITTFont* create(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

I suppose I could create an IGUITTFont class for Irrlicht and have it issue a special #define that causes CGUITTFont to properly export its static functions. That should allow the class to work properly inside and outside of Irrlicht.
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Post by Nalin »

New version of CGUITTFont:
  • Fixed a crash issue when failing to load a font.
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Post by stefbuet »

I had the shift problem when using twice the same font with different sizes but I discovered in the last responces that you had fixed it so I may thank you again for this amazing work :wink:
CuteAlien wrote:coders are well-known creatures of the night
Jake007
Posts: 16
Joined: Wed Jun 29, 2011 8:39 pm
Location: Slovenia

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Post by Jake007 »

Hi!

This looks awesome. But I'm having problems with program crashing. First it always crashed when I tried to load a font. Now it doesn't anymore probably because of the new fix.
Now it crashes when I'm trying to draw text.

It happens at this line:

Code: Select all

tt_font->draw( test, rect<s32>( 300, 300,400, 400), SColor( 0, 50, 50, 50), false, false,0);
Here is how I load the font:

Code: Select all

CGUITTFont* tt_font = CGUITTFont::createTTFont(env, "arial.ttf", 20, true, true);
    gui::IGUISkin* skin = env->getSkin();
    skin->setFont(tt_font);
Debugger says that I'm having segmentation error (SIGSEGV).
Also when I try to create default env->addStaticText, it displays default irrlicht font :(.
Could someone please help me?

Regards,
Jake
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Post by Nalin »

Do you have "arial.ttf" in the same directory as your .exe file? It is possible it isn't loading it. The crashing shouldn't happen, though. When I get back from work today, I'll try to see what is going wrong. I'll also add some logging to let you know if it fails to load the font properly.
Jake007
Posts: 16
Joined: Wed Jun 29, 2011 8:39 pm
Location: Slovenia

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Post by Jake007 »

Yes I have arial.ttf in the same directory as .exe. I even tried full path to it but it still crashes.

I included irrUString.h in CGUIFont.h.
This is full striped code:

Code: Select all

#include <iostream>
#include <irrlicht.h>
#include "CGUITTFont.h"
 
using namespace std;
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
int main()
{
    IrrlichtDevice* device = createDevice( EDT_OPENGL, dimension2d<u32>(640, 480), 32, false, false, false, NULL);
 
    device->setWindowCaption(L"True type test");
 
    IVideoDriver* driver = device->getVideoDriver();
    IGUIEnvironment* env = device->getGUIEnvironment();
 
    CGUITTFont* tt_font = CGUITTFont::createTTFont(env, "arial.ttf", 20, false, false);
    gui::IGUISkin* skin = env->getSkin();
    skin->setFont(tt_font);
 
    while( device->run() && driver)
    {
            driver->beginScene(true, true, video::SColor(255, 0xBB,0xBB,0xBB));
 
            tt_font->draw( L"Simple font test!", rect<s32>( 0, 0,100, 100), SColor( 0, 50, 50, 50), false, false,0);
 
            driver->endScene();
    }
 
    tt_font->drop();
    driver->drop();
 
    return 0;
}
 
I'm very new to Irrlicht so it's possible that I forgot something, or that I striped out a little too much ;).
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Post by Nalin »

Well, I have uploaded a new version of CGUITTFont that has some slight debugging stuff added. See if the newer versions work. In order to use the new debug version, pass your IrrlichtDevice* instead of your IGUIEnvironment*.

Code: Select all

    CGUITTFont* tt_font = CGUITTFont::createTTFont(device, "arial.ttf", 20, false, false);
It would also help to know which line it crashes on. Try running your code in a debugger to see where the issue is at.
Post Reply