Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet
DeclarationBlock::createFontShorthand
Устарела с версии since 8.7.0, will be removed without substitution in version 9.0 in #511. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.
Looks for long format CSS font properties (e.g. font-weight) and tries to convert them into a shorthand CSS font property.
At least font-size AND font-family must be present in order to create a shorthand declaration.
Метод класса: DeclarationBlock{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$DeclarationBlock = new DeclarationBlock(); $DeclarationBlock->createFontShorthand();
Список изменений
| Устарела | С версии 8.7.0 | , will be removed without substitution in version 9.0 in #511 |
Код DeclarationBlock::createFontShorthand() DeclarationBlock::createFontShorthand WC 10.4.3
public function createFontShorthand()
{
$aFontProperties = [
'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;
}
$oOldRule = isset($aRules['font-size']) ? $aRules['font-size'] : $aRules['font-family'];
$oNewRule = new Rule('font', $oOldRule->getLineNo(), $oOldRule->getColNo());
unset($oOldRule);
foreach (['font-style', 'font-variant', 'font-weight'] as $sProperty) {
if (isset($aRules[$sProperty])) {
$oRule = $aRules[$sProperty];
$mRuleValue = $oRule->getValue();
$aValues = [];
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 = [];
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 = [];
if (!$mRuleValue instanceof RuleValueList) {
$aLHValues[] = $mRuleValue;
} else {
$aLHValues = $mRuleValue->getListComponents();
}
if ($aLHValues[0] !== 'normal') {
$val = new RuleValueList('/', $this->getLineNo());
$val->addListComponent($aFSValues[0]);
$val->addListComponent($aLHValues[0]);
$oNewRule->addValue($val);
}
} else {
$oNewRule->addValue($aFSValues[0]);
}
$oRule = $aRules['font-family'];
$mRuleValue = $oRule->getValue();
$aFFValues = [];
if (!$mRuleValue instanceof RuleValueList) {
$aFFValues[] = $mRuleValue;
} else {
$aFFValues = $mRuleValue->getListComponents();
}
$oFFValue = new RuleValueList(',', $this->getLineNo());
$oFFValue->setListComponents($aFFValues);
$oNewRule->addValue($oFFValue);
$this->addRule($oNewRule);
foreach ($aFontProperties as $sProperty) {
$this->removeRule($sProperty);
}
}