Exemplo n.º 1
0
 public static function parse($value, $variable = false)
 {
     $sv = new SizeValue($variable);
     // Definitive keyword sizes
     if (preg_match('/^(xx-small|x-small|small|medium|large|x-large|xx-large)$/i', $value)) {
         $sv->setSize($value);
         // Relative keyword sizes
     } elseif (preg_match('/^(larger|smaller)$/i', $value)) {
         $sv->setSize($value);
         // Hierarchical keyword sizes
     } elseif (preg_match('/^(inherit|initial|unset)$/i', $value)) {
         $sv->setSize($value);
         // Definitive sizes
     } elseif (preg_match('/^([1-9][0-9]*(\\.[0-9]+)?)(px|pt|pc|mm|cm|in)$/i', $value, $matches)) {
         $sv->setSize(floatval($matches[1]));
         $sv->setUnit($matches[3]);
         // Relative sizes
     } elseif (preg_match('/^([1-9][0-9]*(\\.[0-9]+)?)(em|rem|ex|%)?$/i', $value, $matches)) {
         $sv->setSize(floatval($matches[1]));
         if (isset($matches[3])) {
             $sv->setUnit($matches[3]);
         } else {
             $sv->setUnit('');
         }
     } else {
         return null;
     }
     return $sv;
 }
Exemplo n.º 2
0
 public static function parse($value, $variable = false)
 {
     if ($value instanceof Less_Tree_Dimension) {
         $unit = 'px';
         if (isset($value->unit->numerator[0])) {
             $unit = $value->unit->numerator[0];
         }
         $sv = new SizeValue($variable);
         $sv->setSize($value->value);
         $sv->setUnit($unit);
     }
     return $sv;
 }
Exemplo n.º 3
0
 public function getValueFromRequest(\Symfony\Component\HttpFoundation\ParameterBag $request)
 {
     $type = $request->get($this->getVariable());
     $tv = new TypeValue($this->getVariable());
     if ($type['font-family']) {
         $tv->setFontFamily($type['font-family']);
     }
     if ($type['font-weight']) {
         $tv->setFontWeight($type['font-weight']);
     }
     if ($type['italic']) {
         $tv->setFontStyle('italic');
     } else {
         if (isset($type['italic'])) {
             $tv->setFontStyle('none');
         }
     }
     if ($type['underline']) {
         $tv->setTextDecoration('underline');
     } else {
         if (isset($type['underline'])) {
             $tv->setDecoration('none');
         }
     }
     if ($type['uppercase']) {
         $tv->setTextTransform('uppercase');
     } else {
         if (isset($type['uppercase'])) {
             $tv->setTextTransform('none');
         }
     }
     if ($type['color']) {
         $cv = new \Primal\Color\Parser($type['color']);
         $result = $cv->getResult();
         $alpha = false;
         if ($result->alpha && $result->alpha < 1) {
             $alpha = $result->alpha;
         }
         $cvv = new ColorValue();
         $cvv->setRed($result->red);
         $cvv->setGreen($result->green);
         $cvv->setBlue($result->blue);
         $cvv->setAlpha($alpha);
         $tv->setColor($cvv);
     }
     if ($type['font-size']) {
         $sv = new SizeValue();
         $sv->setSize($type['font-size']['size']);
         if ($type['font-size']['unit']) {
             $sv->setUnit($type['font-size']['unit']);
         }
         $tv->setFontSize($sv);
     }
     if ($type['letter-spacing']) {
         $sv = new SizeValue();
         $sv->setSize($type['letter-spacing']['size']);
         if ($type['letter-spacing']['unit']) {
             $sv->setUnit($type['letter-spacing']['unit']);
         }
         $tv->setLetterSpacing($sv);
     }
     if ($type['line-height']) {
         $sv = new SizeValue();
         $sv->setSize($type['line-height']['size']);
         if ($type['line-height']['unit']) {
             $sv->setUnit($type['line-height']['unit']);
         }
         $tv->setLineHeight($sv);
     }
     return $tv;
 }