当前位置: 首页>>代码示例>>C++>>正文


C++ XmlDocument::load方法代码示例

本文整理汇总了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;
			}
开发者ID:Babelz,项目名称:SaNi,代码行数:86,代码来源:spritefont_description_importer.cpp


注:本文中的XmlDocument::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。