libpurple/protocols/yahoo/util.c

changeset 28045
dca626985d99
parent 28041
84fb2d6540ea
child 28051
378df616b029
equal deleted inserted replaced
28044:9d48a4bd7ee2 28045:dca626985d99
213 /* Hash table has already been initialized */ 213 /* Hash table has already been initialized */
214 return; 214 return;
215 215
216 ht = g_hash_table_new(g_str_hash, g_str_equal); 216 ht = g_hash_table_new(g_str_hash, g_str_equal);
217 /* the numbers in comments are what gyach uses, but i think they're incorrect */ 217 /* the numbers in comments are what gyach uses, but i think they're incorrect */
218 #ifdef USE_CSS_FORMATTING
218 g_hash_table_insert(ht, "30", "<span style=\"color: #000000\">"); /* black */ 219 g_hash_table_insert(ht, "30", "<span style=\"color: #000000\">"); /* black */
219 g_hash_table_insert(ht, "31", "<span style=\"color: #0000FF\">"); /* blue */ 220 g_hash_table_insert(ht, "31", "<span style=\"color: #0000FF\">"); /* blue */
220 g_hash_table_insert(ht, "32", "<span style=\"color: #008080\">"); /* cyan */ /* 00b2b2 */ 221 g_hash_table_insert(ht, "32", "<span style=\"color: #008080\">"); /* cyan */ /* 00b2b2 */
221 g_hash_table_insert(ht, "33", "<span style=\"color: #808080\">"); /* gray */ /* 808080 */ 222 g_hash_table_insert(ht, "33", "<span style=\"color: #808080\">"); /* gray */ /* 808080 */
222 g_hash_table_insert(ht, "34", "<span style=\"color: #008000\">"); /* green */ /* 00c200 */ 223 g_hash_table_insert(ht, "34", "<span style=\"color: #008000\">"); /* green */ /* 00c200 */
223 g_hash_table_insert(ht, "35", "<span style=\"color: #FF0080\">"); /* pink */ /* ffafaf */ 224 g_hash_table_insert(ht, "35", "<span style=\"color: #FF0080\">"); /* pink */ /* ffafaf */
224 g_hash_table_insert(ht, "36", "<span style=\"color: #800080\">"); /* purple */ /* b200b2 */ 225 g_hash_table_insert(ht, "36", "<span style=\"color: #800080\">"); /* purple */ /* b200b2 */
225 g_hash_table_insert(ht, "37", "<span style=\"color: #FF8000\">"); /* orange */ /* ffff00 */ 226 g_hash_table_insert(ht, "37", "<span style=\"color: #FF8000\">"); /* orange */ /* ffff00 */
226 g_hash_table_insert(ht, "38", "<span style=\"color: #FF0000\">"); /* red */ 227 g_hash_table_insert(ht, "38", "<span style=\"color: #FF0000\">"); /* red */
227 g_hash_table_insert(ht, "39", "<span style=\"color: #808000\">"); /* olive */ /* 546b50 */ 228 g_hash_table_insert(ht, "39", "<span style=\"color: #808000\">"); /* olive */ /* 546b50 */
229 #else
230 g_hash_table_insert(ht, "30", "<font color=\"#000000\">"); /* black */
231 g_hash_table_insert(ht, "31", "<font color=\"#0000FF\">"); /* blue */
232 g_hash_table_insert(ht, "32", "<font color=\"#008080\">"); /* cyan */ /* 00b2b2 */
233 g_hash_table_insert(ht, "33", "<font color=\"#808080\">"); /* gray */ /* 808080 */
234 g_hash_table_insert(ht, "34", "<font color=\"#008000\">"); /* green */ /* 00c200 */
235 g_hash_table_insert(ht, "35", "<font color=\"#FF0080\">"); /* pink */ /* ffafaf */
236 g_hash_table_insert(ht, "36", "<font color=\"#800080\">"); /* purple */ /* b200b2 */
237 g_hash_table_insert(ht, "37", "<font color=\"#FF8000\">"); /* orange */ /* ffff00 */
238 g_hash_table_insert(ht, "38", "<font color=\"#FF0000\">"); /* red */
239 g_hash_table_insert(ht, "39", "<font color=\"#808000\">"); /* olive */ /* 546b50 */
240 #endif /* !USE_CSS_FORMATTING */
228 241
229 g_hash_table_insert(ht, "1", "<b>"); 242 g_hash_table_insert(ht, "1", "<b>");
230 g_hash_table_insert(ht, "x1", "</b>"); 243 g_hash_table_insert(ht, "x1", "</b>");
231 g_hash_table_insert(ht, "2", "<i>"); 244 g_hash_table_insert(ht, "2", "<i>");
232 g_hash_table_insert(ht, "x2", "</i>"); 245 g_hash_table_insert(ht, "x2", "</i>");
238 * just ignore it. 251 * just ignore it.
239 */ 252 */
240 g_hash_table_insert(ht, "l", ""); /* link start */ 253 g_hash_table_insert(ht, "l", ""); /* link start */
241 g_hash_table_insert(ht, "xl", ""); /* link end */ 254 g_hash_table_insert(ht, "xl", ""); /* link end */
242 255
256 #ifdef USE_CSS_FORMATTING
243 g_hash_table_insert(ht, "<black>", "<span style=\"color: #000000\">"); 257 g_hash_table_insert(ht, "<black>", "<span style=\"color: #000000\">");
244 g_hash_table_insert(ht, "<blue>", "<span style=\"color: #0000FF\">"); 258 g_hash_table_insert(ht, "<blue>", "<span style=\"color: #0000FF\">");
245 g_hash_table_insert(ht, "<cyan>", "<span style=\"color: #008284\">"); 259 g_hash_table_insert(ht, "<cyan>", "<span style=\"color: #008284\">");
246 g_hash_table_insert(ht, "<gray>", "<span style=\"color: #848284\">"); 260 g_hash_table_insert(ht, "<gray>", "<span style=\"color: #848284\">");
247 g_hash_table_insert(ht, "<green>", "<span style=\"color: #008200\">"); 261 g_hash_table_insert(ht, "<green>", "<span style=\"color: #008200\">");
259 g_hash_table_insert(ht, "</pink>", "</span>"); 273 g_hash_table_insert(ht, "</pink>", "</span>");
260 g_hash_table_insert(ht, "</purple>", "</span>"); 274 g_hash_table_insert(ht, "</purple>", "</span>");
261 g_hash_table_insert(ht, "</orange>", "</span>"); 275 g_hash_table_insert(ht, "</orange>", "</span>");
262 g_hash_table_insert(ht, "</red>", "</span>"); 276 g_hash_table_insert(ht, "</red>", "</span>");
263 g_hash_table_insert(ht, "</yellow>", "</span>"); 277 g_hash_table_insert(ht, "</yellow>", "</span>");
278 #else
279 g_hash_table_insert(ht, "<black>", "<font color=\"#000000\">");
280 g_hash_table_insert(ht, "<blue>", "<font color=\"#0000FF\">");
281 g_hash_table_insert(ht, "<cyan>", "<font color=\"#008284\">");
282 g_hash_table_insert(ht, "<gray>", "<font color=\"#848284\">");
283 g_hash_table_insert(ht, "<green>", "<font color=\"#008200\">");
284 g_hash_table_insert(ht, "<pink>", "<font color=\"#FF0084\">");
285 g_hash_table_insert(ht, "<purple>", "<font color=\"#840084\">");
286 g_hash_table_insert(ht, "<orange>", "<font color=\"#FF8000\">");
287 g_hash_table_insert(ht, "<red>", "<font color=\"#FF0000\">");
288 g_hash_table_insert(ht, "<yellow>", "<font color=\"#848200\">");
289
290 g_hash_table_insert(ht, "</black>", "</font>");
291 g_hash_table_insert(ht, "</blue>", "</font>");
292 g_hash_table_insert(ht, "</cyan>", "</font>");
293 g_hash_table_insert(ht, "</gray>", "</font>");
294 g_hash_table_insert(ht, "</green>", "</font>");
295 g_hash_table_insert(ht, "</pink>", "</font>");
296 g_hash_table_insert(ht, "</purple>", "</font>");
297 g_hash_table_insert(ht, "</orange>", "</font>");
298 g_hash_table_insert(ht, "</red>", "</font>");
299 g_hash_table_insert(ht, "</yellow>", "</font>");
300 #endif /* !USE_CSS_FORMATTING */
264 301
265 /* remove these once we have proper support for <FADE> and <ALT> */ 302 /* remove these once we have proper support for <FADE> and <ALT> */
266 g_hash_table_insert(ht, "</fade>", ""); 303 g_hash_table_insert(ht, "</fade>", "");
267 g_hash_table_insert(ht, "</alt>", ""); 304 g_hash_table_insert(ht, "</alt>", "");
268 305
289 326
290 g_hash_table_destroy(ht); 327 g_hash_table_destroy(ht);
291 ht = NULL; 328 ht = NULL;
292 } 329 }
293 330
331 #ifndef USE_CSS_FORMATTING
294 static int point_to_html(int x) 332 static int point_to_html(int x)
295 { 333 {
296 if (x < 9) 334 if (x < 9)
297 return 1; 335 return 1;
298 if (x < 11) 336 if (x < 11)
305 return 5; 343 return 5;
306 if (x < 35) 344 if (x < 35)
307 return 6; 345 return 6;
308 return 7; 346 return 7;
309 } 347 }
310 348 #endif /* !USE_CSS_FORMATTING */
311 /* The Yahoo size tag is actually an absz tag; convert it to an HTML size, and include both tags */ 349
350 /*
351 * The Yahoo font size value is given in pt, even thougth the HTML
352 * standard for <font size="x"> treats the size as a number on a
353 * scale between 1 and 7. Let's get rid of this shoddyness and
354 * convert it to CSS.
355 */
312 static void _font_tags_fix_size(const char *tag, GString *dest) 356 static void _font_tags_fix_size(const char *tag, GString *dest)
313 { 357 {
314 char *x, *end; 358 char *x, *end;
315 int size; 359 int size;
316 360
317 if (((x = strstr(tag, "size"))) && ((x = strchr(x, '=')))) { 361 if (((x = strstr(tag, "size"))) && ((x = strchr(x, '=')))) {
318 while (*x && !g_ascii_isdigit(*x)) 362 while (*x && !g_ascii_isdigit(*x))
319 x++; 363 x++;
320 if (*x) { 364 if (*x) {
365 #ifndef USE_CSS_FORMATTING
321 int htmlsize; 366 int htmlsize;
367 #endif /* !USE_CSS_FORMATTING */
322 368
323 size = strtol(x, &end, 10); 369 size = strtol(x, &end, 10);
370
371 #ifdef USE_CSS_FORMATTING
372 g_string_append_len(dest, tag, x - tag - 7);
373 g_string_append(dest, end + 1);
374 g_string_append_printf(dest, "<span style=\"font-size: %dpt\">", size);
375 #else
324 htmlsize = point_to_html(size); 376 htmlsize = point_to_html(size);
325 g_string_append_len(dest, tag, x - tag); 377 g_string_append_len(dest, tag, x - tag);
326 g_string_append_printf(dest, "%d", htmlsize); 378 g_string_append_printf(dest, "%d", htmlsize);
327 g_string_append_printf(dest, "\" absz=\"%d", size); 379 g_string_append_printf(dest, "\" absz=\"%d", size);
328 g_string_append(dest, end); 380 g_string_append(dest, end);
381 #endif /* !USE_CSS_FORMATTING */
329 } else { 382 } else {
330 g_string_append(dest, tag); 383 g_string_append(dest, tag);
331 return; 384 return;
332 } 385 }
333 } else { 386 } else {
359 continue; 412 continue;
360 else { 413 else {
361 /* We've reached the end of the formatting code, yay */ 414 /* We've reached the end of the formatting code, yay */
362 tmp = g_strndup(x + i + 2, j - i - 2); 415 tmp = g_strndup(x + i + 2, j - i - 2);
363 if (tmp[0] == '#') 416 if (tmp[0] == '#')
417 #ifdef USE_CSS_FORMATTING
364 g_string_append_printf(s, "<span style=\"color: %s\">", tmp); 418 g_string_append_printf(s, "<span style=\"color: %s\">", tmp);
419 #else
420 g_string_append_printf(s, "<font color=\"%s\">", tmp);
421 #endif /* !USE_CSS_FORMATTING */
365 else if ((match = g_hash_table_lookup(ht, tmp))) 422 else if ((match = g_hash_table_lookup(ht, tmp)))
366 g_string_append(s, match); 423 g_string_append(s, match);
367 else { 424 else {
368 purple_debug_error("yahoo", 425 purple_debug_error("yahoo",
369 "Unknown ansi code 'ESC[%sm'.\n", tmp); 426 "Unknown ansi code 'ESC[%sm'.\n", tmp);

mercurial