[Solved] Line counts in rendered strings not working with some character sets?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

zuur
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Tue Apr 01, 2008 21:17

[Solved] Line counts in rendered strings not working with some character sets?

Postby zuur » Fri Apr 09, 2021 00:43

CEGUI 0.8 compiled for 32-bit Windows for use with Ogre3D.

I've written the following little function to tell me how many lines a piece of text will wrap to for a given pixel width window. This works fine for English text and most other Latin character sets (Spanish, French, German), but when I use it to count lines in Russian (Cyrillic alphabet) it seems to tell me about twice the number of lines it actually displays on the screen.

Code: Select all

int getWrappedTextLineCount(const CEGUI::String &text, const CEGUI::Font *font, const float width, const CEGUI::Window *ref_wnd)
{
   CEGUI::RenderedStringTextComponent rstc(text);
   rstc.setFont(font);
   CEGUI::RenderedString rs;
   rs.appendComponent(rstc);
   CEGUI::RenderedStringWordWrapper<CEGUI::LeftAlignedRenderedString> rsww(rs);
   rsww.format(ref_wnd, CEGUI::Sizef(width, 999999));
   return rsww.getFormattedLineCount();
}


The font I'm using is Google's "NotoSansCJK", and as I said, it displays correctly on screen when displayed in the CEGUI window, so it's probably most likely that I've got something wrong in the function above as clearly CEGUI "can" get the metrics right for it. Just struggling a bit with this and would love some input.

Any help is most appreciated!

zuur
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Tue Apr 01, 2008 21:17

Re: [Solved] Line counts in rendered strings not working with some character sets?

Postby zuur » Sun Apr 11, 2021 23:19

I found my problem; I was passing a utf8-encoded std::string as the text argument to my function which was being converting to a CEGUI::String incorrectly - ie: two utf8 bytes for a single character were turning into two incorrect characters in CEGUI-land. This worked with utf8 encoded strings with one byte per character though.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 11 guests