示例#1
0
FontLIB_LoadFontFile( const char *filepath )
{
	int id;
#ifdef LCUI_FONT_ENGINE_FREETYPE
	FT_Face face;
	int error_code;
#endif
	if( !filepath ) {
		return -1;
	}
	/* 如果有同一文件路径的字族信息 */
	id = FontLIB_FindInfoByFilePath( filepath );
	if( id >= 0 ) {
		return -1;
	}
	
#ifdef LCUI_FONT_ENGINE_FREETYPE
	error_code = FT_New_Face( library, filepath , 0 , &face );
	if( error_code != 0 ) {
		FT_Done_FreeType( library );
		printf("%s: ", __FUNCTION__);
		if ( error_code == FT_Err_Unknown_File_Format ) {
			printf( "%s", FT_UNKNOWN_FILE_FORMAT );
		} else {
			printf("%s", FT_OPEN_FILE_ERROR);
		}
		perror( filepath );
		return -1;
	}
	/* 打印字体信息 */
	printf(	"=============== font info ==============\n" 
		"family name: %s\n"
		"style name : %s\n"
		"========================================\n" ,
		face->family_name, face->style_name );

	/* 设定为UNICODE,默认的也是 */
	FT_Select_Charmap( face, FT_ENCODING_UNICODE );
	/* 记录字体信息至数据库中 */
	id = FontLIB_AddFontInfo( face->family_name, face->style_name, filepath, face );
#else
	printf("%s: %s\n", __FUNCTION__, "warning: not font engine support!");
#endif
	return id;
}
示例#2
0
/** 载入字体值数据库中 */
LCUI_API int FontLIB_LoadFontFile( const char *filepath )
{
	int id;
#ifdef LCUI_FONT_ENGINE_FREETYPE
	FT_Face face;
	int error_code;
#endif
	if( !filepath ) {
		return -1;
	}
	/* 如果有同一文件路径的字族信息 */
	id = FontLIB_FindInfoByFilePath( filepath );
	if( id >= 0 ) {
		return id;
	}

#ifdef LCUI_FONT_ENGINE_FREETYPE
	error_code = FT_New_Face( fontlib.library, filepath, 0, &face );
	if( error_code != 0 ) {
		_DEBUG_MSG( "%s: open error\n", filepath );
		if ( error_code == FT_Err_Unknown_File_Format ) {
			// ...
		} else {
			// ...
		}
		return -2;
	}
	/* 打印字体信息 */
	printf( "=============== font info ==============\n"
		"family name: %s\n"
		"style name : %s\n"
		"========================================\n" ,
		face->family_name, face->style_name );

	/* 设定为UNICODE,默认的也是 */
	FT_Select_Charmap( face, FT_ENCODING_UNICODE );
	/* 记录字体信息至数据库中 */
	id = FontLIB_AddFontInfo( face->family_name, face->style_name, filepath, face );
#else
	_DEBUG_MSG("warning: not font engine support!");
#endif
	return id;
}