Page 1 of 1

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

Posted: Fri Apr 09, 2021 00:43
by zuur
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!

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

Posted: Sun Apr 11, 2021 23:19
by zuur
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.