From 2ac23692b3faad4573e28ad61dfd8930eae5e9f5 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 10:16:35 -0500 Subject: [PATCH 01/10] Fix TextBreak.php Returns line return instead of paragraph return on textrun, footnote, and endnote. --- src/PhpWord/Writer/RTF/Element/TextBreak.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Element/TextBreak.php b/src/PhpWord/Writer/RTF/Element/TextBreak.php index d74bf23dcb..c7924b0f8d 100644 --- a/src/PhpWord/Writer/RTF/Element/TextBreak.php +++ b/src/PhpWord/Writer/RTF/Element/TextBreak.php @@ -36,6 +36,10 @@ public function write() $parentWriter = $this->parentWriter; $parentWriter->setLastParagraphStyle(); - return '\pard\par' . PHP_EOL; + if ($this->withoutP) { + return '\line' . PHP_EOL; + } else { + return '\pard\par' . PHP_EOL; + } } } From 969a10a30c31d96c8f7b03b1f1d19009d1e94bc7 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 19:08:01 -0500 Subject: [PATCH 02/10] Update TextBreak.php - Fix Formatting --- src/PhpWord/Writer/RTF/Element/TextBreak.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Element/TextBreak.php b/src/PhpWord/Writer/RTF/Element/TextBreak.php index c7924b0f8d..656da1c389 100644 --- a/src/PhpWord/Writer/RTF/Element/TextBreak.php +++ b/src/PhpWord/Writer/RTF/Element/TextBreak.php @@ -38,8 +38,8 @@ public function write() if ($this->withoutP) { return '\line' . PHP_EOL; - } else { - return '\pard\par' . PHP_EOL; } + + return '\pard\par' . PHP_EOL; } } From ea46753af69e48a7d0ec7d7ffada8ef827a97bc2 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 19:11:12 -0500 Subject: [PATCH 03/10] Update TextBreak.php - Fix formatting --- src/PhpWord/Writer/RTF/Element/TextBreak.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Element/TextBreak.php b/src/PhpWord/Writer/RTF/Element/TextBreak.php index 656da1c389..c533a32f45 100644 --- a/src/PhpWord/Writer/RTF/Element/TextBreak.php +++ b/src/PhpWord/Writer/RTF/Element/TextBreak.php @@ -39,7 +39,7 @@ public function write() if ($this->withoutP) { return '\line' . PHP_EOL; } - + return '\pard\par' . PHP_EOL; } } From 6a28762467b821aee3a0a49d29979dd7674772b9 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 21:59:42 -0500 Subject: [PATCH 04/10] Update 1.5.0.md - Changelog for Pull 2816 --- docs/changes/1.x/1.5.0.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changes/1.x/1.5.0.md b/docs/changes/1.x/1.5.0.md index b96865bada..f260d5a88a 100644 --- a/docs/changes/1.x/1.5.0.md +++ b/docs/changes/1.x/1.5.0.md @@ -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: Fix paragraph return when it should be line return in TextBreak by [@rasamassen](https://github.com/rasamassen) in [#2816](https://github.com/PHPOffice/PHPWord/pull/2816) ### Miscellaneous @@ -16,4 +17,4 @@ ### BC Breaks -### Notes \ No newline at end of file +### Notes From 2b590d72b77f7975ca594cd22ff9d981a3472d4a Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 1 Oct 2025 15:29:28 -0500 Subject: [PATCH 05/10] Create TextBreakTest.php --- .../Writer/RTF/Element/TextBreakTest.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php diff --git a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php new file mode 100644 index 0000000000..f6f1a0c500 --- /dev/null +++ b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php @@ -0,0 +1,48 @@ +write()); + } + + public function testTextBreakParagraph(): void + { + $parentWriter = new RTF(); + $element = new TextBreakElement(); + $writer = new TextBreakWriter($parentWriter, $element); + $expect = "\\pard\\par\n"; + self::assertEquals($expect, $this->removeCr($writer)); + } + +} From ecb2ff9bc102b3b7a96ae5006afe01c66dcc77d5 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 1 Oct 2025 15:32:49 -0500 Subject: [PATCH 06/10] Update TextBreakTest.php --- .../PhpWordTests/Writer/RTF/Element/TextBreakTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php index f6f1a0c500..d5187d2da7 100644 --- a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php +++ b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php @@ -30,12 +30,15 @@ protected function tearDown(): void { Settings::setDefaultRtl(null); } - - public function removeCr($field) + + /** + * @param TextBreakWriter $field + */ + public function removeCr($field): string { return str_replace("\r\n", "\n", $field->write()); } - + public function testTextBreakParagraph(): void { $parentWriter = new RTF(); @@ -44,5 +47,4 @@ public function testTextBreakParagraph(): void $expect = "\\pard\\par\n"; self::assertEquals($expect, $this->removeCr($writer)); } - } From d6111f21cf32e6cbfeb7c6d92822c4c6aeb620e4 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 1 Oct 2025 15:40:07 -0500 Subject: [PATCH 07/10] Update TextBreakTest.php --- .../Writer/RTF/Element/TextBreakTest.php | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php index d5187d2da7..d99be6fd4c 100644 --- a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php +++ b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php @@ -33,12 +33,15 @@ protected function tearDown(): void /** * @param TextBreakWriter $field - */ + */ public function removeCr($field): string { return str_replace("\r\n", "\n", $field->write()); } + /** + * Test a normal textBreak + */ public function testTextBreakParagraph(): void { $parentWriter = new RTF(); @@ -47,4 +50,28 @@ public function testTextBreakParagraph(): void $expect = "\\pard\\par\n"; self::assertEquals($expect, $this->removeCr($writer)); } + + /** + * Test a textBreak with two paragraph breaks + */ + public function testTextBreakTwoParagraphs(): void + { + $parentWriter = new RTF(); + $element = new TextBreakElement(2); + $writer = new TextBreakWriter($parentWriter, $element); + $expect = "\\pard\\par\n\\pard\\par\n"; + self::assertEquals($expect, $this->removeCr($writer)); + } + + /** + * Test a textBreak as a line break + */ + public function testTextBreakLine(): void + { + $parentWriter = new RTF(); + $element = new TextBreakElement(); + $writer = new TextBreakWriter($parentWriter, $element, true); + $expect = "\\line\n"; + self::assertEquals($expect, $this->removeCr($writer)); + } } From aa6f62105cfde2f334e14a7b974af34dcfab1371 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 1 Oct 2025 15:41:20 -0500 Subject: [PATCH 08/10] Update TextBreakTest.php --- tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php index d99be6fd4c..919a89b05e 100644 --- a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php +++ b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php @@ -40,7 +40,7 @@ public function removeCr($field): string } /** - * Test a normal textBreak + * Test a normal textBreak. */ public function testTextBreakParagraph(): void { @@ -52,7 +52,7 @@ public function testTextBreakParagraph(): void } /** - * Test a textBreak with two paragraph breaks + * Test a textBreak with two paragraph breaks. */ public function testTextBreakTwoParagraphs(): void { @@ -64,7 +64,7 @@ public function testTextBreakTwoParagraphs(): void } /** - * Test a textBreak as a line break + * Test a textBreak as a line break. */ public function testTextBreakLine(): void { From 711945e955909ebd9e31713453c17d90e2b8cfe6 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 1 Oct 2025 15:44:53 -0500 Subject: [PATCH 09/10] Update TextBreakTest.php --- .../Writer/RTF/Element/TextBreakTest.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php index 919a89b05e..a83eb3ea74 100644 --- a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php +++ b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php @@ -51,18 +51,6 @@ public function testTextBreakParagraph(): void self::assertEquals($expect, $this->removeCr($writer)); } - /** - * Test a textBreak with two paragraph breaks. - */ - public function testTextBreakTwoParagraphs(): void - { - $parentWriter = new RTF(); - $element = new TextBreakElement(2); - $writer = new TextBreakWriter($parentWriter, $element); - $expect = "\\pard\\par\n\\pard\\par\n"; - self::assertEquals($expect, $this->removeCr($writer)); - } - /** * Test a textBreak as a line break. */ From 34217ed5f80dea4ce0338bad74b69cb918534f3e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 18:13:14 -0500 Subject: [PATCH 10/10] Update TextBreakTest.php - added reference to specs for verification --- tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php index a83eb3ea74..0873a6de84 100644 --- a/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php +++ b/tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php @@ -41,6 +41,7 @@ public function removeCr($field): string /** * Test a normal textBreak. + * See page 142-143 of RTF Specification 1.9.1. */ public function testTextBreakParagraph(): void { @@ -53,6 +54,7 @@ public function testTextBreakParagraph(): void /** * Test a textBreak as a line break. + * See page 142-143 of RTF Specification 1.9.1. */ public function testTextBreakLine(): void {