Irrlicht i18n (Unicode, FreeType, etc.)
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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.
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.
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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).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.
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.
Re: Irrlicht i18n (Unicode, FreeType, etc.)
I found a bug in the ustring16::findLastCharNotInList() method. This causes problems too in the ustring16::trim() method.
The method reads as follow :
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 :
I fixed it like this :
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;
}
Example :
Code: Select all
core::ustring test(L"5");
test.trim();
bool thisShouldNotBeTrue = (test == L"");
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;
}
Re: Irrlicht i18n (Unicode, FreeType, etc.)
Thank you for reporting it. I've applied your changes to the version of irrUString.h that I'm hosting.MartinVee wrote:I found a bug in the ustring16::findLastCharNotInList() method. This causes problems too in the ustring16::trim() method.
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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.
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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!
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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?
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?
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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
The CGUITTFont files are stampled November 2016
http://nalin.suckerfree.org/public/code ... _Nalin.zip
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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?
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?
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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
CGUITTFont p* = core::irrAllocator<CGUITTFont >;
The error is "
class irr::core::irrAllocator<irr::gui::CGUITTFont>
! Vert simple allocator imple....
type name is not allowed
Re: Irrlicht i18n (Unicode, FreeType, etc.)
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:
To allocate memory with it:
Anyway...
To create an allocator:
Code: Select all
core::irrAllocator<CGUITTFont> allocator;
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm