# HG changeset patch # User Sadrul Habib Chowdhury # Date 1244048645 0 # Node ID af4a4ebc64413023b29c75a24006061e774b9a1b # Parent f2ca52166a0dfa7d3987a2035cee47031039bcfd Add a utlity function purple_markup_is_rtl Use this function to check for RTL text in messages. Fixes #9261. diff -r f2ca52166a0d -r af4a4ebc6441 ChangeLog --- a/ChangeLog Wed Jun 03 15:50:08 2009 +0000 +++ b/ChangeLog Wed Jun 03 17:04:05 2009 +0000 @@ -82,6 +82,7 @@ rejoin. * Always set unseen-count and unseen-state on conversations. (Joshua Stein) + * Fix a bug in 'Conversation Colors' plugin for RTL messages. Finch: * The hardware cursor is updated correctly. This will be useful diff -r f2ca52166a0d -r af4a4ebc6441 ChangeLog.API --- a/ChangeLog.API Wed Jun 03 15:50:08 2009 +0000 +++ b/ChangeLog.API Wed Jun 03 17:04:05 2009 +0000 @@ -36,6 +36,7 @@ * purple_global_proxy_set_info * purple_group_destroy * purple_log_get_activity_score + * purple_markup_is_rtl * purple_network_force_online * purple_network_set_stun_server * purple_network_set_turn_server diff -r f2ca52166a0d -r af4a4ebc6441 libpurple/util.c --- a/libpurple/util.c Wed Jun 03 15:50:08 2009 +0000 +++ b/libpurple/util.c Wed Jun 03 17:04:05 2009 +0000 @@ -1041,6 +1041,35 @@ return ret; } +gboolean purple_markup_is_rtl(const char *html) +{ + GData *attributes; + const gchar *start, *end; + gboolean res = FALSE; + + if (purple_markup_find_tag("span", html, &start, &end, &attributes)) + { + /* tmp is a member of attributes and is free with g_datalist_clear call */ + const char *tmp = g_datalist_get_data(&attributes, "dir"); + if (tmp && !g_ascii_strcasecmp(tmp, "RTL")) + res = TRUE; + if (!res) + { + tmp = g_datalist_get_data(&attributes, "style"); + if (tmp) + { + char *tmp2 = purple_markup_get_css_property(tmp, "direction"); + if (tmp2 && !g_ascii_strcasecmp(tmp2, "RTL")) + res = TRUE; + g_free(tmp2); + } + + } + g_datalist_clear(&attributes); + } + return res; +} + gboolean purple_markup_find_tag(const char *needle, const char *haystack, const char **start, const char **end, GData **attributes) diff -r f2ca52166a0d -r af4a4ebc6441 libpurple/util.h --- a/libpurple/util.h Wed Jun 03 15:50:08 2009 +0000 +++ b/libpurple/util.h Wed Jun 03 17:04:05 2009 +0000 @@ -579,6 +579,16 @@ */ char * purple_markup_get_css_property(const gchar *style, const gchar *opt); +/** + * Check if the given HTML contains RTL text. + * + * @param html The HTML text. + * + * @return TRUE if the text contains RTL text, FALSE otherwise. + * + * @since 2.6.0 + */ +gboolean purple_markup_is_rtl(const char *html); /*@}*/ diff -r f2ca52166a0d -r af4a4ebc6441 pidgin/gtkconv.c --- a/pidgin/gtkconv.c Wed Jun 03 15:50:08 2009 +0000 +++ b/pidgin/gtkconv.c Wed Jun 03 17:04:05 2009 +0000 @@ -5629,38 +5629,6 @@ #endif } -/* Returns true if the given HTML contains RTL text */ -static gboolean -html_is_rtl(const char *html) -{ - GData *attributes; - const gchar *start, *end; - gboolean res = FALSE; - - if (purple_markup_find_tag("span", html, &start, &end, &attributes)) - { - /* tmp is a member of attributes and is free with g_datalist_clear call */ - const char *tmp = g_datalist_get_data(&attributes, "dir"); - if (tmp && !g_ascii_strcasecmp(tmp, "RTL")) - res = TRUE; - if (!res) - { - tmp = g_datalist_get_data(&attributes, "style"); - if (tmp) - { - char *tmp2 = purple_markup_get_css_property(tmp, "direction"); - if (tmp2 && !g_ascii_strcasecmp(tmp2, "RTL")) - res = TRUE; - g_free(tmp2); - } - - } - g_datalist_clear(&attributes); - } - return res; -} - - static void pidgin_conv_write_conv(PurpleConversation *conv, const char *name, const char *alias, const char *message, PurpleMessageFlags flags, @@ -5822,7 +5790,7 @@ } /* Bi-Directional support - set timestamp direction using unicode characters */ - is_rtl_message = html_is_rtl(message); + is_rtl_message = purple_markup_is_rtl(message); /* Enforce direction only if message is RTL - doesn't effect LTR users */ if (is_rtl_message) str_embed_direction_chars(&mdate); diff -r f2ca52166a0d -r af4a4ebc6441 pidgin/plugins/convcolors.c --- a/pidgin/plugins/convcolors.c Wed Jun 03 15:50:08 2009 +0000 +++ b/pidgin/plugins/convcolors.c Wed Jun 03 17:04:05 2009 +0000 @@ -101,6 +101,7 @@ gboolean bold, italic, underline; int f; const char *color; + gboolean rtl = FALSE; for (i = 0; formats[i].prefix; i++) if (flags & formats[i].flag) @@ -126,6 +127,7 @@ bold = (f & FONT_BOLD); italic = (f & FONT_ITALIC); underline = (f & FONT_UNDERLINE); + rtl = purple_markup_is_rtl(*displaying); if (purple_prefs_get_bool(PREF_IGNORE)) { @@ -156,11 +158,13 @@ } t = *displaying; - *displaying = g_strdup_printf("%s%s%s%s%s%s%s", + *displaying = g_strdup_printf("%s%s%s%s%s%s%s%s%s", bold ? "" : "", italic ? "" : "", underline ? "" : "", - t, + rtl ? "" : "", + t, + rtl ? "" : "", bold ? "" : "", italic ? "" : "", underline ? "" : ""