From d79423f2cfe1db48300d1d3aee7d82f83ffa9f05 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Wed, 26 Apr 2017 18:43:49 +0200 Subject: [PATCH] [Lexer] Fix wrong division factor for #RGB color parsing (15 not 16) --- lexer/theme-lexer.l | 6 ++--- test/theme-parser-test.c | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 96f3936b..c6a7795f 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -426,9 +426,9 @@ if ( queue == NULL ){ union { uint16_t val; struct { unsigned char b:4,g:4,r:4,a :4;};} val; val.val = (uint16_t )g_ascii_strtoull ( &yytext[1], NULL, 16); yylval->colorval.alpha = 1.0; - yylval->colorval.red = val.r/16.0; - yylval->colorval.green = val.g/16.0; - yylval->colorval.blue = val.b/16.0; + yylval->colorval.red = val.r/15.0; + yylval->colorval.green = val.g/15.0; + yylval->colorval.blue = val.b/15.0; return T_COLOR; } rgba\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3},[01](\.{NUMBER}+)?\) { diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index 29c7daa8..1846a57c 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -297,6 +297,57 @@ int main ( int argc, char ** argv ) rofi_theme_free ( rofi_theme ); rofi_theme = NULL; } + { + rofi_theme = NULL; + error = 0; + rofi_theme_parse_string ( "* { none: none; bold: bold; underline: underline; italic: italic;}"); + TASSERT ( error == 0 ); + ThemeHighlight th = { HL_BOLD, {0.0,0.0,0.0,0.0}}; + th = rofi_theme_get_highlight ( &wid, "none", th); + TASSERT ( th.style == HL_NONE ); + th = rofi_theme_get_highlight ( &wid, "underline", th); + TASSERT ( th.style == HL_UNDERLINE); + th = rofi_theme_get_highlight ( &wid, "italic", th); + TASSERT ( th.style == HL_ITALIC); + th = rofi_theme_get_highlight ( &wid, "bold", th); + TASSERT ( th.style == HL_BOLD); + + rofi_theme_parse_string ( "* { boldu: bold underline ; boldi: bold italic; underlinei: underline italic; italicu: italic underline;}"); + th = rofi_theme_get_highlight ( &wid, "boldu", th); + TASSERT ( th.style == (HL_UNDERLINE|HL_BOLD)); + th = rofi_theme_get_highlight ( &wid, "boldi", th); + TASSERT ( th.style == (HL_ITALIC|HL_BOLD)); + th = rofi_theme_get_highlight ( &wid, "underlinei", th); + TASSERT ( th.style == (HL_ITALIC|HL_UNDERLINE)); + th = rofi_theme_get_highlight ( &wid, "italicu", th); + TASSERT ( th.style == (HL_ITALIC|HL_UNDERLINE)); + rofi_theme_free ( rofi_theme ); + rofi_theme = NULL; + } + { + rofi_theme = NULL; + error = 0; + rofi_theme_parse_string ( "* { red: #F00; green: #0F0; blue: #00F; }"); + TASSERT ( error == 0 ); + ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE ); + Property *p = rofi_theme_find_property ( twid, P_COLOR, "red", FALSE ); + TASSERT ( p != NULL ); + TASSERT ( p->value.color.red == 1 ); + TASSERT ( p->value.color.green == 0 ); + TASSERT ( p->value.color.blue == 0 ); + p = rofi_theme_find_property ( twid, P_COLOR, "green", FALSE ); + TASSERT ( p != NULL ); + TASSERT ( p->value.color.red == 0 ); + TASSERT ( p->value.color.green == 1 ); + TASSERT ( p->value.color.blue == 0 ); + p = rofi_theme_find_property ( twid, P_COLOR, "blue", FALSE ); + TASSERT ( p != NULL ); + TASSERT ( p->value.color.red == 0 ); + TASSERT ( p->value.color.green == 0 ); + TASSERT ( p->value.color.blue == 1 ); + rofi_theme_free ( rofi_theme ); + rofi_theme = NULL; + } { rofi_theme = NULL; rofi_theme_parse_file ("/dev/null");