From d9d5f9a3900bf88306a62612bb07270c4fc92ad5 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 20:57:51 -0500 Subject: [PATCH 01/51] Update Border.php - Add BorderSpace for Sections and Paragraphs --- src/PhpWord/Style/Border.php | 158 ++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index 722e09931a..57bd5772ad 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -46,6 +46,13 @@ class Border extends AbstractStyle */ protected $borderTopStyle; + /** + * Border Top Space. For section and paragraph borders only. + * + * @var string + */ + protected $borderTopSpace; + /** * Border Left Size. * @@ -67,6 +74,13 @@ class Border extends AbstractStyle */ protected $borderLeftStyle; + /** + * Border Left Space. For section and paragraph borders only. + * + * @var string + */ + protected $borderLeftSpace; + /** * Border Right Size. * @@ -88,6 +102,13 @@ class Border extends AbstractStyle */ protected $borderRightStyle; + /** + * Border Right Space. For section and paragraph borders only. + * + * @var string + */ + protected $borderRightSpace; + /** * Border Bottom Size. * @@ -109,6 +130,13 @@ class Border extends AbstractStyle */ protected $borderBottomStyle; + /** + * Border Bottom Space. For section and paragraph borders only. + * + * @var string + */ + protected $borderBottomSpace; + /** * Top margin spacing. * @@ -233,6 +261,38 @@ public function setBorderStyle($value = null) return $this; } + /** + * Get border space. + * + * @return string[] + */ + public function getBorderSpace() + { + return [ + $this->getBorderTopSpace(), + $this->getBorderLeftSpace(), + $this->getBorderRightSpace(), + $this->getBorderBottomSpace(), + ]; + } + + /** + * Set border space. + * + * @param string $value + * + * @return self + */ + public function setBorderSpace($value = null) + { + $this->setBorderTopSpace($value); + $this->setBorderLeftSpace($value); + $this->setBorderRightSpace($value); + $this->setBorderBottomSpace($value); + + return $this; + } + /** * Get border top size. * @@ -292,7 +352,7 @@ public function getBorderTopStyle() } /** - * Set border top Style. + * Set border top style. * * @param string $value * @@ -305,6 +365,30 @@ public function setBorderTopStyle($value = null) return $this; } + /** + * Get border top space. + * + * @return string + */ + public function getBorderTopSpace() + { + return $this->borderTopSpace; + } + + /** + * Set border top space. + * + * @param string $value + * + * @return self + */ + public function setBorderTopSpace($value = null) + { + $this->borderTopSpace = $value; + + return $this; + } + /** * Get border left size. * @@ -377,6 +461,30 @@ public function setBorderLeftStyle($value = null) return $this; } + /** + * Get border left space. + * + * @return string + */ + public function getBorderLeftSpace() + { + return $this->borderLeftSpace; + } + + /** + * Set border left space. + * + * @param string $value + * + * @return self + */ + public function setBorderLeftSpace($value = null) + { + $this->borderLeftSpace = $value; + + return $this; + } + /** * Get border right size. * @@ -449,6 +557,30 @@ public function setBorderRightStyle($value = null) return $this; } + /** + * Get border right space. + * + * @return string + */ + public function getBorderRightSpace() + { + return $this->borderRightSpace; + } + + /** + * Set border right space. + * + * @param string $value + * + * @return self + */ + public function setBorderRightSpace($value = null) + { + $this->borderRightSpace = $value; + + return $this; + } + /** * Get border bottom size. * @@ -521,6 +653,30 @@ public function setBorderBottomStyle($value = null) return $this; } + /** + * Get border bottom space. + * + * @return string + */ + public function getBorderBottomSpace() + { + return $this->borderBottomSpace; + } + + /** + * Set border bottom space. + * + * @param string $value + * + * @return self + */ + public function setBorderBottomSpace($value = null) + { + $this->borderBottomSpace = $value; + + return $this; + } + /** * Check if any of the border is not null. * From 8ecc6d69bf3d9c3716f6350d2360bdcffcb9be1c Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 20:58:14 -0500 Subject: [PATCH 02/51] Update Border.php - Fix Missing Underline --- src/PhpWord/SimpleType/Border.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/SimpleType/Border.php b/src/PhpWord/SimpleType/Border.php index acd1c1a1b1..03925e87d6 100644 --- a/src/PhpWord/SimpleType/Border.php +++ b/src/PhpWord/SimpleType/Border.php @@ -48,7 +48,7 @@ final class Border extends AbstractEnum const THIN_THICK_LARGE_GAP = 'thinThickLargeGap'; //A thin line contained within a thick line with a large-sized intermediate gap const THIN_THICK_MEDIUM_GAP = 'thinThickMediumGap'; //A thick line contained within a thin line with a medium-sized intermediate gap const THIN_THICK_SMALL_GAP = 'thinThickSmallGap'; //A thick line contained within a thin line with a small intermediate gap - const THIN_THICK_THINLARGE_GAP = 'thinThickThinLargeGap'; //A thin-thick-thin line with a large gap + const THIN_THICK_THIN_LARGE_GAP = 'thinThickThinLargeGap'; //A thin-thick-thin line with a large gap const THIN_THICK_THIN_MEDIUM_GAP = 'thinThickThinMediumGap'; //A thin-thick-thin line with a medium gap const THIN_THICK_THIN_SMALL_GAP = 'thinThickThinSmallGap'; //A thin-thick-thin line with a small gap const THREE_D_EMBOSS = 'threeDEmboss'; //A three-staged gradient line, getting darker towards the paragraph From 73baf4af58a9360ed1293e09deb837975cea76ca Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 21:08:31 -0500 Subject: [PATCH 03/51] Update Border.php - Greatly Improved Works with all border types now through setting the $type variable - section (page), paragraph, table, and cell. Prepared for future usage with header, footer, character, and row. Implements border style. Implements border space (for sections and paragraphs). --- src/PhpWord/Writer/RTF/Style/Border.php | 149 +++++++++++++++++++++--- 1 file changed, 135 insertions(+), 14 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index c8dc943579..b27d6beedb 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -18,6 +18,8 @@ namespace PhpOffice\PhpWord\Writer\RTF\Style; +use PhpOffice\PhpWord\SimpleType\Border as BorderType; + /** * Border style writer. * @@ -39,6 +41,29 @@ class Border extends AbstractStyle */ private $colors = []; + /** + * Styles. + * + * @var array + */ + private $styles = []; + + /** + * Spaces. + * + * @var array + */ + private $spaces = []; + + /** + * Type + * + * Can be page, header, footer, paragraph, character, row, or cell. + * + * @var string + */ + private $type; + /** * Write style. * @@ -46,22 +71,23 @@ class Border extends AbstractStyle */ public function write() { + $style = $this->getStyle(); + if (!$style instanceof \PhpOffice\PhpWord\Style\Border) { + return ''; + } + $content = ''; $sides = ['top', 'left', 'right', 'bottom']; $sizeCount = count($this->sizes); - // Page border measure - // 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off - $content .= '\pgbrdropt32'; - for ($i = 0; $i < $sizeCount; ++$i) { if ($this->sizes[$i] !== null) { $color = null; if (isset($this->colors[$i])) { $color = $this->colors[$i]; } - $content .= $this->writeSide($sides[$i], $this->sizes[$i], $color); + $content .= $this->writeSide($sides[$i], $this->sizes[$i], $color, $this->styles[$i], $this->spaces[$i]); } } @@ -74,29 +100,94 @@ public function write() * @param string $side * @param int $width * @param string $color + * @param string $style * * @return string */ - private function writeSide($side, $width, $color = '') + private function writeSide($side, $width, $color = '', $style, $space) { - /** @var \PhpOffice\PhpWord\Writer\RTF $rtfWriter */ - $rtfWriter = $this->getParentWriter(); + $types = [ + 'page' => '\pgbrdr', + 'header' => '\pgbrdrhead', + 'footer' => '\pgbrdrfoot', + 'paragraph' => '\brdr', + 'character' => '\chbrdr', + 'row' => '\trbrdr', + 'cell' => '\clbrdr', + ]; + + $styles = [ + BorderType::SINGLE => '\brdrs', + BorderType::DASH_DOT_STROKED => '\brdrdashd', // no equivalent in RTF + BorderType::DASHED => '\brdrdash', + BorderType::DASH_SMALL_GAP => '\brdrdashsm', + BorderType::DOT_DASH => '\brdrdashd', + BorderType::DOT_DOT_DASH => '\brdrdashdd', + BorderType::DOTTED => '\brdrdot', + BorderType::DOUBLE => '\brdrdb', + BorderType::DOUBLE_WAVE => '\brdrwavydb', + BorderType::INSET => '\brdrinset', + BorderType::NIL => '\brdrnil', + BorderType::NONE => '\brdrnone', + BorderType::OUTSET => '\brdroutset', + BorderType::THICK => '\brdrth', + BorderType::THICK_THIN_LARGE_GAP => '\brdrtnthlg', + BorderType::THICK_THIN_MEDIUM_GAP => '\brdrtnthmg', + BorderType::THICK_THIN_SMALL_GAP => '\brdrtnthsg', + BorderType::THIN_THICK_LARGE_GAP => '\brdrthtnlg', + BorderType::THIN_THICK_MEDIUM_GAP => '\brdrthtnmg', + BorderType::THIN_THICK_SMALL_GAP => '\brdrthtnsg', + BorderType::THIN_THICK_THIN_LARGE_GAP => '\brdrtnthtnlg', + BorderType::THIN_THICK_THIN_MEDIUM_GAP => '\brdrtnthtnmg', + BorderType::THIN_THICK_THIN_SMALL_GAP => '\brdrtnthtnmg', + BorderType::THREE_D_EMBOSS => '\brdremboss', + BorderType::THREE_D_ENGRAVE => '\brdrengrave', + BorderType::TRIPLE => '\brdrtriple', + BorderType::WAVE => '\brdrwavy', + ]; + + /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter */ + $parentWriter = $this->getParentWriter(); $colorIndex = 0; - if ($rtfWriter !== null) { - $colorTable = $rtfWriter->getColorTable(); - $index = array_search($color, $colorTable); + if ($parentWriter !== null) { + $index = array_search($color, $parentWriter->getColorTable()); if ($index !== false) { $colorIndex = $index + 1; } } $content = ''; + $type = 'paragraph'; + if (isset($types[$this->type])) { + if (in_array($types[$this->type], ['header', 'footer', 'character'])) { + $content .= $types[$this->type]; // header, footer, and character borders cannot vary by side + } else { + $content .= $types[$this->type] . substr($side, 0, 1); + } + } else { + return ''; + } - $content .= '\pgbrdr' . substr($side, 0, 1); - $content .= '\brdrs'; // Single-thickness border; @todo Get other type of border + if (isset($styles[$style])) { + $content .= $styles[$style]; + } else { + $content .= '\brdrs'; // default style + } $content .= '\brdrw' . round($width); // Width $content .= '\brdrcf' . $colorIndex; // Color - $content .= '\brsp480'; // Space in twips between borders and the paragraph (24pt, following OOXML) + + // Space + if ($this->type == 'page') { + $space = $space !== null ? $space : '480'; + } elseif ($this->type == 'paragraph') { + if ($side == 'top' || $side == 'bottom') { + $space = $space !== null ? $space : '20'; + } elseif ($side == 'left' || $side == 'right') { + $space = $space !== null ? $space : '80'; + } + } + $content .= $this->getValueIf($space !== null, '\brsp' . round($space ?? 0)); + $content .= ' '; return $content; @@ -121,4 +212,34 @@ public function setColors($value): void { $this->colors = $value; } + + /** + * Set styles. + * + * @param string[] $value + */ + public function setStyles($value): void + { + $this->styles = $value; + } + + /** + * Set styles. + * + * @param string[] $value + */ + public function setSpaces($value): void + { + $this->spaces = $value; + } + + /** + * Set type. + * + * @param string $value + */ + public function setType($value = 'paragraph'): void + { + $this->type = $value; + } } From 93ae63b24a9a965cbb69cb689a9c0450c1704b00 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 21:09:12 -0500 Subject: [PATCH 04/51] Update Paragraph.php - Adds Border support --- src/PhpWord/Writer/RTF/Style/Paragraph.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/PhpWord/Writer/RTF/Style/Paragraph.php b/src/PhpWord/Writer/RTF/Style/Paragraph.php index 040c60b5aa..8cec362d0f 100644 --- a/src/PhpWord/Writer/RTF/Style/Paragraph.php +++ b/src/PhpWord/Writer/RTF/Style/Paragraph.php @@ -101,6 +101,18 @@ public function write() $styles = $style->getStyleValues(); $content .= $this->writeTabs($styles['tabs']); + // Borders + if ($style->hasBorder()) { + $styleWriter = new Border($style); + $styleWriter->setParentWriter($this->getParentWriter()); + $styleWriter->setType('paragraph'); + $styleWriter->setSizes($style->getBorderSize()); + $styleWriter->setColors($style->getBorderColor()); + $styleWriter->setStyles($style->getBorderStyle()); + $styleWriter->setSpaces($style->getBorderSpace()); + $content .= $styleWriter->write(); + } + return $content; } From 9b4f037f2fa288c45c2b7834773eee69133c9ed9 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 21:09:40 -0500 Subject: [PATCH 05/51] Update Section.php - Improves Border Support --- src/PhpWord/Writer/RTF/Style/Section.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/PhpWord/Writer/RTF/Style/Section.php b/src/PhpWord/Writer/RTF/Style/Section.php index 598015ed4d..f45c358f67 100644 --- a/src/PhpWord/Writer/RTF/Style/Section.php +++ b/src/PhpWord/Writer/RTF/Style/Section.php @@ -59,10 +59,16 @@ public function write() // Borders if ($style->hasBorder()) { + // Page border measure + // 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off + $content .= '\pgbrdropt32'; $styleWriter = new Border($style); $styleWriter->setParentWriter($this->getParentWriter()); + $styleWriter->setType('page'); $styleWriter->setSizes($style->getBorderSize()); $styleWriter->setColors($style->getBorderColor()); + $styleWriter->setStyles($style->getBorderStyle()); + $styleWriter->setSpaces($style->getBorderSpace()); $content .= $styleWriter->write(); } From d5e32cdf4466f38bd83b77c96de3f24a0c87e2a4 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 21:22:20 -0500 Subject: [PATCH 06/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index b27d6beedb..5ceb74f339 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -56,8 +56,8 @@ class Border extends AbstractStyle private $spaces = []; /** - * Type - * + * Type. + * * Can be page, header, footer, paragraph, character, row, or cell. * * @var string @@ -101,10 +101,11 @@ public function write() * @param int $width * @param string $color * @param string $style + * @param int $space * * @return string */ - private function writeSide($side, $width, $color = '', $style, $space) + private function writeSide($side, $width, $color, $style, $space) { $types = [ 'page' => '\pgbrdr', @@ -159,7 +160,7 @@ private function writeSide($side, $width, $color = '', $style, $space) $content = ''; $type = 'paragraph'; if (isset($types[$this->type])) { - if (in_array($types[$this->type], ['header', 'footer', 'character'])) { + if (in_array($types[$this->type], ['header', 'footer', 'character'])) { $content .= $types[$this->type]; // header, footer, and character borders cannot vary by side } else { $content .= $types[$this->type] . substr($side, 0, 1); From 98767428832d4c78ffc9f27f0bf30a8a0dde4a17 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 21:31:05 -0500 Subject: [PATCH 07/51] Update StyleTest.php --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 8ba2bcb9c9..7e37d9264d 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -20,7 +20,6 @@ use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Writer\RTF; -use PhpOffice\PhpWord\Writer\RTF\Style\Border; use PHPUnit\Framework\Assert; /** @@ -54,12 +53,15 @@ public function testEmptyStyles(): void public function testBorderWithNonRegisteredColors(): void { - $border = new Border(); - $border->setSizes([1, 2, 3, 4]); - $border->setColors(['#FF0000', '#FF0000', '#FF0000', '#FF0000']); - $border->setSizes([20, 20, 20, 20]); - - $content = $border->write(); + $border = new \PhpOffice\PhpWord\Style\Border(); + $borderWriter = new RTF\Style\Border($border); + $borderWriter->setParentWriter(new RTF()); + $borderWriter->setType('page'); + $borderWriter->setSizes([1, 2, 3, 4]); + $borderWriter->setColors(['#FF0000', '#FF0000', '#FF0000', '#FF0000']); + $borderWriter->setSizes([20, 20, 20, 20]); + + $content = $borderWriter->write(); $expected = '\pgbrdropt32'; $expected .= '\pgbrdrt\brdrs\brdrw20\brdrcf0\brsp480 '; From 519bf69ec89deeff48acb8080c77a3a085f6abea Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 21:47:38 -0500 Subject: [PATCH 08/51] Update StyleTest.php --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 7e37d9264d..71dfd6d81f 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -60,6 +60,8 @@ public function testBorderWithNonRegisteredColors(): void $borderWriter->setSizes([1, 2, 3, 4]); $borderWriter->setColors(['#FF0000', '#FF0000', '#FF0000', '#FF0000']); $borderWriter->setSizes([20, 20, 20, 20]); + $borderWriter->setStyles($border->getBorderStyle()); + $borderWriter->setSpaces($border->getBorderSpace()); $content = $borderWriter->write(); From 2abcc85c178bd60efcf11e87381de22d5d54d8c2 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 21:50:17 -0500 Subject: [PATCH 09/51] Update StyleTest.php --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 71dfd6d81f..5083014c81 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -65,8 +65,7 @@ public function testBorderWithNonRegisteredColors(): void $content = $borderWriter->write(); - $expected = '\pgbrdropt32'; - $expected .= '\pgbrdrt\brdrs\brdrw20\brdrcf0\brsp480 '; + $expected = '\pgbrdrt\brdrs\brdrw20\brdrcf0\brsp480 '; $expected .= '\pgbrdrl\brdrs\brdrw20\brdrcf0\brsp480 '; $expected .= '\pgbrdrr\brdrs\brdrw20\brdrcf0\brsp480 '; $expected .= '\pgbrdrb\brdrs\brdrw20\brdrcf0\brsp480 '; From a3dcb86c66b3b61db8207d28aea422c1314a7915 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sun, 5 Oct 2025 21:52:27 -0500 Subject: [PATCH 10/51] 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..5b77ac31f4 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 Borders, add missing features, and prepare for future uses by [@rasamassen](https://github.com/rasamassen) in [#2838](https://github.com/PHPOffice/PHPWord/pull/2838) ### Miscellaneous @@ -16,4 +17,4 @@ ### BC Breaks -### Notes \ No newline at end of file +### Notes From e11d71d161e616ace6b301587395f833a50c5595 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 19:56:35 -0500 Subject: [PATCH 11/51] Update Section.php --- src/PhpWord/Writer/RTF/Style/Section.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Section.php b/src/PhpWord/Writer/RTF/Style/Section.php index f45c358f67..47525ed289 100644 --- a/src/PhpWord/Writer/RTF/Style/Section.php +++ b/src/PhpWord/Writer/RTF/Style/Section.php @@ -59,16 +59,9 @@ public function write() // Borders if ($style->hasBorder()) { - // Page border measure - // 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off - $content .= '\pgbrdropt32'; $styleWriter = new Border($style); $styleWriter->setParentWriter($this->getParentWriter()); - $styleWriter->setType('page'); - $styleWriter->setSizes($style->getBorderSize()); - $styleWriter->setColors($style->getBorderColor()); - $styleWriter->setStyles($style->getBorderStyle()); - $styleWriter->setSpaces($style->getBorderSpace()); + $styleWriter->setType('section'); $content .= $styleWriter->write(); } From 668599dcbd009842613a53f8c918ea2e882ca18f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 19:56:59 -0500 Subject: [PATCH 12/51] Update Paragraph.php --- src/PhpWord/Writer/RTF/Style/Paragraph.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Paragraph.php b/src/PhpWord/Writer/RTF/Style/Paragraph.php index 8cec362d0f..41b570cecf 100644 --- a/src/PhpWord/Writer/RTF/Style/Paragraph.php +++ b/src/PhpWord/Writer/RTF/Style/Paragraph.php @@ -106,10 +106,6 @@ public function write() $styleWriter = new Border($style); $styleWriter->setParentWriter($this->getParentWriter()); $styleWriter->setType('paragraph'); - $styleWriter->setSizes($style->getBorderSize()); - $styleWriter->setColors($style->getBorderColor()); - $styleWriter->setStyles($style->getBorderStyle()); - $styleWriter->setSpaces($style->getBorderSpace()); $content .= $styleWriter->write(); } From a333f50aa7cf19e29d83909897a3e1321915df76 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 19:57:11 -0500 Subject: [PATCH 13/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 110 ++++++------------------ 1 file changed, 26 insertions(+), 84 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 5ceb74f339..a642c0ae7a 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -28,37 +28,9 @@ class Border extends AbstractStyle { /** - * Sizes. - * - * @var array - */ - private $sizes = []; - - /** - * Colors. - * - * @var array - */ - private $colors = []; - - /** - * Styles. - * - * @var array - */ - private $styles = []; - - /** - * Spaces. - * - * @var array - */ - private $spaces = []; - - /** - * Type. - * - * Can be page, header, footer, paragraph, character, row, or cell. + * Type + * + * Can be section, header, footer, paragraph, font, row, or cell. * * @var string */ @@ -78,16 +50,27 @@ public function write() $content = ''; + if ($this->type == 'section') { + // Page border measure + // 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off + $content .= '\pgbrdropt32'; + } + $sides = ['top', 'left', 'right', 'bottom']; - $sizeCount = count($this->sizes); + $sizeCount = 4; + + if (in_array($this->type, ['header', 'footer', 'font'])) { + $sizeCount = 1; + } + + $sizes = $style->getBorderSize(); + $colors = $style->getBorderColor(); + $styles = $style->getBorderStyle(); + $spaces = $style->getBorderSpace(); for ($i = 0; $i < $sizeCount; ++$i) { - if ($this->sizes[$i] !== null) { - $color = null; - if (isset($this->colors[$i])) { - $color = $this->colors[$i]; - } - $content .= $this->writeSide($sides[$i], $this->sizes[$i], $color, $this->styles[$i], $this->spaces[$i]); + if ($sides[$i] !== null) { + $content .= $this->writeSide($sides[$i], $sizes[$i], $colors[$i], $styles[$i], $spaces[$i]); } } @@ -101,18 +84,17 @@ public function write() * @param int $width * @param string $color * @param string $style - * @param int $space * * @return string */ - private function writeSide($side, $width, $color, $style, $space) + private function writeSide($side, $width, $color = '', $style, $space) { $types = [ - 'page' => '\pgbrdr', + 'section' => '\pgbrdr', 'header' => '\pgbrdrhead', 'footer' => '\pgbrdrfoot', 'paragraph' => '\brdr', - 'character' => '\chbrdr', + 'font' => '\chbrdr', 'row' => '\trbrdr', 'cell' => '\clbrdr', ]; @@ -160,7 +142,7 @@ private function writeSide($side, $width, $color, $style, $space) $content = ''; $type = 'paragraph'; if (isset($types[$this->type])) { - if (in_array($types[$this->type], ['header', 'footer', 'character'])) { + if (in_array($types[$this->type], ['header', 'footer', 'font'])) { $content .= $types[$this->type]; // header, footer, and character borders cannot vary by side } else { $content .= $types[$this->type] . substr($side, 0, 1); @@ -178,7 +160,7 @@ private function writeSide($side, $width, $color, $style, $space) $content .= '\brdrcf' . $colorIndex; // Color // Space - if ($this->type == 'page') { + if ($this->type == 'section') { $space = $space !== null ? $space : '480'; } elseif ($this->type == 'paragraph') { if ($side == 'top' || $side == 'bottom') { @@ -194,46 +176,6 @@ private function writeSide($side, $width, $color, $style, $space) return $content; } - /** - * Set sizes. - * - * @param int[] $value - */ - public function setSizes($value): void - { - $this->sizes = $value; - } - - /** - * Set colors. - * - * @param string[] $value - */ - public function setColors($value): void - { - $this->colors = $value; - } - - /** - * Set styles. - * - * @param string[] $value - */ - public function setStyles($value): void - { - $this->styles = $value; - } - - /** - * Set styles. - * - * @param string[] $value - */ - public function setSpaces($value): void - { - $this->spaces = $value; - } - /** * Set type. * From 63b5a666c5939d1aeca82aeaf8562c7f366b64c2 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:00:54 -0500 Subject: [PATCH 14/51] Update StyleTest.php --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 5083014c81..6e20d0997b 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -54,18 +54,17 @@ public function testEmptyStyles(): void public function testBorderWithNonRegisteredColors(): void { $border = new \PhpOffice\PhpWord\Style\Border(); + $border->setBorderSize(40); + $border->setBorderTopSize(20); + $border->setBorderColor('#FF0000'); $borderWriter = new RTF\Style\Border($border); $borderWriter->setParentWriter(new RTF()); - $borderWriter->setType('page'); - $borderWriter->setSizes([1, 2, 3, 4]); - $borderWriter->setColors(['#FF0000', '#FF0000', '#FF0000', '#FF0000']); - $borderWriter->setSizes([20, 20, 20, 20]); - $borderWriter->setStyles($border->getBorderStyle()); - $borderWriter->setSpaces($border->getBorderSpace()); - + $borderWriter->setType('section'); + $content = $borderWriter->write(); - $expected = '\pgbrdrt\brdrs\brdrw20\brdrcf0\brsp480 '; + $expected = '\pgbrdropt32'; + $expected . = '\pgbrdrt\brdrs\brdrw40\brdrcf0\brsp480 '; $expected .= '\pgbrdrl\brdrs\brdrw20\brdrcf0\brsp480 '; $expected .= '\pgbrdrr\brdrs\brdrw20\brdrcf0\brsp480 '; $expected .= '\pgbrdrb\brdrs\brdrw20\brdrcf0\brsp480 '; From b3f4a1226a0920164918fe16a3f0e02025372a26 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:02:20 -0500 Subject: [PATCH 15/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index a642c0ae7a..3b6a2edfd5 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -29,7 +29,7 @@ class Border extends AbstractStyle { /** * Type - * + * * Can be section, header, footer, paragraph, font, row, or cell. * * @var string @@ -55,7 +55,7 @@ public function write() // 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off $content .= '\pgbrdropt32'; } - + $sides = ['top', 'left', 'right', 'bottom']; $sizeCount = 4; @@ -84,10 +84,11 @@ public function write() * @param int $width * @param string $color * @param string $style + * @param int $space * * @return string */ - private function writeSide($side, $width, $color = '', $style, $space) + private function writeSide($side, $width, $color, $style, $space) { $types = [ 'section' => '\pgbrdr', @@ -142,7 +143,7 @@ private function writeSide($side, $width, $color = '', $style, $space) $content = ''; $type = 'paragraph'; if (isset($types[$this->type])) { - if (in_array($types[$this->type], ['header', 'footer', 'font'])) { + if (in_array($types[$this->type], ['header', 'footer', 'font'])) { $content .= $types[$this->type]; // header, footer, and character borders cannot vary by side } else { $content .= $types[$this->type] . substr($side, 0, 1); From f5dae82837220f957aaeb92b5b8fc563a47f0134 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:04:08 -0500 Subject: [PATCH 16/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 3b6a2edfd5..1131f7b678 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -28,9 +28,7 @@ class Border extends AbstractStyle { /** - * Type - * - * Can be section, header, footer, paragraph, font, row, or cell. + * Type. Can be section, header, footer, paragraph, font, row, or cell. * * @var string */ From 1ceaa5a2d7415a0f2b9e70f773b63cbb841a316c Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:04:29 -0500 Subject: [PATCH 17/51] Update StyleTest.php --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 6e20d0997b..680f95ef8e 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -64,7 +64,7 @@ public function testBorderWithNonRegisteredColors(): void $content = $borderWriter->write(); $expected = '\pgbrdropt32'; - $expected . = '\pgbrdrt\brdrs\brdrw40\brdrcf0\brsp480 '; + $expected .= '\pgbrdrt\brdrs\brdrw40\brdrcf0\brsp480 '; $expected .= '\pgbrdrl\brdrs\brdrw20\brdrcf0\brsp480 '; $expected .= '\pgbrdrr\brdrs\brdrw20\brdrcf0\brsp480 '; $expected .= '\pgbrdrb\brdrs\brdrw20\brdrcf0\brsp480 '; From f6027fd1749b75a51659b4faa35a224bb5c88f46 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:07:27 -0500 Subject: [PATCH 18/51] Update StyleTest.php --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 680f95ef8e..253bfdef97 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -60,14 +60,14 @@ public function testBorderWithNonRegisteredColors(): void $borderWriter = new RTF\Style\Border($border); $borderWriter->setParentWriter(new RTF()); $borderWriter->setType('section'); - + $content = $borderWriter->write(); $expected = '\pgbrdropt32'; - $expected .= '\pgbrdrt\brdrs\brdrw40\brdrcf0\brsp480 '; - $expected .= '\pgbrdrl\brdrs\brdrw20\brdrcf0\brsp480 '; - $expected .= '\pgbrdrr\brdrs\brdrw20\brdrcf0\brsp480 '; - $expected .= '\pgbrdrb\brdrs\brdrw20\brdrcf0\brsp480 '; + $expected .= '\pgbrdrt\brdrs\brdrw20\brdrcf0\brsp480 '; + $expected .= '\pgbrdrl\brdrs\brdrw40\brdrcf0\brsp480 '; + $expected .= '\pgbrdrr\brdrs\brdrw40\brdrcf0\brsp480 '; + $expected .= '\pgbrdrb\brdrs\brdrw40\brdrcf0\brsp480 '; self::assertEquals($expected, $content); } From 1039aee2867c8528152b04560e60adfd384b97fe Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:09:13 -0500 Subject: [PATCH 19/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 1131f7b678..4c1e9e88d4 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -67,9 +67,7 @@ public function write() $spaces = $style->getBorderSpace(); for ($i = 0; $i < $sizeCount; ++$i) { - if ($sides[$i] !== null) { - $content .= $this->writeSide($sides[$i], $sizes[$i], $colors[$i], $styles[$i], $spaces[$i]); - } + $content .= $this->writeSide($sides[$i], $sizes[$i], $colors[$i], $styles[$i], $spaces[$i]); } return $content; From 09d1d2d304cd1adb2e81605ec0afdf0d38ea248b Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:12:32 -0500 Subject: [PATCH 20/51] Update Border.php --- src/PhpWord/Style/Border.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index 57bd5772ad..9809073883 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -49,7 +49,7 @@ class Border extends AbstractStyle /** * Border Top Space. For section and paragraph borders only. * - * @var string + * @var float|int */ protected $borderTopSpace; @@ -77,7 +77,7 @@ class Border extends AbstractStyle /** * Border Left Space. For section and paragraph borders only. * - * @var string + * @var float|int */ protected $borderLeftSpace; @@ -105,7 +105,7 @@ class Border extends AbstractStyle /** * Border Right Space. For section and paragraph borders only. * - * @var string + * @var float|int */ protected $borderRightSpace; @@ -133,7 +133,7 @@ class Border extends AbstractStyle /** * Border Bottom Space. For section and paragraph borders only. * - * @var string + * @var float|int */ protected $borderBottomSpace; @@ -264,7 +264,7 @@ public function setBorderStyle($value = null) /** * Get border space. * - * @return string[] + * @return int[] */ public function getBorderSpace() { @@ -279,7 +279,7 @@ public function getBorderSpace() /** * Set border space. * - * @param string $value + * @param float|int $value * * @return self */ @@ -368,7 +368,7 @@ public function setBorderTopStyle($value = null) /** * Get border top space. * - * @return string + * @return float|int */ public function getBorderTopSpace() { @@ -378,7 +378,7 @@ public function getBorderTopSpace() /** * Set border top space. * - * @param string $value + * @param float|int $value * * @return self */ @@ -464,7 +464,7 @@ public function setBorderLeftStyle($value = null) /** * Get border left space. * - * @return string + * @return float|int */ public function getBorderLeftSpace() { @@ -474,7 +474,7 @@ public function getBorderLeftSpace() /** * Set border left space. * - * @param string $value + * @param float|int $value * * @return self */ @@ -560,7 +560,7 @@ public function setBorderRightStyle($value = null) /** * Get border right space. * - * @return string + * @return float|int */ public function getBorderRightSpace() { @@ -570,7 +570,7 @@ public function getBorderRightSpace() /** * Set border right space. * - * @param string $value + * @param float|int $value * * @return self */ @@ -656,7 +656,7 @@ public function setBorderBottomStyle($value = null) /** * Get border bottom space. * - * @return string + * @return float|int */ public function getBorderBottomSpace() { @@ -666,7 +666,7 @@ public function getBorderBottomSpace() /** * Set border bottom space. * - * @param string $value + * @param float|int $value * * @return self */ From af123923442147a7b73ee4a4fa36968065c572ff Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:16:37 -0500 Subject: [PATCH 21/51] Update Border.php --- src/PhpWord/Style/Border.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index 9809073883..5a29fe7db5 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -264,7 +264,7 @@ public function setBorderStyle($value = null) /** * Get border space. * - * @return int[] + * @return float|int[] */ public function getBorderSpace() { From 283aa678d8ea9cd6c34f27673d4965baee23c5d9 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:23:32 -0500 Subject: [PATCH 22/51] Update Border.php --- src/PhpWord/Style/Border.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index 5a29fe7db5..b5841cb824 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -264,7 +264,7 @@ public function setBorderStyle($value = null) /** * Get border space. * - * @return float|int[] + * @return float[]|int[] */ public function getBorderSpace() { From 3e97c7e833a532f1b08179fa7e4dba637419b814 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:27:18 -0500 Subject: [PATCH 23/51] Update Border.php --- src/PhpWord/Style/Border.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index b5841cb824..1e59dff556 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -168,7 +168,7 @@ class Border extends AbstractStyle /** * Get border size. * - * @return int[] + * @return float[]|int[] */ public function getBorderSize() { From f65cdf416a7cb6d3ade6ec7058a73eaed8cc2475 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:27:52 -0500 Subject: [PATCH 24/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 4c1e9e88d4..dab27cad23 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -77,10 +77,10 @@ public function write() * Write side. * * @param string $side - * @param int $width + * @param float|int $width * @param string $color * @param string $style - * @param int $space + * @param float|int $space * * @return string */ From ccd572dcbb88b653e4bad10992b5ea3f691f1ba8 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:31:35 -0500 Subject: [PATCH 25/51] Update Border.php --- src/PhpWord/Style/Border.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index 1e59dff556..46f13d28ac 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -168,7 +168,7 @@ class Border extends AbstractStyle /** * Get border size. * - * @return float[]|int[] + * @return array */ public function getBorderSize() { @@ -264,7 +264,7 @@ public function setBorderStyle($value = null) /** * Get border space. * - * @return float[]|int[] + * @return array */ public function getBorderSpace() { From b7a67f5ba9079d587d5f607fc71dbd95ca1d5702 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:32:23 -0500 Subject: [PATCH 26/51] Update MarginBorder.php --- src/PhpWord/Writer/Word2007/Style/MarginBorder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php index b464e66ffb..f472e15cd4 100644 --- a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php +++ b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php @@ -30,7 +30,7 @@ class MarginBorder extends AbstractStyle /** * Sizes. * - * @var int[] + * @var array */ private $sizes = []; @@ -80,7 +80,7 @@ public function write(): void * Write side. * * @param string $side - * @param int $width + * @param float|int $width * @param string $color * @param string $borderStyle */ @@ -111,7 +111,7 @@ private function writeSide(XMLWriter $xmlWriter, $side, $width, $color = null, $ /** * Set sizes. * - * @param int[] $value + * @param array $value */ public function setSizes($value): void { From a6f8f6c6a79aec53780c2e425b0ee83a274a5f8e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:47:20 -0500 Subject: [PATCH 27/51] Create BorderTest.php --- .../Writer/RTF/Style/BorderTest.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/PhpWordTests/Writer/RTF/Style/BorderTest.php diff --git a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php new file mode 100644 index 0000000000..f51b736759 --- /dev/null +++ b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php @@ -0,0 +1,65 @@ +write()); + } + + /** + * Test Border styles in paragraph. + * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + */ + public function testBorderStyle(): void + { + $parentWriter = new RTF(); + $style = new BorderStyle(); + $writer = new BorderWriter($style); + $writer->setParentWriter($parentWriter); + + $border->setBorderSize(40); + $border->setBorderColor('#FF0000'); + $border->setBorderStyle(BorderType::DASHED); + $border->setBorderSpace(20); + + $expected .= '\brdrt\brdrdash\brdrw40\brdrcf0\brsp20 '; + $expected .= '\brdrl\brdrdash\brdrw40\brdrcf0\brsp20 '; + $expected .= '\brdrr\brdrdash\brdrw40\brdrcf0\brsp20 '; + $expected .= '\brdrb\brdrdash\brdrw40\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + } +} From b30a6c147b74073c18e65ed3819357171f7b6a69 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:51:12 -0500 Subject: [PATCH 28/51] Update BorderTest.php --- .../PhpWordTests/Writer/RTF/Style/BorderTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php index f51b736759..5f89998539 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php @@ -51,15 +51,15 @@ public function testBorderStyle(): void $writer = new BorderWriter($style); $writer->setParentWriter($parentWriter); - $border->setBorderSize(40); - $border->setBorderColor('#FF0000'); - $border->setBorderStyle(BorderType::DASHED); - $border->setBorderSpace(20); + $style->setBorderSize(40); + $style->setBorderColor('#FF0000'); + $style->setBorderStyle(BorderType::DASHED); + $style->setBorderSpace(20); - $expected .= '\brdrt\brdrdash\brdrw40\brdrcf0\brsp20 '; - $expected .= '\brdrl\brdrdash\brdrw40\brdrcf0\brsp20 '; - $expected .= '\brdrr\brdrdash\brdrw40\brdrcf0\brsp20 '; - $expected .= '\brdrb\brdrdash\brdrw40\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrdash\brdrw40\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrdash\brdrw40\brdrcf0\brsp20 '; + $expect .= '\brdrr\brdrdash\brdrw40\brdrcf0\brsp20 '; + $expect .= '\brdrb\brdrdash\brdrw40\brdrcf0\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); } } From 644625c872f43209266ddeeef82fe09673072912 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 6 Oct 2025 20:56:14 -0500 Subject: [PATCH 29/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index dab27cad23..a38c8e105e 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -32,7 +32,7 @@ class Border extends AbstractStyle * * @var string */ - private $type; + private $type = 'paragraph'; /** * Write style. @@ -137,7 +137,6 @@ private function writeSide($side, $width, $color, $style, $space) } $content = ''; - $type = 'paragraph'; if (isset($types[$this->type])) { if (in_array($types[$this->type], ['header', 'footer', 'font'])) { $content .= $types[$this->type]; // header, footer, and character borders cannot vary by side From 3a6ce9309c233eb874998cd607e5f9135556ba3e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 20:59:54 -0500 Subject: [PATCH 30/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index a38c8e105e..16a810211d 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -152,8 +152,8 @@ private function writeSide($side, $width, $color, $style, $space) } else { $content .= '\brdrs'; // default style } - $content .= '\brdrw' . round($width); // Width - $content .= '\brdrcf' . $colorIndex; // Color + $content .= $this->getValueIf($width !== null, '\brdrw' . round($width)); // Width + $content .= $this->getValueIf($colorIndex !== 0, '\brdrcf' . $colorIndex); // Color // Space if ($this->type == 'section') { From 3849afaf35f05cf913c3f9468206645d2e2a308a Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 21:02:00 -0500 Subject: [PATCH 31/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 16a810211d..86b6eb3688 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -165,7 +165,9 @@ private function writeSide($side, $width, $color, $style, $space) $space = $space !== null ? $space : '80'; } } - $content .= $this->getValueIf($space !== null, '\brsp' . round($space ?? 0)); + if (in_array($types[$this->type], ['section', 'paragraph'])) { + $content .= $this->getValueIf($space !== null, '\brsp' . round($space ?? 0)); + } $content .= ' '; From c9d40544abc8d3d824598b12ce8d05d017acc441 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 21:08:07 -0500 Subject: [PATCH 32/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 86b6eb3688..8958f3293e 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -28,7 +28,7 @@ class Border extends AbstractStyle { /** - * Type. Can be section, header, footer, paragraph, font, row, or cell. + * Type. Can be section, paragraph, font, row, or cell. * * @var string */ @@ -57,7 +57,7 @@ public function write() $sides = ['top', 'left', 'right', 'bottom']; $sizeCount = 4; - if (in_array($this->type, ['header', 'footer', 'font'])) { + if ($this->type == 'font') { $sizeCount = 1; } @@ -88,8 +88,6 @@ private function writeSide($side, $width, $color, $style, $space) { $types = [ 'section' => '\pgbrdr', - 'header' => '\pgbrdrhead', - 'footer' => '\pgbrdrfoot', 'paragraph' => '\brdr', 'font' => '\chbrdr', 'row' => '\trbrdr', @@ -138,8 +136,8 @@ private function writeSide($side, $width, $color, $style, $space) $content = ''; if (isset($types[$this->type])) { - if (in_array($types[$this->type], ['header', 'footer', 'font'])) { - $content .= $types[$this->type]; // header, footer, and character borders cannot vary by side + if ($types[$this->type] == 'font') { + $content .= $types[$this->type]; // character borders cannot vary by side } else { $content .= $types[$this->type] . substr($side, 0, 1); } From 550d36c6420fbe92618b94715a3f58426630cb9a Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 21:11:13 -0500 Subject: [PATCH 33/51] Update BorderTest.php --- .../Writer/RTF/Style/BorderTest.php | 60 ++++++++++++++++--- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php index 5f89998539..195d7e8444 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php @@ -44,22 +44,64 @@ public function removeCr($field): string * Test Border styles in paragraph. * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. */ - public function testBorderStyle(): void + public function testBorderBasic(): void { $parentWriter = new RTF(); $style = new BorderStyle(); $writer = new BorderWriter($style); $writer->setParentWriter($parentWriter); - $style->setBorderSize(40); - $style->setBorderColor('#FF0000'); - $style->setBorderStyle(BorderType::DASHED); - $style->setBorderSpace(20); + $expect = '\brdrt\brdrs\brsp20 '; + $expect .= '\brdrl\brdrs\brsp80 '; + $expect .= '\brdrr\brdrs\brsp80 '; + $expect .= '\brdrb\brdrs\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + } + + /** + * Test Border styles in paragraph. + * See page 76 of RTF Specification 1.9.1 for Page Borders. + * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + * See page 103 of RTF Specification 1.9.1 for Row Borders and Cell Borders. + * See page 139 of RTF Specification 1.9.1 for Character Borders. + */ + public function testBorderType(): void + { + $parentWriter = new RTF(); + $style = new BorderStyle(); + $writer = new BorderWriter($style); + $writer->setParentWriter($parentWriter); + + $writer->setType('section'); + $expect = '\pgbrdrt\brdrs\brsp480 '; + $expect .= '\pgbrdrl\brdrs\brsp480 '; + $expect .= '\pgbrdrr\brdrs\brsp480 '; + $expect .= '\pgbrdrb\brdrs\brsp480 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $writer->setType('paragraph'); + $expect = '\brdrt\brdrs\brsp20 '; + $expect .= '\brdrl\brdrs\brsp80 '; + $expect .= '\brdrr\brdrs\brsp80 '; + $expect .= '\brdrb\brdrs\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $writer->setType('font'); + $expect = '\chbrdr\brdrs '; + self::assertEquals($expect, $this->removeCr($writer)); + + $writer->setType('row'); + $expect = '\tdbrdrt\brdrs '; + $expect .= '\tdbrdrl\brdrs '; + $expect .= '\tdbrdrr\brdrs '; + $expect .= '\tdbrdrb\brdrs '; + self::assertEquals($expect, $this->removeCr($writer)); - $expect = '\brdrt\brdrdash\brdrw40\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrdash\brdrw40\brdrcf0\brsp20 '; - $expect .= '\brdrr\brdrdash\brdrw40\brdrcf0\brsp20 '; - $expect .= '\brdrb\brdrdash\brdrw40\brdrcf0\brsp20 '; + $writer->setType('cell'); + $expect = '\clbrdrt\brdrs '; + $expect .= '\clbrdrl\brdrs '; + $expect .= '\clbrdrr\brdrs '; + $expect .= '\clbrdrb\brdrs '; self::assertEquals($expect, $this->removeCr($writer)); } } From bf912eacbb9023eb3ebbc14d44b707d62ab28540 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 21:15:10 -0500 Subject: [PATCH 34/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 8958f3293e..0379c27390 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -136,7 +136,7 @@ private function writeSide($side, $width, $color, $style, $space) $content = ''; if (isset($types[$this->type])) { - if ($types[$this->type] == 'font') { + if ($this->type == 'font') { $content .= $types[$this->type]; // character borders cannot vary by side } else { $content .= $types[$this->type] . substr($side, 0, 1); @@ -151,7 +151,7 @@ private function writeSide($side, $width, $color, $style, $space) $content .= '\brdrs'; // default style } $content .= $this->getValueIf($width !== null, '\brdrw' . round($width)); // Width - $content .= $this->getValueIf($colorIndex !== 0, '\brdrcf' . $colorIndex); // Color + $content .= '\brdrcf' . $colorIndex; // Color // Space if ($this->type == 'section') { @@ -163,7 +163,7 @@ private function writeSide($side, $width, $color, $style, $space) $space = $space !== null ? $space : '80'; } } - if (in_array($types[$this->type], ['section', 'paragraph'])) { + if (in_array($this->type, ['section', 'paragraph'])) { $content .= $this->getValueIf($space !== null, '\brsp' . round($space ?? 0)); } From bc5efdda5144d3ae71502ca002695cc10dcbc6f3 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 21:41:09 -0500 Subject: [PATCH 35/51] Update BorderTest.php --- .../Writer/RTF/Style/BorderTest.php | 160 +++++++++++++++--- 1 file changed, 139 insertions(+), 21 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php index 195d7e8444..c37dfb34ce 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php @@ -21,6 +21,7 @@ use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\SimpleType\Border as BorderType; use PhpOffice\PhpWord\Style\Border as BorderStyle; +use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Writer\RTF; use PhpOffice\PhpWord\Writer\RTF\Style\Border as BorderWriter; use PHPUnit\Framework\TestCase; @@ -51,10 +52,10 @@ public function testBorderBasic(): void $writer = new BorderWriter($style); $writer->setParentWriter($parentWriter); - $expect = '\brdrt\brdrs\brsp20 '; - $expect .= '\brdrl\brdrs\brsp80 '; - $expect .= '\brdrr\brdrs\brsp80 '; - $expect .= '\brdrb\brdrs\brsp20 '; + $expect = '\brdrt\brdrs\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrs\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrs\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrs\brdrcf0\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -73,35 +74,152 @@ public function testBorderType(): void $writer->setParentWriter($parentWriter); $writer->setType('section'); - $expect = '\pgbrdrt\brdrs\brsp480 '; - $expect .= '\pgbrdrl\brdrs\brsp480 '; - $expect .= '\pgbrdrr\brdrs\brsp480 '; - $expect .= '\pgbrdrb\brdrs\brsp480 '; + $expect = '\pgbrdrt\brdrs\brdrcf0\brsp480 '; + $expect .= '\pgbrdrl\brdrs\brdrcf0\brsp480 '; + $expect .= '\pgbrdrr\brdrs\brdrcf0\brsp480 '; + $expect .= '\pgbrdrb\brdrs\brdrcf0\brsp480 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('paragraph'); - $expect = '\brdrt\brdrs\brsp20 '; - $expect .= '\brdrl\brdrs\brsp80 '; - $expect .= '\brdrr\brdrs\brsp80 '; - $expect .= '\brdrb\brdrs\brsp20 '; + $expect = '\brdrt\brdrs\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrs\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrs\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrs\brdrcf0\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('font'); - $expect = '\chbrdr\brdrs '; + $expect = '\chbrdr\brdrs\brdrcf0 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('row'); - $expect = '\tdbrdrt\brdrs '; - $expect .= '\tdbrdrl\brdrs '; - $expect .= '\tdbrdrr\brdrs '; - $expect .= '\tdbrdrb\brdrs '; + $expect = '\tdbrdrt\brdrs\brdrcf0 '; + $expect .= '\tdbrdrl\brdrs\brdrcf0 '; + $expect .= '\tdbrdrr\brdrs\brdrcf0 '; + $expect .= '\tdbrdrb\brdrs\brdrcf0 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('cell'); - $expect = '\clbrdrt\brdrs '; - $expect .= '\clbrdrl\brdrs '; - $expect .= '\clbrdrr\brdrs '; - $expect .= '\clbrdrb\brdrs '; + $expect = '\clbrdrt\brdrs\brdrcf0 '; + $expect .= '\clbrdrl\brdrs\brdrcf0 '; + $expect .= '\clbrdrr\brdrs\brdrcf0 '; + $expect .= '\clbrdrb\brdrs\brdrcf0 '; + self::assertEquals($expect, $this->removeCr($writer)); + } + + /** + * Test Border size. + * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + */ + public function testBorderSize(): void + { + $parentWriter = new RTF(); + $style = new BorderStyle(); + $writer = new BorderWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setBorderSize(100); + $expect = '\brdrt\brdrs\brdrw100\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrs\brdrw100\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrs\brdrw100\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrs\brdrw100\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setBorderTopSize(200); + $style->setBorderLeftSize(150); + $style->setBorderRightSize(50); + $style->setBorderBottomSize(20); + $expect = '\brdrt\brdrs\brdrw200\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrs\brdrw150\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrs\brdrw50\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrs\brdrw20\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + } + + /** + * Test Border colors. + * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + */ + public function testBorderColor(): void + { + $phpWord = new \PhpOffice\PhpWord\PhpWord(); + $parentWriter = new RTF($phpWord); + + $style1 = new ParagraphStyle(); + $style1->setBorderColor('FFFFFF'); + $phpWord->addParagraphStyle('style1', $style1); + + $style2 = new ParagraphStyle(); + $style2->setBorderTopColor('FFFF00'); + $style2->setBorderLeftColor('FF0000'); + $style2->setBorderRightColor('000000'); + $style2->setBorderBottomColor('0000FF'); + $phpWord->addParagraphStyle('style2', $style2); + + $parentWriter->getWriterPart('Header')->write(); + + $writer = new BorderWriter(new Border($style1)); + $writer->setParentWriter($parentWriter); + $expect = '\brdrt\brdrs\brdrcf1\brsp20 '; + $expect .= '\brdrl\brdrs\brdrcf1\brsp80 '; + $expect .= '\brdrr\brdrs\brdrcf1\brsp80 '; + $expect .= '\brdrb\brdrs\brdrcf1\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $writer = new BorderWriter(new Border($style2)); + $writer->setParentWriter($parentWriter); + $expect = '\brdrt\brdrs\brdrcf2\brsp20 '; + $expect .= '\brdrl\brdrs\brdrcf3\brsp80 '; + $expect .= '\brdrr\brdrs\brdrcf4\brsp80 '; + $expect .= '\brdrb\brdrs\brdrcf5\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + } + + /** + * Test Border space. + * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + */ + public function testBorderSpace(): void + { + $parentWriter = new RTF(); + $style = new BorderStyle(); + $writer = new BorderWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setBorderSpace(100); + $expect = '\brdrt\brdrs\brdrcf0\brsp100 '; + $expect .= '\brdrl\brdrs\brdrcf0\brsp100 '; + $expect .= '\brdrr\brdrs\brdrcf0\brsp100 '; + $expect .= '\brdrb\brdrs\brdrcf0\brsp100 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setBorderTopSpace(200); + $style->setBorderLeftSpace(150); + $style->setBorderRightSpace(50); + $style->setBorderBottomSpace(20); + $expect = '\brdrt\brdrs\brdrcf0\brsp200 '; + $expect .= '\brdrl\brdrs\brdrcf0\brsp150 '; + $expect .= '\brdrr\brdrs\brdrcf0\brsp500 '; + $expect .= '\brdrb\brdrs\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $writer->setType('font'); + $expect = '\chbrdr\brdrs\brdrcf0 '; + self::assertEquals($expect, $this->removeCr($writer)); + + // Technically rows can have \brspN, but it messes up the table drawing - margin/padding should be used instead. + $writer->setType('row'); + $expect = '\tdbrdrt\brdrs\brdrcf0 '; + $expect .= '\tdbrdrl\brdrs\brdrcf0 '; + $expect .= '\tdbrdrr\brdrs\brdrcf0 '; + $expect .= '\tdbrdrb\brdrs\brdrcf0 '; + self::assertEquals($expect, $this->removeCr($writer)); + + // Technically cells can have \brspN, but it messes up the table drawing - margin/padding should be used instead. + $writer->setType('cell'); + $expect = '\clbrdrt\brdrs\brdrcf0 '; + $expect .= '\clbrdrl\brdrs\brdrcf0 '; + $expect .= '\clbrdrr\brdrs\brdrcf0 '; + $expect .= '\clbrdrb\brdrs\brdrcf0 '; self::assertEquals($expect, $this->removeCr($writer)); } } From 79661dfe4d2037196afbdf1dc7990f7b5a6ed3c5 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 21:59:52 -0500 Subject: [PATCH 36/51] Update BorderTest.php --- .../Writer/RTF/Style/BorderTest.php | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php index c37dfb34ce..4f5bb9a2d6 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php @@ -21,7 +21,6 @@ use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\SimpleType\Border as BorderType; use PhpOffice\PhpWord\Style\Border as BorderStyle; -use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Writer\RTF; use PhpOffice\PhpWord\Writer\RTF\Style\Border as BorderWriter; use PHPUnit\Framework\TestCase; @@ -74,7 +73,8 @@ public function testBorderType(): void $writer->setParentWriter($parentWriter); $writer->setType('section'); - $expect = '\pgbrdrt\brdrs\brdrcf0\brsp480 '; + $exoect = '\pgbrdropt32'; + $expect .= '\pgbrdrt\brdrs\brdrcf0\brsp480 '; $expect .= '\pgbrdrl\brdrs\brdrcf0\brsp480 '; $expect .= '\pgbrdrr\brdrs\brdrcf0\brsp480 '; $expect .= '\pgbrdrb\brdrs\brdrcf0\brsp480 '; @@ -107,10 +107,10 @@ public function testBorderType(): void } /** - * Test Border size. + * Test Border style. * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. */ - public function testBorderSize(): void + public function testBorderStyle(): void { $parentWriter = new RTF(); $style = new BorderStyle(); @@ -135,10 +135,43 @@ public function testBorderSize(): void self::assertEquals($expect, $this->removeCr($writer)); } + /** + * Test Border size. + * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + */ + public function testBorderSize(): void + { + $parentWriter = new RTF(); + $style = new BorderStyle(); + $writer = new BorderWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setBorderStyle(BorderType::DASH_DOT_STROKED); + $expect = '\brdrt\brdrdashd\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrdashd\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrdashd\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrdashd\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setBorderTopStyle(BorderType::DASHED); + $style->setBorderLeftStyle(BorderType::DASH_SMALL_GAP); + $style->setBorderRightStyle(BorderType::DOT_DASH); + $style->setBorderBottomStyle(BorderType::DOT_DOT_DASH); + $expect = '\brdrt\brdrdash\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrdashsm\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrdashd\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrdashdd\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + } + /** * Test Border colors. * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + * + * Create test when paragraph inherits border. */ + + /** public function testBorderColor(): void { $phpWord = new \PhpOffice\PhpWord\PhpWord(); @@ -172,7 +205,7 @@ public function testBorderColor(): void $expect .= '\brdrr\brdrs\brdrcf4\brsp80 '; $expect .= '\brdrb\brdrs\brdrcf5\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); - } + } */ /** * Test Border space. @@ -198,7 +231,7 @@ public function testBorderSpace(): void $style->setBorderBottomSpace(20); $expect = '\brdrt\brdrs\brdrcf0\brsp200 '; $expect .= '\brdrl\brdrs\brdrcf0\brsp150 '; - $expect .= '\brdrr\brdrs\brdrcf0\brsp500 '; + $expect .= '\brdrr\brdrs\brdrcf0\brsp50 '; $expect .= '\brdrb\brdrs\brdrcf0\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); From 2b3c2824c204cb6d594991098911c27550453596 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 22:16:55 -0500 Subject: [PATCH 37/51] Update BorderTest.php --- .../Writer/RTF/Style/BorderTest.php | 115 +++++++++++------- 1 file changed, 68 insertions(+), 47 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php index 4f5bb9a2d6..095a6ea246 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php @@ -73,7 +73,7 @@ public function testBorderType(): void $writer->setParentWriter($parentWriter); $writer->setType('section'); - $exoect = '\pgbrdropt32'; + $expect = '\pgbrdropt32'; $expect .= '\pgbrdrt\brdrs\brdrcf0\brsp480 '; $expect .= '\pgbrdrl\brdrs\brdrcf0\brsp480 '; $expect .= '\pgbrdrr\brdrs\brdrcf0\brsp480 '; @@ -147,10 +147,10 @@ public function testBorderSize(): void $writer->setParentWriter($parentWriter); $style->setBorderStyle(BorderType::DASH_DOT_STROKED); - $expect = '\brdrt\brdrdashd\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrdashd\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrdashd\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrdashd\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrdashdotstr\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrdashdotstr\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrdashdotstr\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrdashdotstr\brdrcf0\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopStyle(BorderType::DASHED); @@ -162,50 +162,71 @@ public function testBorderSize(): void $expect .= '\brdrr\brdrdashd\brdrcf0\brsp80 '; $expect .= '\brdrb\brdrdashdd\brdrcf0\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); - } - /** - * Test Border colors. - * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. - * - * Create test when paragraph inherits border. - */ - - /** - public function testBorderColor(): void - { - $phpWord = new \PhpOffice\PhpWord\PhpWord(); - $parentWriter = new RTF($phpWord); + $style->setBorderTopStyle(BorderType::DOTTED); + $style->setBorderLeftStyle(BorderType::DOUBLE); + $style->setBorderRightStyle(BorderType::DOUBLE_WAVE); + $style->setBorderBottomStyle(BorderType::INSET); + $expect = '\brdrt\brdrdot\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrdb\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrdashd\brdrwavydb\brsp80 '; + $expect .= '\brdrb\brdrdashdd\brdrinset\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); - $style1 = new ParagraphStyle(); - $style1->setBorderColor('FFFFFF'); - $phpWord->addParagraphStyle('style1', $style1); + $style->setBorderTopStyle(BorderType::NIL); + $style->setBorderLeftStyle(BorderType::NONE); + $style->setBorderRightStyle(BorderType::OUTSET); + $style->setBorderBottomStyle(BorderType::THICK); + $expect = '\brdrt\brdrnil\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrnone\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdroutset\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrth\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); - $style2 = new ParagraphStyle(); - $style2->setBorderTopColor('FFFF00'); - $style2->setBorderLeftColor('FF0000'); - $style2->setBorderRightColor('000000'); - $style2->setBorderBottomColor('0000FF'); - $phpWord->addParagraphStyle('style2', $style2); + $style->setBorderTopStyle(BorderType::THICK_THIN_LARGE_GAP); + $style->setBorderLeftStyle(BorderType::THICK_THIN_MEDIUM_GAP); + $style->setBorderRightStyle(BorderType::THICK_THIN_SMALL_GAP); + $style->setBorderBottomStyle(BorderType::THIN_THICK_LARGE_GAP); + $expect = '\brdrt\brdrtnthlg\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrtnthmg\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrtnthsg\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrthtnlg\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); - $parentWriter->getWriterPart('Header')->write(); + $style->setBorderTopStyle(BorderType::THIN_THICK_MEDIUM_GAP); + $style->setBorderLeftStyle(BorderType::THIN_THICK_SMALL_GAP); + $style->setBorderRightStyle(BorderType::THIN_THICK_THIN_LARGE_GAP); + $style->setBorderBottomStyle(BorderType::THIN_THICK_THIN_MEDIUM_GAP); + $expect = '\brdrt\brdrthtnmg\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrthtnsg\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrtnthtnlg\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrtnthtnmg\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); - $writer = new BorderWriter(new Border($style1)); - $writer->setParentWriter($parentWriter); - $expect = '\brdrt\brdrs\brdrcf1\brsp20 '; - $expect .= '\brdrl\brdrs\brdrcf1\brsp80 '; - $expect .= '\brdrr\brdrs\brdrcf1\brsp80 '; - $expect .= '\brdrb\brdrs\brdrcf1\brsp20 '; + $style->setBorderTopStyle(BorderType::THIN_THICK_THIN_SMALL_GAP); + $style->setBorderLeftStyle(BorderType::THREE_D_EMBOSS); + $style->setBorderRightStyle(BorderType::THREE_D_ENGRAVE); + $style->setBorderBottomStyle(BorderType::TRIPLE); + $expect = '\brdrt\brdrtnthtnsg\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdremboss\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrengrave\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrtriple\brdrcf0\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); - $writer = new BorderWriter(new Border($style2)); - $writer->setParentWriter($parentWriter); - $expect = '\brdrt\brdrs\brdrcf2\brsp20 '; - $expect .= '\brdrl\brdrs\brdrcf3\brsp80 '; - $expect .= '\brdrr\brdrs\brdrcf4\brsp80 '; - $expect .= '\brdrb\brdrs\brdrcf5\brsp20 '; + $style->setBorderStyle(BorderType::WAVE); + $expect = '\brdrt\brdrwavy\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrwavy\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrwavy\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrwavy\brdrcf0\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); - } */ + } + + /** + * Test Border colors. + * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + * + * Create test when paragraph inherits border. + */ /** * Test Border space. @@ -239,15 +260,15 @@ public function testBorderSpace(): void $expect = '\chbrdr\brdrs\brdrcf0 '; self::assertEquals($expect, $this->removeCr($writer)); - // Technically rows can have \brspN, but it messes up the table drawing - margin/padding should be used instead. + // Technically rows can have space, but it messes up the table drawing - margin/padding should be used instead. $writer->setType('row'); - $expect = '\tdbrdrt\brdrs\brdrcf0 '; - $expect .= '\tdbrdrl\brdrs\brdrcf0 '; - $expect .= '\tdbrdrr\brdrs\brdrcf0 '; - $expect .= '\tdbrdrb\brdrs\brdrcf0 '; + $expect = '\trbrdrt\brdrs\brdrcf0 '; + $expect .= '\trbrdrl\brdrs\brdrcf0 '; + $expect .= '\trbrdrr\brdrs\brdrcf0 '; + $expect .= '\trbrdrb\brdrs\brdrcf0 '; self::assertEquals($expect, $this->removeCr($writer)); - // Technically cells can have \brspN, but it messes up the table drawing - margin/padding should be used instead. + // Technically cells can have space, but it messes up the table drawing - margin/padding should be used instead. $writer->setType('cell'); $expect = '\clbrdrt\brdrs\brdrcf0 '; $expect .= '\clbrdrl\brdrs\brdrcf0 '; From 39ada03d3647b109107e89b9afce94e0c704f109 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 22:17:05 -0500 Subject: [PATCH 38/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 0379c27390..cac3cda104 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -96,7 +96,7 @@ private function writeSide($side, $width, $color, $style, $space) $styles = [ BorderType::SINGLE => '\brdrs', - BorderType::DASH_DOT_STROKED => '\brdrdashd', // no equivalent in RTF + BorderType::DASH_DOT_STROKED => '\brdrdashdotstr', BorderType::DASHED => '\brdrdash', BorderType::DASH_SMALL_GAP => '\brdrdashsm', BorderType::DOT_DASH => '\brdrdashd', From f842fcd9fcb2882b93ef68356081275f47f98dcb Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 22:23:28 -0500 Subject: [PATCH 39/51] Update BorderTest.php --- .../Writer/RTF/Style/BorderTest.php | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php index 095a6ea246..d266ea1ec6 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php @@ -92,10 +92,10 @@ public function testBorderType(): void self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('row'); - $expect = '\tdbrdrt\brdrs\brdrcf0 '; - $expect .= '\tdbrdrl\brdrs\brdrcf0 '; - $expect .= '\tdbrdrr\brdrs\brdrcf0 '; - $expect .= '\tdbrdrb\brdrs\brdrcf0 '; + $expect = '\trbrdrt\brdrs\brdrcf0 '; + $expect .= '\trbrdrl\brdrs\brdrcf0 '; + $expect .= '\trbrdrr\brdrs\brdrcf0 '; + $expect .= '\trbrdrb\brdrs\brdrcf0 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('cell'); @@ -117,35 +117,6 @@ public function testBorderStyle(): void $writer = new BorderWriter($style); $writer->setParentWriter($parentWriter); - $style->setBorderSize(100); - $expect = '\brdrt\brdrs\brdrw100\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrs\brdrw100\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrs\brdrw100\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrs\brdrw100\brdrcf0\brsp20 '; - self::assertEquals($expect, $this->removeCr($writer)); - - $style->setBorderTopSize(200); - $style->setBorderLeftSize(150); - $style->setBorderRightSize(50); - $style->setBorderBottomSize(20); - $expect = '\brdrt\brdrs\brdrw200\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrs\brdrw150\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrs\brdrw50\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrs\brdrw20\brdrcf0\brsp20 '; - self::assertEquals($expect, $this->removeCr($writer)); - } - - /** - * Test Border size. - * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. - */ - public function testBorderSize(): void - { - $parentWriter = new RTF(); - $style = new BorderStyle(); - $writer = new BorderWriter($style); - $writer->setParentWriter($parentWriter); - $style->setBorderStyle(BorderType::DASH_DOT_STROKED); $expect = '\brdrt\brdrdashdotstr\brdrcf0\brsp20 '; $expect .= '\brdrl\brdrdashdotstr\brdrcf0\brsp80 '; @@ -169,8 +140,8 @@ public function testBorderSize(): void $style->setBorderBottomStyle(BorderType::INSET); $expect = '\brdrt\brdrdot\brdrcf0\brsp20 '; $expect .= '\brdrl\brdrdb\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrdashd\brdrwavydb\brsp80 '; - $expect .= '\brdrb\brdrdashdd\brdrinset\brsp20 '; + $expect .= '\brdrr\brdrwavydb\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrinset\brdrcf0\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopStyle(BorderType::NIL); @@ -221,6 +192,35 @@ public function testBorderSize(): void self::assertEquals($expect, $this->removeCr($writer)); } + /** + * Test Border size. + * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + */ + public function testBorderSize(): void + { + $parentWriter = new RTF(); + $style = new BorderStyle(); + $writer = new BorderWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setBorderSize(100); + $expect = '\brdrt\brdrs\brdrw100\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrs\brdrw100\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrs\brdrw100\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrs\brdrw100\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setBorderTopSize(200); + $style->setBorderLeftSize(150); + $style->setBorderRightSize(50); + $style->setBorderBottomSize(20); + $expect = '\brdrt\brdrs\brdrw200\brdrcf0\brsp20 '; + $expect .= '\brdrl\brdrs\brdrw150\brdrcf0\brsp80 '; + $expect .= '\brdrr\brdrs\brdrw50\brdrcf0\brsp80 '; + $expect .= '\brdrb\brdrs\brdrw20\brdrcf0\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + } + /** * Test Border colors. * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. From 4dbd6dd991d5ead6ea4f579676872a1ef3060274 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 22:28:49 -0500 Subject: [PATCH 40/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index cac3cda104..84c18081f5 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -117,7 +117,7 @@ private function writeSide($side, $width, $color, $style, $space) BorderType::THIN_THICK_SMALL_GAP => '\brdrthtnsg', BorderType::THIN_THICK_THIN_LARGE_GAP => '\brdrtnthtnlg', BorderType::THIN_THICK_THIN_MEDIUM_GAP => '\brdrtnthtnmg', - BorderType::THIN_THICK_THIN_SMALL_GAP => '\brdrtnthtnmg', + BorderType::THIN_THICK_THIN_SMALL_GAP => '\brdrtnthtnsg', BorderType::THREE_D_EMBOSS => '\brdremboss', BorderType::THREE_D_ENGRAVE => '\brdrengrave', BorderType::TRIPLE => '\brdrtriple', From 66b75dcd307d6b7f71cb80fc50d10956f4e53b55 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 23:08:36 -0500 Subject: [PATCH 41/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 84c18081f5..ba983dba27 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -150,7 +150,7 @@ private function writeSide($side, $width, $color, $style, $space) } else { $content .= '\brdrs'; // default style } - $content .= $this->getValueIf($width !== null, '\brdrw' . round($width)); // Width + $content .= $this->getValueIf($width !== null, '\brdrw' . round($width ?? 0)); // Width $content .= '\brdrcf' . $colorIndex; // Color // Space From 1c2dff663b930d952a60d6e5859a67962818b3a1 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 18:14:35 -0500 Subject: [PATCH 42/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index ba983dba27..1c7803212b 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -86,6 +86,14 @@ public function write() */ private function writeSide($side, $width, $color, $style, $space) { + if ($side === null && $width == null && $color === null && $style === null) { + if ($this->type == 'font' || $this->type == 'row' || $this->type == 'cell') { + return ''; + } elseif ($space === null) { + return ''; + } + } + $types = [ 'section' => '\pgbrdr', 'paragraph' => '\brdr', @@ -151,21 +159,21 @@ private function writeSide($side, $width, $color, $style, $space) $content .= '\brdrs'; // default style } $content .= $this->getValueIf($width !== null, '\brdrw' . round($width ?? 0)); // Width - $content .= '\brdrcf' . $colorIndex; // Color + $content .= $this->getValueIf($color !== null, '\brdrcf' . $colorIndex); // Color // Space if ($this->type == 'section') { - $space = $space !== null ? $space : '480'; + $space = $space !== null ? $space : '480'; // section default is 480 } elseif ($this->type == 'paragraph') { if ($side == 'top' || $side == 'bottom') { - $space = $space !== null ? $space : '20'; + $space = $space !== null ? $space : '20'; // paragraph top|bottom default is 20 } elseif ($side == 'left' || $side == 'right') { - $space = $space !== null ? $space : '80'; + $space = $space !== null ? $space : '80'; // paragraph left|rigth default is 80 } + } else { + $space === null; // font|row|cell don't use space } - if (in_array($this->type, ['section', 'paragraph'])) { - $content .= $this->getValueIf($space !== null, '\brsp' . round($space ?? 0)); - } + $content .= $this->getValueIf($space !== null, '\brsp' . round($space ?? 0)); $content .= ' '; From 23c5f03ca50d66d202916e5bfc1c901efe5d210e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 18:16:39 -0500 Subject: [PATCH 43/51] Update Border.php --- src/PhpWord/Style/Border.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index 46f13d28ac..76d711dcdb 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -685,6 +685,9 @@ public function setBorderBottomSpace($value = null) public function hasBorder() { $borders = $this->getBorderSize(); + array_push($borders, $this->getBorderColor()); + array_push($borders, $this->getBorderStyle()); + array_push($borders, $this->getBorderSpace()); return $borders !== array_filter($borders, 'is_null'); } From 8d27ccf3817612c04ece50fbba8d7be2ef18cb8f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 18:27:14 -0500 Subject: [PATCH 44/51] Update Border.php --- src/PhpWord/Style/Border.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index 76d711dcdb..aa92ad386f 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -684,10 +684,7 @@ public function setBorderBottomSpace($value = null) */ public function hasBorder() { - $borders = $this->getBorderSize(); - array_push($borders, $this->getBorderColor()); - array_push($borders, $this->getBorderStyle()); - array_push($borders, $this->getBorderSpace()); + $borders = array_merge($this->getBorderSize(), $this->getBorderColor(), $this->getBorderStyle(), $this->getBorderSpace()); return $borders !== array_filter($borders, 'is_null'); } From 25784d323ab7519f54eaaf106be5af3db7f5a89f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 18:27:22 -0500 Subject: [PATCH 45/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 1c7803212b..7d532b51c8 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -93,7 +93,7 @@ private function writeSide($side, $width, $color, $style, $space) return ''; } } - + $types = [ 'section' => '\pgbrdr', 'paragraph' => '\brdr', From bf31cf4bacc660d2e2567780e75464c90aba8ee8 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 18:38:31 -0500 Subject: [PATCH 46/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 7d532b51c8..4b80baf24a 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -86,7 +86,7 @@ public function write() */ private function writeSide($side, $width, $color, $style, $space) { - if ($side === null && $width == null && $color === null && $style === null) { + if ($width == null && $color === null && $style === null) { if ($this->type == 'font' || $this->type == 'row' || $this->type == 'cell') { return ''; } elseif ($space === null) { From ff0410032d22d08345ec597b8ba0d3b9d8912c6f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 18:38:35 -0500 Subject: [PATCH 47/51] Update BorderTest.php --- .../Writer/RTF/Style/BorderTest.php | 156 +++++++++--------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php index d266ea1ec6..e38405f055 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php @@ -51,10 +51,10 @@ public function testBorderBasic(): void $writer = new BorderWriter($style); $writer->setParentWriter($parentWriter); - $expect = '\brdrt\brdrs\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrs\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrs\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrs\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrs\brsp20 '; + $expect .= '\brdrl\brdrs\brsp80 '; + $expect .= '\brdrr\brdrs\brsp80 '; + $expect .= '\brdrb\brdrs\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -74,35 +74,35 @@ public function testBorderType(): void $writer->setType('section'); $expect = '\pgbrdropt32'; - $expect .= '\pgbrdrt\brdrs\brdrcf0\brsp480 '; - $expect .= '\pgbrdrl\brdrs\brdrcf0\brsp480 '; - $expect .= '\pgbrdrr\brdrs\brdrcf0\brsp480 '; - $expect .= '\pgbrdrb\brdrs\brdrcf0\brsp480 '; + $expect .= '\pgbrdrt\brdrs\brsp480 '; + $expect .= '\pgbrdrl\brdrs\brsp480 '; + $expect .= '\pgbrdrr\brdrs\brsp480 '; + $expect .= '\pgbrdrb\brdrs\brsp480 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('paragraph'); - $expect = '\brdrt\brdrs\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrs\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrs\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrs\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrs\brsp20 '; + $expect .= '\brdrl\brdrs\brsp80 '; + $expect .= '\brdrr\brdrs\brsp80 '; + $expect .= '\brdrb\brdrs\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('font'); - $expect = '\chbrdr\brdrs\brdrcf0 '; + $expect = '\chbrdr\brdrs '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('row'); - $expect = '\trbrdrt\brdrs\brdrcf0 '; - $expect .= '\trbrdrl\brdrs\brdrcf0 '; - $expect .= '\trbrdrr\brdrs\brdrcf0 '; - $expect .= '\trbrdrb\brdrs\brdrcf0 '; + $expect = '\trbrdrt\brdrs '; + $expect .= '\trbrdrl\brdrs '; + $expect .= '\trbrdrr\brdrs '; + $expect .= '\trbrdrb\brdrs '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('cell'); - $expect = '\clbrdrt\brdrs\brdrcf0 '; - $expect .= '\clbrdrl\brdrs\brdrcf0 '; - $expect .= '\clbrdrr\brdrs\brdrcf0 '; - $expect .= '\clbrdrb\brdrs\brdrcf0 '; + $expect = '\clbrdrt\brdrs '; + $expect .= '\clbrdrl\brdrs '; + $expect .= '\clbrdrr\brdrs '; + $expect .= '\clbrdrb\brdrs '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -118,77 +118,77 @@ public function testBorderStyle(): void $writer->setParentWriter($parentWriter); $style->setBorderStyle(BorderType::DASH_DOT_STROKED); - $expect = '\brdrt\brdrdashdotstr\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrdashdotstr\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrdashdotstr\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrdashdotstr\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrdashdotstr\brsp20 '; + $expect .= '\brdrl\brdrdashdotstr\brsp80 '; + $expect .= '\brdrr\brdrdashdotstr\brsp80 '; + $expect .= '\brdrb\brdrdashdotstr\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopStyle(BorderType::DASHED); $style->setBorderLeftStyle(BorderType::DASH_SMALL_GAP); $style->setBorderRightStyle(BorderType::DOT_DASH); $style->setBorderBottomStyle(BorderType::DOT_DOT_DASH); - $expect = '\brdrt\brdrdash\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrdashsm\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrdashd\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrdashdd\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrdash\brsp20 '; + $expect .= '\brdrl\brdrdashsm\brsp80 '; + $expect .= '\brdrr\brdrdashd\brsp80 '; + $expect .= '\brdrb\brdrdashdd\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopStyle(BorderType::DOTTED); $style->setBorderLeftStyle(BorderType::DOUBLE); $style->setBorderRightStyle(BorderType::DOUBLE_WAVE); $style->setBorderBottomStyle(BorderType::INSET); - $expect = '\brdrt\brdrdot\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrdb\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrwavydb\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrinset\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrdot\brsp20 '; + $expect .= '\brdrl\brdrdb\brsp80 '; + $expect .= '\brdrr\brdrwavydb\brsp80 '; + $expect .= '\brdrb\brdrinset\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopStyle(BorderType::NIL); $style->setBorderLeftStyle(BorderType::NONE); $style->setBorderRightStyle(BorderType::OUTSET); $style->setBorderBottomStyle(BorderType::THICK); - $expect = '\brdrt\brdrnil\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrnone\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdroutset\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrth\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrnil\brsp20 '; + $expect .= '\brdrl\brdrnone\brsp80 '; + $expect .= '\brdrr\brdroutset\brsp80 '; + $expect .= '\brdrb\brdrth\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopStyle(BorderType::THICK_THIN_LARGE_GAP); $style->setBorderLeftStyle(BorderType::THICK_THIN_MEDIUM_GAP); $style->setBorderRightStyle(BorderType::THICK_THIN_SMALL_GAP); $style->setBorderBottomStyle(BorderType::THIN_THICK_LARGE_GAP); - $expect = '\brdrt\brdrtnthlg\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrtnthmg\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrtnthsg\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrthtnlg\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrtnthlg\brsp20 '; + $expect .= '\brdrl\brdrtnthmg\brsp80 '; + $expect .= '\brdrr\brdrtnthsg\brsp80 '; + $expect .= '\brdrb\brdrthtnlg\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopStyle(BorderType::THIN_THICK_MEDIUM_GAP); $style->setBorderLeftStyle(BorderType::THIN_THICK_SMALL_GAP); $style->setBorderRightStyle(BorderType::THIN_THICK_THIN_LARGE_GAP); $style->setBorderBottomStyle(BorderType::THIN_THICK_THIN_MEDIUM_GAP); - $expect = '\brdrt\brdrthtnmg\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrthtnsg\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrtnthtnlg\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrtnthtnmg\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrthtnmg\brsp20 '; + $expect .= '\brdrl\brdrthtnsg\brsp80 '; + $expect .= '\brdrr\brdrtnthtnlg\brsp80 '; + $expect .= '\brdrb\brdrtnthtnmg\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopStyle(BorderType::THIN_THICK_THIN_SMALL_GAP); $style->setBorderLeftStyle(BorderType::THREE_D_EMBOSS); $style->setBorderRightStyle(BorderType::THREE_D_ENGRAVE); $style->setBorderBottomStyle(BorderType::TRIPLE); - $expect = '\brdrt\brdrtnthtnsg\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdremboss\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrengrave\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrtriple\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrtnthtnsg\brsp20 '; + $expect .= '\brdrl\brdremboss\brsp80 '; + $expect .= '\brdrr\brdrengrave\brsp80 '; + $expect .= '\brdrb\brdrtriple\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderStyle(BorderType::WAVE); - $expect = '\brdrt\brdrwavy\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrwavy\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrwavy\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrwavy\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrwavy\brsp20 '; + $expect .= '\brdrl\brdrwavy\brsp80 '; + $expect .= '\brdrr\brdrwavy\brsp80 '; + $expect .= '\brdrb\brdrwavy\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -204,20 +204,20 @@ public function testBorderSize(): void $writer->setParentWriter($parentWriter); $style->setBorderSize(100); - $expect = '\brdrt\brdrs\brdrw100\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrs\brdrw100\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrs\brdrw100\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrs\brdrw100\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrs\brdrw100\brsp20 '; + $expect .= '\brdrl\brdrs\brdrw100\brsp80 '; + $expect .= '\brdrr\brdrs\brdrw100\brsp80 '; + $expect .= '\brdrb\brdrs\brdrw100\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopSize(200); $style->setBorderLeftSize(150); $style->setBorderRightSize(50); $style->setBorderBottomSize(20); - $expect = '\brdrt\brdrs\brdrw200\brdrcf0\brsp20 '; - $expect .= '\brdrl\brdrs\brdrw150\brdrcf0\brsp80 '; - $expect .= '\brdrr\brdrs\brdrw50\brdrcf0\brsp80 '; - $expect .= '\brdrb\brdrs\brdrw20\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrs\brdrw200\brsp20 '; + $expect .= '\brdrl\brdrs\brdrw150\brsp80 '; + $expect .= '\brdrr\brdrs\brdrw50\brsp80 '; + $expect .= '\brdrb\brdrs\brdrw20\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -240,40 +240,40 @@ public function testBorderSpace(): void $writer->setParentWriter($parentWriter); $style->setBorderSpace(100); - $expect = '\brdrt\brdrs\brdrcf0\brsp100 '; - $expect .= '\brdrl\brdrs\brdrcf0\brsp100 '; - $expect .= '\brdrr\brdrs\brdrcf0\brsp100 '; - $expect .= '\brdrb\brdrs\brdrcf0\brsp100 '; + $expect = '\brdrt\brdrs\brsp100 '; + $expect .= '\brdrl\brdrs\brsp100 '; + $expect .= '\brdrr\brdrs\brsp100 '; + $expect .= '\brdrb\brdrs\brsp100 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setBorderTopSpace(200); $style->setBorderLeftSpace(150); $style->setBorderRightSpace(50); $style->setBorderBottomSpace(20); - $expect = '\brdrt\brdrs\brdrcf0\brsp200 '; - $expect .= '\brdrl\brdrs\brdrcf0\brsp150 '; - $expect .= '\brdrr\brdrs\brdrcf0\brsp50 '; - $expect .= '\brdrb\brdrs\brdrcf0\brsp20 '; + $expect = '\brdrt\brdrs\brsp200 '; + $expect .= '\brdrl\brdrs\brsp150 '; + $expect .= '\brdrr\brdrs\brsp50 '; + $expect .= '\brdrb\brdrs\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('font'); - $expect = '\chbrdr\brdrs\brdrcf0 '; + $expect = '\chbrdr\brdrs '; self::assertEquals($expect, $this->removeCr($writer)); // Technically rows can have space, but it messes up the table drawing - margin/padding should be used instead. $writer->setType('row'); - $expect = '\trbrdrt\brdrs\brdrcf0 '; - $expect .= '\trbrdrl\brdrs\brdrcf0 '; - $expect .= '\trbrdrr\brdrs\brdrcf0 '; - $expect .= '\trbrdrb\brdrs\brdrcf0 '; + $expect = '\trbrdrt\brdrs '; + $expect .= '\trbrdrl\brdrs '; + $expect .= '\trbrdrr\brdrs '; + $expect .= '\trbrdrb\brdrs '; self::assertEquals($expect, $this->removeCr($writer)); // Technically cells can have space, but it messes up the table drawing - margin/padding should be used instead. $writer->setType('cell'); - $expect = '\clbrdrt\brdrs\brdrcf0 '; - $expect .= '\clbrdrl\brdrs\brdrcf0 '; - $expect .= '\clbrdrr\brdrs\brdrcf0 '; - $expect .= '\clbrdrb\brdrs\brdrcf0 '; + $expect = '\clbrdrt\brdrs '; + $expect .= '\clbrdrl\brdrs '; + $expect .= '\clbrdrr\brdrs '; + $expect .= '\clbrdrb\brdrs '; self::assertEquals($expect, $this->removeCr($writer)); } } From a81cbefaa936ab552c7b68089ddedde32aedb342 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 19:13:04 -0500 Subject: [PATCH 48/51] Update BorderTest.php --- .../Writer/RTF/Style/BorderTest.php | 86 ++++++++++++------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php index e38405f055..b1f2837c44 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/BorderTest.php @@ -51,10 +51,35 @@ public function testBorderBasic(): void $writer = new BorderWriter($style); $writer->setParentWriter($parentWriter); - $expect = '\brdrt\brdrs\brsp20 '; - $expect .= '\brdrl\brdrs\brsp80 '; - $expect .= '\brdrr\brdrs\brsp80 '; - $expect .= '\brdrb\brdrs\brsp20 '; + $expect = ''; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setBorderSize(1); + $expect = '\brdrt\brdrs\brdrw1\brsp20 '; + $expect .= '\brdrl\brdrs\brdrw1\brsp80 '; + $expect .= '\brdrr\brdrs\brdrw1\brsp80 '; + $expect .= '\brdrb\brdrs\brdrw1\brsp20 '; + self::assertEquals($expect, $this->removeCr($writer)); + } + + /** + * Test Border not all all four sides. + * See page 89-90 of RTF Specification 1.9.1 for Paragraph Borders. + */ + public function testBorderSide(): void + { + $parentWriter = new RTF(); + $style = new BorderStyle(); + $writer = new BorderWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setBorderLeftSize(1); + $expect = '\brdrl\brdrs\brdrw1\brsp80 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setBorderBottomSize(100); + $expect = '\brdrl\brdrs\brdrw1\brsp80 '; + $expect .= '\brdrb\brdrs\brdrw100\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -72,37 +97,39 @@ public function testBorderType(): void $writer = new BorderWriter($style); $writer->setParentWriter($parentWriter); + $style->setBorderSize(1); + $writer->setType('section'); $expect = '\pgbrdropt32'; - $expect .= '\pgbrdrt\brdrs\brsp480 '; - $expect .= '\pgbrdrl\brdrs\brsp480 '; - $expect .= '\pgbrdrr\brdrs\brsp480 '; - $expect .= '\pgbrdrb\brdrs\brsp480 '; + $expect .= '\pgbrdrt\brdrs\brdrw1\brsp480 '; + $expect .= '\pgbrdrl\brdrs\brdrw1\brsp480 '; + $expect .= '\pgbrdrr\brdrs\brdrw1\brsp480 '; + $expect .= '\pgbrdrb\brdrs\brdrw1\brsp480 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('paragraph'); - $expect = '\brdrt\brdrs\brsp20 '; - $expect .= '\brdrl\brdrs\brsp80 '; - $expect .= '\brdrr\brdrs\brsp80 '; - $expect .= '\brdrb\brdrs\brsp20 '; + $expect = '\brdrt\brdrs\brdrw1\brsp20 '; + $expect .= '\brdrl\brdrs\brdrw1\brsp80 '; + $expect .= '\brdrr\brdrs\brdrw1\brsp80 '; + $expect .= '\brdrb\brdrs\brdrw1\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('font'); - $expect = '\chbrdr\brdrs '; + $expect = '\chbrdr\brdrs\brdrw1 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('row'); - $expect = '\trbrdrt\brdrs '; - $expect .= '\trbrdrl\brdrs '; - $expect .= '\trbrdrr\brdrs '; - $expect .= '\trbrdrb\brdrs '; + $expect = '\trbrdrt\brdrs\brdrw1 '; + $expect .= '\trbrdrl\brdrs\brdrw1 '; + $expect .= '\trbrdrr\brdrs\brdrw1 '; + $expect .= '\trbrdrb\brdrs\brdrw1 '; self::assertEquals($expect, $this->removeCr($writer)); $writer->setType('cell'); - $expect = '\clbrdrt\brdrs '; - $expect .= '\clbrdrl\brdrs '; - $expect .= '\clbrdrr\brdrs '; - $expect .= '\clbrdrb\brdrs '; + $expect = '\clbrdrt\brdrs\brdrw1 '; + $expect .= '\clbrdrl\brdrs\brdrw1 '; + $expect .= '\clbrdrr\brdrs\brdrw1 '; + $expect .= '\clbrdrb\brdrs\brdrw1 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -256,24 +283,19 @@ public function testBorderSpace(): void $expect .= '\brdrb\brdrs\brsp20 '; self::assertEquals($expect, $this->removeCr($writer)); + // Space doesn't matter for fonts. $writer->setType('font'); - $expect = '\chbrdr\brdrs '; + $expect = ''; self::assertEquals($expect, $this->removeCr($writer)); - // Technically rows can have space, but it messes up the table drawing - margin/padding should be used instead. + // Space doesn't matter for rows. $writer->setType('row'); - $expect = '\trbrdrt\brdrs '; - $expect .= '\trbrdrl\brdrs '; - $expect .= '\trbrdrr\brdrs '; - $expect .= '\trbrdrb\brdrs '; + $expect = ''; self::assertEquals($expect, $this->removeCr($writer)); - // Technically cells can have space, but it messes up the table drawing - margin/padding should be used instead. + // Space doesn't matter for cells. $writer->setType('cell'); - $expect = '\clbrdrt\brdrs '; - $expect .= '\clbrdrl\brdrs '; - $expect .= '\clbrdrr\brdrs '; - $expect .= '\clbrdrb\brdrs '; + $expect = ''; self::assertEquals($expect, $this->removeCr($writer)); } } From 2b44c72cbe509482d650268eb9e47b8069bf109e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 19:17:31 -0500 Subject: [PATCH 49/51] Update Border.php --- src/PhpWord/Writer/RTF/Style/Border.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 4b80baf24a..a2b5c7695c 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -170,8 +170,6 @@ private function writeSide($side, $width, $color, $style, $space) } elseif ($side == 'left' || $side == 'right') { $space = $space !== null ? $space : '80'; // paragraph left|rigth default is 80 } - } else { - $space === null; // font|row|cell don't use space } $content .= $this->getValueIf($space !== null, '\brsp' . round($space ?? 0)); From 0306bcc0436bbabda63148c8985a47416e482526 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 19:21:34 -0500 Subject: [PATCH 50/51] 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 5b77ac31f4..d7f2290238 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: Improve Borders, add missing features, and prepare for future uses by [@rasamassen](https://github.com/rasamassen) in [#2838](https://github.com/PHPOffice/PHPWord/pull/2838) +- Writer RTF: Border - Improve add missing features, also adds spaces to Styles > Border and fixes hasBorder to check all border variables by [@rasamassen](https://github.com/rasamassen) in [#2838](https://github.com/PHPOffice/PHPWord/pull/2838) ### Miscellaneous From ac5c42290d28b2458b2abf4f8f3f180d13eb5b75 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 8 Oct 2025 23:37:32 -0500 Subject: [PATCH 51/51] Update StyleTest.php --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 253bfdef97..ceeae5ee19 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -51,27 +51,6 @@ public function testEmptyStyles(): void } } - public function testBorderWithNonRegisteredColors(): void - { - $border = new \PhpOffice\PhpWord\Style\Border(); - $border->setBorderSize(40); - $border->setBorderTopSize(20); - $border->setBorderColor('#FF0000'); - $borderWriter = new RTF\Style\Border($border); - $borderWriter->setParentWriter(new RTF()); - $borderWriter->setType('section'); - - $content = $borderWriter->write(); - - $expected = '\pgbrdropt32'; - $expected .= '\pgbrdrt\brdrs\brdrw20\brdrcf0\brsp480 '; - $expected .= '\pgbrdrl\brdrs\brdrw40\brdrcf0\brsp480 '; - $expected .= '\pgbrdrr\brdrs\brdrw40\brdrcf0\brsp480 '; - $expected .= '\pgbrdrb\brdrs\brdrw40\brdrcf0\brsp480 '; - - self::assertEquals($expected, $content); - } - public function testIndentation(): void { $indentation = new \PhpOffice\PhpWord\Style\Indentation();