diff src/gtkimhtml.c @ 8686:140b0d020c43

[gaim-migrate @ 9439] " This fixes the GTKIMHTML CSS processing so that it works again: - Added support for background colors in the CSS processing. - Log viewer will now display all formatting including font colors, sizes, faces, etc. - Jabber underline will now appear in received messages - Logger will now log *ALL 7* possible font sizes instead of just smaller (1-3), medium (4), and larger (5-7) and recognize them in IMHTML. This is accomplished by fixing the font size specifications in gaim_markup_html_to_xhtml and then a partial rewrite of the CSS formatting code." --Kevin Stange committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 18 Apr 2004 00:21:58 +0000
parents e2e56231023c
children 0680ca680e92
line wrap: on
line diff
--- a/src/gtkimhtml.c	Sat Apr 17 18:50:46 2004 +0000
+++ b/src/gtkimhtml.c	Sun Apr 18 00:21:58 2004 +0000
@@ -1943,22 +1943,27 @@
 					/* Inline CSS Support - Douglas Thrift
 					 *
 					 * color
+					 * background
 					 * font-family
 					 * font-size
+					 * text-decoration: underline
 					 */
 					{
-						gchar *style, *color, *family, *size;
+						gchar *style, *color, *background, *family, *size;
+						gchar *textdec;
 						GtkIMHtmlFontDetail *font, *oldfont = NULL;
 						style = gtk_imhtml_get_html_opt (tag, "style=");
 
 						if (!style) break;
 
 						color = gtk_imhtml_get_css_opt (style, "color: ");
+						background = gtk_imhtml_get_css_opt (style, "background: ");
 						family = gtk_imhtml_get_css_opt (style,
 							"font-family: ");
 						size = gtk_imhtml_get_css_opt (style, "font-size: ");
-
-						if (!(color || family || size)) {
+						textdec = gtk_imhtml_get_css_opt (style, "text-decoration: ");
+
+						if (!(color || family || size || background || textdec)) {
 							g_free(style);
 							break;
 						}
@@ -1973,15 +1978,26 @@
 							oldfont = fonts->data;
 
 						if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR))
+						{
 							font->fore = color;
+							gtk_imhtml_toggle_forecolor(imhtml, font->fore);
+						}
 						else if (oldfont && oldfont->fore)
 							font->fore = g_strdup(oldfont->fore);
 
-						if (oldfont && oldfont->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR))
+						if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR))
+						{
+							font->back = background;
+							gtk_imhtml_toggle_backcolor(imhtml, font->back);
+						}
+						else if (oldfont && oldfont->back)
 							font->back = g_strdup(oldfont->back);
 
 						if (family && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE))
+						{
 							font->face = family;
+							gtk_imhtml_toggle_fontface(imhtml, font->face);
+						}
 						else if (oldfont && oldfont->face)
 							font->face = g_strdup(oldfont->face);
 						if (font->face && (atoi(font->face) > 100)) {
@@ -1994,20 +2010,40 @@
 							font->sml = g_strdup(oldfont->sml);
 
 						if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) {
-							if (g_ascii_strcasecmp(size, "smaller") == 0)
-							{
+							if (g_ascii_strcasecmp(size, "xx-small") == 0)
+								font->size = 1;
+							else if (g_ascii_strcasecmp(size, "smaller") == 0
+								  || g_ascii_strcasecmp(size, "x-small") == 0)
 								font->size = 2;
-							}
-							else if (g_ascii_strcasecmp(size, "larger") == 0)
-							{
+							else if (g_ascii_strcasecmp(size, "larger") == 0
+								  || g_ascii_strcasecmp(size, "medium") == 0)
 								font->size = 4;
-							}
+							else if (g_ascii_strcasecmp(size, "large") == 0)
+								font->size = 5;
+							else if (g_ascii_strcasecmp(size, "x-large") == 0)
+								font->size = 6;
+							else if (g_ascii_strcasecmp(size, "xx-large") == 0)
+								font->size = 7;
 							else
-							{
 								font->size = 3;
-							}
-						} else if (oldfont)
-							font->size = oldfont->size;
+						    gtk_imhtml_font_set_size(imhtml, font->size);
+						}
+						else if (oldfont)
+						{
+						    font->size = oldfont->size;
+						}
+
+						if (oldfont)
+						{
+						    font->underline = oldfont->underline;
+						}
+						if (textdec && font->underline != 1
+							&& g_ascii_strcasecmp(size, "underline") == 0
+							&& (imhtml->format_functions & GTK_IMHTML_UNDERLINE))
+						{
+						    gtk_imhtml_toggle_underline(imhtml);
+						    font->underline = 1;
+						}
 
 						g_free(style);
 						g_free(size);
@@ -2017,17 +2053,33 @@
 				case 57:	/* /SPAN */
 					/* Inline CSS Support - Douglas Thrift */
 					if (fonts && !imhtml->wbfo) {
+						GtkIMHtmlFontDetail *oldfont = NULL;
 						GtkIMHtmlFontDetail *font = fonts->data;
 						gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
 						ws[0] = '\0'; wpos = 0;
 						/* NEW_BIT (NEW_TEXT_BIT); */
 						fonts = g_slist_remove (fonts, font);
-						if (font->face)
+						oldfont = fonts->data;
+
+						if (font->size != oldfont->size)
+						    gtk_imhtml_font_set_size(imhtml, oldfont->size);
+						if (font->underline != oldfont->underline)
+						    gtk_imhtml_toggle_underline(imhtml);
+						if (oldfont->face == NULL || strcmp(font->face, oldfont->face) != 0)
+						{
 							g_free (font->face);
-						if (font->fore)
+						    gtk_imhtml_toggle_fontface(imhtml, oldfont->face);
+						}
+						if (oldfont->fore == NULL || strcmp(font->fore, oldfont->fore) != 0)
+						{
 							g_free (font->fore);
-						if (font->back)
+						    gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore);
+						}
+						if (oldfont->back == NULL || strcmp(font->back, oldfont->back) != 0)
+						{
 							g_free (font->back);
+						    gtk_imhtml_toggle_backcolor(imhtml, oldfont->back);
+						}
 						if (font->sml)
 							g_free (font->sml);
 						g_free (font);