Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet

DeclarationBlock::expandFontShorthandpublicWC 1.0

Deprecated since since 8.7.0, will be removed without substitution in version 9.0 in #511. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

Converts shorthand font declarations (e.g. font: 300 italic 11px/14px verdana, helvetica, sans-serif;) into their constituent parts.

Method of the class: DeclarationBlock{}

No Hooks.

Returns

null. Nothing (null).

Usage

$DeclarationBlock = new DeclarationBlock();
$DeclarationBlock->expandFontShorthand();

Changelog

Deprecated Since 8.7.0 , will be removed without substitution in version 9.0 in #511

DeclarationBlock::expandFontShorthand() code WC 10.5.0

public function expandFontShorthand()
{
    $aRules = $this->getRulesAssoc();
    if (!isset($aRules['font'])) {
        return;
    }
    $oRule = $aRules['font'];
    // reset properties to 'normal' per http://www.w3.org/TR/21/fonts.html#font-shorthand
    $aFontProperties = [
        'font-style' => 'normal',
        'font-variant' => 'normal',
        'font-weight' => 'normal',
        'font-size' => 'normal',
        'line-height' => 'normal',
    ];
    $mRuleValue = $oRule->getValue();
    $aValues = [];
    if (!$mRuleValue instanceof RuleValueList) {
        $aValues[] = $mRuleValue;
    } else {
        $aValues = $mRuleValue->getListComponents();
    }
    foreach ($aValues as $mValue) {
        if (!$mValue instanceof Value) {
            $mValue = mb_strtolower($mValue);
        }
        if (in_array($mValue, ['normal', 'inherit'])) {
            foreach (['font-style', 'font-weight', 'font-variant'] as $sProperty) {
                if (!isset($aFontProperties[$sProperty])) {
                    $aFontProperties[$sProperty] = $mValue;
                }
            }
        } elseif (in_array($mValue, ['italic', 'oblique'])) {
            $aFontProperties['font-style'] = $mValue;
        } elseif ($mValue == 'small-caps') {
            $aFontProperties['font-variant'] = $mValue;
        } elseif (
            in_array($mValue, ['bold', 'bolder', 'lighter'])
            || ($mValue instanceof Size
                && in_array($mValue->getSize(), range(100, 900, 100)))
        ) {
            $aFontProperties['font-weight'] = $mValue;
        } elseif ($mValue instanceof RuleValueList && $mValue->getListSeparator() == '/') {
            list($oSize, $oHeight) = $mValue->getListComponents();
            $aFontProperties['font-size'] = $oSize;
            $aFontProperties['line-height'] = $oHeight;
        } elseif ($mValue instanceof Size && $mValue->getUnit() !== null) {
            $aFontProperties['font-size'] = $mValue;
        } else {
            $aFontProperties['font-family'] = $mValue;
        }
    }
    foreach ($aFontProperties as $sProperty => $mValue) {
        $oNewRule = new Rule($sProperty, $oRule->getLineNo(), $oRule->getColNo());
        $oNewRule->addValue($mValue);
        $oNewRule->setIsImportant($oRule->getIsImportant());
        $this->addRule($oNewRule);
    }
    $this->removeRule('font');
}