mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 06:15:32 +00:00
Book formatter: Support FONT closing tag, minor code cleanup
This commit is contained in:
parent
175d4f3d44
commit
cb5f661596
2 changed files with 41 additions and 11 deletions
|
@ -21,7 +21,7 @@ namespace MWGui
|
|||
{
|
||||
/* BookTextParser */
|
||||
BookTextParser::BookTextParser(const std::string & text)
|
||||
: mIndex(0), mText(text), mIgnoreNewlineTags(true), mIgnoreLineEndings(true)
|
||||
: mIndex(0), mText(text), mIgnoreNewlineTags(true), mIgnoreLineEndings(true), mClosingTag(false)
|
||||
{
|
||||
MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor
|
||||
mText = Interpreter::fixDefinesBook(mText, interpreterContext);
|
||||
|
@ -40,7 +40,7 @@ namespace MWGui
|
|||
mTagTypes[tag] = type;
|
||||
}
|
||||
|
||||
std::string BookTextParser::getReadyText()
|
||||
std::string BookTextParser::getReadyText() const
|
||||
{
|
||||
return mReadyText;
|
||||
}
|
||||
|
@ -117,12 +117,27 @@ namespace MWGui
|
|||
return mAttributes;
|
||||
}
|
||||
|
||||
bool BookTextParser::isClosingTag() const
|
||||
{
|
||||
return mClosingTag;
|
||||
}
|
||||
|
||||
void BookTextParser::parseTag(std::string tag)
|
||||
{
|
||||
size_t tagNameEndPos = tag.find(' ');
|
||||
mAttributes.clear();
|
||||
mTag = tag.substr(0, tagNameEndPos);
|
||||
Misc::StringUtils::toLower(mTag);
|
||||
mAttributes.clear();
|
||||
if (mTag.empty())
|
||||
return;
|
||||
|
||||
mClosingTag = (mTag[0] == '/');
|
||||
if (mClosingTag)
|
||||
{
|
||||
mTag.erase(mTag.begin());
|
||||
return;
|
||||
}
|
||||
|
||||
if (tagNameEndPos == std::string::npos)
|
||||
return;
|
||||
tag.erase(0, tagNameEndPos+1);
|
||||
|
@ -232,7 +247,10 @@ namespace MWGui
|
|||
break;
|
||||
}
|
||||
case BookTextParser::Event_FontTag:
|
||||
handleFont(parser.getAttributes());
|
||||
if (parser.isClosingTag())
|
||||
resetFontProperties();
|
||||
else
|
||||
handleFont(parser.getAttributes());
|
||||
break;
|
||||
case BookTextParser::Event_DivTag:
|
||||
handleDiv(parser.getAttributes());
|
||||
|
@ -256,6 +274,13 @@ namespace MWGui
|
|||
return markupToWidget(parent, markup, parent->getWidth(), parent->getHeight());
|
||||
}
|
||||
|
||||
void BookFormatter::resetFontProperties()
|
||||
{
|
||||
MyGUI::Align align = mTextStyle.mTextAlign;
|
||||
mTextStyle = TextStyle();
|
||||
mTextStyle.mTextAlign = align;
|
||||
}
|
||||
|
||||
void BookFormatter::handleDiv(const BookTextParser::Attributes & attr)
|
||||
{
|
||||
if (attr.find("align") == attr.end())
|
||||
|
|
|
@ -40,15 +40,18 @@ namespace MWGui
|
|||
};
|
||||
|
||||
BookTextParser(const std::string & text);
|
||||
void registerTag(const std::string & tag, Events type);
|
||||
std::string getReadyText();
|
||||
|
||||
Events next();
|
||||
void flushBuffer();
|
||||
|
||||
const Attributes & getAttributes() const;
|
||||
void parseTag(std::string tag);
|
||||
std::string getReadyText() const;
|
||||
bool isClosingTag() const;
|
||||
|
||||
private:
|
||||
void registerTag(const std::string & tag, Events type);
|
||||
void flushBuffer();
|
||||
void parseTag(std::string tag);
|
||||
|
||||
size_t mIndex;
|
||||
std::string mText;
|
||||
std::string mReadyText;
|
||||
|
@ -57,6 +60,7 @@ namespace MWGui
|
|||
bool mIgnoreLineEndings;
|
||||
Attributes mAttributes;
|
||||
std::string mTag;
|
||||
bool mClosingTag;
|
||||
std::map<std::string, Events> mTagTypes;
|
||||
std::string mBuffer;
|
||||
};
|
||||
|
@ -101,11 +105,12 @@ namespace MWGui
|
|||
Paginator::Pages markupToWidget(MyGUI::Widget * parent, const std::string & markup, const int pageWidth, const int pageHeight);
|
||||
Paginator::Pages markupToWidget(MyGUI::Widget * parent, const std::string & markup);
|
||||
|
||||
protected:
|
||||
void handleImg(const BookTextParser::Attributes & attr);
|
||||
private:
|
||||
void resetFontProperties();
|
||||
|
||||
void handleDiv(const BookTextParser::Attributes & attr);
|
||||
void handleFont(const BookTextParser::Attributes & attr);
|
||||
private:
|
||||
|
||||
TextStyle mTextStyle;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue