/** * @deprecated Old-Style 2-dimensional array given. Retained for (some) backwards-compatibility. Use setValue() instead and wrapp the value inside a RuleValueList if necessary. */ public function setValues($aSpaceSeparatedValues) { $oSpaceSeparatedList = null; if (count($aSpaceSeparatedValues) > 1) { $oSpaceSeparatedList = new RuleValueList(' '); } foreach ($aSpaceSeparatedValues as $aCommaSeparatedValues) { $oCommaSeparatedList = null; if (count($aCommaSeparatedValues) > 1) { $oCommaSeparatedList = new RuleValueList(','); } 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; }
/** * 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->getRulesAssoc(); if (!isset($aRules['font-size']) || !isset($aRules['font-family'])) { return; } $oNewRule = new Rule('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 RuleValueList) { $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 RuleValueList) { $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 RuleValueList) { $aLHValues[] = $mRuleValue; } else { $aLHValues = $mRuleValue->getListComponents(); } if ($aLHValues[0] !== 'normal') { $val = new RuleValueList('/'); $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 RuleValueList) { $aFFValues[] = $mRuleValue; } else { $aFFValues = $mRuleValue->getListComponents(); } $oFFValue = new RuleValueList(','); $oFFValue->setListComponents($aFFValues); $oNewRule->addValue($oFFValue); $this->addRule($oNewRule); foreach ($aFontProperties as $sProperty) { $this->removeRule($sProperty); } }
private function parseValue($aListDelimiters) { $aStack = array(); $this->consumeWhiteSpace(); //Build a list of delimiters and parsed values 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(); } //Convert the list to list objects 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, ++$iLength) { if ($sDelimiter !== $aStack[$i]) { break; } } $oList = new RuleValueList($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]; }
/** * * @param CSS\Value\RuleValueList $value */ public function rtl_border_radius_components($value) { // border-radius: 25px 10px => 10px 25px /* @var $components CSS\Value\Size[] */ $components = $value->getListComponents(); if (count($components) == 2) { $top_left = $components[1]->getSize(); $top_left_unit = $components[1]->getUnit(); $components[1]->setSize($components[0]->getSize()); $components[1]->setUnit($components[0]->getUnit()); $components[0]->setSize($top_left); $components[0]->setUnit($top_left_unit); return false; } else { if (count($components) == 3) { // border-radius: 25px 10px 15px => 10px 25px 10px 15px; // swap 1st and 2nd components $top_left = $components[1]->getSize(); $top_left_unit = $components[1]->getUnit(); $components[1]->setSize($components[0]->getSize()); $components[1]->setUnit($components[0]->getUnit()); $components[0]->setSize($top_left); $components[0]->setUnit($top_left_unit); // copy 3rd to 4th components $value->addListComponent(clone $components[2]); // copy the 1st components to the 3rd $components[2]->setSize($components[0]->getSize()); $components[2]->setUnit($components[0]->getUnit()); return false; } else { if (count($components) == 4) { // border-radius: 25px 10px 15px 8px => 10px 25px 8px 15px; // swap 1st and 2nd components $top_left = $components[1]->getSize(); $top_left_unit = $components[1]->getUnit(); $components[1]->setSize($components[0]->getSize()); $components[1]->setUnit($components[0]->getUnit()); $components[0]->setSize($top_left); $components[0]->setUnit($top_left_unit); // swap 3rd and 4th components $buttom_right = $components[3]->getSize(); $buttom_right_unit = $components[3]->getUnit(); $components[3]->setSize($components[2]->getSize()); $components[3]->setUnit($components[2]->getUnit()); $components[2]->setSize($buttom_right); $components[2]->setUnit($buttom_right_unit); return false; } else { return true; } } } }