From ddb1c599d6804d03a5003bfffc848700efa4af7c Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 10:12:23 -0500 Subject: [PATCH 1/8] Update Tab.php Implement all Tab features. --- src/PhpWord/Writer/RTF/Style/Tab.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Tab.php b/src/PhpWord/Writer/RTF/Style/Tab.php index 95e1f10a5c..9fcc036297 100644 --- a/src/PhpWord/Writer/RTF/Style/Tab.php +++ b/src/PhpWord/Writer/RTF/Style/Tab.php @@ -38,12 +38,24 @@ public function write() \PhpOffice\PhpWord\Style\Tab::TAB_STOP_RIGHT => '\tqr', \PhpOffice\PhpWord\Style\Tab::TAB_STOP_CENTER => '\tqc', \PhpOffice\PhpWord\Style\Tab::TAB_STOP_DECIMAL => '\tqdec', + \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT => '\tldot', + \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_HYPHEN => '\tlhyph', + \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_UNDERSCORE => '\tlul', + \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_HEAVY => '\tlth', + \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_MIDDLEDOT => '\tlmdot', ]; $content = ''; if (isset($tabs[$style->getType()])) { $content .= $tabs[$style->getType()]; } - $content .= '\tx' . round($style->getPosition()); + if (isset($tabs[$style->getLeader()])) { + $content .= $tabs[$style->getLeader()]; + } + if ($style->getType() == \PhpOffice\PhpWord\Style\Tab::TAB_STOP_BAR) { + $content .= '\tb' . round($style->getPosition()); + } else { + $content .= '\tx' . round($style->getPosition()); + } return $content; } From 3eb5a8a97bd65262c38792a94a27065c6f29436b Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 21:56:40 -0500 Subject: [PATCH 2/8] Update 1.5.0.md - Changelog for Pull 2815 --- 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..f582c281eb 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: Support for type 'bar' and leaders in Tab by [@rasamassen](https://github.com/rasamassen) in [#2815](https://github.com/PHPOffice/PHPWord/pull/2815) ### Miscellaneous @@ -16,4 +17,4 @@ ### BC Breaks -### Notes \ No newline at end of file +### Notes From 8b9bc5ae3c941ccc11409e4fe43d58499575e72e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 18:59:59 -0500 Subject: [PATCH 3/8] Update Tab.php - specification says no leader on tab bar --- src/PhpWord/Writer/RTF/Style/Tab.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Tab.php b/src/PhpWord/Writer/RTF/Style/Tab.php index 9fcc036297..1dc5c5730b 100644 --- a/src/PhpWord/Writer/RTF/Style/Tab.php +++ b/src/PhpWord/Writer/RTF/Style/Tab.php @@ -18,6 +18,8 @@ namespace PhpOffice\PhpWord\Writer\RTF\Style; +use PhpOffice\PhpWord\Style\Tab as TabStyle; + /** * Line numbering style writer. * @@ -31,27 +33,27 @@ class Tab extends AbstractStyle public function write() { $style = $this->getStyle(); - if (!$style instanceof \PhpOffice\PhpWord\Style\Tab) { + if (!$style instanceof TabStyle) { return; } $tabs = [ - \PhpOffice\PhpWord\Style\Tab::TAB_STOP_RIGHT => '\tqr', - \PhpOffice\PhpWord\Style\Tab::TAB_STOP_CENTER => '\tqc', - \PhpOffice\PhpWord\Style\Tab::TAB_STOP_DECIMAL => '\tqdec', - \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT => '\tldot', - \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_HYPHEN => '\tlhyph', - \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_UNDERSCORE => '\tlul', - \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_HEAVY => '\tlth', - \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_MIDDLEDOT => '\tlmdot', + TabStyle::TAB_STOP_RIGHT => '\tqr', + TabStyle::TAB_STOP_CENTER => '\tqc', + TabStyle::TAB_STOP_DECIMAL => '\tqdec', + TabStyle::TAB_LEADER_DOT => '\tldot', + TabStyle::TAB_LEADER_HYPHEN => '\tlhyph', + TabStyle::TAB_LEADER_UNDERSCORE => '\tlul', + TabStyle::TAB_LEADER_HEAVY => '\tlth', + TabStyle::TAB_LEADER_MIDDLEDOT => '\tlmdot', ]; $content = ''; if (isset($tabs[$style->getType()])) { $content .= $tabs[$style->getType()]; } - if (isset($tabs[$style->getLeader()])) { + if (isset($tabs[$style->getLeader()]) && $style->getType() != TabStyle::TAB_STOP_BAR) { $content .= $tabs[$style->getLeader()]; } - if ($style->getType() == \PhpOffice\PhpWord\Style\Tab::TAB_STOP_BAR) { + if ($style->getType() == TabStyle::TAB_STOP_BAR) { $content .= '\tb' . round($style->getPosition()); } else { $content .= '\tx' . round($style->getPosition()); From 37df6094454b075404eb65aff1638fd077d8a345 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 19:00:03 -0500 Subject: [PATCH 4/8] Create TabTest.php --- .../PhpWordTests/Writer/RTF/Style/TabTest.php | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 tests/PhpWordTests/Writer/RTF/Style/TabTest.php diff --git a/tests/PhpWordTests/Writer/RTF/Style/TabTest.php b/tests/PhpWordTests/Writer/RTF/Style/TabTest.php new file mode 100644 index 0000000000..4a3ee4f951 --- /dev/null +++ b/tests/PhpWordTests/Writer/RTF/Style/TabTest.php @@ -0,0 +1,119 @@ +write()); + } + + /** + * Test tab stops. + * See page 83 of RTF Specification 1.9.1 for Tabs. + */ + public function testTabStop(): void + { + $parentWriter = new RTF(); + $style = new TabStyle(); + $writer = new TabWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setPosition(3000); + $style->setType($style::TAB_STOP_CLEAR); + $expect = '\tx3000'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setType(TabStyle::TAB_STOP_LEFT); + $expect = '\tx3000'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setType(TabStyle::TAB_STOP_CENTER); + $expect = '\tcq\tx3000'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setType(TabStyle::TAB_STOP_RIGHT); + $expect = '\tqr\tx3000'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setType(TabStyle::TAB_STOP_DECIMAL); + $expect = '\tqdec\tx3000'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setType(TabStyle::TAB_STOP_BAR); + $expect = '\tb3000'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setType(TabStyle::TAB_STOP_NUM); // No equivalent specified in RTF + $expect = '\tx3000'; + self::assertEquals($expect, $this->removeCr($writer)); + } + + /** + * Test tab leaders. + * See page 83 of RTF Specification 1.9.1 for Formatting. + */ + public function testTabLeader(): void + { + $parentWriter = new RTF(); + $style = new TabStyle(); + $writer = new TabWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setPosition(600); + $style->setLeader(TabStyle::TAB_LEADER_NONE); + $expect = '\tx600'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setLeader(TabStyle::TAB_LEADER_DOT); + $expect = '\tldot\tx600'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setLeader(TabStyle::TAB_LEADER_HYPHEN); + $expect = '\tlhyph\tx600'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setLeader(TabStyle::TAB_LEADER_UNDERSCORE); + $expect = '\tlul\tx600'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setLeader(TabStyle::TAB_LEADER_HEAVY); + $expect = '\tlth\tx600'; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setLeader(TabStyle::TAB_LEADER_MIDDLEDOT); + $expect = '\tlmdot\tx600'; + self::assertEquals($expect, $this->removeCr($writer)); + } +} From d2b5dd30bf2c3dcb859226998fd9a08003365691 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 19:03:00 -0500 Subject: [PATCH 5/8] Update TabTest.php --- tests/PhpWordTests/Writer/RTF/Style/TabTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/TabTest.php b/tests/PhpWordTests/Writer/RTF/Style/TabTest.php index 4a3ee4f951..c85aaf2eeb 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/TabTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/TabTest.php @@ -60,7 +60,7 @@ public function testTabStop(): void self::assertEquals($expect, $this->removeCr($writer)); $style->setType(TabStyle::TAB_STOP_CENTER); - $expect = '\tcq\tx3000'; + $expect = '\tqc\tx3000'; self::assertEquals($expect, $this->removeCr($writer)); $style->setType(TabStyle::TAB_STOP_RIGHT); From 78e51a6d6d8597da5ed10468a5fa4b9766c59e57 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 19:05:12 -0500 Subject: [PATCH 6/8] Update TabTest.php --- tests/PhpWordTests/Writer/RTF/Style/TabTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/TabTest.php b/tests/PhpWordTests/Writer/RTF/Style/TabTest.php index c85aaf2eeb..809224f679 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/TabTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/TabTest.php @@ -82,7 +82,7 @@ public function testTabStop(): void /** * Test tab leaders. - * See page 83 of RTF Specification 1.9.1 for Formatting. + * See page 83 of RTF Specification 1.9.1 for Tabs. */ public function testTabLeader(): void { From 5a79a1f14750166ea79831762a3929a0dd71c6fe Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 23:38:17 -0500 Subject: [PATCH 7/8] Update StyleTest.php --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 37 --------------------- 1 file changed, 37 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 8ba2bcb9c9..aa44d648c9 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -84,43 +84,6 @@ public function testIndentation(): void Assert::assertEquals('\fi3\li1\ri2 ', $result); } - public function testRightTab(): void - { - $tabRight = new \PhpOffice\PhpWord\Style\Tab(); - $tabRight->setType(\PhpOffice\PhpWord\Style\Tab::TAB_STOP_RIGHT); - $tabRight->setPosition(5); - - $tabWriter = new RTF\Style\Tab($tabRight); - $tabWriter->setParentWriter(new RTF()); - $result = $tabWriter->write(); - - Assert::assertEquals('\tqr\tx5', $result); - } - - public function testCenterTab(): void - { - $tabRight = new \PhpOffice\PhpWord\Style\Tab(); - $tabRight->setType(\PhpOffice\PhpWord\Style\Tab::TAB_STOP_CENTER); - - $tabWriter = new RTF\Style\Tab($tabRight); - $tabWriter->setParentWriter(new RTF()); - $result = $tabWriter->write(); - - Assert::assertEquals('\tqc\tx0', $result); - } - - public function testDecimalTab(): void - { - $tabRight = new \PhpOffice\PhpWord\Style\Tab(); - $tabRight->setType(\PhpOffice\PhpWord\Style\Tab::TAB_STOP_DECIMAL); - - $tabWriter = new RTF\Style\Tab($tabRight); - $tabWriter->setParentWriter(new RTF()); - $result = $tabWriter->write(); - - Assert::assertEquals('\tqdec\tx0', $result); - } - public function testRTL(): void { $parentWriter = new RTF(); From 695a305d831615d4683bfdff5b3cb24871f96403 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 17 Oct 2025 23:30:13 -0500 Subject: [PATCH 8/8] Update 1.5.0.md --- docs/changes/1.x/1.5.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changes/1.x/1.5.0.md b/docs/changes/1.x/1.5.0.md index f582c281eb..3067e807d4 100644 --- a/docs/changes/1.x/1.5.0.md +++ b/docs/changes/1.x/1.5.0.md @@ -7,7 +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: Support for type 'bar' and leaders in Tab by [@rasamassen](https://github.com/rasamassen) in [#2815](https://github.com/PHPOffice/PHPWord/pull/2815) +- Writer RTF: Support for type 'bar' and leaders in Tab by [@rasamassen](https://github.com/rasamassen) in [#2815](https://github.com/PHPOffice/PHPWord/pull/2815), partially fixing [#862](https://github.com/PHPOffice/PHPWord/issues/862) ### Miscellaneous