|
|
|
@ -11,7 +11,7 @@ namespace
|
|
|
|
|
int convertFromHex(std::string hex)
|
|
|
|
|
{
|
|
|
|
|
int value = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int a = 0;
|
|
|
|
|
int b = hex.length() - 1;
|
|
|
|
|
for (; b >= 0; a++, b--)
|
|
|
|
@ -28,43 +28,144 @@ namespace
|
|
|
|
|
case 'a':
|
|
|
|
|
value += 10 * (1 << (a * 4));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'B':
|
|
|
|
|
case 'b':
|
|
|
|
|
value += 11 * (1 << (a * 4));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
|
case 'c':
|
|
|
|
|
value += 12 * (1 << (a * 4));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
|
case 'd':
|
|
|
|
|
value += 13 * (1 << (a * 4));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'E':
|
|
|
|
|
case 'e':
|
|
|
|
|
value += 14 * (1 << (a * 4));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
|
case 'f':
|
|
|
|
|
value += 15 * (1 << (a * 4));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw std::runtime_error("invalid character in hex number");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> BookTextParser::split(std::string text, const int width, const int height)
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> result;
|
|
|
|
|
|
|
|
|
|
boost::algorithm::replace_all(text, "<BR>", "\n");
|
|
|
|
|
boost::algorithm::replace_all(text, "<P>", "\n\n");
|
|
|
|
|
|
|
|
|
|
const int spacing = 48;
|
|
|
|
|
|
|
|
|
|
while (text.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
// read in characters until we have exceeded the size, or run out of text
|
|
|
|
|
int currentWidth = 0;
|
|
|
|
|
int currentHeight = 0;
|
|
|
|
|
std::string currentText;
|
|
|
|
|
std::string currentWord;
|
|
|
|
|
|
|
|
|
|
unsigned int i=0;
|
|
|
|
|
while (currentHeight <= height-spacing && i<text.size())
|
|
|
|
|
{
|
|
|
|
|
if (text[i] == '<')
|
|
|
|
|
{
|
|
|
|
|
if (text.find('>', i) == std::string::npos)
|
|
|
|
|
throw std::runtime_error("BookTextParser Error: Tag is not terminated");
|
|
|
|
|
|
|
|
|
|
if (text.size() > i+4 && text.substr(i, 4) == "<IMG")
|
|
|
|
|
{
|
|
|
|
|
int h = mHeight;
|
|
|
|
|
parseImage(text.substr(i, text.find('>', i)-i), false);
|
|
|
|
|
currentHeight += (mHeight-h);
|
|
|
|
|
currentWidth = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (text.size() > i+5 && text.substr(i, 5) == "<FONT")
|
|
|
|
|
{
|
|
|
|
|
parseFont(text.substr(i, text.find('>', i)-i));
|
|
|
|
|
currentHeight += 18; // keep this in sync with the font size
|
|
|
|
|
currentWidth = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (text.size() > i+4 && text.substr(i, 4) == "<DIV")
|
|
|
|
|
{
|
|
|
|
|
parseDiv(text.substr(i, text.find('>', i)-i));
|
|
|
|
|
currentHeight += 18; // keep this in sync with the font size
|
|
|
|
|
currentWidth = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentText += text.substr(i, text.find('>', i)-i+1);
|
|
|
|
|
i = text.find('>', i);
|
|
|
|
|
}
|
|
|
|
|
else if (text[i] == '\n')
|
|
|
|
|
{
|
|
|
|
|
currentHeight += 18; // keep this in sync with the font size
|
|
|
|
|
currentWidth = 0;
|
|
|
|
|
currentWord = "";
|
|
|
|
|
currentText += text[i];
|
|
|
|
|
}
|
|
|
|
|
else if (text[i] == ' ')
|
|
|
|
|
{
|
|
|
|
|
currentWidth += 3; // keep this in sync with the font's SpaceWidth property
|
|
|
|
|
currentWord = "";
|
|
|
|
|
currentText += text[i];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentWidth +=
|
|
|
|
|
MyGUI::FontManager::getInstance().getByName (mTextStyle.mFont == "Default" ? "EB Garamond" : mTextStyle.mFont)
|
|
|
|
|
->getGlyphInfo(static_cast<unsigned int>(text[i]))->width;
|
|
|
|
|
currentWord += text[i];
|
|
|
|
|
currentText += text[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentWidth > width)
|
|
|
|
|
{
|
|
|
|
|
currentHeight += 18; // keep this in sync with the font size
|
|
|
|
|
currentWidth = 0;
|
|
|
|
|
|
|
|
|
|
// add size of the current word
|
|
|
|
|
unsigned int j=0;
|
|
|
|
|
while (j<currentWord.size())
|
|
|
|
|
{
|
|
|
|
|
currentWidth +=
|
|
|
|
|
MyGUI::FontManager::getInstance().getByName (mTextStyle.mFont == "Default" ? "EB Garamond" : mTextStyle.mFont)
|
|
|
|
|
->getGlyphInfo(static_cast<unsigned int>(currentWord[j]))->width;
|
|
|
|
|
++j;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
if (currentHeight > height-spacing)
|
|
|
|
|
{
|
|
|
|
|
// remove the last word
|
|
|
|
|
currentText.erase(currentText.size()-currentWord.size(), currentText.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.push_back(currentText);
|
|
|
|
|
text.erase(0, currentText.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MyGUI::IntSize BookTextParser::parse(std::string text, MyGUI::Widget* parent, const int width)
|
|
|
|
|
{
|
|
|
|
|
mParent = parent;
|
|
|
|
@ -92,7 +193,7 @@ MyGUI::IntSize BookTextParser::parse(std::string text, MyGUI::Widget* parent, co
|
|
|
|
|
return MyGUI::IntSize(mWidth, mHeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BookTextParser::parseImage(std::string tag)
|
|
|
|
|
void BookTextParser::parseImage(std::string tag, bool createWidget)
|
|
|
|
|
{
|
|
|
|
|
int src_start = tag.find("SRC=")+5;
|
|
|
|
|
std::string image = tag.substr(src_start, tag.find('"', src_start)-src_start);
|
|
|
|
@ -111,11 +212,14 @@ void BookTextParser::parseImage(std::string tag)
|
|
|
|
|
int height_start = tag.find("HEIGHT=")+8;
|
|
|
|
|
int height = boost::lexical_cast<int>(tag.substr(height_start, tag.find('"', height_start)-height_start));
|
|
|
|
|
|
|
|
|
|
MyGUI::ImageBox* box = mParent->createWidget<MyGUI::ImageBox> ("ImageBox",
|
|
|
|
|
MyGUI::IntCoord(0, mHeight, width, height), MyGUI::Align::Left | MyGUI::Align::Top,
|
|
|
|
|
mParent->getName() + boost::lexical_cast<std::string>(mParent->getChildCount()));
|
|
|
|
|
box->setImageTexture("bookart\\" + image);
|
|
|
|
|
box->setProperty("NeedMouse", "false");
|
|
|
|
|
if (createWidget)
|
|
|
|
|
{
|
|
|
|
|
MyGUI::ImageBox* box = mParent->createWidget<MyGUI::ImageBox> ("ImageBox",
|
|
|
|
|
MyGUI::IntCoord(0, mHeight, width, height), MyGUI::Align::Left | MyGUI::Align::Top,
|
|
|
|
|
mParent->getName() + boost::lexical_cast<std::string>(mParent->getChildCount()));
|
|
|
|
|
box->setImageTexture("bookart\\" + image);
|
|
|
|
|
box->setProperty("NeedMouse", "false");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mWidth = std::max(mWidth, width);
|
|
|
|
|
mHeight += height;
|
|
|
|
|