Пример #1
0
/** 对指定行的文本进行排版 */
static void TextLayer_TextRowTypeset( LCUI_TextLayer* layer, int row )
{
	int col, row_width;
	TextRowData *p_row, *p_next_row;
	TextCharData *p_char;

	p_row = layer->row_list.rowdata[row];
	row_width = 0;
	for( col=0; col<p_row->string_len; ++col ) {
		p_char = p_row->string[col];
		if( !p_char->bitmap ) {
			continue;
		}
		/* 累加行宽度 */
		row_width += p_char->bitmap->advance.x;
		/* 如果是当前行的第一个字符,或者行宽度没有超过宽度限制 */
		if( layer->max_width <= 0 || !layer->is_autowrap_mode 
		 || (layer->is_autowrap_mode && !layer->is_mulitiline_mode)
		 || col < 1 || p_row->max_width <= layer->max_width ) {
			continue;
		}
		TextLayer_BreakTextRow( layer, row, col, EOL_NONE );
		return;
	}
	TextRow_UpdateSize( p_row, layer->text_style.pixel_size );
	/* 如果本行有换行符,或者是最后一行 */
	if( p_row->eol != EOL_NONE || row == layer->row_list.rows-1 ) {
		return;
	}
	
	row_width = p_row->max_width;
	/* 本行的文本宽度未达到限制宽度,需要将下行的文本转移至本行 */
	while( p_row->eol != EOL_NONE ) {
		/* 获取下一行的指针 */
		p_next_row = TextRowList_GetRow( &layer->row_list, row+1 );
		if( !p_next_row ) {
			return;
		}
		for( col=0; col<p_next_row->string_len; ++col ) {
			p_char = p_next_row->string[col];
			/* 忽略无字体位图的文字 */
			if( !p_char->bitmap ) {
				TextRow_Insert( p_row, p_row->string_len, p_char );
				p_next_row->string[col] = NULL;
				continue;
			}
			row_width += p_char->bitmap->advance.x;
			/* 如果没有超过宽度限制 */
			if( !layer->is_autowrap_mode || layer->max_width <= 0
			 || (layer->is_autowrap_mode && !layer->is_mulitiline_mode)
			 || p_row->max_width <= layer->max_width ) {
				TextRow_Insert( p_row, p_row->string_len, p_char );
				p_next_row->string[col] = NULL;
				continue;
			}
			/* 如果插入点在下一行 */
			if( layer->insert_y == row+1 ) {
				/* 如果插入点处于被转移的几个文字中 */
				if( layer->insert_x < col ) {
					layer->insert_y = row;
					layer->insert_x += p_row->string_len;
				} else {
					/* 否则,减去被转移的文字数 */
					layer->insert_x -= col;
				}
			}
			/* 将这一行剩余的文字向前移 */
			TextRow_LeftMove( p_next_row, col );
			TextRow_UpdateSize( p_row, layer->text_style.pixel_size );
			return;
		}
		TextRow_UpdateSize( p_row, layer->text_style.pixel_size );
		TextLayer_InvalidateRowRect( layer, row );
		TextLayer_InvalidateRowRect( layer, row+1 );
		_DEBUG_MSG("remove row %d\n", row+1);
		/* 删除这一行,因为这一行的内容已经转移至当前行 */
		TextRowList_RemoveRow( &layer->row_list, row+1 );
		/* 如果插入点当前行在后面 */
		if( layer->insert_y > row ) {
			--layer->insert_y;
		}
	}
}
Пример #2
0
/** 对指定行的文本进行排版 */
static void TextLayer_TextRowTypeset( LCUI_TextLayer layer, int row )
{
	TextRow txtrow;
	TextChar txtchar;
	LCUI_BOOL not_autowrap;
	int col, row_width = 0;
	int max_width;
	if( layer->fixed_width > 0 ) {
		max_width = layer->fixed_width;
	} else {
		max_width = layer->max_width;
	}
	if( max_width <= 0 || !layer->is_autowrap_mode ||
	    (layer->is_autowrap_mode && !layer->is_mulitiline_mode) ) {
		not_autowrap = TRUE;
	} else {
		not_autowrap = FALSE;
	}
	txtrow = layer->rowlist.rows[row];
	for( col = 0; col < txtrow->length; ++col ) {
		txtchar = txtrow->string[col];
		if( !txtchar->bitmap ) {
			continue;
		}
		/* 累加行宽度 */
		row_width += txtchar->bitmap->advance.x;
		/* 如果是当前行的第一个字符,或者行宽度没有超过宽度限制 */
		if( not_autowrap || col < 1 || row_width <= max_width ) {
			continue;
		}
		TextLayer_BreakTextRow( layer, row, col, EOL_NONE );
		return;
	}
	TextLayer_UpdateRowSize( layer, txtrow );
	/* 如果本行有换行符,或者是最后一行 */
	if( txtrow->eol != EOL_NONE || row == layer->rowlist.length - 1 ) {
		return;
	}
	row_width = txtrow->width;
	/* 本行的文本宽度未达到限制宽度,需要将下行的文本转移至本行 */
	while( txtrow->eol == EOL_NONE ) {
		/* 获取下一行的指针 */
		TextRow next_txtrow = TextLayer_GetRow( layer, row + 1 );
		if( !next_txtrow ) {
			break;
		}
		for( col = 0; col < next_txtrow->length; ++col ) {
			txtchar = next_txtrow->string[col];
			/* 忽略无字体位图的文字 */
			if( !txtchar->bitmap ) {
				TextRow_Insert( txtrow, -1, txtchar );
				next_txtrow->string[col] = NULL;
				continue;
			}
			row_width += txtchar->bitmap->advance.x;
			/* 如果没有超过宽度限制 */
			if( not_autowrap || row_width <= max_width ) {
				TextRow_Insert( txtrow, -1, txtchar );
				next_txtrow->string[col] = NULL;
				continue;
			}
			/* 如果插入点在下一行 */
			if( layer->insert_y == row + 1 ) {
				/* 如果插入点处于被转移的几个文字中 */
				if( layer->insert_x < col ) {
					layer->insert_y = row;
					layer->insert_x += txtrow->length;
				} else {
					/* 否则,减去被转移的文字数 */
					layer->insert_x -= col;
				}
			}
			/* 将这一行剩余的文字向前移 */
			TextRow_LeftMove( next_txtrow, col );
			TextLayer_UpdateRowSize( layer, txtrow );
			return;
		}
		txtrow->eol = next_txtrow->eol;
		TextLayer_UpdateRowSize( layer, txtrow );
		TextLayer_InvalidateRowRect( layer, row, 0, -1 );
		TextLayer_InvalidateRowRect( layer, row + 1, 0, -1 );
		/* 删除这一行,因为这一行的内容已经转移至当前行 */
		TextRowList_RemoveRow( &layer->rowlist, row + 1 );
		/* 如果插入点当前行在后面 */
		if( layer->insert_y > row ) {
			--layer->insert_y;
		}
	}
}