Exemple #1
0
	void axClientQuit() {
//		g_shaderManager->saveShaderCache();

		SafeDelete(g_soundSystem);

		g_inputSystem->finalize();
		SafeDelete(g_inputSystem);

		g_defaultFont.clear();
		g_consoleFont.clear();
		g_miniFont.clear();

#ifdef AX_CONFIG_OPTION_USE_SPEEDTREE_40
		g_renderSystem->removeEntityManager(g_treeManager);
		SafeDelete(g_treeManager);
#endif // AX_CONFIG_OPTION_USE_SPEEDTREE_40

		g_fontFactory->finalize();
		g_assetManager->removeType(Asset::kFont);
		SafeDelete(g_fontFactory);

		g_assetManager->removeType(RenderMaterial::AssetType);
		SafeDelete(gMaterialFactory);

		g_renderSystem->finalize();
		SafeDelete(g_renderSystem);

		g_renderQueue->finalize();
		SafeDelete(g_renderQueue);
	}
	unsigned TextBox::GetTextBoxHeight() const
	{
		FontPtr pFont = Renderer::GetInstance().GetFont(mTextSize);		
		float height = pFont->GetHeight();
		pFont->SetBackToOrigHeight();
		return Round(height * mNumTextLines) + 16;
	}
Exemple #3
0
FontManager::FontPtr FontManager::Load(const std::string& locator){
	std::string file;
	int size;

	std::string::size_type plast = locator.find_last_not_of(";");
	std::string::size_type pfirst = locator.find_first_of(";");
	std::string tmp;

	if((plast == std::string::npos) || (pfirst == std::string::npos)){
		file = locator;
		size = DEFAULT_FONT_SIZE;
	}else{
		file = locator.substr(0, plast - 2);
		tmp = locator.substr(pfirst + 1);
		std::istringstream iss(tmp);
		iss >> size;
	}

	file = "content/fonts/" + file;

	FontPtr font = FontPtr(new sf::Font());
	if( !font->LoadFromFile(file, size))
		return FontPtr();

	return font;
}
//! [font_translate]
void FontTranslator::translate(ScriptCompiler* compiler, const AbstractNodePtr& node)
{
    ObjectAbstractNode* obj = static_cast<ObjectAbstractNode*>(node.get());

    // Must have a name - unless we are in legacy mode. Then the class is the name.
    if (obj->name.empty() && obj->cls == "font")
    {
        compiler->addError(ScriptCompiler::CE_OBJECTNAMEEXPECTED, obj->file, obj->line,
                           "font must be given a name");
        return;
    }

    String& name = obj->cls == "font" ? obj->name : obj->cls;

    FontPtr font = FontManager::getSingleton().create(name, compiler->getResourceGroup());
    font->_notifyOrigin(obj->file);

    for (auto& c : obj->children)
    {
        if (c->type == ANT_PROPERTY)
        {
            parseAttribute(compiler, font, static_cast<PropertyAbstractNode*>(c.get()));
        }
    }
}
Exemple #5
0
float
Menu::get_width() const
{
  /* The width of the menu has to be more than the width of the text
     with the most characters */
  float menu_width = 0;
  for(unsigned int i = 0; i < items.size(); ++i)
  {
    FontPtr font = Resources::Resources::normal_font;
    if(items[i]->kind == MN_LABEL)
      font = Resources::big_font;

    float w = font->get_text_width(items[i]->text) +
      Resources::big_font->get_text_width(items[i]->input) + 16;
    if(items[i]->kind == MN_TOGGLE)
      w += 32;
    if (items[i]->kind == MN_STRINGSELECT)
      w += font->get_text_width(items[i]->list[items[i]->selected]) + 32;


    if(w > menu_width)
      menu_width = w;
  }

  return menu_width + 24;
}
Exemple #6
0
ObjectPtr<Object> Font::restoreObject(SaveGame *state) {
	const char *fname = state->readCharString();
	FontPtr font = g_resourceloader->getFont(fname);
	delete[] fname;
	ObjectPtr<Object> ptr = font.object();

	return ptr;
}
	void TextBox::CalcTextWidth()
	{
		// analyze the text length
		FontPtr pFont = Renderer::GetInstance().GetFont(mTextSize);
		unsigned width = mSize.x;		
		float textWidth;
		mMultiLineText = pFont->InsertLineFeed((const char*)mTextw.c_str(), mTextw.size() * 2, width, &textWidth, &mNumTextLines);
		mTextWidth = (unsigned)Round(textWidth);
		pFont->SetBackToOrigHeight();
		mUIObject->SetText(mMultiLineText.c_str());
	}
