From 50313116ff7561cf9c2bd99edc3822a671a34b91 Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:36:18 +0100 Subject: [PATCH 01/19] Add default font color for Word (.docx) Adds the abillity to add a default font color for generated .docx. --- src/PhpWord/PhpWord.php | 21 +++++++++++++++ src/PhpWord/Settings.php | 29 +++++++++++++++++++++ src/PhpWord/Writer/Word2007/Part/Styles.php | 4 +++ 3 files changed, 54 insertions(+) diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index cf6f16ae02..8d8142ba88 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -255,6 +255,27 @@ public function setDefaultFontName($fontName): void { Settings::setDefaultFontName($fontName); } + + /** + * Set default font color. + * + * @param string $fontColor + */ + public function setDefaultFontColor($fontColor): void + { + Settings::setDefaultFontColor($fontColor); + } + + /** + * Get default font color. + * + * @return string + */ + public function getDefaultFontColor() + { + return Settings::getDefaultFontColor(); + } + /** * Get default font size. diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php index 984486ccfe..3983d6da06 100644 --- a/src/PhpWord/Settings.php +++ b/src/PhpWord/Settings.php @@ -117,6 +117,13 @@ class Settings */ private static $defaultFontName = self::DEFAULT_FONT_NAME; + /** + * Default font color. + * + * @var string + */ + private static $defaultFontColor = self::DEFAULT_FONT_COLOR; + /** * Default font size. * @@ -367,6 +374,28 @@ public static function setDefaultFontName(string $value): bool return false; } + + /** + * Get default font color. + */ + public static function getDefaultFontColor(): string + { + return self::$defaultFontColor; + } + + /** + * Set default font color. + */ + public static function setDefaultFontColor(string $value): bool + { + if (trim($value) !== '') { + self::$defaultFontColor = $value; + + return true; + } + + return false; + } /** * Get default font size. diff --git a/src/PhpWord/Writer/Word2007/Part/Styles.php b/src/PhpWord/Writer/Word2007/Part/Styles.php index 2112fd3ce6..c20c465d5c 100644 --- a/src/PhpWord/Writer/Word2007/Part/Styles.php +++ b/src/PhpWord/Writer/Word2007/Part/Styles.php @@ -84,6 +84,7 @@ private function writeDefaultStyles(XMLWriter $xmlWriter, $styles): void $phpWord = $this->getParentWriter()->getPhpWord(); $fontName = $phpWord->getDefaultFontName(); $fontSize = $phpWord->getDefaultFontSize(); + $fontColor = $phpWord->getDefaultFontColor(); $language = $phpWord->getSettings()->getThemeFontLang(); $latinLanguage = ($language == null || $language->getLatin() === null) ? 'en-US' : $language->getLatin(); @@ -97,6 +98,9 @@ private function writeDefaultStyles(XMLWriter $xmlWriter, $styles): void $xmlWriter->writeAttribute('w:eastAsia', $fontName); $xmlWriter->writeAttribute('w:cs', $fontName); $xmlWriter->endElement(); // w:rFonts + $xmlWriter->startElement('w:color'); + $xmlWriter->writeAttribute('w:val', $fontColor); + $xmlWriter->endElement(); $xmlWriter->startElement('w:sz'); $xmlWriter->writeAttribute('w:val', $fontSize * 2); $xmlWriter->endElement(); // w:sz From 61c3375570794eed99eb6cc11cf9801e6084c9c5 Mon Sep 17 00:00:00 2001 From: MichaelFrey Date: Fri, 22 Nov 2024 17:52:41 +0100 Subject: [PATCH 02/19] fix format --- src/PhpWord/PhpWord.php | 9 ++++----- src/PhpWord/Settings.php | 8 ++++---- src/PhpWord/Writer/Word2007/Part/Styles.php | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index 8d8142ba88..c0b88f7cbc 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -255,8 +255,8 @@ public function setDefaultFontName($fontName): void { Settings::setDefaultFontName($fontName); } - - /** + + /** * Set default font color. * * @param string $fontColor @@ -265,8 +265,8 @@ public function setDefaultFontColor($fontColor): void { Settings::setDefaultFontColor($fontColor); } - - /** + + /** * Get default font color. * * @return string @@ -276,7 +276,6 @@ public function getDefaultFontColor() return Settings::getDefaultFontColor(); } - /** * Get default font size. * diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php index 3983d6da06..d50a08e5b6 100644 --- a/src/PhpWord/Settings.php +++ b/src/PhpWord/Settings.php @@ -117,13 +117,13 @@ class Settings */ private static $defaultFontName = self::DEFAULT_FONT_NAME; - /** + /** * Default font color. * * @var string */ private static $defaultFontColor = self::DEFAULT_FONT_COLOR; - + /** * Default font size. * @@ -374,8 +374,8 @@ public static function setDefaultFontName(string $value): bool return false; } - - /** + + /** * Get default font color. */ public static function getDefaultFontColor(): string diff --git a/src/PhpWord/Writer/Word2007/Part/Styles.php b/src/PhpWord/Writer/Word2007/Part/Styles.php index c20c465d5c..1d75b34c45 100644 --- a/src/PhpWord/Writer/Word2007/Part/Styles.php +++ b/src/PhpWord/Writer/Word2007/Part/Styles.php @@ -84,7 +84,7 @@ private function writeDefaultStyles(XMLWriter $xmlWriter, $styles): void $phpWord = $this->getParentWriter()->getPhpWord(); $fontName = $phpWord->getDefaultFontName(); $fontSize = $phpWord->getDefaultFontSize(); - $fontColor = $phpWord->getDefaultFontColor(); + $fontColor = $phpWord->getDefaultFontColor(); $language = $phpWord->getSettings()->getThemeFontLang(); $latinLanguage = ($language == null || $language->getLatin() === null) ? 'en-US' : $language->getLatin(); @@ -98,9 +98,9 @@ private function writeDefaultStyles(XMLWriter $xmlWriter, $styles): void $xmlWriter->writeAttribute('w:eastAsia', $fontName); $xmlWriter->writeAttribute('w:cs', $fontName); $xmlWriter->endElement(); // w:rFonts - $xmlWriter->startElement('w:color'); + $xmlWriter->startElement('w:color'); $xmlWriter->writeAttribute('w:val', $fontColor); - $xmlWriter->endElement(); + $xmlWriter->endElement(); $xmlWriter->startElement('w:sz'); $xmlWriter->writeAttribute('w:val', $fontSize * 2); $xmlWriter->endElement(); // w:sz From 0658b4e9eb071a2f2ca6beda0753fb54c629d7f6 Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:37:07 +0100 Subject: [PATCH 03/19] Update 1.4.0.md Add default font color --- docs/changes/1.x/1.4.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changes/1.x/1.4.0.md b/docs/changes/1.x/1.4.0.md index 8db845337d..cfff0810b1 100644 --- a/docs/changes/1.x/1.4.0.md +++ b/docs/changes/1.x/1.4.0.md @@ -6,6 +6,7 @@ - Writer ODText: Support for ListItemRun by [@Progi1984](https://github.com/Progi1984) fixing [#2159](https://github.com/PHPOffice/PHPWord/issues/2159), [#2620](https://github.com/PHPOffice/PHPWord/issues/2620) in [#2669](https://github.com/PHPOffice/PHPWord/pull/2669) - Writer HTML: Support for vAlign in Tables by [@SpraxDev](https://github.com/SpraxDev) in [#2675](https://github.com/PHPOffice/PHPWord/pull/2675) +- Add Default font color for Word by [@Collie-IT](https://github.com/Collie-IT) in [#2700](https://github.com/PHPOffice/PHPWord/pull/2700) ### Bug fixes From a60896c984dfe679f5cf596dfab10ca07e9278cc Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:38:55 +0100 Subject: [PATCH 04/19] Update introduction.md Add documentation default font color --- docs/usage/introduction.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/usage/introduction.md b/docs/usage/introduction.md index b3a101ab0d..1a87fe4b93 100644 --- a/docs/usage/introduction.md +++ b/docs/usage/introduction.md @@ -128,13 +128,14 @@ You can alter the default paper by using the following function: ### Default font -By default, every text appears in Arial 10 point. You can alter the +By default, every text appears in Arial 10 point in the color red (FF0000). You can alter the default font by using the following two functions: ``` php setDefaultFontName('Times New Roman'); +$phpWord->setDefaultFontColor('FF0000'); $phpWord->setDefaultFontSize(12); ``` @@ -381,4 +382,4 @@ To control whether or not words in all capital letters shall be hyphenated use t getSettings()->setDoNotHyphenateCaps(true); -``` \ No newline at end of file +``` From d44bd6fc33b1670db52b343ed4d48cf20dcf1877 Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:39:34 +0100 Subject: [PATCH 05/19] Update introduction.md Correct default value --- docs/usage/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/introduction.md b/docs/usage/introduction.md index 1a87fe4b93..8a7e428c56 100644 --- a/docs/usage/introduction.md +++ b/docs/usage/introduction.md @@ -128,7 +128,7 @@ You can alter the default paper by using the following function: ### Default font -By default, every text appears in Arial 10 point in the color red (FF0000). You can alter the +By default, every text appears in Arial 10 point in the color black (000000). You can alter the default font by using the following two functions: ``` php From 6c5f33e4eb1ea2c85bde5f4e7367bbedb9e533e9 Mon Sep 17 00:00:00 2001 From: MichaelFrey Date: Fri, 22 Nov 2024 20:33:38 +0100 Subject: [PATCH 06/19] add tests for SetGetDefaultFontColor --- src/PhpWord/Reader/Word2007/Styles.php | 3 +++ tests/PhpWordTests/PhpWordTest.php | 12 ++++++++++++ tests/PhpWordTests/SettingsTest.php | 16 ++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/PhpWord/Reader/Word2007/Styles.php b/src/PhpWord/Reader/Word2007/Styles.php index 760adf9493..f43199ab33 100644 --- a/src/PhpWord/Reader/Word2007/Styles.php +++ b/src/PhpWord/Reader/Word2007/Styles.php @@ -46,6 +46,9 @@ public function read(PhpWord $phpWord): void if (array_key_exists('size', $fontDefaultStyle)) { $phpWord->setDefaultFontSize($fontDefaultStyle['size']); } + if (array_key_exists('color', $fontDefaultStyle)) { + $phpWord->setDefaultFontColor($fontDefaultStyle['color']); + } if (array_key_exists('lang', $fontDefaultStyle)) { $phpWord->getSettings()->setThemeFontLang(new Language($fontDefaultStyle['lang'])); } diff --git a/tests/PhpWordTests/PhpWordTest.php b/tests/PhpWordTests/PhpWordTest.php index 33118a11e8..a3c74993b1 100644 --- a/tests/PhpWordTests/PhpWordTest.php +++ b/tests/PhpWordTests/PhpWordTest.php @@ -82,6 +82,18 @@ public function testSetGetDefaultFontSize(): void self::assertEquals($fontSize, $phpWord->getDefaultFontSize()); } + /** + * Test set/get default font color. + */ + public function testSetGetDefaultFontColor(): void + { + $phpWord = new PhpWord(); + $fontColor = 'FF0000'; + self::assertEquals(Settings::DEFAULT_FONT_COLOR, $phpWord->getDefaultFontColor()); + $phpWord->setDefaultFontColor($fontColor); + self::assertEquals($fontColor, $phpWord->getDefaultFontColor()); + } + /** * Test set default paragraph style. */ diff --git a/tests/PhpWordTests/SettingsTest.php b/tests/PhpWordTests/SettingsTest.php index 46c72eab28..10dde7b55a 100644 --- a/tests/PhpWordTests/SettingsTest.php +++ b/tests/PhpWordTests/SettingsTest.php @@ -59,6 +59,7 @@ class SettingsTest extends TestCase protected function setUp(): void { $this->compatibility = Settings::hasCompatibility(); + $this->defaultFontColor = Settings::getDefaultFontColor(); $this->defaultFontSize = Settings::getDefaultFontSize(); $this->defaultFontName = Settings::getDefaultFontName(); $this->defaultPaper = Settings::getDefaultPaper(); @@ -75,6 +76,7 @@ protected function setUp(): void protected function tearDown(): void { Settings::setCompatibility($this->compatibility); + Settings::setDefaultFontColor($this->defaultFontColor); Settings::setDefaultFontSize($this->defaultFontSize); Settings::setDefaultFontName($this->defaultFontName); Settings::setDefaultPaper($this->defaultPaper); @@ -236,6 +238,20 @@ public function testSetGetDefaultFontSize(): void self::assertEquals(12.5, Settings::getDefaultFontSize()); } + /** + * Test set/get default font color. + */ + public function testSetGetDefaultFontColor(): void + { + self::assertEquals(Settings::DEFAULT_FONT_COLOR, Settings::getDefaultFontColor()); + self::assertFalse(Settings::setDefaultFontColor(' ')); + self::assertEquals(Settings::DEFAULT_FONT_COLOR, Settings::getDefaultFontColor()); + self::assertTrue(Settings::setDefaultFontColor('FF0000')); + self::assertEquals('FF0000', Settings::getDefaultFontColor()); + self::assertFalse(Settings::setDefaultFontColor(' ')); + self::assertEquals('FF0000', Settings::getDefaultFontColor()); + } + /** * Test set/get default paper. */ From b398d4d4b99be9b96c701d3d6a019f9c625e5736 Mon Sep 17 00:00:00 2001 From: MichaelFrey Date: Fri, 22 Nov 2024 22:36:46 +0100 Subject: [PATCH 07/19] debug test --- phpword.ini.dist | 1 + tests/PhpWordTests/SettingsTest.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/phpword.ini.dist b/phpword.ini.dist index f3f66dbe2e..21d3b50609 100644 --- a/phpword.ini.dist +++ b/phpword.ini.dist @@ -14,6 +14,7 @@ outputEscapingEnabled = false defaultFontName = Arial defaultFontSize = 10 +defaultFontColor = 000000 [Paper] diff --git a/tests/PhpWordTests/SettingsTest.php b/tests/PhpWordTests/SettingsTest.php index 10dde7b55a..843ade7159 100644 --- a/tests/PhpWordTests/SettingsTest.php +++ b/tests/PhpWordTests/SettingsTest.php @@ -30,6 +30,9 @@ class SettingsTest extends TestCase { private $compatibility; + /** @var string */ + private $defaultFontColor; + private $defaultFontSize; private $defaultFontName; @@ -287,6 +290,7 @@ public function testLoadConfig(): void 'pdfRendererPath' => '', 'defaultFontName' => 'Arial', 'defaultFontSize' => 10, + 'defaultFontColor' => '000000', 'outputEscapingEnabled' => false, 'defaultPaper' => 'A4', ]; From 8aaa00f2e75444f4d1f0bcc7b5e3707a13e84e4f Mon Sep 17 00:00:00 2001 From: MichaelFrey Date: Fri, 22 Nov 2024 22:40:47 +0100 Subject: [PATCH 08/19] add defaultFontColor to FontTest --- tests/PhpWordTests/Writer/HTML/FontTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/PhpWordTests/Writer/HTML/FontTest.php b/tests/PhpWordTests/Writer/HTML/FontTest.php index 442c2639c9..87b58a516b 100644 --- a/tests/PhpWordTests/Writer/HTML/FontTest.php +++ b/tests/PhpWordTests/Writer/HTML/FontTest.php @@ -33,6 +33,9 @@ class FontTest extends \PHPUnit\Framework\TestCase /** @var float|int */ private $defaultFontSize; + /** @var string */ + private $defaultFontColor; + /** * Executed before each method of the class. */ @@ -40,6 +43,7 @@ protected function setUp(): void { $this->defaultFontName = Settings::getDefaultFontName(); $this->defaultFontSize = Settings::getDefaultFontSize(); + $this->defaultFontColor = Settings::getDefaultFontColor(); } /** @@ -49,6 +53,7 @@ protected function tearDown(): void { Settings::setDefaultFontName($this->defaultFontName); Settings::setDefaultFontSize($this->defaultFontSize); + Settings::setDefaultFontColor($this->defaultFontColor); } /** From 0532b0eabec02d75b0f2b44b3d13ee0ecb10cc0b Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Sun, 24 Nov 2024 21:34:46 +0100 Subject: [PATCH 09/19] Update src/PhpWord/PhpWord.php As suggested Co-authored-by: Progi1984 --- src/PhpWord/PhpWord.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index c0b88f7cbc..af5c470081 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -261,7 +261,7 @@ public function setDefaultFontName($fontName): void * * @param string $fontColor */ - public function setDefaultFontColor($fontColor): void + public function setDefaultFontColor(string $fontColor): void { Settings::setDefaultFontColor($fontColor); } From 56d3411cca26b1d642d4de2255cad50a2b12d6d7 Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Sun, 24 Nov 2024 21:35:06 +0100 Subject: [PATCH 10/19] Update src/PhpWord/PhpWord.php As suggested Co-authored-by: Progi1984 --- src/PhpWord/PhpWord.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index af5c470081..0678f1e70d 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -271,7 +271,7 @@ public function setDefaultFontColor(string $fontColor): void * * @return string */ - public function getDefaultFontColor() + public function getDefaultFontColor(): string { return Settings::getDefaultFontColor(); } From 13bcec70bf5d200c098f67ab5e658d09a68efa72 Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:37:07 +0100 Subject: [PATCH 11/19] Update 1.4.0.md Add default font color --- docs/changes/1.x/1.4.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changes/1.x/1.4.0.md b/docs/changes/1.x/1.4.0.md index 8db845337d..cfff0810b1 100644 --- a/docs/changes/1.x/1.4.0.md +++ b/docs/changes/1.x/1.4.0.md @@ -6,6 +6,7 @@ - Writer ODText: Support for ListItemRun by [@Progi1984](https://github.com/Progi1984) fixing [#2159](https://github.com/PHPOffice/PHPWord/issues/2159), [#2620](https://github.com/PHPOffice/PHPWord/issues/2620) in [#2669](https://github.com/PHPOffice/PHPWord/pull/2669) - Writer HTML: Support for vAlign in Tables by [@SpraxDev](https://github.com/SpraxDev) in [#2675](https://github.com/PHPOffice/PHPWord/pull/2675) +- Add Default font color for Word by [@Collie-IT](https://github.com/Collie-IT) in [#2700](https://github.com/PHPOffice/PHPWord/pull/2700) ### Bug fixes From f0885cdf510be91ae7e5d1e2346bfa0b8592620f Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:38:55 +0100 Subject: [PATCH 12/19] Update introduction.md Add documentation default font color --- docs/usage/introduction.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/usage/introduction.md b/docs/usage/introduction.md index b3a101ab0d..1a87fe4b93 100644 --- a/docs/usage/introduction.md +++ b/docs/usage/introduction.md @@ -128,13 +128,14 @@ You can alter the default paper by using the following function: ### Default font -By default, every text appears in Arial 10 point. You can alter the +By default, every text appears in Arial 10 point in the color red (FF0000). You can alter the default font by using the following two functions: ``` php setDefaultFontName('Times New Roman'); +$phpWord->setDefaultFontColor('FF0000'); $phpWord->setDefaultFontSize(12); ``` @@ -381,4 +382,4 @@ To control whether or not words in all capital letters shall be hyphenated use t getSettings()->setDoNotHyphenateCaps(true); -``` \ No newline at end of file +``` From 6a03f95efca92664bf63dc3fd6e4f3e186930982 Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:39:34 +0100 Subject: [PATCH 13/19] Update introduction.md Correct default value --- docs/usage/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/introduction.md b/docs/usage/introduction.md index 1a87fe4b93..8a7e428c56 100644 --- a/docs/usage/introduction.md +++ b/docs/usage/introduction.md @@ -128,7 +128,7 @@ You can alter the default paper by using the following function: ### Default font -By default, every text appears in Arial 10 point in the color red (FF0000). You can alter the +By default, every text appears in Arial 10 point in the color black (000000). You can alter the default font by using the following two functions: ``` php From 6a30d7001a203ebf154fabf92bbdee877fa471d8 Mon Sep 17 00:00:00 2001 From: MichaelFrey Date: Fri, 22 Nov 2024 20:33:38 +0100 Subject: [PATCH 14/19] add tests for SetGetDefaultFontColor --- src/PhpWord/Reader/Word2007/Styles.php | 3 +++ tests/PhpWordTests/PhpWordTest.php | 12 ++++++++++++ tests/PhpWordTests/SettingsTest.php | 16 ++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/PhpWord/Reader/Word2007/Styles.php b/src/PhpWord/Reader/Word2007/Styles.php index 760adf9493..f43199ab33 100644 --- a/src/PhpWord/Reader/Word2007/Styles.php +++ b/src/PhpWord/Reader/Word2007/Styles.php @@ -46,6 +46,9 @@ public function read(PhpWord $phpWord): void if (array_key_exists('size', $fontDefaultStyle)) { $phpWord->setDefaultFontSize($fontDefaultStyle['size']); } + if (array_key_exists('color', $fontDefaultStyle)) { + $phpWord->setDefaultFontColor($fontDefaultStyle['color']); + } if (array_key_exists('lang', $fontDefaultStyle)) { $phpWord->getSettings()->setThemeFontLang(new Language($fontDefaultStyle['lang'])); } diff --git a/tests/PhpWordTests/PhpWordTest.php b/tests/PhpWordTests/PhpWordTest.php index 33118a11e8..a3c74993b1 100644 --- a/tests/PhpWordTests/PhpWordTest.php +++ b/tests/PhpWordTests/PhpWordTest.php @@ -82,6 +82,18 @@ public function testSetGetDefaultFontSize(): void self::assertEquals($fontSize, $phpWord->getDefaultFontSize()); } + /** + * Test set/get default font color. + */ + public function testSetGetDefaultFontColor(): void + { + $phpWord = new PhpWord(); + $fontColor = 'FF0000'; + self::assertEquals(Settings::DEFAULT_FONT_COLOR, $phpWord->getDefaultFontColor()); + $phpWord->setDefaultFontColor($fontColor); + self::assertEquals($fontColor, $phpWord->getDefaultFontColor()); + } + /** * Test set default paragraph style. */ diff --git a/tests/PhpWordTests/SettingsTest.php b/tests/PhpWordTests/SettingsTest.php index 46c72eab28..10dde7b55a 100644 --- a/tests/PhpWordTests/SettingsTest.php +++ b/tests/PhpWordTests/SettingsTest.php @@ -59,6 +59,7 @@ class SettingsTest extends TestCase protected function setUp(): void { $this->compatibility = Settings::hasCompatibility(); + $this->defaultFontColor = Settings::getDefaultFontColor(); $this->defaultFontSize = Settings::getDefaultFontSize(); $this->defaultFontName = Settings::getDefaultFontName(); $this->defaultPaper = Settings::getDefaultPaper(); @@ -75,6 +76,7 @@ protected function setUp(): void protected function tearDown(): void { Settings::setCompatibility($this->compatibility); + Settings::setDefaultFontColor($this->defaultFontColor); Settings::setDefaultFontSize($this->defaultFontSize); Settings::setDefaultFontName($this->defaultFontName); Settings::setDefaultPaper($this->defaultPaper); @@ -236,6 +238,20 @@ public function testSetGetDefaultFontSize(): void self::assertEquals(12.5, Settings::getDefaultFontSize()); } + /** + * Test set/get default font color. + */ + public function testSetGetDefaultFontColor(): void + { + self::assertEquals(Settings::DEFAULT_FONT_COLOR, Settings::getDefaultFontColor()); + self::assertFalse(Settings::setDefaultFontColor(' ')); + self::assertEquals(Settings::DEFAULT_FONT_COLOR, Settings::getDefaultFontColor()); + self::assertTrue(Settings::setDefaultFontColor('FF0000')); + self::assertEquals('FF0000', Settings::getDefaultFontColor()); + self::assertFalse(Settings::setDefaultFontColor(' ')); + self::assertEquals('FF0000', Settings::getDefaultFontColor()); + } + /** * Test set/get default paper. */ From edcfedbb2af47d220a0f51710191e1f8b83c3ddb Mon Sep 17 00:00:00 2001 From: MichaelFrey Date: Fri, 22 Nov 2024 22:36:46 +0100 Subject: [PATCH 15/19] debug test --- phpword.ini.dist | 1 + tests/PhpWordTests/SettingsTest.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/phpword.ini.dist b/phpword.ini.dist index f3f66dbe2e..21d3b50609 100644 --- a/phpword.ini.dist +++ b/phpword.ini.dist @@ -14,6 +14,7 @@ outputEscapingEnabled = false defaultFontName = Arial defaultFontSize = 10 +defaultFontColor = 000000 [Paper] diff --git a/tests/PhpWordTests/SettingsTest.php b/tests/PhpWordTests/SettingsTest.php index 10dde7b55a..843ade7159 100644 --- a/tests/PhpWordTests/SettingsTest.php +++ b/tests/PhpWordTests/SettingsTest.php @@ -30,6 +30,9 @@ class SettingsTest extends TestCase { private $compatibility; + /** @var string */ + private $defaultFontColor; + private $defaultFontSize; private $defaultFontName; @@ -287,6 +290,7 @@ public function testLoadConfig(): void 'pdfRendererPath' => '', 'defaultFontName' => 'Arial', 'defaultFontSize' => 10, + 'defaultFontColor' => '000000', 'outputEscapingEnabled' => false, 'defaultPaper' => 'A4', ]; From 3cdc8851924a11d890ff0647833f4ec9855c3ff6 Mon Sep 17 00:00:00 2001 From: MichaelFrey Date: Fri, 22 Nov 2024 22:40:47 +0100 Subject: [PATCH 16/19] add defaultFontColor to FontTest --- tests/PhpWordTests/Writer/HTML/FontTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/PhpWordTests/Writer/HTML/FontTest.php b/tests/PhpWordTests/Writer/HTML/FontTest.php index 442c2639c9..87b58a516b 100644 --- a/tests/PhpWordTests/Writer/HTML/FontTest.php +++ b/tests/PhpWordTests/Writer/HTML/FontTest.php @@ -33,6 +33,9 @@ class FontTest extends \PHPUnit\Framework\TestCase /** @var float|int */ private $defaultFontSize; + /** @var string */ + private $defaultFontColor; + /** * Executed before each method of the class. */ @@ -40,6 +43,7 @@ protected function setUp(): void { $this->defaultFontName = Settings::getDefaultFontName(); $this->defaultFontSize = Settings::getDefaultFontSize(); + $this->defaultFontColor = Settings::getDefaultFontColor(); } /** @@ -49,6 +53,7 @@ protected function tearDown(): void { Settings::setDefaultFontName($this->defaultFontName); Settings::setDefaultFontSize($this->defaultFontSize); + Settings::setDefaultFontColor($this->defaultFontColor); } /** From 86e9776440ccb49d4f16ccef6a26a7fc2bef61e7 Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Sun, 24 Nov 2024 21:34:46 +0100 Subject: [PATCH 17/19] Update src/PhpWord/PhpWord.php As suggested Co-authored-by: Progi1984 --- src/PhpWord/PhpWord.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index c0b88f7cbc..af5c470081 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -261,7 +261,7 @@ public function setDefaultFontName($fontName): void * * @param string $fontColor */ - public function setDefaultFontColor($fontColor): void + public function setDefaultFontColor(string $fontColor): void { Settings::setDefaultFontColor($fontColor); } From e8c396d7e4ee42f1b413dddae06a890cfe44404f Mon Sep 17 00:00:00 2001 From: Collie-IT <40590185+Collie-IT@users.noreply.github.com> Date: Sun, 24 Nov 2024 21:35:06 +0100 Subject: [PATCH 18/19] Update src/PhpWord/PhpWord.php As suggested Co-authored-by: Progi1984 --- src/PhpWord/PhpWord.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index af5c470081..0678f1e70d 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -271,7 +271,7 @@ public function setDefaultFontColor(string $fontColor): void * * @return string */ - public function getDefaultFontColor() + public function getDefaultFontColor(): string { return Settings::getDefaultFontColor(); } From e0b42c3d3a83e2c50d867d1b9a7bff700b3880f6 Mon Sep 17 00:00:00 2001 From: MichaelFrey Date: Mon, 25 Nov 2024 06:49:30 +0100 Subject: [PATCH 19/19] fix format --- src/PhpWord/PhpWord.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index 0678f1e70d..e67dfb7187 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -258,8 +258,6 @@ public function setDefaultFontName($fontName): void /** * Set default font color. - * - * @param string $fontColor */ public function setDefaultFontColor(string $fontColor): void { @@ -268,8 +266,6 @@ public function setDefaultFontColor(string $fontColor): void /** * Get default font color. - * - * @return string */ public function getDefaultFontColor(): string {