From 050d393fa52b9d06e11bd572d4effbdb96c34319 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 10:39:08 -0500 Subject: [PATCH 01/83] Update AbstractElement.php - fgColor and bgColor In combination with next edit... Sets the fgColor and bgColor according to the colorTable. --- src/PhpWord/Writer/RTF/Element/AbstractElement.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/PhpWord/Writer/RTF/Element/AbstractElement.php b/src/PhpWord/Writer/RTF/Element/AbstractElement.php index e007e6aa26..cb5ecba009 100644 --- a/src/PhpWord/Writer/RTF/Element/AbstractElement.php +++ b/src/PhpWord/Writer/RTF/Element/AbstractElement.php @@ -200,6 +200,18 @@ protected function writeFontStyle() $styleWriter->setColorIndex($colorIndex + 1); } } + if ($this->fontStyle->getFgColor() != null) { + $colorIndex = array_search($this->fontStyle->getFgColor(), $parentWriter->getColorTable()); + if ($colorIndex !== false) { + $styleWriter->setFgColorIndex($colorIndex + 1); + } + } + if ($this->fontStyle->getBgColor() != null) { + $colorIndex = array_search($this->fontStyle->getBgColor(), $parentWriter->getColorTable()); + if ($colorIndex !== false) { + $styleWriter->setBgColorIndex($colorIndex + 1); + } + } if ($this->fontStyle->getName() != null) { $fontIndex = array_search($this->fontStyle->getName(), $parentWriter->getFontTable()); if ($fontIndex !== false) { From 5f97167adb0b2e95d99fbf5ed5549207d0182b2d Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 10:48:11 -0500 Subject: [PATCH 02/83] Update Font.php - add many missing features Adds underline styles, doublestrikethrough, smallcaps, allcaps, fgcolor, hidden, scall, spacing, kerning, position, noproof, and bgcolor. --- src/PhpWord/Writer/RTF/Style/Font.php | 86 +++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 6 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index f343c0502f..4c4232a37d 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -37,6 +37,16 @@ class Font extends AbstractStyle */ private $colorIndex = 0; + /** + * @var int Font foreground color index + */ + private $fgColorIndex = 0; + + /** + * @var int Font background color index + */ + private $bgColorIndex = 0; + /** * Write style. * @@ -50,19 +60,63 @@ public function write() } $content = ''; - $content .= $this->getValueIf($style->isRTL(), '\rtlch'); - $content .= '\cf' . $this->colorIndex; - $content .= '\f' . $this->nameIndex; - $size = $style->getSize(); - $content .= $this->getValueIf(is_numeric($size), '\fs' . round($size * 2)); + // To make it easy to determine what's missing as new features are added, + // Everything below is in the same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues + + // Basic + $content .= $this->getValueIf($style->getName() !== null, '\f' . $this->nameIndex); + $content .= $this->getValueIf($style->getSize() !== null, '\fs' . round($style->getSize() * 2)); + $content .= $this->getValueIf($style->getColor() !== null, '\cf' . $this->colorIndex); + // Underline Keywords + $underlines = [ + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASH => '\uldash', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHHEAVY => '\ulth', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONG => '\ulldash', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONGHEAVY => '\ulthldash', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOUBLE => '\uldb', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASH => '\uldashd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASHHEAVY => '\ulthdashd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASH => '\uldashdd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASHHEAVY => '\ulthdashdd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTED => '\uld', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTEDHEAVY => '\ulthd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_HEAVY => '\ulth', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE => '\ul', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVY => '\ulwave', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYDOUBLE => '\ululdbwave', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYHEAVY => '\ulhwave', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_WORDS => '\ulw', + ]; + + // Style $content .= $this->getValueIf($style->isBold(), '\b'); $content .= $this->getValueIf($style->isItalic(), '\i'); - $content .= $this->getValueIf($style->getUnderline() != FontStyle::UNDERLINE_NONE, '\ul'); + if (isset($underlines[$style->getUnderline()])) { + $content .= $underlines[$style->getUnderline()]; + } $content .= $this->getValueIf($style->isStrikethrough(), '\strike'); + $content .= $this->getValueIf($style->isDoubleStrikethrough(), '\striked1'); $content .= $this->getValueIf($style->isSuperScript(), '\super'); $content .= $this->getValueIf($style->isSubScript(), '\sub'); + $content .= $this->getValueIf($style->isSmallCaps(), '\scaps'); + $content .= $this->getValueIf($style->isAllCaps(), '\caps'); + $content .= $this->getValueIf($style->getFgColor() !== null, '\highlight' . $this->fgColorIndex); + $content .= $this->getValueIf($style->isHidden(), '\v'); + + // Spacing + $content .= $this->getValueIf($style->getScale() !== null, '\charscalex' . $style->getScale()); + $content .= $this->getValueIf($style->getSpacing() !== null, '\expnd' . $style->getSpacing()); + $content .= $this->getValueIf($style->getKerning() !== null, '\kerning' . $style->getKerning() * 2); + $content .= $this->getValueIf($style->getPosition() !== null, '\up' . $style->getPosition()); + + // General + $content .= $this->getValueIf($style->isRTL(), '\rtlch'); + + // Other (Font settings currently not in included in array) + $content .= $this->getValueIf($style->isNoProof(), '\noproof'); + $content .= $this->getValueIf($style->getBgColor() !== null, '\cb' . $this->bgColorIndex); return $content . ' '; } @@ -86,4 +140,24 @@ public function setColorIndex($value = 0): void { $this->colorIndex = $value; } + + /** + * Set font foreground color index. + * + * @param int $value + */ + public function setFgColorIndex($value = 0): void + { + $this->fgColorIndex = $value; + } + + /** + * Set font background color index. + * + * @param int $value + */ + public function setBgColorIndex($value = 0): void + { + $this->bgColorIndex = $value; + } } From c12ed05f1c5d0f46e181bd78cea89d89473180df Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 19:05:54 -0500 Subject: [PATCH 03/83] Update Font.php - Fix Extra Space Now that Font isn't returning unnecessary values, it could sometimes occur where it returned an extra space in the document if ($content == ''). This is fixed. --- src/PhpWord/Writer/RTF/Style/Font.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 4c4232a37d..6566fd3e2a 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -117,6 +117,10 @@ public function write() // Other (Font settings currently not in included in array) $content .= $this->getValueIf($style->isNoProof(), '\noproof'); $content .= $this->getValueIf($style->getBgColor() !== null, '\cb' . $this->bgColorIndex); + + if (empty($content)) { + return $content; + } return $content . ' '; } From 9c1618f25232e7e63b60a777fe6e80ab402fed8a Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 22:04:00 -0500 Subject: [PATCH 04/83] Update Font.php - Fix formatting --- src/PhpWord/Writer/RTF/Style/Font.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 6566fd3e2a..cb57a784c8 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -113,11 +113,11 @@ public function write() // General $content .= $this->getValueIf($style->isRTL(), '\rtlch'); - + // Other (Font settings currently not in included in array) $content .= $this->getValueIf($style->isNoProof(), '\noproof'); $content .= $this->getValueIf($style->getBgColor() !== null, '\cb' . $this->bgColorIndex); - + if (empty($content)) { return $content; } From e8a11015fe48547f8d886066a5ae4b72666b3563 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 22:05:44 -0500 Subject: [PATCH 05/83] Update 1.5.0.md - Changelog for Pull 2819 --- 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..a3f1b074fa 100644 --- a/docs/changes/1.x/1.5.0.md +++ b/docs/changes/1.x/1.5.0.md @@ -7,6 +7,7 @@ ### Bug fixes - Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776) +- Writer RTF: Support for various underline styles, doublestrikethrough, smallcaps, allcaps, fgcolor, hidden, scale, spacing, kerning, position, noproof, and bgcolor in Font by [@rasamassen](https://github.com/rasamassen) in [#2819](https://github.com/PHPOffice/PHPWord/pull/2819) ### Miscellaneous @@ -16,4 +17,4 @@ ### BC Breaks -### Notes \ No newline at end of file +### Notes From 86a990ce8dd06659c4e2e7a5a46e795875fca71f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 22:31:53 -0500 Subject: [PATCH 06/83] Update Font.php - Fix formatting --- src/PhpWord/Writer/RTF/Style/Font.php | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index cb57a784c8..d2da0927ad 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -63,7 +63,7 @@ public function write() // To make it easy to determine what's missing as new features are added, // Everything below is in the same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues - + // Basic $content .= $this->getValueIf($style->getName() !== null, '\f' . $this->nameIndex); $content .= $this->getValueIf($style->getSize() !== null, '\fs' . round($style->getSize() * 2)); @@ -71,23 +71,23 @@ public function write() // Underline Keywords $underlines = [ - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASH => '\uldash', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHHEAVY => '\ulth', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONG => '\ulldash', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONGHEAVY => '\ulthldash', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOUBLE => '\uldb', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASH => '\uldashd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASHHEAVY => '\ulthdashd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASH => '\uldashdd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASHHEAVY => '\ulthdashdd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTED => '\uld', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTEDHEAVY => '\ulthd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_HEAVY => '\ulth', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE => '\ul', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVY => '\ulwave', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYDOUBLE => '\ululdbwave', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYHEAVY => '\ulhwave', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_WORDS => '\ulw', + Font::UNDERLINE_DASH => '\uldash', + Font::UNDERLINE_DASHHEAVY => '\ulth', + Font::UNDERLINE_DASHLONG => '\ulldash', + Font::UNDERLINE_DASHLONGHEAVY => '\ulthldash', + Font::UNDERLINE_DOUBLE => '\uldb', + Font::UNDERLINE_DOTDASH => '\uldashd', + Font::UNDERLINE_DOTDASHHEAVY => '\ulthdashd', + Font::UNDERLINE_DOTDOTDASH => '\uldashdd', + Font::UNDERLINE_DOTDOTDASHHEAVY => '\ulthdashdd', + Font::UNDERLINE_DOTTED => '\uld', + Font::UNDERLINE_DOTTEDHEAVY => '\ulthd', + Font::UNDERLINE_HEAVY => '\ulth', + Font::UNDERLINE_SINGLE => '\ul', + Font::UNDERLINE_WAVY => '\ulwave', + Font::UNDERLINE_WAVYDOUBLE => '\ululdbwave', + Font::UNDERLINE_WAVYHEAVY => '\ulhwave', + Font::UNDERLINE_WORDS => '\ulw', ]; // Style From fb17d4145278d79881c341c4c5312702e2ad8e8b Mon Sep 17 00:00:00 2001 From: rasamassen Date: Mon, 1 Sep 2025 22:35:05 -0500 Subject: [PATCH 07/83] Update Font.php - Revert previous commit --- src/PhpWord/Writer/RTF/Style/Font.php | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index d2da0927ad..b2bbff2716 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -71,23 +71,23 @@ public function write() // Underline Keywords $underlines = [ - Font::UNDERLINE_DASH => '\uldash', - Font::UNDERLINE_DASHHEAVY => '\ulth', - Font::UNDERLINE_DASHLONG => '\ulldash', - Font::UNDERLINE_DASHLONGHEAVY => '\ulthldash', - Font::UNDERLINE_DOUBLE => '\uldb', - Font::UNDERLINE_DOTDASH => '\uldashd', - Font::UNDERLINE_DOTDASHHEAVY => '\ulthdashd', - Font::UNDERLINE_DOTDOTDASH => '\uldashdd', - Font::UNDERLINE_DOTDOTDASHHEAVY => '\ulthdashdd', - Font::UNDERLINE_DOTTED => '\uld', - Font::UNDERLINE_DOTTEDHEAVY => '\ulthd', - Font::UNDERLINE_HEAVY => '\ulth', - Font::UNDERLINE_SINGLE => '\ul', - Font::UNDERLINE_WAVY => '\ulwave', - Font::UNDERLINE_WAVYDOUBLE => '\ululdbwave', - Font::UNDERLINE_WAVYHEAVY => '\ulhwave', - Font::UNDERLINE_WORDS => '\ulw', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASH => '\uldash', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHHEAVY => '\ulth', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONG => '\ulldash', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONGHEAVY => '\ulthldash', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOUBLE => '\uldb', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASH => '\uldashd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASHHEAVY => '\ulthdashd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASH => '\uldashdd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASHHEAVY => '\ulthdashdd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTED => '\uld', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTEDHEAVY => '\ulthd', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_HEAVY => '\ulth', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE => '\ul', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVY => '\ulwave', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYDOUBLE => '\ululdbwave', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYHEAVY => '\ulhwave', + \PhpOffice\PhpWord\Style\Font::UNDERLINE_WORDS => '\ulw', ]; // Style From 710bdfb1c85ab0d5dc2976f4984c72b68e96de73 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 2 Sep 2025 19:34:16 -0500 Subject: [PATCH 08/83] Update AbstractElement.php - Fix binary operation error In these cases, the array_search should always return an integer, but because the php static analysis tests didn't like the chance that it might return a string, let's explicitly cast the variable as an integer. --- src/PhpWord/Writer/RTF/Element/AbstractElement.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Element/AbstractElement.php b/src/PhpWord/Writer/RTF/Element/AbstractElement.php index cb5ecba009..4c7b6d795c 100644 --- a/src/PhpWord/Writer/RTF/Element/AbstractElement.php +++ b/src/PhpWord/Writer/RTF/Element/AbstractElement.php @@ -197,25 +197,25 @@ protected function writeFontStyle() if ($this->fontStyle->getColor() != null) { $colorIndex = array_search($this->fontStyle->getColor(), $parentWriter->getColorTable()); if ($colorIndex !== false) { - $styleWriter->setColorIndex($colorIndex + 1); + $styleWriter->setColorIndex((int)$colorIndex + 1); } } if ($this->fontStyle->getFgColor() != null) { $colorIndex = array_search($this->fontStyle->getFgColor(), $parentWriter->getColorTable()); if ($colorIndex !== false) { - $styleWriter->setFgColorIndex($colorIndex + 1); + $styleWriter->setFgColorIndex((int)$colorIndex + 1); } } if ($this->fontStyle->getBgColor() != null) { $colorIndex = array_search($this->fontStyle->getBgColor(), $parentWriter->getColorTable()); if ($colorIndex !== false) { - $styleWriter->setBgColorIndex($colorIndex + 1); + $styleWriter->setBgColorIndex((int)$colorIndex + 1); } } if ($this->fontStyle->getName() != null) { $fontIndex = array_search($this->fontStyle->getName(), $parentWriter->getFontTable()); if ($fontIndex !== false) { - $styleWriter->setNameIndex($fontIndex); + $styleWriter->setNameIndex((int)$fontIndex); } } From d9d2176ac3016a0d6676be08f4054ec8568c6329 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 5 Sep 2025 15:25:42 -0500 Subject: [PATCH 09/83] Update AbstractElement.php - Address CS Fixer issues --- src/PhpWord/Writer/RTF/Element/AbstractElement.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Element/AbstractElement.php b/src/PhpWord/Writer/RTF/Element/AbstractElement.php index 4c7b6d795c..b6d9d91994 100644 --- a/src/PhpWord/Writer/RTF/Element/AbstractElement.php +++ b/src/PhpWord/Writer/RTF/Element/AbstractElement.php @@ -197,25 +197,25 @@ protected function writeFontStyle() if ($this->fontStyle->getColor() != null) { $colorIndex = array_search($this->fontStyle->getColor(), $parentWriter->getColorTable()); if ($colorIndex !== false) { - $styleWriter->setColorIndex((int)$colorIndex + 1); + $styleWriter->setColorIndex((int) $colorIndex + 1); } } if ($this->fontStyle->getFgColor() != null) { $colorIndex = array_search($this->fontStyle->getFgColor(), $parentWriter->getColorTable()); if ($colorIndex !== false) { - $styleWriter->setFgColorIndex((int)$colorIndex + 1); + $styleWriter->setFgColorIndex((int) $colorIndex + 1); } } if ($this->fontStyle->getBgColor() != null) { $colorIndex = array_search($this->fontStyle->getBgColor(), $parentWriter->getColorTable()); if ($colorIndex !== false) { - $styleWriter->setBgColorIndex((int)$colorIndex + 1); + $styleWriter->setBgColorIndex((int) $colorIndex + 1); } } if ($this->fontStyle->getName() != null) { $fontIndex = array_search($this->fontStyle->getName(), $parentWriter->getFontTable()); if ($fontIndex !== false) { - $styleWriter->setNameIndex((int)$fontIndex); + $styleWriter->setNameIndex((int) $fontIndex); } } From 2ddc15125fc42befd51dbc9e4f5de9f17fb6bfed Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 08:46:40 -0500 Subject: [PATCH 10/83] Update StyleTest.php - Remove \\cf0 --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 8ba2bcb9c9..3b0731f1f9 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -126,7 +126,7 @@ public function testRTL(): void $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\Text('אב גד', ['RTL' => true]); $text = new RTF\Element\Text($parentWriter, $element); - $expect = "\\pard\\nowidctlpar {\\rtlch\\cf0\\f0 \\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n"; + $expect = "\\pard\\nowidctlpar {\\rtlch\\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n"; self::assertEquals($expect, $this->removeCr($text)); } @@ -136,7 +136,7 @@ public function testRTL2(): void $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\Text('אב גד'); $text = new RTF\Element\Text($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\qr{\\rtlch\\cf0\\f0 \\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n"; + $expect = "\\pard\\nowidctlpar \\qr{\\rtlch\\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n"; self::assertEquals($expect, $this->removeCr($text)); } @@ -145,7 +145,7 @@ public function testPageBreakLineHeight(): void $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\Text('New page', null, ['lineHeight' => 1.08, 'pageBreakBefore' => true]); $text = new RTF\Element\Text($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\sl259\\slmult1\\page{\\cf0\\f0 New page}\\par\n"; + $expect = "\\pard\\nowidctlpar \\sl259\\slmult1\\page{New page}\\par\n"; self::assertEquals($expect, $this->removeCr($text)); } @@ -155,7 +155,7 @@ public function testPageBreakLineHeight2(): void $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\Text('New page', null, ['lineHeight' => 1.08, 'pageBreakBefore' => true]); $text = new RTF\Element\Text($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\ql\\sl259\\slmult1\\page{\\cf0\\f0 New page}\\par\n"; + $expect = "\\pard\\nowidctlpar \\ql\\sl259\\slmult1\\page{New page}\\par\n"; self::assertEquals($expect, $this->removeCr($text)); } From 77d48cebfc93d5744dc5dcf827ade3ce3cdc18b5 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 08:47:56 -0500 Subject: [PATCH 11/83] Update Element2Test.php - Remove \\cf0\\f0 --- tests/PhpWordTests/Writer/RTF/Element2Test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Element2Test.php b/tests/PhpWordTests/Writer/RTF/Element2Test.php index 2220d93b68..c293967806 100644 --- a/tests/PhpWordTests/Writer/RTF/Element2Test.php +++ b/tests/PhpWordTests/Writer/RTF/Element2Test.php @@ -47,7 +47,7 @@ public function testTextRun(): void $element->addText('Hello '); $element->addText('there.'); $textrun = new WriterTextRun($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\ql{{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n"; + $expect = "\\pard\\nowidctlpar \\ql{{Hello }{there.}}\\par\n"; self::assertEquals($expect, $this->removeCr($textrun)); } @@ -59,7 +59,7 @@ public function testTextRunParagraphStyle(): void $element->addText('Hello '); $element->addText('there.'); $textrun = new WriterTextRun($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\ql\\sb0\\sa0{{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n"; + $expect = "\\pard\\nowidctlpar \\ql\\sb0\\sa0{{Hello }{there.}}\\par\n"; self::assertEquals($expect, $this->removeCr($textrun)); } @@ -72,7 +72,7 @@ public function testTitle(): void $section = $phpWord->addSection(); $element = $section->addTitle('First Heading', 1); $elwrite = new WriterTitle($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\ql\\sb0\\sa0{\\outlinelevel0{\\cf0\\f0 First Heading}\\par\n}"; + $expect = "\\pard\\nowidctlpar \\ql\\sb0\\sa0{\\outlinelevel0{First Heading}\\par\n}"; self::assertEquals($expect, $this->removeCr($elwrite)); Settings::setDefaultRtl(null); } From f77213ecacabace2c6315ea8deab232f5a041a42 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 08:48:40 -0500 Subject: [PATCH 12/83] Update TableTest.php - Remove \\cf0\\f0 --- .../PhpWordTests/Writer/RTF/Element/TableTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Element/TableTest.php b/tests/PhpWordTests/Writer/RTF/Element/TableTest.php index 7c1ceac68e..ecd5f7b0ea 100644 --- a/tests/PhpWordTests/Writer/RTF/Element/TableTest.php +++ b/tests/PhpWordTests/Writer/RTF/Element/TableTest.php @@ -59,18 +59,18 @@ public function testTable(): void '\\pard', "\\trowd \\cellx$width \\cellx$width2 ", '\\intbl', - '\\ql{\\cf0\\f0 1}\\par', + '\\ql{1}\\par', '\\cell', '\\intbl', - '{\\cf0\\f0 2}\\par', + '{2}\\par', '\\cell', '\\row', "\\trowd \\cellx$width \\cellx$width2 ", '\\intbl', - '\\ql{\\cf0\\f0 3}\\par', + '\\ql{3}\\par', '\\cell', '\\intbl', - '{\\cf0\\f0 4}\par', + '{4}\par', '\\cell', '\\row', '\\pard', @@ -102,7 +102,7 @@ public function testTableStyle(): void '\\clbrdrr\\brdrs\\brdrw2\\brdrcf0', "\\cellx$width ", '\\intbl', - '\\ql{\\cf0\\f0 1}\\par', + '\\ql{1}\\par', '\\cell', '\\row', '\\pard', @@ -128,7 +128,7 @@ public function testTableStyleNotExisting(): void '\\pard', "\\trowd \\cellx$width ", '\\intbl', - '\\ql{\\cf0\\f0 1}\\par', + '\\ql{1}\\par', '\\cell', '\\row', '\\pard', @@ -158,7 +158,7 @@ public function testTableCellStyle(): void '\\clbrdrr\\brdrdot\\brdrw2\\brdrcf0', "\\cellx$width ", '\\intbl', - '\\ql{\\cf0\\f0 1}\\par', + '\\ql{1}\\par', '\\cell', '\\row', '\\pard', From f089e4de804a43c4c2ec5d52dece65543b73e2db Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 08:50:49 -0500 Subject: [PATCH 13/83] Create FontTest.php - Create FontTest --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/PhpWordTests/Writer/RTF/Style/FontTest.php diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -0,0 +1 @@ + From d7fd8913685cd01f8d0d9259bc53d33ec63a1394 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 08:56:51 -0500 Subject: [PATCH 14/83] Update StyleTest.php - Fix test --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index 3b0731f1f9..ca0e0eca25 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -126,7 +126,7 @@ public function testRTL(): void $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\Text('אב גד', ['RTL' => true]); $text = new RTF\Element\Text($parentWriter, $element); - $expect = "\\pard\\nowidctlpar {\\rtlch\\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n"; + $expect = "\\pard\\nowidctlpar {\\rtlch \\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n"; self::assertEquals($expect, $this->removeCr($text)); } @@ -136,7 +136,7 @@ public function testRTL2(): void $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\Text('אב גד'); $text = new RTF\Element\Text($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\qr{\\rtlch\\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n"; + $expect = "\\pard\\nowidctlpar \\qr{\\rtlch \\uc0{\\u1488}\\uc0{\\u1489} \\uc0{\\u1490}\\uc0{\\u1491}}\\par\n"; self::assertEquals($expect, $this->removeCr($text)); } From bc3d139080de5d54b976612bd4b4243348c7d55f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 08:58:48 -0500 Subject: [PATCH 15/83] Update ElementTest.php - Fix tests --- tests/PhpWordTests/Writer/RTF/ElementTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/ElementTest.php b/tests/PhpWordTests/Writer/RTF/ElementTest.php index 36504a18f8..be12c1655b 100644 --- a/tests/PhpWordTests/Writer/RTF/ElementTest.php +++ b/tests/PhpWordTests/Writer/RTF/ElementTest.php @@ -149,7 +149,7 @@ public function testTextRun(): void $element->addText('Hello '); $element->addText('there.'); $textrun = new RTF\Element\TextRun($parentWriter, $element); - $expect = "\\pard\\nowidctlpar {{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n"; + $expect = "\\pard\\nowidctlpar {{Hello }{there.}}\\par\n"; self::assertEquals($expect, $this->removeCr($textrun)); } @@ -160,7 +160,7 @@ public function testTextRunParagraphStyle(): void $element->addText('Hello '); $element->addText('there.'); $textrun = new RTF\Element\TextRun($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\sb0\\sa0{{\\cf0\\f0 Hello }{\\cf0\\f0 there.}}\\par\n"; + $expect = "\\pard\\nowidctlpar \\sb0\\sa0{{Hello }{there.}}\\par\n"; self::assertEquals($expect, $this->removeCr($textrun)); } @@ -172,7 +172,7 @@ public function testTitle(): void $section = $phpWord->addSection(); $element = $section->addTitle('First Heading', 1); $elwrite = new RTF\Element\Title($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\sb0\\sa0{\\outlinelevel0{\\cf0\\f0 First Heading}\\par\n}"; + $expect = "\\pard\\nowidctlpar \\sb0\\sa0{\\outlinelevel0{First Heading}\\par\n}"; self::assertEquals($expect, $this->removeCr($elwrite)); } @@ -213,7 +213,7 @@ public function testRubyTitle(): void $element = $section->addTitle($textRun, 1); $elwrite = new RTF\Element\Title($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\sb0\\sa2{\\outlinelevel0{\\cf0\\f0\\fs48\\b base text (ruby)}\\par\n}"; + $expect = "\\pard\\nowidctlpar \\sb0\\sa2{\\outlinelevel0{\\fs48\\cf0\\b base text (ruby)}\\par\n}"; self::assertEquals($expect, $this->removeCr($elwrite)); } } From 8495bfaaea31dc8deff5f6f3b49ec8ad822e81df Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:00:10 -0500 Subject: [PATCH 16/83] Update RtfEscaper3Test.php - Fix Test --- tests/PhpWordTests/Escaper/RtfEscaper3Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PhpWordTests/Escaper/RtfEscaper3Test.php b/tests/PhpWordTests/Escaper/RtfEscaper3Test.php index 1aebea52f0..ec0d868277 100644 --- a/tests/PhpWordTests/Escaper/RtfEscaper3Test.php +++ b/tests/PhpWordTests/Escaper/RtfEscaper3Test.php @@ -25,8 +25,8 @@ */ class RtfEscaper3Test extends \PHPUnit\Framework\TestCase { - const HEADER = '\\pard\\nowidctlpar \ql{\\cf0\\f0 '; - const HEADER_RTL = '\\pard\\nowidctlpar \qr{\\rtlch\\cf0\\f0 '; + const HEADER = '\\pard\\nowidctlpar \ql{'; + const HEADER_RTL = '\\pard\\nowidctlpar \qr{\\rtlch'; const TRAILER = '}\\par'; protected function tearDown(): void From fe0300b44cacba1c2a2751be23330dfb66c060aa Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:00:35 -0500 Subject: [PATCH 17/83] Update RtfEscaper2Test.php - Fix Test --- tests/PhpWordTests/Escaper/RtfEscaper2Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Escaper/RtfEscaper2Test.php b/tests/PhpWordTests/Escaper/RtfEscaper2Test.php index d65b543f21..97924dc5e2 100644 --- a/tests/PhpWordTests/Escaper/RtfEscaper2Test.php +++ b/tests/PhpWordTests/Escaper/RtfEscaper2Test.php @@ -23,7 +23,7 @@ */ class RtfEscaper2Test extends \PHPUnit\Framework\TestCase { - const HEADER = '\\pard\\nowidctlpar {\\cf0\\f0 '; + const HEADER = '\\pard\\nowidctlpar {'; const TRAILER = '}\\par'; public function escapestring($str) From d39f49903b1241d8f98b8302290a0fca24c14fb2 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:11:42 -0500 Subject: [PATCH 18/83] Update FontTest.php - First Basic Test --- .../Writer/RTF/Style/FontTest.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 8b13789179..73b644d724 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -1 +1,64 @@ +write()); + } + + /** + * Test basic font settings. + */ + public function testFontBasics(): void + { + $font = new \PhpOffice\PhpWord\Style\Tab(); + $font->setName('Times New Roman'); + $font->setSize(22); + $font->setColor('yellow'); + // $font->setHint('test'); + + $writer = new RTF\Style\Font($font); + $writer->setParentWriter(new RTF()); + $result = $writer->write(); + + Assert::assertEquals('\f0\fs22\c0', $result); + } +} From 098d617afb5fa0a420702a42e3368b88fcb4c3cc Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:13:45 -0500 Subject: [PATCH 19/83] Update FontTest.php - minor fix --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 73b644d724..5b5ba600c8 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -49,7 +49,7 @@ public function removeCr($field): string */ public function testFontBasics(): void { - $font = new \PhpOffice\PhpWord\Style\Tab(); + $font = new \PhpOffice\PhpWord\Style\Font(); $font->setName('Times New Roman'); $font->setSize(22); $font->setColor('yellow'); From 5de30d1cd739532b4bbe69049b4aeebb7eed70fa Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:14:44 -0500 Subject: [PATCH 20/83] Update RtfEscaper3Test.php - Minor Fix --- tests/PhpWordTests/Escaper/RtfEscaper3Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Escaper/RtfEscaper3Test.php b/tests/PhpWordTests/Escaper/RtfEscaper3Test.php index ec0d868277..f0c5552580 100644 --- a/tests/PhpWordTests/Escaper/RtfEscaper3Test.php +++ b/tests/PhpWordTests/Escaper/RtfEscaper3Test.php @@ -26,7 +26,7 @@ class RtfEscaper3Test extends \PHPUnit\Framework\TestCase { const HEADER = '\\pard\\nowidctlpar \ql{'; - const HEADER_RTL = '\\pard\\nowidctlpar \qr{\\rtlch'; + const HEADER_RTL = '\\pard\\nowidctlpar \qr{\\rtlch '; const TRAILER = '}\\par'; protected function tearDown(): void From 17e9c280012465e7e4a225f3c85b42f5f50484c7 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:15:32 -0500 Subject: [PATCH 21/83] Update ElementTest.php - Remove \\cf0\\f0 --- tests/PhpWordTests/Writer/RTF/ElementTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/ElementTest.php b/tests/PhpWordTests/Writer/RTF/ElementTest.php index be12c1655b..d22b08c02a 100644 --- a/tests/PhpWordTests/Writer/RTF/ElementTest.php +++ b/tests/PhpWordTests/Writer/RTF/ElementTest.php @@ -121,18 +121,18 @@ public function testTable(): void '\\pard', "\\trowd \\cellx$width \\cellx$width2 ", '\\intbl', - '{\\cf0\\f0 1}\\par', + '{1}\\par', '\\cell', '\\intbl', - '{\\cf0\\f0 2}\\par', + '{2}\\par', '\\cell', '\\row', "\\trowd \\cellx$width \\cellx$width2 ", '\\intbl', - '{\\cf0\\f0 3}\\par', + '{3}\\par', '\\cell', '\\intbl', - '{\\cf0\\f0 4}\par', + '{4}\par', '\\cell', '\\row', '\\pard', From 8e91bbe7441fcb766012a20697c2e7d6d65bb9c2 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:21:08 -0500 Subject: [PATCH 22/83] Update FontTest.php - Fix --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 5b5ba600c8..b6018ff1d5 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -38,12 +38,6 @@ protected function tearDown(): void Settings::setDefaultRtl(null); } - /** @param WriterTextRun|WriterTitle $field */ - public function removeCr($field): string - { - return str_replace("\r\n", "\n", $field->write()); - } - /** * Test basic font settings. */ @@ -59,6 +53,6 @@ public function testFontBasics(): void $writer->setParentWriter(new RTF()); $result = $writer->write(); - Assert::assertEquals('\f0\fs22\c0', $result); + self::assertEquals('\f0\fs22\c0', $result); } } From dda1cf18ac137c096ee883a0aa11b8b990cd9353 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:33:37 -0500 Subject: [PATCH 23/83] Update FontTest.php - Add full suite of tests --- .../Writer/RTF/Style/FontTest.php | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index b6018ff1d5..7aec6f7a63 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -53,6 +53,66 @@ public function testFontBasics(): void $writer->setParentWriter(new RTF()); $result = $writer->write(); - self::assertEquals('\f0\fs22\c0', $result); + self::assertEquals('\f0\fs44\cf0 ', $result); + } + + /** + * Test font style settings. + */ + public function testFontStyle(): void + { + $font = new \PhpOffice\PhpWord\Style\Font(); + $font->setBold(true); + $font->setItalic(true); + $font->setUnderline('dashLong'); + $font->setStrikethrough(true); + $font->setDoubleStrikethrough(true); + $font->setSuperScript(true); + $font->setSubScript(true); + $font->setSmallCaps(true); + $font->setAllCaps(true); + $font->setFgColor('yellow'); + $font->setBgColor('green'); + $font->setHidden(true); + + $writer = new RTF\Style\Font($font); + $writer->setParentWriter(new RTF()); + $result = $writer->write(); + + self::assertEquals('\b\i\ulldash\strike\striked1\super\sub\scaps\caps\highlight0\cb1\v ', $result); + } + + /** + * Test font spacing settings. + */ + public function testFontSpacing(): void + { + $font = new \PhpOffice\PhpWord\Style\Font(); + $font->setScale(5); + $font->setSpacing(4); + $font->setKerning(100); + $font->setPosition(10); + + $writer = new RTF\Style\Font($font); + $writer->setParentWriter(new RTF()); + $result = $writer->write(); + + self::assertEquals('\charscalex5\expnd4\kerning200\up10 ', $result); + } + + /** + * Test general font settings. + */ + public function testFontGeneral(): void + { + $font = new \PhpOffice\PhpWord\Style\Font(); + $font->setRTL(true); + $font->setNoProof(true); + + $writer = new RTF\Style\Font($font); + $writer->setParentWriter(new RTF()); + $result = $writer->write(); + + self::assertEquals('\rtlch\noproof ', $result); } } From 92587705c0e4ff5f2789fa2f70983b36b076512d Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:37:35 -0500 Subject: [PATCH 24/83] Update FontTest.php - Missed some cancelations --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 7aec6f7a63..b557e1964f 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -66,20 +66,20 @@ public function testFontStyle(): void $font->setItalic(true); $font->setUnderline('dashLong'); $font->setStrikethrough(true); - $font->setDoubleStrikethrough(true); + $font->setDoubleStrikethrough(true); // cancels out strike $font->setSuperScript(true); - $font->setSubScript(true); + $font->setSubScript(true); // cancels out super $font->setSmallCaps(true); - $font->setAllCaps(true); + $font->setAllCaps(true); // cancels out smallcaps $font->setFgColor('yellow'); - $font->setBgColor('green'); + $font->setBgColor('yellow'); $font->setHidden(true); $writer = new RTF\Style\Font($font); $writer->setParentWriter(new RTF()); $result = $writer->write(); - self::assertEquals('\b\i\ulldash\strike\striked1\super\sub\scaps\caps\highlight0\cb1\v ', $result); + self::assertEquals('\b\i\ulldash\striked1\sub\caps\highlight0\v\cb0 ', $result); } /** From b4914f2e72d70e85e8cf6c7662c82d5ea087ad3d Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 6 Sep 2025 09:59:43 -0500 Subject: [PATCH 25/83] Update Font.php - CS Fix --- src/PhpWord/Writer/RTF/Style/Font.php | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index b2bbff2716..2c7d2dddf6 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -71,23 +71,23 @@ public function write() // Underline Keywords $underlines = [ - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASH => '\uldash', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHHEAVY => '\ulth', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONG => '\ulldash', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONGHEAVY => '\ulthldash', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOUBLE => '\uldb', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASH => '\uldashd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASHHEAVY => '\ulthdashd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASH => '\uldashdd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASHHEAVY => '\ulthdashdd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTED => '\uld', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTEDHEAVY => '\ulthd', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_HEAVY => '\ulth', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE => '\ul', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVY => '\ulwave', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYDOUBLE => '\ululdbwave', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYHEAVY => '\ulhwave', - \PhpOffice\PhpWord\Style\Font::UNDERLINE_WORDS => '\ulw', + FontStyle::UNDERLINE_DASH => '\uldash', + FontStyle::UNDERLINE_DASHHEAVY => '\ulth', + FontStyle::UNDERLINE_DASHLONG => '\ulldash', + FontStyle::UNDERLINE_DASHLONGHEAVY => '\ulthldash', + FontStyle::UNDERLINE_DOUBLE => '\uldb', + FontStyle::UNDERLINE_DOTDASH => '\uldashd', + FontStyle::UNDERLINE_DOTDASHHEAVY => '\ulthdashd', + FontStyle::UNDERLINE_DOTDOTDASH => '\uldashdd', + FontStyle::UNDERLINE_DOTDOTDASHHEAVY => '\ulthdashdd', + FontStyle::UNDERLINE_DOTTED => '\uld', + FontStyle::UNDERLINE_DOTTEDHEAVY => '\ulthd', + FontStyle::UNDERLINE_HEAVY => '\ulth', + FontStyle::UNDERLINE_SINGLE => '\ul', + FontStyle::UNDERLINE_WAVY => '\ulwave', + FontStyle::UNDERLINE_WAVYDOUBLE => '\ululdbwave', + FontStyle::UNDERLINE_WAVYHEAVY => '\ulhwave', + FontStyle::UNDERLINE_WORDS => '\ulw', ]; // Style From b633680e04774fe308845505e548e9f637365d5f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 09:27:56 -0500 Subject: [PATCH 26/83] Update Language.php - Makes langId work for RTF --- src/PhpWord/Style/Language.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 641ed7b41e..5db64b8fde 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -24,6 +24,7 @@ * Language * A couple of predefined values are defined here, see the websites below for more values. * + * @see https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a * @see http://www.datypic.com/sc/ooxml/t-w_CT_Language.html * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx */ @@ -126,6 +127,7 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st { if (!empty($latin)) { $this->setLatin($latin); + $this->setLangId(); } if (!empty($eastAsia)) { $this->setEastAsia($eastAsia); @@ -168,7 +170,7 @@ public function getLatin(): ?string */ public function setLangId($langId) { - $this->langId = $langId; + $this->langId = $this->convertLocale(); return $this; } @@ -258,4 +260,26 @@ private function validateLocale($locale) return $locale; } + + /** + * Converts a language from the format xx-xx to decimal. + * + * @return int + */ + private function convertLocale() + { + if ($this->getLatin() === null) { + return 0; + } + + $locale = strtoupper(str_replace('-', '_', $this->getLatin())) . '_ID'; + + if (defined($locale)) { + return constant($locale); + } elseif (defined("self::$locale")) { + return constant("self::$locale"); + } + + return 0; + } } From 01f0fc56f259aae612e3b2c9f529fd99c1356b5e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 09:31:08 -0500 Subject: [PATCH 27/83] Update Font.php - support for setting language --- src/PhpWord/Writer/RTF/Style/Font.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 2c7d2dddf6..669761aa2d 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -113,8 +113,11 @@ public function write() // General $content .= $this->getValueIf($style->isRTL(), '\rtlch'); + if($style->getLang() !== null) { + $content .= '\lang' . $style->getLang()->getLangId(); + } - // Other (Font settings currently not in included in array) + // Other (Font settings currently not included in getStyleValues() array) $content .= $this->getValueIf($style->isNoProof(), '\noproof'); $content .= $this->getValueIf($style->getBgColor() !== null, '\cb' . $this->bgColorIndex); From 13fedeeb6c127724396f80b4af7c9eebfb4d25ba Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 09:32:46 -0500 Subject: [PATCH 28/83] Update 1.5.0.md - Update changes --- 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 a3f1b074fa..bd93884d52 100644 --- a/docs/changes/1.x/1.5.0.md +++ b/docs/changes/1.x/1.5.0.md @@ -7,7 +7,7 @@ ### Bug fixes - Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776) -- Writer RTF: Support for various underline styles, doublestrikethrough, smallcaps, allcaps, fgcolor, hidden, scale, spacing, kerning, position, noproof, and bgcolor in Font by [@rasamassen](https://github.com/rasamassen) in [#2819](https://github.com/PHPOffice/PHPWord/pull/2819) +- Writer RTF: Support for various underline styles, doublestrikethrough, smallcaps, allcaps, fgcolor, hidden, scale, spacing, kerning, position, lang, noproof, and bgcolor in Font by [@rasamassen](https://github.com/rasamassen) in [#2819](https://github.com/PHPOffice/PHPWord/pull/2819), also fixing [#321](https://github.com/PHPOffice/PHPWord/issues/321) ### Miscellaneous From 7e64464c550bdbc35f647fb160eada6639dfb4b5 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 09:36:42 -0500 Subject: [PATCH 29/83] Update Language.php - Forgot to remove variable --- src/PhpWord/Style/Language.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 5db64b8fde..b8db3580a5 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -161,14 +161,11 @@ public function getLatin(): ?string /** * Set the Language ID. * - * @param int $langId - * The value for the language ID - * * @return self * * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx */ - public function setLangId($langId) + public function setLangId() { $this->langId = $this->convertLocale(); From 6949ee0f83a3df0fefdb2579f4ff6c0852e9faa4 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 09:47:20 -0500 Subject: [PATCH 30/83] Update Language.php - Make it so tests don't break. --- src/PhpWord/Style/Language.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index b8db3580a5..ab546b034b 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -127,7 +127,7 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st { if (!empty($latin)) { $this->setLatin($latin); - $this->setLangId(); + $this->setLangId($this->getLatin()); } if (!empty($eastAsia)) { $this->setEastAsia($eastAsia); @@ -142,6 +142,8 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st * * @param string $latin * The value for the latin language + * + * @return self */ public function setLatin(?string $latin): self { @@ -161,13 +163,20 @@ public function getLatin(): ?string /** * Set the Language ID. * + * @param string|int $latin + * The value for the latin language + * * @return self * * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx */ - public function setLangId() + public function setLangId($latin) { - $this->langId = $this->convertLocale(); + if(is_string($latin)) { + $this->langId = $this->convertLocale($latin); + } else { + $this->langId = $latin; + } return $this; } @@ -261,15 +270,18 @@ private function validateLocale($locale) /** * Converts a language from the format xx-xx to decimal. * + * @param string $latin + * The value for the latin language + * * @return int */ - private function convertLocale() + private function convertLocale($latin) { - if ($this->getLatin() === null) { + if ($latin === null) { return 0; } - $locale = strtoupper(str_replace('-', '_', $this->getLatin())) . '_ID'; + $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; if (defined($locale)) { return constant($locale); From 7110bc264535856e7f56fefcc60f67a920fec2db Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 09:54:06 -0500 Subject: [PATCH 31/83] Update Language.php - 1024 for none/undefined --- src/PhpWord/Style/Language.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index ab546b034b..3be3831965 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -278,7 +278,7 @@ private function validateLocale($locale) private function convertLocale($latin) { if ($latin === null) { - return 0; + return 1024; } $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; @@ -289,6 +289,6 @@ private function convertLocale($latin) return constant("self::$locale"); } - return 0; + return 1024; } } From f2ae7d8406fab27c29f43fbb0f9bd67cf69e2d1a Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:03:41 -0500 Subject: [PATCH 32/83] Update Language.php - Testing cause of issue. --- src/PhpWord/Style/Language.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 3be3831965..3ed81f4f04 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -142,8 +142,6 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st * * @param string $latin * The value for the latin language - * - * @return self */ public function setLatin(?string $latin): self { @@ -163,7 +161,7 @@ public function getLatin(): ?string /** * Set the Language ID. * - * @param string|int $latin + * @param int|string $latin * The value for the latin language * * @return self @@ -172,11 +170,14 @@ public function getLatin(): ?string */ public function setLangId($latin) { + $this->langId = $latin; + + /* if(is_string($latin)) { $this->langId = $this->convertLocale($latin); } else { $this->langId = $latin; - } + } */ return $this; } From eb7cec1e6b7e46aed69670a95d92fc4caaa65e7e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:13:56 -0500 Subject: [PATCH 33/83] Update Language.php - Hoping this will fix issues. --- src/PhpWord/Style/Language.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 3ed81f4f04..106a6c9a86 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -127,7 +127,7 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st { if (!empty($latin)) { $this->setLatin($latin); - $this->setLangId($this->getLatin()); + $this->setLangId($this->convertLocale($this->getLang())); } if (!empty($eastAsia)) { $this->setEastAsia($eastAsia); @@ -161,23 +161,16 @@ public function getLatin(): ?string /** * Set the Language ID. * - * @param int|string $latin - * The value for the latin language + * @param int $langId + * The value for the language ID * * @return self * * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx */ - public function setLangId($latin) + public function setLangId($langId) { - $this->langId = $latin; - - /* - if(is_string($latin)) { - $this->langId = $this->convertLocale($latin); - } else { - $this->langId = $latin; - } */ + $this->langId = $langId; return $this; } @@ -283,7 +276,7 @@ private function convertLocale($latin) } $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; - + if (defined($locale)) { return constant($locale); } elseif (defined("self::$locale")) { From c26353aeac7bccca52cff938896168165aadff30 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:15:48 -0500 Subject: [PATCH 34/83] Update Language.php --- src/PhpWord/Style/Language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 106a6c9a86..a5e135432f 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -127,7 +127,7 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st { if (!empty($latin)) { $this->setLatin($latin); - $this->setLangId($this->convertLocale($this->getLang())); + $this->setLangId($this->convertLocale($this->getLatin())); } if (!empty($eastAsia)) { $this->setEastAsia($eastAsia); From 7810169fc5f9ef2ec9f40becac9d09ee2e42c9ac Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:26:04 -0500 Subject: [PATCH 35/83] Update Language.php - Not sure cause of errors; testing --- src/PhpWord/Style/Language.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index a5e135432f..de7e66c534 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -272,7 +272,7 @@ private function validateLocale($locale) private function convertLocale($latin) { if ($latin === null) { - return 1024; + return 1036; } $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; @@ -283,6 +283,6 @@ private function convertLocale($latin) return constant("self::$locale"); } - return 1024; + return 1036; } } From 0df857d7ce67fdb2c4fd1269c039c9c1a1519088 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:28:03 -0500 Subject: [PATCH 36/83] Update Language.php - Testing cause of issue. --- src/PhpWord/Style/Language.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index de7e66c534..f81446f26c 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -272,17 +272,17 @@ private function validateLocale($locale) private function convertLocale($latin) { if ($latin === null) { - return 1036; + return 1024; } $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; if (defined($locale)) { - return constant($locale); + return 1024; } elseif (defined("self::$locale")) { - return constant("self::$locale"); + return 1024; } - return 1036; + return 1024; } } From 4c23ee6aaf5c4c635b065300dba4736901d4fa26 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:29:51 -0500 Subject: [PATCH 37/83] Update Language.php - Testing cause of issue. --- src/PhpWord/Style/Language.php | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index f81446f26c..aaaf0dda56 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -127,7 +127,6 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st { if (!empty($latin)) { $this->setLatin($latin); - $this->setLangId($this->convertLocale($this->getLatin())); } if (!empty($eastAsia)) { $this->setEastAsia($eastAsia); @@ -260,29 +259,4 @@ private function validateLocale($locale) return $locale; } - - /** - * Converts a language from the format xx-xx to decimal. - * - * @param string $latin - * The value for the latin language - * - * @return int - */ - private function convertLocale($latin) - { - if ($latin === null) { - return 1024; - } - - $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; - - if (defined($locale)) { - return 1024; - } elseif (defined("self::$locale")) { - return 1024; - } - - return 1024; - } } From 6e45af72ae95ffca32b1f63922be54d79d8c7175 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:31:27 -0500 Subject: [PATCH 38/83] Update Language.php - Complete revert to see where problem is --- src/PhpWord/Style/Language.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index aaaf0dda56..641ed7b41e 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -24,7 +24,6 @@ * Language * A couple of predefined values are defined here, see the websites below for more values. * - * @see https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a * @see http://www.datypic.com/sc/ooxml/t-w_CT_Language.html * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx */ From ec204603752b0634a51b4c4dd55f4ccc47bd946e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:44:47 -0500 Subject: [PATCH 39/83] Update Language.php - Finalize --- src/PhpWord/Style/Language.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 641ed7b41e..30c3cea582 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -126,6 +126,7 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st { if (!empty($latin)) { $this->setLatin($latin); + $this->setLangId($latin); } if (!empty($eastAsia)) { $this->setEastAsia($eastAsia); @@ -168,7 +169,11 @@ public function getLatin(): ?string */ public function setLangId($langId) { - $this->langId = $langId; + if(is_string($langId)) { + $this->langId = $this->convertLocale($this->validateLocale($langId)); + } else { + $this->langId = $langId; + } return $this; } @@ -258,4 +263,28 @@ private function validateLocale($locale) return $locale; } -} + + /** + * Converts a language from the format xx-xx to decimal. + * + * @param string $latin + * The value for the latin language + * + * @return int + */ + private function convertLocale($latin) + { + if ($latin === null) { + return 1024; + } + + $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; + + if (defined($locale)) { + return constant($locale); + } elseif (defined("self::$locale")) { + return constant("self::$locale"); + } + + return 1024; + }} From 65fc5c78cbb4268f63a2a5577e253582852bbd95 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:45:36 -0500 Subject: [PATCH 40/83] Update Language.php - Commit for future language additions --- src/PhpWord/Style/Language.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 30c3cea582..03ff757bfa 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -24,6 +24,7 @@ * Language * A couple of predefined values are defined here, see the websites below for more values. * + * @see https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a * @see http://www.datypic.com/sc/ooxml/t-w_CT_Language.html * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx */ From aec9df8abd93aef82fde715103cd64752c9142f1 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:50:50 -0500 Subject: [PATCH 41/83] Update Font.php - Fixing errors --- src/PhpWord/Writer/RTF/Style/Font.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 669761aa2d..7778fed35d 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -113,8 +113,9 @@ public function write() // General $content .= $this->getValueIf($style->isRTL(), '\rtlch'); - if($style->getLang() !== null) { - $content .= '\lang' . $style->getLang()->getLangId(); + $lang = $style->getLang(); + if ($lang !== null && function_exists($lang->getLangId())) { + $content .= $this->getValueIf($lang->getLangId() !== null, '\lang' . $lang->getLangId()); } // Other (Font settings currently not included in getStyleValues() array) From f9a8d6e93626e8648b3a3602048eddba78a54ede Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:52:10 -0500 Subject: [PATCH 42/83] Update Font.php - Revert --- src/PhpWord/Writer/RTF/Style/Font.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 7778fed35d..aa76b80817 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -113,10 +113,6 @@ public function write() // General $content .= $this->getValueIf($style->isRTL(), '\rtlch'); - $lang = $style->getLang(); - if ($lang !== null && function_exists($lang->getLangId())) { - $content .= $this->getValueIf($lang->getLangId() !== null, '\lang' . $lang->getLangId()); - } // Other (Font settings currently not included in getStyleValues() array) $content .= $this->getValueIf($style->isNoProof(), '\noproof'); From 533ef57b00369932d9db41732d8c169faa99df3e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:53:51 -0500 Subject: [PATCH 43/83] Update Language.php - Format Fixes --- src/PhpWord/Style/Language.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 03ff757bfa..8f7ef1f724 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -170,7 +170,7 @@ public function getLatin(): ?string */ public function setLangId($langId) { - if(is_string($langId)) { + if (is_string($langId)) { $this->langId = $this->convertLocale($this->validateLocale($langId)); } else { $this->langId = $langId; @@ -288,4 +288,5 @@ private function convertLocale($latin) } return 1024; - }} + } +} From c12e599232e74d9d396c2569a2069d6e18ea3aba Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:54:49 -0500 Subject: [PATCH 44/83] Update Font.php - Revert --- src/PhpWord/Writer/RTF/Style/Font.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index aa76b80817..7778fed35d 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -113,6 +113,10 @@ public function write() // General $content .= $this->getValueIf($style->isRTL(), '\rtlch'); + $lang = $style->getLang(); + if ($lang !== null && function_exists($lang->getLangId())) { + $content .= $this->getValueIf($lang->getLangId() !== null, '\lang' . $lang->getLangId()); + } // Other (Font settings currently not included in getStyleValues() array) $content .= $this->getValueIf($style->isNoProof(), '\noproof'); From 4f0b52d75a852582b1864a0646aa273293d14f6e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:55:50 -0500 Subject: [PATCH 45/83] Update Language.php - Could be string or int --- src/PhpWord/Style/Language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 8f7ef1f724..afe4345e96 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -161,7 +161,7 @@ public function getLatin(): ?string /** * Set the Language ID. * - * @param int $langId + * @param int|string $langId * The value for the language ID * * @return self From 17ac2cd3055f77b9e4b582802ae1ea84eaca4973 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 10:56:54 -0500 Subject: [PATCH 46/83] Update Language.php - Keep it simpler --- src/PhpWord/Style/Language.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index afe4345e96..87e0f38a7f 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -127,7 +127,7 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st { if (!empty($latin)) { $this->setLatin($latin); - $this->setLangId($latin); + $this->setLangId($this->convertLocale($this->validateLocale($latin))); } if (!empty($eastAsia)) { $this->setEastAsia($eastAsia); @@ -161,7 +161,7 @@ public function getLatin(): ?string /** * Set the Language ID. * - * @param int|string $langId + * @param int $langId * The value for the language ID * * @return self @@ -170,11 +170,7 @@ public function getLatin(): ?string */ public function setLangId($langId) { - if (is_string($langId)) { - $this->langId = $this->convertLocale($this->validateLocale($langId)); - } else { - $this->langId = $langId; - } + $this->langId = $langId; return $this; } From e66881a9fcd981e87cb0e0f7adfb8ac63406063d Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 11:07:56 -0500 Subject: [PATCH 47/83] Update Language.php - See if fixes... --- src/PhpWord/Style/Language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 87e0f38a7f..e4db89913e 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -271,7 +271,7 @@ private function validateLocale($locale) */ private function convertLocale($latin) { - if ($latin === null) { + if (empty($latin)) { return 1024; } From 30b819b550c7c4d6dfa983ac8e5de5e6427f5dfe Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 11:11:19 -0500 Subject: [PATCH 48/83] Update Language.php - Testing --- src/PhpWord/Style/Language.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index e4db89913e..e4a6ff94bc 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -272,7 +272,7 @@ private function validateLocale($locale) private function convertLocale($latin) { if (empty($latin)) { - return 1024; + return null; } $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; @@ -283,6 +283,6 @@ private function convertLocale($latin) return constant("self::$locale"); } - return 1024; + return null; } } From 20bec15ca2d8d8ba0b10871830d2662d44145583 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 11:12:58 -0500 Subject: [PATCH 49/83] Update Font.php - Reverting --- src/PhpWord/Writer/RTF/Style/Font.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 7778fed35d..a900ef9cf4 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -113,9 +113,8 @@ public function write() // General $content .= $this->getValueIf($style->isRTL(), '\rtlch'); - $lang = $style->getLang(); - if ($lang !== null && function_exists($lang->getLangId())) { - $content .= $this->getValueIf($lang->getLangId() !== null, '\lang' . $lang->getLangId()); + if($style->getLang() !== null) { + $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\lang' . $style->getLang()->getLangId()); } // Other (Font settings currently not included in getStyleValues() array) From 693fe074abfd71c110910daf2aa083d97ac19618 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 11:14:59 -0500 Subject: [PATCH 50/83] Update Language.php - Complete Revert --- src/PhpWord/Style/Language.php | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index e4a6ff94bc..641ed7b41e 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -24,7 +24,6 @@ * Language * A couple of predefined values are defined here, see the websites below for more values. * - * @see https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a * @see http://www.datypic.com/sc/ooxml/t-w_CT_Language.html * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx */ @@ -127,7 +126,6 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st { if (!empty($latin)) { $this->setLatin($latin); - $this->setLangId($this->convertLocale($this->validateLocale($latin))); } if (!empty($eastAsia)) { $this->setEastAsia($eastAsia); @@ -260,29 +258,4 @@ private function validateLocale($locale) return $locale; } - - /** - * Converts a language from the format xx-xx to decimal. - * - * @param string $latin - * The value for the latin language - * - * @return int - */ - private function convertLocale($latin) - { - if (empty($latin)) { - return null; - } - - $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; - - if (defined($locale)) { - return constant($locale); - } elseif (defined("self::$locale")) { - return constant("self::$locale"); - } - - return null; - } } From 602521774111b9d3eb5331460e98ba7f2d497c92 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 11:17:37 -0500 Subject: [PATCH 51/83] Update Language.php - Revert the Revert --- src/PhpWord/Style/Language.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 641ed7b41e..e4db89913e 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -24,6 +24,7 @@ * Language * A couple of predefined values are defined here, see the websites below for more values. * + * @see https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a * @see http://www.datypic.com/sc/ooxml/t-w_CT_Language.html * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx */ @@ -126,6 +127,7 @@ public function __construct(?string $latin = null, ?string $eastAsia = null, ?st { if (!empty($latin)) { $this->setLatin($latin); + $this->setLangId($this->convertLocale($this->validateLocale($latin))); } if (!empty($eastAsia)) { $this->setEastAsia($eastAsia); @@ -258,4 +260,29 @@ private function validateLocale($locale) return $locale; } + + /** + * Converts a language from the format xx-xx to decimal. + * + * @param string $latin + * The value for the latin language + * + * @return int + */ + private function convertLocale($latin) + { + if (empty($latin)) { + return 1024; + } + + $locale = strtoupper(str_replace('-', '_', $latin)) . '_ID'; + + if (defined($locale)) { + return constant($locale); + } elseif (defined("self::$locale")) { + return constant("self::$locale"); + } + + return 1024; + } } From 37ffeb672299330c3b8d277b0b278b37898fee07 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 12 Sep 2025 11:20:33 -0500 Subject: [PATCH 52/83] Update Font.php - Style fix --- src/PhpWord/Writer/RTF/Style/Font.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index a900ef9cf4..0a14883b37 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -113,7 +113,7 @@ public function write() // General $content .= $this->getValueIf($style->isRTL(), '\rtlch'); - if($style->getLang() !== null) { + if ($style->getLang() !== null) { $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\lang' . $style->getLang()->getLangId()); } From e17a2936bedc78a19b074e1e9496ee775d57d4cb Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 23:19:59 -0500 Subject: [PATCH 53/83] Update FontTest.php - Greatly expand tests --- .../Writer/RTF/Style/FontTest.php | 243 +++++++++++++----- 1 file changed, 176 insertions(+), 67 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index b557e1964f..eb049c29c2 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -19,100 +19,209 @@ namespace PhpOffice\PhpWordTests\Writer\RTF\Style; use PhpOffice\PhpWord\Settings; +use PhpOffice\PhpWord\Style\Font as FontStyle; +use PhpOffice\PhpWord\Style\Language; use PhpOffice\PhpWord\Writer\RTF; +use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontWriter; +use PHPUnit\Framework\TestCase; -/** - * Test class for PhpOffice\PhpWord\Writer\RTF\Style\Font. - * - * @coversDefaultClass \PhpOffice\PhpWord\Writer\RTF\Style\Font - * - * @runTestsInSeparateProcesses - */ -class FontTest extends \PHPUnit\Framework\TestCase +class FontTest extends TestCase { - /** - * Executed before each method of the class. - */ protected function tearDown(): void { Settings::setDefaultRtl(null); } /** - * Test basic font settings. + * @param FontWriter $field */ - public function testFontBasics(): void + public function removeCr($field): string { - $font = new \PhpOffice\PhpWord\Style\Font(); - $font->setName('Times New Roman'); - $font->setSize(22); - $font->setColor('yellow'); - // $font->setHint('test'); - - $writer = new RTF\Style\Font($font); - $writer->setParentWriter(new RTF()); - $result = $writer->write(); - - self::assertEquals('\f0\fs44\cf0 ', $result); + return str_replace("\r\n", "\n", $field->write()); } /** - * Test font style settings. + * Test font and color. + * See page 131 of RTF Specification 1.9.1 for Font (Character). + * See page 142 of RTF Specification 1.9.1 for Highlighting. */ - public function testFontStyle(): void + public function testFontColor(): void { - $font = new \PhpOffice\PhpWord\Style\Font(); - $font->setBold(true); - $font->setItalic(true); - $font->setUnderline('dashLong'); - $font->setStrikethrough(true); - $font->setDoubleStrikethrough(true); // cancels out strike - $font->setSuperScript(true); - $font->setSubScript(true); // cancels out super - $font->setSmallCaps(true); - $font->setAllCaps(true); // cancels out smallcaps - $font->setFgColor('yellow'); - $font->setBgColor('yellow'); - $font->setHidden(true); - - $writer = new RTF\Style\Font($font); - $writer->setParentWriter(new RTF()); - $result = $writer->write(); - - self::assertEquals('\b\i\ulldash\striked1\sub\caps\highlight0\v\cb0 ', $result); + $parentWriter = new RTF(); + $style = new FontStyle(); + $writer = new FontWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setName('Times New Roman'); + $style->setFallbackFont('serif'); + $style->setSize(24); + $style->setColor($style::FGCOLOR_YELLOW); + $style->setFgColor($style::FGCOLOR_RED); + $style->setBgColor('#123456'); + $expect = '\f0\fs48\cf0\highlight0\cb0 '; + self::assertEquals($expect, $this->removeCr($writer)); } /** - * Test font spacing settings. + * Test formatting. + * See page 130-133 of RTF Specification 1.9.1 for Font (Character). */ - public function testFontSpacing(): void + public function testFontFormatting(): void { - $font = new \PhpOffice\PhpWord\Style\Font(); - $font->setScale(5); - $font->setSpacing(4); - $font->setKerning(100); - $font->setPosition(10); - - $writer = new RTF\Style\Font($font); - $writer->setParentWriter(new RTF()); - $result = $writer->write(); - - self::assertEquals('\charscalex5\expnd4\kerning200\up10 ', $result); + $parentWriter = new RTF(); + $style = new FontStyle(); + $writer = new FontWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setAllCaps(true); + $style->setBold(true); + $style->setdoubleStrikethrough(true); + $style->setHidden(true); + $style->setItalic(true); + $style->setNoProof(true); + $style->setSubScript(true); + $expect = '\b\i\striked1\sub\caps\v\noproof '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setSmallCaps(true); + $style->setStrikethrough(true); + $style->setSuperScript(true); + $expect = '\b\i\strike\super\scaps\v\noproof '; + self::assertEquals($expect, $this->removeCr($writer)); + + // Disable styles (in case default is enabled) + $style->setBold(false); + $style->setHidden(false); + $style->setItalic(false); + $style->setSmallCaps(false); + $style->setStrikethrough(false); + $style->setSuperScript(false); + $style->setNoProof(false); + $expect = '\b0\i0\strike0\super0\scaps0\v0 '; + self::assertEquals($expect, $this->removeCr($writer)); } /** - * Test general font settings. + * Test underline. + * See page 132-133 of RTF Specification 1.9.1 for Formatting. */ - public function testFontGeneral(): void + public function testFontUnderline(): void { - $font = new \PhpOffice\PhpWord\Style\Font(); - $font->setRTL(true); - $font->setNoProof(true); + $parentWriter = new RTF(); + $style = new FontStyle(); + $writer = new FontWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setUnderline($style::UNDERLINE_DASH); + $expect = '\uldash '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DASHHEAVY); + $expect = '\ulthdash '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DASHLONG); + $expect = '\ulldash '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DASHLONGHEAVY); + $expect = '\ulthldash '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DOUBLE); + $expect = '\uldb '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DOTDASH); + $expect = '\uldashd '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DOTDASHHEAVY); + $expect = '\ulthdashd '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DOTDOTDASH); + $expect = '\uldashdd '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DOTDOTDASHHEAVY); + $expect = '\ulthdashdd '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DOTTED); + $expect = '\uld '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_DOTTEDHEAVY); + $expect = '\ulthd '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_HEAVY); + $expect = '\ulth '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_SINGLE); + $expect = '\ul '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_WAVY); + $expect = '\ulwave '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_WAVYDOUBLE); + $expect = '\ululdbwave '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_WAVYHEAVY); + $expect = '\ulhwave '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_WORDS); + $expect = '\ulw '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setUnderline($style::UNDERLINE_NONE); + $expect = ' '; + self::assertEquals($expect, $this->removeCr($writer)); + } - $writer = new RTF\Style\Font($font); - $writer->setParentWriter(new RTF()); - $result = $writer->write(); + /** + * Test language. + * See page 132 of RTF Specification 1.9.1 for Spacing. + */ + public function testFontLang(): void + { + $parentWriter = new RTF(); + $style = new FontStyle(); + $writer = new FontWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setRTL(true); + $style->setLang(Language::KO_KR); + $expect = '\rtlch\lang0 '; + self::assertEquals($expect, $this->removeCr($writer)); + + $style->setRTL(false); + $style->setLang(Language::EN_US); + $expect = '\ltrch\lang0 '; + self::assertEquals($expect, $this->removeCr($writer)); + } - self::assertEquals('\rtlch\noproof ', $result); + /** + * Test font spacing settings. + */ + public function testFontSpacing(): void + { + $parentWriter = new RTF(); + $style = new FontStyle(); + $writer = new FontWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setScale(5); + $style->setSpacing(4); + $style->setKerning(100); + $style->setPosition(10); + $expect = '\charscalex5\expnd4\kerning200\up10 '; + self::assertEquals($expect, $this->removeCr($writer)); } } From daec4567da19e67c9fdad8f98326c020e5e662f4 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 23:29:39 -0500 Subject: [PATCH 54/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index eb049c29c2..ba3aa758c6 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -97,7 +97,7 @@ public function testFontFormatting(): void $style->setStrikethrough(false); $style->setSuperScript(false); $style->setNoProof(false); - $expect = '\b0\i0\strike0\super0\scaps0\v0 '; + $expect = '\b0\i0\strike0\scaps0\v0 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -198,12 +198,12 @@ public function testFontLang(): void $style->setRTL(true); $style->setLang(Language::KO_KR); - $expect = '\rtlch\lang0 '; + $expect = '\rtlch\lang1042 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setRTL(false); $style->setLang(Language::EN_US); - $expect = '\ltrch\lang0 '; + $expect = '\ltrch\lang1033 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -216,7 +216,7 @@ public function testFontSpacing(): void $style = new FontStyle(); $writer = new FontWriter($style); $writer->setParentWriter($parentWriter); - + $style->setScale(5); $style->setSpacing(4); $style->setKerning(100); From 048e62d0b309ae02e3cd2b17b132d191ad5c5e36 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 23:29:43 -0500 Subject: [PATCH 55/83] Update Font.php --- src/PhpWord/Writer/RTF/Style/Font.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 0a14883b37..a44d7668b6 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -72,7 +72,7 @@ public function write() // Underline Keywords $underlines = [ FontStyle::UNDERLINE_DASH => '\uldash', - FontStyle::UNDERLINE_DASHHEAVY => '\ulth', + FontStyle::UNDERLINE_DASHHEAVY => '\ulthdash', FontStyle::UNDERLINE_DASHLONG => '\ulldash', FontStyle::UNDERLINE_DASHLONGHEAVY => '\ulthldash', FontStyle::UNDERLINE_DOUBLE => '\uldb', @@ -92,12 +92,15 @@ public function write() // Style $content .= $this->getValueIf($style->isBold(), '\b'); + $content .= $this->getValueIf($style->isBold() === false, '\b0'); $content .= $this->getValueIf($style->isItalic(), '\i'); + $content .= $this->getValueIf($style->isItalic() === false, '\i0'); if (isset($underlines[$style->getUnderline()])) { $content .= $underlines[$style->getUnderline()]; } $content .= $this->getValueIf($style->isStrikethrough(), '\strike'); $content .= $this->getValueIf($style->isDoubleStrikethrough(), '\striked1'); + $content .= $this->getValueIf($style->isStrikethrough() === false && $style->isDoubleStrikethrough() === false, '\strike0'); $content .= $this->getValueIf($style->isSuperScript(), '\super'); $content .= $this->getValueIf($style->isSubScript(), '\sub'); $content .= $this->getValueIf($style->isSmallCaps(), '\scaps'); @@ -113,12 +116,14 @@ public function write() // General $content .= $this->getValueIf($style->isRTL(), '\rtlch'); + $content .= $this->getValueIf($style->isRTL() === false, '\ltrch'); if ($style->getLang() !== null) { $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\lang' . $style->getLang()->getLangId()); } // Other (Font settings currently not included in getStyleValues() array) $content .= $this->getValueIf($style->isNoProof(), '\noproof'); + $content .= $this->getValueIf($style->isNoProof() === false, '\noproof0'); $content .= $this->getValueIf($style->getBgColor() !== null, '\cb' . $this->bgColorIndex); if (empty($content)) { From 509f672aff0a9c4d867c0584e3a9d99e66b6a93e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 23:52:25 -0500 Subject: [PATCH 56/83] Update Font.php --- src/PhpWord/Writer/RTF/Style/Font.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index a44d7668b6..7cd88253bd 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -107,6 +107,7 @@ public function write() $content .= $this->getValueIf($style->isAllCaps(), '\caps'); $content .= $this->getValueIf($style->getFgColor() !== null, '\highlight' . $this->fgColorIndex); $content .= $this->getValueIf($style->isHidden(), '\v'); + $content .= $this->getValueIf($style->isHidden() === false, '\v0'); // Spacing $content .= $this->getValueIf($style->getScale() !== null, '\charscalex' . $style->getScale()); @@ -117,13 +118,16 @@ public function write() // General $content .= $this->getValueIf($style->isRTL(), '\rtlch'); $content .= $this->getValueIf($style->isRTL() === false, '\ltrch'); + $content .= $this->getValueIf($style->isNoProof(), '\noproof\lang1024'); if ($style->getLang() !== null) { - $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\lang' . $style->getLang()->getLangId()); + if ($style->isNoProof()) { + $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\langnp' . $style->getLang()->getLangId()); + } else { + $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\lang' . $style->getLang()->getLangId()); + } } // Other (Font settings currently not included in getStyleValues() array) - $content .= $this->getValueIf($style->isNoProof(), '\noproof'); - $content .= $this->getValueIf($style->isNoProof() === false, '\noproof0'); $content .= $this->getValueIf($style->getBgColor() !== null, '\cb' . $this->bgColorIndex); if (empty($content)) { From 964300dee63b905243d4235a532f8325e7d55413 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 23:52:27 -0500 Subject: [PATCH 57/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index ba3aa758c6..16646e2374 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -80,13 +80,14 @@ public function testFontFormatting(): void $style->setItalic(true); $style->setNoProof(true); $style->setSubScript(true); - $expect = '\b\i\striked1\sub\caps\v\noproof '; + $expect = '\b\i\striked1\sub\caps\v\noproof\lang1024 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setSmallCaps(true); $style->setStrikethrough(true); $style->setSuperScript(true); - $expect = '\b\i\strike\super\scaps\v\noproof '; + $style->setNoProof(false); + $expect = '\b\i\strike\super\scaps\v '; self::assertEquals($expect, $this->removeCr($writer)); // Disable styles (in case default is enabled) @@ -96,8 +97,7 @@ public function testFontFormatting(): void $style->setSmallCaps(false); $style->setStrikethrough(false); $style->setSuperScript(false); - $style->setNoProof(false); - $expect = '\b0\i0\strike0\scaps0\v0 '; + $expect = '\b0\i0\strike0\v0 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -181,7 +181,7 @@ public function testFontUnderline(): void self::assertEquals($expect, $this->removeCr($writer)); $style->setUnderline($style::UNDERLINE_NONE); - $expect = ' '; + $expect = ''; self::assertEquals($expect, $this->removeCr($writer)); } From 78632f11531db254934ddc921671723bed88df2b Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 23:54:10 -0500 Subject: [PATCH 58/83] Update StyleTest.php - remove unnecessary setDefaultRtl(false) --- tests/PhpWordTests/Writer/RTF/StyleTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/StyleTest.php b/tests/PhpWordTests/Writer/RTF/StyleTest.php index ca0e0eca25..dc0f1bdbd2 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -151,7 +151,6 @@ public function testPageBreakLineHeight(): void public function testPageBreakLineHeight2(): void { - Settings::setDefaultRtl(false); $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\Text('New page', null, ['lineHeight' => 1.08, 'pageBreakBefore' => true]); $text = new RTF\Element\Text($parentWriter, $element); From 7bc914abdccee58f508c37b027dfe20fa037c55f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 3 Oct 2025 23:59:18 -0500 Subject: [PATCH 59/83] 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 dc0f1bdbd2..5291635a31 100644 --- a/tests/PhpWordTests/Writer/RTF/StyleTest.php +++ b/tests/PhpWordTests/Writer/RTF/StyleTest.php @@ -154,7 +154,7 @@ public function testPageBreakLineHeight2(): void $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\Text('New page', null, ['lineHeight' => 1.08, 'pageBreakBefore' => true]); $text = new RTF\Element\Text($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\ql\\sl259\\slmult1\\page{New page}\\par\n"; + $expect = "\\pard\\nowidctlpar \\sl259\\slmult1\\page{New page}\\par\n"; self::assertEquals($expect, $this->removeCr($text)); } From e296f52a96a7936fb5726d25a512a722e14bf604 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 00:01:31 -0500 Subject: [PATCH 60/83] Update Element2Test.php - remove unnecessary setDefaultRtl(false) --- tests/PhpWordTests/Writer/RTF/Element2Test.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Element2Test.php b/tests/PhpWordTests/Writer/RTF/Element2Test.php index c293967806..a6afbb8497 100644 --- a/tests/PhpWordTests/Writer/RTF/Element2Test.php +++ b/tests/PhpWordTests/Writer/RTF/Element2Test.php @@ -41,25 +41,23 @@ public function removeCr($field): string public function testTextRun(): void { - Settings::setDefaultRtl(false); $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\TextRun(); $element->addText('Hello '); $element->addText('there.'); $textrun = new WriterTextRun($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\ql{{Hello }{there.}}\\par\n"; + $expect = "\\pard\\nowidctlpar {{Hello }{there.}}\\par\n"; self::assertEquals($expect, $this->removeCr($textrun)); } public function testTextRunParagraphStyle(): void { - Settings::setDefaultRtl(false); $parentWriter = new RTF(); $element = new \PhpOffice\PhpWord\Element\TextRun(['spaceBefore' => 0, 'spaceAfter' => 0]); $element->addText('Hello '); $element->addText('there.'); $textrun = new WriterTextRun($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\ql\\sb0\\sa0{{Hello }{there.}}\\par\n"; + $expect = "\\pard\\nowidctlpar \\sb0\\sa0{{Hello }{there.}}\\par\n"; self::assertEquals($expect, $this->removeCr($textrun)); } @@ -67,12 +65,11 @@ public function testTitle(): void { $parentWriter = new RTF(); $phpWord = new \PhpOffice\PhpWord\PhpWord(); - Settings::setDefaultRtl(false); $phpWord->addTitleStyle(1, [], ['spaceBefore' => 0, 'spaceAfter' => 0]); $section = $phpWord->addSection(); $element = $section->addTitle('First Heading', 1); $elwrite = new WriterTitle($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\ql\\sb0\\sa0{\\outlinelevel0{First Heading}\\par\n}"; + $expect = "\\pard\\nowidctlpar \\sb0\\sa0{\\outlinelevel0{First Heading}\\par\n}"; self::assertEquals($expect, $this->removeCr($elwrite)); Settings::setDefaultRtl(null); } From f3c3e9471a7a405d86ea476d5bfe5fa5454f50ea Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 00:02:49 -0500 Subject: [PATCH 61/83] Update TableTest.php - remove unnecessary setDefaultRtl(false) --- .../PhpWordTests/Writer/RTF/Element/TableTest.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Element/TableTest.php b/tests/PhpWordTests/Writer/RTF/Element/TableTest.php index ecd5f7b0ea..348beec5dd 100644 --- a/tests/PhpWordTests/Writer/RTF/Element/TableTest.php +++ b/tests/PhpWordTests/Writer/RTF/Element/TableTest.php @@ -39,7 +39,6 @@ public function removeCr(WriterTable $field): string public function testTable(): void { - Settings::setDefaultRtl(false); $parentWriter = new RTF(); $element = new Table(); $width = 100; @@ -59,7 +58,7 @@ public function testTable(): void '\\pard', "\\trowd \\cellx$width \\cellx$width2 ", '\\intbl', - '\\ql{1}\\par', + '{1}\\par', '\\cell', '\\intbl', '{2}\\par', @@ -67,7 +66,7 @@ public function testTable(): void '\\row', "\\trowd \\cellx$width \\cellx$width2 ", '\\intbl', - '\\ql{3}\\par', + '{3}\\par', '\\cell', '\\intbl', '{4}\par', @@ -84,7 +83,6 @@ public function testTableStyle(): void { $width = 100; - Settings::setDefaultRtl(false); $parentWriter = new RTF(); Style::addTableStyle('TableStyle', ['borderSize' => 6, 'borderColor' => '006699']); @@ -102,7 +100,7 @@ public function testTableStyle(): void '\\clbrdrr\\brdrs\\brdrw2\\brdrcf0', "\\cellx$width ", '\\intbl', - '\\ql{1}\\par', + '{1}\\par', '\\cell', '\\row', '\\pard', @@ -116,7 +114,6 @@ public function testTableStyleNotExisting(): void { $width = 100; - Settings::setDefaultRtl(false); $parentWriter = new RTF(); $element = new Table('TableStyleNotExisting'); @@ -128,7 +125,7 @@ public function testTableStyleNotExisting(): void '\\pard', "\\trowd \\cellx$width ", '\\intbl', - '\\ql{1}\\par', + '{1}\\par', '\\cell', '\\row', '\\pard', @@ -142,7 +139,6 @@ public function testTableCellStyle(): void { $width = 100; - Settings::setDefaultRtl(false); $parentWriter = new RTF(); $element = new Table(); @@ -158,7 +154,7 @@ public function testTableCellStyle(): void '\\clbrdrr\\brdrdot\\brdrw2\\brdrcf0', "\\cellx$width ", '\\intbl', - '\\ql{1}\\par', + '{1}\\par', '\\cell', '\\row', '\\pard', From 0503884b43f921adea6b3a68e01e2b482fb5b8d3 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 00:04:08 -0500 Subject: [PATCH 62/83] Update RtfEscaper3Test.php --- tests/PhpWordTests/Escaper/RtfEscaper3Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Escaper/RtfEscaper3Test.php b/tests/PhpWordTests/Escaper/RtfEscaper3Test.php index f0c5552580..b20bb6bda9 100644 --- a/tests/PhpWordTests/Escaper/RtfEscaper3Test.php +++ b/tests/PhpWordTests/Escaper/RtfEscaper3Test.php @@ -25,7 +25,7 @@ */ class RtfEscaper3Test extends \PHPUnit\Framework\TestCase { - const HEADER = '\\pard\\nowidctlpar \ql{'; + const HEADER = '\\pard\\nowidctlpar \ql{\ltrch '; const HEADER_RTL = '\\pard\\nowidctlpar \qr{\\rtlch '; const TRAILER = '}\\par'; From ffb151d1aaf82d1e713e48382599472baa9a35d1 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 08:44:54 -0500 Subject: [PATCH 63/83] Update FontTest.php - create test with header table set --- .../Writer/RTF/Style/FontTest.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 16646e2374..609b7ae22f 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -62,6 +62,32 @@ public function testFontColor(): void self::assertEquals($expect, $this->removeCr($writer)); } + /** + * Test font and color after registering header tables. + */ + public function testFontColorRegistered(): void + { + $phpWord = new \PhpOffice\PhpWord\PhpWord(); + $parentWriter = new RTF($phpWord); + $style = new FontStyle(); + $writer = new FontWriter($style); + $writer->setParentWriter($parentWriter); + + $style->setName('Times New Roman'); + $style->setFallbackFont('serif'); + $style->setSize(24); + $style->setColor($style::FGCOLOR_YELLOW); + $style->setFgColor($style::FGCOLOR_RED); + $style->setBgColor('#123456'); + + $secton = $phpWord->addSection(); + $section->addFontStyle('style1', $style); + $parentWriter->getWriterPart('Header')->write(); + + $expect = '\f0\fs48\cf0\highlight0\cb0 '; + self::assertEquals($expect, $this->removeCr($writer)); + } + /** * Test formatting. * See page 130-133 of RTF Specification 1.9.1 for Font (Character). From d407afd4f0f8ed46705d5e81041477d8cbe81a39 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 08:46:25 -0500 Subject: [PATCH 64/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 609b7ae22f..4eaf2a4da2 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -72,7 +72,7 @@ public function testFontColorRegistered(): void $style = new FontStyle(); $writer = new FontWriter($style); $writer->setParentWriter($parentWriter); - + $style->setName('Times New Roman'); $style->setFallbackFont('serif'); $style->setSize(24); @@ -80,10 +80,10 @@ public function testFontColorRegistered(): void $style->setFgColor($style::FGCOLOR_RED); $style->setBgColor('#123456'); - $secton = $phpWord->addSection(); + $section = $phpWord->addSection(); $section->addFontStyle('style1', $style); $parentWriter->getWriterPart('Header')->write(); - + $expect = '\f0\fs48\cf0\highlight0\cb0 '; self::assertEquals($expect, $this->removeCr($writer)); } From 3c34abf4ccf7175e64ba4adbea781b65394172e5 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 08:49:19 -0500 Subject: [PATCH 65/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 4eaf2a4da2..bf44970974 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -80,8 +80,7 @@ public function testFontColorRegistered(): void $style->setFgColor($style::FGCOLOR_RED); $style->setBgColor('#123456'); - $section = $phpWord->addSection(); - $section->addFontStyle('style1', $style); + $phpWord->addFontStyle('style1', $style); $parentWriter->getWriterPart('Header')->write(); $expect = '\f0\fs48\cf0\highlight0\cb0 '; From 76ab10b988e6416a8055fde1bccc0ee7e622f347 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 08:58:32 -0500 Subject: [PATCH 66/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index bf44970974..509274ed36 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -70,8 +70,6 @@ public function testFontColorRegistered(): void $phpWord = new \PhpOffice\PhpWord\PhpWord(); $parentWriter = new RTF($phpWord); $style = new FontStyle(); - $writer = new FontWriter($style); - $writer->setParentWriter($parentWriter); $style->setName('Times New Roman'); $style->setFallbackFont('serif'); @@ -83,6 +81,8 @@ public function testFontColorRegistered(): void $phpWord->addFontStyle('style1', $style); $parentWriter->getWriterPart('Header')->write(); + $writer = new FontWriter($style); + $writer->setParentWriter($parentWriter); $expect = '\f0\fs48\cf0\highlight0\cb0 '; self::assertEquals($expect, $this->removeCr($writer)); } From ebe5a580c840935b5513fb959277359bdb7ead8f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 09:17:56 -0500 Subject: [PATCH 67/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 509274ed36..9d1f8acbb4 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -19,9 +19,11 @@ namespace PhpOffice\PhpWordTests\Writer\RTF\Style; use PhpOffice\PhpWord\Settings; +use PhpOffice\PhpWord\Element\Text as TextElement; use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Language; use PhpOffice\PhpWord\Writer\RTF; +use PhpOffice\PhpWord\Writer\RTF\Element\Text as TextWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontWriter; use PHPUnit\Framework\TestCase; @@ -70,6 +72,8 @@ public function testFontColorRegistered(): void $phpWord = new \PhpOffice\PhpWord\PhpWord(); $parentWriter = new RTF($phpWord); $style = new FontStyle(); + $element = new TextElement(); + $writer = new TextWriter($parentWriter, $element); $style->setName('Times New Roman'); $style->setFallbackFont('serif'); @@ -81,8 +85,9 @@ public function testFontColorRegistered(): void $phpWord->addFontStyle('style1', $style); $parentWriter->getWriterPart('Header')->write(); - $writer = new FontWriter($style); - $writer->setParentWriter($parentWriter); + $element->setText('Test'); + $element->setFontStyle($style); + $expect = '\f0\fs48\cf0\highlight0\cb0 '; self::assertEquals($expect, $this->removeCr($writer)); } From 25b85c3562f874695f464bb09e07635ac1003614 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 09:27:47 -0500 Subject: [PATCH 68/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 9d1f8acbb4..1a00e84bb0 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -18,8 +18,8 @@ namespace PhpOffice\PhpWordTests\Writer\RTF\Style; -use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Element\Text as TextElement; +use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Language; use PhpOffice\PhpWord\Writer\RTF; @@ -88,7 +88,7 @@ public function testFontColorRegistered(): void $element->setText('Test'); $element->setFontStyle($style); - $expect = '\f0\fs48\cf0\highlight0\cb0 '; + $expect = '\pard\nowidctlpar {\f1\fs48\cf1\highlight2\cb0 Test}\par\n'; self::assertEquals($expect, $this->removeCr($writer)); } From 3a59a68a2468e4aa6ece8168c2b5cb8f5dade7ff Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 09:28:31 -0500 Subject: [PATCH 69/83] Update Header.php - register font background colors --- src/PhpWord/Writer/RTF/Part/Header.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PhpWord/Writer/RTF/Part/Header.php b/src/PhpWord/Writer/RTF/Part/Header.php index 97644fe4ac..ea181f3d65 100644 --- a/src/PhpWord/Writer/RTF/Part/Header.php +++ b/src/PhpWord/Writer/RTF/Part/Header.php @@ -238,6 +238,7 @@ private function registerFontItems($style): void $this->registerTableItem($this->fontTable, $style->getName(), $defaultFont); $this->registerTableItem($this->colorTable, $style->getColor(), $defaultColor); $this->registerTableItem($this->colorTable, $style->getFgColor(), $defaultColor); + $this->registerTableItem($this->colorTable, $style->getBgColor(), $defaultColor); return; } From 79c89c4aabc2172c5551502f0ddf03d5296c6fe9 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 09:41:39 -0500 Subject: [PATCH 70/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 1a00e84bb0..2950e71666 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -73,7 +73,7 @@ public function testFontColorRegistered(): void $parentWriter = new RTF($phpWord); $style = new FontStyle(); $element = new TextElement(); - $writer = new TextWriter($parentWriter, $element); + $writer = new TextWriter($parentWriter, $element, true); $style->setName('Times New Roman'); $style->setFallbackFont('serif'); @@ -88,7 +88,7 @@ public function testFontColorRegistered(): void $element->setText('Test'); $element->setFontStyle($style); - $expect = '\pard\nowidctlpar {\f1\fs48\cf1\highlight2\cb0 Test}\par\n'; + $expect = '\pard\nowidctlpar {\f1\fs48\cf1\highlight2\cb3 Test}'; self::assertEquals($expect, $this->removeCr($writer)); } From ffa633af3de938e75ad14235d0620324320a7d35 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 09:45:49 -0500 Subject: [PATCH 71/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 2950e71666..e1548dc955 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -55,7 +55,7 @@ public function testFontColor(): void $writer->setParentWriter($parentWriter); $style->setName('Times New Roman'); - $style->setFallbackFont('serif'); + $style->setFallbackFont('serif'); // currently does nothing in RTF, see pg. 18 of spec for implementation $style->setSize(24); $style->setColor($style::FGCOLOR_YELLOW); $style->setFgColor($style::FGCOLOR_RED); @@ -76,7 +76,7 @@ public function testFontColorRegistered(): void $writer = new TextWriter($parentWriter, $element, true); $style->setName('Times New Roman'); - $style->setFallbackFont('serif'); + $style->setFallbackFont('serif'); // currently does nothing in RTF, see pg. 18 of spec for implementation $style->setSize(24); $style->setColor($style::FGCOLOR_YELLOW); $style->setFgColor($style::FGCOLOR_RED); @@ -88,7 +88,7 @@ public function testFontColorRegistered(): void $element->setText('Test'); $element->setFontStyle($style); - $expect = '\pard\nowidctlpar {\f1\fs48\cf1\highlight2\cb3 Test}'; + $expect = '{\f1\fs48\cf1\highlight2\cb3 Test}'; self::assertEquals($expect, $this->removeCr($writer)); } From a13bc1ed092e0b75090972f634262305a7076f55 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 4 Oct 2025 09:57:08 -0500 Subject: [PATCH 72/83] Update FontTest.php - add comments on non-working features in tests --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index e1548dc955..bda5e096c6 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -124,9 +124,9 @@ public function testFontFormatting(): void $style->setBold(false); $style->setHidden(false); $style->setItalic(false); - $style->setSmallCaps(false); + $style->setSmallCaps(false); // should display \caps0\scaps0; currently doesn't work $style->setStrikethrough(false); - $style->setSuperScript(false); + $style->setSuperScript(false); // should display \nosupersub; currently doesn't work $expect = '\b0\i0\strike0\v0 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -210,7 +210,7 @@ public function testFontUnderline(): void $expect = '\ulw '; self::assertEquals($expect, $this->removeCr($writer)); - $style->setUnderline($style::UNDERLINE_NONE); + $style->setUnderline($style::UNDERLINE_NONE); // should display \ulnone\ul0; currently doesn't work $expect = ''; self::assertEquals($expect, $this->removeCr($writer)); } From 36e31e736f3bc9357627c6fde41539ad0bc11923 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 7 Oct 2025 20:52:21 -0500 Subject: [PATCH 73/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index bda5e096c6..b4deccafa6 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -35,7 +35,7 @@ protected function tearDown(): void } /** - * @param FontWriter $field + * @param FontWriter|TextWriter $field */ public function removeCr($field): string { From 20c6bdfcc87dd1ce2ca0487907f0ca7577f05859 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Thu, 9 Oct 2025 22:55:18 -0500 Subject: [PATCH 74/83] Update Font.php - Fix Background Color, see page 23 of RTF specification --- src/PhpWord/Writer/RTF/Style/Font.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 7cd88253bd..d0a68b2511 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -128,7 +128,8 @@ public function write() } // Other (Font settings currently not included in getStyleValues() array) - $content .= $this->getValueIf($style->getBgColor() !== null, '\cb' . $this->bgColorIndex); + // Shading needs to be set to make background color work in Word, see page 23 of RTF specification. + $content .= $this->getValueIf($style->getBgColor() !== null, '\chshdng0\chcbpat' . $this->bgColorIndex . '\cb' . $this->bgColorIndex); if (empty($content)) { return $content; From 64397b23163ccef2d38bfa74641da939ece49372 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 17 Oct 2025 13:52:39 -0500 Subject: [PATCH 75/83] Update Font.php - Fixes spacing issue, reorganizes to match Word2007Writer order (making it easier for proofing in the future) --- src/PhpWord/Writer/RTF/Style/Font.php | 81 ++++++++++++++++----------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index d0a68b2511..29fe9f1c9a 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -61,14 +61,6 @@ public function write() $content = ''; - // To make it easy to determine what's missing as new features are added, - // Everything below is in the same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues - - // Basic - $content .= $this->getValueIf($style->getName() !== null, '\f' . $this->nameIndex); - $content .= $this->getValueIf($style->getSize() !== null, '\fs' . round($style->getSize() * 2)); - $content .= $this->getValueIf($style->getColor() !== null, '\cf' . $this->colorIndex); - // Underline Keywords $underlines = [ FontStyle::UNDERLINE_DASH => '\uldash', @@ -90,50 +82,75 @@ public function write() FontStyle::UNDERLINE_WORDS => '\ulw', ]; - // Style + // Style Name + + // Font name/family + $content .= $this->getValueIf($style->getName() !== null, '\f' . $this->nameIndex); + + // Language + if ($style->getLang() !== null) { + if ($style->isNoProof()) { + $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\langnp' . $style->getLang()->getLangId()); + } else { + $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\lang' . $style->getLang()->getLangId()); + } + } + + // Color + $content .= $this->getValueIf($style->getColor() !== null, '\cf' . $this->colorIndex); + + // Size + $content .= $this->getValueIf($style->getSize() !== null, '\fs' . round($style->getSize() * 2)); + + // Bold, italic $content .= $this->getValueIf($style->isBold(), '\b'); $content .= $this->getValueIf($style->isBold() === false, '\b0'); $content .= $this->getValueIf($style->isItalic(), '\i'); $content .= $this->getValueIf($style->isItalic() === false, '\i0'); - if (isset($underlines[$style->getUnderline()])) { - $content .= $underlines[$style->getUnderline()]; - } + + // Strikethrough, double strikethrough $content .= $this->getValueIf($style->isStrikethrough(), '\strike'); $content .= $this->getValueIf($style->isDoubleStrikethrough(), '\striked1'); $content .= $this->getValueIf($style->isStrikethrough() === false && $style->isDoubleStrikethrough() === false, '\strike0'); - $content .= $this->getValueIf($style->isSuperScript(), '\super'); - $content .= $this->getValueIf($style->isSubScript(), '\sub'); + + // Small caps, all caps $content .= $this->getValueIf($style->isSmallCaps(), '\scaps'); $content .= $this->getValueIf($style->isAllCaps(), '\caps'); - $content .= $this->getValueIf($style->getFgColor() !== null, '\highlight' . $this->fgColorIndex); + + // Hidden text $content .= $this->getValueIf($style->isHidden(), '\v'); $content .= $this->getValueIf($style->isHidden() === false, '\v0'); + // Underline + if (isset($underlines[$style->getUnderline()])) { + $content .= $underlines[$style->getUnderline()]; + } + + // Foreground color + $content .= $this->getValueIf($style->getFgColor() !== null, '\highlight' . $this->fgColorIndex); + + // Superscript/subscript + $content .= $this->getValueIf($style->isSuperScript(), '\super'); + $content .= $this->getValueIf($style->isSubScript(), '\sub'); + // Spacing $content .= $this->getValueIf($style->getScale() !== null, '\charscalex' . $style->getScale()); - $content .= $this->getValueIf($style->getSpacing() !== null, '\expnd' . $style->getSpacing()); + $content .= $this->getValueIf($style->getSpacing() !== null, '\expnd' . $style->getSpacing() * 0.2); + $content .= $this->getValueIf($style->getSpacing() !== null, '\expndtw' . $style->getSpacing()); $content .= $this->getValueIf($style->getKerning() !== null, '\kerning' . $style->getKerning() * 2); - $content .= $this->getValueIf($style->getPosition() !== null, '\up' . $style->getPosition()); - // General - $content .= $this->getValueIf($style->isRTL(), '\rtlch'); - $content .= $this->getValueIf($style->isRTL() === false, '\ltrch'); + // noProof $content .= $this->getValueIf($style->isNoProof(), '\noproof\lang1024'); - if ($style->getLang() !== null) { - if ($style->isNoProof()) { - $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\langnp' . $style->getLang()->getLangId()); - } else { - $content .= $this->getValueIf($style->getLang()->getLangId() !== null, '\lang' . $style->getLang()->getLangId()); - } - } - // Other (Font settings currently not included in getStyleValues() array) - // Shading needs to be set to make background color work in Word, see page 23 of RTF specification. + // Bakground-Color $content .= $this->getValueIf($style->getBgColor() !== null, '\chshdng0\chcbpat' . $this->bgColorIndex . '\cb' . $this->bgColorIndex); - if (empty($content)) { - return $content; - } + // RTL + $content .= $this->getValueIf($style->isRTL(), '\rtlch'); + $content .= $this->getValueIf($style->isRTL() === false, '\ltrch'); + + // Position + $content .= $this->getValueIf($style->getPosition() !== null, '\up' . $style->getPosition()); return $content . ' '; } From d04293e77193d19d820a1bce8292f49477370402 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 17 Oct 2025 14:43:24 -0500 Subject: [PATCH 76/83] Update Font.php --- src/PhpWord/Writer/RTF/Style/Font.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 29fe9f1c9a..0185dbdbb4 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -134,10 +134,10 @@ public function write() $content .= $this->getValueIf($style->isSubScript(), '\sub'); // Spacing - $content .= $this->getValueIf($style->getScale() !== null, '\charscalex' . $style->getScale()); - $content .= $this->getValueIf($style->getSpacing() !== null, '\expnd' . $style->getSpacing() * 0.2); - $content .= $this->getValueIf($style->getSpacing() !== null, '\expndtw' . $style->getSpacing()); - $content .= $this->getValueIf($style->getKerning() !== null, '\kerning' . $style->getKerning() * 2); + $content .= $this->getValueIf($style->getScale() !== null, '\charscalex' . round($style->getScale())); + $content .= $this->getValueIf($style->getSpacing() !== null, '\expnd' . round($style->getSpacing() * 0.2)); + $content .= $this->getValueIf($style->getSpacing() !== null, '\expndtw' . round($style->getSpacing())); + $content .= $this->getValueIf($style->getKerning() !== null, '\kerning' . round($style->getKerning() * 2)); // noProof $content .= $this->getValueIf($style->isNoProof(), '\noproof\lang1024'); @@ -152,6 +152,9 @@ public function write() // Position $content .= $this->getValueIf($style->getPosition() !== null, '\up' . $style->getPosition()); + if (empty($content)) { + return $content; + } return $content . ' '; } From 7774093085d370e22892930d5c7f021fe389c50e Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 17 Oct 2025 14:49:22 -0500 Subject: [PATCH 77/83] Update Font.php --- src/PhpWord/Writer/RTF/Style/Font.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 0185dbdbb4..18d118d2a0 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -134,9 +134,9 @@ public function write() $content .= $this->getValueIf($style->isSubScript(), '\sub'); // Spacing - $content .= $this->getValueIf($style->getScale() !== null, '\charscalex' . round($style->getScale())); + $content .= $this->getValueIf($style->getScale() !== null, '\charscalex' . round($style->getScale() ?? 0)); $content .= $this->getValueIf($style->getSpacing() !== null, '\expnd' . round($style->getSpacing() * 0.2)); - $content .= $this->getValueIf($style->getSpacing() !== null, '\expndtw' . round($style->getSpacing())); + $content .= $this->getValueIf($style->getSpacing() !== null, '\expndtw' . round($style->getSpacing() ?? 0)); $content .= $this->getValueIf($style->getKerning() !== null, '\kerning' . round($style->getKerning() * 2)); // noProof @@ -155,6 +155,7 @@ public function write() if (empty($content)) { return $content; } + return $content . ' '; } From 8f8be80f80b820cbbdc626ccdfeef7d2c22b2aca Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 17 Oct 2025 14:53:34 -0500 Subject: [PATCH 78/83] Update ElementTest.php --- tests/PhpWordTests/Writer/RTF/ElementTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/ElementTest.php b/tests/PhpWordTests/Writer/RTF/ElementTest.php index d22b08c02a..231e12f08f 100644 --- a/tests/PhpWordTests/Writer/RTF/ElementTest.php +++ b/tests/PhpWordTests/Writer/RTF/ElementTest.php @@ -213,7 +213,7 @@ public function testRubyTitle(): void $element = $section->addTitle($textRun, 1); $elwrite = new RTF\Element\Title($parentWriter, $element); - $expect = "\\pard\\nowidctlpar \\sb0\\sa2{\\outlinelevel0{\\fs48\\cf0\\b base text (ruby)}\\par\n}"; + $expect = "\\pard\\nowidctlpar \\sb0\\sa2{\\outlinelevel0{\\cf0\\fs48\\b base text (ruby)}\\par\n}"; self::assertEquals($expect, $this->removeCr($elwrite)); } } From 107fc28b861e2440d37ef6e84afeabb57436fbab Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 17 Oct 2025 14:56:04 -0500 Subject: [PATCH 79/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index b4deccafa6..9a86595da2 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -60,7 +60,7 @@ public function testFontColor(): void $style->setColor($style::FGCOLOR_YELLOW); $style->setFgColor($style::FGCOLOR_RED); $style->setBgColor('#123456'); - $expect = '\f0\fs48\cf0\highlight0\cb0 '; + $expect = '\f0\cf0\fs48\highlight0\chshdng0\chcbpat0\cb0 '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -88,7 +88,7 @@ public function testFontColorRegistered(): void $element->setText('Test'); $element->setFontStyle($style); - $expect = '{\f1\fs48\cf1\highlight2\cb3 Test}'; + $expect = '{\f1\cf1\fs48\highlight2\chshdng0\chcbpat3\cb3 Test}'; self::assertEquals($expect, $this->removeCr($writer)); } @@ -110,7 +110,7 @@ public function testFontFormatting(): void $style->setItalic(true); $style->setNoProof(true); $style->setSubScript(true); - $expect = '\b\i\striked1\sub\caps\v\noproof\lang1024 '; + $expect = '\b\i\striked1\caps\v\sub\noproof\lang1024 '; self::assertEquals($expect, $this->removeCr($writer)); $style->setSmallCaps(true); @@ -228,12 +228,12 @@ public function testFontLang(): void $style->setRTL(true); $style->setLang(Language::KO_KR); - $expect = '\rtlch\lang1042 '; + $expect = '\lang1042\rtlch '; self::assertEquals($expect, $this->removeCr($writer)); $style->setRTL(false); $style->setLang(Language::EN_US); - $expect = '\ltrch\lang1033 '; + $expect = '\lang1033\ltrch '; self::assertEquals($expect, $this->removeCr($writer)); } @@ -251,7 +251,7 @@ public function testFontSpacing(): void $style->setSpacing(4); $style->setKerning(100); $style->setPosition(10); - $expect = '\charscalex5\expnd4\kerning200\up10 '; + $expect = '\charscalex5\expnd1\expndtw4\kerning200\up10 '; self::assertEquals($expect, $this->removeCr($writer)); } } From c4fbd60b762ec9a829b2888ee5c74e6f4ac79148 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 17 Oct 2025 14:57:51 -0500 Subject: [PATCH 80/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 9a86595da2..8d4866d54d 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -117,7 +117,7 @@ public function testFontFormatting(): void $style->setStrikethrough(true); $style->setSuperScript(true); $style->setNoProof(false); - $expect = '\b\i\strike\super\scaps\v '; + $expect = '\b\i\strike\scaps\v\super '; self::assertEquals($expect, $this->removeCr($writer)); // Disable styles (in case default is enabled) From 4c1c1273749a7474bd59a59de306a102035376a6 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 25 Oct 2025 08:59:20 -0500 Subject: [PATCH 81/83] Update Header.php - Register Default Color --- src/PhpWord/Writer/RTF/Part/Header.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PhpWord/Writer/RTF/Part/Header.php b/src/PhpWord/Writer/RTF/Part/Header.php index ea181f3d65..23607547e0 100644 --- a/src/PhpWord/Writer/RTF/Part/Header.php +++ b/src/PhpWord/Writer/RTF/Part/Header.php @@ -188,6 +188,7 @@ private function registerFont(): void { $phpWord = $this->getParentWriter()->getPhpWord(); $this->fontTable[] = Settings::getDefaultFontName(); + $this->colorTable[] = Settings::getDefaultFontColor(); // Search named styles $styles = Style::getStyles(); From 1655031a65476e8d2eaf61c3aea2fbab7c986367 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 25 Oct 2025 09:03:10 -0500 Subject: [PATCH 82/83] Update FontTest.php - Registering default font color shifted color table. --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 8d4866d54d..241fc0df72 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -88,7 +88,7 @@ public function testFontColorRegistered(): void $element->setText('Test'); $element->setFontStyle($style); - $expect = '{\f1\cf1\fs48\highlight2\chshdng0\chcbpat3\cb3 Test}'; + $expect = '{\f1\cf2\fs48\highlight3\chshdng0\chcbpat3\cb4 Test}'; self::assertEquals($expect, $this->removeCr($writer)); } From 7c6de8ae16ce031cce23f245e7ff338f77a592a8 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Sat, 25 Oct 2025 09:11:35 -0500 Subject: [PATCH 83/83] Update FontTest.php --- tests/PhpWordTests/Writer/RTF/Style/FontTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php index 241fc0df72..fc3bf10b46 100644 --- a/tests/PhpWordTests/Writer/RTF/Style/FontTest.php +++ b/tests/PhpWordTests/Writer/RTF/Style/FontTest.php @@ -88,7 +88,7 @@ public function testFontColorRegistered(): void $element->setText('Test'); $element->setFontStyle($style); - $expect = '{\f1\cf2\fs48\highlight3\chshdng0\chcbpat3\cb4 Test}'; + $expect = '{\f1\cf2\fs48\highlight3\chshdng0\chcbpat4\cb4 Test}'; self::assertEquals($expect, $this->removeCr($writer)); }