hippo-canvas r7260 - in trunk: common/hippo tests
- From: otaylor svn gnome org
- To: svn-commits-list gnome org
- Subject: hippo-canvas r7260 - in trunk: common/hippo tests
- Date: Sat, 24 May 2008 23:53:50 +0000 (UTC)
Author: otaylor
Date: Sat May 24 23:53:50 2008
New Revision: 7260
URL: http://svn.gnome.org/viewvc/hippo-canvas?rev=7260&view=rev
Log:
Add support for rgba(255,0,0,0.1) color values in CSS files
Modified:
trunk/common/hippo/hippo-canvas-style.c
trunk/tests/test.css
Modified: trunk/common/hippo/hippo-canvas-style.c
==============================================================================
--- trunk/common/hippo/hippo-canvas-style.c (original)
+++ trunk/common/hippo/hippo-canvas-style.c Sat May 24 23:53:50 2008
@@ -212,6 +212,88 @@
VALUE_INHERIT
} GetFromTermResult;
+static int
+color_component_from_double(double component)
+{
+ /* http://people.redhat.com/otaylor/pixel-converting.html */
+ if (component >= 1.0)
+ return 255;
+ else
+ return (int)(component * 256);
+}
+
+static GetFromTermResult
+get_color_from_rgba_term(CRTerm *term,
+ guint32 *color)
+{
+ CRTerm *arg = term->ext_content.func_param;
+ CRNum *num;
+ double r = 0, g = 0, b = 0, a = 0;
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ double value;
+
+ if (arg == NULL)
+ return VALUE_NOT_FOUND;
+
+ if ((i == 0 && arg->the_operator != NO_OP) ||
+ (i > 0 && arg->the_operator != COMMA))
+ return VALUE_NOT_FOUND;
+
+ if (arg->type != TERM_NUMBER)
+ return VALUE_NOT_FOUND;
+
+ num = arg->content.num;
+
+ /* For simplicity, we convert a,r,g,b to [0,1.0] floats and then
+ * convert them back below. Then when we set them on a cairo content
+ * we convert them back to floats, and then cairo converts them
+ * back to integers to pass them to X, and so forth...
+ */
+ if (i < 3) {
+ if (num->type == NUM_PERCENTAGE) {
+ value = num->val / 100;
+ } else if (num->type == NUM_GENERIC) {
+ value = num->val / 255;
+ } else {
+ return VALUE_NOT_FOUND;
+ }
+ } else {
+ if (num->type != NUM_GENERIC)
+ return VALUE_NOT_FOUND;
+
+ value = num->val;
+ }
+
+ value = CLAMP(value, 0, 1);
+
+ switch (i) {
+ case 0:
+ r = value;
+ break;
+ case 1:
+ g = value;
+ break;
+ case 2:
+ b = value;
+ break;
+ case 3:
+ a = value;
+ break;
+ }
+
+ arg = arg->next;
+ }
+
+ *color = ((color_component_from_double(r) << 24) |
+ (color_component_from_double(g) << 16) |
+ (color_component_from_double(b) << 8) |
+ ((color_component_from_double(a))));
+
+ return VALUE_FOUND;
+}
+
static GetFromTermResult
get_color_from_term(HippoCanvasStyle *style,
CRTerm *term,
@@ -220,6 +302,31 @@
CRRgb rgb;
enum CRStatus status;
+ /* Since libcroco doesn't know about rgba colors, it can't handle
+ * the transparent keyword
+ */
+ if (term->type == TERM_IDENT &&
+ term->content.str &&
+ term->content.str->stryng &&
+ term->content.str->stryng->str &&
+ strcmp(term->content.str->stryng->str, "transparent") == 0)
+ {
+ *color = 0;
+ return VALUE_FOUND;
+ }
+ /* rgba() colors - a CSS3 addition, are not supported by libcroco,
+ * but they are parsed as a "function", so we can emulate the
+ * functionality.
+ */
+ else if (term->type == TERM_FUNCTION &&
+ term->content.str &&
+ term->content.str->stryng &&
+ term->content.str->stryng->str &&
+ strcmp(term->content.str->stryng->str, "rgba") == 0)
+ {
+ return get_color_from_rgba_term(term, color);
+ }
+
status = cr_rgb_set_from_term(&rgb, term);
if (status != CR_OK)
return VALUE_NOT_FOUND;
Modified: trunk/tests/test.css
==============================================================================
--- trunk/tests/test.css (original)
+++ trunk/tests/test.css Sat May 24 23:53:50 2008
@@ -32,7 +32,7 @@
.nested {
border: 1px solid black;
- background-color: red;
+ background-color: rgba(255, 0, 0, 0.1);
padding: 2px;
padding-left: 4px;
padding-right: 4px;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]