Skip to content

Commit 97d60dd

Browse files
committed
tranlate percentage to rate
1 parent fe3f383 commit 97d60dd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

samples/Sample_26_Html.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
$html .= '<p style="margin-top: 240pt;">Unordered (bulleted) list:</p>';
1919
$html .= '<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>';
2020

21+
$html .= '<p style="margin-top: 240pt;">1.5 line height with first line text indent:</p>';
22+
$html .= '<p style="text-align: justify; text-indent: 70.9pt; line-height: 150%;">Lorem ipsum dolor sit amet, <strong>consectetur adipiscing elit</strong>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>';
23+
2124
$html .= '<h2 style="align: center">centered title</h2>';
2225

2326
$html .= '<p style="margin-top: 240pt;">Ordered (numbered) list:</p>';

src/PhpWord/Shared/Html.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ private static function parseStyle($attribute, $styles)
521521
$styles['bgColor'] = trim($cValue, '#');
522522
break;
523523
case 'line-height':
524-
$styles['lineHeight'] = $cValue;
524+
$styles['lineHeight'] = Html::toMultiplier($cValue);
525525
break;
526526
case 'text-indent':
527527
$styles['indentation']['firstLine'] = Converter::cssToTwip($cValue);
@@ -681,6 +681,15 @@ private static function mapAlign($cssAlignment)
681681
return null;
682682
}
683683

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+
684693
/**
685694
* Parse line break
686695
*

0 commit comments

Comments
 (0)