2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
2003-04-04 19:19:32 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-08-28 00:09:57 +04:00
|
|
|
#include <stdbool.h>
|
2003-04-04 19:19:32 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#define CSS_INTERNALS
|
2003-04-06 22:09:34 +04:00
|
|
|
#define NDEBUG
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/css/css.h"
|
2003-07-15 02:57:45 +04:00
|
|
|
#include "netsurf/content/content.h"
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/utils/log.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
|
|
|
|
|
|
|
struct property_entry {
|
|
|
|
const char name[20];
|
2003-10-08 01:34:27 +04:00
|
|
|
void (*parse) (struct css_style * const s, const struct css_node * const v);
|
2003-04-04 19:19:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct colour_entry {
|
|
|
|
const char name[12];
|
|
|
|
colour col;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct font_size_entry {
|
|
|
|
const char name[10];
|
|
|
|
float size;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
static int compare_selectors(const struct css_node *n0, const struct css_node *n1);
|
2003-08-28 00:09:57 +04:00
|
|
|
static int parse_length(struct css_length * const length,
|
2003-10-08 01:34:27 +04:00
|
|
|
const struct css_node * const v, bool non_negative);
|
|
|
|
static colour parse_colour(const struct css_node * const v);
|
|
|
|
static void parse_background(struct css_style * const s, const struct css_node * v);
|
|
|
|
static void parse_background_color(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_clear(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_color(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_display(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_float(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_font(struct css_style * const s, const struct css_node * v);
|
2004-01-29 02:08:28 +03:00
|
|
|
static void parse_font_family(struct css_style * const s, const struct css_node * v);
|
2003-10-08 01:34:27 +04:00
|
|
|
static void parse_font_size(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_font_style(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_font_weight(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_height(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_line_height(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_text_align(struct css_style * const s, const struct css_node * const v);
|
2003-10-18 03:47:13 +04:00
|
|
|
static void parse_text_decoration(struct css_style * const s, const struct css_node * const v);
|
2003-10-10 22:13:36 +04:00
|
|
|
static void parse_visibility(struct css_style * const s, const struct css_node * const v);
|
2003-10-08 01:34:27 +04:00
|
|
|
static void parse_width(struct css_style * const s, const struct css_node * const v);
|
|
|
|
static void parse_white_space(struct css_style * const s, const struct css_node * const v);
|
2003-11-05 19:25:35 +03:00
|
|
|
static css_text_decoration css_text_decoration_parse(const char * const s);
|
2003-04-04 19:19:32 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* table of property parsers: MUST be sorted by property name */
|
|
|
|
static const struct property_entry property_table[] = {
|
2003-10-01 00:34:35 +04:00
|
|
|
{ "background", parse_background },
|
2003-04-04 19:19:32 +04:00
|
|
|
{ "background-color", parse_background_color },
|
|
|
|
{ "clear", parse_clear },
|
|
|
|
{ "color", parse_color },
|
|
|
|
{ "display", parse_display },
|
|
|
|
{ "float", parse_float },
|
2003-10-01 00:34:35 +04:00
|
|
|
{ "font", parse_font },
|
2004-01-29 00:48:10 +03:00
|
|
|
{ "font-family", parse_font_family },
|
2003-04-04 19:19:32 +04:00
|
|
|
{ "font-size", parse_font_size },
|
|
|
|
{ "font-style", parse_font_style },
|
|
|
|
{ "font-weight", parse_font_weight },
|
|
|
|
{ "height", parse_height },
|
|
|
|
{ "line-height", parse_line_height },
|
|
|
|
{ "text-align", parse_text_align },
|
2003-10-18 03:47:13 +04:00
|
|
|
{ "text-decoration", parse_text_decoration },
|
2003-10-10 22:13:36 +04:00
|
|
|
{ "visibility", parse_visibility },
|
2003-10-08 01:34:27 +04:00
|
|
|
{ "white-space", parse_white_space },
|
2003-04-04 19:19:32 +04:00
|
|
|
{ "width", parse_width },
|
|
|
|
};
|
|
|
|
|
2003-04-13 16:50:10 +04:00
|
|
|
/* table of standard colour names: MUST be sorted by colour name
|
|
|
|
* note: colour is 0xbbggrr */
|
2003-04-04 19:19:32 +04:00
|
|
|
static const struct colour_entry colour_table[] = {
|
2003-04-13 16:50:10 +04:00
|
|
|
{ "aqua", 0xffff00 },
|
2003-04-04 19:19:32 +04:00
|
|
|
{ "black", 0x000000 },
|
2003-04-13 16:50:10 +04:00
|
|
|
{ "blue", 0xff0000 },
|
2003-04-04 19:19:32 +04:00
|
|
|
{ "fuchsia", 0xff00ff },
|
|
|
|
{ "gray", 0x808080 },
|
|
|
|
{ "green", 0x008000 },
|
|
|
|
{ "lime", 0x00ff00 },
|
2003-04-13 16:50:10 +04:00
|
|
|
{ "maroon", 0x000080 },
|
|
|
|
{ "navy", 0x800000 },
|
|
|
|
{ "olive", 0x008080 },
|
2004-01-23 18:06:04 +03:00
|
|
|
{ "orange", 0x00a5ff },
|
2003-04-04 19:19:32 +04:00
|
|
|
{ "purple", 0x800080 },
|
2003-04-13 16:50:10 +04:00
|
|
|
{ "red", 0x0000ff },
|
2003-04-04 19:19:32 +04:00
|
|
|
{ "silver", 0xc0c0c0 },
|
2003-04-13 16:50:10 +04:00
|
|
|
{ "teal", 0x808000 },
|
2003-04-04 19:19:32 +04:00
|
|
|
{ "transparent", TRANSPARENT },
|
|
|
|
{ "white", 0xffffff },
|
2003-04-13 16:50:10 +04:00
|
|
|
{ "yellow", 0x00ffff },
|
2003-04-04 19:19:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* table of font sizes: MUST be sorted by name */
|
|
|
|
#define SIZE_FACTOR 1.2
|
|
|
|
static const struct font_size_entry font_size_table[] = {
|
|
|
|
{ "large", 1.0 * SIZE_FACTOR },
|
|
|
|
{ "medium", 1.0 },
|
|
|
|
{ "small", 1.0 / SIZE_FACTOR },
|
|
|
|
{ "x-large", 1.0 * SIZE_FACTOR * SIZE_FACTOR },
|
|
|
|
{ "x-small", 1.0 / (SIZE_FACTOR * SIZE_FACTOR) },
|
|
|
|
{ "xx-large", 1.0 * SIZE_FACTOR * SIZE_FACTOR * SIZE_FACTOR },
|
|
|
|
{ "xx-small", 1.0 / (SIZE_FACTOR * SIZE_FACTOR * SIZE_FACTOR) },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* css_add_ruleset -- add a ruleset to a stylesheet
|
|
|
|
*/
|
|
|
|
|
2003-04-06 22:09:34 +04:00
|
|
|
void css_add_ruleset(struct content *c,
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *selector,
|
|
|
|
struct css_node *declaration)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2003-09-28 21:37:43 +04:00
|
|
|
bool found;
|
2003-04-06 22:09:34 +04:00
|
|
|
struct css_stylesheet *stylesheet = c->data.css.css;
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *n, *sel, *next_sel, *prev;
|
2003-04-04 19:19:32 +04:00
|
|
|
struct css_style *style;
|
2003-04-05 19:35:55 +04:00
|
|
|
unsigned int hash;
|
|
|
|
|
|
|
|
for (sel = selector; sel != 0; sel = next_sel) {
|
|
|
|
next_sel = sel->next;
|
|
|
|
|
2003-04-13 16:50:10 +04:00
|
|
|
/*LOG(("+++"));
|
|
|
|
for (n = sel; n != 0; n = n->right) {
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *m;
|
2003-04-13 16:50:10 +04:00
|
|
|
if (n->data != 0)
|
|
|
|
fprintf(stderr, "%s", n->data);
|
|
|
|
for (m = n->left; m != 0; m = m->next) {
|
|
|
|
switch (m->type) {
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_ID: fprintf(stderr, "%s", m->data); break;
|
|
|
|
case CSS_NODE_CLASS: fprintf(stderr, ".%s", m->data); break;
|
2003-04-13 16:50:10 +04:00
|
|
|
default: fprintf(stderr, "unexpected node");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");*/
|
|
|
|
|
|
|
|
/* skip empty selectors */
|
|
|
|
if (sel->left == 0 && sel->data == 0)
|
|
|
|
continue;
|
|
|
|
|
2003-04-05 19:35:55 +04:00
|
|
|
/* check if this selector is already present */
|
2003-09-28 21:37:43 +04:00
|
|
|
found = false;
|
|
|
|
prev = 0;
|
2003-04-05 19:35:55 +04:00
|
|
|
hash = css_hash(sel->data);
|
2003-09-28 21:37:43 +04:00
|
|
|
/* selectors are ordered by specificity in the hash chain */
|
|
|
|
for (n = stylesheet->rule[hash];
|
|
|
|
n && n->specificity < sel->specificity;
|
|
|
|
n = n->next)
|
|
|
|
prev = n;
|
|
|
|
for ( ; n && n->specificity == sel->specificity;
|
|
|
|
n = n->next) {
|
|
|
|
prev = n;
|
|
|
|
if (compare_selectors(sel, n)) {
|
|
|
|
found = true;
|
2003-04-05 19:35:55 +04:00
|
|
|
break;
|
2003-09-28 21:37:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2003-04-05 19:35:55 +04:00
|
|
|
/* not present: construct a new struct css_style */
|
2003-04-06 01:38:06 +04:00
|
|
|
LOG(("constructing new style"));
|
2003-04-05 19:35:55 +04:00
|
|
|
style = xcalloc(1, sizeof(*style));
|
2003-04-06 01:38:06 +04:00
|
|
|
memcpy(style, &css_empty_style, sizeof(*style));
|
2003-04-05 19:35:55 +04:00
|
|
|
sel->style = style;
|
2003-09-28 21:37:43 +04:00
|
|
|
sel->next = n;
|
|
|
|
if (prev)
|
|
|
|
prev->next = sel;
|
|
|
|
else
|
|
|
|
stylesheet->rule[hash] = sel;
|
2003-04-11 01:44:45 +04:00
|
|
|
c->size += sizeof(*style);
|
2003-04-05 19:35:55 +04:00
|
|
|
} else {
|
|
|
|
/* already exists: augument existing style */
|
2003-04-06 01:38:06 +04:00
|
|
|
LOG(("augumenting existing style"));
|
2003-04-05 19:35:55 +04:00
|
|
|
style = n->style;
|
|
|
|
sel->next = 0;
|
|
|
|
css_free_node(sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in the declarations */
|
2003-04-05 20:24:43 +04:00
|
|
|
css_add_declarations(style, declaration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void css_add_declarations(struct css_style *style, struct css_node *declaration)
|
2003-04-05 20:24:43 +04:00
|
|
|
{
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *n;
|
2003-04-05 20:24:43 +04:00
|
|
|
for (n = declaration; n != 0; n = n->next) {
|
|
|
|
struct property_entry *p;
|
2003-10-08 01:34:27 +04:00
|
|
|
assert(n->type == CSS_NODE_DECLARATION && n->data != 0 && n->left != 0);
|
2003-04-05 20:24:43 +04:00
|
|
|
p = bsearch(n->data, property_table,
|
|
|
|
sizeof(property_table) / sizeof(property_table[0]),
|
2003-12-27 04:37:51 +03:00
|
|
|
sizeof(property_table[0]), (void*)strcasecmp);
|
2003-04-05 20:24:43 +04:00
|
|
|
if (p == 0)
|
|
|
|
continue;
|
|
|
|
p->parse(style, n->left);
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
2003-04-05 19:35:55 +04:00
|
|
|
}
|
2003-04-04 19:19:32 +04:00
|
|
|
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
int compare_selectors(const struct css_node *n0, const struct css_node *n1)
|
2003-04-05 19:35:55 +04:00
|
|
|
{
|
2003-10-08 01:34:27 +04:00
|
|
|
struct css_node *m0, *m1;
|
2003-04-06 01:38:06 +04:00
|
|
|
unsigned int count0 = 0, count1 = 0;
|
2003-04-13 16:50:10 +04:00
|
|
|
|
2003-04-05 19:35:55 +04:00
|
|
|
/* compare element name */
|
|
|
|
if (!((n0->data == 0 && n1->data == 0) ||
|
2003-04-06 01:38:06 +04:00
|
|
|
(n0->data != 0 && n1->data != 0 && strcmp(n0->data, n1->data) == 0)))
|
2003-04-05 19:35:55 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (n0->comb != n1->comb)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* compare classes and ids */
|
|
|
|
for (m0 = n0->left; m0 != 0; m0 = m0->next)
|
|
|
|
count0++;
|
|
|
|
for (m1 = n1->left; m1 != 0; m1 = m1->next)
|
|
|
|
count1++;
|
|
|
|
if (count0 != count1)
|
|
|
|
return 0;
|
|
|
|
for (m0 = n0->left; m0 != 0; m0 = m0->next) {
|
|
|
|
int found = 0;
|
|
|
|
for (m1 = n1->left; m1 != 0; m1 = m1->next) {
|
|
|
|
/* TODO: should this be case sensitive for IDs? */
|
2003-09-28 03:36:34 +04:00
|
|
|
if (m0->type == m1->type &&
|
|
|
|
strcasecmp(m0->data, m1->data) == 0 &&
|
|
|
|
((m0->data2 == 0 && m1->data2 == 0) ||
|
|
|
|
strcasecmp(m0->data2, m1->data2) == 0)) {
|
2003-04-05 19:35:55 +04:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
return 0;
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
2003-04-05 19:35:55 +04:00
|
|
|
/* compare ancestors */
|
2003-10-08 01:34:27 +04:00
|
|
|
if (n0->comb == CSS_COMB_NONE)
|
2003-04-05 19:35:55 +04:00
|
|
|
return 1;
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-04-05 19:35:55 +04:00
|
|
|
return compare_selectors(n0->right, n1->right);
|
|
|
|
}
|
2003-04-04 19:19:32 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* property parsers
|
|
|
|
*/
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
/* TODO: consider CSS_NODE_NUMBER whenever a value may be '0' */
|
2003-07-20 17:13:09 +04:00
|
|
|
|
2003-08-28 00:09:57 +04:00
|
|
|
int parse_length(struct css_length * const length,
|
2003-10-08 01:34:27 +04:00
|
|
|
const struct css_node * const v, bool non_negative)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
css_unit u;
|
2003-08-28 00:09:57 +04:00
|
|
|
float value;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (v->type != CSS_NODE_DIMENSION)
|
2003-04-04 19:19:32 +04:00
|
|
|
return 1;
|
|
|
|
u = css_unit_parse(v->data + strspn(v->data, "0123456789+-."));
|
|
|
|
if (u == CSS_UNIT_UNKNOWN)
|
|
|
|
return 1;
|
2003-08-28 00:09:57 +04:00
|
|
|
value = atof(v->data);
|
|
|
|
if (non_negative && value < 0)
|
|
|
|
return 1;
|
2003-04-04 19:19:32 +04:00
|
|
|
length->unit = u;
|
2003-08-28 00:09:57 +04:00
|
|
|
length->value = value;
|
2003-04-04 19:19:32 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-13 16:50:10 +04:00
|
|
|
colour named_colour(const char *name)
|
|
|
|
{
|
|
|
|
struct colour_entry *col;
|
|
|
|
col = bsearch(name, colour_table,
|
|
|
|
sizeof(colour_table) / sizeof(colour_table[0]),
|
2003-12-27 04:37:51 +03:00
|
|
|
sizeof(colour_table[0]), (void*)strcasecmp);
|
2003-04-13 16:50:10 +04:00
|
|
|
if (col == 0)
|
|
|
|
return TRANSPARENT;
|
|
|
|
return col->col;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
colour parse_colour(const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2003-10-01 00:34:35 +04:00
|
|
|
colour c = CSS_COLOR_NONE;
|
2003-04-04 19:19:32 +04:00
|
|
|
int len;
|
|
|
|
unsigned int r, g, b;
|
|
|
|
struct colour_entry *col;
|
|
|
|
|
|
|
|
switch (v->type) {
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_HASH:
|
2003-04-04 19:19:32 +04:00
|
|
|
len = strlen(v->data);
|
|
|
|
if (len == 4) {
|
|
|
|
if (sscanf(v->data + 1, "%1x%1x%1x", &r, &g, &b) == 3)
|
|
|
|
c = (b << 20) | (b << 16) | (g << 12) | (g << 8) | (r << 4) | r;
|
|
|
|
} else if (len == 7) {
|
|
|
|
if (sscanf(v->data + 1, "%2x%2x%2x", &r, &g, &b) == 3)
|
|
|
|
c = (b << 16) | (g << 8) | r;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_FUNCTION:
|
2003-04-04 19:19:32 +04:00
|
|
|
/* TODO: rgb(r, g, b) */
|
|
|
|
break;
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_IDENT:
|
2003-04-04 19:19:32 +04:00
|
|
|
col = bsearch(v->data, colour_table,
|
|
|
|
sizeof(colour_table) / sizeof(colour_table[0]),
|
2003-12-27 04:37:51 +03:00
|
|
|
sizeof(colour_table[0]), (void*)strcasecmp);
|
2003-04-04 19:19:32 +04:00
|
|
|
if (col != 0)
|
|
|
|
c = col->col;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_background(struct css_style * const s, const struct css_node * v)
|
2003-10-01 00:34:35 +04:00
|
|
|
{
|
|
|
|
colour c;
|
|
|
|
for (; v; v = v->next) {
|
|
|
|
switch (v->type) {
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_HASH:
|
|
|
|
case CSS_NODE_FUNCTION:
|
|
|
|
case CSS_NODE_IDENT:
|
2003-10-01 00:34:35 +04:00
|
|
|
c = parse_colour(v);
|
|
|
|
if (c != CSS_COLOR_NONE)
|
|
|
|
s->background_color = c;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_background_color(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2003-10-01 00:34:35 +04:00
|
|
|
colour c = parse_colour(v);
|
|
|
|
if (c != CSS_COLOR_NONE)
|
|
|
|
s->background_color = c;
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_clear(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
css_clear z;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (v->type != CSS_NODE_IDENT || v->next != 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
return;
|
|
|
|
z = css_clear_parse(v->data);
|
|
|
|
if (z != CSS_CLEAR_UNKNOWN)
|
|
|
|
s->clear = z;
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_color(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2003-10-01 00:34:35 +04:00
|
|
|
colour c = parse_colour(v);
|
|
|
|
if (c != CSS_COLOR_NONE)
|
|
|
|
s->color = c;
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_display(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
css_display z;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (v->type != CSS_NODE_IDENT || v->next != 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
return;
|
|
|
|
z = css_display_parse(v->data);
|
|
|
|
if (z != CSS_DISPLAY_UNKNOWN)
|
|
|
|
s->display = z;
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_float(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
css_float z;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (v->type != CSS_NODE_IDENT || v->next != 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
return;
|
|
|
|
z = css_float_parse(v->data);
|
|
|
|
if (z != CSS_FLOAT_UNKNOWN)
|
|
|
|
s->float_ = z;
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_font(struct css_style * const s, const struct css_node * v)
|
2003-10-01 00:34:35 +04:00
|
|
|
{
|
2004-01-29 02:08:28 +03:00
|
|
|
css_font_family ff;
|
2003-10-01 00:34:35 +04:00
|
|
|
css_font_style fs;
|
|
|
|
css_font_weight fw;
|
2004-01-29 00:48:10 +03:00
|
|
|
s->font_family = CSS_FONT_FAMILY_SANS_SERIF;
|
2003-10-01 00:34:35 +04:00
|
|
|
s->font_style = CSS_FONT_STYLE_NORMAL;
|
|
|
|
s->font_weight = CSS_FONT_WEIGHT_NORMAL;
|
|
|
|
s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE;
|
|
|
|
s->line_height.value.absolute = 1.3;
|
|
|
|
for (; v; v = v->next) {
|
|
|
|
switch (v->type) {
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_IDENT:
|
2004-01-29 00:48:10 +03:00
|
|
|
/* font-family */
|
|
|
|
ff = css_font_family_parse(v->data);
|
|
|
|
if (ff != CSS_FONT_FAMILY_UNKNOWN) {
|
|
|
|
s->font_family = ff;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-10-01 00:34:35 +04:00
|
|
|
/* font-style, font-variant, or font-weight */
|
|
|
|
fs = css_font_style_parse(v->data);
|
|
|
|
if (fs != CSS_FONT_STYLE_UNKNOWN) {
|
|
|
|
s->font_style = fs;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fw = css_font_weight_parse(v->data);
|
|
|
|
if (fw != CSS_FONT_WEIGHT_UNKNOWN) {
|
|
|
|
s->font_weight = fw;
|
|
|
|
break;
|
|
|
|
}
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_PERCENTAGE:
|
|
|
|
case CSS_NODE_DIMENSION:
|
2003-10-01 00:34:35 +04:00
|
|
|
parse_font_size(s, v);
|
|
|
|
break;
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_DELIM:
|
2003-10-01 00:34:35 +04:00
|
|
|
if (v->data[0] == '/' && v->data[1] == 0 &&
|
|
|
|
v->next) {
|
|
|
|
v = v->next;
|
|
|
|
parse_line_height(s, v);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-29 02:08:28 +03:00
|
|
|
void parse_font_family(struct css_style * const s, const struct css_node * v)
|
2004-01-29 00:48:10 +03:00
|
|
|
{
|
|
|
|
css_font_family z;
|
2004-01-29 02:08:28 +03:00
|
|
|
for (; v; v = v->next) {
|
|
|
|
switch (v->type) {
|
|
|
|
case CSS_NODE_IDENT:
|
|
|
|
z = css_font_family_parse(v->data);
|
|
|
|
if (z != CSS_FONT_FAMILY_UNKNOWN) {
|
|
|
|
s->font_family = z;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-01-29 00:48:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_font_size(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
struct font_size_entry *fs;
|
|
|
|
switch (v->type) {
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_IDENT:
|
2003-04-04 19:19:32 +04:00
|
|
|
fs = bsearch(v->data, font_size_table,
|
|
|
|
sizeof(font_size_table) / sizeof(font_size_table[0]),
|
2003-12-27 04:37:51 +03:00
|
|
|
sizeof(font_size_table[0]), (void*)strcasecmp);
|
2003-04-04 19:19:32 +04:00
|
|
|
if (fs != 0) {
|
|
|
|
s->font_size.size = CSS_FONT_SIZE_LENGTH;
|
|
|
|
s->font_size.value.length.unit = CSS_UNIT_PT;
|
2003-09-09 02:47:38 +04:00
|
|
|
s->font_size.value.length.value = fs->size * 10;
|
2003-04-04 19:19:32 +04:00
|
|
|
} else if (strcasecmp(v->data, "larger") == 0) {
|
|
|
|
s->font_size.size = CSS_FONT_SIZE_PERCENT;
|
|
|
|
s->font_size.value.percent = SIZE_FACTOR * 100;
|
|
|
|
} else if (strcmp(v->data, "smaller") == 0) {
|
|
|
|
s->font_size.size = CSS_FONT_SIZE_PERCENT;
|
|
|
|
s->font_size.value.percent = 1 / SIZE_FACTOR * 100;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_PERCENTAGE:
|
2003-04-04 19:19:32 +04:00
|
|
|
s->font_size.size = CSS_FONT_SIZE_PERCENT;
|
|
|
|
s->font_size.value.percent = atof(v->data);
|
|
|
|
break;
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
case CSS_NODE_DIMENSION:
|
2003-08-28 00:09:57 +04:00
|
|
|
if (parse_length(&s->font_size.value.length, v, true) == 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
s->font_size.size = CSS_FONT_SIZE_LENGTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_font_style(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
css_font_style z;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (v->type != CSS_NODE_IDENT || v->next != 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
return;
|
|
|
|
z = css_font_style_parse(v->data);
|
|
|
|
if (z != CSS_FONT_STYLE_UNKNOWN)
|
|
|
|
s->font_style = z;
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_font_weight(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
css_font_weight z;
|
2004-01-29 02:08:28 +03:00
|
|
|
if ((v->type != CSS_NODE_IDENT && v->type != CSS_NODE_NUMBER) || v->next != 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
return;
|
|
|
|
z = css_font_weight_parse(v->data);
|
|
|
|
if (z != CSS_FONT_WEIGHT_UNKNOWN)
|
|
|
|
s->font_weight = z;
|
|
|
|
}
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_height(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2003-10-08 01:34:27 +04:00
|
|
|
if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "auto") == 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
s->height.height = CSS_HEIGHT_AUTO;
|
2003-10-08 01:34:27 +04:00
|
|
|
else if (v->type == CSS_NODE_DIMENSION && parse_length(&s->height.length, v, true) == 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
s->height.height = CSS_HEIGHT_LENGTH;
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_line_height(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2003-10-08 01:34:27 +04:00
|
|
|
if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "normal") == 0) {
|
2003-04-04 19:19:32 +04:00
|
|
|
s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE;
|
2003-10-01 00:34:35 +04:00
|
|
|
s->line_height.value.absolute = 1.3;
|
2003-10-08 01:34:27 +04:00
|
|
|
} else if (v->type == CSS_NODE_PERCENTAGE) {
|
2003-04-04 19:19:32 +04:00
|
|
|
s->line_height.size = CSS_LINE_HEIGHT_PERCENT;
|
|
|
|
s->line_height.value.percent = atof(v->data);
|
2003-10-08 01:34:27 +04:00
|
|
|
} else if (v->type == CSS_NODE_DIMENSION &&
|
2003-08-28 00:09:57 +04:00
|
|
|
parse_length(&s->line_height.value.length, v, true) == 0) {
|
2003-04-04 19:19:32 +04:00
|
|
|
s->line_height.size = CSS_LINE_HEIGHT_LENGTH;
|
2003-10-08 01:34:27 +04:00
|
|
|
} else if (v->type == CSS_NODE_NUMBER) {
|
2003-07-20 17:13:09 +04:00
|
|
|
s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE;
|
2003-07-20 17:58:12 +04:00
|
|
|
s->line_height.value.absolute = atof(v->data);
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_text_align(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
|
|
|
css_text_align z;
|
2003-10-08 01:34:27 +04:00
|
|
|
if (v->type != CSS_NODE_IDENT || v->next != 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
return;
|
|
|
|
z = css_text_align_parse(v->data);
|
|
|
|
if (z != CSS_TEXT_ALIGN_UNKNOWN)
|
|
|
|
s->text_align = z;
|
|
|
|
}
|
|
|
|
|
2003-10-18 03:47:13 +04:00
|
|
|
void parse_text_decoration(struct css_style * const s, const struct css_node * const v)
|
|
|
|
{
|
2003-12-27 04:37:51 +03:00
|
|
|
struct css_node *temp;
|
2003-10-18 03:47:13 +04:00
|
|
|
css_text_decoration z;
|
2003-11-05 19:25:35 +03:00
|
|
|
if (v->type != CSS_NODE_IDENT)
|
2003-10-18 03:47:13 +04:00
|
|
|
return;
|
|
|
|
z = css_text_decoration_parse(v->data);
|
2003-11-05 19:25:35 +03:00
|
|
|
if (z == CSS_TEXT_DECORATION_INHERIT || z == CSS_TEXT_DECORATION_NONE) {
|
|
|
|
if (v->next != 0)
|
|
|
|
return;
|
2003-10-18 03:47:13 +04:00
|
|
|
s->text_decoration = z;
|
2003-11-05 19:25:35 +03:00
|
|
|
}
|
|
|
|
if (z != CSS_TEXT_DECORATION_UNKNOWN)
|
|
|
|
s->text_decoration |= z;
|
2003-12-27 04:37:51 +03:00
|
|
|
for (temp = v->next; temp; temp = temp->next) {
|
|
|
|
z = css_text_decoration_parse(temp->data);
|
2003-11-05 19:25:35 +03:00
|
|
|
if (z != CSS_TEXT_DECORATION_UNKNOWN)
|
|
|
|
s->text_decoration |= z;
|
|
|
|
}
|
2003-10-18 03:47:13 +04:00
|
|
|
}
|
|
|
|
|
2003-10-10 22:13:36 +04:00
|
|
|
void parse_visibility(struct css_style * const s, const struct css_node * const v)
|
|
|
|
{
|
|
|
|
css_visibility z;
|
|
|
|
if (v->type != CSS_NODE_IDENT || v->next != 0)
|
|
|
|
return;
|
|
|
|
z = css_visibility_parse(v->data);
|
|
|
|
if (z != CSS_VISIBILITY_UNKNOWN)
|
|
|
|
s->visibility = z;
|
|
|
|
}
|
|
|
|
|
2003-10-08 01:34:27 +04:00
|
|
|
void parse_width(struct css_style * const s, const struct css_node * const v)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2003-10-08 01:34:27 +04:00
|
|
|
if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "auto") == 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
s->width.width = CSS_WIDTH_AUTO;
|
2003-10-08 01:34:27 +04:00
|
|
|
else if (v->type == CSS_NODE_PERCENTAGE) {
|
2003-04-04 19:19:32 +04:00
|
|
|
s->width.width = CSS_WIDTH_PERCENT;
|
|
|
|
s->width.value.percent = atof(v->data);
|
2003-10-08 01:34:27 +04:00
|
|
|
} else if (v->type == CSS_NODE_DIMENSION &&
|
2003-08-28 00:09:57 +04:00
|
|
|
parse_length(&s->width.value.length, v, true) == 0)
|
2003-04-04 19:19:32 +04:00
|
|
|
s->width.width = CSS_WIDTH_LENGTH;
|
|
|
|
}
|
2003-10-08 01:34:27 +04:00
|
|
|
|
|
|
|
void parse_white_space(struct css_style * const s, const struct css_node * const v)
|
|
|
|
{
|
|
|
|
css_white_space z;
|
|
|
|
if (v->type != CSS_NODE_IDENT || v->next != 0)
|
|
|
|
return;
|
|
|
|
z = css_white_space_parse(v->data);
|
|
|
|
if (z != CSS_WHITE_SPACE_UNKNOWN)
|
|
|
|
s->white_space = z;
|
|
|
|
}
|
2003-11-05 19:25:35 +03:00
|
|
|
|
|
|
|
css_text_decoration css_text_decoration_parse(const char * const s)
|
|
|
|
{
|
|
|
|
if (strcasecmp(s, "inherit") == 0) return CSS_TEXT_DECORATION_INHERIT;
|
|
|
|
if (strcasecmp(s, "none") == 0) return CSS_TEXT_DECORATION_NONE;
|
|
|
|
if (strcasecmp(s, "blink") == 0) return CSS_TEXT_DECORATION_BLINK;
|
|
|
|
if (strcasecmp(s, "line-through") == 0) return CSS_TEXT_DECORATION_LINE_THROUGH;
|
|
|
|
if (strcasecmp(s, "overline") == 0) return CSS_TEXT_DECORATION_OVERLINE;
|
|
|
|
if (strcasecmp(s, "underline") == 0) return CSS_TEXT_DECORATION_UNDERLINE;
|
|
|
|
return CSS_TEXT_DECORATION_UNKNOWN;
|
|
|
|
}
|
2004-01-29 00:48:10 +03:00
|
|
|
|