Пример #1
0
std::string Menu::chopString(const std::string& src, const float h, const Ogre::FontPtr& glyphs)
{
  if (h<=0.0f or glyphs.isNull()) return src;
  const float maxWidth = 1.05;
  unsigned int i;
  std::string result = "";
  float currentWidth = 0.0f;
  for (i=0; i<src.size(); ++i)
  {
    if (src.at(i)=='\n')
    {
      currentWidth = 0.0f;
      result.append(1, '\n');
    }
    else
    {
      const float add_w = glyphs->getGlyphAspectRatio(src.at(i))*h;
      if (currentWidth+add_w>maxWidth)
      {
        result = result+"\n"+src.at(i);
        currentWidth = add_w;
      }//if
      else
      {
        result = result + src.at(i);
        currentWidth = currentWidth + add_w;
      }//else
    }//else
  }//for
  return result;
}
Пример #2
0
void gkFontManager::parseScript(utMemoryStream* buffer)
{
	utScript script;
	script.parseBuffer("FontManager:parseScript", gkString((const char*)buffer->ptr()));


	utScriptTree* treePtr = script.getTreePtr();

	if (treePtr->getNodes().empty())
		return;


	utScriptTree::Nodes::Iterator niter = treePtr->getNodes().iterator();
	while (niter.hasMoreElements())
	{
		utScriptNode* tree = niter.getNext();

		if (!tree->hasAttribute("source"))
		{
			gkLogMessage("FontManager: Missing font script attribute 'source'");
			continue;
		}
		const gkString src = tree->getAttribute("source")->getValue();

		if (!exists(src))
		{
			gkLogMessage("FontManager: Missing internal font " << src);
			continue;
		}

		const gkString name = tree->getType();

		Ogre::FontPtr fp = Ogre::FontManager::getSingleton().getByName(name);
		if (!fp.isNull())
		{
			// use it
			return;
		}


		gkFont* gkf = (gkFont*)getByName(src);


		int size = 0, res = UT_NPOS;

		if (tree->hasAttribute("size"))
			gkFromString(tree->getAttribute("size")->getValue(), size);

		if (tree->hasAttribute("resolution"))
			gkFromString(tree->getAttribute("resolution")->getValue(), res);

		try
		{

			gkFont::Loader* fl = gkf->addLoader(size > 0 && size != UT_NPOS ? size : 12, res != UT_NPOS ? res : 55);
			fp = Ogre::FontManager::getSingleton().create(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true, fl);
			fl->setFont(fp.getPointer());
		}
		catch (Ogre::Exception& e)
		{
			gkLogMessage("FontManager::parseScript: " << e.getDescription());
		}
	}
}