pidgin: dbad9300: Change MySpace to wrap incoming messages...

markdoliner at pidgin.im markdoliner at pidgin.im
Sun Dec 14 20:20:39 EST 2008


-----------------------------------------------------------------
Revision: dbad9300b40f03937a5bed27529b9c1445d02322
Ancestor: 0a45c969cabb78cafbfaec83aaf5d274bf042109
Author: markdoliner at pidgin.im
Date: 2008-12-15T01:16:59
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/dbad9300b40f03937a5bed27529b9c1445d02322

Modified files:
        libpurple/protocols/myspace/markup.c

ChangeLog: 

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

-------------- next part --------------
============================================================
--- libpurple/protocols/myspace/markup.c	02510b48be3a87123ec1ed4865c31415ed7f9aa3
+++ libpurple/protocols/myspace/markup.c	264b817061421ccbb12b5e2c63b4f5a27aaa3e61
@@ -192,36 +192,39 @@ msim_markup_f_to_html(MsimSession *sessi
 	height_str = xmlnode_get_attrib(root, "h");
 	decor_str = xmlnode_get_attrib(root, "s");
 
-	if (height_str) {
-		height = atol(height_str);
-	} else {
-		height = 12;
-	}
+	/* Validate the font face, to avoid constructing invalid HTML later */
+	if (strchr(face, '\'') != NULL)
+		face = NULL;
 
-	if (decor_str) {
-		decor = atol(decor_str);
-	} else {
-		decor = 0;
-	}
+	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("");
-	/* 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)));
+		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) {
-		g_string_printf(gs_begin, "<font face='%s' size='%d'>", face,
-				msim_point_to_purple_size(session, msim_height_to_point(session, height)));
+		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 {
-		g_string_printf(gs_begin, "<font>");
+		g_string_printf(gs_begin, "<font><span>");
 	}
 
-	/* 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("</span></font>");
 
-	gs_end = g_string_new("</font>");
-
 	if (decor & MSIM_TEXT_BOLD) {
 		g_string_append(gs_begin, "<b>");
 		g_string_prepend(gs_end, "</b>");
@@ -237,7 +240,6 @@ msim_markup_f_to_html(MsimSession *sessi
 		g_string_append(gs_end, "</u>");
 	}
 
-
 	*begin = g_string_free(gs_begin, FALSE);
 	*end = g_string_free(gs_end, FALSE);
 }


More information about the Commits mailing list