summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2013-12-11 12:48:32 +0100
committerSebastien Helleu <flashcode@flashtux.org>2013-12-11 12:48:32 +0100
commit95adb3a04b0f367cdb53d16ea0c7a0e730353de3 (patch)
tree0f3610168dcc3551a3b9726cdd71269d4c9d734c
parent92ab912fae1f061228a5001a02cef77f2d1a44b0 (diff)
downloadweechat-95adb3a04b0f367cdb53d16ea0c7a0e730353de3.zip
core: fix text emphasis with wide chars on screen like japanese (patch #8253) (patch from Ryuunosuke Ayanokouzi)
-rw-r--r--ChangeLog1
-rw-r--r--src/gui/curses/gui-curses-bar-window.c4
-rw-r--r--src/gui/curses/gui-curses-chat.c10
-rw-r--r--src/gui/gui-chat.c9
-rw-r--r--src/gui/gui-chat.h3
-rw-r--r--src/gui/gui-color.c6
6 files changed, 23 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 3ba6d4146..7706759dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
== Version 0.4.3 (under dev)
+* core: fix text emphasis with wide chars on screen like japanese (patch #8253)
* core: add signal "buffer_cleared"
* core: remove option on /unset of plugin description option (plugins.desc.xxx)
(bug #40768)
diff --git a/src/gui/curses/gui-curses-bar-window.c b/src/gui/curses/gui-curses-bar-window.c
index f9f53fe6e..3e5ee5a1d 100644
--- a/src/gui/curses/gui-curses-bar-window.c
+++ b/src/gui/curses/gui-curses-bar-window.c
@@ -582,7 +582,9 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
}
/* compute new start for displaying input */
- new_start_input = pos_after_start_input + gui_chat_string_real_pos (pos_after_start_input, diff);
+ new_start_input = pos_after_start_input +
+ gui_chat_string_real_pos (pos_after_start_input,
+ diff, 1);
if (new_start_input > pos_cursor)
new_start_input = pos_cursor;
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 5955fb56c..88b37e016 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -527,7 +527,8 @@ gui_chat_display_word (struct t_gui_window *window,
if (window->win_chat_cursor_x + chars_to_display > gui_chat_get_real_width (window))
{
num_displayed = gui_chat_get_real_width (window) - window->win_chat_cursor_x;
- pos_saved_char = gui_chat_string_real_pos (ptr_data, num_displayed);
+ pos_saved_char = gui_chat_string_real_pos (ptr_data, num_displayed,
+ 1);
saved_char = ptr_data[pos_saved_char];
ptr_data[pos_saved_char] = '\0';
if ((count == 0) || (*lines_displayed >= num_lines - count))
@@ -790,7 +791,8 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
short_name,
short_name +
gui_chat_string_real_pos (short_name,
- chars_to_display),
+ chars_to_display,
+ 1),
1, num_lines, count,
pre_lines_displayed, lines_displayed,
simulate,
@@ -1043,9 +1045,9 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
(prefix_highlighted) ? prefix_highlighted : ptr_prefix,
(prefix_highlighted) ?
prefix_highlighted + gui_chat_string_real_pos (prefix_highlighted,
- chars_to_display) :
+ chars_to_display, 1) :
ptr_prefix + gui_chat_string_real_pos (ptr_prefix,
- chars_to_display),
+ chars_to_display, 1),
1, num_lines, count,
pre_lines_displayed,
lines_displayed,
diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c
index 2391c15f3..5c6512d95 100644
--- a/src/gui/gui-chat.c
+++ b/src/gui/gui-chat.c
@@ -243,11 +243,16 @@ gui_chat_string_add_offset_screen (const char *string, int offset_screen)
* Gets real position in string (ignoring formatting chars like
* colors/attributes).
*
+ * If argument "use_screen_size" is 0, the "pos" argument is a number of UTF-8
+ * chars.
+ * If argument "use_screen_size" is 1, the "pos" argument is the width of UTF-8
+ * chars on screen.
+ *
* Returns real position, in bytes.
*/
int
-gui_chat_string_real_pos (const char *string, int pos)
+gui_chat_string_real_pos (const char *string, int pos, int use_screen_size)
{
const char *real_pos, *real_pos_prev, *ptr_string;
int size_on_screen;
@@ -267,7 +272,7 @@ gui_chat_string_real_pos (const char *string, int pos)
{
size_on_screen = gui_chat_char_size_screen (ptr_string);
if (size_on_screen > 0)
- pos -= size_on_screen;
+ pos -= (use_screen_size) ? size_on_screen : 1;
ptr_string = utf8_next_char (ptr_string);
real_pos_prev = real_pos;
real_pos = ptr_string;
diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h
index 9e6f65fc7..cfee63b4a 100644
--- a/src/gui/gui-chat.h
+++ b/src/gui/gui-chat.h
@@ -70,7 +70,8 @@ extern int gui_chat_strlen_screen (const char *string);
extern char *gui_chat_string_add_offset (const char *string, int offset);
extern char *gui_chat_string_add_offset_screen (const char *string,
int offset_screen);
-extern int gui_chat_string_real_pos (const char *string, int pos);
+extern int gui_chat_string_real_pos (const char *string, int pos,
+ int use_screen_size);
extern int gui_chat_string_pos (const char *string, int real_pos);
extern void gui_chat_get_word_info (struct t_gui_window *window,
const char *data, int *word_start_offset,
diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c
index f5f65dcca..84b9441d5 100644
--- a/src/gui/gui-color.c
+++ b/src/gui/gui-color.c
@@ -700,9 +700,11 @@ gui_color_emphasize (const char *string,
* color codes)
*/
real_pos1 = gui_chat_string_real_pos (ptr_string,
- gui_chat_string_pos (ptr_no_color, pos1));
+ gui_chat_string_pos (ptr_no_color, pos1),
+ 0);
real_pos2 = gui_chat_string_real_pos (ptr_string,
- gui_chat_string_pos (ptr_no_color, pos2));
+ gui_chat_string_pos (ptr_no_color, pos2),
+ 0);
/*
* concatenate following strings to the result: