comparison libpurple/protocols/msn/msn-utils.c @ 16083:f2a4b05407d7

Patch from shlomil in ticket #78. This fixes RTL text support in MSN, and lays the framework so it could be supported in other prpls as well. As added pluses, shlomil removed some duplicate code and fixed some small related bugs. committer: Richard Laager <rlaager@wiktel.com>
author Shlomi Loubaton <shlomister@gmail.com>
date Fri, 13 Apr 2007 04:13:24 +0000
parents 32c366eeeb99
children a5a831a5f186
comparison
equal deleted inserted replaced
16082:7a7377a86ad1 16083:f2a4b05407d7
108 pre = g_string_append(pre, tag); 108 pre = g_string_append(pre, tag);
109 post = g_string_prepend(post, "</FONT>"); 109 post = g_string_prepend(post, "</FONT>");
110 } 110 }
111 } 111 }
112 112
113 cur = strstr(mime, "RL=");
114
115 if (cur && (*(cur = cur + 3) != ';'))
116 {
117 if(*cur == '1') {
118 /* RTL text was received */
119 pre = g_string_append(pre, "<SPAN style=\"direction:rtl;text-align:right;\">");
120 post = g_string_prepend(post, "</SPAN>");
121 }
122 }
123
113 cur = g_strdup(purple_url_decode(pre->str)); 124 cur = g_strdup(purple_url_decode(pre->str));
114 g_string_free(pre, TRUE); 125 g_string_free(pre, TRUE);
115 126
116 if (pre_ret != NULL) 127 if (pre_ret != NULL)
117 *pre_ret = cur; 128 *pre_ret = cur;
159 * Taken from the zephyr plugin. 170 * Taken from the zephyr plugin.
160 * This parses HTML formatting (put out by one of the gtkimhtml widgets 171 * This parses HTML formatting (put out by one of the gtkimhtml widgets
161 * and converts it to msn formatting. It doesn't deal with the tag closing, 172 * and converts it to msn formatting. It doesn't deal with the tag closing,
162 * but gtkimhtml widgets give valid html. 173 * but gtkimhtml widgets give valid html.
163 * It currently deals properly with <b>, <u>, <i>, <font face=...>, 174 * It currently deals properly with <b>, <u>, <i>, <font face=...>,
164 * <font color=...>. 175 * <font color=...>, <span dir=...>, <span style="direction: ...">.
165 * It ignores <font back=...> and <font size=...> 176 * It ignores <font back=...> and <font size=...>
166 */ 177 */
167 void 178 void
168 msn_import_html(const char *html, char **attributes, char **message) 179 msn_import_html(const char *html, char **attributes, char **message)
169 { 180 {
171 const char *c; 182 const char *c;
172 char *msg; 183 char *msg;
173 char *fontface = NULL; 184 char *fontface = NULL;
174 char fonteffect[4]; 185 char fonteffect[4];
175 char fontcolor[7]; 186 char fontcolor[7];
187 char direction = '0';
176 188
177 gboolean has_bold = FALSE; 189 gboolean has_bold = FALSE;
178 gboolean has_italic = FALSE; 190 gboolean has_italic = FALSE;
179 gboolean has_underline = FALSE; 191 gboolean has_underline = FALSE;
180 gboolean has_strikethrough = FALSE; 192 gboolean has_strikethrough = FALSE;
253 while ((*c != '\0') && g_ascii_strncasecmp(c, "</a>", 4)) 265 while ((*c != '\0') && g_ascii_strncasecmp(c, "</a>", 4))
254 c++; 266 c++;
255 267
256 if (*c != '\0') 268 if (*c != '\0')
257 c += 4; 269 c += 4;
270 }
271 else if (!g_ascii_strncasecmp(c + 1, "span", 4))
272 {
273 /* Bi-directional text support using CSS properties in span tags */
274 c += 5;
275
276 while (*c != '\0' && *c != '>')
277 {
278 while (*c == ' ')
279 c++;
280 if (!g_ascii_strncasecmp(c, "dir=\"rtl\"", 9))
281 {
282 c += 9;
283 direction = '1';
284 }
285 else if (!g_ascii_strncasecmp(c, "style=\"", 7))
286 {
287 /* Parse inline CSS attributes */
288 char* attributes;
289 int attr_len = 0;
290 c += 7;
291 while (*(c + attr_len) != '\0' && *(c + attr_len) != '"')
292 attr_len++;
293 if(*(c + attr_len) == '"')
294 {
295 char *attr_dir;
296 attributes = g_strndup(c, attr_len);
297 attr_dir = purple_markup_get_css_property(attributes, "direction");
298 if(attr_dir && (!strncasecmp(attr_dir, "RTL", 3)))
299 direction = '1';
300 if(attr_dir)
301 g_free(attr_dir);
302 if(attributes)
303 g_free(attributes);
304 }
305
306 }
307 else
308 {
309 c++;
310 }
311 }
312 if (*c == '>')
313 c++;
258 } 314 }
259 else if (!g_ascii_strncasecmp(c + 1, "font", 4)) 315 else if (!g_ascii_strncasecmp(c + 1, "font", 4))
260 { 316 {
261 c += 5; 317 c += 5;
262 318
352 } 408 }
353 409
354 if (fontface == NULL) 410 if (fontface == NULL)
355 fontface = g_strdup("MS Sans Serif"); 411 fontface = g_strdup("MS Sans Serif");
356 412
357 *attributes = g_strdup_printf("FN=%s; EF=%s; CO=%s; PF=0", 413 *attributes = g_strdup_printf("FN=%s; EF=%s; CO=%s; PF=0; RL=%c",
358 encode_spaces(fontface), 414 encode_spaces(fontface),
359 fonteffect, fontcolor); 415 fonteffect, fontcolor, direction);
360 *message = g_strdup(msg); 416 *message = g_strdup(msg);
361 417
362 g_free(fontface); 418 g_free(fontface);
363 g_free(msg); 419 g_free(msg);
364 } 420 }