function csstidy_optimise::merge_font in Advanced CSS/JS Aggregation 6
Same name and namespace in other branches
- 7 advagg_css_compress/csstidy/class.csstidy_optimise.inc \csstidy_optimise::merge_font()
Merges all fonts properties
@version 1.3
Parameters
array $input_css:
Return value
array
See also
dissolve_short_font()
1 call to csstidy_optimise::merge_font()
- csstidy_optimise::postparse in advagg_css_compress/
csstidy/ class.csstidy_optimise.inc - Optimises $css after parsing @access public @version 1.0
File
- advagg_css_compress/
csstidy/ class.csstidy_optimise.inc, line 946
Class
- csstidy_optimise
- CSS Optimising Class
Code
function merge_font($input_css) {
$font_prop_default =& $GLOBALS['csstidy']['font_prop_default'];
$new_font_value = '';
$important = '';
// Skip if not 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 (csstidy::is_important($cur_value)) {
$important = '!important';
$cur_value = csstidy::gvw_important($cur_value);
}
$new_font_value .= $cur_value;
// Add delimiter
$new_font_value .= $font_property === 'font-size' && 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_property !== 'font' or !$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;
}