/** * Merges all fonts properties. * * @since 1.0.0 * * @param [type] $input_css [description] * @return [type] [description] */ public function merge_font($input_css) { $font_prop_default =& $this->parser->data['csstidy']['font_prop_default']; $new_font_value = ''; $important = ''; // Skip if no font-family and font-size set. if (isset($input_css['font-family']) && isset($input_css['font-size'])) { // Fix several words in font-family - add quotes. if (isset($input_css['font-family'])) { $families = explode(",", $input_css['font-family']); $result_families = array(); foreach ($families as $family) { $family = trim($family); $len = strlen($family); if (strpos($family, " ") && !('"' === $family[0] && '"' === $family[$len - 1] || "'" === $family[0] && "'" === $family[$len - 1])) { $family = '"' . $family . '"'; } $result_families[] = $family; } $input_css['font-family'] = implode(",", $result_families); } foreach ($font_prop_default as $font_property => $default_value) { // Skip if property does not exist. if (!isset($input_css[$font_property])) { continue; } $cur_value = $input_css[$font_property]; // Skip if default value is used. if ($cur_value === $default_value) { continue; } // Remove !important. if ($this->parser->is_important($cur_value)) { $important = ' !important'; $cur_value = $this->parser->gvw_important($cur_value); } $new_font_value .= $cur_value; // Add delimiter. $new_font_value .= 'font-size' === $font_property && isset($input_css['line-height']) ? '/' : ' '; } $new_font_value = trim($new_font_value); // Delete all font properties. foreach ($font_prop_default as $font_property => $default_value) { if ('font' !== $font_property || !$new_font_value) { unset($input_css[$font_property]); } } // Add new font property. if ('' !== $new_font_value) { $input_css['font'] = $new_font_value . $important; } } return $input_css; }
/** * Converts $this->css array to a raw array ($this->tokens). * * @since 1.0.0 * * @param string $default_media Optional. Default @media to add to selectors without any @media. */ protected function _convert_raw_css($default_media = '') { $this->tokens = array(); $sort_selectors = $this->parser->get_cfg('sort_selectors'); $sort_properties = $this->parser->get_cfg('sort_properties'); foreach ($this->css as $medium => $val) { if ($sort_selectors) { ksort($val); } if (intval($medium) < DEFAULT_AT) { // un medium vide (contenant @font-face ou autre @) ne produit aucun conteneur if (strlen(trim($medium))) { $this->parser->_add_token(AT_START, $medium, true); } } elseif ($default_media) { $this->parser->_add_token(AT_START, $default_media, true); } foreach ($val as $selector => $vali) { if ($sort_properties) { ksort($vali); } $this->parser->_add_token(SEL_START, $selector, true); $invalid = array('*' => array(), '_' => array(), '/' => array(), '-' => array()); foreach ($vali as $property => $valj) { if (0 !== strncmp($property, '//', 2)) { $matches = array(); if ($sort_properties && preg_match('/^(\\*|_|\\/|-)(?!(ms|moz|o\\b|xv|atsc|wap|khtml|webkit|ah|hp|ro|rim|tc)-)/', $property, $matches)) { $invalid[$matches[1]][$property] = $valj; } else { $this->parser->_add_token(PROPERTY, $property, true); $this->parser->_add_token(VALUE, $valj, true); } } } foreach ($invalid as $prefix => $props) { foreach ($props as $property => $valj) { $this->parser->_add_token(PROPERTY, $property, true); $this->parser->_add_token(VALUE, $valj, true); } } $this->parser->_add_token(SEL_END, $selector, true); } if (intval($medium) < DEFAULT_AT) { // un medium vide (contenant @font-face ou autre @) ne produit aucun conteneur if (strlen(trim($medium))) { $this->parser->_add_token(AT_END, $medium, true); } } elseif ($default_media) { $this->parser->_add_token(AT_END, $default_media, true); } } }