1
+ use std:: libc:: c_float;
1
2
use ast:: * ;
2
3
use super :: to_ascii_lower;
3
4
use self :: color_data:: { COLOR_KEYWORDS , COLOR_VALUES } ;
4
5
5
6
mod color_data;
6
7
7
- pub type ColorFloat = f64 ;
8
+
9
+ // Try to match rust-azure’s AzFloat
10
+ pub type ColorFloat = c_float ;
8
11
9
12
10
13
pub enum Color {
@@ -115,31 +118,31 @@ fn parse_color_function(name: &str, arguments: &[(ComponentValue, SourceLocation
115
118
// Either integers or percentages, but all the same type.
116
119
match iter. next ( ) {
117
120
Some ( & Number ( ref v) ) if v. int_value . is_some ( ) => {
118
- red = v. value / 255. ;
121
+ red = ( v. value as ColorFloat / 255. ) as ColorFloat ;
119
122
expect_comma ! ( ) ;
120
- green = expect_integer ! ( ) / 255. ;
123
+ green = ( expect_integer ! ( ) / 255. ) as ColorFloat ;
121
124
expect_comma ! ( ) ;
122
- blue = expect_integer ! ( ) / 255. ;
125
+ blue = ( expect_integer ! ( ) / 255. ) as ColorFloat ;
123
126
}
124
127
Some ( & Percentage ( ref v) ) => {
125
- red = v. value / 100. ;
128
+ red = ( v. value as ColorFloat / 100. ) as ColorFloat ;
126
129
expect_comma ! ( ) ;
127
- green = expect_percentage ! ( ) / 100. ;
130
+ green = ( expect_percentage ! ( ) / 100. ) as ColorFloat ;
128
131
expect_comma ! ( ) ;
129
- blue = expect_percentage ! ( ) / 100. ;
132
+ blue = ( expect_percentage ! ( ) / 100. ) as ColorFloat ;
130
133
}
131
134
_ => return None
132
135
} ;
133
136
} else {
134
- let hue: ColorFloat = expect_number ! ( ) / 360. ;
137
+ let hue = expect_number ! ( ) / 360. ;
135
138
let hue = hue - hue. floor ( ) ;
136
139
expect_comma ! ( ) ;
137
- let saturation: ColorFloat = ( expect_percentage ! ( ) / 100. ) . max ( & 0. ) . min ( & 1. ) ;
140
+ let saturation = ( expect_percentage ! ( ) / 100. ) . max ( & 0. ) . min ( & 1. ) ;
138
141
expect_comma ! ( ) ;
139
- let lightness: ColorFloat = ( expect_percentage ! ( ) / 100. ) . max ( & 0. ) . min ( & 1. ) ;
142
+ let lightness = ( expect_percentage ! ( ) / 100. ) . max ( & 0. ) . min ( & 1. ) ;
140
143
141
144
// http://www.w3.org/TR/css3-color/#hsl-color
142
- fn hue_to_rgb ( m1 : ColorFloat , m2 : ColorFloat , mut h : ColorFloat ) -> ColorFloat {
145
+ fn hue_to_rgb ( m1 : f64 , m2 : f64 , mut h : f64 ) -> f64 {
143
146
if h < 0. { h += 1. }
144
147
if h > 1. { h -= 1. }
145
148
@@ -151,17 +154,14 @@ fn parse_color_function(name: &str, arguments: &[(ComponentValue, SourceLocation
151
154
let m2 = if lightness <= 0.5 { lightness * ( saturation + 1. ) }
152
155
else { lightness + saturation - lightness * saturation } ;
153
156
let m1 = lightness * 2. - m2;
154
- red = hue_to_rgb ( m1, m2, hue + 1. / 3. ) ;
155
- green = hue_to_rgb ( m1, m2, hue) ;
156
- blue = hue_to_rgb ( m1, m2, hue - 1. / 3. ) ;
157
+ red = hue_to_rgb ( m1, m2, hue + 1. / 3. ) as ColorFloat ;
158
+ green = hue_to_rgb ( m1, m2, hue) as ColorFloat ;
159
+ blue = hue_to_rgb ( m1, m2, hue - 1. / 3. ) as ColorFloat ;
157
160
}
158
161
159
162
let alpha = if has_alpha {
160
163
expect_comma ! ( ) ;
161
- match iter. next ( ) {
162
- Some ( & Number ( ref a) ) => a. value . max ( & 0. ) . min ( & 1. ) ,
163
- _ => return None
164
- }
164
+ ( expect_number ! ( ) ) . max ( & 0. ) . min ( & 1. ) as ColorFloat
165
165
} else {
166
166
1.
167
167
} ;
0 commit comments