comparison 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
comparison
equal deleted inserted replaced
8685:2ac2f4cf1de5 8686:140b0d020c43
1941 case 51: /* /CITE */ 1941 case 51: /* /CITE */
1942 case 56: /* SPAN (opt) */ 1942 case 56: /* SPAN (opt) */
1943 /* Inline CSS Support - Douglas Thrift 1943 /* Inline CSS Support - Douglas Thrift
1944 * 1944 *
1945 * color 1945 * color
1946 * background
1946 * font-family 1947 * font-family
1947 * font-size 1948 * font-size
1949 * text-decoration: underline
1948 */ 1950 */
1949 { 1951 {
1950 gchar *style, *color, *family, *size; 1952 gchar *style, *color, *background, *family, *size;
1953 gchar *textdec;
1951 GtkIMHtmlFontDetail *font, *oldfont = NULL; 1954 GtkIMHtmlFontDetail *font, *oldfont = NULL;
1952 style = gtk_imhtml_get_html_opt (tag, "style="); 1955 style = gtk_imhtml_get_html_opt (tag, "style=");
1953 1956
1954 if (!style) break; 1957 if (!style) break;
1955 1958
1956 color = gtk_imhtml_get_css_opt (style, "color: "); 1959 color = gtk_imhtml_get_css_opt (style, "color: ");
1960 background = gtk_imhtml_get_css_opt (style, "background: ");
1957 family = gtk_imhtml_get_css_opt (style, 1961 family = gtk_imhtml_get_css_opt (style,
1958 "font-family: "); 1962 "font-family: ");
1959 size = gtk_imhtml_get_css_opt (style, "font-size: "); 1963 size = gtk_imhtml_get_css_opt (style, "font-size: ");
1960 1964 textdec = gtk_imhtml_get_css_opt (style, "text-decoration: ");
1961 if (!(color || family || size)) { 1965
1966 if (!(color || family || size || background || textdec)) {
1962 g_free(style); 1967 g_free(style);
1963 break; 1968 break;
1964 } 1969 }
1965 1970
1966 1971
1971 font = g_new0 (GtkIMHtmlFontDetail, 1); 1976 font = g_new0 (GtkIMHtmlFontDetail, 1);
1972 if (fonts) 1977 if (fonts)
1973 oldfont = fonts->data; 1978 oldfont = fonts->data;
1974 1979
1975 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) 1980 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR))
1981 {
1976 font->fore = color; 1982 font->fore = color;
1983 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
1984 }
1977 else if (oldfont && oldfont->fore) 1985 else if (oldfont && oldfont->fore)
1978 font->fore = g_strdup(oldfont->fore); 1986 font->fore = g_strdup(oldfont->fore);
1979 1987
1980 if (oldfont && oldfont->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) 1988 if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR))
1989 {
1990 font->back = background;
1991 gtk_imhtml_toggle_backcolor(imhtml, font->back);
1992 }
1993 else if (oldfont && oldfont->back)
1981 font->back = g_strdup(oldfont->back); 1994 font->back = g_strdup(oldfont->back);
1982 1995
1983 if (family && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) 1996 if (family && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE))
1997 {
1984 font->face = family; 1998 font->face = family;
1999 gtk_imhtml_toggle_fontface(imhtml, font->face);
2000 }
1985 else if (oldfont && oldfont->face) 2001 else if (oldfont && oldfont->face)
1986 font->face = g_strdup(oldfont->face); 2002 font->face = g_strdup(oldfont->face);
1987 if (font->face && (atoi(font->face) > 100)) { 2003 if (font->face && (atoi(font->face) > 100)) {
1988 /* WTF is this? */ 2004 /* WTF is this? */
1989 g_free(font->face); 2005 g_free(font->face);
1992 2008
1993 if (oldfont && oldfont->sml) 2009 if (oldfont && oldfont->sml)
1994 font->sml = g_strdup(oldfont->sml); 2010 font->sml = g_strdup(oldfont->sml);
1995 2011
1996 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) { 2012 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) {
1997 if (g_ascii_strcasecmp(size, "smaller") == 0) 2013 if (g_ascii_strcasecmp(size, "xx-small") == 0)
1998 { 2014 font->size = 1;
2015 else if (g_ascii_strcasecmp(size, "smaller") == 0
2016 || g_ascii_strcasecmp(size, "x-small") == 0)
1999 font->size = 2; 2017 font->size = 2;
2000 } 2018 else if (g_ascii_strcasecmp(size, "larger") == 0
2001 else if (g_ascii_strcasecmp(size, "larger") == 0) 2019 || g_ascii_strcasecmp(size, "medium") == 0)
2002 {
2003 font->size = 4; 2020 font->size = 4;
2004 } 2021 else if (g_ascii_strcasecmp(size, "large") == 0)
2022 font->size = 5;
2023 else if (g_ascii_strcasecmp(size, "x-large") == 0)
2024 font->size = 6;
2025 else if (g_ascii_strcasecmp(size, "xx-large") == 0)
2026 font->size = 7;
2005 else 2027 else
2006 {
2007 font->size = 3; 2028 font->size = 3;
2008 } 2029 gtk_imhtml_font_set_size(imhtml, font->size);
2009 } else if (oldfont) 2030 }
2010 font->size = oldfont->size; 2031 else if (oldfont)
2032 {
2033 font->size = oldfont->size;
2034 }
2035
2036 if (oldfont)
2037 {
2038 font->underline = oldfont->underline;
2039 }
2040 if (textdec && font->underline != 1
2041 && g_ascii_strcasecmp(size, "underline") == 0
2042 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE))
2043 {
2044 gtk_imhtml_toggle_underline(imhtml);
2045 font->underline = 1;
2046 }
2011 2047
2012 g_free(style); 2048 g_free(style);
2013 g_free(size); 2049 g_free(size);
2014 fonts = g_slist_prepend (fonts, font); 2050 fonts = g_slist_prepend (fonts, font);
2015 } 2051 }
2016 break; 2052 break;
2017 case 57: /* /SPAN */ 2053 case 57: /* /SPAN */
2018 /* Inline CSS Support - Douglas Thrift */ 2054 /* Inline CSS Support - Douglas Thrift */
2019 if (fonts && !imhtml->wbfo) { 2055 if (fonts && !imhtml->wbfo) {
2056 GtkIMHtmlFontDetail *oldfont = NULL;
2020 GtkIMHtmlFontDetail *font = fonts->data; 2057 GtkIMHtmlFontDetail *font = fonts->data;
2021 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); 2058 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
2022 ws[0] = '\0'; wpos = 0; 2059 ws[0] = '\0'; wpos = 0;
2023 /* NEW_BIT (NEW_TEXT_BIT); */ 2060 /* NEW_BIT (NEW_TEXT_BIT); */
2024 fonts = g_slist_remove (fonts, font); 2061 fonts = g_slist_remove (fonts, font);
2025 if (font->face) 2062 oldfont = fonts->data;
2063
2064 if (font->size != oldfont->size)
2065 gtk_imhtml_font_set_size(imhtml, oldfont->size);
2066 if (font->underline != oldfont->underline)
2067 gtk_imhtml_toggle_underline(imhtml);
2068 if (oldfont->face == NULL || strcmp(font->face, oldfont->face) != 0)
2069 {
2026 g_free (font->face); 2070 g_free (font->face);
2027 if (font->fore) 2071 gtk_imhtml_toggle_fontface(imhtml, oldfont->face);
2072 }
2073 if (oldfont->fore == NULL || strcmp(font->fore, oldfont->fore) != 0)
2074 {
2028 g_free (font->fore); 2075 g_free (font->fore);
2029 if (font->back) 2076 gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore);
2077 }
2078 if (oldfont->back == NULL || strcmp(font->back, oldfont->back) != 0)
2079 {
2030 g_free (font->back); 2080 g_free (font->back);
2081 gtk_imhtml_toggle_backcolor(imhtml, oldfont->back);
2082 }
2031 if (font->sml) 2083 if (font->sml)
2032 g_free (font->sml); 2084 g_free (font->sml);
2033 g_free (font); 2085 g_free (font);
2034 } 2086 }
2035 break; 2087 break;