Beispiel #1
0
 public function getHexValue()
 {
     $channels = $this->channels;
     if (isset($channels['a']) && $channels['a']->getValue() !== 1) {
         return null;
     }
     if ($this->mode === 'rgb') {
         return Util\Color::rgbToHex($channels['r']->getValue(), $channels['g']->getValue(), $channels['b']->getValue());
     } else {
         if ($this->mode === 'hsl') {
             return Util\Color::hslToX11($channels['h']->getValue(), $channels['s']->getValue(), $channels['l']->getValue());
         }
     }
 }
Beispiel #2
0
 /**
  * term
  *   : unary_operator?
  *     [ NUMBER S* | PERCENTAGE S* | LENGTH S* | ANGLE S* | TIME S* | FREQ S* ]
  *   | STRING S* | IDENT S* | URI S* | UNICODERANGE S* | FROM_SYM S* | TO_SYM S*
  *   | hexcolor | function | math
  *   ;
  **/
 protected function _term()
 {
     /*{{{*/
     $token = $this->LT();
     switch ($token->type) {
         case Lexer::T_NUMBER:
             $this->consume();
             $this->_ws();
             return new Value\Dimension($token->value, null);
         case Lexer::T_DIMENSION:
             $value = $token->value;
             $this->consume();
             $this->_ws();
             return new Value\Dimension($value['value'], $value['unit']);
         case Lexer::T_RATIO:
             $value = $token->value;
             $this->consume();
             $this->_ws();
             return new Value\Ratio($value['numerator'], $value['denominator']);
         case Lexer::T_PERCENTAGE:
             $this->consume();
             $this->_ws();
             return new Value\Percentage($token->value);
         case Lexer::T_LENGTH:
             $value = $token->value;
             $this->consume();
             $this->_ws();
             return new Value\Length($value['value'], $value['unit']);
         case Lexer::T_ANGLE:
             $value = $token->value;
             $this->consume();
             $this->_ws();
             return new Value\Angle($value['value'], $value['unit']);
         case Lexer::T_TIME:
             $value = $token->value;
             $this->consume();
             $this->_ws();
             return new Value\Time($value['value'], $value['unit']);
         case Lexer::T_FREQ:
             $value = $token->value;
             $this->consume();
             $this->_ws();
             return new Value\Frequency($value['value'], $value['unit']);
         case Lexer::T_STRING:
             $this->consume();
             $this->_ws();
             return new Value\String($token->value);
         case Lexer::T_FROM_SYM:
         case Lexer::T_TO_SYM:
             $ident = $token->value;
             $this->consume();
             $this->_ws();
             return $ident;
         case Lexer::T_IDENT:
             $ident = $token->value;
             $this->consume();
             $this->_ws();
             // is it a color name ?
             if ($rgb = Util\Color::x11ToRgb($ident)) {
                 $color = new Value\Color();
                 return $color->fromRgb($rgb);
             }
             return $ident;
         case Lexer::T_URI:
             $this->consume();
             $this->_ws();
             return new Value\Url(new Value\String($token->value));
         case Lexer::T_UNICODERANGE:
             $this->consume();
             $this->_ws();
             return new Value\UnicodeRange($token->value);
         case Lexer::T_FUNCTION:
             return $this->_function();
         case Lexer::T_HASH:
             return $this->_hexcolor();
         case Lexer::T_INVALID:
         case Lexer::T_BADSTRING:
         case Lexer::T_BADURI:
         case Lexer::T_EOF:
             $this->_unexpectedToken($token, array(Lexer::T_HASH, Lexer::T_FUNCTION, Lexer::T_UNICODERANGE, Lexer::T_URI, Lexer::T_IDENT, Lexer::T_STRING, Lexer::T_FREQ, Lexer::T_TIME, Lexer::T_ANGLE, Lexer::T_LENGTH, Lexer::T_PERCENTAGE, Lexer::T_RATIO, Lexer::T_DIMENSION, Lexer::T_FROM_SYM, Lexer::T_TO_SYM, Lexer::T_NUMBER));
             break;
         default:
             break;
     }
 }