Irrlicht i18n (Unicode, FreeType, etc.)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

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

Post by christianclavet »

OK. Thanks for the reply!

So if I understand correctly, when you create a ustring it should be created in UTF16 and is stored in that format.

If I have another character encoding in the string (Irrlicht bitmap font usually use ANSI-Similar to LATIN1), it will have to be converted first. The USTRING class is only to convert between UNICODE types.

I'll use google and check how others are converting LATIN1 to UNICODE (UTF16) and the reverse then.
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 »

christianclavet wrote:OK. Thanks for the reply!

So if I understand correctly, when you create a ustring it should be created in UTF16 and is stored in that format.

If I have another character encoding in the string (Irrlicht bitmap font usually use ANSI-Similar to LATIN1), it will have to be converted first. The USTRING class is only to convert between UNICODE types.

I'll use google and check how others are converting LATIN1 to UNICODE (UTF16) and the reverse then.
Your source string has to be unicode, yes. It cannot do conversions between different character maps. Just between the different encoding types of unicode (UTF8/16/32).

Also, your source string doesn't have to be UTF16. It can be UTF8 or UTF32 if you desire. ustring just converts and stores the string internally as UTF16. If you pass in a uchar16_t string, it loads it as UTF16. If you pass in uchar32_t, it loads it as UTF32. If you pass in a const char*, it attempts to find a unicode byte-order mark. If it finds one, it loads as UTF8/16/32 (whatever the BOM says it is). If no byte-order mark is found, it treats the source string as UTF8.
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

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

Post by MartinVee »

I found a bug in the ustring16::findLastCharNotInList() method. This causes problems too in the ustring16::trim() method.

The method reads as follow :

Code: Select all

 
//! Finds last position of a character not in a given list.
//! \param c A list of characters to NOT find. For example if the method should find the first occurrence of a character not 'a' or 'b', this parameter should be "ab".
//! \param count The amount of characters in the list. Usually, this should be strlen(c).
//! \return Position where the character has been found, or -1 if not found.
s32 findLastCharNotInList(const uchar32_t* const c, u32 count=1) const
{
  if (!c || !count)
    return -1;
 
  const_iterator i(end());
  --i;
 
  s32 pos = size() - 1;
  while (!i.atStart())
  {
    uchar32_t t = *i;
    u32 j;
    for (j=0; j<count; ++j)
      if (t == c[j])
        break;
 
    if (j==count)
      return pos;
    --pos;
    --i;
  }
  return -1;
}
 
Since the iterator starts at end()-minus-one and the while checks for atStart(), the loop is never executed for single-character strings. Like I said, this causes the trim() function to return an empty string.

Example :

Code: Select all

 
core::ustring test(L"5");
test.trim();
bool thisShouldNotBeTrue = (test == L"");
 
I fixed it like this :

Code: Select all

 
s32 findLastCharNotInList(const uchar32_t* const c, u32 count=1) const
{
  if (!c || !count)
    return -1;
 
  const_iterator i(end());
  --i;
 
  s32 pos = size() - 1;
  while (true)
  {
    uchar32_t t = *i;
    u32 j;
    for (j=0; j<count; ++j)
      if (t == c[j])
        break;
 
    if (j==count)
      return pos;
    --pos;
 
    if(i.atStart())
      break;
 
    --i;
  }
 
  return -1;
}
 
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 »

MartinVee wrote:I found a bug in the ustring16::findLastCharNotInList() method. This causes problems too in the ustring16::trim() method.
Thank you for reporting it. I've applied your changes to the version of irrUString.h that I'm hosting.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

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

Post by REDDemon »

This is very usefull, I recently finished working on an Arabic teaching game and I understand how valuable is having working unicode and UTF-X for irrlicht.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

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

Post by robmar »

On Windows 10 loadiing TTF files from Windows\Fonts requires special permissions, I´ve had a search but can't see how this is done with Irrlicht? I can copy the TTF files to another directory but that would be a bodge.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post by CuteAlien »

If I remember right it doesn't load font-files, but uses some Windows API functions to access installed fonts. But would have to dig into source to be certain.
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
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

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

Post by robmar »

I have it working now, the latest version directly loads .ttf files, and I just had to use "/" instead of "\\" in the path to have it open Windows/Fonts directly. Nice job by Nalin!
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

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

Post by robmar »

I downloaded the files for this from the website, but as there is no create function, I allocate the font and face classes, and call load and then attach for the face, which works perfectly for several create/destroy cycles, then crashes as the face gets corrupted.
There is no ustring conversions in this class, so I guess it must be a later version without the create function.
The CGUIFont.cpp is 634 lines long, no header with date or version, am I using the correct file, and implementation?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

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

Post by robmar »

I downloaded from Nalin's thread "TrueType font Support by FreeType Library"

The CGUITTFont files are stampled November 2016

http://nalin.suckerfree.org/public/code ... _Nalin.zip
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post by CuteAlien »

Ah - I thought this was about the Irrlicht Fonttool... its's about TTF's. There's a few versions around. The one I use (which is also based on Nalin's stuff) are the CGUITTFont files here: https://bitbucket.org/mzeilfelder/irr-p ... -micha/src and the ttf.cpp file is an example how to use it. And I don't use them with any installed fonts, but just use some free fonts I find online.
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
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

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

Post by robmar »

Okay, thanks for the link will compare the code.

I read in your posts, and Nalin's, that the GUI environment grabs the fonts for the skin, so that may be a problem for me, because I drop the TTF's face and font between scene reloading, which if I don't, is leaving some 133 grabs after I destroy the engine (its a very big TTF font so many textures I guess). Should I drop the textures somehow for the font, or set a new font with one texture?... something's not correct.

Also I create the classes in MFC, so the "new" will be the wrong block type, and maybe I should use irAllocator, but I´m getting compile errors.
I have the CGUITTFont class in my MFC application, not in Irrlict, and I use:

CGUITTFont p* = core::irrAllocator<CGUITTFont >; // But its saying non static member usage error

Do I need to put CGUITTFont class into Irrlicht for the allocator to work?
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post by CuteAlien »

Can you please copy-paste the exact error?
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
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

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

Post by robmar »

On this line within my MFC app, with Irrlicht compiling and working fine:

CGUITTFont p* = core::irrAllocator<CGUITTFont >;

The error is "

class irr::core::irrAllocator<irr::gui::CGUITTFont>
! Vert simple allocator imple....

type name is not allowed
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post by CuteAlien »

That doesn't look like a complete copy-paste somehow. Anyway - I'm not quite sure what your line is supposed to do. The * after the variable, what is this? Are you using some wrapper for another language like c# or so? Sorry I don't know about those.

Anyway...

To create an allocator:

Code: Select all

 
core::irrAllocator<CGUITTFont> allocator;
 
To allocate memory with it:

Code: Select all

 
CGUITTFont  *p = allocator.allocate(500);
 
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
Post Reply