summaryrefslogtreecommitdiff
path: root/source/html/css-apply.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-11-18 13:32:21 +0100
committerTor Andersson <tor.andersson@artifex.com>2014-12-03 12:25:52 +0100
commitbb875f77f23ac4c51a072f4fc6692ce2dc352997 (patch)
tree931b3ffd1fee41eea73d22046d8f2fe6a5532376 /source/html/css-apply.c
parent880a2fc8ad25bc4a1e64bb600f4605dd3d864eaa (diff)
downloadmupdf-bb875f77f23ac4c51a072f4fc6692ce2dc352997.tar.xz
html: Text and background colors.
Diffstat (limited to 'source/html/css-apply.c')
-rw-r--r--source/html/css-apply.c87
1 files changed, 86 insertions, 1 deletions
diff --git a/source/html/css-apply.c b/source/html/css-apply.c
index 8284c5ac..351f05e6 100644
--- a/source/html/css-apply.c
+++ b/source/html/css-apply.c
@@ -751,7 +751,8 @@ number_from_value(struct value *value, float initial, int initial_unit)
return make_number(initial, initial_unit);
}
-static struct number number_from_property(struct style *node, const char *property, float initial, int initial_unit)
+static struct number
+number_from_property(struct style *node, const char *property, float initial, int initial_unit)
{
return number_from_value(get_style_property(node, property), initial, initial_unit);
}
@@ -778,6 +779,85 @@ from_number_scale(struct number number, float scale, float em, float width)
}
}
+static struct color
+make_color(int r, int g, int b, int a)
+{
+ struct color c;
+ c.r = r;
+ c.g = g;
+ c.b = b;
+ c.a = a;
+ return c;
+}
+
+static int tohex(int c)
+{
+ if (c - '0' < 10)
+ return c - '0';
+ return (c | 32) - 'a' + 10;
+}
+
+static struct color
+color_from_value(struct value *value)
+{
+ if (!value)
+ return make_color(0, 0, 0, 0);
+ if (value->type == CSS_COLOR)
+ {
+ int r = tohex(value->data[0]) * 16 + tohex(value->data[1]);
+ int g = tohex(value->data[2]) * 16 + tohex(value->data[3]);
+ int b = tohex(value->data[4]) * 16 + tohex(value->data[5]);
+ return make_color(r, g, b, 255);
+ }
+ if (value->type == CSS_KEYWORD)
+ {
+ if (!strcmp(value->data, "transparent"))
+ return make_color(0, 0, 0, 0);
+ if (!strcmp(value->data, "maroon"))
+ return make_color(0x80, 0x00, 0x00, 255);
+ if (!strcmp(value->data, "red"))
+ return make_color(0xFF, 0x00, 0x00, 255);
+ if (!strcmp(value->data, "orange"))
+ return make_color(0xFF, 0xA5, 0x00, 255);
+ if (!strcmp(value->data, "yellow"))
+ return make_color(0xFF, 0xFF, 0x00, 255);
+ if (!strcmp(value->data, "olive"))
+ return make_color(0x80, 0x80, 0x00, 255);
+ if (!strcmp(value->data, "purple"))
+ return make_color(0x80, 0x00, 0x80, 255);
+ if (!strcmp(value->data, "fuchsia"))
+ return make_color(0xFF, 0x00, 0xFF, 255);
+ if (!strcmp(value->data, "white"))
+ return make_color(0xFF, 0xFF, 0xFF, 255);
+ if (!strcmp(value->data, "lime"))
+ return make_color(0x00, 0xFF, 0x00, 255);
+ if (!strcmp(value->data, "green"))
+ return make_color(0x00, 0x80, 0x00, 255);
+ if (!strcmp(value->data, "navy"))
+ return make_color(0x00, 0x00, 0x80, 255);
+ if (!strcmp(value->data, "blue"))
+ return make_color(0x00, 0x00, 0xFF, 255);
+ if (!strcmp(value->data, "aqua"))
+ return make_color(0x00, 0xFF, 0xFF, 255);
+ if (!strcmp(value->data, "teal"))
+ return make_color(0x00, 0x80, 0x80, 255);
+ if (!strcmp(value->data, "black"))
+ return make_color(0x00, 0x00, 0x00, 255);
+ if (!strcmp(value->data, "silver"))
+ return make_color(0xC0, 0xC0, 0xC0, 255);
+ if (!strcmp(value->data, "gray"))
+ return make_color(0x80, 0x80, 0x80, 255);
+ return make_color(0, 0, 0, 255);
+ }
+ return make_color(0, 0, 0, 0);
+}
+
+static struct color
+color_from_property(struct style *node, const char *property)
+{
+ return color_from_value(get_style_property(node, property));
+}
+
int
get_style_property_display(struct style *node)
{
@@ -819,6 +899,8 @@ default_computed_style(struct computed_style *style)
style->vertical_align = 0;
style->white_space = WS_NORMAL;
style->font_size = make_number(1, N_SCALE);
+ style->background_color = make_color(0, 0, 0, 0);
+ style->color = make_color(0, 0, 0, 255);
}
void
@@ -885,6 +967,9 @@ compute_style(html_document *doc, struct computed_style *style, struct style *no
style->padding[2] = number_from_property(node, "padding-bottom", 0, N_NUMBER);
style->padding[3] = number_from_property(node, "padding-left", 0, N_NUMBER);
+ style->color = color_from_property(node, "color");
+ style->background_color = color_from_property(node, "background-color");
+
{
const char *font_family = get_style_property_string(node, "font-family", "serif");
const char *font_variant = get_style_property_string(node, "font-variant", "normal");