1
0
mirror of https://github.com/irssi/irssi.git synced 2025-02-02 15:08:01 -05:00

BIG5 fixes by vanilla@FreeBSD.org(?)

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3134 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2003-10-19 19:09:51 +00:00 committed by cras
parent 6122035f2f
commit 7eb2fc70e3
6 changed files with 94 additions and 11 deletions

View File

@ -68,6 +68,27 @@ void gui_entry_destroy(GUI_ENTRY_REC *entry)
g_free(entry);
}
/* Fixes the cursor position if it at big5_lo .
Direct: -1 , left shift 1 byte.
Direct: 0, +1 , right shift 1 byte.
*/
static int _fix_big5_pos(unichar *p, int pos, int direct)
{
int newpos;
for (newpos = 0; newpos < pos && p[newpos] != 0; ) {
if (is_big5(p[newpos], p[newpos+1]))
newpos += 2;
else
newpos++;
}
if (newpos != pos)
pos += direct > 0 ? 1 : -1;
return pos;
}
/* Fixes the cursor position in screen */
static void gui_entry_fix_cursor(GUI_ENTRY_REC *entry)
{
@ -85,6 +106,8 @@ static void gui_entry_fix_cursor(GUI_ENTRY_REC *entry)
entry->scrstart = entry->pos - entry->scrpos;
}
entry->scrstart = _fix_big5_pos(entry->text, entry->scrstart, -1);
if (old_scrstart != entry->scrstart)
entry->redraw_needed_from = 0;
}
@ -341,13 +364,31 @@ char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry)
return buf;
}
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int update_cutbuffer)
{
int newpos, size = 0;
g_return_if_fail(entry != NULL);
for (newpos = gui_entry_get_pos(entry); newpos > pos; size++)
newpos = _fix_big5_pos(entry->text, newpos - 1, -1);
gui_entry_erase(entry, size, update_cutbuffer);
}
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer)
{
int newpos;
g_return_if_fail(entry != NULL);
if (entry->pos < size)
return;
/* recount the erase size with big5 charsets */
for (newpos = entry->pos; newpos > 0 && size > 0; size--)
newpos = _fix_big5_pos(entry->text, newpos-1, -1);
size = entry->pos - newpos;
if (update_cutbuffer) {
/* put erased text to cutbuffer */
if (entry->cutbuffer == NULL || entry->cutbuffer_len < size) {
@ -471,10 +512,24 @@ void gui_entry_set_pos(GUI_ENTRY_REC *entry, int pos)
void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos)
{
int newpos;
g_return_if_fail(entry != NULL);
if (entry->pos+pos >= 0 && entry->pos+pos <= entry->text_len)
entry->pos += pos;
/* move cursor with big5 charset */
newpos = _fix_big5_pos(entry->text, entry->pos, -1);
if (pos > 0) {
while (pos > 0 && newpos < entry->text_len) {
newpos = _fix_big5_pos(entry->text, newpos+1, 1);
pos--;
}
} else {
while (pos < 0 && newpos > 0) {
newpos = _fix_big5_pos(entry->text, newpos-1, -1);
pos++;
}
}
entry->pos = newpos;
gui_entry_fix_cursor(entry);
gui_entry_draw(entry);

View File

@ -39,6 +39,7 @@ void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str);
void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr);
char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry);
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int update_cutbuffer);
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer);
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space);
void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space);

View File

@ -50,6 +50,10 @@ static KEYBOARD_REC *keyboard;
static ENTRY_REDIRECT_REC *redir;
static int escape_next_key;
static int big5high = FALSE;
static unichar prekey = '\0';
static int readtag;
static time_t idle_time;
@ -148,6 +152,20 @@ static void sig_gui_key_pressed(gpointer keyp)
idle_time = time(NULL);
if (big5high || is_big5_hi(key)) {
if (big5high) {
big5high = FALSE;
str[0] = prekey;
str[1] = key;
str[2] = '\0';
gui_entry_insert_text(active_entry, str);
} else {
big5high = TRUE;
prekey = key;
}
return;
}
if (key < 32) {
/* control key */
str[0] = '^';

View File

@ -564,12 +564,6 @@ static int input_utf8(const unsigned char *buffer, int size, unichar *result)
}
}
/* XXX I didn't check the encoding range of big5+. This is standard big5. */
#define is_big5_los(lo) (0x40 <= (lo) && (lo) <= 0x7E) /* standard */
#define is_big5_lox(lo) (0x80 <= (lo) && (lo) <= 0xFE) /* extended */
#define is_big5_hi(hi) (0x81 <= (hi) && (hi) <= 0xFE)
#define is_big5(hi,lo) (is_big5_hi(hi) && (is_big5_los(lo) || is_big5_lox(lo)))
static int input_big5(const unsigned char *buffer, int size, unichar *result)
{
if (is_big5_hi(*buffer)) {

View File

@ -199,8 +199,12 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
}
if (!view->utf8) {
next_ptr = ptr+1;
char_len = 1;
/* MH */
if (ptr[1] == '\0' || !is_big5(ptr[0], ptr[1]))
char_len = 1;
else
char_len = 2;
next_ptr = ptr+char_len;
} else {
char_len = 1;
while (ptr[char_len] != '\0' && char_len < 6)
@ -251,7 +255,11 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
continue;
}
if (*ptr == ' ') {
if (!view->utf8 && char_len > 1) {
last_space = xpos;
last_space_ptr = next_ptr;
last_color = color;
} else if (*ptr == ' ') {
last_space = xpos;
last_space_ptr = ptr;
last_color = color;

View File

@ -18,6 +18,13 @@ int utf16_char_to_utf8(unichar c, char *outbuf);
Make sure out is at least 6 x length of str. */
void utf16_to_utf8(const unichar *str, char *out);
/* XXX I didn't check the encoding range of big5+. This is standard big5. */
#define is_big5_los(lo) (0x40 <= (lo) && (lo) <= 0x7E) /* standard */
#define is_big5_lox(lo) (0x80 <= (lo) && (lo) <= 0xFE) /* extended */
#define is_big5_lo(lo) ((is_big5_los(lo) || is_big5_lox(lo)))
#define is_big5_hi(hi) (0x81 <= (hi) && (hi) <= 0xFE)
#define is_big5(hi,lo) (is_big5_hi(hi) && is_big5_lo(lo))
/* Returns width for character (0-2). */
int utf8_width(unichar c);