Skip to content

Commit de01e86

Browse files
committed
parse fixed line space
1 parent 97d60dd commit de01e86

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,18 @@ private static function parseStyle($attribute, $styles)
521521
$styles['bgColor'] = trim($cValue, '#');
522522
break;
523523
case 'line-height':
524-
$styles['lineHeight'] = Html::toMultiplier($cValue);
524+
if (preg_match('/([0-9]+[a-z]+)/', $cValue, $matches)) {
525+
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT;
526+
$spacing = Converter::cssToTwip($matches[1]) / \PhpOffice\PhpWord\Style\Paragraph::LINE_HEIGHT;
527+
} elseif (preg_match('/([0-9]+)%/', $cValue, $matches)) {
528+
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
529+
$spacing = ((int) $matches[1]) / 100;
530+
} else {
531+
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
532+
$spacing = $cValue;
533+
}
534+
$styles['spacingLineRule'] = $spacingLineRule;
535+
$styles['lineHeight'] = $spacing;
525536
break;
526537
case 'text-indent':
527538
$styles['indentation']['firstLine'] = Converter::cssToTwip($cValue);
@@ -681,15 +692,6 @@ private static function mapAlign($cssAlignment)
681692
return null;
682693
}
683694

684-
private static function toMultiplier($cssValue)
685-
{
686-
if (preg_match('/([0-9]+)%/', $cssValue, $matches)) {
687-
return ((int) $matches[1]) / 100;
688-
}
689-
690-
return $cssValue;
691-
}
692-
693695
/**
694696
* Parse line break
695697
*

0 commit comments

Comments
 (0)