forked from teamnwah/openmw-tes3coop
Book formatter: Fix an excessive line break case
This commit is contained in:
parent
cb5f661596
commit
1c4e52a0e5
1 changed files with 26 additions and 6 deletions
|
@ -199,6 +199,8 @@ namespace MWGui
|
|||
|
||||
BookTextParser parser(markup);
|
||||
BookTextParser::Events event;
|
||||
|
||||
bool brBeforeLastTag = false;
|
||||
for (;;)
|
||||
{
|
||||
event = parser.next();
|
||||
|
@ -206,12 +208,27 @@ namespace MWGui
|
|||
continue;
|
||||
|
||||
std::string plainText = parser.getReadyText();
|
||||
if (!plainText.empty())
|
||||
if (plainText.empty())
|
||||
brBeforeLastTag = false;
|
||||
else
|
||||
{
|
||||
// if there's a newline at the end of the box caption, remove it
|
||||
if (plainText[plainText.size()-1] == '\n')
|
||||
// Each block of text (between two tags / boundary and tag) will be displayed in a separate editbox widget,
|
||||
// which means an additonal linebreak will be created.
|
||||
// ^ This is not the case in vanilla MW (though having multiple tags in one line seems to result in undefined behavior).
|
||||
// We must deal with linebreaks around tags appropriately.
|
||||
{
|
||||
bool brAtStart = (plainText[0] == '\n');
|
||||
bool brAtEnd = (plainText[plainText.size()-1] == '\n');
|
||||
|
||||
if (!brBeforeLastTag && brAtStart)
|
||||
plainText.erase(plainText.begin());
|
||||
|
||||
if (plainText.size() && brAtEnd)
|
||||
plainText.erase(plainText.end()-1);
|
||||
|
||||
brBeforeLastTag = brAtEnd;
|
||||
}
|
||||
|
||||
#if (MYGUI_VERSION < MYGUI_DEFINE_VERSION(3, 2, 2))
|
||||
// splitting won't be fully functional until 3.2.2 (see TextElement::pageSplit())
|
||||
// hack: prevent newlines at the end of the book possibly creating unnecessary pages
|
||||
|
@ -222,9 +239,12 @@ namespace MWGui
|
|||
}
|
||||
#endif
|
||||
|
||||
if (!plainText.empty())
|
||||
{
|
||||
TextElement elem(paper, pag, mTextStyle, plainText);
|
||||
elem.paginate();
|
||||
}
|
||||
}
|
||||
|
||||
if (event == BookTextParser::Event_EOF)
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue