- Enables dynamic line-height based on font-size

This commit is contained in:
Vlad
2016-04-08 15:16:11 -04:00
parent 813db1ae33
commit ba40437eb9
5 changed files with 26 additions and 11 deletions

View File

@@ -27,7 +27,8 @@ class StylesHelper {
'Trebuchet MS' => "'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Tahoma, sans-serif",
'Verdana' => 'Verdana, Geneva, sans-serif'
);
static $line_height = 1.61803398875;
static $line_height_multiplier = 1.6;
static $heading_margin_multiplier = 0.3;
static $padding_width = 20;
static function getBlockStyles($element, $ignore_specific_styles = false) {
@@ -55,6 +56,7 @@ class StylesHelper {
static function setStyle($style, $selector) {
$css = $selector . '{' . PHP_EOL;
$style = self::applyHeadingMargin($style, $selector);
$style = self::applyLineHeight($style, $selector);
foreach($style as $attribute => $individual_style) {
$individual_style = self::applyFontFamily($attribute, $individual_style);
$css .= self::translateCSSAttribute($attribute) . ':' . $individual_style . ';' . PHP_EOL;
@@ -87,9 +89,16 @@ class StylesHelper {
}
static function applyHeadingMargin($style, $selector) {
if (!preg_match('/h[1|2|3|4]/i', $selector)) return $style;
if (!preg_match('/h[1-4]/i', $selector)) return $style;
$font_size = (int) $style['fontSize'];
$style['margin'] = sprintf('0 0 %spx 0', 0.3 * $font_size);
$style['margin'] = sprintf('0 0 %spx 0', self::$heading_margin_multiplier * $font_size);
return $style;
}
static function applyLineHeight($style, $selector) {
if (!preg_match('/mailpoet_paragraph|h[1-4]/i', $selector)) return $style;
$font_size = (int) $style['fontSize'];
$style['lineHeight'] = sprintf('%spx', self::$line_height_multiplier * $font_size);
return $style;
}
}