mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
修改BUG代码,为一些数据添加有效性判断
现在, 图形输出功能在初始化失败后不会终止程序运行, 在其它地方做了数据有效性判断,以应对初始化失败的情况。
This commit is contained in:
+16
-12
@@ -128,8 +128,8 @@ static void DestroyTreeNode( void *arg )
|
||||
RBTree_Destroy( (LCUI_RBTree*)arg );
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加字体信息记录,并返回该字体的ID
|
||||
/**
|
||||
* 添加字体信息记录,并返回该字体的ID
|
||||
* @warning 该函数仅仅是将 font 参数的引用添加至记录中,为保证记录的有效性,
|
||||
* 传入的 font 参数必须是动态分配的。
|
||||
*/
|
||||
@@ -143,7 +143,7 @@ int LCUIFont_Add( LCUI_Font *font, const char *filepath )
|
||||
if( font->id >= fontlib.font_cache_num * FONT_CACHE_SIZE ) {
|
||||
LCUI_Font ***caches, **cache;
|
||||
fontlib.font_cache_num += 1;
|
||||
caches = (LCUI_Font***)realloc( fontlib.font_cache,
|
||||
caches = (LCUI_Font***)realloc( fontlib.font_cache,
|
||||
fontlib.font_cache_num * sizeof(LCUI_Font**) );
|
||||
if( caches == NULL ) {
|
||||
fontlib.font_cache_num -= 1;
|
||||
@@ -194,7 +194,7 @@ static LCUI_Font* LCUIFont_GetById( int id )
|
||||
if( id < 0 || id >= fontlib.font_cache_num * FONT_CACHE_SIZE ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return SelectFontCache(id);
|
||||
}
|
||||
|
||||
@@ -212,8 +212,8 @@ int LCUIFont_GetIdByPath( const char *filepath )
|
||||
return font->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字体的ID
|
||||
/**
|
||||
* 获取字体的ID
|
||||
* @param[in] family_name 字族名称
|
||||
* @param[in] style_name 样式名称,若设为 NULL,则默认获取 regular 样式或
|
||||
* 最后一个样式的字体
|
||||
@@ -356,6 +356,9 @@ int LCUIFont_GetBitmap( wchar_t ch, int font_id, int size,
|
||||
break;
|
||||
}
|
||||
if( font_id <= 0 ) {
|
||||
if( !fontlib.default_font ) {
|
||||
return -3;
|
||||
}
|
||||
font_id = fontlib.default_font->id;
|
||||
}
|
||||
ctx = SelectFont( ctx, font_id );
|
||||
@@ -398,7 +401,7 @@ int LCUIFont_LoadFile( const char *filepath )
|
||||
}
|
||||
font->engine = fontlib.engine;
|
||||
id = LCUIFont_Add( font, filepath );
|
||||
printf("[font] add family: %s, style name: %s, id: %d\n",
|
||||
printf("[font] add family: %s, style name: %s, id: %d\n",
|
||||
font->family_name, font->family_name, id);
|
||||
return id;
|
||||
}
|
||||
@@ -476,7 +479,7 @@ int FontBitmap_Print( LCUI_FontBitmap *fontbmp )
|
||||
}
|
||||
|
||||
static void FontBitmap_MixARGB( LCUI_Graph *graph, LCUI_Rect *write_rect,
|
||||
const LCUI_FontBitmap *bmp, LCUI_Color color,
|
||||
const LCUI_FontBitmap *bmp, LCUI_Color color,
|
||||
LCUI_Rect *read_rect )
|
||||
{
|
||||
int x, y;
|
||||
@@ -513,7 +516,7 @@ static void FontBitmap_MixARGB( LCUI_Graph *graph, LCUI_Rect *write_rect,
|
||||
}
|
||||
|
||||
static void FontBitmap_MixRGB( LCUI_Graph *graph, LCUI_Rect *write_rect,
|
||||
const LCUI_FontBitmap *bmp, LCUI_Color color,
|
||||
const LCUI_FontBitmap *bmp, LCUI_Color color,
|
||||
LCUI_Rect *read_rect )
|
||||
{
|
||||
int x, y;
|
||||
@@ -564,7 +567,7 @@ int FontBitmap_Mix( LCUI_Graph *graph, LCUI_Pos pos,
|
||||
graph = Graph_GetQuote( graph );
|
||||
if( graph->color_type == COLOR_TYPE_ARGB ) {
|
||||
FontBitmap_MixARGB( graph, &w_rect, bmp, color, &r_rect );
|
||||
} else {
|
||||
} else {
|
||||
FontBitmap_MixRGB( graph, &w_rect, bmp, color, &r_rect );
|
||||
}
|
||||
return 0;
|
||||
@@ -589,11 +592,12 @@ int FontBitmap_Load( LCUI_FontBitmap *buff, wchar_t ch,
|
||||
info = fontlib.incore_font;
|
||||
}
|
||||
}
|
||||
if( !info ) {
|
||||
return -1;
|
||||
}
|
||||
return info->engine->render( buff, ch, pixel_size, info );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef LCUI_BUILD_IN_WIN32
|
||||
#define MAX_FONTFILE_NUM 4
|
||||
#else
|
||||
|
||||
+16
-10
@@ -79,7 +79,7 @@ static struct {
|
||||
#define SPLIT_STYLE (1<<2)
|
||||
|
||||
int ParseStyleOption( const char *str )
|
||||
{
|
||||
{
|
||||
LCUI_RBTreeNode *node;
|
||||
node = RBTree_CustomSearch( &self.option_tree, str );
|
||||
if( !node ) {
|
||||
@@ -93,7 +93,7 @@ const char *GetStyleName( int key )
|
||||
return RBTree_GetData( &self.name_tree, key );
|
||||
}
|
||||
|
||||
static int SplitValues( const char *str, LCUI_Style *slist,
|
||||
static int SplitValues( const char *str, LCUI_Style *slist,
|
||||
int max_len, int mode )
|
||||
{
|
||||
int val, vi = 0, vj = 0;
|
||||
@@ -378,7 +378,7 @@ static int OnParsePadding( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
int value_count;
|
||||
LCUI_Style s[4];
|
||||
|
||||
|
||||
value_count = SplitValues( str, s, 4, SPLIT_NUMBER );
|
||||
switch( value_count ) {
|
||||
case 1:
|
||||
@@ -413,7 +413,7 @@ static int OnParseMargin( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
int value_count;
|
||||
LCUI_Style s[4];
|
||||
|
||||
|
||||
value_count = SplitValues( str, s, 4, SPLIT_NUMBER );
|
||||
switch( value_count ) {
|
||||
case 1:
|
||||
@@ -492,6 +492,7 @@ static KeyNameGroup style_name_map[] = {
|
||||
{ key_width, "width" },
|
||||
{ key_height, "height" },
|
||||
{ key_display, "display" },
|
||||
{ key_z_index, "z-index" },
|
||||
{ key_top, "top" },
|
||||
{ key_right, "right" },
|
||||
{ key_left, "left" },
|
||||
@@ -648,7 +649,7 @@ static int LCUICSS_LoadBlock( CSSParserContext ctx, const char *str )
|
||||
size_t size = 0;
|
||||
LCUI_Selector s;
|
||||
LinkedListNode *node;
|
||||
|
||||
|
||||
ctx->ptr = str;
|
||||
for( ; *ctx->ptr && size < ctx->buffer_size; ++ctx->ptr, ++size ) {
|
||||
switch( ctx->target ) {
|
||||
@@ -681,7 +682,7 @@ static int LCUICSS_LoadBlock( CSSParserContext ctx, const char *str )
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case ';':
|
||||
case ';':
|
||||
ctx->pos = 0;
|
||||
continue;
|
||||
case ':': break;
|
||||
@@ -747,7 +748,7 @@ proc_comment:
|
||||
switch( *(ctx->ptr + 1) ) {
|
||||
case '/': ctx->is_line_comment = TRUE; break;
|
||||
case '*': ctx->is_line_comment = FALSE; break;
|
||||
default:
|
||||
default:
|
||||
ctx->buffer[ctx->pos++] = *ctx->ptr;
|
||||
continue;
|
||||
}
|
||||
@@ -765,7 +766,7 @@ put_css:
|
||||
LinkedList_Clear( &ctx->selectors, OnDeleteSelector );
|
||||
DeleteStyleSheet( &ctx->css );
|
||||
continue;
|
||||
select_parser:
|
||||
select_parser:
|
||||
ctx->target = is_value;
|
||||
ctx->buffer[ctx->pos] = 0;
|
||||
ctx->pos = 0;
|
||||
@@ -800,7 +801,7 @@ int LCUICSS_LoadFile( const char *filepath )
|
||||
FILE *fp;
|
||||
char buff[512];
|
||||
CSSParserContext ctx;
|
||||
|
||||
|
||||
fp = fopen( filepath, "r" );
|
||||
if( !fp ) {
|
||||
return -1;
|
||||
@@ -886,7 +887,12 @@ void LCUICSS_Init(void)
|
||||
new_sp->key = sp->key;
|
||||
new_sp->parse = sp->parse;
|
||||
if( !sp->name && sp->key >= 0 ) {
|
||||
new_sp->name = strdup( GetStyleName(sp->key) );
|
||||
const char *name = GetStyleName(sp->key);
|
||||
if( !name ) {
|
||||
free( new_sp );
|
||||
continue;
|
||||
}
|
||||
new_sp->name = strdup( name );
|
||||
} else {
|
||||
new_sp->name = strdup( sp->name );
|
||||
}
|
||||
|
||||
+31
-16
@@ -171,7 +171,7 @@ static void LCUIDisplay_BindSurface( LCUI_Widget widget )
|
||||
Surface_SetCaptionW( p_sr->surface, widget->title );
|
||||
p_rect = &widget->box.graph;
|
||||
|
||||
if( widget->style->sheet[key_top].is_valid &&
|
||||
if( widget->style->sheet[key_top].is_valid &&
|
||||
widget->style->sheet[key_left].is_valid ) {
|
||||
Surface_Move( p_sr->surface, p_rect->x, p_rect->y );
|
||||
}
|
||||
@@ -225,8 +225,7 @@ static int LCUIDisplay_Windowed( void )
|
||||
break;
|
||||
}
|
||||
Widget_Show( root );
|
||||
Widget_Resize( root, display.info.getWidth(),
|
||||
display.info.getHeight() );
|
||||
Widget_Resize( root, LCUIDisplay_GetWidth(), LCUIDisplay_GetHeight() );
|
||||
display.mode = LDM_WINDOWED;
|
||||
return 0;
|
||||
}
|
||||
@@ -244,8 +243,7 @@ static int LCUIDisplay_FullScreen( void )
|
||||
return 0;
|
||||
}
|
||||
display.mode = LDM_FULLSCREEN;
|
||||
LCUIDisplay_SetSize( display.info.getWidth(),
|
||||
display.info.getHeight() );
|
||||
LCUIDisplay_SetSize( LCUIDisplay_GetWidth(), LCUIDisplay_GetHeight() );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -327,13 +325,13 @@ void LCUIDisplay_SetSize( int width, int height )
|
||||
/** 获取屏幕宽度 */
|
||||
int LCUIDisplay_GetWidth( void )
|
||||
{
|
||||
return display.info.getWidth();
|
||||
return display.info.getWidth ? display.info.getWidth() : 0;
|
||||
}
|
||||
|
||||
/** 获取屏幕高度 */
|
||||
int LCUIDisplay_GetHeight( void )
|
||||
{
|
||||
return display.info.getHeight();
|
||||
return display.info.getHeight ? display.info.getHeight() : 0;
|
||||
}
|
||||
|
||||
/** LCUI的图形显示处理线程 */
|
||||
@@ -442,17 +440,22 @@ static void Surface_OnInvalidRect( LCUI_Surface surface, LCUI_Rect *rect )
|
||||
|
||||
void Surface_Delete( LCUI_Surface surface )
|
||||
{
|
||||
display.methods->delete( surface );
|
||||
if( display.methods && display.methods->delete ) {
|
||||
display.methods->delete( surface );
|
||||
}
|
||||
}
|
||||
|
||||
LCUI_Surface Surface_New( void )
|
||||
{
|
||||
return display.methods->new();
|
||||
if( display.methods ) {
|
||||
return display.methods->new();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LCUI_BOOL Surface_IsReady( LCUI_Surface surface )
|
||||
{
|
||||
if( display.methods->isReady ) {
|
||||
if( display.methods && display.methods->isReady ) {
|
||||
return display.methods->isReady( surface );
|
||||
}
|
||||
return TRUE;
|
||||
@@ -460,7 +463,7 @@ LCUI_BOOL Surface_IsReady( LCUI_Surface surface )
|
||||
|
||||
void Surface_Move( LCUI_Surface surface, int x, int y )
|
||||
{
|
||||
if( display.methods->move ) {
|
||||
if( display.methods && display.methods->move ) {
|
||||
display.methods->move( surface, x, y );
|
||||
}
|
||||
}
|
||||
@@ -474,21 +477,21 @@ void Surface_Resize( LCUI_Surface surface, int w, int h )
|
||||
|
||||
void Surface_SetCaptionW( LCUI_Surface surface, const wchar_t *str )
|
||||
{
|
||||
if( display.methods->setCaptionW ) {
|
||||
if( display.methods && display.methods->setCaptionW ) {
|
||||
display.methods->setCaptionW( surface, str );
|
||||
}
|
||||
}
|
||||
|
||||
void Surface_Show( LCUI_Surface surface )
|
||||
{
|
||||
if( display.methods->show ) {
|
||||
if( display.methods && display.methods->show ) {
|
||||
display.methods->show( surface );
|
||||
}
|
||||
}
|
||||
|
||||
void Surface_Hide( LCUI_Surface surface )
|
||||
{
|
||||
if( display.methods->hide ) {
|
||||
if( display.methods && display.methods->hide ) {
|
||||
display.methods->hide( surface );
|
||||
}
|
||||
}
|
||||
@@ -496,7 +499,7 @@ void Surface_Hide( LCUI_Surface surface )
|
||||
/** 设置 Surface 的渲染模式 */
|
||||
void Surface_SetRenderMode( LCUI_Surface surface, int mode )
|
||||
{
|
||||
if( display.methods->setRenderMode ) {
|
||||
if( display.methods && display.methods->setRenderMode ) {
|
||||
display.methods->setRenderMode( surface, mode );
|
||||
}
|
||||
}
|
||||
@@ -504,7 +507,7 @@ void Surface_SetRenderMode( LCUI_Surface surface, int mode )
|
||||
/** 更新 surface,应用缓存的变更 */
|
||||
void Surface_Update( LCUI_Surface surface )
|
||||
{
|
||||
if( display.methods->update ) {
|
||||
if( display.methods && display.methods->update ) {
|
||||
display.methods->update( surface );
|
||||
}
|
||||
}
|
||||
@@ -517,6 +520,9 @@ void Surface_Update( LCUI_Surface surface )
|
||||
*/
|
||||
LCUI_PaintContext Surface_BeginPaint( LCUI_Surface surface, LCUI_Rect *rect )
|
||||
{
|
||||
if( !display.methods ) {
|
||||
return NULL;
|
||||
}
|
||||
return display.methods->beginPaint( surface, rect );
|
||||
}
|
||||
|
||||
@@ -527,12 +533,18 @@ LCUI_PaintContext Surface_BeginPaint( LCUI_Surface surface, LCUI_Rect *rect )
|
||||
*/
|
||||
void Surface_EndPaint( LCUI_Surface surface, LCUI_PaintContext paint_ctx )
|
||||
{
|
||||
if( !display.methods ) {
|
||||
return;
|
||||
}
|
||||
display.methods->endPaint( surface, paint_ctx );
|
||||
}
|
||||
|
||||
/** 将帧缓存中的数据呈现至Surface的窗口内 */
|
||||
void Surface_Present( LCUI_Surface surface )
|
||||
{
|
||||
if( !display.methods ) {
|
||||
return;
|
||||
}
|
||||
display.methods->present( surface );
|
||||
}
|
||||
|
||||
@@ -553,6 +565,9 @@ int LCUI_InitDisplay( void )
|
||||
#elif defined(LCUI_VIDEO_DRIVER_FRAMEBUFFER)
|
||||
display.methods = LCUIDisplay_InitLinuxFB( &display.info );
|
||||
#endif
|
||||
if( !display.methods ) {
|
||||
return -2;
|
||||
}
|
||||
display.methods->onInvalidRect = Surface_OnInvalidRect;
|
||||
display.methods->onEvent = Surface_OnEvent;
|
||||
display.fc_ctx = FrameControl_Create();
|
||||
|
||||
@@ -200,7 +200,7 @@ LCUI_PaintContext LinuxFB_BeginPaint( LCUI_Surface surface, LCUI_Rect *rect )
|
||||
Graph_Init( &paint->canvas );
|
||||
Graph_Create( &paint->canvas, rect->w, rect->h );
|
||||
paint->rect = *rect;
|
||||
_DEBUG_MSG("canvas: %p, rect: %d,%d,%d,%d\n",
|
||||
_DEBUG_MSG("canvas: %p, rect: %d,%d,%d,%d\n",
|
||||
&paint->canvas, rect->x, rect->y, rect->w, rect->h);
|
||||
return paint;
|
||||
}
|
||||
@@ -350,7 +350,7 @@ void LinuxFB_EndPaint( LCUI_Surface surface, LCUI_PaintContext paint_ctx )
|
||||
LCUI_Rect cut_rect;
|
||||
LCUI_Graph canvas;
|
||||
|
||||
LCUIRect_GetCutArea( linuxfb.width, linuxfb.height,
|
||||
LCUIRect_GetCutArea( linuxfb.width, linuxfb.height,
|
||||
paint_ctx->rect, &cut_rect );
|
||||
if( cut_rect.w <= 0 || cut_rect.h <= 0 ) {
|
||||
free( paint_ctx );
|
||||
@@ -438,7 +438,7 @@ LCUI_SurfaceMethods *LCUIDisplay_InitLinuxFB( LCUI_DisplayInfo *info )
|
||||
if( (void *)-1 == linuxfb.mem ) {
|
||||
printf("fail\n");
|
||||
perror(strerror(errno));
|
||||
exit(-1);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("success\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user