diff --git a/include/LCUI/LCUI_Font.h b/include/LCUI/LCUI_Font.h index 0920e232..5ef90bf0 100755 --- a/include/LCUI/LCUI_Font.h +++ b/include/LCUI/LCUI_Font.h @@ -42,13 +42,13 @@ #define __LCUI_FONT_H__ #include - LCUI_BEGIN_HEADER #include LC_CHARSET_H #include LC_FONTBMP_H #include LC_TEXTSTYLE_H #include LC_TEXTLAYER_H +#include LC_FONTLIB_H LCUI_END_HEADER diff --git a/include/LCUI/font/Makefile.am b/include/LCUI/font/Makefile.am index 18a9dad7..3e4c284d 100644 --- a/include/LCUI/font/Makefile.am +++ b/include/LCUI/font/Makefile.am @@ -1,5 +1,5 @@ AUTOMAKE_OPTIONS=foreign # Headers to install -pkginclude_HEADERS = textlayer.h textstyle.h bitmapfont.h charset.h +pkginclude_HEADERS = fontlibrary.h textlayer.h textstyle.h bitmapfont.h charset.h pkgincludedir=$(prefix)/include/LCUI/font diff --git a/include/LCUI/font/Makefile.in b/include/LCUI/font/Makefile.in index 6e079930..1a5f75ca 100644 --- a/include/LCUI/font/Makefile.in +++ b/include/LCUI/font/Makefile.in @@ -207,7 +207,7 @@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = foreign # Headers to install -pkginclude_HEADERS = textlayer.h textstyle.h bitmapfont.h charset.h +pkginclude_HEADERS = fontlibrary.h textlayer.h textstyle.h bitmapfont.h charset.h all: all-am .SUFFIXES: diff --git a/include/LCUI/font/fontlibrary.h b/include/LCUI/font/fontlibrary.h new file mode 100644 index 00000000..eb20769b --- /dev/null +++ b/include/LCUI/font/fontlibrary.h @@ -0,0 +1,34 @@ +#ifndef __LCUI_FONT_LIBRARY_H__ +#define __LCUI_FONT_LIBRARY_H__ + +LCUI_BEGIN_HEADER + +void FontLIB_DestroyAll( void ); + +/* 初始化字体数据库 */ +void FontLIB_Init( void ); + +/* 获取字体的风格ID */ +int FontLIB_GetStyleID( const char *style_name ); + +/* 获取字体的字族ID */ +int FontLIB_GetFamliyID( const char *famliy_name ); + +/* + * 添加一个字体位图数据至数据库中 + * 注意:调用此函数后,作为参数fontbmp_buff的变量,不能被free掉,否则,数据库中记录 + * 的此数据会无效 + * */ +LCUI_FontBMP * +FontLIB_Add( wchar_t char_code, int famliy_id, + int style_id, int pixel_size, + LCUI_FontBMP *fontbmp_buff ); + +/* 获取字体位图数据 */ +LCUI_FontBMP * +FontLIB_GetFontBMP( wchar_t char_code, int famliy_id, + int style_id, int pixel_size ); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI_Build.h b/include/LCUI_Build.h index 6490217c..6ca6dfa7 100644 --- a/include/LCUI_Build.h +++ b/include/LCUI_Build.h @@ -67,6 +67,7 @@ #define LC_MISC_H #define LC_FONT_H +#define LC_FONTLIB_H #define LC_GRAPH_H #define LC_GRAPH_HPP #define LC_DRAW_H diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index 3f5527e2..73a54d44 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -39,45 +39,62 @@ static LCUI_Queue famliy_table, style_table; static LCUI_Queue font_database; /* 初始化字体的字族信息表 */ -void FontLIB_FamliyTableInit( void ) +static void FontLIB_FamliyTableInit( void ) { Queue_Init( &famliy_table, sizeof(LCUI_FontFamliy), NULL ); } /* 初始化字体的样式信息表 */ -void FontLIB_StyleTableInit( void ) +static void FontLIB_StyleTableInit( void ) { Queue_Init( &style_table, sizeof(LCUI_FontStyle), NULL ); } -void FontLIB_DestroyBMP( LCUI_FontBMPItem *bmp ) +static void FontLIB_DestroyBMP( LCUI_FontBMPItem *bmp ) { - + if( bmp->bitmap ) { + free( bmp->bitmap ); + } } -void FontLIB_DestroyStyle( LCUI_FontStyleItem *style ) +static void FontLIB_DestroyStyle( LCUI_FontStyleItem *style ) { - + Destroy_Queue( &style->font_bmp ); } -void FontLIB_DestroyFamliy( LCUI_FontFamliyItem *famliy ) +static void FontLIB_DestroyFamliy( LCUI_FontFamliyItem *famliy ) { - + Destroy_Queue( &famliy->font_style ); } -void FontLIB_Destroy( LCUI_FontDataItem *font ) +static void FontLIB_Destroy( LCUI_FontDataItem *font ) { - + Destroy_Queue( &font->font_famliy ); } -void FontLIB_FamliyInit( LCUI_FontFamliyItem *item ) +void FontLIB_DestroyAll( void ) +{ + if( !database_init ) { + return; + } + Destroy_Queue( &font_database ); +} + +static void FontLIB_StyleInit( LCUI_FontStyleItem *item ) +{ + Queue_Init( &item->font_bmp, + sizeof(LCUI_FontBMPItem), + FontLIB_DestroyBMP ); +} + +static void FontLIB_FamliyInit( LCUI_FontFamliyItem *item ) { Queue_Init( &item->font_style, sizeof(LCUI_FontStyleItem), FontLIB_DestroyStyle ); } -void FontLIB_DataInit( LCUI_FontDataItem *item ) +static void FontLIB_DataInit( LCUI_FontDataItem *item ) { Queue_Init( &item->font_famliy, sizeof(LCUI_FontFamliyItem), @@ -98,41 +115,6 @@ void FontLIB_Init( void ) FontLIB_StyleTableInit(); } -LCUI_FontBMPItem * -FontLIB_GetBMPItem( LCUI_FontStyleItem *item, int pixel_size ) -{ - return NULL; -} - -LCUI_FontStyleItem * -FontLIB_GetStyleItemByID( LCUI_FontFamliyItem *item, int style_id ) -{ - return NULL; -} - -LCUI_FontStyleItem * -FontLIB_GetStyleItem( LCUI_FontFamliyItem *item, const char *style_name ) -{ - return NULL; -} - -LCUI_FontFamliyItem * -FontLIB_GetFamliyItemByID( LCUI_FontDataItem *item, int famliy_id ) -{ - return NULL; -} - -LCUI_FontFamliyItem * -FontLIB_GetFamliyItem( LCUI_FontDataItem *item, const char *famliy_name ) -{ - return NULL; -} - -LCUI_FontDataItem * -FontLIB_GetDataItem( wchar_t char_code ) -{ - return NULL; -} /* 获取字体的风格ID */ int FontLIB_GetStyleID( const char *style_name ) @@ -192,13 +174,156 @@ int FontLIB_GetFamliyID( const char *famliy_name ) return item->famliy_id; } -/* 添加一个字体位图数据至数据库中 */ + +static LCUI_FontBMPItem * +FontLIB_GetBMPItem( LCUI_FontStyleItem *style_item, int pixel_size ) +{ + int i, n; + LCUI_FontBMPItem *item; + + n = Queue_Get_Total( &style_item->font_bmp ); + for( i=0; ifont_bmp, i ); + if( !item ) { + continue; + } + if( item->pixel_size == pixel_size ) { + return item; + } + } + return NULL; +} + +static LCUI_FontStyleItem * +FontLIB_GetStyleItemByID( LCUI_FontFamliyItem *famliy_item, int style_id ) +{ + int i, n; + LCUI_FontStyleItem *item; + + n = Queue_Get_Total( &famliy_item->font_style); + for( i=0; ifont_style, i ); + if( !item ) { + continue; + } + if( item->style_id == style_id ) { + return item; + } + } + return NULL; +} + +static LCUI_FontFamliyItem * +FontLIB_GetFamliyItemByID( LCUI_FontDataItem *data_item, int famliy_id ) +{ + int i, n; + LCUI_FontFamliyItem *item; + + n = Queue_Get_Total( &data_item->font_famliy ); + for( i=0; ifont_famliy, i ); + if( !item ) { + continue; + } + if( item->famliy_id == famliy_id ) { + return item; + } + } + return NULL; +} + +static LCUI_FontDataItem * +FontLIB_GetDataItem( wchar_t char_code ) +{ + int i, n; + LCUI_FontDataItem *item; + + n = Queue_Get_Total( &font_database ); + for( i=0; ichar_code == char_code ) { + return item; + } + } + return NULL; +} + +/* + * 添加一个字体位图数据至数据库中 + * 注意:调用此函数后,作为参数fontbmp_buff的变量,不能被free掉,否则,数据库中记录 + * 的此数据会无效 + * */ LCUI_FontBMP * FontLIB_Add( wchar_t char_code, int famliy_id, int style_id, int pixel_size, - LCUI_FontBMP *font_bmp ) + LCUI_FontBMP *fontbmp_buff ) { - return NULL; + LCUI_FontDataItem *font; + LCUI_FontFamliyItem *famliy; + LCUI_FontStyleItem *style; + LCUI_FontBMPItem *bmp; + + if( !database_init ) { + return NULL; + } + /* 获取字体数据句柄,如果获取失败,则新增 */ + font = FontLIB_GetDataItem( char_code ); + if( !font ) { + font = malloc( sizeof(LCUI_FontDataItem) ); + if( !font ) { + return NULL; + } + FontLIB_DataInit( font ); + Queue_Add_Pointer( &font_database, font ); + } + + /* 获取字体字族句柄,如果获取失败,则新增 */ + famliy = FontLIB_GetFamliyItemByID( font, famliy_id ); + if( !famliy ) { + famliy = malloc( sizeof(LCUI_FontFamliyItem) ); + if( !famliy ) { + return NULL; + } + FontLIB_FamliyInit( famliy ); + Queue_Add_Pointer( &font->font_famliy, famliy ); + } + + /* 获取字体风格句柄,如果获取失败,则新增 */ + style = FontLIB_GetStyleItemByID( famliy, style_id ); + if( !style ) { + style = malloc( sizeof(LCUI_FontStyleItem) ); + if( !style ) { + return NULL; + } + FontLIB_StyleInit( style ); + Queue_Add_Pointer( &famliy->font_style, style ); + } + + /* 获取字体位图句柄,如果获取失败,则新增 */ + bmp = FontLIB_GetBMPItem( style, pixel_size ); + if( !bmp ) { + bmp = malloc( sizeof(LCUI_FontBMPItem) ); + if( !bmp ) { + return NULL; + } + bmp->pixel_size = pixel_size; + bmp->bitmap = NULL; + Queue_Add_Pointer( &style->font_bmp, bmp ); + } + + /* 如果该指针为NULL,那么就申请一块空间 */ + if( NULL == bmp->bitmap ) { + bmp->bitmap = malloc( sizeof(LCUI_FontBMP) ); + if( !bmp->bitmap ) { + return NULL; + } + } + /* 拷贝数据至该空间内 */ + memcpy( bmp->bitmap, fontbmp_buff, sizeof(LCUI_FontBMP) ); + return bmp->bitmap; } /* 获取字体位图数据 */ @@ -206,5 +331,30 @@ LCUI_FontBMP * FontLIB_GetFontBMP( wchar_t char_code, int famliy_id, int style_id, int pixel_size ) { - return NULL; + LCUI_FontDataItem *font; + LCUI_FontFamliyItem *famliy; + LCUI_FontStyleItem *style; + LCUI_FontBMPItem *bmp; + + if( !database_init ) { + return NULL; + } + + font = FontLIB_GetDataItem( char_code ); + if( !font ) { + return NULL; + } + famliy = FontLIB_GetFamliyItemByID( font, famliy_id ); + if( !famliy ) { + return NULL; + } + style = FontLIB_GetStyleItemByID( famliy, style_id ); + if( !style ) { + return NULL; + } + bmp = FontLIB_GetBMPItem( style, pixel_size ); + if( !bmp ) { + return NULL; + } + return bmp->bitmap; }