[project @ 2004-02-01 22:42:40 by jmb]

Add text-indent support.

svn path=/import/netsurf/; revision=527
This commit is contained in:
John Mark Bell 2004-02-01 22:42:40 +00:00
parent 9d342dad80
commit edf9d941f1
4 changed files with 64 additions and 4 deletions

View File

@ -51,6 +51,7 @@ const struct css_style css_base_style = {
{ CSS_LINE_HEIGHT_ABSOLUTE, { 1.3 } },
CSS_TEXT_ALIGN_LEFT,
CSS_TEXT_DECORATION_NONE,
{ CSS_TEXT_INDENT_LENGTH, { { 0, CSS_UNIT_EM } } },
CSS_TEXT_TRANSFORM_NONE,
CSS_VISIBILITY_VISIBLE,
{ CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } },
@ -72,6 +73,7 @@ const struct css_style css_empty_style = {
{ CSS_LINE_HEIGHT_INHERIT, { 1.3 } },
CSS_TEXT_ALIGN_INHERIT,
CSS_TEXT_DECORATION_INHERIT,
{ CSS_TEXT_INDENT_INHERIT, { { 0, CSS_UNIT_EM } } },
CSS_TEXT_TRANSFORM_INHERIT,
CSS_VISIBILITY_INHERIT,
{ CSS_WIDTH_INHERIT, { { 1, CSS_UNIT_EM } } },
@ -93,6 +95,7 @@ const struct css_style css_blank_style = {
{ CSS_LINE_HEIGHT_INHERIT, { 1.3 } },
CSS_TEXT_ALIGN_INHERIT,
CSS_TEXT_DECORATION_INHERIT,
{ CSS_TEXT_INDENT_INHERIT, { { 0, CSS_UNIT_EM } } },
CSS_TEXT_TRANSFORM_INHERIT,
CSS_VISIBILITY_INHERIT,
{ CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } },
@ -689,6 +692,14 @@ void css_dump_style(const struct css_style * const style)
fprintf(stderr, " blink");
}
fprintf(stderr, "; ");
fprintf(stderr, "text-indent: ");
switch (style->text_indent.size) {
case CSS_TEXT_INDENT_LENGTH: dump_length(&style->text_indent.value.length); break;
case CSS_TEXT_INDENT_PERCENT: fprintf(stderr, "%g%%", style->text_indent.value.percent); break;
case CSS_TEXT_INDENT_INHERIT: fprintf(stderr, "inherit"); break;
default: fprintf(stderr, "UNKNOWN"); break;
}
fprintf(stderr, "; ");
fprintf(stderr, "text-transform: %s; ", css_text_transform_name[style->text_transform]);
fprintf(stderr, "visibility: %s; ", css_visibility_name[style->visibility]);
fprintf(stderr, "width: ");
@ -774,6 +785,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_indent.size != CSS_TEXT_INDENT_INHERIT)
style->text_indent = apply->text_indent;
if (apply->text_transform != CSS_TEXT_TRANSFORM_INHERIT)
style->text_transform = apply->text_transform;
if (apply->visibility != CSS_VISIBILITY_INHERIT)
@ -853,6 +866,8 @@ void css_merge(struct css_style * const style, const struct css_style * const ap
style->text_align = apply->text_align;
if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT)
style->text_decoration = apply->text_decoration;
if (apply->text_indent.size != CSS_TEXT_INDENT_INHERIT)
style->text_indent = apply->text_indent;
if (apply->text_transform != CSS_TEXT_TRANSFORM_INHERIT)
style->text_transform = apply->text_transform;
if (apply->visibility != CSS_VISIBILITY_INHERIT)

View File

