本文整理汇总了C++中XmlDocument::load方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlDocument::load方法的具体用法?C++ XmlDocument::load怎么用?C++ XmlDocument::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument::load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: import
ResourceItem* SpriteFontDescriptionImporter::import(const String& filename, io::FileSystem* fileSystem) const {
using namespace sani::io;
using namespace sani::parser;
FileStream* stream = nullptr;
// the file exists so we can just open it
fileSystem->openFile(filename, Filemode::Read, &stream);
// the file points to XML
XmlDocument doc;
try {
doc.load(stream);
}
catch (const XmlException& ex) {
(void)ex;
fileSystem->closeFile(filename);
throw;
}
fileSystem->closeFile(filename);
XmlNode root, nameNode, sizeNode, spacingNode, regionsNode, outlineNode, outlineTypeNode, outlineWidthNode;
std::vector<XmlNode> regionNodes;
CharacterRegionCollection characterRegions;
doc.firstNode(root);
root.firstNode("name", nameNode);
root.firstNode("size", sizeNode);
root.firstNode("spacing", spacingNode);
root.firstNode("character_regions", regionsNode);
String nameOfFont(nameNode.value());
String nameOfFontWithoutExtension(nameOfFont);
size_t index = 0;
if ((index = nameOfFontWithoutExtension.rfind(".")) != String::npos) {
nameOfFontWithoutExtension = nameOfFont.substr(0, index);
}
FontDescription* desc = new FontDescription(
nameOfFontWithoutExtension,
XmlUtil::get<float>(sizeNode),
XmlUtil::get<float>(spacingNode)
);
if (root.firstNode("outline", outlineNode)) {
if (outlineNode.firstNode("type", outlineTypeNode)) {
desc->setOutlineType(
static_cast<OutlineType>(XmlUtil::get<int32>(outlineTypeNode)
));
}
if (outlineNode.firstNode("type", outlineWidthNode)) {
desc->setOutlineWidth(
(XmlUtil::get<float32>(outlineWidthNode)
));
}
}
regionsNode.getChildNodes(regionNodes);
for (auto& regionNode : regionNodes) {
XmlNode startNode, endNode;
regionNode.firstNode("start", startNode);
regionNode.firstNode("end", endNode);
unsigned short start = XmlUtil::get<uint32>(startNode);
unsigned short end = XmlUtil::get<uint32>(endNode);
characterRegions.push_back(std::make_tuple(start, end));
}
desc->setSetCharacterRegions(characterRegions);
String basename(filename.substr(0, filename.rfind("\\")));
String assetFolderPath(basename + "\\" + nameOfFont);
if (fileSystem->fileExists(assetFolderPath)) {
desc->setFontPath(assetFolderPath);
} else {
// it is a system font
if (!platformIsFontInstalled(nameOfFont.c_str())){
throw std::runtime_error(String("Can find font ") + nameOfFont);
}
desc->setFontPath(platformGetFontPath(nameOfFont));
}
return desc;
}