Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/changes/1.x/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Bug fixes

- Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776)
- Writer RTF: Add/Fix pagination in Paragraph by [@rasamassen](https://github.com/rasamassen) in [#2824](https://github.com/PHPOffice/PHPWord/pull/2824)

### Miscellaneous

Expand All @@ -16,4 +17,4 @@

### BC Breaks

### Notes
### Notes
14 changes: 9 additions & 5 deletions src/PhpWord/Writer/RTF/Style/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function write()

$content = '';
if ($this->nestedLevel == 0) {
$content .= '\pard\nowidctlpar ';
$content .= '\pard';
}
$alignment = $style->getAlignment();
$bidi = $style->isBidi();
Expand All @@ -94,14 +94,18 @@ public function write()
$lineHeightAdjusted = (int) ($lineHeight * 240);
$content .= "\\sl$lineHeightAdjusted\\slmult1";
}
if ($style->hasPageBreakBefore()) {
$content .= '\\page';
}

// Pagination
$content .= $this->getValueIf($style->hasWidowControl(), '\widctlpar');
$content .= $this->getValueIf(!$style->hasWidowControl(), '\nowidctlpar');
$content .= $this->getValueIf($style->isKeepNext(), '\keepn');
$content .= $this->getValueIf($style->isKeepLines(), '\keep');
$content .= $this->getValueIf($style->hasPageBreakBefore(), '\pagebb');

$styles = $style->getStyleValues();
$content .= $this->writeTabs($styles['tabs']);

return $content;
return $content . ' ';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpWordTests/Escaper/RtfEscaper2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class RtfEscaper2Test extends \PHPUnit\Framework\TestCase
{
const HEADER = '\\pard\\nowidctlpar {\\cf0\\f0 ';
const HEADER = '\\pard\\widctlpar {\\cf0\\f0 ';
const TRAILER = '}\\par';

public function escapestring($str)
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpWordTests/Escaper/RtfEscaper3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
class RtfEscaper3Test extends \PHPUnit\Framework\TestCase
{
const HEADER = '\\pard\\nowidctlpar \ql{\\cf0\\f0 ';
const HEADER_RTL = '\\pard\\nowidctlpar \qr{\\rtlch\\cf0\\f0 ';
const HEADER = '\\pard\\ql\\widctlpar {\\cf0\\f0 ';
const HEADER_RTL = '\\pard\\qr\\widctlpar {\\rtlch\\cf0\\f0 ';
const TRAILER = '}\\par';

protected function tearDown(): void
Expand Down
10 changes: 5 additions & 5 deletions tests/PhpWordTests/Writer/RTF/Element/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public function testTable(): void
'\\pard',
"\\trowd \\cellx$width \\cellx$width2 ",
'\\intbl',
'\\ql{\\cf0\\f0 1}\\par',
'\\ql\\widctlpar {\\cf0\\f0 1}\\par',
'\\cell',
'\\intbl',
'{\\cf0\\f0 2}\\par',
'\\cell',
'\\row',
"\\trowd \\cellx$width \\cellx$width2 ",
'\\intbl',
'\\ql{\\cf0\\f0 3}\\par',
'\\ql\\widctlpar {\\cf0\\f0 3}\\par',
'\\cell',
'\\intbl',
'{\\cf0\\f0 4}\par',
Expand Down Expand Up @@ -102,7 +102,7 @@ public function testTableStyle(): void
'\\clbrdrr\\brdrs\\brdrw2\\brdrcf0',
"\\cellx$width ",
'\\intbl',
'\\ql{\\cf0\\f0 1}\\par',
'\\ql\\widctlpar {\\cf0\\f0 1}\\par',
'\\cell',
'\\row',
'\\pard',
Expand All @@ -128,7 +128,7 @@ public function testTableStyleNotExisting(): void
'\\pard',
"\\trowd \\cellx$width ",
'\\intbl',
'\\ql{\\cf0\\f0 1}\\par',
'\\ql\\widctlpar {\\cf0\\f0 1}\\par',
'\\cell',
'\\row',
'\\pard',
Expand Down Expand Up @@ -158,7 +158,7 @@ public function testTableCellStyle(): void
'\\clbrdrr\\brdrdot\\brdrw2\\brdrcf0',
"\\cellx$width ",
'\\intbl',
'\\ql{\\cf0\\f0 1}\\par',
'\\ql\\widctlpar {\\cf0\\f0 1}\\par',
'\\cell',
'\\row',
'\\pard',
Expand Down
6 changes: 3 additions & 3 deletions tests/PhpWordTests/Writer/RTF/Element2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testTextRun(): void
$element->addText('Hello ');
$element->addText('there.');
$textrun = new WriterTextRun($parentWriter, $element);
$expect = "\\pard\\nowidctlpar \\ql{{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n";
$expect = "\\pard\\ql\\widctlpar {{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n";
self::assertEquals($expect, $this->removeCr($textrun));
}

Expand All @@ -59,7 +59,7 @@ public function testTextRunParagraphStyle(): void
$element->addText('Hello ');
$element->addText('there.');
$textrun = new WriterTextRun($parentWriter, $element);
$expect = "\\pard\\nowidctlpar \\ql\\sb0\\sa0{{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n";
$expect = "\\pard\\ql\\sb0\\sa0\\widctlpar {{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n";
self::assertEquals($expect, $this->removeCr($textrun));
}

