You are here

public function SassColour::toString in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/sass/script/literals/SassColour.php \SassColour::toString()

Converts the colour to a string.

Parameters

boolean whether to use CSS3 SVG1.0 colour names:

Return value

string the colour as a named colour, rgba(r,g,g,a) or #rrggbb

Overrides SassLiteral::toString

File

phpsass/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;
  }
}