Exemple #8
0
IECore::ConstObjectPtr Text::computeSource( const Context *context ) const
{
	std::string fontFileName = fontPlug()->getValue();
	std::string text = textPlug()->getValue();
	if( !text.size() || !fontFileName.size() )
	{
		return outPlug()->objectPlug()->defaultValue();
	}

	FontPtr font = Detail::fontCache()->get( fontFileName );
	return font->mesh( text );
}
WONButtonPtr WinSkin::CalcCheckButton(const char *theBitmapName, WONButton *orig)
{
	WONButtonPtr aCheckbox = new WONButton;
	aCheckbox->SetPushOffsets(0,0);
	aCheckbox->SetHasCheck(true);
	aCheckbox->SetScaleImage(false);

	RawImagePtr aButtonMasterImage = GetRawImage("Buttons",theBitmapName);
	int aNumPictures = GetIntParam("Buttons","EnhancedMode")?5:4;
	if(aButtonMasterImage.get()==NULL)
		return orig;

	int aWidth = aButtonMasterImage->GetWidth()/aNumPictures;
	aCheckbox->SetTextPadding(aWidth + 4,2,2,2);

	int aColor = GetColor("Buttons","NormalColour");
	FontPtr aFont = GetFont("Buttons","NormalFont");
	if(aFont.get()==NULL)
		aFont = mWindow->GetWindowManager()->GetNamedFont("MSButton");
	if(aColor==-1)
		aColor = 0;

	CropImageFilterPtr aCrop = new CropImageFilter;
	aCrop->SetSize(aWidth,aButtonMasterImage->GetHeight());
	for(int i=0; i<4; i++)
	{
		aCrop->SetPos(i*aWidth,0);
		RawImagePtr aRawImage = aCrop->Filter(aButtonMasterImage);
		NativeImagePtr aNativeImage = aRawImage->GetNative(mWindow->GetDisplayContext());

		bool checked = i&1?true:false;
		int anIndex = i>=2?2:0;

		aCheckbox->SetButtonState(anIndex,aNativeImage,aColor,aFont,checked);
		if(anIndex==0)
		{
			RawImagePtr aRawImage2 = (RawImage*)aRawImage->Duplicate().get();
			TintImageFilterPtr aTint = new TintImageFilter(100,100,150);
			aTint->Filter(aRawImage);
			aNativeImage = aRawImage->GetNative(mWindow->GetDisplayContext());

			aCheckbox->SetButtonState(3,aNativeImage,aColor,aFont,checked);

			aTint = new TintImageFilter(100,150,100);
			aTint->Filter(aRawImage2);
			aNativeImage = aRawImage2->GetNative(mWindow->GetDisplayContext());

			aCheckbox->SetButtonState(1,aNativeImage,aColor,aFont,checked);
		}
	}
	return aCheckbox;
}
Exemple #10
0
	void CategorizedList::Category::layoutChildren()
	{
		FontPtr font = parent.GetFont();
		float pos = font ? font->getLineSpacing() : 0.f;
		std::vector<window_ptr>::iterator i = children.begin();
		std::vector<window_ptr>::iterator end = children.end();
		while(i != end)
		{
			window_ptr child = *i;
			child->setPosition(point(area.m_left, area.m_top + pos));
			pos += child->getArea().getHeight();

			++i;
		}
	}