Expand All @@ -72,7 +72,7 @@ public function testTitle(): void
$section = $phpWord->addSection();
$element = $section->addTitle('First Heading', 1);
$elwrite = new WriterTitle($parentWriter, $element);
$expect = "\\pard\\nowidctlpar \\ql\\sb0\\sa0{\\outlinelevel0{\\cf0\\f0 First Heading}\\par\n}";
$expect = "\\pard\\ql\\sb0\\sa0\\widctlpar {\\outlinelevel0{\\cf0\\f0 First Heading}\\par\n}";
self::assertEquals($expect, $this->removeCr($elwrite));
Settings::setDefaultRtl(null);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/PhpWordTests/Writer/RTF/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ public function testTable(): void
'\\pard',
"\\trowd \\cellx$width \\cellx$width2 ",
'\\intbl',
'{\\cf0\\f0 1}\\par',
'\\widctlpar {\\cf0\\f0 1}\\par',
'\\cell',
'\\intbl',
'{\\cf0\\f0 2}\\par',
'\\cell',
'\\row',
"\\trowd \\cellx$width \\cellx$width2 ",
'\\intbl',
'{\\cf0\\f0 3}\\par',
'\\widctlpar {\\cf0\\f0 3}\\par',
'\\cell',
'\\intbl',
'{\\cf0\\f0 4}\par',
Expand All @@ -149,7 +149,7 @@ public function testTextRun(): void
$element->addText('Hello ');
$element->addText('there.');
$textrun = new RTF\Element\TextRun($parentWriter, $element);
$expect = "\\pard\\nowidctlpar {{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n";
$expect = "\\pard\\widctlpar {{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n";
self::assertEquals($expect, $this->removeCr($textrun));
}

Expand All @@ -160,7 +160,7 @@ public function testTextRunParagraphStyle(): void
$element->addText('Hello ');
$element->addText('there.');
$textrun = new RTF\Element\TextRun($parentWriter, $element);
$expect = "\\pard\\nowidctlpar \\sb0\\sa0{{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n";
$expect = "\\pard\\sb0\\sa0\\widctlpar {{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n";
self::assertEquals($expect, $this->removeCr($textrun));
}

