/** 向文本行插入一个字符数据副本 */ static int TextRow_InsertCopy( TextRowData *p_row, int ins_pos, TextCharData *p_char ) { TextCharData* p_copy_char; p_copy_char = (TextCharData*)malloc( sizeof(TextCharData) ); memcpy( p_copy_char, p_char, sizeof(TextCharData) ); return TextRow_Insert( p_row, ins_pos, p_copy_char ); }
/** 向文本行插入一个字符数据副本 */ static int TextRow_InsertCopy( TextRow txtrow, int ins_pos, TextChar txtchar ) { TextChar txtchar2; txtchar2 = malloc( sizeof(TextCharRec) ); *txtchar2 = *txtchar; return TextRow_Insert( txtrow, ins_pos, txtchar2 ); }
/** 对文本行进行断行 */ static void TextLayer_BreakTextRow( LCUI_TextLayer layer, int i_row, int col, EOLChar eol ) { int n; TextRow txtrow, next_txtrow; txtrow = layer->rowlist.rows[i_row]; next_txtrow = TextRowList_InsertNewRow( &layer->rowlist, i_row + 1 ); /* 将本行原有的行尾符转移至下一行 */ next_txtrow->eol = txtrow->eol; txtrow->eol = eol; for( n = txtrow->length - 1; n >= col; --n ) { TextRow_Insert( next_txtrow, 0, txtrow->string[n] ); txtrow->string[n] = NULL; } txtrow->length = col; TextLayer_UpdateRowSize( layer, txtrow ); TextLayer_UpdateRowSize( layer, next_txtrow ); }
/** 对文本行进行断行 */ static void TextLayer_BreakTextRow( LCUI_TextLayer *layer, int i_row, int col, EOLChar eol ) { int n; TextRowData *p_row, *p_next_row; p_row = layer->row_list.rowdata[i_row]; p_next_row = TextRowList_InsertNewRow( &layer->row_list, i_row+1 ); /* 将本行原有的行尾符转移至下一行 */ p_next_row->eol = p_row->eol; p_row->eol = eol; for( n=p_row->string_len-1; n>=col; --n ) { TextRow_Insert( p_next_row, 0, p_row->string[n] ); p_row->string[n] = NULL; } p_row->string_len = col; TextRow_UpdateSize( p_row, layer->text_style.pixel_size ); TextRow_UpdateSize( p_next_row, layer->text_style.pixel_size ); }
/** 对指定行的文本进行排版 */ 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; } } }
/** 对指定行的文本进行排版 */ 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; } } }