public function SassColour::toString in Sassy 7
Same name and namespace in other branches
- 7.3 phpsass/script/literals/SassColour.php \SassColour::toString()
* Converts the colour to a string. *
Parameters
boolean whether to use CSS3 SVG1.0 colour names: * @return string the colour as a named colour, rgba(r,g,g,a) or #rrggbb
Overrides SassLiteral::toString
File
- phamlp/
sass/ script/ literals/ SassColour.php, line 739
Class
- SassColour
- SassColour class. A SassScript object representing a CSS colour.
Code
public function toString($css3 = false) {
$rgba = $this->rgba;
if ($rgba[3] == 0) {
return 'transparent';
}
elseif ($rgba[3] < 1) {
return sprintf('rgba(%d,%d,%d,%1.2f)', $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
}
else {
$colour = sprintf('#%02x%02x%02x', $rgba[0], $rgba[1], $rgba[2]);
}
if ($css3) {
if (empty(self::$_svgColours)) {
self::$_svgColours = array_flip(self::$svgColours);
}
return array_key_exists($colour, self::$svgColours) ? self::$_svgColours[$colour] : $colour;
}
else {
return array_key_exists($colour, self::$_html4Colours) ? self::$_html4Colours[$colour] : $colour;
}
}