Ejemplo n.º 1
0
static int FreeType_Render( LCUI_FontBitmap *bmp, wchar_t ch,
			    int pixel_size, LCUI_Font *font )
{
	int ret = 0;
	size_t size;
	FT_UInt index;
	LCUI_BOOL has_space = FALSE;
	FT_Face ft_face = (FT_Face)font->data;

	/* 设定字体尺寸 */
	FT_Set_Pixel_Sizes( ft_face, 0, pixel_size );
	/* 如果是空格 */
	if( ch == ' ' ) {
		ch = 'a';
		has_space = TRUE;
	}
	index = FT_Get_Char_Index( ft_face, ch );
	if( index == 0 ) {
		ret = -1;
	}
	/* 载入该字的字形数据 */
	if( FT_Load_Glyph( ft_face, index, LCUI_FONT_LOAD_FALGS ) != 0 ) {
		return -2;
	}
	size = Convert_FTGlyph( bmp, ft_face->glyph, LCUI_FONT_RENDER_MODE );
	/* 如果是空格则将位图内容清空 */
	if( has_space ) {
		memset( bmp->buffer, 0, size );
	}
	return ret;
}
Ejemplo n.º 2
0
/** 载入字体位图 */
LCUI_API int FontBMP_Load( LCUI_FontBMP *buff, int font_id, 
				wchar_t ch, int pixel_size )
{
#ifdef LCUI_FONT_ENGINE_FREETYPE
	size_t size;
	LCUI_BOOL have_space = FALSE;

	FT_Face face;
	int error;

	if( font_id > 0 ) {
		face = FontLIB_GetFontFace( font_id );
		if( !face ) {
			GetDefaultFontBMP( ch, buff );
			return -1;
		}
	} else {
		GetDefaultFontBMP( ch, buff );
		return -1;
	}

	/* 设定字体尺寸 */
	FT_Set_Pixel_Sizes( face, 0, pixel_size );
	/* 如果是空格 */
	if( ch == ' ' ) {
		ch = 'a';
		have_space = TRUE;
	}
	/* 这个函数只是简单地调用FT_Get_Char_Index和FT_Load_Glyph */
	error = FT_Load_Char( face, ch, LCUI_FONT_LOAD_FALGS );
	if(error) {
		return error;
	}
	size = Convert_FTGlyph( buff, face->glyph, LCUI_FONT_RENDER_MODE );
	/* 如果是空格则将位图内容清空 */
	if( have_space ) {
		memset( buff->buffer, 0, size );
	}
	return 0;
#else
	GetDefaultFontBMP( ch, buff );
	return -1;
#endif
}