[project @ 2003-11-05 16:25:35 by bursa]

Improved text-decoration support.

svn path=/import/netsurf/; revision=403
This commit is contained in:
James Bursa 2003-11-05 16:25:35 +00:00
parent 2b8e469f19
commit b1a8dce16c
5 changed files with 86 additions and 55 deletions

View File

@ -83,7 +83,7 @@ const struct css_style css_blank_style = {
{ CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } },
{ CSS_LINE_HEIGHT_INHERIT, { 1.3 } },
CSS_TEXT_ALIGN_INHERIT,
CSS_TEXT_DECORATION_NONE,
CSS_TEXT_DECORATION_INHERIT,
CSS_VISIBILITY_INHERIT,
{ CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } },
CSS_WHITE_SPACE_INHERIT
@ -601,7 +601,7 @@ void css_parse_property_list(struct css_style * style, char * str)
static void dump_length(const struct css_length * const length)
{
fprintf(stderr, "%g%s", length->value,
css_unit_name[length->unit]);
css_unit_name[length->unit]);
}
void css_dump_style(const struct css_style * const style)
@ -638,7 +638,21 @@ void css_dump_style(const struct css_style * const style)
}
fprintf(stderr, "; ");
fprintf(stderr, "text-align: %s; ", css_text_align_name[style->text_align]);
fprintf(stderr, "text-decoration: %s; ", css_text_decoration_name[style->text_decoration]);
fprintf(stderr, "text-decoration:");
switch (style->text_decoration) {
case CSS_TEXT_DECORATION_NONE: fprintf(stderr, " none"); break;
case CSS_TEXT_DECORATION_INHERIT: fprintf(stderr, " inherit"); break;
default:
if (style->text_decoration & CSS_TEXT_DECORATION_UNDERLINE)
fprintf(stderr, " underline");
if (style->text_decoration & CSS_TEXT_DECORATION_OVERLINE)
fprintf(stderr, " overline");
if (style->text_decoration & CSS_TEXT_DECORATION_LINE_THROUGH)
fprintf(stderr, " line-through");
if (style->text_decoration & CSS_TEXT_DECORATION_BLINK)
fprintf(stderr, " blink");
}
fprintf(stderr, "; ");
fprintf(stderr, "visibility: %s; ", css_visibility_name[style->visibility]);
fprintf(stderr, "width: ");
switch (style->width.width) {
@ -693,6 +707,12 @@ void css_cascade(struct css_style * const style, const struct css_style * const
{
float f;
/* text-decoration: approximate CSS 2.1 by inheriting into inline elements */
if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT)
style->text_decoration = apply->text_decoration;
/* if (style->display == CSS_DISPLAY_INLINE && apply->display != CSS_DISPLAY_INLINE)
style->text_decoration = CSS_TEXT_DECORATION_NONE;*/
if (apply->background_color != CSS_COLOR_INHERIT)
style->background_color = apply->background_color;
if (apply->clear != CSS_CLEAR_INHERIT)
@ -713,10 +733,8 @@ void css_cascade(struct css_style * const style, const struct css_style * const
style->line_height = apply->line_height;
if (apply->text_align != CSS_TEXT_ALIGN_INHERIT)
style->text_align = apply->text_align;
if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT)
style->text_decoration = apply->text_decoration;
if (apply->visibility != CSS_VISIBILITY_INHERIT)
style->visibility = apply->visibility;
style->visibility = apply->visibility;
if (apply->width.width != CSS_WIDTH_INHERIT)
style->width = apply->width;
if (apply->white_space != CSS_WHITE_SPACE_INHERIT)
@ -786,9 +804,9 @@ void css_merge(struct css_style * const style, const struct css_style * const ap
style->line_height = apply->line_height;
if (apply->text_align != CSS_TEXT_ALIGN_INHERIT)
style->text_align = apply->text_align;
if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT)
if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT)
style->text_decoration = apply->text_decoration;
if (apply->visibility != CSS_VISIBILITY_INHERIT)
if (apply->visibility != CSS_VISIBILITY_INHERIT)
style->visibility = apply->visibility;
if (apply->width.width != CSS_WIDTH_INHERIT)
style->width = apply->width;

View File

@ -26,6 +26,16 @@ struct css_length {
css_unit unit;
};
typedef enum {
CSS_TEXT_DECORATION_NONE = 0x0,
CSS_TEXT_DECORATION_INHERIT = 0x1,
CSS_TEXT_DECORATION_UNDERLINE = 0x2,
CSS_TEXT_DECORATION_BLINK = 0x4,
CSS_TEXT_DECORATION_LINE_THROUGH = 0x8,
CSS_TEXT_DECORATION_OVERLINE = 0x10,
CSS_TEXT_DECORATION_UNKNOWN = 0x1000
} css_text_decoration;
struct css_style {
colour background_color;
css_clear clear;

View File

@ -15,7 +15,6 @@ css_list_style_position outside inside
css_list_style_type disc circle square decimal lower_alpha lower_roman upper_alpha upper_roman none
css_margin auto length percent
css_text_align inherit left right center justify
css_text_decoration inherit none blink line-through overline underline
css_text_transform none capitalize lowercase uppercase
css_vertical_align baseline bottom middle sub super text_bottom text_top top percent
css_visibility inherit visible hidden

View File

@ -54,6 +54,7 @@ static void parse_text_decoration(struct css_style * const s, const struct css_n
static void parse_visibility(struct css_style * const s, const struct css_node * const v);
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);
static css_text_decoration css_text_decoration_parse(const char * const s);
/* table of property parsers: MUST be sorted by property name */
@ -90,6 +91,7 @@ static const struct colour_entry colour_table[] = {
{ "maroon", 0x000080 },
{ "navy", 0x800000 },
{ "olive", 0x008080 },
{ "orange", 0xffa500 },
{ "purple", 0x800080 },
{ "red", 0x0000ff },
{ "silver", 0xc0c0c0 },
@ -523,11 +525,21 @@ void parse_text_align(struct css_style * const s, const struct css_node * const
void parse_text_decoration(struct css_style * const s, const struct css_node * const v)
{
css_text_decoration z;
if (v->type != CSS_NODE_IDENT || v->next != 0)
if (v->type != CSS_NODE_IDENT)
return;
z = css_text_decoration_parse(v->data);
if (z != CSS_TEXT_DECORATION_UNKNOWN)
if (z == CSS_TEXT_DECORATION_INHERIT || z == CSS_TEXT_DECORATION_NONE) {
if (v->next != 0)
return;
s->text_decoration = z;
}
if (z != CSS_TEXT_DECORATION_UNKNOWN)
s->text_decoration |= z;
for (v = v->next; v; v = v->next) {
z = css_text_decoration_parse(v->data);
if (z != CSS_TEXT_DECORATION_UNKNOWN)
s->text_decoration |= z;
}
}
void parse_visibility(struct css_style * const s, const struct css_node * const v)
@ -561,3 +573,14 @@ void parse_white_space(struct css_style * const s, const struct css_node * const
if (z != CSS_WHITE_SPACE_UNKNOWN)
s->white_space = z;
}
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;
}

View File

@ -76,7 +76,7 @@ void html_redraw_box(struct content *content, struct box * box,
struct box *c;
char *select_text;
struct form_option *opt;
int width, height, x0, y0, x1, y1;
int width, height, x0, y0, x1, y1, colour;
x += box->x * 2;
y -= box->y * 2;
@ -279,53 +279,34 @@ void html_redraw_box(struct content *content, struct box * box,
colourtrans_set_font_colours(box->font->handle, current_background_color << 8,
box->style->color << 8, 14, 0, 0, 0);
colour = box->style->color;
colour = ((((colour >> 16) + (current_background_color >> 16)) / 2) << 16)
| (((((colour >> 8) & 0xff) +
((current_background_color >> 8) & 0xff)) / 2) << 8)
| ((((colour & 0xff) +
(current_background_color & 0xff)) / 2) << 0);
colourtrans_set_gcol(colour << 8, colourtrans_USE_ECFS,
os_ACTION_OVERWRITE, 0);
if (box->style->text_decoration == CSS_TEXT_DECORATION_NONE ||
box->style->text_decoration == CSS_TEXT_DECORATION_BLINK) {
font_paint(box->font->handle, box->text,
if (box->style->text_decoration & CSS_TEXT_DECORATION_UNDERLINE) {
os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.8));
os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2, 0);
}
if (box->style->text_decoration & CSS_TEXT_DECORATION_OVERLINE) {
os_plot(os_MOVE_TO, x, y - (int) (box->height * 0.2));
os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2, 0);
}
if (box->style->text_decoration & CSS_TEXT_DECORATION_LINE_THROUGH) {
os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.0));
os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2, 0);
}
font_paint(box->font->handle, box->text,
font_OS_UNITS | font_GIVEN_FONT | font_KERN | font_GIVEN_LENGTH,
x, y - (int) (box->height * 1.5),
NULL, NULL, (int) box->length);
}
if (box->style->text_decoration == CSS_TEXT_DECORATION_UNDERLINE || (box->parent->parent->style->text_decoration == CSS_TEXT_DECORATION_UNDERLINE && box->parent->parent->type == BOX_BLOCK)) {
char ulctrl[3];
char *temp = xcalloc(strlen(box->text)+4,
sizeof(char));
sprintf(ulctrl, "%c%c%c", (char)25, (char)230,
(char)10);
sprintf(temp, "%s%s", ulctrl, box->text);
font_paint(box->font->handle, temp,
font_OS_UNITS | font_GIVEN_FONT | font_KERN | font_GIVEN_LENGTH,
x, y - (int) (box->height * 1.5),
NULL, NULL, (int) box->length + 3);
xfree(temp);
}
if (box->style->text_decoration == CSS_TEXT_DECORATION_LINE_THROUGH || (box->parent->parent->style->text_decoration == CSS_TEXT_DECORATION_LINE_THROUGH && box->parent->parent->type == BOX_BLOCK)) {
char ulctrl[3];
char *temp = xcalloc(strlen(box->text)+4,
sizeof(char));
sprintf(ulctrl, "%c%c%c", (char)25, (char)95,
(char)10);
sprintf(temp, "%s%s", ulctrl, box->text);
font_paint(box->font->handle, temp,
font_OS_UNITS | font_GIVEN_FONT | font_KERN | font_GIVEN_LENGTH,
x, y - (int) (box->height * 1.5),
NULL, NULL, (int) box->length + 3);
xfree(temp);
}
if (box->style->text_decoration == CSS_TEXT_DECORATION_OVERLINE || (box->parent->parent->style->text_decoration == CSS_TEXT_DECORATION_OVERLINE && box->parent->parent->type == BOX_BLOCK)) {
char ulctrl[3];
char *temp = xcalloc(strlen(box->text)+4,
sizeof(char));
sprintf(ulctrl, "%c%c%c", (char)25, (char)127,
(char)10);
sprintf(temp, "%s%s", ulctrl, box->text);
font_paint(box->font->handle, temp,
font_OS_UNITS | font_GIVEN_FONT | font_KERN | font_GIVEN_LENGTH,
x, y - (int) (box->height * 1.5),
NULL, NULL, (int) box->length + 3);
xfree(temp);
}
} else {
for (c = box->children; c != 0; c = c->next)
if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT)