private function lessc::color in Less CSS Preprocessor 6
Same name and namespace in other branches
- 6.3 lessphp/lessc.inc.php \lessc::color()
1 call to lessc::color()
File
- ./
lessc.inc.php, line 626
Class
Code
private function color(&$out) {
$color = array(
'color',
);
if ($this
->match('(#([0-9a-f]{6})|#([0-9a-f]{3}))', $m)) {
if (isset($m[3])) {
$num = $m[3];
$width = 16;
}
else {
$num = $m[2];
$width = 256;
}
$num = hexdec($num);
foreach (array(
3,
2,
1,
) as $i) {
$t = $num % $width;
$num /= $width;
// todo: this is retarded
$color[$i] = $t * (256 / $width) + $t * floor(16 / $width);
}
}
else {
$save = $this->count;
try {
$this
->literal('rgb');
try {
$this
->literal('a');
$count = 4;
} catch (exception $ex) {
$count = 3;
}
$this
->literal('(');
// grab the numbers and format
foreach (range(1, $count) as $i) {
$this
->unit($color[], array(
'%',
));
if ($i != $count) {
$this
->literal(',');
}
if ($color[$i][0] == '%') {
$color[$i] = 255 * ($color[$i][1] / 100);
}
else {
$color[$i] = $color[$i][1];
}
}
$this
->literal(')');
$color = $this
->fixColor($color);
} catch (exception $ex) {
$this->count = $save;
throw new exception('failed to find color');
}
}
$out = $color;
// don't put things on out unless everything works out
return $this;
}