From de01e86d41e397891fe5a8255b2b595ccd883b75 Mon Sep 17 00:00:00 2001 From: troosan Date: Mon, 19 Mar 2018 22:43:10 +0100 Subject: [PATCH] parse fixed line space --- src/PhpWord/Shared/Html.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index dcf84778..f8b25605 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -521,7 +521,18 @@ class Html $styles['bgColor'] = trim($cValue, '#'); break; case 'line-height': - $styles['lineHeight'] = Html::toMultiplier($cValue); + if (preg_match('/([0-9]+[a-z]+)/', $cValue, $matches)) { + $spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT; + $spacing = Converter::cssToTwip($matches[1]) / \PhpOffice\PhpWord\Style\Paragraph::LINE_HEIGHT; + } elseif (preg_match('/([0-9]+)%/', $cValue, $matches)) { + $spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO; + $spacing = ((int) $matches[1]) / 100; + } else { + $spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO; + $spacing = $cValue; + } + $styles['spacingLineRule'] = $spacingLineRule; + $styles['lineHeight'] = $spacing; break; case 'text-indent': $styles['indentation']['firstLine'] = Converter::cssToTwip($cValue); @@ -681,15 +692,6 @@ class Html return null; } - private static function toMultiplier($cssValue) - { - if (preg_match('/([0-9]+)%/', $cssValue, $matches)) { - return ((int) $matches[1]) / 100; - } - - return $cssValue; - } - /** * Parse line break *