forked from mirror/openmw-tes3mp
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::BookTextParser(const std::string & text)
|
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
|
MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor
|
||||||
mText = Interpreter::fixDefinesBook(mText, interpreterContext);
|
mText = Interpreter::fixDefinesBook(mText, interpreterContext);
|
||||||
|
@ -40,7 +40,7 @@ namespace MWGui
|
||||||
mTagTypes[tag] = type;
|
mTagTypes[tag] = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BookTextParser::getReadyText()
|
std::string BookTextParser::getReadyText() const
|
||||||
{
|
{
|
||||||
return mReadyText;
|
return mReadyText;
|
||||||
}
|
}
|
||||||
|
@ -117,12 +117,27 @@ namespace MWGui
|
||||||
return mAttributes;
|
return mAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BookTextParser::isClosingTag() const
|
||||||
|
{
|
||||||
|
return mClosingTag;
|
||||||
|
}
|
||||||
|
|
||||||
void BookTextParser::parseTag(std::string tag)
|
void BookTextParser::parseTag(std::string tag)
|
||||||
{
|
{
|
||||||
size_t tagNameEndPos = tag.find(' ');
|
size_t tagNameEndPos = tag.find(' ');
|
||||||
|
mAttributes.clear();
|
||||||
mTag = tag.substr(0, tagNameEndPos);
|
mTag = tag.substr(0, tagNameEndPos);
|
||||||
Misc::StringUtils::toLower(mTag);
|
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)
|
if (tagNameEndPos == std::string::npos)
|
||||||
return;
|
return;
|
||||||
tag.erase(0, tagNameEndPos+1);
|
tag.erase(0, tagNameEndPos+1);
|
||||||
|
@ -232,7 +247,10 @@ namespace MWGui
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BookTextParser::Event_FontTag:
|
case BookTextParser::Event_FontTag:
|
||||||
handleFont(parser.getAttributes());
|
if (parser.isClosingTag())
|
||||||
|
resetFontProperties();
|
||||||
|
else
|
||||||
|
handleFont(parser.getAttributes());
|
||||||
break;
|
break;
|
||||||
case BookTextParser::Event_DivTag:
|
case BookTextParser::Event_DivTag:
|
||||||
handleDiv(parser.getAttributes());
|
handleDiv(parser.getAttributes());
|
||||||
|
@ -256,6 +274,13 @@ namespace MWGui
|
||||||
return markupToWidget(parent, markup, parent->getWidth(), parent->getHeight());
|
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)
|
void BookFormatter::handleDiv(const BookTextParser::Attributes & attr)
|
||||||
{
|
{
|
||||||
if (attr.find("align") == attr.end())
|
if (attr.find("align") == attr.end())
|
||||||
|
|
|
@ -40,15 +40,18 @@ namespace MWGui
|
||||||
};
|
};
|
||||||
|
|
||||||
BookTextParser(const std::string & text);
|
BookTextParser(const std::string & text);
|
||||||
void registerTag(const std::string & tag, Events type);
|
|
||||||
std::string getReadyText();
|
|
||||||
|
|
||||||
Events next();
|
Events next();
|
||||||
void flushBuffer();
|
|
||||||
const Attributes & getAttributes() const;
|
const Attributes & getAttributes() const;
|
||||||
void parseTag(std::string tag);
|
std::string getReadyText() const;
|
||||||
|
bool isClosingTag() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void registerTag(const std::string & tag, Events type);
|
||||||
|
void flushBuffer();
|
||||||
|
void parseTag(std::string tag);
|
||||||
|
|
||||||
size_t mIndex;
|
size_t mIndex;
|
||||||
std::string mText;
|
std::string mText;
|
||||||
std::string mReadyText;
|
std::string mReadyText;
|
||||||
|
@ -57,6 +60,7 @@ namespace MWGui
|
||||||
bool mIgnoreLineEndings;
|
bool mIgnoreLineEndings;
|
||||||
Attributes mAttributes;
|
Attributes mAttributes;
|
||||||
std::string mTag;
|
std::string mTag;
|
||||||
|
bool mClosingTag;
|
||||||
std::map<std::string, Events> mTagTypes;
|
std::map<std::string, Events> mTagTypes;
|
||||||
std::string mBuffer;
|
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, const int pageWidth, const int pageHeight);
|
||||||
Paginator::Pages markupToWidget(MyGUI::Widget * parent, const std::string & markup);
|
Paginator::Pages markupToWidget(MyGUI::Widget * parent, const std::string & markup);
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
void handleImg(const BookTextParser::Attributes & attr);
|
void resetFontProperties();
|
||||||
|
|
||||||
void handleDiv(const BookTextParser::Attributes & attr);
|
void handleDiv(const BookTextParser::Attributes & attr);
|
||||||
void handleFont(const BookTextParser::Attributes & attr);
|
void handleFont(const BookTextParser::Attributes & attr);
|
||||||
private:
|
|
||||||
TextStyle mTextStyle;
|
TextStyle mTextStyle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue