pidgin: 80c06f69: Change yahoo_codes_to_html() to use the ...

markdoliner at pidgin.im markdoliner at pidgin.im
Fri Jul 31 17:50:34 EDT 2009


-----------------------------------------------------------------
Revision: 80c06f6950b5ea3ca311d8e4752ad5b19ea84059
Ancestor: 20e16d28b924016a1310911f9b12376bba9a9859
Author: markdoliner at pidgin.im
Date: 2009-07-31T21:44:52
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/80c06f6950b5ea3ca311d8e4752ad5b19ea84059

Modified files:
        libpurple/protocols/yahoo/util.c
        libpurple/tests/test_yahoo_util.c

ChangeLog: 

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

-------------- next part --------------
============================================================
--- libpurple/protocols/yahoo/util.c	a68d6174b58d18b4490705f2e4b3fd5110e0e906
+++ libpurple/protocols/yahoo/util.c	379b884cf44e9ae3c7037bef8cd5277076a484b0
@@ -215,6 +215,7 @@ void yahoo_init_colorht()
 
 	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", "<span style=\"color: #000000\">"); /* black */
 	g_hash_table_insert(ht, "31", "<span style=\"color: #0000FF\">"); /* blue */
 	g_hash_table_insert(ht, "32", "<span style=\"color: #008080\">"); /* cyan */      /* 00b2b2 */
@@ -225,6 +226,18 @@ void yahoo_init_colorht()
 	g_hash_table_insert(ht, "37", "<span style=\"color: #FF8000\">"); /* orange */    /* ffff00 */
 	g_hash_table_insert(ht, "38", "<span style=\"color: #FF0000\">"); /* red */
 	g_hash_table_insert(ht, "39", "<span style=\"color: #808000\">"); /* olive */     /* 546b50 */
+#else
+	g_hash_table_insert(ht, "30", "<font color=\"#000000\">"); /* black */
+	g_hash_table_insert(ht, "31", "<font color=\"#0000FF\">"); /* blue */
+	g_hash_table_insert(ht, "32", "<font color=\"#008080\">"); /* cyan */      /* 00b2b2 */
+	g_hash_table_insert(ht, "33", "<font color=\"#808080\">"); /* gray */      /* 808080 */
+	g_hash_table_insert(ht, "34", "<font color=\"#008000\">"); /* green */     /* 00c200 */
+	g_hash_table_insert(ht, "35", "<font color=\"#FF0080\">"); /* pink */      /* ffafaf */
+	g_hash_table_insert(ht, "36", "<font color=\"#800080\">"); /* purple */    /* b200b2 */
+	g_hash_table_insert(ht, "37", "<font color=\"#FF8000\">"); /* orange */    /* ffff00 */
+	g_hash_table_insert(ht, "38", "<font color=\"#FF0000\">"); /* red */
+	g_hash_table_insert(ht, "39", "<font color=\"#808000\">"); /* olive */     /* 546b50 */
+#endif /* !USE_CSS_FORMATTING */
 
 	g_hash_table_insert(ht,  "1",  "<b>");
 	g_hash_table_insert(ht, "x1", "</b>");
@@ -240,6 +253,7 @@ void yahoo_init_colorht()
 	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, "<black>",  "<span style=\"color: #000000\">");
 	g_hash_table_insert(ht, "<blue>",   "<span style=\"color: #0000FF\">");
 	g_hash_table_insert(ht, "<cyan>",   "<span style=\"color: #008284\">");
@@ -261,7 +275,30 @@ void yahoo_init_colorht()
 	g_hash_table_insert(ht, "</orange>", "</span>");
 	g_hash_table_insert(ht, "</red>",    "</span>");
 	g_hash_table_insert(ht, "</yellow>", "</span>");
+#else
+	g_hash_table_insert(ht, "<black>",  "<font color=\"#000000\">");
+	g_hash_table_insert(ht, "<blue>",   "<font color=\"#0000FF\">");
+	g_hash_table_insert(ht, "<cyan>",   "<font color=\"#008284\">");
+	g_hash_table_insert(ht, "<gray>",   "<font color=\"#848284\">");
+	g_hash_table_insert(ht, "<green>",  "<font color=\"#008200\">");
+	g_hash_table_insert(ht, "<pink>",   "<font color=\"#FF0084\">");
+	g_hash_table_insert(ht, "<purple>", "<font color=\"#840084\">");
+	g_hash_table_insert(ht, "<orange>", "<font color=\"#FF8000\">");
+	g_hash_table_insert(ht, "<red>",    "<font color=\"#FF0000\">");
+	g_hash_table_insert(ht, "<yellow>", "<font color=\"#848200\">");
 
