예제 #1
0
 /**
  * @dataProvider rgb2hslProvider
  * @depends testNormalizeRGBValue
  **/
 public function testRgb2hsl($r, $g, $b, $aExpected)
 {
     $aHSL = CSSColorUtils::rgb2hsl($r, $g, $b, $aExpected);
     // assertEquals because hsl2rgb returns an array of floats,
     // even if they are rounded
     $this->assertEquals($aHSL, $aExpected);
 }
예제 #2
0
 private function parseIdentifier($bAllowFunctions = false, $bAllowColors = false)
 {
     $sResult = $this->parseCharacter(true);
     if ($sResult === null) {
         throw new Exception("Identifier expected, got {$this->peek(5)}");
     }
     $sCharacter;
     while (($sCharacter = $this->parseCharacter(true)) !== null) {
         $sResult .= $sCharacter;
     }
     if ($bAllowColors) {
         // is it a color name ?
         if ($aColor = CSSColorUtils::namedColor2rgb($sResult)) {
             $oColor = new CSSColor();
             return $oColor->fromRGB($aColor);
         }
     }
     if ($bAllowFunctions && $this->comes('(')) {
         $this->consume('(');
         $sResult = new CSSFunction($sResult, $this->parseValue(array('=', ',')));
         $this->consume(')');
     }
     return $sResult;
 }
예제 #3
0
 public function getHexValue()
 {
     $aComponents = $this->aComponents;
     if (isset($aComponents['a']) && $aComponents['a']->getSize() !== 1) {
         return null;
     }
     $sName = $this->getName();
     if ($sName == 'rgb') {
         return CSSColorUtils::rgb2hex($aComponents['r']->getSize(), $aComponents['g']->getSize(), $aComponents['b']->getSize());
     } else {
         if ($sName == 'hsl') {
             return CSSColorUtils::hsl2hex($aComponents['h']->getSize(), $aComponents['s']->getSize(), $aComponents['l']->getSize());
         }
     }
 }