From f7bd2332ab42c5d41d7e1c57230466d60e17454c Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 20:36:14 -0500 Subject: [PATCH 1/8] Create Indentation.php --- .../Writer/RTF/Style/Indentation.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/PhpWordTests/Writer/RTF/Style/Indentation.php diff --git a/tests/PhpWordTests/Writer/RTF/Style/Indentation.php b/tests/PhpWordTests/Writer/RTF/Style/Indentation.php new file mode 100644 index 0000000000..aa21fb149c --- /dev/null +++ b/tests/PhpWordTests/Writer/RTF/Style/Indentation.php @@ -0,0 +1,73 @@ +write()); + } + + /** + * Test indentation. + * See page 79 of RTF Specification 1.9.1 for Indentation. + */ + public function testIndentation(): void + { + $parentWriter = new RTF(); + $style = new IndentationStyle(); + $writer = new IndentationWriter($style); + $writer->setParentWriter($parentWriter); + + $expect = ' '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setLeft(1440); + $style->setRight(720); + $style->setFirstLine(360); + $style->setFirstLineChars(180); + $expect = '\fi360\cufi180\li1440\ri720 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style = new IndentationStyle(); + $writer = new IndentationWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setLeft(1440); + $style->setRight(720); + $style->setHanging(360); + $expect = '\fi-360\li1440\ri720 '; + self::assertEquals($expect, $this->removeCr($writer)); + } +} From 19220ed55badd9cf4164bf147c44656d90e016c1 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 20:39:40 -0500 Subject: [PATCH 2/8] Update Indentation.php - Add missing commands, don't set commands if 0 (default) --- src/PhpWord/Writer/RTF/Style/Indentation.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Indentation.php b/src/PhpWord/Writer/RTF/Style/Indentation.php index 589125a26a..e0a5df4e06 100644 --- a/src/PhpWord/Writer/RTF/Style/Indentation.php +++ b/src/PhpWord/Writer/RTF/Style/Indentation.php @@ -37,9 +37,13 @@ public function write() return ''; } - $content = '\fi' . round($style->getFirstLine()); - $content .= '\li' . round($style->getLeft()); - $content .= '\ri' . round($style->getRight()); + $content = ''; + + $content .= getValueIf($style->getFirstLine() !== 0, '\fi' . round($style->getFirstLine())); + $content .= getValueIf($style->getFirstLineChars() !== 0, '\cufi' . round($style->getFirstLineChars())); + $content .= getValueIf($style->getHanging() !== 0, '\fi-' . round($style->getHanging())); + $content .= getValueIf($style->getLeft() !== 0, '\li' . round($style->getLeft())); + $content .= getValueIf($style->getRight() !== 0, '\ri' . round($style->getRight())); return $content . ' '; } From 78a4b3c5697d52fe7e4877b7215c904b07b2a285 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 20:44:12 -0500 Subject: [PATCH 3/8] Update Indentation.php --- src/PhpWord/Writer/RTF/Style/Indentation.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Indentation.php b/src/PhpWord/Writer/RTF/Style/Indentation.php index e0a5df4e06..a9fa6d7f85 100644 --- a/src/PhpWord/Writer/RTF/Style/Indentation.php +++ b/src/PhpWord/Writer/RTF/Style/Indentation.php @@ -38,12 +38,12 @@ public function write() } $content = ''; - - $content .= getValueIf($style->getFirstLine() !== 0, '\fi' . round($style->getFirstLine())); - $content .= getValueIf($style->getFirstLineChars() !== 0, '\cufi' . round($style->getFirstLineChars())); - $content .= getValueIf($style->getHanging() !== 0, '\fi-' . round($style->getHanging())); - $content .= getValueIf($style->getLeft() !== 0, '\li' . round($style->getLeft())); - $content .= getValueIf($style->getRight() !== 0, '\ri' . round($style->getRight())); + + $content .= $this->getValueIf($style->getFirstLine() !== 0, '\fi' . round($style->getFirstLine())); + $content .= $this->getValueIf($style->getFirstLineChars() !== 0, '\cufi' . round($style->getFirstLineChars())); + $content .= $this->getValueIf($style->getHanging() !== 0, '\fi-' . round($style->getHanging())); + $content .= $this->getValueIf($style->getLeft() !== 0, '\li' . round($style->getLeft())); + $content .= $this->getValueIf($style->getRight() !== 0, '\ri' . round($style->getRight())); return $content . ' '; } From 3a2a5fc5df793b8080207f2da99b65412ec28f53 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 20:44:14 -0500 Subject: [PATCH 4/8] Update Indentation.php --- tests/PhpWordTests/Writer/RTF/Style/Indentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/Indentation.php b/tests/PhpWordTests/Writer/RTF/Style/Indentation.php index aa21fb149c..896535c32e 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/Indentation.php +++ b/tests/PhpWordTests/Writer/RTF/Style/Indentation.php @@ -24,7 +24,7 @@ use PhpOffice\PhpWord\Writer\RTF\Style\Indentation as IndentationWriter; use PHPUnit\Framework\TestCase; -class ParagraphTest extends TestCase +class IndentationTest extends TestCase { protected function tearDown(): void { From d9ce5d904a59c0e24433eb51599b67e0b55b64f3 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 20:51:21 -0500 Subject: [PATCH 5/8] Update and rename Indentation.php to IndentationTest.php --- .../Writer/RTF/Style/{Indentation.php => IndentationTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/PhpWordTests/Writer/RTF/Style/{Indentation.php => IndentationTest.php} (98%) diff --git a/tests/PhpWordTests/Writer/RTF/Style/Indentation.php b/tests/PhpWordTests/Writer/RTF/Style/IndentationTest.php similarity index 98% rename from tests/PhpWordTests/Writer/RTF/Style/Indentation.php rename to tests/PhpWordTests/Writer/RTF/Style/IndentationTest.php index 896535c32e..f555263ddb 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/Indentation.php +++ b/tests/PhpWordTests/Writer/RTF/Style/IndentationTest.php @@ -32,7 +32,7 @@ protected function tearDown(): void } /** - * @param ParagraphWriter $field + * @param IndentationWriter $field */ public function removeCr($field): string { From 2c18c773194ea04bd40133512c2ad9a9518bd076 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 20:51:38 -0500 Subject: [PATCH 6/8] Update Indentation.php --- src/PhpWord/Writer/RTF/Style/Indentation.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Indentation.php b/src/PhpWord/Writer/RTF/Style/Indentation.php index a9fa6d7f85..60a95d599f 100644 --- a/src/PhpWord/Writer/RTF/Style/Indentation.php +++ b/src/PhpWord/Writer/RTF/Style/Indentation.php @@ -39,11 +39,11 @@ public function write() $content = ''; - $content .= $this->getValueIf($style->getFirstLine() !== 0, '\fi' . round($style->getFirstLine())); - $content .= $this->getValueIf($style->getFirstLineChars() !== 0, '\cufi' . round($style->getFirstLineChars())); - $content .= $this->getValueIf($style->getHanging() !== 0, '\fi-' . round($style->getHanging())); - $content .= $this->getValueIf($style->getLeft() !== 0, '\li' . round($style->getLeft())); - $content .= $this->getValueIf($style->getRight() !== 0, '\ri' . round($style->getRight())); + $content .= $this->getValueIf($style->getFirstLine() != 0, '\fi' . round($style->getFirstLine())); + $content .= $this->getValueIf($style->getFirstLineChars() != 0, '\cufi' . round($style->getFirstLineChars())); + $content .= $this->getValueIf($style->getHanging() != 0, '\fi-' . round($style->getHanging())); + $content .= $this->getValueIf($style->getLeft() != 0, '\li' . round($style->getLeft())); + $content .= $this->getValueIf($style->getRight() != 0, '\ri' . round($style->getRight())); return $content . ' '; } From c76ab024889f60f63545098f8804d012beef0481 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 20:56:33 -0500 Subject: [PATCH 7/8] Update 1.5.0.md --- 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..6140f64e08 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: Improve Indentation and add missing commands by [@rasamassen](https://github.com/rasamassen) in [#2836](https://github.com/PHPOffice/PHPWord/pull/2836) ### Miscellaneous @@ -16,4 +17,4 @@ ### BC Breaks -### Notes \ No newline at end of file +### Notes From 993eb581db1ed359d2e990c886ffa418316336f1 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 23:38:50 -0500 Subject: [PATCH 8/8] Update StyleTest.php --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 8ba2bcb9c9..377caed924 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -70,20 +70,6 @@ public function testBorderWithNonRegisteredColors(): void self::assertEquals($expected, $content); } - public function testIndentation(): void - { - $indentation = new \PhpOffice\PhpWord\Style\Indentation(); - $indentation->setLeft(1); - $indentation->setRight(2); - $indentation->setFirstLine(3); - - $indentWriter = new RTF\Style\Indentation($indentation); - $indentWriter->setParentWriter(new RTF()); - $result = $indentWriter->write(); - - Assert::assertEquals('\fi3\li1\ri2 ', $result); - } - public function testRightTab(): void { $tabRight = new \PhpOffice\PhpWord\Style\Tab();