summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-05-15 09:10:02 +0200
committerDave Davenport <qball@gmpclient.org>2017-05-15 09:10:02 +0200
commitf0ceeb86d8f11526fc2fd52c3ef8e3c9e340a20f (patch)
treece9d50e1697d37f003ca932f116fe91d975caca5
parent9d068151fdbad2710b1fe9294c21c4c9d28ca15b (diff)
[Lexer] Support hsla
-rw-r--r--lexer/theme-lexer.l2
-rw-r--r--lexer/theme-parser.y11
-rw-r--r--test/theme-parser-test.c31
3 files changed, 42 insertions, 2 deletions
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l
index f6921027..a43323f5 100644
--- a/lexer/theme-lexer.l
+++ b/lexer/theme-lexer.l
@@ -176,7 +176,7 @@ RGBA "rgba"
RGB "rgb"
HWB "hwb"
CMYK "cmyk"
-HSL "hsl"
+HSL hsl[a]?
S_T_PARENT_LEFT \(
S_T_PARENT_RIGHT \)
diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y
index bf0019e0..1ccc551e 100644
--- a/lexer/theme-parser.y
+++ b/lexer/theme-parser.y
@@ -500,6 +500,17 @@ t_property_color
$$ = hsl_to_rgb ( h/360.0, s/100.0, l/100.0 );
$$.alpha = 1.0;
}
+ /** hsl ( 0-360 , 0-100 %, 0 - 100 %) */
+| T_COL_HSL T_PARENT_LEFT T_INT T_COMMA t_property_color_value T_PERCENT T_COMMA t_property_color_value T_PERCENT T_COMMA t_property_color_value T_PERCENT T_PARENT_RIGHT {
+ if ( ! check_in_range($3, 0,360, &(@$)) ) { YYABORT; }
+ if ( ! check_in_range($5, 0,100, &(@$)) ) { YYABORT; }
+ if ( ! check_in_range($8, 0,100, &(@$)) ) { YYABORT; }
+ gdouble h = $3;
+ gdouble s = $5;
+ gdouble l = $8;
+ $$ = hsl_to_rgb ( h/360.0, s/100.0, l/100.0 );
+ $$.alpha = $11/100.0;
+}
/** Hex colors parsed by lexer. */
| T_COLOR {
$$ = $1;
diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c
index 68eba616..5aa0b298 100644
--- a/test/theme-parser-test.c
+++ b/test/theme-parser-test.c
@@ -593,7 +593,35 @@ START_TEST ( test_properties_color_hsl )
widget wid;
wid.name = "blaat";
wid.state = NULL;
- rofi_theme_parse_string ( "* { test1: hsl(127,40%,66.66666%); test2: hsl(0, 100%, 50%); }");
+ rofi_theme_parse_string ( "* { test1: hsl(127,40%,66.66666%); test2: hsl(0, 100%, 50%); testa: hsl(127,40%, 66.66666%, 30%);}");
+ ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
+
+ Property *p = rofi_theme_find_property ( twid, P_COLOR, "test1", FALSE );
+ ck_assert_ptr_nonnull ( p );
+ ck_assert_double_eq ( p->value.color.alpha , 1.0 );
+ ck_assert_double_eq_tol ( p->value.color.red , 0x88/255.0 , 0.004);
+ ck_assert_double_eq_tol ( p->value.color.green, 0xcd/255.0, 0.004 );
+ ck_assert_double_eq_tol ( p->value.color.blue , 0x90/255.0 , 0.004);
+ p = rofi_theme_find_property ( twid, P_COLOR, "test2", FALSE );
+ ck_assert_ptr_nonnull ( p );
+ ck_assert_double_eq ( p->value.color.alpha , 1.0 );
+ ck_assert_double_eq_tol ( p->value.color.red , 1 , 0.004);
+ ck_assert_double_eq_tol ( p->value.color.green , 0, 0.004 );
+ ck_assert_double_eq_tol ( p->value.color.blue , 0 , 0.004);
+ p = rofi_theme_find_property ( twid, P_COLOR, "testa", FALSE );
+ ck_assert_ptr_nonnull ( p );
+ ck_assert_double_eq ( p->value.color.alpha , 0.3 );
+ ck_assert_double_eq_tol ( p->value.color.red , 0x88/255.0 ,0.004);
+ ck_assert_double_eq_tol ( p->value.color.green ,0xcd/255.0, 0.004 );
+ ck_assert_double_eq_tol ( p->value.color.blue , 0x90/255.0 ,0.004);
+}
+END_TEST
+START_TEST ( test_properties_color_hsla )
+{
+ widget wid;
+ wid.name = "blaat";
+ wid.state = NULL;
+ rofi_theme_parse_string ( "* { test1: hsla(127,40%,66.66666%); test2: hsla(0, 100%, 50%); }");
ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
Property *p = rofi_theme_find_property ( twid, P_COLOR, "test1", FALSE );
@@ -879,6 +907,7 @@ static Suite * theme_parser_suite (void)
tcase_add_test ( tc_prop_color, test_properties_color_rgba_percent);
tcase_add_test ( tc_prop_color, test_properties_color_argb);
tcase_add_test ( tc_prop_color, test_properties_color_hsl);
+ tcase_add_test ( tc_prop_color, test_properties_color_hsla);
tcase_add_test ( tc_prop_color, test_properties_color_hwb);
tcase_add_test ( tc_prop_color, test_properties_color_cmyk);
suite_add_tcase(s, tc_prop_color );