Exemplo n.º 1
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     // Shorthand RGB color values
     if ($oOutputFormat->getRGBHashNotation() && implode('', array_keys($this->aComponents)) === 'rgb') {
         $sResult = sprintf('%02x%02x%02x', $this->aComponents['r']->getSize(), $this->aComponents['g']->getSize(), $this->aComponents['b']->getSize());
         return '#' . ($sResult[0] == $sResult[1] && $sResult[2] == $sResult[3] && $sResult[4] == $sResult[5] ? "{$sResult['0']}{$sResult['2']}{$sResult['4']}" : $sResult);
     }
     return parent::render($oOutputFormat);
 }
Exemplo n.º 2
0
 public function __toString()
 {
     // Shorthand RGB color values
     // TODO: Include in output settings (once they’re done)
     if (implode('', array_keys($this->aComponents)) === 'rgb') {
         $sResult = sprintf('%02x%02x%02x', $this->aComponents['r']->__toString(), $this->aComponents['g']->__toString(), $this->aComponents['b']->__toString());
         return '#' . ($sResult[0] == $sResult[1] && $sResult[2] == $sResult[3] && $sResult[4] == $sResult[5] ? "{$sResult['0']}{$sResult['2']}{$sResult['4']}" : $sResult);
     }
     return parent::__toString();
 }
Exemplo n.º 3
0
 public function __construct($mColor = null)
 {
     parent::__construct('rgb', null);
     if (is_array($mColor)) {
         if (isset($mColor['r'], $mColor['g'], $mColor['b'])) {
             $this->fromRGB($mColor);
         } else {
             if (isset($mColor['h'], $mColor['s'], $mColor['l'])) {
                 $this->fromHSL($mColor);
             }
         }
     } else {
         if (is_string($mColor)) {
             if ($aRGB = CSSColorUtils::namedColor2rgb($mColor)) {
                 $this->fromRGB($aRGB);
             } else {
                 if ($aRGB = CSSColorUtils::hex2rgb($mColor)) {
                     $this->fromRGB($aRGB);
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
 public function __construct($aColor)
 {
     parent::__construct(implode('', array_keys($aColor)), $aColor);
 }