Exemple #11
0
FontPtr FontManager::load(std::string path)
{
	if(isLoaded(path))
	{
		throw runtime_error("Font '" + path + "' already loaded");
	}

	FontPtr New = make_shared<Font>();

	if(!New->loadFromFile(path))
	{
		throw runtime_error("Cannot load font " + path);
	}

	return New;
}
void BadUserItem::Paint(Graphics &g, ListArea *theListArea)
{
	int aColor = theListArea->GetTextColor();
	if(mSelected)
		aColor = theListArea->GetSelColor().GetForegroundColor(g,aColor);

	int aPaintCol = 0;
	bool drawSelection = mSelected;
	if(!mIsSimple)
	{
		aPaintCol = ((MultiListArea*)theListArea)->GetColumnPaintContext();
		if(aPaintCol!=-1)
			drawSelection = false;
	}
	
	
	if(drawSelection)
	{
		g.SetColor(theListArea->GetSelColor().GetBackgroundColor(g));
		g.FillRect(0,0,theListArea->GetPaintColumnWidth(),mFont->GetHeight());
		if(!mIsSimple)
			return;
	}
	if(aPaintCol<0 || aPaintCol>5)
		return;

	g.SetColor(aColor);
	g.SetFont(mFont);
	g.DrawString(mColStr[aPaintCol],0,0);
}
Exemple #13
0
	void MarkupBase::render(const Rect& finalRect, const Rect& finalClip)
	{
		size_t len = m_text.length();
		std::vector<PTextLine>::const_iterator i = m_textlines.begin();
		std::vector<PTextLine>::const_iterator end = m_textlines.end();
		while(i != end)
		{
			const TextLine* line = (*i).get();
			size_t offset = line->start;
			Rect rl(line->area);

			std::vector<PText>::const_iterator c = line->children.begin();
			std::vector<PText>::const_iterator stop = line->children.end();
			while(c != stop)
			{
				const Text* chunk = (*c).get();
				if(chunk->len > 0 && chunk->len <= len)
				{
					FontPtr f = chunk->font;
					Color col = chunk->selected ? chunk->selcol : chunk->col;
					std::string buf = m_text.substr(chunk->start + offset, chunk->len);
					Rect rc(chunk->area);
					rc.offset(rl.getPosition());
					rc.offset(finalRect.getPosition());
					f->drawText(buf, rc, 1.0f, finalClip, LeftAligned, col, 1.f, 1.f);
				}

				++c;
			}
			++i;
		}
		Renderer& r = m_system.getRenderer();

		std::vector<PImg>::const_iterator cimg = m_images.begin();
		std::vector<PImg>::const_iterator cimgend = m_images.end();
		while(cimg != cimgend)
		{
			const Img* img = (*cimg).get();
			Rect rc(img->area);
			rc.offset(finalRect.getPosition());
			if (img->img)
			{
				r.draw(*img->img, rc, 1.f, finalClip,  m_backColor, Stretch, Stretch);
			}
			++cimg;
		}
	}
Exemple #14
0
std::vector<std::unique_ptr<InfoBoxLine> >
InfoBoxLine::split(const std::string& text, float width)
{
  std::vector<std::unique_ptr<InfoBoxLine> > lines;

  std::string::size_type i = 0;
  std::string::size_type l;
  char format_char = '#';
  while(i < text.size()) {
    // take care of empty lines - represent them as blank lines of normal text
    if (text[i] == '\n') {
      lines.emplace_back(new InfoBoxLine('\t', ""));
      i++;
      continue;
    }

    // extract the format_char
    format_char = text[i];
    i++;
    if (i >= text.size()) break;

    // extract one line
    l = text.find("\n", i);
    if (l == std::string::npos) l=text.size();
    std::string s = text.substr(i, l-i);
    i = l+1;

    // if we are dealing with an image, just store the line
    if (format_char == '!') {
      lines.emplace_back(new InfoBoxLine(format_char, s));
      continue;
    }

    // append wrapped parts of line into list
    std::string overflow;
    do {
      FontPtr font = get_font_by_format_char(format_char);
      std::string s2 = s;
      if (font) s2 = font->wrap_to_width(s2, width, &overflow);
      lines.emplace_back(new InfoBoxLine(format_char, s2));
      s = overflow;
    } while (s.length() > 0);
  }

  return lines;
}
Exemple #15
0
    //---------------------------------------------------------------------
    void FontManager::parseScript(DataStreamPtr& stream, const String& groupName)
    {
        String line;
        FontPtr pFont;

        while( !stream->eof() )
        {
            line = stream->getLine();
            // Ignore blanks & comments
            if( !line.length() || line.substr( 0, 2 ) == "//" )
            {
                continue;
            }
            else
            {
                if (pFont.isNull())
                {
                    // No current font
                    // So first valid data should be font name
                    if (StringUtil::startsWith(line, "font "))
                    {
                        // chop off the 'particle_system ' needed by new compilers
                        line = line.substr(5);
                    }
                    pFont = create(line, groupName);
                    pFont->_notifyOrigin(stream->getName());
                    // Skip to and over next {
                    stream->skipLine("{");
                }
                else
                {
                    // Already in font
                    if (line == "}")
                    {
                        // Finished 
                        pFont.setNull();
                        // NB font isn't loaded until required
                    }
                    else
                    {
                        parseAttribute(line, pFont);
                    }
                }
            }
        }
    }
