/* simplistic HTML table border handling */ void html_table_borders(CSSBox *box, int border, int padding) { CSSProperty **last_prop; CSSBox *box1; if (box->tag == CSS_ID_td) { last_prop = &box->properties; while (*last_prop != NULL) last_prop = &(*last_prop)->next; if (border >= 1) { css_add_prop_unit(&last_prop, CSS_border_left_width, CSS_UNIT_PIXEL, border); css_add_prop_unit(&last_prop, CSS_border_right_width, CSS_UNIT_PIXEL, border); css_add_prop_unit(&last_prop, CSS_border_top_width, CSS_UNIT_PIXEL, border); css_add_prop_unit(&last_prop, CSS_border_bottom_width, CSS_UNIT_PIXEL, border); css_add_prop_int(&last_prop, CSS_border_left_style, CSS_BORDER_STYLE_RIDGE); css_add_prop_int(&last_prop, CSS_border_right_style, CSS_BORDER_STYLE_RIDGE); css_add_prop_int(&last_prop, CSS_border_top_style, CSS_BORDER_STYLE_RIDGE); css_add_prop_int(&last_prop, CSS_border_bottom_style, CSS_BORDER_STYLE_RIDGE); } if (padding >= 1) { css_add_prop_unit(&last_prop, CSS_padding_left, CSS_UNIT_PIXEL, padding); css_add_prop_unit(&last_prop, CSS_padding_right, CSS_UNIT_PIXEL, padding); css_add_prop_unit(&last_prop, CSS_padding_top, CSS_UNIT_PIXEL, padding); css_add_prop_unit(&last_prop, CSS_padding_bottom, CSS_UNIT_PIXEL, padding); } } if (box->content_type == CSS_CONTENT_TYPE_CHILDS) { for (box1 = box->u.child.first; box1 != NULL; box1 = box1->next) { html_table_borders(box1, border, padding); } } }
static void html_eval_tag(XMLState *s, CSSBox *box) { const char *value; CSSProperty *first_prop, **last_prop; QEColor color; int width, height, val, type; int border, padding; CSSPropertyValue arg; CSSPropertyValue args[2]; first_prop = NULL; last_prop = &first_prop; switch (box->tag) { case CSS_ID_img: parse_img: box->content_type = CSS_CONTENT_TYPE_IMAGE; box->u.image.content_alt = NULL; /* set alt content */ value = css_attr_str(box, CSS_ID_alt); if (!value) { /* if no alt, display the name of the image */ value = css_attr_str(box, CSS_ID_src); if (value) value = basename(value); } if (value && value[0] != '\0') { arg.type = CSS_VALUE_STRING; arg.u.str = strdup(value); css_add_prop(&last_prop, CSS_content_alt, &arg); } width = css_attr_int(box, CSS_ID_width, 0); if (width <= 0) width = DEFAULT_IMG_WIDTH; height = css_attr_int(box, CSS_ID_height, 0); if (height <= 0) height = DEFAULT_IMG_HEIGHT; css_add_prop_unit(&last_prop, CSS_width, CSS_UNIT_PIXEL, width); css_add_prop_unit(&last_prop, CSS_height, CSS_UNIT_PIXEL, height); /* border */ val = css_attr_int(box, CSS_ID_border, -1); if (val >= 0) { css_add_prop_unit(&last_prop, CSS_border_left_width, CSS_UNIT_PIXEL, val); css_add_prop_unit(&last_prop, CSS_border_right_width, CSS_UNIT_PIXEL, val); css_add_prop_unit(&last_prop, CSS_border_top_width, CSS_UNIT_PIXEL, val); css_add_prop_unit(&last_prop, CSS_border_bottom_width, CSS_UNIT_PIXEL, val); css_add_prop_int(&last_prop, CSS_border_left_style, CSS_BORDER_STYLE_SOLID); css_add_prop_int(&last_prop, CSS_border_right_style, CSS_BORDER_STYLE_SOLID); css_add_prop_int(&last_prop, CSS_border_top_style, CSS_BORDER_STYLE_SOLID); css_add_prop_int(&last_prop, CSS_border_bottom_style, CSS_BORDER_STYLE_SOLID); } /* margins */ val = css_attr_int(box, CSS_ID_hspace, -1); if (val >= 0) { css_add_prop_unit(&last_prop, CSS_margin_left, CSS_UNIT_PIXEL, val); css_add_prop_unit(&last_prop, CSS_margin_right, CSS_UNIT_PIXEL, val); } val = css_attr_int(box, CSS_ID_vspace, -1); if (val >= 0) { css_add_prop_unit(&last_prop, CSS_margin_top, CSS_UNIT_PIXEL, val); css_add_prop_unit(&last_prop, CSS_margin_bottom, CSS_UNIT_PIXEL, val); } break; case CSS_ID_body: value = css_attr_str(box, CSS_ID_text); if (value && !css_get_color(&color, value)) { css_add_prop_int(&last_prop, CSS_color, color); } /* we handle link by adding a new stylesheet entry */ value = css_attr_str(box, CSS_ID_link); if (value && !css_get_color(&color, value)) { CSSStyleSheetEntry *e; CSSSimpleSelector ss1, *ss = &ss1; CSSProperty **last_prop; CSSStyleSheetAttributeEntry **plast_attr; /* specific to <a href="xxx"> tag */ memset(ss, 0, sizeof(CSSSimpleSelector)); ss->tag = CSS_ID_a; plast_attr = &ss->attrs; add_attribute(&plast_attr, CSS_ID_href, CSS_ATTR_OP_SET, ""); e = add_style_entry(s->style_sheet, ss, CSS_MEDIA_ALL); /* add color property */ last_prop = &e->props; css_add_prop_int(&last_prop, CSS_color, color); } break; case CSS_ID_font: case CSS_ID_basefont: /* size */ value = css_attr_str(box, CSS_ID_size); if (value) { val = strtol(value, NULL, 10); if (value[0] == '+' || value[0] == '-') { /* relative size */ val += s->base_font; } if (val < 1) val = 1; else if (val > 7) val = 7; if (box->tag == CSS_ID_basefont) s->base_font = val; /* XXX: incorrect for basefont */ css_add_prop_unit(&last_prop, CSS_font_size, CSS_UNIT_IN, get_font_size(val - 1)); } /* color */ value = css_attr_str(box, CSS_ID_color); if (value && !css_get_color(&color, value)) { css_add_prop_int(&last_prop, CSS_color, color); } break; case CSS_ID_br: value = css_attr_strlower(box, CSS_ID_clear); if (value) { val = css_get_enum(value, "none,left,right,all"); if (val >= 0) { css_add_prop_int(&last_prop, CSS_clear, val + CSS_CLEAR_NONE); } } break; case CSS_ID_table: val = css_attr_int(box, CSS_ID_width, -1); if (val >= 0) { css_add_prop_unit(&last_prop, CSS_width, CSS_UNIT_PIXEL, val); } border = css_attr_int(box, CSS_ID_border, -1); if (border >= 0) { css_add_prop_unit(&last_prop, CSS_border_left_width, CSS_UNIT_PIXEL, border); css_add_prop_unit(&last_prop, CSS_border_right_width, CSS_UNIT_PIXEL, border); css_add_prop_unit(&last_prop, CSS_border_top_width, CSS_UNIT_PIXEL, border); css_add_prop_unit(&last_prop, CSS_border_bottom_width, CSS_UNIT_PIXEL, border); css_add_prop_int(&last_prop, CSS_border_left_style, CSS_BORDER_STYLE_GROOVE); css_add_prop_int(&last_prop, CSS_border_right_style, CSS_BORDER_STYLE_GROOVE); css_add_prop_int(&last_prop, CSS_border_top_style, CSS_BORDER_STYLE_GROOVE); css_add_prop_int(&last_prop, CSS_border_bottom_style, CSS_BORDER_STYLE_GROOVE); /* cell have a border of 1 pixel width */ if (border > 1) border = 1; } val = css_attr_int(box, CSS_ID_cellspacing, -1); if (val >= 0) { css_add_prop_unit(&last_prop, CSS_border_spacing_horizontal, CSS_UNIT_PIXEL, val); css_add_prop_unit(&last_prop, CSS_border_spacing_vertical, CSS_UNIT_PIXEL, val); } padding = css_attr_int(box, CSS_ID_cellpadding, -1); /* apply border styles to each cell (cannot be done exactly by CSS) */ if (border >= 1 || padding >= 1) html_table_borders(box, border, padding); break; case CSS_ID_col: case CSS_ID_colgroup: val = css_attr_int(box, CSS_ID_width, -1); if (val >= 0) { css_add_prop_unit(&last_prop, CSS_width, CSS_UNIT_PIXEL, val); } break; case CSS_ID_td: val = css_attr_int(box, CSS_ID_width, -1); if (val >= 0) { css_add_prop_unit(&last_prop, CSS_width, CSS_UNIT_PIXEL, val); } val = css_attr_int(box, CSS_ID_height, -1); if (val >= 0) { css_add_prop_unit(&last_prop, CSS_height, CSS_UNIT_PIXEL, val); } break; case CSS_ID_ol: case CSS_ID_li: /* NOTE: case is important */ /* XXX: currently cannot propagate for LI tag */ value = css_attr_str(box, CSS_ID_type); if (value) { val = css_get_enum(value, "1,a,A,i,I"); if (val >= 0) { val += CSS_LIST_STYLE_TYPE_DECIMAL; css_add_prop_int(&last_prop, CSS_list_style_type, val); } } /* XXX: add value, but needs a css extension */ if (box->tag == CSS_ID_ol) val = CSS_ID_start; else val = CSS_ID_value; /* NOTE: only works with digits */ val = css_attr_int(box, val, 0); if (val > 0) { args[0].type = CSS_VALUE_IDENT; args[0].u.val = CSS_ID_list_item; args[1].type = CSS_VALUE_INTEGER; args[1].u.val = val - 1; /* currently needs minus 1 */ css_add_prop_values(&last_prop, CSS_counter_reset, 2, args); } break; /* controls */ case CSS_ID_button: type = CSS_ID_submit; value = css_attr_strlower(box, CSS_ID_type); if (value) type = css_new_ident(value); if (type != CSS_ID_button && type != CSS_ID_reset) type = CSS_ID_submit; goto parse_input; case CSS_ID_input: type = CSS_ID_text; value = css_attr_strlower(box, CSS_ID_type); if (value) { type = css_new_ident(value); } else { CSSAttribute *attr; /* NOTE: we add an attribute for css rules */ attr = box_new_attr(CSS_ID_type, "text"); if (attr) { attr->next = box->attrs; box->attrs = attr; } } parse_input: if (type == CSS_ID_image) goto parse_img; if (type == CSS_ID_button || type == CSS_ID_reset || type == CSS_ID_submit || type == CSS_ID_text || type == CSS_ID_password || type == CSS_ID_file) { /* put text inside the box (XXX: use attr() in content attribute ? */ value = css_attr_str(box, CSS_ID_value); if (value) { css_set_text_string(box, value); } } /* size */ if (type == CSS_ID_text || type == CSS_ID_password) { val = css_attr_int(box, CSS_ID_size, 10); css_add_prop_unit(&last_prop, CSS_width, CSS_UNIT_EM, val << CSS_LENGTH_FRAC_BITS); } break; case CSS_ID_textarea: val = css_attr_int(box, CSS_ID_cols, 10); if (val < 1) val = 1; css_add_prop_unit(&last_prop, CSS_width, CSS_UNIT_EM, val << CSS_LENGTH_FRAC_BITS); val = css_attr_int(box, CSS_ID_rows, 1); if (val < 1) val = 1; css_add_prop_unit(&last_prop, CSS_height, CSS_UNIT_EM, val << CSS_LENGTH_FRAC_BITS); break; case CSS_ID_select: val = css_attr_int(box, CSS_ID_size, 1); if (val < 1) val = 1; css_add_prop_unit(&last_prop, CSS_height, CSS_UNIT_EM, val << CSS_LENGTH_FRAC_BITS); break; default: break; } /* generic attributes */ value = css_attr_str(box, CSS_ID_bgcolor); if (value && !css_get_color(&color, value)) { css_add_prop_int(&last_prop, CSS_background_color, color); } value = css_attr_strlower(box, CSS_ID_align); if (value) { switch (box->tag) { case CSS_ID_caption: /* use caption-side property for captions */ val = css_get_enum(value, "top,bottom,left,right"); if (val >= 0) { css_add_prop_int(&last_prop, CSS_caption_side, val); } break; case CSS_ID_img: /* floating images */ val = css_get_enum(value, "left,right"); if (val >= 0) { css_add_prop_int(&last_prop, CSS_float, val + CSS_FLOAT_LEFT); } break; case CSS_ID_table: val = css_get_enum(value, "left,right,center"); if (val == CSS_TEXT_ALIGN_LEFT || val == CSS_TEXT_ALIGN_RIGHT) { css_add_prop_int(&last_prop, CSS_float, val + CSS_FLOAT_LEFT); } else if (val == CSS_TEXT_ALIGN_CENTER) { css_add_prop_int(&last_prop, CSS_margin_left, CSS_AUTO); css_add_prop_int(&last_prop, CSS_margin_right, CSS_AUTO); } break; default: val = css_get_enum(value, "left,right,center"); if (val >= 0) { css_add_prop_int(&last_prop, CSS_text_align, val); } break; } } value = css_attr_strlower(box, CSS_ID_valign); if (value) { val = css_get_enum(value, "baseline,,,top,,middle,bottom"); if (val >= 0) { css_add_prop_int(&last_prop, CSS_vertical_align, val); } } val = css_attr_int(box, CSS_ID_colspan, 1); if (val > 1) { css_add_prop_unit(&last_prop, CSS_column_span, CSS_VALUE_INTEGER, val); } val = css_attr_int(box, CSS_ID_rowspan, 1); if (val > 1) { css_add_prop_unit(&last_prop, CSS_row_span, CSS_VALUE_INTEGER, val); } value = css_attr_str(box, CSS_ID_style); if (value) { CSSParseState b1, *b = &b1; b->ptr = NULL; b->line_num = s->line_num; /* XXX: slightly incorrect */ b->filename = s->filename; b->ignore_case = s->ignore_case; *last_prop = css_parse_properties(b, value); } box->properties = first_prop; }
void css_add_prop_int(CSSProperty ***last_prop, int property_index, int val) { css_add_prop_unit(last_prop, property_index, CSS_UNIT_NONE, val); }