1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:53:50 +00:00

Book formatter: Fix an excessive line break case

This commit is contained in:
MiroslavR 2014-09-27 17:35:57 +02:00
parent cb5f661596
commit 1c4e52a0e5

View file

@ -199,6 +199,8 @@ namespace MWGui
BookTextParser parser(markup); BookTextParser parser(markup);
BookTextParser::Events event; BookTextParser::Events event;
bool brBeforeLastTag = false;
for (;;) for (;;)
{ {
event = parser.next(); event = parser.next();
@ -206,12 +208,27 @@ namespace MWGui
continue; continue;
std::string plainText = parser.getReadyText(); 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 // Each block of text (between two tags / boundary and tag) will be displayed in a separate editbox widget,
if (plainText[plainText.size()-1] == '\n') // 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); plainText.erase(plainText.end()-1);
brBeforeLastTag = brAtEnd;
}
#if (MYGUI_VERSION < MYGUI_DEFINE_VERSION(3, 2, 2)) #if (MYGUI_VERSION < MYGUI_DEFINE_VERSION(3, 2, 2))
// splitting won't be fully functional until 3.2.2 (see TextElement::pageSplit()) // 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 // hack: prevent newlines at the end of the book possibly creating unnecessary pages
@ -222,9 +239,12 @@ namespace MWGui
} }
#endif #endif
if (!plainText.empty())
{
TextElement elem(paper, pag, mTextStyle, plainText); TextElement elem(paper, pag, mTextStyle, plainText);
elem.paginate(); elem.paginate();
} }
}
if (event == BookTextParser::Event_EOF) if (event == BookTextParser::Event_EOF)
break; break;