HTMLStyle * parse_border (HTMLStyle *style,const gchar *origvalue) { if (origvalue && *origvalue) { gchar * value = g_strdup(origvalue); gchar * tmpvalue = value; while (value && *value) { gchar *next; gint modified; gchar orig = 0; while (isspace (*value)) value ++; next = value; while (*next && !isspace (*next)) next ++; if (*next) { orig = *next; *next = 0; modified = 1; } else modified = 0; style = parse_border_style (style, value); style = parse_border_color (style, value); style = parse_border_width (style, value); if (modified) { *next = orig; next ++; } value = next; } g_free(tmpvalue); } return style; }
static HTMLStyle * parse_border (HTMLStyle *style, gchar *value) { while (value && *value) { gchar *next; gint modified; gchar orig = 0; while (isspace (*value)) value++; next = value; while (*next && !isspace (*next)) next++; if (*next) { orig = *next; *next = 0; modified = 1; } else modified = 0; style = parse_border_style (style, value); style = parse_border_color (style, value); style = parse_border_width (style, value); if (modified) { *next = orig; next++; } value = next; } return style; }
/* atributes from style only*/ HTMLStyle * html_style_add_styleattribute (HTMLStyle *style, const gchar *attr, const gchar *value) { if (!attr) return style; if (!value) return style; if (!g_ascii_strcasecmp ("align", attr)) { style = html_style_add_text_align (style, parse_halign (value, HTML_VALIGN_NONE)); } else if (!g_ascii_strcasecmp ("valign", attr)) { style = html_style_add_text_valign (style, parse_valign (value, HTML_VALIGN_MIDDLE)); } else if (!g_ascii_strcasecmp ("width", attr)) { style = html_style_add_width (style, value); } else if (!g_ascii_strcasecmp ("height", attr)) { style = html_style_add_height (style, value); } else if (!g_ascii_strcasecmp ("color", attr)) { GdkColor color; if (html_parse_color (value, &color)) { HTMLColor *hc = html_color_new_from_gdk_color (&color); style = html_style_add_color (style, hc); html_color_unref (hc); } } else if (!g_ascii_strcasecmp ("face", attr)) { style = html_style_add_font_face (style, value); } else if (!g_ascii_strcasecmp ("background-image", attr)) { style = html_style_add_background_image (style, value); } else if (!g_ascii_strcasecmp ("border", attr)) { style = parse_border (style, value); } else if (!g_ascii_strcasecmp ("border-style", attr)) { style = parse_border_style (style, value); } else if (!g_ascii_strcasecmp ("dir", attr)) { style = html_style_add_dir (style, value); } else if (!g_ascii_strcasecmp ("border-color", attr)) { style = parse_border_color (style, value); } else if (!g_ascii_strcasecmp ("border-width", attr)) { style = parse_border_width (style, value); } else if (!g_ascii_strcasecmp ("padding", attr)) { style = html_style_set_padding (style, atoi (value)); } else if (!g_ascii_strcasecmp ("bgcolor", attr) ) { GdkColor color; if (html_parse_color (value, &color)) { HTMLColor *hc = html_color_new_from_gdk_color (&color); style = html_style_add_background_color (style, hc); html_color_unref (hc); } } else if (!g_ascii_strcasecmp ("white-space", attr)) { /* normal, pre, nowrap, pre-wrap, pre-line, inherit */ /* if (!g_ascii_strcasecmp ("normal", value)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_NORMAL); } else if (!g_ascii_strcasecmp ("pre", value)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_PRE); } else if (!g_ascii_strcasecmp ("nowrap", value)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_NOWRAP); } else if (!g_ascii_strcasecmp ("pre-wrap", value)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_PRE_WRAP); } else if (!g_ascii_strcasecmp ("pre-line", value)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_PRE_LINE); } else if (!g_ascii_strcasecmp ("inherit", value)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_INHERIT); }*/ } else if (!g_ascii_strcasecmp ("attr-decoration", attr)) { if (!g_ascii_strcasecmp ("none", value)) { style = html_style_unset_decoration (style, ~GTK_HTML_FONT_STYLE_SIZE_MASK); } } else if (!g_ascii_strcasecmp ("display", attr)) { if (!g_ascii_strcasecmp ("block", value)) { style = html_style_set_display (style, HTMLDISPLAY_BLOCK); } else if (!g_ascii_strcasecmp ("inline", value)) { style = html_style_set_display (style, HTMLDISPLAY_INLINE); } else if (!g_ascii_strcasecmp ("none", value)) { style = html_style_set_display (style, HTMLDISPLAY_NONE); } else if (!g_ascii_strcasecmp ("inline-table", value)) { style = html_style_set_display (style, HTMLDISPLAY_INLINE_TABLE); } } else if (!g_ascii_strcasecmp ("attr-align", attr)) { if (!g_ascii_strcasecmp ("center", value)) { style = html_style_add_text_align (style, HTML_HALIGN_CENTER); } } else if (!g_ascii_strcasecmp ("width", attr)) { style = html_style_add_width (style, value); } else if (!g_ascii_strcasecmp ("height", attr)) { style = html_style_add_height (style, value); } else if (!g_ascii_strcasecmp ("clear", attr)) { if (!g_ascii_strcasecmp ("left", value)) { style = html_style_set_clear (style, HTML_CLEAR_LEFT); } else if (!g_ascii_strcasecmp ("right", value)) { style = html_style_set_clear (style, HTML_CLEAR_RIGHT); } else if (!g_ascii_strcasecmp ("both", value)) { style = html_style_set_clear (style, HTML_CLEAR_ALL); } else if (!g_ascii_strcasecmp ("inherit", value)) { style = html_style_set_clear (style, HTML_CLEAR_INHERIT); } else if (!g_ascii_strcasecmp ("none", value)) { style = html_style_set_clear (style, HTML_CLEAR_NONE); } } else if (!g_ascii_strcasecmp ("href", attr)) { /*a*/ if (!style) style = html_style_new (); if (style->href) g_free (style->href); style->href = g_strdup(value); } else if (!g_ascii_strcasecmp ("src", attr)) { /*iframe, frame, img*/ if (!style) style = html_style_new (); if (style->url) g_free (style->url); style->url = g_strdup(value); } else if (!g_ascii_strcasecmp ("target", attr)) { if (!style) style = html_style_new (); if (style->target) g_free (style->target); style->target = g_strdup(value); } else if ( !g_ascii_strcasecmp ("list-style-type", attr)) { style = parse_list_type (style, value); } else if (!g_ascii_strcasecmp ("leftmargin", attr)) { if (!style) style = html_style_new (); style->leftmargin = atoi (value); } else if (!g_ascii_strcasecmp ("rightmargin", attr)) { if (!style) style = html_style_new (); style->rightmargin = atoi (value); } else if (!g_ascii_strcasecmp ("topmargin", attr)) { if (!style) style = html_style_new (); style->topmargin = atoi (value); } else if (!g_ascii_strcasecmp ("bottommargin", attr)) { if (!style) style = html_style_new (); style->bottommargin = atoi (value); } else if (!g_ascii_strcasecmp ("marginwidth", attr)) { if (!style) style = html_style_new (); style->leftmargin = style->rightmargin = atoi (value); } else if (!g_ascii_strcasecmp ("marginheight", attr)) { if (!style) style = html_style_new (); style->topmargin = style->bottommargin = atoi (value); } return style; }
HTMLStyle * html_style_add_attribute (HTMLStyle *style, const gchar *attr) { gchar **prop; prop = g_strsplit (attr, ";", 100); if (prop) { gint i; for (i = 0; prop[i]; i++) { gchar *text; text = g_strstrip (prop[i]); if (!g_ascii_strncasecmp ("color: ", text, 7)) { GdkColor color; if (html_parse_color (g_strstrip (text + 7), &color)) { HTMLColor *hc = html_color_new_from_gdk_color (&color); style = html_style_add_color (style, hc); html_color_unref (hc); } } else if (!g_ascii_strncasecmp ("background: ", text, 12)) { GdkColor color; if (html_parse_color (text + 12, &color)) { HTMLColor *hc = html_color_new_from_gdk_color (&color); style = html_style_add_background_color (style, hc); html_color_unref (hc); } } else if (!g_ascii_strncasecmp ("background-color: ", text, 18)) { GdkColor color; if (html_parse_color (text + 18, &color)) { HTMLColor *hc = html_color_new_from_gdk_color (&color); style = html_style_add_background_color (style, hc); html_color_unref (hc); } } else if (!g_ascii_strncasecmp ("background-image: ", text, 18)) { style = html_style_add_background_image (style, text + 18); } else if (!g_ascii_strncasecmp ("border: ", text, 8)) { style = parse_border (style, text + 8); } else if (!g_ascii_strncasecmp ("border-style: ", text, 14)) { style = parse_border_style (style, text + 14); } else if (!g_ascii_strncasecmp ("border-color: ", text, 14)) { style = parse_border_color (style, text + 14); } else if (!g_ascii_strncasecmp ("border-width: ", text, 14)) { style = parse_border_width (style, text + 14); } else if (!g_ascii_strncasecmp ("padding: ", text, 9)) { gchar *value = text + 9; style = html_style_set_padding (style, atoi (value)); } else if (!g_ascii_strncasecmp ("white-space: ", text, 13)) { /* normal, pre, nowrap, pre-wrap, pre-line, inherit */ /* if (!g_ascii_strcasecmp ("normal", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_NORMAL); } else if (!g_ascii_strcasecmp ("pre", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_PRE); } else if (!g_ascii_strcasecmp ("nowrap", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_NOWRAP); } else if (!g_ascii_strcasecmp ("pre-wrap", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_PRE_WRAP); } else if (!g_ascii_strcasecmp ("pre-line", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_PRE_LINE); } else if (!g_ascii_strcasecmp ("inherit", text + 13)) { style = html_style_set_white_space (style, HTML_WHITE_SPACE_INHERIT); } */ } else if (!g_ascii_strncasecmp ("text-decoration: none", text, 21)) { style = html_style_unset_decoration (style, ~GTK_HTML_FONT_STYLE_SIZE_MASK); } else if (!g_ascii_strncasecmp ("display: ", text, 9)) { gchar *value = text + 9; if (!g_ascii_strcasecmp ("block", value)) { style = html_style_set_display (style, DISPLAY_BLOCK); } else if (!g_ascii_strcasecmp ("inline", value)) { style = html_style_set_display (style, DISPLAY_INLINE); } else if (!g_ascii_strcasecmp ("none", value)) { style = html_style_set_display (style, DISPLAY_NONE); } else if (!g_ascii_strcasecmp ("inline-table", value)) { style = html_style_set_display (style, DISPLAY_INLINE_TABLE); } } else if (!g_ascii_strncasecmp ("text-align: center", text, 18)) { style = html_style_add_text_align (style, HTML_HALIGN_CENTER); } else if (!g_ascii_strncasecmp ("width: ", text, 7)) { style = html_style_add_width (style, text + 7); } else if (!g_ascii_strncasecmp ("height: ", text, 8)) { style = html_style_add_height (style, text + 8); } else if (!g_ascii_strncasecmp ("clear: ", text, 7)) { gchar *value = text + 7; if (!g_ascii_strcasecmp ("left", value)) { style = html_style_set_clear (style, HTML_CLEAR_LEFT); } else if (!g_ascii_strcasecmp ("right", value)) { style = html_style_set_clear (style, HTML_CLEAR_RIGHT); } else if (!g_ascii_strcasecmp ("both", value)) { style = html_style_set_clear (style, HTML_CLEAR_ALL); } else if (!g_ascii_strcasecmp ("inherit", value)) { style = html_style_set_clear (style, HTML_CLEAR_INHERIT); } else if (!g_ascii_strcasecmp ("none", value)) { style = html_style_set_clear (style, HTML_CLEAR_NONE); } } } g_strfreev (prop); } return style; }