Fix several book formatting issues (Fixes #2204)

This commit is contained in:
MiroslavR 2014-12-14 16:25:27 +01:00
parent 97a4b30b59
commit c5a604453e
2 changed files with 34 additions and 5 deletions

View file

@ -193,6 +193,9 @@ namespace MWGui
MyGUI::Gui::getInstance().destroyWidget(parent->getChildAt(0)); MyGUI::Gui::getInstance().destroyWidget(parent->getChildAt(0));
} }
mTextStyle = TextStyle();
mBlockStyle = BlockStyle();
MyGUI::Widget * paper = parent->createWidget<MyGUI::Widget>("Widget", MyGUI::IntCoord(0, 0, pag.getPageWidth(), pag.getPageHeight()), MyGUI::Align::Left | MyGUI::Align::Top); MyGUI::Widget * paper = parent->createWidget<MyGUI::Widget>("Widget", MyGUI::IntCoord(0, 0, pag.getPageWidth(), pag.getPageHeight()), MyGUI::Align::Left | MyGUI::Align::Top);
paper->setNeedMouseFocus(false); paper->setNeedMouseFocus(false);
@ -207,8 +210,25 @@ namespace MWGui
continue; continue;
std::string plainText = parser.getReadyText(); std::string plainText = parser.getReadyText();
// for cases when linebreaks are used to cause a shift to the next page
// if the split text block ends in an empty line, proceeding text block(s) should have leading empty lines removed
if (pag.getIgnoreLeadingEmptyLines())
{
while (!plainText.empty())
{
if (plainText[0] == '\n')
plainText.erase(plainText.begin());
else
{
pag.setIgnoreLeadingEmptyLines(false);
break;
}
}
}
if (plainText.empty()) if (plainText.empty())
brBeforeLastTag = false; brBeforeLastTag = true;
else else
{ {
// Each block of text (between two tags / boundary and tag) will be displayed in a separate editbox widget, // Each block of text (between two tags / boundary and tag) will be displayed in a separate editbox widget,
@ -252,6 +272,8 @@ namespace MWGui
{ {
case BookTextParser::Event_ImgTag: case BookTextParser::Event_ImgTag:
{ {
pag.setIgnoreLeadingEmptyLines(false);
const BookTextParser::Attributes & attr = parser.getAttributes(); const BookTextParser::Attributes & attr = parser.getAttributes();
if (attr.find("src") == attr.end() || attr.find("width") == attr.end() || attr.find("height") == attr.end()) if (attr.find("src") == attr.end() || attr.find("width") == attr.end() || attr.find("height") == attr.end())
@ -331,9 +353,7 @@ namespace MWGui
if (attr.find("face") != attr.end()) if (attr.find("face") != attr.end())
{ {
std::string face = attr.at("face"); std::string face = attr.at("face");
mTextStyle.mFont = face;
if (face != "Magic Cards")
mTextStyle.mFont = face;
} }
if (attr.find("size") != attr.end()) if (attr.find("size") != attr.end())
{ {
@ -408,13 +428,18 @@ namespace MWGui
// first empty lines that would go to the next page should be ignored // first empty lines that would go to the next page should be ignored
// unfortunately, getLineInfo method won't be available until 3.2.2 // unfortunately, getLineInfo method won't be available until 3.2.2
#if (MYGUI_VERSION >= MYGUI_DEFINE_VERSION(3, 2, 2)) #if (MYGUI_VERSION >= MYGUI_DEFINE_VERSION(3, 2, 2))
mPaginator.setIgnoreLeadingEmptyLines(true);
const MyGUI::VectorLineInfo & lines = mEditBox->getSubWidgetText()->castType<MyGUI::EditText>()->getLineInfo(); const MyGUI::VectorLineInfo & lines = mEditBox->getSubWidgetText()->castType<MyGUI::EditText>()->getLineInfo();
for (unsigned int i = lastLine; i < lines.size(); ++i) for (unsigned int i = lastLine; i < lines.size(); ++i)
{ {
if (lines[i].width == 0) if (lines[i].width == 0)
ret += lineHeight; ret += lineHeight;
else else
{
mPaginator.setIgnoreLeadingEmptyLines(false);
break; break;
}
} }
#endif #endif
return ret; return ret;

View file

@ -81,7 +81,8 @@ namespace MWGui
Paginator(int pageWidth, int pageHeight) Paginator(int pageWidth, int pageHeight)
: mStartTop(0), mCurrentTop(0), : mStartTop(0), mCurrentTop(0),
mPageWidth(pageWidth), mPageHeight(pageHeight) mPageWidth(pageWidth), mPageHeight(pageHeight),
mIgnoreLeadingEmptyLines(false)
{ {
} }
@ -89,10 +90,12 @@ namespace MWGui
int getCurrentTop() const { return mCurrentTop; } int getCurrentTop() const { return mCurrentTop; }
int getPageWidth() const { return mPageWidth; } int getPageWidth() const { return mPageWidth; }
int getPageHeight() const { return mPageHeight; } int getPageHeight() const { return mPageHeight; }
bool getIgnoreLeadingEmptyLines() const { return mIgnoreLeadingEmptyLines; }
Pages getPages() const { return mPages; } Pages getPages() const { return mPages; }
void setStartTop(int top) { mStartTop = top; } void setStartTop(int top) { mStartTop = top; }
void setCurrentTop(int top) { mCurrentTop = top; } void setCurrentTop(int top) { mCurrentTop = top; }
void setIgnoreLeadingEmptyLines(bool ignore) { mIgnoreLeadingEmptyLines = ignore; }
Paginator & operator<<(const Page & page) Paginator & operator<<(const Page & page)
{ {
@ -103,6 +106,7 @@ namespace MWGui
private: private:
int mStartTop, mCurrentTop; int mStartTop, mCurrentTop;
int mPageWidth, mPageHeight; int mPageWidth, mPageHeight;
bool mIgnoreLeadingEmptyLines;
Pages mPages; Pages mPages;
}; };