@ -98,6 +98,15 @@ struct css_style {
css_text_align text_align;
css_text_decoration text_decoration;
struct {
enum { CSS_TEXT_INDENT_INHERIT,
CSS_TEXT_INDENT_LENGTH,
CSS_TEXT_INDENT_PERCENT } size;
union {
struct css_length length;
float percent;
} value ;
} text_indent;
css_text_transform text_transform;
css_visibility visibility;
@ -233,7 +242,7 @@ void css_add_declarations(struct css_style *style, struct css_node *declaration)
unsigned int css_hash(const char *s);
void css_parser_Trace(FILE *TraceFILE, char *zTracePrompt);
void *css_parser_alloc(void *(*mallocProc)(size_t));
void *css_parser_Alloc(void *(*mallocProc)(/*size_t*/int));
void css_parser_Free(void *p, void (*freeProc)(void*));
void css_parser_(void *yyp, int yymajor, char* yyminor,
struct parse_params *param);

View File

@ -53,6 +53,7 @@ static void parse_height(struct css_style * const s, const struct css_node * con
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);
static void parse_text_decoration(struct css_style * const s, const struct css_node * const v);
static void parse_text_indent(struct css_style * const s, const struct css_node * const v);
static void parse_text_transform(struct css_style * const s, const struct css_node * const v);
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);
@ -78,6 +79,7 @@ static const struct property_entry property_table[] = {
{ "line-height", parse_line_height },
{ "text-align", parse_text_align },
{ "text-decoration", parse_text_decoration },
{ "text-indent", parse_text_indent },
{ "text-transform", parse_text_transform },
{ "visibility", parse_visibility },
{ "white-space", parse_white_space },
@ -571,6 +573,18 @@ void parse_text_align(struct css_style * const s, const struct css_node * const
s->text_align = z;
}
void parse_text_indent(struct css_style * const s, const struct css_node * const v)
{
if (v->type == CSS_NODE_IDENT) {
return;
} else if (v->type == CSS_NODE_PERCENTAGE) {
s->text_indent.size = CSS_TEXT_INDENT_PERCENT;
s->text_indent.value.percent = atof(v->data);
} else if (v->type == CSS_NODE_DIMENSION && parse_length(&s->text_indent.value.length, v, true) == 0) {
s->text_indent.size = CSS_TEXT_INDENT_LENGTH;
}
}
void parse_text_decoration(struct css_style * const s, const struct css_node * const v)
{
struct css_node *temp;

View File

@ -9,6 +9,7 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -39,7 +40,7 @@ static void layout_inline_container(struct box * box, unsigned long width, struc
unsigned long cx, unsigned long cy);
static signed long line_height(struct css_style * style);
static struct box * layout_line(struct box * first, unsigned long width, unsigned long * y,
unsigned long cy, struct box * cont);
unsigned long cy, struct box * cont, bool indent);
static void place_float_below(struct box * c, unsigned long width, unsigned long y, struct box * cont);
static void layout_table(struct box * box, unsigned long width, struct box * cont,
unsigned long cx, unsigned long cy);
@ -240,7 +241,8 @@ void layout_inline_container(struct box * box, unsigned long width, struct box *
LOG(("box %p, width %lu, cont %p, cx %lu, cy %lu", box, width, cont, cx, cy));
for (c = box->children; c != 0; ) {
c = layout_line(c, width, &y, cy + y, cont);
c = layout_line(c, width, &y, cy + y, cont,
c == box->children ? true : false);
}
box->width = width;
@ -265,7 +267,7 @@ signed long line_height(struct css_style * style)
struct box * layout_line(struct box * first, unsigned long width, unsigned long * y,
unsigned long cy, struct box * cont)
unsigned long cy, struct box * cont, bool indent)
{
unsigned long height, used_height;
unsigned long x0 = 0;
@ -323,6 +325,25 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
x1 = width;
find_sides(cont->float_children, cy, cy + height, &x0, &x1, &left, &right);
/* text-indent */
/* TODO - fix <BR> related b0rkage */
if (indent) {
switch (first->parent->parent->style->text_indent.size) {
case CSS_TEXT_INDENT_LENGTH:
x0 += len(&first->parent->parent->style->text_indent.value.length, first->parent->parent->style);
if (x0 + x > x1)
x1 = x0 + x;
break;
case CSS_TEXT_INDENT_PERCENT:
x0 += ((x1-x0) * first->parent->parent->style->text_indent.value.percent) / 100;
if (x0 + x > x1)
x1 = x0 + x;
break;
default:
break;
}
}
/* pass 2: place boxes in line */
for (x = x_previous = 0, b = first; x <= x1 - x0 && b != 0; b = b->next) {
if (b->type == BOX_INLINE || b->type == BOX_INLINE_BLOCK) {
@ -491,6 +512,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
case CSS_TEXT_ALIGN_CENTER: x0 = (x0 + (x1 - x)) / 2; break;
default: break; /* leave on left */
}
for (d = first; d != b; d = d->next) {
if (d->type == BOX_INLINE || d->type == BOX_INLINE_BLOCK) {
d->x += x0;