TextSprite::TextSprite(MaterialPtr material, const std::string &text, FontPtr font, PropertiesPtr	properties)
	: Sprite(), _text(text), _font(font)
{
	// Create geometry
	createGeometry();

	// Add atlas texture to the material
	material->setTexture(bRenderer::DEFAULT_SHADER_UNIFORM_CHARACTER_MAP(), font->getAtlas());

	setMaterial(material);
	setProperties(properties);
}
void OgreText::calculateTextPixelSize(DisplayString text, FontPtr mpFont, Real mCharHeight, Real& width, Real& height)
{
    Real vpWidth, vpHeight;
    vpWidth = (Real) (OverlayManager::getSingleton().getViewportWidth());
    vpHeight = (Real) (OverlayManager::getSingleton().getViewportHeight());
    //ROS_ERROR("[viewport] w: %f h: %f",vpWidth,vpHeight);   

    Real mViewportAspectCoef = vpHeight/vpWidth;

    height = mCharHeight;
    width = 0;

    Real len = 0.0f;
    for(DisplayString::iterator i = text.begin();i!=text.end();++i)
    {
        Font::CodePoint character = OGRE_DEREF_DISPLAYSTRING_ITERATOR(i);
        if (character == UNICODE_CR
                || character == UNICODE_NEL
                || character == UNICODE_LF)
        {
            height += mCharHeight;
            if(len > width)
                width = len;
            len = 0;
        }
        else if (character == UNICODE_SPACE) // space
        {
            len += mpFont->getGlyphAspectRatio(UNICODE_ZERO) * mCharHeight;// * 2.0 * mViewportAspectCoef;
        }
        else
        {
            len += mpFont->getGlyphAspectRatio(character) * mCharHeight;// * 2.0 * mViewportAspectCoef;
        }
    }
    if(len > width)
        width = len;
}
TextSprite::TextSprite(ObjectManager *o, const std::string &name, vmml::Vector3f color, const std::string &text, FontPtr font, PropertiesPtr properties)
	: Sprite(), _text(text), _font(font)
{
	// Create geometry
	createGeometry();

	// Create shader and material
	ShaderPtr shader = o->generateShader(name, { 0, false, true, false, false, true, false, false, false, false, false, false, true });
	MaterialPtr material = o->createMaterial(name, shader);
	
	// Add atlas texture to the material
	material->setTexture(bRenderer::DEFAULT_SHADER_UNIFORM_CHARACTER_MAP(), font->getAtlas());
	// Pass color to material (don't pass texture, has to be treated separately to bind right tex unit)
	material->setVector(bRenderer::WAVEFRONT_MATERIAL_DIFFUSE_COLOR(), color);

	setMaterial(material);
	setProperties(properties);
}
void
DrawingContext::draw_text(FontPtr font, const std::string& text,
                          const Vector& position, FontAlignment alignment, int layer, Color color)
{
  DrawingRequest* request = new(obst) DrawingRequest();

  request->target = target;
  request->type = TEXT;
  request->pos = transform.apply(position);
  request->layer = layer;
  request->drawing_effect = transform.drawing_effect;
  request->alpha = transform.alpha;
  request->color = color;

  TextRequest* textrequest = new(obst) TextRequest();
  textrequest->font = font.get();
  textrequest->text = text;
  textrequest->alignment = alignment;
  request->request_data = textrequest;

  requests->push_back(request);
}
Exemple #20
0
  void get_logfont(FontPtr font, LOGFONT * lf) {
    D3DXFONT_DESC fd;
    HRESULT hr = font->GetDesc(&fd);
    if (FAILED(hr)) DX_EXCEPT("Failed call to ID3DXFont::GetDesc(). ", hr);

    LOGFONT f = {
      fd.Height,
      fd.Width,
      0,
      0,
      fd.Weight,
      static_cast<BYTE>(fd.Italic),
      0,
      0,
      fd.CharSet,
      fd.OutputPrecision,
      CLIP_DEFAULT_PRECIS,
      QUALITY, //fd.Quality,
      fd.PitchAndFamily,
    };
    _tcscpy(f.lfFaceName, fd.FaceName);
    *lf = f;
  }
