reworked: edit_get_utf return int value is utf-8 char, char_width

This commit is contained in:
Ilia Maslakov 2009-04-12 19:16:52 +00:00
parent 7d7560deea
commit d29c5d6d5f
2 changed files with 45 additions and 9 deletions

View File

@ -120,17 +120,44 @@ int edit_get_byte (WEdit * edit, long byte_index)
}
}
char *edit_get_utf_char (WEdit * edit, long byte_index)
int edit_get_utf (WEdit * edit, long byte_index, int *char_width)
{
unsigned long p;
gunichar *str;
int res = -1;
gunichar ch;
gunichar *next_ch = NULL;
char_width = -1;
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
return NULL;
return NULL;
if (byte_index >= edit->curs1) {
p = edit->curs1 + edit->curs2 - byte_index - 1;
return str_get_next_char_safe (edit->buffers2[p >> S_EDIT_BUF_SIZE]+(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
p = edit->curs1 + edit->curs2 - byte_index - 1;
str = (edit->buffers2[p >> S_EDIT_BUF_SIZE]+(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
} else {
return str_get_next_char_safe (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE]+(byte_index & M_EDIT_BUF_SIZE));
str = (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE]+(byte_index & M_EDIT_BUF_SIZE));
}
res = g_utf8_get_char_validated (str, -1);
if ( res < 0 ) {
ch = (char) str;
char_width = 1;
} else {
ch = res;
next_ch = g_utf8_next_char(str);
if ( next_ch ) {
if ( next_ch != str ) {
char_width = next_ch - str;
} else {
char_width = -1;
}
} else {
ch = 0;
char_width = -1;
}
}
}

View File

@ -235,7 +235,7 @@ print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
while (p->ch) {
int style;
int textchar;
unsigned int textchar;
int color;
if (cols_to_skip) {
@ -292,6 +292,7 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
long m1 = 0, m2 = 0, q, c1, c2;
int col, start_col_real;
int cw;
unsigned int c;
int color;
int i;
@ -335,8 +336,13 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
if (q >= edit->found_start
&& q < edit->found_start + edit->found_len)
p->style |= MOD_BOLD;
c = edit_get_byte (edit, q);
/* we don't use bg for mc - fg contains both */
cw = 1;
if ( !edit->utf8 ) {
c = edit_get_byte (edit, q);
} else {
c = edit_get_utf (edit, q, &cw);
}
/* we don't use bg for mc - fg contains both */
edit_get_syntax_color (edit, q, &color);
p->style |= color << 16;
switch (c) {
@ -441,7 +447,10 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
p++;
}
} else {
//FIXME: col += utfchar_width - 1
p->ch = c;
p++;
if ( cw > 1)
col += cw - 1;
}
col++;
break;