diff --git a/src/bin/edje/edje_cc.h b/src/bin/edje/edje_cc.h index 159d7ca68c..65299b580e 100644 --- a/src/bin/edje/edje_cc.h +++ b/src/bin/edje/edje_cc.h @@ -253,6 +253,7 @@ void edje_cc_handlers_pop_notify(const char *token); int get_param_index(char *str); void color_tree_root_free(void); +void convert_color_code(char *str, int *r, int *g, int *b, int *a); /* global vars */ extern Eina_List *ext_dirs; diff --git a/src/bin/edje/edje_cc_handlers.c b/src/bin/edje/edje_cc_handlers.c index 26f53ca0a8..382f4bc5e1 100644 --- a/src/bin/edje/edje_cc_handlers.c +++ b/src/bin/edje/edje_cc_handlers.c @@ -2803,14 +2803,34 @@ static void st_color_class_color(void) { Edje_Color_Class *cc; - - check_arg_count(4); + int nargs = get_arg_count(); cc = eina_list_data_get(eina_list_last(edje_file->color_classes)); - cc->r = parse_int_range(0, 0, 255); - cc->g = parse_int_range(1, 0, 255); - cc->b = parse_int_range(2, 0, 255); - cc->a = parse_int_range(3, 0, 255); + + if (nargs == 1) + { + int r, g, b, a; + char *str = parse_str(0); + + convert_color_code(str, &r, &g, &b, &a); + cc->r = r; + cc->g = g; + cc->b = b; + cc->a = a; + } + else if (nargs == 4) + { + cc->r = parse_int_range(0, 0, 255); + cc->g = parse_int_range(1, 0, 255); + cc->b = parse_int_range(2, 0, 255); + cc->a = parse_int_range(3, 0, 255); + } + else + { + ERR("%s:%i. color code should be a string or a set of 4 integers.", + file_in, line - 1); + exit(-1); + } } /** @@ -2827,14 +2847,34 @@ static void st_color_class_color2(void) { Edje_Color_Class *cc; - - check_arg_count(4); + int nargs = get_arg_count(); cc = eina_list_data_get(eina_list_last(edje_file->color_classes)); - cc->r2 = parse_int_range(0, 0, 255); - cc->g2 = parse_int_range(1, 0, 255); - cc->b2 = parse_int_range(2, 0, 255); - cc->a2 = parse_int_range(3, 0, 255); + + if (nargs == 1) + { + int r, g, b, a; + char *str = parse_str(0); + + convert_color_code(str, &r, &g, &b, &a); + cc->r2 = r; + cc->g2 = g; + cc->b2 = b; + cc->a2 = a; + } + else if (nargs == 4) + { + cc->r2 = parse_int_range(0, 0, 255); + cc->g2 = parse_int_range(1, 0, 255); + cc->b2 = parse_int_range(2, 0, 255); + cc->a2 = parse_int_range(3, 0, 255); + } + else + { + ERR("%s:%i. color code should be a string or a set of 4 integers.", + file_in, line - 1); + exit(-1); + } } /** @@ -2851,14 +2891,34 @@ static void st_color_class_color3(void) { Edje_Color_Class *cc; - - check_arg_count(4); + int nargs = get_arg_count(); cc = eina_list_data_get(eina_list_last(edje_file->color_classes)); - cc->r3 = parse_int_range(0, 0, 255); - cc->g3 = parse_int_range(1, 0, 255); - cc->b3 = parse_int_range(2, 0, 255); - cc->a3 = parse_int_range(3, 0, 255); + + if (nargs == 1) + { + int r, g, b, a; + char *str = parse_str(0); + + convert_color_code(str, &r, &g, &b, &a); + cc->r3 = r; + cc->g3 = g; + cc->b3 = b; + cc->a3 = a; + } + else if (nargs == 4) + { + cc->r3 = parse_int_range(0, 0, 255); + cc->g3 = parse_int_range(1, 0, 255); + cc->b3 = parse_int_range(2, 0, 255); + cc->a3 = parse_int_range(3, 0, 255); + } + else + { + ERR("%s:%i. color code should be a string or a set of 4 integers.", + file_in, line - 1); + exit(-1); + } } /** @@ -8394,19 +8454,39 @@ st_collections_group_parts_part_description_color_class(void) static void st_collections_group_parts_part_description_color(void) { - check_arg_count(4); + int nargs = get_arg_count(); if (current_part->type == EDJE_PART_TYPE_SPACER) { ERR("parse error %s:%i. SPACER part can't have a color defined", - file_in, line - 1); + file_in, line - 1); exit(-1); } - current_desc->color.r = parse_int_range(0, 0, 255); - current_desc->color.g = parse_int_range(1, 0, 255); - current_desc->color.b = parse_int_range(2, 0, 255); - current_desc->color.a = parse_int_range(3, 0, 255); + if (nargs == 1) + { + int r, g, b, a; + char *str = parse_str(0); + + convert_color_code(str, &r, &g, &b, &a); + current_desc->color.r = r; + current_desc->color.g = g; + current_desc->color.b = b; + current_desc->color.a = a; + } + else if (nargs == 4) + { + current_desc->color.r = parse_int_range(0, 0, 255); + current_desc->color.g = parse_int_range(1, 0, 255); + current_desc->color.b = parse_int_range(2, 0, 255); + current_desc->color.a = parse_int_range(3, 0, 255); + } + else + { + ERR("%s:%i. color code should be a string or a set of 4 integers.", + file_in, line - 1); + exit(-1); + } } /** @@ -8422,19 +8502,39 @@ st_collections_group_parts_part_description_color(void) static void st_collections_group_parts_part_description_color2(void) { - check_arg_count(4); + int nargs = get_arg_count(); if (current_part->type == EDJE_PART_TYPE_SPACER) { ERR("parse error %s:%i. SPACER part can't have a color defined", - file_in, line - 1); + file_in, line - 1); exit(-1); } - current_desc->color2.r = parse_int_range(0, 0, 255); - current_desc->color2.g = parse_int_range(1, 0, 255); - current_desc->color2.b = parse_int_range(2, 0, 255); - current_desc->color2.a = parse_int_range(3, 0, 255); + if (nargs == 1) + { + int r, g, b, a; + char *str = parse_str(0); + + convert_color_code(str, &r, &g, &b, &a); + current_desc->color2.r = r; + current_desc->color2.g = g; + current_desc->color2.b = b; + current_desc->color2.a = a; + } + else if (nargs == 4) + { + current_desc->color2.r = parse_int_range(0, 0, 255); + current_desc->color2.g = parse_int_range(1, 0, 255); + current_desc->color2.b = parse_int_range(2, 0, 255); + current_desc->color2.a = parse_int_range(3, 0, 255); + } + else + { + ERR("%s:%i. color code should be a string or a set of 4 integers.", + file_in, line - 1); + exit(-1); + } } /** @@ -8452,8 +8552,7 @@ st_collections_group_parts_part_description_color3(void) { Edje_Part_Collection *pc; Edje_Part_Description_Text *ed; - - check_arg_count(4); + int nargs = get_arg_count(); pc = eina_list_data_get(eina_list_last(edje_collections)); @@ -8467,10 +8566,30 @@ st_collections_group_parts_part_description_color3(void) ed = (Edje_Part_Description_Text*)current_desc; - ed->text.color3.r = parse_int_range(0, 0, 255); - ed->text.color3.g = parse_int_range(1, 0, 255); - ed->text.color3.b = parse_int_range(2, 0, 255); - ed->text.color3.a = parse_int_range(3, 0, 255); + if (nargs == 1) + { + int r, g, b, a; + char *str = parse_str(0); + + convert_color_code(str, &r, &g, &b, &a); + ed->text.color3.r = r; + ed->text.color3.g = g; + ed->text.color3.b = b; + ed->text.color3.a = a; + } + else if (nargs == 4) + { + ed->text.color3.r = parse_int_range(0, 0, 255); + ed->text.color3.g = parse_int_range(1, 0, 255); + ed->text.color3.b = parse_int_range(2, 0, 255); + ed->text.color3.a = parse_int_range(3, 0, 255); + } + else + { + ERR("%s:%i. color code should be a string or a set of 4 integers.", + file_in, line - 1); + exit(-1); + } } /** diff --git a/src/bin/edje/edje_cc_out.c b/src/bin/edje/edje_cc_out.c index 3a063babbe..ee5fe147d3 100644 --- a/src/bin/edje/edje_cc_out.c +++ b/src/bin/edje/edje_cc_out.c @@ -4262,3 +4262,102 @@ process_color_tree(char *s, const char *f_in, int ln) eina_array_clean(array); eina_array_free(array); } + +char +validate_hex_digit(char c) +{ + if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) + return c; + + ERR("%s:%i. invalid character '%c' is used in color code.", + file_in, line - 1, c); + exit(-1); +} + +void +convert_color_code(char *str, int *r, int *g, int *b, int *a) +{ + char buf[3]; + int len; + + len = strlen(str); + + if ((str[0] != '#') || (len != 4 && len != 5 && len != 7 && len != 9)) + { + ERR("%s:%i color code should start with '#' and have 4 or 8 digit hex number. (3 or 6 digits are allowed to omit alpha value of 255)", + file_in, line - 1); + exit(-1); + } + + buf[2] = '\0'; + + if (r) + { + if ((len == 4) || (len == 5)) + { + buf[0] = validate_hex_digit(str[1]); + buf[1] = validate_hex_digit(str[1]); + } + else + { + buf[0] = validate_hex_digit(str[1]); + buf[1] = validate_hex_digit(str[2]); + } + + *r = (int)strtol(buf, NULL, 16); + } + if (g) + { + if ((len == 4) || (len == 5)) + { + buf[0] = validate_hex_digit(str[2]); + buf[1] = validate_hex_digit(str[2]); + } + else + { + buf[0] = validate_hex_digit(str[3]); + buf[1] = validate_hex_digit(str[4]); + } + + *g = (int)strtol(buf, NULL, 16); + } + if (b) + { + if ((len == 4) || (len == 5)) + { + buf[0] = validate_hex_digit(str[3]); + buf[1] = validate_hex_digit(str[3]); + } + else + { + buf[0] = validate_hex_digit(str[5]); + buf[1] = validate_hex_digit(str[6]); + } + + *b = (int)strtol(buf, NULL, 16); + } + if (a) + { + if ((len == 5) || (len == 9)) + { + if (len == 5) + { + buf[0] = validate_hex_digit(str[4]); + buf[1] = validate_hex_digit(str[4]); + } + else + { + buf[0] = validate_hex_digit(str[7]); + buf[1] = validate_hex_digit(str[8]); + } + + *a = (int)strtol(buf, NULL, 16); + } + else + { + *a = 255; + } + } + + free(str); +}