Exemple #21
0
    //---------------------------------------------------------------------
    void FontManager::parseAttribute(const String& line, FontPtr& pFont)
    {
        vector<String>::type params = StringUtil::split(line);
        String& attrib = params[0];
        StringUtil::toLowerCase(attrib);
        if (attrib == "type")
        {
            // Check params
            if (params.size() != 2)
            {
                logBadAttrib(line, pFont);
                return;
            }
            // Set
            StringUtil::toLowerCase(params[1]);
            if (params[1] == "truetype")
            {
                pFont->setType(FT_TRUETYPE);
            }
            else
            {
                pFont->setType(FT_IMAGE);
            }

        }
        else if (attrib == "source")
        {
            // Check params
            if (params.size() != 2)
            {
                logBadAttrib(line, pFont);
                return;
            }
            // Set
            pFont->setSource(params[1]);
        }
        else if (attrib == "glyph")
        {
            // Check params
            if (params.size() != 6)
            {
                logBadAttrib(line, pFont);
                return;
            }
            // Set
            // Support numeric and character glyph specification
            Font::CodePoint cp;
            if (params[1].at(0) == 'u' && params[1].size() > 1)
            {
                // Unicode glyph spec
                String trimmed = params[1].substr(1);
                cp = StringConverter::parseUnsignedInt(trimmed);
            }
            else
            {
                // Direct character
                cp = params[1].at(0);
            }
            pFont->setGlyphTexCoords(
                cp, 
                StringConverter::parseReal(params[2]),
                StringConverter::parseReal(params[3]),
                StringConverter::parseReal(params[4]),
                StringConverter::parseReal(params[5]), 1.0 ); // assume image is square
        }
        else if (attrib == "size")
        {
            // Check params
            if (params.size() != 2)
            {
                logBadAttrib(line, pFont);
                return;
            }
            // Set
            pFont->setTrueTypeSize(
                StringConverter::parseReal(params[1]));
        }
        else if (attrib == "character_spacer")
        {
            // Check params
            if (params.size() != 2)
            {
                logBadAttrib(line, pFont);
                return;
            }
            // Set
            pFont->setCharacterSpacer(
                StringConverter::parseUnsignedInt(params[1]));
        }
        else if (attrib == "resolution")
        {
            // Check params
            if (params.size() != 2)
            {
                logBadAttrib(line, pFont);
                return;
            }
            // Set
            pFont->setTrueTypeResolution(
                (uint)StringConverter::parseReal(params[1]) );
        }
        else if (attrib == "antialias_colour")
        {
            // Check params
            if (params.size() != 2)
            {
                logBadAttrib(line, pFont);
                return;
            }
            // Set
            pFont->setAntialiasColour(StringConverter::parseBool(params[1]));
        }
        else if (attrib == "code_points")
        {
            for (size_t c = 1; c < params.size(); ++c)
            {
                String& item = params[c];
                StringVector itemVec = StringUtil::split(item, "-");
                if (itemVec.size() == 2)
                {
                    pFont->addCodePointRange(Font::CodePointRange(
                        StringConverter::parseUnsignedInt(itemVec[0]),
                        StringConverter::parseUnsignedInt(itemVec[1])));
                }
            }
        }

    }
