|
23 | 23 | use PhpOffice\PhpWord\Settings;
|
24 | 24 | use PhpOffice\PhpWord\SimpleType\Jc;
|
25 | 25 | use PhpOffice\PhpWord\SimpleType\NumberFormat;
|
| 26 | +use PhpOffice\PhpWord\Style\Paragraph; |
26 | 27 |
|
27 | 28 | /**
|
28 | 29 | * Common Html functions
|
@@ -533,17 +534,25 @@ private static function parseStyle($attribute, $styles)
|
533 | 534 | case 'line-height':
|
534 | 535 | $matches = array();
|
535 | 536 | if (preg_match('/([0-9]+\.?[0-9]*[a-z]+)/', $cValue, $matches)) {
|
| 537 | + //matches number with a unit, e.g. 12px, 15pt, 20mm, ... |
536 | 538 | $spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT;
|
537 |
| - $spacing = Converter::cssToTwip($matches[1]) / \PhpOffice\PhpWord\Style\Paragraph::LINE_HEIGHT; |
| 539 | + $spacing = Converter::cssToTwip($matches[1]); |
538 | 540 | } elseif (preg_match('/([0-9]+)%/', $cValue, $matches)) {
|
| 541 | + //matches percentages |
539 | 542 | $spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
|
540 |
| - $spacing = ((int) $matches[1]) / 100; |
| 543 | + //we are subtracting 1 line height because the Spacing writer is adding one line |
| 544 | + $spacing = ((((int) $matches[1]) / 100) * Paragraph::LINE_HEIGHT) - Paragraph::LINE_HEIGHT; |
541 | 545 | } else {
|
| 546 | + //any other, wich is a multiplier. E.g. 1.2 |
542 | 547 | $spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
|
543 |
| - $spacing = $cValue; |
| 548 | + //we are subtracting 1 line height because the Spacing writer is adding one line |
| 549 | + $spacing = ($cValue * Paragraph::LINE_HEIGHT) - Paragraph::LINE_HEIGHT; |
544 | 550 | }
|
545 | 551 | $styles['spacingLineRule'] = $spacingLineRule;
|
546 |
| - $styles['lineHeight'] = $spacing; |
| 552 | + $styles['line-spacing'] = $spacing; |
| 553 | + break; |
| 554 | + case 'letter-spacing': |
| 555 | + $styles['letter-spacing'] = Converter::cssToTwip($cValue); |
547 | 556 | break;
|
548 | 557 | case 'text-indent':
|
549 | 558 | $styles['indentation']['firstLine'] = Converter::cssToTwip($cValue);
|
|
0 commit comments