# HG changeset patch # User Mark Doliner # Date 1249076692 0 # Node ID 07de864fc024f15318a53324fc83ceda552d61a1 # Parent 9d43d9d33477b2a4b05cc13f1597373c8d489898 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define that myspace uses. If this is defined then we send css formatting to the core. Otherwise we send the old font tags to the core. This maintains compatability will old UIs which might not support span tags. We should probably set this flag for both Pidgin and Finch diff -r 9d43d9d33477 -r 07de864fc024 libpurple/protocols/yahoo/util.c --- a/libpurple/protocols/yahoo/util.c Fri Jul 31 14:40:03 2009 +0000 +++ b/libpurple/protocols/yahoo/util.c Fri Jul 31 21:44:52 2009 +0000 @@ -215,6 +215,7 @@ ht = g_hash_table_new(g_str_hash, g_str_equal); /* the numbers in comments are what gyach uses, but i think they're incorrect */ +#ifdef USE_CSS_FORMATTING g_hash_table_insert(ht, "30", ""); /* black */ g_hash_table_insert(ht, "31", ""); /* blue */ g_hash_table_insert(ht, "32", ""); /* cyan */ /* 00b2b2 */ @@ -225,6 +226,18 @@ g_hash_table_insert(ht, "37", ""); /* orange */ /* ffff00 */ g_hash_table_insert(ht, "38", ""); /* red */ g_hash_table_insert(ht, "39", ""); /* olive */ /* 546b50 */ +#else + g_hash_table_insert(ht, "30", ""); /* black */ + g_hash_table_insert(ht, "31", ""); /* blue */ + g_hash_table_insert(ht, "32", ""); /* cyan */ /* 00b2b2 */ + g_hash_table_insert(ht, "33", ""); /* gray */ /* 808080 */ + g_hash_table_insert(ht, "34", ""); /* green */ /* 00c200 */ + g_hash_table_insert(ht, "35", ""); /* pink */ /* ffafaf */ + g_hash_table_insert(ht, "36", ""); /* purple */ /* b200b2 */ + g_hash_table_insert(ht, "37", ""); /* orange */ /* ffff00 */ + g_hash_table_insert(ht, "38", ""); /* red */ + g_hash_table_insert(ht, "39", ""); /* olive */ /* 546b50 */ +#endif /* !USE_CSS_FORMATTING */ g_hash_table_insert(ht, "1", ""); g_hash_table_insert(ht, "x1", ""); @@ -240,6 +253,7 @@ g_hash_table_insert(ht, "l", ""); /* link start */ g_hash_table_insert(ht, "xl", ""); /* link end */ +#ifdef USE_CSS_FORMATTING g_hash_table_insert(ht, "", ""); g_hash_table_insert(ht, "", ""); g_hash_table_insert(ht, "", ""); @@ -261,6 +275,29 @@ g_hash_table_insert(ht, "", ""); g_hash_table_insert(ht, "", ""); g_hash_table_insert(ht, "", ""); +#else + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); + g_hash_table_insert(ht, "", ""); +#endif /* !USE_CSS_FORMATTING */ /* remove these once we have proper support for and */ g_hash_table_insert(ht, "", ""); @@ -291,6 +328,7 @@ ht = NULL; } +#ifndef USE_CSS_FORMATTING static int point_to_html(int x) { if (x < 9) @@ -307,8 +345,14 @@ return 6; return 7; } +#endif /* !USE_CSS_FORMATTING */ -/* The Yahoo size tag is actually an absz tag; convert it to an HTML size, and include both tags */ +/* + * The Yahoo font size value is given in pt, even thougth the HTML + * standard for treats the size as a number on a + * scale between 1 and 7. Let's get rid of this shoddyness and + * convert it to CSS. + */ static void _font_tags_fix_size(const char *tag, GString *dest) { char *x, *end; @@ -318,14 +362,23 @@ while (*x && !g_ascii_isdigit(*x)) x++; if (*x) { +#ifndef USE_CSS_FORMATTING int htmlsize; +#endif /* !USE_CSS_FORMATTING */ size = strtol(x, &end, 10); + +#ifdef USE_CSS_FORMATTING + g_string_append_len(dest, tag, x - tag - 7); + g_string_append(dest, end + 1); + g_string_append_printf(dest, "", size); +#else htmlsize = point_to_html(size); g_string_append_len(dest, tag, x - tag); g_string_append_printf(dest, "%d", htmlsize); g_string_append_printf(dest, "\" absz=\"%d", size); g_string_append(dest, end); +#endif /* !USE_CSS_FORMATTING */ } else { g_string_append(dest, tag); return; @@ -361,7 +414,11 @@ /* We've reached the end of the formatting code, yay */ tmp = g_strndup(x + i + 2, j - i - 2); if (tmp[0] == '#') +#ifdef USE_CSS_FORMATTING g_string_append_printf(s, "", tmp); +#else + g_string_append_printf(s, "", tmp); +#endif /* !USE_CSS_FORMATTING */ else if ((match = g_hash_table_lookup(ht, tmp))) g_string_append(s, match); else { diff -r 9d43d9d33477 -r 07de864fc024 libpurple/tests/test_yahoo_util.c --- a/libpurple/tests/test_yahoo_util.c Fri Jul 31 14:40:03 2009 +0000 +++ b/libpurple/tests/test_yahoo_util.c Fri Jul 31 21:44:52 2009 +0000 @@ -15,7 +15,8 @@ START_TEST(test_codes_to_html) { - assert_string_equal_free("plain", yahoo_codes_to_html("plain")); + assert_string_equal_free("plain", + yahoo_codes_to_html("plain")); /* bold/italic/underline */ assert_string_equal_free("bold", @@ -27,15 +28,39 @@ assert_string_equal_free("bold italic underline", yahoo_codes_to_html("\x1B[1mbold\x1B[x1m \x1B[2mitalic\x1B[x2m \x1B[4munderline")); - /* font color and size */ +#ifdef USE_CSS_FORMATTING + /* font color */ assert_string_equal_free("blue", yahoo_codes_to_html("\x1B[31mblue")); - assert_string_equal_free("test", - yahoo_codes_to_html("\x1B[#70ea15mtest")); + assert_string_equal_free("custom color", + yahoo_codes_to_html("\x1B[#70ea15mcustom color")); + + /* font size */ + assert_string_equal_free("test", + yahoo_codes_to_html("test")); + assert_string_equal_free("size 32", + yahoo_codes_to_html("size 32")); + + /* combinations */ + assert_string_equal_free("test", + yahoo_codes_to_html("\x1B[35mtest")); +#else + /* font color */ + assert_string_equal_free("blue", + yahoo_codes_to_html("\x1B[31mblue")); + assert_string_equal_free("custom color", + yahoo_codes_to_html("\x1B[#70ea15mcustom color")); + + /* font size */ assert_string_equal_free("test", yahoo_codes_to_html("test")); - assert_string_equal_free("test", + assert_string_equal_free("size 32", + yahoo_codes_to_html("size 32")); + + /* combinations */ + assert_string_equal_free("test", yahoo_codes_to_html("\x1B[35mtest")); +#endif /* !USE_CSS_FORMATTING */ } END_TEST