void BadUserItem::CalcDimensions(ListArea *theListArea)
{
	mFont = theListArea->GetFont();
	mHeight = mFont->GetHeight();
}
WONButtonPtr WinSkin::CalcButton(const char *theSection, const char *theBitmapName, WONButton *orig)
{
	RawImagePtr aButtonMasterImage = GetRawImage(theSection,theBitmapName);
	if(aButtonMasterImage.get()==NULL)
		return orig;

	bool isTab = false;
	bool isHeader = false;

	if(stricmp(theSection,"HeaderBar")==0)
	{
		isHeader = true;
		mSkin->mListCtrl->SetHeaderHeight(aButtonMasterImage->GetHeight());
	}
	else if(stricmp(theSection,"Tabs")==0)
	{
		mSkin->mTabCtrl->SetTabBarHeight(aButtonMasterImage->GetHeight());
		isTab = true;
	}

	WONButtonPtr aButton;
	if(isHeader)
		aButton = new WONHeaderButton;
	else
		aButton = new WONButton;

	int leftWidth = GetIntParam(theSection,"LeftWidth");
	int topHeight = GetIntParam(theSection,"TopHeight");
	int rightWidth = GetIntParam(theSection,"RightWidth");
	int bottomHeight = GetIntParam(theSection,"BottomHeight");
	int tile = GetIntParam(theSection,"Tile");
	bool mouseOver = GetIntParam(theSection,"MouseOver")?true:false;
	aButton->SetButtonFlags(ButtonFlag_InvalidateOnMouseOver,mouseOver);
//	aButton->SetTextPaddingAtLeast(leftWidth+2,topHeight+2,rightWidth+2,bottomHeight+2);

	int aNumFrames = GetIntParam(theSection,"FrameCount");
	if(aNumFrames<5)
		aNumFrames = 5;

	int aWidth = aButtonMasterImage->GetWidth()/aNumFrames;

	const char *colornames[] = { "NormalColour", "PressedColour", "DisabledColour", "FocusColour", "DefaultColour" };
	const char *fontnames[] = { "NormalFont", "PressedFont", "DisabledFont", "FocusFont", "DefaultFont" };

	CropImageFilterPtr aCrop = new CropImageFilter;
	aCrop->SetSize(aWidth,aButtonMasterImage->GetHeight());
	for(int i=0; i<5; i++)
	{
		StretchImagePtr aStretchImage = NULL;
		if(i<5)
		{
			aCrop->SetPos(i*aWidth,0);
			RawImagePtr aRawImage = aCrop->Filter(aButtonMasterImage);

			aStretchImage = new StretchImage(aRawImage,leftWidth,topHeight,rightWidth,bottomHeight);
			switch(tile)
			{
				case 0: aStretchImage->SetTile(false,false); break;
				case 1: aStretchImage->SetTile(true,true); break;
				case 2: aStretchImage->SetTile(true,false); break;
				case 3: aStretchImage->SetTile(false,true); break;
			}
		}

		int aColor = GetColor(theSection,colornames[i]);
		FontPtr aFont = GetFont(theSection,fontnames[i]);
		if(i==0)
		{
			if(aFont.get()==NULL)
				aFont = mWindow->GetWindowManager()->GetNamedFont("MSButton");
			if(aColor==-1)
				aColor = 0;
		}

		if(i==1 && isTab)
		{
			aButton->SetHasCheck(true);
			aButton->SetButtonState(0,aStretchImage,aColor,aFont,true);
		}
		else
			aButton->SetButtonState(i,aStretchImage,aColor,aFont);
	}

	aButton->SetTransparent(aButtonMasterImage->HasTransparency());
	return aButton;
}
Exemple #24
0
void render(const text::utf32_string& inText, const vector<Range>& lines, const FontPtr& font, const RenderedTextPtr& target, bool characterMetrics, int align)
{
  // these arrays will receive the character geometry in space, relative to a 0,0 baseline
  // and the corresponding pixel coordinates of the subtexture within the font texture atlas
  // used to draw the character
  vector<math::Vec2> lineBounds;
  vector<math::Rect> characterRects;
  vector<math::Rect> pixelCoordRects;
    
  // size calculation 
  Vec2 pmin, pmax; 
  uint32_t addIndex=0; // we iterate over all chracters, but not all of them might be drawable
                       // so we need a separate index for the actual insertion of a character into the mesh

  uint32_t previousGlyphIndex = 0;
  float xoffset = 0;    
  float yoffset = std::max((float)lines.size()-1, 0.0f)*floorf(font->lineHeight);
  if(characterMetrics) {target->resetCharacterMetrics(); }
  for(vector<Range>::const_iterator pos=lines.begin(); pos!=lines.end(); ++pos)
  {
    if(characterMetrics) {target->pushEmptyCharacterMetricLine();}
    if(pos->begin != pos->end) // skip empty lines
    {
      Vec2 bounds(addIndex,addIndex);
      for(uint32_t i=pos->begin; i<pos->end; ++i)
      {
        text::utf32_char c = inText[i];
        xoffset+=font->kerningOffset(previousGlyphIndex, c);
        GlyphPtr glyph = font->glyph(c);
        if (!glyph) continue;
        if (glyph->drawable)
        {
          addGlyph(characterRects, pixelCoordRects, glyph, xoffset, yoffset, pmin, pmax);
          if(characterMetrics) {target->pushCharacterRect(characterRects[addIndex]);}
          addIndex++;
        }
        else
        {
          // push dummy rect for metrics if char was not drawable
          if(characterMetrics) {target->pushCharacterRect(Rect(xoffset,yoffset,glyph->advance,font->lineHeight));}
        }
        xoffset+=glyph->advance;
      }
      if (align != 0 && addIndex > 0) {
        bounds.max = addIndex-1;
        lineBounds.push_back(bounds);
      }
    }
    xoffset = 0;
    yoffset -= floorf(font->lineHeight);
    previousGlyphIndex = 0;
  }

  // horizontal align center/right
  if (align != 0) {
    float maxWidth = (pmax.x-pmin.x)+1;
    for (vector<math::Vec2>::iterator b = lineBounds.begin(); b != lineBounds.end(); ++b) {
      int offset = (maxWidth - (characterRects[b->max].x+characterRects[b->max].width-characterRects[b->min].x));
      if (offset > 0) {
        if (align == 1) {
          offset /= 2.0f;
        }
        for (int c = b->min; c <= b->max; ++c) {
          characterRects[c].x += offset;
        }
      }
    }
  }

  target->init(characterRects, font->atlas, pixelCoordRects, false);
  target->min = pmin;
  target->max = pmax;
  target->size.width = (pmax.x-pmin.x)+1;  
  target->size.height = (pmax.y-pmin.y)+1;
  target->material->blendPremultiplied();
  target->numLines = lines.size();
}
Exemple #25
0
void
Canvas::draw_text(const FontPtr& font, const std::string& text,
                  const Vector& pos, FontAlignment alignment, int layer, const Color& color)
{
  font->draw_text(*this, text, pos, alignment, layer, color);
}
Exemple #26
0
 Dimension get_char_dim(FontPtr font) {
   TEXTMETRIC tm;
   if (!font->GetTextMetrics(&tm)) MISC_EXCEPT("Failed call to ID3DXFont::GetTextMetrics(). ");
   return Dimension(tm.tmAveCharWidth, tm.tmHeight);
 }
