@@ -15,9 +15,17 @@ mod color_data;
1515pub type ColorFloat = c_float ;
1616
1717
18+ pub struct RGBA {
19+ // All in 0..1
20+ red : ColorFloat ,
21+ green : ColorFloat ,
22+ blue : ColorFloat ,
23+ alpha : ColorFloat ,
24+ }
25+
1826pub enum Color {
1927 CurrentColor ,
20- RGBA ( ColorFloat , ColorFloat , ColorFloat , ColorFloat ) , // 0..1
28+ RGBA ( RGBA ) ,
2129}
2230
2331
@@ -38,7 +46,7 @@ impl Color {
3846fn parse_color_keyword ( value : & str ) -> Option < Color > {
3947 let lower_value = value. to_ascii_lower ( ) ;
4048 match COLOR_KEYWORDS . bsearch_elem ( & lower_value. as_slice ( ) ) {
41- Some ( index) => Some ( COLOR_VALUES [ index] ) ,
49+ Some ( index) => Some ( RGBA ( COLOR_VALUES [ index] ) ) ,
4250 None => if "currentcolor" == lower_value { Some ( CurrentColor ) }
4351 else { None }
4452 }
@@ -60,8 +68,10 @@ fn parse_color_hash(value: &str) -> Option<Color> {
6068 )
6169 macro_rules! to_rgba(
6270 ( $r: expr, $g: expr, $b: expr, ) => {
63- Some ( RGBA ( $r as ColorFloat / 255. , $g as ColorFloat / 255. ,
64- $b as ColorFloat / 255. , 1. ) )
71+ Some ( RGBA ( RGBA { red: $r as ColorFloat / 255. ,
72+ green: $g as ColorFloat / 255. ,
73+ blue: $b as ColorFloat / 255. ,
74+ alpha: 1. } ) )
6575 } ;
6676 )
6777
@@ -170,5 +180,9 @@ fn parse_color_function(name: &str, arguments: &[ComponentValue])
170180 } else {
171181 1.
172182 } ;
173- if iter. next ( ) . is_none ( ) { Some ( RGBA ( red, green, blue, alpha) ) } else { None }
183+ if iter. next ( ) . is_none ( ) {
184+ Some ( RGBA ( RGBA { red : red, green : green, blue : blue, alpha : alpha } ) )
185+ } else {
186+ None
187+ }
174188}
0 commit comments