/** * 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); } }
/** * rtl background position-x and gradient * @param CSS\Value\RuleValueList $value */ public function rtl_background($value) { // if background poition-x is % or px rtl them /* @var $components CSS\Value\Size[] */ $components = $value->getListComponents(); foreach ($components as $key => $component) { if (is_string($component) && in_array($component, array('left', 'right'))) { // don't do any thing, this will be swaped later return true; } elseif ($component instanceof CSS\Value\Size) { if ($component->getUnit() == "%") { $component->setSize(100 - $component->getSize()); return false; } elseif ($component->getUnit() == "px") { $rtl_components = array(); foreach ($components as $ikey => $icomponent) { if ($key == $ikey) { $rtl_components[] = "left"; } // it will be swaped to right later $rtl_components[] = $icomponent; } $value->setListComponents($rtl_components); return false; } } } }