Exemple #27
0
    //---------------------------------------------------------------------
    void FontManager::logBadAttrib(const String& line, FontPtr& pFont)
    {
        LogManager::getSingleton().logMessage("Bad attribute line: " + line +
            " in font " + pFont->getName(), LML_CRITICAL);

    }
Exemple #28
0
namespace Axon {

	AX_DECLARE_MODULE(axopengl);
	AX_DECLARE_MODULE(axdirect3d9);

	using namespace Axon::Render;
//	using namespace Axon::PARTICLESYSTEM;

	// console variable
#define AX_CVARDECL(name, defaultstring, flags) \
	Cvar* name;
#include <axclient/cvardecls.h>
#undef AX_CVARDECL

	// statistic
#define AX_STATDECL(name, desc, autoreset)  int name;
#include "axclient/statdecls.h"
#undef AX_STATDECL

	// public object
	Render::System* g_renderSystem;
	Render::Queue* g_renderQueue;
	Render::Queue* g_queues[2];
	Render::ShaderMacro			g_shaderMacro;
	Render::Uniforms			g_uniforms;
	Render::IDriver* g_renderDriver;

	Render::TargetManager* g_targetManager;
	Render::ShaderManager* g_shaderManager;
	Render::PrimitiveManager* g_primitiveManager;

	Render::QueryManager* g_queryManager;

	InputSystem* g_inputSystem;
	SoundSystem* g_soundSystem;

	FontPtr						g_defaultFont;
	FontPtr						g_consoleFont;
	FontPtr						g_miniFont;

	// only visible in this module
	FontFactory* g_fontFactory;
	MaterialFactory* gMaterialFactory;

#ifdef AX_CONFIG_OPTION_USE_SPEEDTREE_40
	TreeManager* g_treeManager;
#endif // AX_CONFIG_OPTION_USE_SPEEDTREE_40

	// xinput
//	Xinput* gXinput;

