Page 1 of 1

[Bug]Blank line in wrapped rendered string cannot display

Posted: Thu Mar 10, 2011 05:41
by zyjhbgd
Crazy Eddie and CEGUI team:
I' ve taken advantage from your awesome work for a period. It' s great. And I found a small problem with BasicRenderedStringParser::appendRenderedText.

For example, when text parsing enabled, text like:
"\n\nabc"
should be displayed with two blank line and then a line "abc", but I only got the last line displayed without the two blank lines.
Soon I found this occured not only in wrapped rendered string but in all rendered string, so the title is not exactly correct.

I think it comes from BasicRenderedStringParser::appendRenderedText, as followed:

Code: Select all

void BasicRenderedStringParser::appendRenderedText(RenderedString& rs,
                                                   const String& text) const
{
    size_t cpos = 0;
    // split the given string into lines based upon the newline character
    while (text.length() > cpos)
    {
        // find next newline
        const size_t nlpos = text.find('\n', cpos);
        // calculate length of this substring
        const size_t len =
            ((nlpos != String::npos) ? nlpos : text.length()) - cpos;

        // construct new text component and append it.
        if (len > 0)//here is it
        {
            RenderedStringTextComponent rtc(text.substr(cpos, len), d_fontName);
            rtc.setPadding(d_padding);
            rtc.setColours(d_colours);
            rtc.setVerticalFormatting(d_vertAlignment);
            rtc.setAspectLock(d_aspectLock);
            rs.appendComponent(rtc);
        }

        // break line if needed
        if (nlpos != String::npos)
            rs.appendLineBreak();

        // advance current position.  +1 to skip the \n char
        cpos += len + 1;
    }
}

The condition (len > 0) in the code above ignores blank lines. I tried to fix it by (len >= 0) and it works.

I don't know whether it's a considered design(blank lines should be ignored) or not. I only raise it. But I found that DefaultRenderedStringParser::parse didn't ignore blank lines.

With best regards. :pint:

Re: [Bug]Blank line in wrapped rendered string cannot displa

Posted: Mon Mar 14, 2011 09:26
by CrazyEddie
Thanks for the heads up, I will add a ticket for this and look into it some time soon.

CE

Re: [Bug]Blank line in wrapped rendered string cannot displa

Posted: Wed Mar 16, 2011 02:21
by zyjhbgd
I found another way for the issue that we can push the '\n' into string rather than drop it.

But I was confused with rendered string's logic to '\n':
1. '\n' is trimed when parsing.
2. There are "LineBreak"s appended into rendered string when parsing, meaning new line.
3. Some fommat characters like \n\t are trimed in split method.