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 1/9] 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 2/9] 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 3/9] 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 4/9] 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 5/9] 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 6/9] 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 7/9] 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 8/9] 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 9/9] 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 {