	void axClientInit() {

		// init cvar
#define AX_CVARDECL(name, defaultstring, flags) \
	name = g_cvarSystem->createCvar(#name, defaultstring, flags);
#include <axclient/cvardecls.h>
#undef AX_CVARDECL

		// init statistic

#define AX_STATDECL(name, desc, autoreset) \
	name = g_statistic->getIndex(Statistic::RenderDrvGroup, desc, autoreset);
#include "axclient/statdecls.h"
#undef AX_STATDECL


#if 1 // _LIB
		AX_REGISTER_MODULE(axopengl);
		AX_REGISTER_MODULE(axdirect3d9);
#endif

		g_renderSystem = new Render::System;
		g_renderSystem->initialize();

		gMaterialFactory = new MaterialFactory;
		g_assetManager->registerType(RenderMaterial::AssetType, gMaterialFactory);

		g_fontFactory = new FontFactory;
		g_assetManager->registerType(Asset::kFont, g_fontFactory);
		g_fontFactory->initialize();

		g_defaultFont = FindAsset_<Font>("fonts/default", Font::makeSize(14,14));
		g_consoleFont = FindAsset_<Font>("fonts/console", Font::makeSize(14,14));
		g_miniFont = FindAsset_<Font>("fonts/console", Font::makeSize(11,11));

		g_renderDriver->postInit();

#ifdef AX_CONFIG_OPTION_USE_SPEEDTREE_40
		g_treeManager = new TreeManager();
		g_renderSystem->addEntityManager(g_treeManager);
#endif

		g_inputSystem = new InputSystem();
		g_inputSystem->initialize();

		g_soundSystem = new SoundSystem();

//		g_shaderManager->applyShaderCache();
	}

	void axClientQuit() {
//		g_shaderManager->saveShaderCache();

		SafeDelete(g_soundSystem);

		g_inputSystem->finalize();
		SafeDelete(g_inputSystem);

		g_defaultFont.clear();
		g_consoleFont.clear();
		g_miniFont.clear();

#ifdef AX_CONFIG_OPTION_USE_SPEEDTREE_40
		g_renderSystem->removeEntityManager(g_treeManager);
		SafeDelete(g_treeManager);
#endif // AX_CONFIG_OPTION_USE_SPEEDTREE_40

		g_fontFactory->finalize();
		g_assetManager->removeType(Asset::kFont);
		SafeDelete(g_fontFactory);

		g_assetManager->removeType(RenderMaterial::AssetType);
		SafeDelete(gMaterialFactory);

		g_renderSystem->finalize();
		SafeDelete(g_renderSystem);

		g_renderQueue->finalize();
		SafeDelete(g_renderQueue);
	}

} // namespace Axon
void FontTranslator::parseAttribute(ScriptCompiler* compiler, FontPtr& pFont,
                                    PropertyAbstractNode* prop)
{
    String& attrib = prop->name;
    String val;

    if (attrib == "glyph")
    {
        float coords[4];
        if (prop->values.size() != 5 || !getString(prop->values.front(), &val) ||
            !getFloats(++prop->values.begin(), prop->values.end(), coords, 4))
        {
            compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
            return;
        }

        // Set
        // Support numeric and character glyph specification
        Font::CodePoint cp;
        if (val.size() > 1 && val[0] == 'u')
        {
            // Unicode glyph spec
            String trimmed = val.substr(1);
            cp = StringConverter::parseUnsignedInt(trimmed);
        }
        else
        {
            // Direct character
            cp = val[0];
        }
        pFont->setGlyphTexCoords(cp, coords[0], coords[1], coords[2], coords[3],
                                 1.0); // assume image is square
    }
    else if (attrib == "antialias_colour")
    {
        bool flag;
        if (prop->values.empty() || !getBoolean(prop->values.front(), &flag))
        {
            compiler->addError(ScriptCompiler::CE_STRINGEXPECTED, prop->file, prop->line);
            return;
        }
        pFont->setAntialiasColour(flag);
    }
    else if (attrib == "code_points")
    {
        if (prop->values.empty())
        {
            compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
            return;
        }

        for (auto& v : prop->values)
        {

            bool succ = getString(v, &val);
            StringVector itemVec = StringUtil::split(val, "-");
            if (succ && itemVec.size() == 2)
            {
                pFont->addCodePointRange(
                    Font::CodePointRange(StringConverter::parseUnsignedInt(itemVec[0]),
                                         StringConverter::parseUnsignedInt(itemVec[1])));
            }
        }
    }
    else if (prop->values.empty() || !getString(prop->values.front(), &val) ||
             !pFont->setParameter(attrib, val))
    {
        compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line);
    }
}