Пример #1
0
static int Font_InternalWrite_vleft ( int x, int y, const char *text, int count )
{
	int n;
	int len = 0;
	int a;

	for ( n = 0; n < count; )
	{
		int charId = Font_GetTextChar ( text, n, &n );
		SCharDescr *ch = Font_GetChar ( charId );

		if ( ch == 0 )
		{
			//debugprintf ( "Unknown Character %d\r\n", charId );
			a = 0;
		}
		else
		{
			if ( cur_pFont->bAutoKerning )
				a = ( ch->xAdv );
			else
				a = cur_pFont->fontsize;

			//rendering
			drawchar_vleft ( x, y, ch );
		}

		y -= a + cur_pFont->kerning;
		len += a + cur_pFont->kerning;
	}

	return len;
}
Пример #2
0
static int bmpfont_text_count_in_width( EGL_FONT* pFont, const char* text, int w )
{
	int n;
	int len = 0;
	int a;
	int count ;
	cur_pFont = EGL_FONT_TO_BMFONT(pFont);
		
	count = Font_GetTextLength ( text );

	for ( n = 0; n < count; )
	{
		int charId = Font_GetTextChar ( text, n, &n );
		SCharDescr *ch = Font_GetChar ( charId );

		if ( ch == 0 )
		{
			//debugprintf ( "Unknown Character %d\r\n", charId );
			a = 0;
		}
		else
		{
			if ( cur_pFont->bAutoKerning )
				a = ( ch->xAdv );
			else
				a = cur_pFont->fontsize;
		}

		len += a + cur_pFont->kerning;
		if( len >= w )
			break;
	}
	return n;
}
Пример #3
0
void Fonts_LoadString(wchar_t* _strText)
{
	size_t nLen = wcslen(_strText); 
	for(int i = 0 ; i <(int)nLen ; i ++)
	{
		xCharTexture* pCharTex = Font_GetChar(_strText[i]);
	}

	//LogToFile("LoadText: %s", UnicodeToANSI(_strText));
}
Пример #4
0
int Fonts_Draw2(wchar_t* _strText,int x , int y, int maxW , int h, int iH)
{
	int sx = x;
	int sy = y;
	int maxH = h;
	size_t nLen = wcslen(_strText);

	for(int i = 0 ; i <(int)nLen ; i ++)
	{
		if(_strText[i] =='\n')
		{
			sx = x ; sy += (iWidthCheck + iH);
			continue;
		}
		xCharTexture* pCharTex = Font_GetChar(_strText[i]);
		Tri_BindTexture(GL_TEXTURE_2D,pCharTex->m_texID);
		Tri_SetTextureParam();
		
		Tri_BlendFunc(GL_SRC_ALPHA,GL_ONE); 
		int w = pCharTex->m_Width;
		int h = pCharTex->m_Height;
		int ch_x = sx + pCharTex->m_delta_x;
		int ch_y = sy - h - pCharTex->m_delta_y;
		if(maxH < h) maxH = h;

		// 不知道该怎么办..
		if(_strText[i] =='$') 
			ch_y-=1;
		
		Tri_Enable(GL_BLEND);
		Tri_BlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
		if(g_iVideoMode)
		{
			glColor4ub(Fonts_iColor_R,Fonts_iColor_G,Fonts_iColor_B,Fonts_iColor_A);
		}
		else gEngfuncs.pTriAPI->Color4ub(Fonts_iColor_R,Fonts_iColor_G,Fonts_iColor_B,255);

		gEngfuncs.pTriAPI->Begin ( TRI_QUADS );
		{
			gEngfuncs.pTriAPI->TexCoord2f(0.0f, 1.0f); gEngfuncs.pTriAPI->Vertex3f(ch_x      , ch_y    ,  0);
			gEngfuncs.pTriAPI->TexCoord2f(1.0f, 1.0f); gEngfuncs.pTriAPI->Vertex3f(ch_x +  w, ch_y    ,  0);
			gEngfuncs.pTriAPI->TexCoord2f(1.0f, 0.0f); gEngfuncs.pTriAPI->Vertex3f(ch_x +  w, ch_y + h,  0);
			gEngfuncs.pTriAPI->TexCoord2f(0.0f, 0.0f); gEngfuncs.pTriAPI->Vertex3f(ch_x     , ch_y + h, 0);
		}
		gEngfuncs.pTriAPI->End();
		sx += pCharTex->m_adv_x;
		if(sx > x + maxW)
		{
			sx = x ; sy += maxH + iH;
		}
	}
	return sx;
}
Пример #5
0
int Fonts_GetLen(wchar_t* _strText)
{
	int sx = 0;
	size_t nLen = wcslen(_strText);
 
	for(int i = 0 ; i <(int)nLen ; i ++)
	{
		xCharTexture* pCharTex = Font_GetChar(_strText[i]);
		int w = pCharTex->m_Width;
		int ch_x = sx + pCharTex->m_delta_x;
		sx += pCharTex->m_adv_x;
	}
	return sx;
}
Пример #6
0
static int bmfont_gettextwidth ( const char *text, int count )
{
	int x = 0;
	int n;

	if ( cur_pFont == 0 )
		return 0;

	if ( count <= 0 )
		count = Font_GetTextLength ( text );

	for ( n = 0; n < count; )
	{
		int charId = Font_GetTextChar ( text, n, &n );
		SCharDescr *ch = Font_GetChar ( charId );
		int a;

		if ( ch == 0 )
			a = 0;
		else
		{
			if ( cur_pFont->bAutoKerning )
				a = ( ch->xAdv );
			else
				a = cur_pFont->fontsize;
		}

		x += ( a + cur_pFont->kerning );
		/*
		if( n < count )
			x += Font_AdjustForKerningPairs(charId, Font_GetTextChar(text,n,0));
			*/
	}

	return x;
}
Пример #7
0
int Fonts_GetHeight(wchar_t* _strText, int maxW ,int iH)
{
	int iHeight = 0;
	int sx = 0;
	size_t nLen = wcslen(_strText);
 
	for(int i = 0 ; i <(int)nLen ; i ++)
	{
		xCharTexture* pCharTex = Font_GetChar(_strText[i]);
		int w = pCharTex->m_Width;
		int ch_x = sx + pCharTex->m_delta_x;
		sx += pCharTex->m_adv_x;

		if(_strText[i] =='\n')
		{
			iHeight += (iWidthCheck + iH);			
		}	
		if(sx > maxW)
		{
			sx = 0 ; iHeight += iWidthCheck + iH;
		}
	}
	return iHeight;
}
Пример #8
0
SURFACE *bmpfont_makesurface (EGL_FONT* pFont, char *text )
{
	int w ;
	SURFACE *fontsurf ;
	SURFACE *surf ;
	int h;
	int bpp;
	int n;
	int len = 0;
	int count;
	int x;
	int a;

	cur_pFont = EGL_FONT_TO_BMFONT(pFont);

	w = bmfont_gettextwidth ( text, 0 );

	if ( w == 0 )
		return 0;

	fontsurf = cur_pFont->surfs[0];
	h = cur_pFont->fontHeight;
	bpp = fontsurf->bpp;
	surf = CREATE_SURFACE ( w, h, bpp );

	if ( surf == 0 )
		return 0;

	memset ( surf->pixels, 0, surf->pitch * surf->h );
	surf->pixtype = fontsurf->pixtype;

	if ( surf->bpp == 8 )
		surf->pal->colors[0] = fontsurf->pal->colors[0];

	len = 0;
	count = Font_GetTextLength ( text );
	x = 0;

	for ( n = 0; n < count; )
	{
		SCharDescr *ch ;
		int charId = Font_GetTextChar ( text, n, &n );
		ch = Font_GetChar ( charId );

		if ( ch == 0 )
		{
			//debugprintf ( "Unknown Character %d\r\n", charId );
			a = 0;
		}
		else
		{
			if ( ch->page < cur_pFont->pagecnt )
			{
				int dx, dy, sx, sy, sh, y;
				U8 *dest;
				U8 *src;
				fontsurf = cur_pFont->surfs[ch->page];

				//copy
				if ( cur_pFont->bAutoKerning )
					dx = x + ch->xOff;
				else
					dx = x + ( ( cur_pFont->fontsize - ch->xAdv + ch->xOff ) / 2 ) + ch->xOff;

				dy = ch->yOff;
				sx = ch->srcX;
				sy = ch->srcY;
				sh = ch->srcH;
				dest = ( ( U8 * ) surf->pixels ) + ( dx * ( bpp / 8 ) ) + ( surf->pitch * dy );
				src = ( ( U8 * ) fontsurf->pixels ) + ( sx * ( fontsurf->bpp / 8 ) ) + ( fontsurf->pitch * sy );

				for ( y = 0; y < sh; y++, dy++ )
				{
					memcpy ( dest, src, ch->srcW );
					dest += surf->pitch;
					src += fontsurf->pitch;
				}
			}

			if ( cur_pFont->bAutoKerning )
				a = ( ch->xAdv );
			else
				a = cur_pFont->fontsize;
		}

		x += a + cur_pFont->kerning;
		len += a + cur_pFont->kerning;
	}

	return surf;
}