mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-24 21:16:50 +03:00
[project @ 2003-09-30 20:34:35 by bursa]
Implement background and font properties. svn path=/import/netsurf/; revision=336
This commit is contained in:
parent
63822e9469
commit
ba64beed38
20
css/css.c
20
css/css.c
@ -577,7 +577,8 @@ void css_dump_style(const struct css_style * const style)
|
|||||||
fprintf(stderr, "color: #%lx; ", style->color);
|
fprintf(stderr, "color: #%lx; ", style->color);
|
||||||
fprintf(stderr, "display: %s; ", css_display_name[style->display]);
|
fprintf(stderr, "display: %s; ", css_display_name[style->display]);
|
||||||
fprintf(stderr, "float: %s; ", css_float_name[style->float_]);
|
fprintf(stderr, "float: %s; ", css_float_name[style->float_]);
|
||||||
fprintf(stderr, "font-size: ");
|
fprintf(stderr, "font: %s %s ", css_font_style_name[style->font_style],
|
||||||
|
css_font_weight_name[style->font_weight]);
|
||||||
switch (style->font_size.size) {
|
switch (style->font_size.size) {
|
||||||
case CSS_FONT_SIZE_ABSOLUTE: fprintf(stderr, "[%g]", style->font_size.value.absolute); break;
|
case CSS_FONT_SIZE_ABSOLUTE: fprintf(stderr, "[%g]", style->font_size.value.absolute); break;
|
||||||
case CSS_FONT_SIZE_LENGTH: dump_length(&style->font_size.value.length); break;
|
case CSS_FONT_SIZE_LENGTH: dump_length(&style->font_size.value.length); break;
|
||||||
@ -585,15 +586,7 @@ void css_dump_style(const struct css_style * const style)
|
|||||||
case CSS_FONT_SIZE_INHERIT: fprintf(stderr, "inherit"); break;
|
case CSS_FONT_SIZE_INHERIT: fprintf(stderr, "inherit"); break;
|
||||||
default: fprintf(stderr, "UNKNOWN"); break;
|
default: fprintf(stderr, "UNKNOWN"); break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "; ");
|
fprintf(stderr, "/");
|
||||||
fprintf(stderr, "height: ");
|
|
||||||
switch (style->height.height) {
|
|
||||||
case CSS_HEIGHT_AUTO: fprintf(stderr, "auto"); break;
|
|
||||||
case CSS_HEIGHT_LENGTH: dump_length(&style->height.length); break;
|
|
||||||
default: fprintf(stderr, "UNKNOWN"); break;
|
|
||||||
}
|
|
||||||
fprintf(stderr, "; ");
|
|
||||||
fprintf(stderr, "line-height: ");
|
|
||||||
switch (style->line_height.size) {
|
switch (style->line_height.size) {
|
||||||
case CSS_LINE_HEIGHT_ABSOLUTE: fprintf(stderr, "[%g]", style->line_height.value.absolute); break;
|
case CSS_LINE_HEIGHT_ABSOLUTE: fprintf(stderr, "[%g]", style->line_height.value.absolute); break;
|
||||||
case CSS_LINE_HEIGHT_LENGTH: dump_length(&style->line_height.value.length); break;
|
case CSS_LINE_HEIGHT_LENGTH: dump_length(&style->line_height.value.length); break;
|
||||||
@ -602,6 +595,13 @@ void css_dump_style(const struct css_style * const style)
|
|||||||
default: fprintf(stderr, "UNKNOWN"); break;
|
default: fprintf(stderr, "UNKNOWN"); break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "; ");
|
fprintf(stderr, "; ");
|
||||||
|
fprintf(stderr, "height: ");
|
||||||
|
switch (style->height.height) {
|
||||||
|
case CSS_HEIGHT_AUTO: fprintf(stderr, "auto"); break;
|
||||||
|
case CSS_HEIGHT_LENGTH: dump_length(&style->height.length); break;
|
||||||
|
default: fprintf(stderr, "UNKNOWN"); break;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "; ");
|
||||||
fprintf(stderr, "text-align: %s; ", css_text_align_name[style->text_align]);
|
fprintf(stderr, "text-align: %s; ", css_text_align_name[style->text_align]);
|
||||||
fprintf(stderr, "width: ");
|
fprintf(stderr, "width: ");
|
||||||
switch (style->width.width) {
|
switch (style->width.width) {
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
typedef unsigned long colour; /* 0xbbggrr */
|
typedef unsigned long colour; /* 0xbbggrr */
|
||||||
#define TRANSPARENT 0x1000000
|
#define TRANSPARENT 0x1000000
|
||||||
#define CSS_COLOR_INHERIT 0x2000000
|
#define CSS_COLOR_INHERIT 0x2000000
|
||||||
|
#define CSS_COLOR_NONE 0x3000000
|
||||||
|
|
||||||
struct css_length {
|
struct css_length {
|
||||||
float value;
|
float value;
|
||||||
|
@ -37,11 +37,13 @@ static int compare_selectors(const struct node *n0, const struct node *n1);
|
|||||||
static int parse_length(struct css_length * const length,
|
static int parse_length(struct css_length * const length,
|
||||||
const struct node * const v, bool non_negative);
|
const struct node * const v, bool non_negative);
|
||||||
static colour parse_colour(const struct node * const v);
|
static colour parse_colour(const struct node * const v);
|
||||||
|
static void parse_background(struct css_style * const s, const struct node * v);
|
||||||
static void parse_background_color(struct css_style * const s, const struct node * const v);
|
static void parse_background_color(struct css_style * const s, const struct node * const v);
|
||||||
static void parse_clear(struct css_style * const s, const struct node * const v);
|
static void parse_clear(struct css_style * const s, const struct node * const v);
|
||||||
static void parse_color(struct css_style * const s, const struct node * const v);
|
static void parse_color(struct css_style * const s, const struct node * const v);
|
||||||
static void parse_display(struct css_style * const s, const struct node * const v);
|
static void parse_display(struct css_style * const s, const struct node * const v);
|
||||||
static void parse_float(struct css_style * const s, const struct node * const v);
|
static void parse_float(struct css_style * const s, const struct node * const v);
|
||||||
|
static void parse_font(struct css_style * const s, const struct node * v);
|
||||||
static void parse_font_size(struct css_style * const s, const struct node * const v);
|
static void parse_font_size(struct css_style * const s, const struct node * const v);
|
||||||
static void parse_font_style(struct css_style * const s, const struct node * const v);
|
static void parse_font_style(struct css_style * const s, const struct node * const v);
|
||||||
static void parse_font_weight(struct css_style * const s, const struct node * const v);
|
static void parse_font_weight(struct css_style * const s, const struct node * const v);
|
||||||
@ -53,11 +55,13 @@ static void parse_width(struct css_style * const s, const struct node * const v)
|
|||||||
|
|
||||||
/* table of property parsers: MUST be sorted by property name */
|
/* table of property parsers: MUST be sorted by property name */
|
||||||
static const struct property_entry property_table[] = {
|
static const struct property_entry property_table[] = {
|
||||||
|
{ "background", parse_background },
|
||||||
{ "background-color", parse_background_color },
|
{ "background-color", parse_background_color },
|
||||||
{ "clear", parse_clear },
|
{ "clear", parse_clear },
|
||||||
{ "color", parse_color },
|
{ "color", parse_color },
|
||||||
{ "display", parse_display },
|
{ "display", parse_display },
|
||||||
{ "float", parse_float },
|
{ "float", parse_float },
|
||||||
|
{ "font", parse_font },
|
||||||
{ "font-size", parse_font_size },
|
{ "font-size", parse_font_size },
|
||||||
{ "font-style", parse_font_style },
|
{ "font-style", parse_font_style },
|
||||||
{ "font-weight", parse_font_weight },
|
{ "font-weight", parse_font_weight },
|
||||||
@ -282,7 +286,7 @@ colour named_colour(const char *name)
|
|||||||
|
|
||||||
colour parse_colour(const struct node * const v)
|
colour parse_colour(const struct node * const v)
|
||||||
{
|
{
|
||||||
colour c = TRANSPARENT;
|
colour c = CSS_COLOR_NONE;
|
||||||
int len;
|
int len;
|
||||||
unsigned int r, g, b;
|
unsigned int r, g, b;
|
||||||
struct colour_entry *col;
|
struct colour_entry *col;
|
||||||
@ -319,9 +323,29 @@ colour parse_colour(const struct node * const v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void parse_background(struct css_style * const s, const struct node * v)
|
||||||
|
{
|
||||||
|
colour c;
|
||||||
|
for (; v; v = v->next) {
|
||||||
|
switch (v->type) {
|
||||||
|
case NODE_HASH:
|
||||||
|
case NODE_FUNCTION:
|
||||||
|
case NODE_IDENT:
|
||||||
|
c = parse_colour(v);
|
||||||
|
if (c != CSS_COLOR_NONE)
|
||||||
|
s->background_color = c;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void parse_background_color(struct css_style * const s, const struct node * const v)
|
void parse_background_color(struct css_style * const s, const struct node * const v)
|
||||||
{
|
{
|
||||||
s->background_color = parse_colour(v);
|
colour c = parse_colour(v);
|
||||||
|
if (c != CSS_COLOR_NONE)
|
||||||
|
s->background_color = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_clear(struct css_style * const s, const struct node * const v)
|
void parse_clear(struct css_style * const s, const struct node * const v)
|
||||||
@ -336,7 +360,9 @@ void parse_clear(struct css_style * const s, const struct node * const v)
|
|||||||
|
|
||||||
void parse_color(struct css_style * const s, const struct node * const v)
|
void parse_color(struct css_style * const s, const struct node * const v)
|
||||||
{
|
{
|
||||||
s->color = parse_colour(v);
|
colour c = parse_colour(v);
|
||||||
|
if (c != CSS_COLOR_NONE)
|
||||||
|
s->color = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_display(struct css_style * const s, const struct node * const v)
|
void parse_display(struct css_style * const s, const struct node * const v)
|
||||||
@ -359,6 +385,45 @@ void parse_float(struct css_style * const s, const struct node * const v)
|
|||||||
s->float_ = z;
|
s->float_ = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parse_font(struct css_style * const s, const struct node * v)
|
||||||
|
{
|
||||||
|
css_font_style fs;
|
||||||
|
css_font_weight fw;
|
||||||
|
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) {
|
||||||
|
case NODE_IDENT:
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
case NODE_PERCENTAGE:
|
||||||
|
case NODE_DIMENSION:
|
||||||
|
parse_font_size(s, v);
|
||||||
|
break;
|
||||||
|
case NODE_DELIM:
|
||||||
|
if (v->data[0] == '/' && v->data[1] == 0 &&
|
||||||
|
v->next) {
|
||||||
|
v = v->next;
|
||||||
|
parse_line_height(s, v);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void parse_font_size(struct css_style * const s, const struct node * const v)
|
void parse_font_size(struct css_style * const s, const struct node * const v)
|
||||||
{
|
{
|
||||||
struct font_size_entry *fs;
|
struct font_size_entry *fs;
|
||||||
@ -426,7 +491,7 @@ void parse_line_height(struct css_style * const s, const struct node * const v)
|
|||||||
{
|
{
|
||||||
if (v->type == NODE_IDENT && strcasecmp(v->data, "normal") == 0) {
|
if (v->type == NODE_IDENT && strcasecmp(v->data, "normal") == 0) {
|
||||||
s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE;
|
s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE;
|
||||||
s->line_height.value.absolute = 1.0;
|
s->line_height.value.absolute = 1.3;
|
||||||
} else if (v->type == NODE_PERCENTAGE) {
|
} else if (v->type == NODE_PERCENTAGE) {
|
||||||
s->line_height.size = CSS_LINE_HEIGHT_PERCENT;
|
s->line_height.size = CSS_LINE_HEIGHT_PERCENT;
|
||||||
s->line_height.value.percent = atof(v->data);
|
s->line_height.value.percent = atof(v->data);
|
||||||
|
Loading…
Reference in New Issue
Block a user