+	g_hash_table_insert(ht, "</black>",  "</font>");
+	g_hash_table_insert(ht, "</blue>",   "</font>");
+	g_hash_table_insert(ht, "</cyan>",   "</font>");
+	g_hash_table_insert(ht, "</gray>",   "</font>");
+	g_hash_table_insert(ht, "</green>",  "</font>");
+	g_hash_table_insert(ht, "</pink>",   "</font>");
+	g_hash_table_insert(ht, "</purple>", "</font>");
+	g_hash_table_insert(ht, "</orange>", "</font>");
+	g_hash_table_insert(ht, "</red>",    "</font>");
+	g_hash_table_insert(ht, "</yellow>", "</font>");
+#endif /* !USE_CSS_FORMATTING */
+
 	/* remove these once we have proper support for <FADE> and <ALT> */
 	g_hash_table_insert(ht, "</fade>", "");
 	g_hash_table_insert(ht, "</alt>", "");
@@ -291,6 +328,7 @@ void yahoo_dest_colorht()
 	ht = NULL;
 }
 
+#ifndef USE_CSS_FORMATTING
 static int point_to_html(int x)
 {
 	if (x < 9)
@@ -307,8 +345,14 @@ static int point_to_html(int x)
 		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 <font size="x"> 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 @@ static void _font_tags_fix_size(const ch
 		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, "<span style=\"font-size: %dpt\">", 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 @@ char *yahoo_codes_to_html(const char *x)
 					/* 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, "<span style=\"color: %s\">", tmp);
+#else
+						g_string_append_printf(s, "<font color=\"%s\">", tmp);
+#endif /* !USE_CSS_FORMATTING */
 					else if ((match = g_hash_table_lookup(ht, tmp)))
 						g_string_append(s, match);
 					else {
============================================================
--- libpurple/tests/test_yahoo_util.c	f5c799e99a03151eb9fbc08023acd91dba366c1c
+++ libpurple/tests/test_yahoo_util.c	e500aea89ba34a5bbce64d4283fafce51598fb0f
@@ -15,7 +15,8 @@ START_TEST(test_codes_to_html)
 
 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("<b>bold",
@@ -27,15 +28,39 @@ START_TEST(test_codes_to_html)
 	assert_string_equal_free("<b>bold</b> <i>italic</i> <u>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("<span style=\"color: #0000FF\">blue",
 			yahoo_codes_to_html("\x1B[31mblue"));
-	assert_string_equal_free("<span style=\"color: #70ea15\">test",
-			yahoo_codes_to_html("\x1B[#70ea15mtest"));
+	assert_string_equal_free("<span style=\"color: #70ea15\">custom color",
+			yahoo_codes_to_html("\x1B[#70ea15mcustom color"));
+
+	/* font size */
+	assert_string_equal_free("<font><span style=\"font-size: 15pt\">test",
+			yahoo_codes_to_html("<font size=\"15\">test"));
+	assert_string_equal_free("<font><span style=\"font-size: 32pt\">size 32",
+			yahoo_codes_to_html("<font size=\"32\">size 32"));
+
+	/* combinations */
+	assert_string_equal_free("<span style=\"color: #FF0080\"><font><span style=\"font-size: 15pt\">test",
+			yahoo_codes_to_html("\x1B[35m<font size=\"15\">test"));
+#else
+	/* font color */
+	assert_string_equal_free("<font color=\"#0000FF\">blue",
+			yahoo_codes_to_html("\x1B[31mblue"));
+	assert_string_equal_free("<font color=\"#70ea15\">custom color",
+			yahoo_codes_to_html("\x1B[#70ea15mcustom color"));
+
+	/* font size */
 	assert_string_equal_free("<font size=\"4\" absz=\"15\">test",
 			yahoo_codes_to_html("<font size=\"15\">test"));
-	assert_string_equal_free("<span style=\"color: #FF0080\"><font size=\"4\" absz=\"15\">test",
+	assert_string_equal_free("<font size=\"6\" absz=\"32\">size 32",
+			yahoo_codes_to_html("<font size=\"32\">size 32"));
+
+	/* combinations */
+	assert_string_equal_free("<font color=\"#FF0080\"><font size=\"4\" absz=\"15\">test",
 			yahoo_codes_to_html("\x1B[35m<font size=\"15\">test"));
+#endif /* !USE_CSS_FORMATTING */
 }
 END_TEST
 


More information about the Commits mailing list