コード例 #1
0
ファイル: bitmapfont.c プロジェクト: hbao/LCUI
/** 释放字体位图占用的资源 */
LCUI_API void FontBMP_Free( LCUI_FontBMP *bitmap )
{
	if( FontBMP_IsValid(bitmap) ) {
		free( bitmap->buffer );
		FontBMP_Init( bitmap );
	}
}
コード例 #2
0
ファイル: fontlibrary.c プロジェクト: scrich998/LCUI
LCUI_API LCUI_FontBMP*
FontLIB_GetExistFontBMP( int font_id, wchar_t ch, int pixel_size )
{
	LCUI_FontBMP *bmp, bmp_cache;
	bmp = FontLIB_GetFontBMP( ch, font_id, pixel_size );
	if( bmp ) {
		return bmp;
	}
	FontBMP_Init( &bmp_cache );
	FontBMP_Load( &bmp_cache, font_id, ch, pixel_size );
	return FontLIB_AddFontBMP( ch, font_id, pixel_size, &bmp_cache );
}
コード例 #3
0
ファイル: text_layer.c プロジェクト: soar-penguin/LCUI
void 
TextLayer_Init( LCUI_TextLayer *layer )
/* 初始化文本图层相关数据 */
{
	layer->read_only = FALSE;
	layer->using_code_mode = FALSE; 
	layer->using_style_tags = FALSE; 
	layer->enable_word_wrap = FALSE; 
	layer->enable_multiline = FALSE;
	layer->need_proc_buff = FALSE;
	layer->need_scroll_layer = FALSE;
	layer->have_select = FALSE;
	layer->start = 0;
	layer->end = 0;
	layer->offset_pos = Pos(0,0);
	layer->old_offset_pos = Pos(0,0);
	
	Queue_Init( &layer->color_keyword, sizeof(Special_KeyWord), Destroy_Special_KeyWord );
	/* 队列中使用链表储存这些数据 */
	Queue_Init( &layer->text_source_data, sizeof(LCUI_CharData), Destroy_CharData );
	Queue_Set_DataMode( &layer->text_source_data, QUEUE_DATA_MODE_LINKED_LIST ); 
	Queue_Init( &layer->rows_data, sizeof(Text_RowData), Destroy_Text_RowData ); 
	Queue_Init( &layer->tag_buff, sizeof(tag_style_data), destroy_tag_style_data );
	Queue_Init( &layer->style_data, sizeof(LCUI_TextStyle), NULL );
	RectQueue_Init( &layer->clear_area );
	/* 初始化屏蔽符的数据 */
	layer->password_char.display = TRUE;
	layer->password_char.need_update = FALSE;
	layer->password_char.data = NULL;
	layer->password_char.char_code = 0;
	FontBMP_Init( &layer->password_char.bitmap );
	
	layer->default_data.pixel_size = 12;
	layer->current_src_pos = 0;
	layer->current_des_pos = Pos(0,0);
	layer->max_text_len = 5000; 
	TextStyle_Init ( &layer->default_data );
	
	String_Init( &layer->text_buff );
	//TextLayer_Text_Add_NewRow ( layer );/* 添加新行 */
}
コード例 #4
0
ファイル: text_layer.c プロジェクト: dwdcth/LCUI
void
TextLayer_Text_Process( LCUI_TextLayer *layer, char *new_text )
/* 对文本进行预处理,处理后的数据保存至layer里 */ 
{
	int total; 
	uint32_t rows, n_ignore = 0;
	wchar_t *finish, *buff, *p, *q;
	
	DEBUG_MSG("%s\n", new_text);
	
	LCUI_CharData char_data; 
	Text_RowData *current_row_data;
	
	/* 如果有选中的文本,那就删除 */
	//......  
	total = Char_To_Wchar_T( new_text, &buff );
	current_row_data = TextLayer_Get_Current_RowData ( layer );
	if( !current_row_data ) {
		TextLayer_Text_Add_NewRow( layer );
		current_row_data = TextLayer_Get_Current_RowData ( layer );
	}
	
	FontBMP_Init( &char_data.bitmap );
	/* 根据样式标签生成对应的样式数据 */
	for(p=buff, finish=buff+total; p<finish; ++p) { 
		if( layer->using_style_tags ) {
			/* 处理样式的结束标签 */ 
			q = handle_style_endtag ( layer, p );
			if(q != NULL) {
				/* 计算需忽略的字符数 */
				n_ignore = q-p+1;
			} else {
				/* 处理样式标签 */
				q = handle_style_tag ( layer, p ); 
				if( q != NULL ) {
					n_ignore = q-p+1;
				}
			}
		}
		if(*p == '\n') { 
			/* 计算需要忽略的换行符的数量 */
			for( n_ignore=0,q=p; *q == '\n'; ++q,++n_ignore);
		} 
		if(n_ignore > 0) {
			/* 被忽略的字符的属性都一样,所以只需赋一次值 */
			char_data.data = NULL;
			char_data.display = IS_FALSE; 
			char_data.need_update = IS_FALSE; 
			FontBMP_Init( &char_data.bitmap ); 
		}
		while(n_ignore > 0) { 
			char_data.char_code = *p++;
			Queue_Insert( &layer->text_source_data, 
				layer->current_src_pos, &char_data );
			/* 遇到换行符,那就增加新行 */
			if(char_data.char_code == '\n') {
				rows = TextLayer_Text_Add_NewRow( layer ); 
				current_row_data = Queue_Get( &layer->rows_data, rows );
				layer->current_des_pos.x = 0;
				layer->current_des_pos.y = rows;
			} else {
				++layer->current_src_pos; 
			}
			--n_ignore;
			if(n_ignore == 0) {
				n_ignore = -1;
				break;
			}
		}
		if(n_ignore == -1) {
			--p; n_ignore = 0;
			continue;
		}
		
		char_data.char_code = *p;
		char_data.display = TRUE; 
		char_data.need_update = TRUE; 
		char_data.data = TextLayer_Get_Current_TextStyle( layer );  
		Queue_Insert( &layer->text_source_data, layer->current_src_pos, &char_data ); 
		Queue_Insert( &current_row_data->string, layer->current_des_pos.x, &char_data ); 
		
		++layer->current_src_pos;
		++layer->current_des_pos.x; 
	}
}
コード例 #5
0
ファイル: text_layer.c プロジェクト: soar-penguin/LCUI
void
TextLayer_Text_Process( LCUI_TextLayer *layer, int pos_type, char *new_text )
/* 对文本进行预处理,处理后的数据保存至layer里 */ 
{
	BOOL refresh = TRUE;
	LCUI_Pos cur_pos, des_pos;
	int total, cur_len, row, src_pos, total_row, n_ignore = 0;
	wchar_t *finish, *buff, *p, *q;
	
	LCUI_Pos tmp_pos;
	LCUI_CharData *char_ptr, char_data; 
	Text_RowData *cur_row_ptr, *tmp_row_ptr;
	
	/* 如果有选中的文本,那就删除 */
	//......  
	DEBUG_MSG1("enter\n");
	/* 如果是将文本追加至文本末尾 */
	if( pos_type == AT_TEXT_LAST ) {
		cur_pos.y = Queue_Get_Total( &layer->rows_data );
		if( cur_pos.y > 0 ) {
			--cur_pos.y;
		}
		cur_row_ptr = Queue_Get( &layer->rows_data, cur_pos.y );
		if( !cur_row_ptr ) {
			TextLayer_Text_Add_NewRow( layer );
			cur_row_ptr = Queue_Get( &layer->rows_data, cur_pos.y );
		}
		cur_pos.x = Queue_Get_Total( &cur_row_ptr->string );
		src_pos = Queue_Get_Total( &layer->text_source_data );
		des_pos = cur_pos;
	} else {/* 否则,是将文本插入至光标所在位置 */
		cur_pos = TextLayer_Get_Cursor_Pos( layer );
		DEBUG_MSG1( "cur_pos: %d,%d\n", cur_pos.x, cur_pos.y );
		cur_row_ptr = Queue_Get( &layer->rows_data, cur_pos.y );
		DEBUG_MSG1( "cur_row_ptr: %p\n", cur_row_ptr );
		if( !cur_row_ptr ) {
			TextLayer_Text_Add_NewRow( layer );
			cur_row_ptr = Queue_Get( &layer->rows_data, cur_pos.y );
		}
		src_pos = layer->current_src_pos;
		des_pos = layer->current_des_pos;
		DEBUG_MSG1( "src_pos: %d\n", src_pos );
		DEBUG_MSG1( "des_pos: %d,%d\n", des_pos.x, des_pos.y );
	}
	row = cur_pos.y;
	
	total = Char_To_Wchar_T( new_text, &buff ); 
	total_row = TextLayer_Get_Rows( layer );
	/* 判断当前要添加的字符的总数是否超出最大限制 */
	cur_len = Queue_Get_Total( &layer->text_source_data );
	if( total + cur_len > layer->max_text_len ) {
		total = layer->max_text_len - cur_len;
	}
	if( total < 0 ) {
		total = 0;
	}
	//_DEBUG_MSG( "layer: %p, cur total: %d, max_len: %d\n", 
	// layer, cur_len, layer->max_text_len );
	DEBUG_MSG1( "total char: %d\n", total );
	DEBUG_MSG1( "total row: %d\n", total_row );
	
	FontBMP_Init( &char_data.bitmap );
	/* 先记录这一行需要刷新的区域,起点为光标所在位置 */
	TextLayer_CharLater_Refresh( layer, cur_pos );
	for(p=buff, finish=buff+total; p<finish; ++p) { 
		DEBUG_MSG2( "1, char: %c\n", *p );
		if( layer->using_style_tags ) {
			/* 处理样式的结束标签 */ 
			q = handle_style_endtag ( layer, p );
			if( q ) {
				/* 计算需忽略的字符数 */
				n_ignore = q-p+1;
			} else {
				/* 处理样式标签 */
				q = handle_style_tag ( layer, p ); 
				if( q ) {
					n_ignore = q-p+1;
				}
			}
		}
		/* 针对换行符模式为Win(CR/LF)的文本,进行处理 */
		if(*p == '\n' || *p == '\r') { 
			/* 计算需要忽略的换行符的数量 */
			for( n_ignore=0,q=p; *q == '\n' || *q == '\r'; 
				++q,++n_ignore);
		} 
		if(n_ignore > 0) {
			/* 被忽略的字符的属性都一样,所以只需赋一次值 */
			char_data.data = NULL;
			char_data.display = FALSE; 
			char_data.need_update = FALSE; 
			FontBMP_Init( &char_data.bitmap ); 
		}
		while(n_ignore > 0) {
			DEBUG_MSG2( "ignore = %d\n", n_ignore );
			char_data.char_code = *p++;
			Queue_Insert( &layer->text_source_data, src_pos, &char_data ); 
			char_ptr = Queue_Get( &layer->text_source_data, src_pos );
			/* 如果启用多行显示,并遇到换行符,那就增加新行 */
			if( layer->enable_multiline 
			 && char_data.char_code == '\n' ) {
				++row;
				if( refresh ) {
					tmp_pos.x = 0;
					tmp_pos.y = row;
					/* 刷新该行后面所有行的字符 */
					for( ; tmp_pos.y<total_row; ++tmp_pos.y ) {
						TextLayer_CharLater_Refresh( layer, tmp_pos );
					}
					refresh = FALSE;
				}
				/* 换行符的数据单独保存 */
				cur_row_ptr->last_char = char_ptr;
				/* 在该行插入新行 */
				TextLayer_Text_Insert_NewRow( layer, row );
				/* 获取新行的行指针 */
				tmp_row_ptr = Queue_Get( &layer->rows_data, row );
				/* 当前位置后面的字符转移到新行里 */
				TextLayer_Text_RowBreak( layer, cur_row_ptr, 
				 des_pos.x, tmp_row_ptr );
				/* 行指针切换到下一行 */
				cur_row_ptr = tmp_row_ptr;
				/* 更新当前字符坐标 */
				des_pos.x = 0;
				des_pos.y = row;
				/* 更新总行数 */
				total_row = TextLayer_Get_Rows( layer );
			}
			++src_pos; 
			--n_ignore;
			if(n_ignore == 0) {
				n_ignore = -1;
				break;
			}
		}
		if(n_ignore == -1) {
			--p; n_ignore = 0;
			continue;
		}
		DEBUG_MSG2( "2, char: %c\n", *p );
		char_data.char_code = *p;
		char_data.display = TRUE; 
		char_data.need_update = TRUE; 
		char_data.data = TextLayer_Get_Current_TextStyle( layer );
		/* 插入至源文本中 */
		Queue_Insert( &layer->text_source_data, src_pos, &char_data );
		/* 获取源文本中的字符数据的指针 */
		char_ptr = Queue_Get( &layer->text_source_data, src_pos );
		/* 将该指针添加至行数据队列中 */
		cur_row_ptr = Queue_Get( &layer->rows_data, des_pos.y );
		Queue_Insert_Pointer( &cur_row_ptr->string, des_pos.x, char_ptr );
		++src_pos; ++des_pos.x; 
	}
	/* 释放用于临时储存Wchar_T字符的空间 */
	free( buff );
	
	if( pos_type == AT_CURSOR_POS ) {
		layer->current_des_pos = des_pos;
		layer->current_src_pos = src_pos;
	}
	DEBUG_MSG1("quit\n");
}