Пример #1
0
int 
TextLayer_Text_Add( LCUI_TextLayer *layer, char *new_text )
/* 在光标处添加文本,如有选中文本,将被删除 */
{
	uint_t i, rows;
	TextLayer_Text_Process( layer, new_text );
	TextLayer_Text_GenerateBMP( layer );
	/* 更新每一行文本位图的尺寸 */
	rows = Queue_Get_Total( &layer->rows_data );
	for(i=0; i<rows; ++i) {
		TextLayer_Update_RowSize( layer, i );
	}
	return 0;
}
Пример #2
0
void
TextLayer_Text_GenerateBMP( LCUI_TextLayer *layer )
/* 为文本图层中的文本生成位图,已存在位图的文字将不重新生成 */
{
	BOOL refresh = FALSE;
	LCUI_Pos pos;
	int i, j, len, rows;
	Text_RowData *row_ptr;
	LCUI_CharData *char_ptr;
	
	DEBUG_MSG1("enter\n");
	DEBUG_MSG1("thread: %lu\n", thread_self());
	rows = Queue_Get_Total( &layer->rows_data );
	for( pos.y=0,j=0; j<rows; ++j ) {
		row_ptr = Queue_Get( &layer->rows_data, j );
		len = Queue_Get_Total( &row_ptr->string );
		DEBUG_MSG1("row %d, len: %d\n", j, len);
		for( pos.x=0,i=0; i<len; ++i) {
			char_ptr = Queue_Get( &row_ptr->string, i );
			DEBUG_MSG1("generate FontBMP, get char_ptr: %p, char: %c\n", 
					char_ptr, char_ptr->char_code );
			if( !char_ptr || !char_ptr->display ) {
				DEBUG_MSG1("no display\n");
				continue;
			}
			if( FontBMP_Valid( &char_ptr->bitmap ) ) {
				DEBUG_MSG1("have FontBMP\n");
				if( !refresh ) {
					pos.x += char_ptr->bitmap.advance.x;
					continue;
				}
			} else {
				refresh = TRUE;
				DEBUG_MSG1( "generate FontBMP, char code: %d\n", char_ptr->char_code );
				TextLayer_Get_Char_BMP ( &layer->default_data, char_ptr );
			}
			DEBUG_MSG1( "char_data->bitmap.advance.x: %d\n", char_ptr->bitmap.advance.x );
			TextLayer_Clear( layer, pos, row_ptr->max_size.h, char_ptr );
			char_ptr->need_update = TRUE;
			pos.x += char_ptr->bitmap.advance.x;
		}
		refresh = FALSE;
		/* 更新当前行的尺寸 */
		TextLayer_Update_RowSize( layer, j );
		DEBUG_MSG1("row size: %d,%d\n", row_ptr->max_size.w, row_ptr->max_size.h);
		pos.y += row_ptr->max_size.h;
	}
	DEBUG_MSG1("quit\n");
}
Пример #3
0
int
TextLayer_Text( LCUI_TextLayer *layer, char *new_text )
/* 设定整个文本图层中需显示的文本,原有选中文本被删除 */
{
	DEBUG_MSG("enter\n"); 
	uint_t i, rows;
	LCUI_TextLayer new_layer;

	TextLayer_Init( &new_layer );
	TextLayer_Text_Set_Default_Style( &new_layer, layer->default_data);
	TextLayer_Using_StyleTags( &new_layer, layer->using_style_tags );
	TextLayer_Text_Process( &new_layer, new_text );
	/* 合并两个文本图层,记录不同字所在区域,等待处理刷新 */
	TextLayer_Merge( layer, &new_layer ); 
	TextLayer_Text_GenerateBMP( layer ); 
	/* 更新每一行文本位图的尺寸 */
	rows = Queue_Get_Total( &layer->rows_data );
	for(i=0; i<rows; ++i) {
		TextLayer_Update_RowSize( layer, i );
	}
	Destroy_TextLayer( &new_layer );  
	DEBUG_MSG("quit\n");
	return 0;
}
Пример #4
0
TextLayer_Text_SetDefaultStyle( 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_GetTotal( &layer->rows_data );
	for(pos.y=0,i=0; i<rows; ++i) {
		row_ptr = Queue_Get( &layer->rows_data, i ); 
		len = Queue_GetTotal( &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) {
				old_style->font_id = style.font_id;
				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;
				TextLayer_GetCharBMP ( &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 );
	}
}
Пример #5
0
static int 
_TextLayer_Text_Delete ( LCUI_TextLayer *layer, LCUI_Pos start_pos, int len )
/* 以start_pos为起点,删除n个文字 */
{
	LCUI_BOOL refresh = TRUE;
	LCUI_CharData *char_ptr;
	LCUI_Pos tmp_pos, pixel_pos;
	int left_or_right, rows, cols;
	Text_RowData *row_ptr, *tmp_row;
	
	if( start_pos.x < 0 ) {
		len += start_pos.x;
		start_pos.x = 0;
	}
	if( start_pos.y < 0 ) {
		start_pos.y = 0;
	}
	if( len <= 0 ) {
		return -1;
	}
	/* 确定起点位置的XY轴坐标 */
	pixel_pos = TextLayer_Char_GetPixelPos( layer, start_pos );
	
	rows = Queue_GetTotal( &layer->rows_data );
	row_ptr = Queue_Get( &layer->rows_data, start_pos.y );
	if( !row_ptr ) {
		return -1;
	}
	cols = Queue_GetTotal( &row_ptr->string );
	
	/* 根据光标所在位置,确定遍历方向 */
	if( layer->current_des_pos.y > start_pos.y 
	 || (layer->current_des_pos.y == start_pos.y 
	 && layer->current_des_pos.x > start_pos.x)) {
		left_or_right = 0;
	}
	else {
		left_or_right = 1;
	}
	
	/* 如果需删除的字符只在当前行 */
	if( start_pos.x + len <= cols ) {
		/* 标记后面的文字位图需要刷新 */
		TextLayer_CharLater_Refresh( layer, start_pos );
	}
	for( ; start_pos.x<=cols && len>0; --len ) {
		/* 如果到了行尾 */
		if( start_pos.x == cols ) {
			/* 如果当前行是最后一行 */
			if( start_pos.y >= rows-1 ) {
				break;
			}
			if( refresh ) {
				tmp_pos.x = 0;
				tmp_pos.y=start_pos.y+1;
				/* 刷新该行后面所有行的字符 */
				for( ; tmp_pos.y<rows; ++tmp_pos.y ) {
					TextLayer_CharLater_Refresh( layer, tmp_pos );
				}
				refresh = FALSE;
			}
			
			/* 将当前行行尾的换行符'\n'从源文本中移除 */
			TextLayer_Text_DeleteChar( layer, row_ptr->last_char, left_or_right );
			/* 获取指向下一行文本的指针 */
			tmp_row = Queue_Get( &layer->rows_data, start_pos.y+1 );
			/* 将下一行的文本拼接至当前行行尾 */
			Queue_Cat( &row_ptr->string, &tmp_row->string );
			/* 将下一行的行尾字符数据转移至当前行 */
			row_ptr->last_char = tmp_row->last_char;
			/* 销毁下一行的文本 */
			Queue_Destroy( &tmp_row->string ); 
			Queue_Delete( &layer->rows_data, start_pos.y+1 );
			/* 更新当前行的总字符数 */
			cols = Queue_GetTotal( &row_ptr->string );
			/* 更新总行数 */
			rows = Queue_GetTotal( &layer->rows_data );
			/* 更新当前行的尺寸 */
			TextLayer_Update_RowSize( layer, start_pos.y );
			continue;
		}
		char_ptr = Queue_Get( &row_ptr->string, start_pos.x );
		if( !char_ptr ) {
			continue;
		}
		TextLayer_Clear( layer, pixel_pos, row_ptr->max_size.h, char_ptr );
		pixel_pos.x += char_ptr->bitmap->advance.x;
		/* 将该字从源文本中移除 */
		TextLayer_Text_DeleteChar( layer, char_ptr, left_or_right );
		/* 该字在这行的字体位图也需要删除 */
		cols = Queue_GetTotal( &row_ptr->string );
		Queue_DeletePointer( &row_ptr->string, start_pos.x );
		cols = Queue_GetTotal( &row_ptr->string );
		char_ptr = Queue_Get( &row_ptr->string, start_pos.x );
		cols = Queue_GetTotal( &row_ptr->string );
	}
	/* 更新当前行的尺寸 */
	TextLayer_Update_RowSize( layer, start_pos.y );
	return 0;
}