diff --git a/mailpoet/lib/Form/Block/BlockRendererHelper.php b/mailpoet/lib/Form/Block/BlockRendererHelper.php index 91232f4d32..f20acc93eb 100644 --- a/mailpoet/lib/Form/Block/BlockRendererHelper.php +++ b/mailpoet/lib/Form/Block/BlockRendererHelper.php @@ -188,8 +188,8 @@ class BlockRendererHelper { public function renderFontStyle(array $formSettings, array $styles = []) { $rules = []; if (isset($formSettings['fontSize'])) { - $rules[] = 'font-size: ' . trim($formSettings['fontSize']) . 'px;'; - $rules[] = 'line-height: ' . (float)trim($formSettings['fontSize']) * 1.2 . 'px";'; + $rules[] = 'font-size: ' . $formSettings['fontSize'] . (is_numeric($formSettings['fontSize']) ? "px;" : ";"); + $rules[] = 'line-height: 1.2;'; } if (isset($styles['bold'])) { $rules[] = 'font-weight: bold;'; diff --git a/mailpoet/lib/Form/Block/Heading.php b/mailpoet/lib/Form/Block/Heading.php index f1b7ef90a1..f24ac6f1af 100644 --- a/mailpoet/lib/Form/Block/Heading.php +++ b/mailpoet/lib/Form/Block/Heading.php @@ -93,7 +93,7 @@ class Heading { $styles[] = 'color: ' . $block['params']['text_color']; } if (!empty($block['params']['font_size'])) { - $styles[] = 'font-size: ' . $block['params']['font_size'] . 'px'; + $styles[] = 'font-size: ' . $block['params']['font_size'] . (is_numeric($block['params']['font_size']) ? 'px' : ''); } if (!empty($block['params']['line_height'])) { $styles[] = 'line-height: ' . $block['params']['line_height']; diff --git a/mailpoet/lib/Form/Block/Paragraph.php b/mailpoet/lib/Form/Block/Paragraph.php index 239279c118..f13286f21f 100644 --- a/mailpoet/lib/Form/Block/Paragraph.php +++ b/mailpoet/lib/Form/Block/Paragraph.php @@ -78,7 +78,7 @@ class Paragraph { $styles[] = 'color: ' . $block['params']['text_color']; } if (!empty($block['params']['font_size'])) { - $styles[] = 'font-size: ' . $block['params']['font_size'] . 'px'; + $styles[] = 'font-size: ' . $block['params']['font_size'] . (is_numeric($block['params']['font_size']) ? 'px' : ''); } if (!empty($block['params']['line_height'])) { $styles[] = 'line-height: ' . $block['params']['line_height']; diff --git a/mailpoet/lib/Form/BlockStylesRenderer.php b/mailpoet/lib/Form/BlockStylesRenderer.php index 2c5bff558c..13f3ec7b7b 100644 --- a/mailpoet/lib/Form/BlockStylesRenderer.php +++ b/mailpoet/lib/Form/BlockStylesRenderer.php @@ -48,10 +48,10 @@ class BlockStylesRenderer { $rules[] = "font-family:'{$formSettings['font_family']}';" ; } if (isset($styles['font_size'])) { - $rules[] = "font-size:" . intval($styles['font_size']) . "px;"; + $rules[] = "font-size:" . $styles['font_size'] . (is_numeric($styles['font_size']) ? "px;" : ";"); } if (isset($formSettings['fontSize']) && !isset($styles['font_size'])) { - $rules[] = "font-size:" . intval($formSettings['fontSize']) . "px;"; + $rules[] = "font-size:" . $formSettings['fontSize'] . (is_numeric($formSettings['fontSize']) ? "px;" : ";"); } if (isset($formSettings['fontSize']) || isset($styles['font_size'])) { $rules[] = "line-height:1.5;"; diff --git a/mailpoet/tests/unit/Form/Block/BlockRendererHelperTest.php b/mailpoet/tests/unit/Form/Block/BlockRendererHelperTest.php index 5e55515e9e..368801541a 100644 --- a/mailpoet/tests/unit/Form/Block/BlockRendererHelperTest.php +++ b/mailpoet/tests/unit/Form/Block/BlockRendererHelperTest.php @@ -58,6 +58,12 @@ class BlockRendererHelperTest extends \MailPoetUnitTest { $block['params']['hide_label'] = '1'; $label = $this->rendererHelper->renderLabel($block, []); expect($label)->equals(''); + + $label = $this->rendererHelper->renderLabel($this->block, ['fontSize' => 10]); + expect($label)->stringContainsString('style="font-size: 10px;'); + + $label = $this->rendererHelper->renderLabel($this->block, ['fontSize' => '1.2em']); + expect($label)->stringContainsString('style="font-size: 1.2em;'); } public function testItShouldRenderLegend() { diff --git a/mailpoet/tests/unit/Form/Block/HeadingTest.php b/mailpoet/tests/unit/Form/Block/HeadingTest.php index b195b5c80e..8bea8676be 100644 --- a/mailpoet/tests/unit/Form/Block/HeadingTest.php +++ b/mailpoet/tests/unit/Form/Block/HeadingTest.php @@ -105,6 +105,16 @@ class HeadingTest extends \MailPoetUnitTest { expect($html)->equals('

Header

'); } + public function testItShouldRenderFontSizeWithUnit() { + $html = $this->heading->render([ + 'params' => [ + 'content' => 'Header', + 'font_size' => '2.2em', + ], + ]); + expect($html)->equals('

Header

'); + } + public function testItShouldRenderLineHeight() { $html = $this->heading->render([ 'params' => [ diff --git a/mailpoet/tests/unit/Form/Block/ParagraphTest.php b/mailpoet/tests/unit/Form/Block/ParagraphTest.php index d54a8e15e7..25a147b77a 100644 --- a/mailpoet/tests/unit/Form/Block/ParagraphTest.php +++ b/mailpoet/tests/unit/Form/Block/ParagraphTest.php @@ -80,6 +80,16 @@ class ParagraphTest extends \MailPoetUnitTest { expect($html)->equals('

Paragraph

'); } + public function testItShouldRenderFontSizeWithUnit() { + $html = $this->paragraph->render([ + 'params' => [ + 'content' => 'Paragraph', + 'font_size' => '2.3em', + ], + ]); + expect($html)->equals('

Paragraph

'); + } + public function testItShouldRenderLineHeight() { $html = $this->paragraph->render([ 'params' => [ diff --git a/mailpoet/tests/unit/Form/BlockStylesRendererTest.php b/mailpoet/tests/unit/Form/BlockStylesRendererTest.php index 37424327e3..695dca283b 100644 --- a/mailpoet/tests/unit/Form/BlockStylesRendererTest.php +++ b/mailpoet/tests/unit/Form/BlockStylesRendererTest.php @@ -123,4 +123,23 @@ class BlockStylesRendererTest extends \MailPoetUnitTest { $result = $this->renderer->renderForButton(['font_family' => 'font2'], $settings); expect($result)->stringContainsString("font-family:'font2'"); } + + public function testItShouldSupportFontSizesWithUnits() { + $settings = [ + 'input_padding' => '40', + 'fontSize' => '1.5rem', + ]; + $result = $this->renderer->renderForButton([], $settings); + expect($result)->stringContainsString('font-size:1.5rem;'); + $styles = [ + 'font_size' => '2.4em', + ]; + $result = $this->renderer->renderForButton($styles, $settings); + expect($result)->stringContainsString('font-size:2.4em;'); + $styles = [ + 'font_size' => '23', + ]; + $result = $this->renderer->renderForButton($styles, $settings); + expect($result)->stringContainsString('font-size:23px;'); + } }