Exemple #1
0
static void 
Destroy_CharData(LCUI_CharData *data)
{ 
	FontBMP_Free( &data->bitmap );
	free( data->data );
	//if( data->using_quote == IS_FALSE ) {
		//free( data->data );
	//}
}
Exemple #2
0
/** 创建字体位图 */
LCUI_API int FontBMP_Create( LCUI_FontBMP *bitmap, int width, int rows )
{
	size_t size;
	if(width < 0 || rows < 0) {
		FontBMP_Free(bitmap);
		return -1;
	}
	if(FontBMP_IsValid(bitmap)) {
		FontBMP_Free(bitmap);
	}
	bitmap->width = width;
	bitmap->rows = rows;
	size = width*rows*sizeof(uchar_t);
	bitmap->buffer = (uchar_t*)malloc( size );
	if( bitmap->buffer == NULL ) {
		return -2;
	}
	return 0;
}
Exemple #3
0
void
TextLayer_Merge( LCUI_TextLayer *des, LCUI_TextLayer *src )
/* 合并两个文本图层 */
{
	LCUI_Rect area, tmp_area;
	uint_t i, j, old_size, new_size;
	LCUI_CharData *src_ptr, *des_ptr;
	Text_RowData *src_row_ptr, *des_row_ptr;
	uint_t old_rows, new_rows, max_rows, min_rows;
	int32_t src_len, des_len, max_len, min_len;
	
	old_rows = Queue_Get_Total( &des->rows_data );
	new_rows = Queue_Get_Total( &src->rows_data );
	DEBUG_MSG("old_rows: %d, new_rows: %d\n", old_rows, new_rows);
	
	if(old_rows > new_rows) {
		max_rows = old_rows;
		min_rows = new_rows;
	} else {
		max_rows = new_rows;
		min_rows = old_rows;
	} 
	for(area.y=0,i=0; i<min_rows; ++i) {
		area.x = 0;
		src_row_ptr = Queue_Get( &src->rows_data, i );
		des_row_ptr = Queue_Get( &des->rows_data, i );
		src_len = Queue_Get_Total( &src_row_ptr->string );
		des_len = Queue_Get_Total( &des_row_ptr->string );
		if(src_len > des_len) {
			max_len = src_len;
			min_len = des_len;
		} else {
			max_len = des_len;
			min_len = src_len;
		}
		for(j=0; j<min_len; ++j) {
			src_ptr = Queue_Get( &src_row_ptr->string, j );
			des_ptr = Queue_Get( &des_row_ptr->string, j );
			area.x += des_ptr->bitmap.left;
			/* 获取字体大小 */
			if(src_ptr->data == NULL) {
				new_size = 12;
			} else {
				if(src_ptr->data->pixel_size > 0) {
					new_size = src_ptr->data->pixel_size;
				} else {
					new_size = 12;
				}
			}
			if(des_ptr->data == NULL) {
				old_size = 12;
			} else {
				if(des_ptr->data->pixel_size > 0) {
					old_size = des_ptr->data->pixel_size;
				} else {
					old_size = 12;
				}
			}
			if(src_ptr->char_code == des_ptr->char_code) {
				/* 转移字体位图数据 */ 
				src_ptr->bitmap = des_ptr->bitmap; 
				/* 指针赋值为NULL,避免被释放 */
				des_ptr->bitmap.buffer = NULL; 
				src_ptr->need_update = FALSE;
			} else {
				src_ptr->need_update = TRUE; 
			}
			if(new_size != old_size) {
				src_ptr->need_update = TRUE; 
			}
			//文本样式也要对比
			//....
			
			
			if(src_ptr->need_update) {
				tmp_area.x = area.x;
				tmp_area.y = area.y + old_size+2 - des_ptr->bitmap.top;
				tmp_area.width = des_ptr->bitmap.width;
				tmp_area.height = des_ptr->bitmap.rows; 
				RectQueue_Add( &des->clear_area, tmp_area ); 
				area.x += des_ptr->bitmap.width;
				FontBMP_Free(&des_ptr->bitmap); 
			} else {
				area.x += des_ptr->bitmap.width;
			}
		}
		if( src_len < max_len ) {
			/* 如果这一行删减了几个字,则记录区域 */
			for(j=min_len; j<max_len; ++j) {
				des_ptr = Queue_Get( &des_row_ptr->string, j );
				if(des_ptr->data == NULL) {
					old_size = 12;
				} else {
					if(des_ptr->data->pixel_size > 0) {
						old_size = des_ptr->data->pixel_size;
					} else {
						old_size = 12;
					}
				}
				area.x += des_ptr->bitmap.left;
				area.width = area.height = old_size+2;
				RectQueue_Add( &des->clear_area, area );
				area.x += des_ptr->bitmap.width;
			}
		} 
		area.y += des_row_ptr->max_size.h; 
	}
	area.x = 0; 
	if(new_rows < max_rows) {/* 如果是删减几行文本,则需要记录被删文本的区域 */ 
		for(i=min_rows; i<max_rows; ++i) {
			des_row_ptr = Queue_Get( &des->rows_data, min_rows );
			area.width = des_row_ptr->max_size.w;
			area.height = des_row_ptr->max_size.h;
			RectQueue_Add( &des->clear_area, area ); 
		}
	} 
	/* 转移数据 */
	Destroy_Queue( &des->text_source_data );
	des->text_source_data = src->text_source_data; 
	Destroy_Queue( &des->rows_data );
	des->rows_data = src->rows_data;
}
Exemple #4
0
void
TextLayer_Text_Set_Default_Style( LCUI_TextLayer *layer, LCUI_TextStyle style )
/* 设定默认的文本样式,需要调用TextLayer_Draw函数进行文本位图更新 */
{
	LCUI_Rect area, tmp_area;
	uint_t i, j;
	LCUI_CharData *char_ptr;
	LCUI_TextStyle *old_style;
	Text_RowData *row_ptr;
	int32_t rows, len, old_size;
	
	layer->default_data = style; 
	rows = Queue_Get_Total( &layer->rows_data );
	for(area.y=0,i=0; i<rows; ++i) {
		area.x = 0;
		row_ptr = Queue_Get( &layer->rows_data, i ); 
		len = Queue_Get_Total( &row_ptr->string );
		for(j=0; j<len; ++j) {
			char_ptr = Queue_Get( &row_ptr->string, j ); 
			area.x += char_ptr->bitmap.left; 
			old_style = char_ptr->data;
			if(old_style == NULL) {
				old_size = 12;
				char_ptr->need_update = TRUE; 
			} else {
				if(old_style->pixel_size > 0) {
					old_size = old_style->pixel_size;
				} else {
					old_size = 12;
				}
			}
			/* 若有属性是缺省的 */
			if(!old_style->_pixel_size) {
				old_style->pixel_size = style.pixel_size;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_style) {
				old_style->style = style.style;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_family) {
				strcpy(old_style->family, style.family);
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_weight) {
				old_style->weight = style.weight;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_back_color) {
				old_style->back_color = style.back_color;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_fore_color) {
				old_style->fore_color = style.fore_color;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_decoration) {
				old_style->decoration = style.decoration;
				char_ptr->need_update = TRUE; 
			} 
			if(char_ptr->need_update) {
				tmp_area.x = area.x;
				tmp_area.y = area.y + old_size+2 - char_ptr->bitmap.top;
				tmp_area.width = char_ptr->bitmap.width;
				tmp_area.height = char_ptr->bitmap.rows; 
				/* 记录之前字体位图所在区域,等待刷新 */
				RectQueue_Add( &layer->clear_area, tmp_area ); 
				area.x += char_ptr->bitmap.width;
				/* 重新获取字体位图 */
				FontBMP_Free(&char_ptr->bitmap); 
				TextLayer_Get_Char_BMP ( &layer->default_data, char_ptr );
			} else {
				area.x += char_ptr->bitmap.width;
			}
		}
		area.y += row_ptr->max_size.h; 
	} 
}
Exemple #5
0
static void FontLIB_DestroyFontBitmap( void *arg )
{
	FontBMP_Free( (LCUI_FontBMP*)arg );
}
Exemple #6
0
void
TextLayer_Text_Set_Default_Style( LCUI_TextLayer *layer, LCUI_TextStyle style )
/* 设定默认的文本样式,需要调用TextLayer_Draw函数进行文本位图更新 */
{
	LCUI_Pos pos;
	LCUI_CharData *char_ptr;
	LCUI_TextStyle *old_style;
	Text_RowData *row_ptr;
	int rows, len, i, j;
	
	layer->default_data = style; 
	rows = Queue_Get_Total( &layer->rows_data );
	for(pos.y=0,i=0; i<rows; ++i) {
		row_ptr = Queue_Get( &layer->rows_data, i ); 
		len = Queue_Get_Total( &row_ptr->string );
		for(pos.x=0,j=0; j<len; ++j) {
			char_ptr = Queue_Get( &row_ptr->string, j );
			if( !char_ptr ) {
				continue;
			}
			old_style = char_ptr->data;
			if( !old_style ) {
				char_ptr->need_update = TRUE; 
				goto skip_style_cmp;
			}
			/* 若有属性是缺省的 */
			if(!old_style->_pixel_size) {
				old_style->pixel_size = style.pixel_size;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_style) {
				old_style->style = style.style;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_family) {
				strcpy(old_style->family, style.family);
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_weight) {
				old_style->weight = style.weight;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_back_color) {
				old_style->back_color = style.back_color;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_fore_color) {
				old_style->fore_color = style.fore_color;
				char_ptr->need_update = TRUE; 
			}
			if(!old_style->_decoration) {
				old_style->decoration = style.decoration;
				char_ptr->need_update = TRUE; 
			} 
skip_style_cmp:;
			if(char_ptr->need_update) {
				TextLayer_Clear( layer, pos, row_ptr->max_size.h, char_ptr );
				pos.x += char_ptr->bitmap.advance.x;
				/* 重新获取字体位图 */
				FontBMP_Free(&char_ptr->bitmap); 
				TextLayer_Get_Char_BMP ( &layer->default_data, char_ptr );
			} else {
				pos.x += char_ptr->bitmap.advance.x;
			}
		}
		pos.y += row_ptr->max_size.h; 
		TextLayer_Update_RowSize( layer, i );
	}
}