diff options
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | src/layeng/cr-style.c | 179 | ||||
-rw-r--r-- | src/parser/cr-rgb.c | 177 | ||||
-rw-r--r-- | src/parser/cr-rgb.h | 6 |
4 files changed, 358 insertions, 8 deletions
@@ -6,7 +6,9 @@ This is gonna take a coupe of months I think. Implement the style properties (of the 4 edges of the box model). test/debug the properties used in test7 code the shortcut properties (border, margin border-style etc ...) - code the color 16 name aliases defined in the html 4.01 spec. + WIRE the use of the "border" properties and all it sub + properties and debug this. + code the color 16 name aliases defined in the html 4.01 spec. (debug this) *Doc:) diff --git a/src/layeng/cr-style.c b/src/layeng/cr-style.c index a12f534..cd84037 100644 --- a/src/layeng/cr-style.c +++ b/src/layeng/cr-style.c @@ -57,6 +57,10 @@ enum CRPropertyID PROP_ID_BORDER_RIGHT_STYLE, PROP_ID_BORDER_BOTTOM_STYLE, PROP_ID_BORDER_LEFT_STYLE, + PROP_ID_BORDER_TOP, + PROP_ID_BORDER_RIGHT, + PROP_ID_BORDER_BOTTOM, + PROP_ID_BORDER_LEFT, PROP_ID_MARGIN_TOP, PROP_ID_MARGIN_RIGHT, PROP_ID_MARGIN_BOTTOM, @@ -100,6 +104,10 @@ static CRPropertyDesc gv_prop_table [] = {"border-right-style", PROP_ID_BORDER_RIGHT_STYLE}, {"border-bottom-style", PROP_ID_BORDER_BOTTOM_STYLE}, {"border-left-style", PROP_ID_BORDER_LEFT_STYLE}, + {"border-top", PROP_ID_BORDER_TOP}, + {"border-right", PROP_ID_BORDER_RIGHT}, + {"border-bottom", PROP_ID_BORDER_BOTTOM}, + {"border-left", PROP_ID_BORDER_LEFT}, {"margin-top", PROP_ID_MARGIN_TOP}, {"margin-right", PROP_ID_MARGIN_RIGHT}, {"margin-bottom", PROP_ID_MARGIN_BOTTOM}, @@ -141,10 +149,13 @@ cr_style_init_properties (void) ; enum CRDirection { - DIR_TOP, + DIR_TOP = 0, DIR_RIGHT, DIR_BOTTOM, - DIR_LEFT + DIR_LEFT, + + /*must be the last one*/ + NB_DIRS } ; static enum CRStatus @@ -186,6 +197,24 @@ static enum CRStatus set_prop_width (CRStyle *a_style, CRTerm *a_value) ; static enum CRStatus +set_prop_color_rgb (CRStyle *a_style, CRTerm *a_value) ; + +static enum CRStatus +set_prop_background_color_rgb (CRStyle *a_style, CRTerm *a_value) ; + +static enum CRStatus +set_prop_border_x_color_from_value (CRStyle *a_style, CRTerm *a_value, + enum CRDirection a_dir) ; + +static enum CRStatus +set_prop_border_x_from_value (CRStyle *a_style, CRTerm *a_value, + enum CRDirection a_dir) ; + +static enum CRStatus +set_prop_border_from_value (CRStyle *a_style, CRTerm *a_value, + enum CRDirection a_dir) ; + +static enum CRStatus cr_style_init_properties (void) { @@ -448,6 +477,7 @@ set_prop_border_x_width_from_value (CRStyle *a_style, break ; default: + return CR_BAD_PARAM_ERROR ; break ; } @@ -1024,7 +1054,7 @@ set_prop_width (CRStyle *a_style, CRTerm *a_value) } static enum CRStatus -set_prop_color (CRStyle *a_style, CRTerm *a_value) +set_prop_color_rgb (CRStyle *a_style, CRTerm *a_value) { g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; @@ -1044,7 +1074,7 @@ set_prop_color (CRStyle *a_style, CRTerm *a_value) } static enum CRStatus -set_prop_background_color (CRStyle *a_style, CRTerm *a_value) +set_prop_background_color_rgb (CRStyle *a_style, CRTerm *a_value) { g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; @@ -1063,6 +1093,128 @@ set_prop_background_color (CRStyle *a_style, CRTerm *a_value) return CR_OK ; } +/** + *Sets border-top-color, border-right-color, + *border-bottom-color or border-left-color properties + *in the style structure. The value is taken from a + *css2 term of type IDENT or RGB. + *@param a_style the style structure to set. + *@param a_value the css2 term to take the color information from. + *@param a_dir the direction (TOP, LEFT, RIGHT, or BOTTOM). + *@return CR_OK upon successfull completion, an error code otherwise. + */ +static enum CRStatus +set_prop_border_x_color_from_value (CRStyle *a_style, CRTerm *a_value, + enum CRDirection a_dir) +{ + CRRgb *rgb_color = NULL ; + enum CRStatus status = CR_OK ; + + g_return_val_if_fail (a_style && a_value, + CR_BAD_PARAM_ERROR) ; + + switch (a_dir) + { + case DIR_TOP: + rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_TOP_COLOR].sv ; + break ; + + case DIR_RIGHT: + rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_RIGHT_COLOR].sv ; + break ; + + case DIR_BOTTOM: + rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_BOTTOM_COLOR].sv; + break ; + + case DIR_LEFT: + rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_LEFT_COLOR].sv ; + break ; + + default: + cr_utils_trace_info ("unknown DIR type") ; + return CR_BAD_PARAM_ERROR ; + } + + status = CR_UNKNOWN_PROP_VAL_ERROR ; + + if (a_value->type == TERM_IDENT) + { + if (a_value->content.str && a_value->content.str->str) + { + status = cr_rgb_set_from_name + (rgb_color, a_value->content.str->str) ; + + } + + if (status != CR_OK) + { + cr_rgb_set_from_name (rgb_color, "black") ; + } + } + else if (a_value->type == TERM_RGB) + { + if (a_value->content.rgb) + { + status = cr_rgb_set_from_rgb + (rgb_color, a_value->content.rgb) ; + } + } + + return status ; +} + + +static enum CRStatus +set_prop_border_x_from_value (CRStyle *a_style, CRTerm *a_value, + enum CRDirection a_dir) +{ + CRTerm *cur_term = NULL ; + + enum CRStatus status = CR_OK ; + + g_return_val_if_fail (a_style && a_value, + CR_BAD_PARAM_ERROR) ; + + for (cur_term = a_value ; cur_term ; cur_term = cur_term->next) + { + status = + set_prop_border_x_width_from_value (a_style, cur_term, + a_dir) ; + + if (status != CR_OK) + { + status = set_prop_border_x_style_from_value + (a_style, cur_term, a_dir) ; + } + + if (status != CR_OK) + { + status = set_prop_border_x_color_from_value + (a_style, a_value, a_dir) ; + } + } + + return CR_OK ; +} + +static enum CRStatus +set_prop_border_from_value (CRStyle *a_style, CRTerm *a_value, + enum CRDirection a_dir) +{ + enum CRDirection direction = 0 ; + + g_return_val_if_fail (a_style && a_value, + CR_BAD_PARAM_ERROR) ; + + for (direction = 0 ; direction < NB_DIRS ; direction ++) + { + set_prop_border_x_from_value (a_style, a_value, direction) ; + } + + return CR_OK ; +} + /****************** *Public methods @@ -1257,7 +1409,22 @@ cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl, DIR_LEFT) ; break ; + /*TODO!!*/ + case PROP_ID_BORDER_TOP: + break ; + + case PROP_ID_BORDER_RIGHT: + break ; + + case PROP_ID_BORDER_BOTTOM: + break ; + + case PROP_ID_BORDER_LEFT: + break ; + case PROP_ID_MARGIN_TOP: + break ; + status = set_prop_margin_x_from_value (a_this, value, DIR_TOP) ; @@ -1319,11 +1486,11 @@ cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl, break ; case PROP_ID_COLOR: - status = set_prop_color (a_this, value) ; + status = set_prop_color_rgb (a_this, value) ; break ; case PROP_ID_BACKGROUND_COLOR: - status = set_prop_background_color (a_this, value) ; + status = set_prop_background_color_rgb (a_this, value) ; default: return CR_UNKNOWN_TYPE_ERROR ; diff --git a/src/parser/cr-rgb.c b/src/parser/cr-rgb.c index 58ac0f4..2f99d28 100644 --- a/src/parser/cr-rgb.c +++ b/src/parser/cr-rgb.c @@ -28,6 +28,157 @@ #include <string.h> #include "cr-rgb.h" +static CRRgb gv_standard_colors[] = +{ + { "aliceblue", 240, 248, 255, 0}, + { "antiquewhite", 250, 235, 215, 0}, + { "aqua", 0, 255, 255, 0}, + { "aquamarine", 127, 255, 212, 0}, + { "azure", 240, 255, 255, 0}, + { "beige", 245, 245, 220, 0}, + { "bisque", 255, 228, 196, 0}, + { "black", 0, 0, 0, 0}, + { "blanchedalmond", 255, 235, 205, 0}, + { "blue", 0, 0, 255, 0}, + { "blueviolet", 138, 43, 226, 0}, + { "brown", 165, 42, 42, 0}, + { "burlywood", 222, 184, 135, 0}, + { "cadetblue", 95, 158, 160, 0}, + { "chartreuse", 127, 255, 0, 0}, + { "chocolate", 210, 105, 30, 0}, + { "coral", 255, 127, 80, 0}, + { "cornflowerblue", 100, 149, 237, 0}, + { "cornsilk", 255, 248, 220, 0}, + { "crimson", 220, 20, 60, 0}, + { "cyan", 0, 255, 255, 0}, + { "darkblue", 0, 0, 139, 0}, + { "darkcyan", 0, 139, 139, 0}, + { "darkgoldenrod", 184, 134, 11, 0}, + { "darkgray", 169, 169, 169, 0}, + { "darkgreen", 0, 100, 0, 0}, + { "darkgrey", 169, 169, 169, 0}, + { "darkkhaki", 189, 183, 107, 0}, + { "darkmagenta", 139, 0, 139, 0}, + { "darkolivegreen", 85, 107, 47, 0}, + { "darkorange", 255, 140, 0, 0}, + { "darkorchid", 153, 50, 204, 0}, + { "darkred", 139, 0, 0, 0}, + { "darksalmon", 233, 150, 122, 0}, + { "darkseagreen", 143, 188, 143, 0}, + { "darkslateblue", 72, 61, 139, 0}, + { "darkslategray", 47, 79, 79, 0}, + { "darkslategrey", 47, 79, 79, 0}, + { "darkturquoise", 0, 206, 209, 0}, + { "darkviolet", 148, 0, 211, 0}, + { "deeppink", 255, 20, 147, 0}, + { "deepskyblue", 0, 191, 255, 0}, + { "dimgray", 105, 105, 105, 0}, + { "dimgrey", 105, 105, 105, 0}, + { "dodgerblue", 30, 144, 255, 0}, + { "firebrick", 178, 34, 34, 0}, + { "floralwhite", 255, 250, 240, 0}, + { "forestgreen", 34, 139, 34, 0}, + { "fuchsia", 255, 0, 255, 0}, + { "gainsboro", 220, 220, 220, 0}, + { "ghostwhite", 248, 248, 255, 0}, + { "gold", 255, 215, 0, 0}, + { "goldenrod", 218, 165, 32, 0}, + { "gray", 128, 128, 128, 0}, + { "grey", 128, 128, 128, 0}, + { "green", 0, 128, 0, 0}, + { "greenyellow", 173, 255, 47, 0}, + { "honeydew", 240, 255, 240, 0}, + { "hotpink", 255, 105, 180, 0}, + { "indianred", 205, 92, 92, 0}, + { "indigo", 75, 0, 130, 0}, + { "ivory", 255, 255, 240, 0}, + { "khaki", 240, 230, 140, 0}, + { "lavender", 230, 230, 250, 0}, + { "lavenderblush", 255, 240, 245, 0}, + { "lawngreen", 124, 252, 0, 0}, + { "lemonchiffon", 255, 250, 205, 0}, + { "lightblue", 173, 216, 230, 0}, + { "lightcoral", 240, 128, 128, 0}, + { "lightcyan", 224, 255, 255, 0}, + { "lightgoldenrodyellow", 250, 250, 210, 0}, + { "lightgray", 211, 211, 211, 0}, + { "lightgreen", 144, 238, 144, 0}, + { "lightgrey", 211, 211, 211, 0}, + { "lightpink", 255, 182, 193, 0}, + { "lightsalmon", 255, 160, 122, 0}, + { "lightseagreen", 32, 178, 170, 0}, + { "lightskyblue", 135, 206, 250, 0}, + { "lightslategray", 119, 136, 153, 0}, + { "lightslategrey", 119, 136, 153, 0}, + { "lightsteelblue", 176, 196, 222, 0}, + { "lightyellow", 255, 255, 224, 0}, + { "lime", 0, 255, 0, 0}, + { "limegreen", 50, 205, 50, 0}, + { "linen", 250, 240, 230, 0}, + { "magenta", 255, 0, 255, 0}, + { "maroon", 128, 0, 0, 0}, + { "mediumaquamarine", 102, 205, 170, 0}, + { "mediumblue", 0, 0, 205, 0}, + { "mediumorchid", 186, 85, 211, 0}, + { "mediumpurple", 147, 112, 219, 0}, + { "mediumseagreen", 60, 179, 113, 0}, + { "mediumslateblue", 123, 104, 238, 0}, + { "mediumspringgreen", 0, 250, 154, 0}, + { "mediumturquoise", 72, 209, 204, 0}, + { "mediumvioletred", 199, 21, 133, 0}, + { "midnightblue", 25, 25, 112, 0}, + { "mintcream", 245, 255, 250, 0}, + { "mistyrose", 255, 228, 225, 0}, + { "moccasin", 255, 228, 181, 0}, + { "navajowhite", 255, 222, 173, 0}, + { "navy", 0, 0, 128, 0}, + { "oldlace", 253, 245, 230, 0}, + { "olive", 128, 128, 0, 0}, + { "olivedrab", 107, 142, 35, 0}, + { "orange", 255, 165, 0, 0}, + { "orangered", 255, 69, 0, 0}, + { "orchid", 218, 112, 214, 0}, + { "palegoldenrod", 238, 232, 170, 0}, + { "palegreen", 152, 251, 152, 0}, + { "paleturquoise", 175, 238, 238, 0}, + { "palevioletred", 219, 112, 147, 0}, + { "papayawhip", 255, 239, 213, 0}, + { "peachpuff", 255, 218, 185, 0}, + { "peru", 205, 133, 63, 0}, + { "pink", 255, 192, 203, 0}, + { "plum", 221, 160, 221, 0}, + { "powderblue", 176, 224, 230, 0}, + { "purple", 128, 0, 128, 0}, + { "red", 255, 0, 0, 0}, + { "rosybrown", 188, 143, 143, 0}, + { "royalblue", 65, 105, 225, 0}, + { "saddlebrown", 139, 69, 19, 0}, + { "salmon", 250, 128, 114, 0}, + { "sandybrown", 244, 164, 96, 0}, + { "seagreen", 46, 139, 87, 0}, + { "seashell", 255, 245, 238, 0}, + { "sienna", 160, 82, 45, 0}, + { "silver", 192, 192, 192, 0}, + { "skyblue", 135, 206, 235, 0}, + { "slateblue", 106, 90, 205, 0}, + { "slategray", 112, 128, 144, 0}, + { "slategrey", 112, 128, 144, 0}, + { "snow", 255, 250, 250, 0}, + { "springgreen", 0, 255, 127, 0}, + { "steelblue", 70, 130, 180, 0}, + { "tan", 210, 180, 140, 0}, + { "teal", 0, 128, 128, 0}, + { "thistle", 216, 191, 216, 0}, + { "tomato", 255, 99, 71, 0}, + { "turquoise", 64, 224, 208, 0}, + { "violet", 238, 130, 238, 0}, + { "wheat", 245, 222, 179, 0}, + { "white", 255, 255, 255, 0}, + { "whitesmoke", 245, 245, 245, 0}, + { "yellow", 255, 255, 0, 0}, + { "yellowgreen", 154, 205, 50, 0} +} ; + /** *The default constructor of #CRRgb. *@return the newly built instance of #CRRgb @@ -214,6 +365,32 @@ cr_rgb_set_from_rgb (CRRgb *a_this, CRRgb *a_rgb) return CR_OK ; } + +enum CRStatus +cr_rgb_set_from_name (CRRgb *a_this, const guchar *a_color_name) +{ + gulong i = 0 ; + enum CRStatus status = CR_OK ; + + g_return_val_if_fail (a_this && a_color_name, CR_BAD_PARAM_ERROR) ; + + for (i = 0 ; i < sizeof (gv_standard_colors); i++) + { + if (!strcmp (a_color_name, gv_standard_colors[i].name)) + { + cr_rgb_set_from_rgb (a_this, &gv_standard_colors[i]) ; + break ; + } + } + + if (i < sizeof (gv_standard_colors)) + status = CR_OK ; + else + status = CR_UNKNOWN_TYPE_ERROR ; + + return status ; +} + /** *Destructor of #CRRgb. *@param a_this the "this pointer" of the diff --git a/src/parser/cr-rgb.h b/src/parser/cr-rgb.h index 9d0d00c..fbd9364 100644 --- a/src/parser/cr-rgb.h +++ b/src/parser/cr-rgb.h @@ -44,10 +44,11 @@ extern "C" *Either NO_UNIT (integer) or *UNIT_PERCENTAGE (percentage). */ - gboolean is_percentage ; + const guchar *name ; glong red ; glong green ; glong blue ; + gboolean is_percentage ; } ; CRRgb * @@ -65,6 +66,9 @@ extern "C" enum CRStatus cr_rgb_set_from_rgb (CRRgb *a_this, CRRgb *a_rgb) ; + enum CRStatus + cr_rgb_set_from_name (CRRgb *a_this, const guchar *a_color_name) ; + guchar * cr_rgb_to_string (CRRgb *a_this) ; |