changeset 24689:e268ad14e693

Change MySpace to wrap incoming messages in <span style="font-size: Npt;"> instead of just <font size="M">. The latter tag is suboptimal for two reasons: 1. It's deprecated 2. With MySpace the incoming messages are formatted with pt (well, basically). If we convert to the <font size="M"> value then we lose a little bit of precision when we actually display it. This should have no effect on Pidgin--it will use the outter <font size="M"> tag and happily ignore the font-size css property. But this change will benefit other UIs with more capable rendering widgets (Meebo, specifically, but I imagine this will help Adium, too). Basically it should just make the font sizes of incoming MySpace messages more accurate
author Mark Doliner <mark@kingant.net>
date Mon, 15 Dec 2008 01:16:59 +0000
parents dce57ce0b860
children 773662f77be7
files libpurple/protocols/myspace/markup.c
diffstat 1 files changed, 29 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/markup.c	Mon Dec 15 01:13:17 2008 +0000
+++ b/libpurple/protocols/myspace/markup.c	Mon Dec 15 01:16:59 2008 +0000
@@ -192,35 +192,38 @@
 	height_str = xmlnode_get_attrib(root, "h");
 	decor_str = xmlnode_get_attrib(root, "s");
 
-	if (height_str) {
-		height = atol(height_str);
+	/* Validate the font face, to avoid constructing invalid HTML later */
+	if (strchr(face, '\'') != NULL)
+		face = NULL;
+
+	height = height_str != NULL ? atol(height_str) : 12;
+	decor = decor_str != NULL ? atol(decor_str) : 0;
+
+	/*
+	 * The HTML we're constructing here is a bit redudant.  Ideally we
+	 * would use only the font-family and font-size CSS span, but Pidgin
+	 * doesn't support it (it's included for other UIs).  For Pidgin we
+	 * wrap the whole thing in an ugly font tag, and Pidgin will happily
+	 * ignore the <span>.
+	 */
+	gs_begin = g_string_new("");
+	if (height && !face) {
+		guint point_size = msim_height_to_point(session, height);
+		g_string_printf(gs_begin,
+				"<font size='%d'><span style='font-size: %dpt'>",
+				msim_point_to_purple_size(session, point_size),
+				point_size);
+	} else if (height && face) {
+		guint point_size = msim_height_to_point(session, height);
+		g_string_printf(gs_begin,
+				"<font face='%s' size='%d'><span style='font-family: %s; font-size: %dpt'>",
+				face, msim_point_to_purple_size(session, point_size),
+				face, point_size);
 	} else {
-		height = 12;
-	}
-
-	if (decor_str) {
-		decor = atol(decor_str);
-	} else {
-		decor = 0;
+		g_string_printf(gs_begin, "<font><span>");
 	}
 
-	gs_begin = g_string_new("");
-	/* TODO: get font size working */
-	if (height && !face) {
-		g_string_printf(gs_begin, "<font size='%d'>",
-				msim_point_to_purple_size(session, msim_height_to_point(session, height)));
-	} else if (height && face) {
-		g_string_printf(gs_begin, "<font face='%s' size='%d'>", face,
-				msim_point_to_purple_size(session, msim_height_to_point(session, height)));
-	} else {
-		g_string_printf(gs_begin, "<font>");
-	}
-
-	/* No support for font-size CSS? */
-	/* g_string_printf(gs_begin, "<span style='font-family: %s; font-size: %dpt'>", face,
-			msim_height_to_point(height)); */
-
-	gs_end = g_string_new("</font>");
+	gs_end = g_string_new("</span></font>");
 
 	if (decor & MSIM_TEXT_BOLD) {
 		g_string_append(gs_begin, "<b>");
@@ -237,7 +240,6 @@
 		g_string_append(gs_end, "</u>");
 	}
 
-
 	*begin = g_string_free(gs_begin, FALSE);
 	*end = g_string_free(gs_end, FALSE);
 }