Example #1
0
 /**
  *	@deprecated Old-Style 2-dimensional array given. Retained for (some) backwards-compatibility. Use setValue() instead and wrapp the value inside a CSSRuleValueList if necessary.
  */
 public function setValues($aSpaceSeparatedValues)
 {
     $oSpaceSeparatedList = null;
     if (count($aSpaceSeparatedValues) > 1) {
         $oSpaceSeparatedList = new CSSRuleValueList(' ');
     }
     foreach ($aSpaceSeparatedValues as $aCommaSeparatedValues) {
         $oCommaSeparatedList = null;
         if (count($aCommaSeparatedValues) > 1) {
             $oCommaSeparatedList = new CSSRuleValueList(',');
         }
         foreach ($aCommaSeparatedValues as $mValue) {
             if (!$oSpaceSeparatedList && !$oCommaSeparatedList) {
                 $this->mValue = $mValue;
                 return $mValue;
             }
             if ($oCommaSeparatedList) {
                 $oCommaSeparatedList->addListComponent($mValue);
             } else {
                 $oSpaceSeparatedList->addListComponent($mValue);
             }
         }
         if (!$oSpaceSeparatedList) {
             $this->mValue = $oCommaSeparatedList;
             return $oCommaSeparatedList;
         } else {
             $oSpaceSeparatedList->addListComponent($oCommaSeparatedList);
         }
     }
     $this->mValue = $oSpaceSeparatedList;
     return $oSpaceSeparatedList;
 }
Example #2
0
 private function parseValue($aListDelimiters)
 {
     $aStack = array();
     $this->consumeWhiteSpace();
     while (!($this->comes('}') || $this->comes(';') || $this->comes('!') || $this->comes(')'))) {
         if (count($aStack) > 0) {
             $bFoundDelimiter = false;
             foreach ($aListDelimiters as $sDelimiter) {
                 if ($this->comes($sDelimiter)) {
                     array_push($aStack, $this->consume($sDelimiter));
                     $this->consumeWhiteSpace();
                     $bFoundDelimiter = true;
                     break;
                 }
             }
             if (!$bFoundDelimiter) {
                 //Whitespace was the list delimiter
                 array_push($aStack, ' ');
             }
         }
         array_push($aStack, $this->parsePrimitiveValue());
         $this->consumeWhiteSpace();
     }
     foreach ($aListDelimiters as $sDelimiter) {
         if (count($aStack) === 1) {
             return $aStack[0];
         }
         $iStartPosition = null;
         while (($iStartPosition = array_search($sDelimiter, $aStack, true)) !== false) {
             $iLength = 2;
             //Number of elements to be joined
             for ($i = $iStartPosition + 2; $i < count($aStack); $i += 2) {
                 if ($sDelimiter !== $aStack[$i]) {
                     break;
                 }
                 $iLength++;
             }
             $oList = new CSSRuleValueList($sDelimiter);
             for ($i = $iStartPosition - 1; $i - $iStartPosition + 1 < $iLength * 2; $i += 2) {
                 $oList->addListComponent($aStack[$i]);
             }
             array_splice($aStack, $iStartPosition - 1, $iLength * 2 - 1, array($oList));
         }
     }
     return $aStack[0];
 }
Example #3
0
 /**
  * Looks for long format CSS font properties (e.g. <tt>font-weight</tt>) and 
  * tries to convert them into a shorthand CSS <tt>font</tt> property. 
  * At least font-size AND font-family must be present in order to create a shorthand declaration.
  **/
 public function createFontShorthand()
 {
     $aFontProperties = array('font-style', 'font-variant', 'font-weight', 'font-size', 'line-height', 'font-family');
     $aRules = $this->getRules();
     if (!isset($aRules['font-size']) || !isset($aRules['font-family'])) {
         return;
     }
     $oNewRule = new CSSRule('font');
     foreach (array('font-style', 'font-variant', 'font-weight') as $sProperty) {
         if (isset($aRules[$sProperty])) {
             $oRule = $aRules[$sProperty];
             $mRuleValue = $oRule->getValue();
             $aValues = array();
             if (!$mRuleValue instanceof CSSRuleValueList) {
                 $aValues[] = $mRuleValue;
             } else {
                 $aValues = $mRuleValue->getListComponents();
             }
             if ($aValues[0] !== 'normal') {
                 $oNewRule->addValue($aValues[0]);
             }
         }
     }
     // Get the font-size value
     $oRule = $aRules['font-size'];
     $mRuleValue = $oRule->getValue();
     $aFSValues = array();
     if (!$mRuleValue instanceof CSSRuleValueList) {
         $aFSValues[] = $mRuleValue;
     } else {
         $aFSValues = $mRuleValue->getListComponents();
     }
     // But wait to know if we have line-height to add it
     if (isset($aRules['line-height'])) {
         $oRule = $aRules['line-height'];
         $mRuleValue = $oRule->getValue();
         $aLHValues = array();
         if (!$mRuleValue instanceof CSSRuleValueList) {
             $aLHValues[] = $mRuleValue;
         } else {
             $aLHValues = $mRuleValue->getListComponents();
         }
         if ($aLHValues[0] !== 'normal') {
             $val = new CSSRuleValueList('/');
             $val->addListComponent($aFSValues[0]);
             $val->addListComponent($aLHValues[0]);
             $oNewRule->addValue($val);
         }
     } else {
         $oNewRule->addValue($aFSValues[0]);
     }
     $oRule = $aRules['font-family'];
     $mRuleValue = $oRule->getValue();
     $aFFValues = array();
     if (!$mRuleValue instanceof CSSRuleValueList) {
         $aFFValues[] = $mRuleValue;
     } else {
         $aFFValues = $mRuleValue->getListComponents();
     }
     $oFFValue = new CSSRuleValueList(',');
     $oFFValue->setListComponents($aFFValues);
     $oNewRule->addValue($oFFValue);
     $this->addRule($oNewRule);
     foreach ($aFontProperties as $sProperty) {
         $this->removeRule($sProperty);
     }
 }