summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2004-01-31 21:18:44 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2004-01-31 21:18:44 +0000
commit00ef17153cd5e0b4fe47dddea4db74450ee06bb1 (patch)
tree7beebb42d0dce3874ce6106ec306ee504975054e
parentf53642c94b8a7bcdddc0bd6e7fcb248403d50ae4 (diff)
downloadnetsurf-00ef17153cd5e0b4fe47dddea4db74450ee06bb1.tar.gz
netsurf-00ef17153cd5e0b4fe47dddea4db74450ee06bb1.tar.bz2
[project @ 2004-01-31 21:18:44 by jmb]
text-transform support. svn path=/import/netsurf/; revision=521
-rw-r--r--css/css.c8
-rw-r--r--css/css.h1
-rw-r--r--css/css_enums2
-rw-r--r--css/ruleset.c12
-rw-r--r--render/box.c58
5 files changed, 80 insertions, 1 deletions
diff --git a/css/css.c b/css/css.c
index 4d37ddece..ab98a2e96 100644
--- a/css/css.c
+++ b/css/css.c
@@ -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_TRANSFORM_NONE,
CSS_VISIBILITY_VISIBLE,
{ CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } },
CSS_WHITE_SPACE_NORMAL
@@ -71,6 +72,7 @@ const struct css_style css_empty_style = {
{ CSS_LINE_HEIGHT_INHERIT, { 1.3 } },
CSS_TEXT_ALIGN_INHERIT,
CSS_TEXT_DECORATION_INHERIT,
+ CSS_TEXT_TRANSFORM_INHERIT,
CSS_VISIBILITY_INHERIT,
{ CSS_WIDTH_INHERIT, { { 1, CSS_UNIT_EM } } },
CSS_WHITE_SPACE_INHERIT
@@ -91,6 +93,7 @@ const struct css_style css_blank_style = {
{ CSS_LINE_HEIGHT_INHERIT, { 1.3 } },
CSS_TEXT_ALIGN_INHERIT,
CSS_TEXT_DECORATION_INHERIT,
+ CSS_TEXT_TRANSFORM_INHERIT,
CSS_VISIBILITY_INHERIT,
{ CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } },
CSS_WHITE_SPACE_INHERIT
@@ -686,6 +689,7 @@ void css_dump_style(const struct css_style * const style)
fprintf(stderr, " blink");
}
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: ");
switch (style->width.width) {
@@ -770,6 +774,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_transform != CSS_TEXT_TRANSFORM_INHERIT)
+ style->text_transform = apply->text_transform;
if (apply->visibility != CSS_VISIBILITY_INHERIT)
style->visibility = apply->visibility;
if (apply->width.width != CSS_WIDTH_INHERIT)
@@ -847,6 +853,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_transform != CSS_TEXT_TRANSFORM_INHERIT)
+ style->text_transform = apply->text_transform;
if (apply->visibility != CSS_VISIBILITY_INHERIT)
style->visibility = apply->visibility;
if (apply->width.width != CSS_WIDTH_INHERIT)
diff --git a/css/css.h b/css/css.h
index 545e7e570..5b13e98cc 100644
--- a/css/css.h
+++ b/css/css.h
@@ -98,6 +98,7 @@ struct css_style {
css_text_align text_align;
css_text_decoration text_decoration;
+ css_text_transform text_transform;
css_visibility visibility;
diff --git a/css/css_enums b/css/css_enums
index c51e8acc7..aaaed1419 100644
--- a/css/css_enums
+++ b/css/css_enums
@@ -16,7 +16,7 @@ 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_transform none capitalize lowercase uppercase
+css_text_transform inherit none capitalize lowercase uppercase
css_vertical_align baseline bottom middle sub super text_bottom text_top top percent
css_visibility inherit visible hidden
css_white_space inherit normal nowrap pre
diff --git a/css/ruleset.c b/css/ruleset.c
index 6e7de6ba5..faa704920 100644
--- a/css/ruleset.c
+++ b/css/ruleset.c
@@ -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_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);
static void parse_white_space(struct css_style * const s, const struct css_node * const v);
@@ -77,6 +78,7 @@ static const struct property_entry property_table[] = {
{ "line-height", parse_line_height },
{ "text-align", parse_text_align },
{ "text-decoration", parse_text_decoration },
+ { "text-transform", parse_text_transform },
{ "visibility", parse_visibility },
{ "white-space", parse_white_space },
{ "width", parse_width },
@@ -590,6 +592,16 @@ void parse_text_decoration(struct css_style * const s, const struct css_node * c
}
}
+void parse_text_transform(struct css_style * const s, const struct css_node * const v)
+{
+ css_text_transform z;
+ if (v->type != CSS_NODE_IDENT || v->next != 0)
+ return;
+ z = css_text_transform_parse(v->data);
+ if (z != CSS_TEXT_TRANSFORM_UNKNOWN)
+ s->text_transform = z;
+}
+
void parse_visibility(struct css_style * const s, const struct css_node * const v)
{
css_visibility z;
diff --git a/render/box.c b/render/box.c
index e51078a12..4a9bdb9fc 100644
--- a/render/box.c
+++ b/render/box.c
@@ -389,6 +389,33 @@ struct box * convert_xml_to_box(xmlNode * n, struct content *content,
box->space = 1;
box->length--;
}
+ switch (parent_style->text_transform) {
+ /* perform text-transform */
+ unsigned int ch;
+ case CSS_TEXT_TRANSFORM_UPPERCASE:
+ for (ch=0; ch!=box->length; ch++) {
+ box->text[ch] = toupper(box->text[ch]);
+ }
+ break;
+ case CSS_TEXT_TRANSFORM_LOWERCASE:
+ for (ch=0; ch!=box->length; ch++) {
+ box->text[ch] = tolower(box->text[ch]);
+ }
+ break;
+ case CSS_TEXT_TRANSFORM_CAPITALIZE:
+ for (ch=0; ch!=box->length; ch++) {
+ if (ch == 0) {
+ box->text[ch] = toupper(box->text[ch]);
+ }
+ else if (!((box->text[ch-1] > 64 && box->text[ch-1] < 91) ||
+ (box->text[ch-1] > 96 && box->text[ch-1] < 123))) {
+ box->text[ch] = toupper(box->text[ch]);
+ }
+ }
+ break;
+ default:
+ break;
+ }
if (parent_style->white_space == CSS_WHITE_SPACE_NOWRAP) {
unsigned int i;
for (i = 0; i != box->length; i++)
@@ -431,6 +458,37 @@ struct box * convert_xml_to_box(xmlNode * n, struct content *content,
box->style_clone = 1;
box->text = xstrdup(current);
box->length = strlen(box->text);
+ switch (parent_style->text_transform) {
+ /* perform text-transform */
+ unsigned int ch;
+ case CSS_TEXT_TRANSFORM_UPPERCASE:
+ for (ch=0; ch!=box->length; ch++) {
+ box->text[ch] =
+ toupper(box->text[ch]);
+ }
+ break;
+ case CSS_TEXT_TRANSFORM_LOWERCASE:
+ for (ch=0; ch!=box->length; ch++) {
+ box->text[ch] =
+ tolower(box->text[ch]);
+ }
+ break;
+ case CSS_TEXT_TRANSFORM_CAPITALIZE:
+ for (ch=0; ch!=box->length; ch++) {
+ if (ch == 0) {
+ box->text[ch] =
+ toupper(box->text[ch]);
+ }
+ else if (!((box->text[ch-1] > 64 && box->text[ch-1] < 91) ||
+ (box->text[ch-1] > 96 && box->text[ch-1] < 123))) {
+ box->text[ch] =
+ toupper(box->text[ch]);
+ }
+ }
+ break;
+ default:
+ break;
+ }
box->font = font_open(content->data.html.fonts, box->style);
box_add_child(inline_container, box);
current[len] = old;