Expand All @@ -172,7 +172,7 @@ public function testTitle(): void
$section = $phpWord->addSection();
$element = $section->addTitle('First Heading', 1);
$elwrite = new RTF\Element\Title($parentWriter, $element);
$expect = "\\pard\\nowidctlpar \\sb0\\sa0{\\outlinelevel0{\\cf0\\f0 First Heading}\\par\n}";
$expect = "\\pard\\sb0\\sa0\\widctlpar {\\outlinelevel0{\\cf0\\f0 First Heading}\\par\n}";
self::assertEquals($expect, $this->removeCr($elwrite));
}

Expand All @@ -188,7 +188,7 @@ public function testRuby(): void
$element->addRuby($baseTextRun, $rubyTextRun, $properties);

$textrun = new RTF\Element\TextRun($parentWriter, $element);
$expect = "\\pard\\nowidctlpar {{base text (ruby)}}\\par\n";
$expect = "\\pard\\widctlpar {{base text (ruby)}}\\par\n";
self::assertEquals($expect, $this->removeCr($textrun));
}

Expand All @@ -213,7 +213,7 @@ public function testRubyTitle(): void
$element = $section->addTitle($textRun, 1);
$elwrite = new RTF\Element\Title($parentWriter, $element);

$expect = "\\pard\\nowidctlpar \\sb0\\sa2{\\outlinelevel0{\\cf0\\f0\\fs48\\b base text (ruby)}\\par\n}";
$expect = "\\pard\\sb0\\sa2\\widctlpar {\\outlinelevel0{\\cf0\\f0\\fs48\\b base text (ruby)}\\par\n}";
self::assertEquals($expect, $this->removeCr($elwrite));
}
}
8 changes: 4 additions & 4 deletions tests/PhpWordTests/Writer/RTF/StyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function testRTL(): void
$parentWriter = new RTF();
$element = new \PhpOffice\PhpWord\Element\Text('אב גד', ['RTL' => true]);
$text = new RTF\Element\Text($parentWriter, $element);
$expect = "\\pard\\nowidctlpar {\\rtlch\\cf0\\f0 \\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n";
$expect = "\\pard\\widctlpar {\\rtlch\\cf0\\f0 \\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n";
self::assertEquals($expect, $this->removeCr($text));
}

Expand All @@ -136,7 +136,7 @@ public function testRTL2(): void
$parentWriter = new RTF();
$element = new \PhpOffice\PhpWord\Element\Text('אב גד');
$text = new RTF\Element\Text($parentWriter, $element);
$expect = "\\pard\\nowidctlpar \\qr{\\rtlch\\cf0\\f0 \\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n";
$expect = "\\pard\\qr\\widctlpar {\\rtlch\\cf0\\f0 \\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n";
self::assertEquals($expect, $this->removeCr($text));
}

Expand All @@ -145,7 +145,7 @@ public function testPageBreakLineHeight(): void
$parentWriter = new RTF();
$element = new \PhpOffice\PhpWord\Element\Text('New page', null, ['lineHeight' => 1.08, 'pageBreakBefore' => true]);
$text = new RTF\Element\Text($parentWriter, $element);
$expect = "\\pard\\nowidctlpar \\sl259\\slmult1\\page{\\cf0\\f0 New page}\\par\n";
$expect = "\\pard\\sl259\\slmult1\\widctlpar\\pagebb {\\cf0\\f0 New page}\\par\n";
self::assertEquals($expect, $this->removeCr($text));
}

Expand All @@ -155,7 +155,7 @@ public function testPageBreakLineHeight2(): void
$parentWriter = new RTF();
$element = new \PhpOffice\PhpWord\Element\Text('New page', null, ['lineHeight' => 1.08, 'pageBreakBefore' => true]);
$text = new RTF\Element\Text($parentWriter, $element);
$expect = "\\pard\\nowidctlpar \\ql\\sl259\\slmult1\\page{\\cf0\\f0 New page}\\par\n";
$expect = "\\pard\\ql\\sl259\\slmult1\\widctlpar\\pagebb {\\cf0\\f0 New page}\\par\n";
self::assertEquals($expect, $this->removeCr($text));
}

Expand Down