Skip to content

Commit 5cc0fc3

Browse files
committed
Writer ODText: Support Default font color
1 parent 269a810 commit 5cc0fc3

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

docs/changes/1.x/1.4.0.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
- Added support for PHP 8.4 by [@Progi1984](https://github.com/Progi1984) in [#2660](https://github.com/PHPOffice/PHPWord/pull/2660)
1313
- Autoload : Allow to use PHPWord without Composer fixing [#2543](https://github.com/PHPOffice/PHPWord/issues/2543), [#2552](https://github.com/PHPOffice/PHPWord/issues/2552), [#2716](https://github.com/PHPOffice/PHPWord/issues/2716), [#2717](https://github.com/PHPOffice/PHPWord/issues/2717) in [#2722](https://github.com/PHPOffice/PHPWord/pull/2722)
1414
- Add Default font color for Word by [@Collie-IT](https://github.com/Collie-IT) in [#2700](https://github.com/PHPOffice/PHPWord/pull/2700)
15-
- Writer HTML: Support Default font color by [@MichaelPFrey](https://github.com/MichaelPFrey)
15+
- Writer HTML: Support Default font color by [@MichaelPFrey](https://github.com/MichaelPFrey) in [#2773](https://github.com/PHPOffice/PHPWord/pull/2773)
16+
- Writer ODText: Support Default font color by [@MichaelPFrey](https://github.com/MichaelPFrey)
1617
- Add basic ruby text (phonetic guide) support for Word2007 and HTML Reader/Writer, RTF Writer, basic support for ODT writing by [@Deadpikle](https://github.com/Deadpikle) in [#2727](https://github.com/PHPOffice/PHPWord/pull/2727)
1718

1819
### Bug fixes
@@ -35,3 +36,9 @@
3536
- Deprecate `PhpOffice\PhpWord\Style\Paragraph::setIndent()` : Use `PhpOffice\PhpWord\Style\Paragraph::setIndentLeft()`
3637

3738
### BC Breaks
39+
40+
### Note
41+
- Writer ODText previously used to set 'style:use-window-font-color' to 'true', now it is set to 'false'.
42+
The effect of this attribute is "implementation dependent" (if implemented at all).
43+
Setting it to false allows setting a default font color and improves interoperabilt,
44+
but may break certain specific use cases.

src/PhpWord/Writer/ODText/Part/Styles.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ private function writeDefault(XMLWriter $xmlWriter): void
9292

9393
// Font
9494
$xmlWriter->startElement('style:text-properties');
95-
$xmlWriter->writeAttribute('style:use-window-font-color', 'true');
95+
$xmlWriter->writeAttribute('style:use-window-font-color', 'false');
9696
$xmlWriter->writeAttribute('style:font-name', Settings::getDefaultFontName());
9797
$xmlWriter->writeAttribute('fo:font-size', Settings::getDefaultFontSize() . 'pt');
9898
$xmlWriter->writeAttribute('fo:language', $latinLang[0]);
9999
$xmlWriter->writeAttribute('fo:country', $latinLang[1]);
100+
$xmlWriter->writeAttribute('fo:color', '#' . Settings::getDefaultFontColor());
100101
$xmlWriter->writeAttribute('style:letter-kerning', 'true');
101102
$xmlWriter->writeAttribute('style:font-name-asian', Settings::getDefaultFontName() . '2');
102103
$xmlWriter->writeAttribute('style:font-size-asian', Settings::getDefaultFontSize() . 'pt');

tests/PhpWordTests/Writer/ODText/Style/FontTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,45 @@ protected function tearDown(): void
3434
TestHelperDOCX::clear();
3535
}
3636

37+
public function testDefaultDefaults(): void
38+
{
39+
//$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
40+
41+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
42+
43+
//$phpWord->setDefaultFontColor($defaultFontColor);
44+
45+
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
46+
47+
$file = 'styles.xml';
48+
49+
$path = '/office:document-styles/office:styles/style:default-style/style:text-properties';
50+
self::assertTrue($doc->elementExists($path, $file));
51+
$element = $doc->getElement($path, $file);
52+
53+
self::assertEquals('#000000', $element->getAttribute('fo:color'));
54+
}
55+
56+
public function testSettingDefaults(): void
57+
{
58+
//$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
59+
60+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
61+
62+
$defaultFontColor = '00FF00';
63+
$phpWord->setDefaultFontColor($defaultFontColor);
64+
65+
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
66+
67+
$file = 'styles.xml';
68+
69+
$path = '/office:document-styles/office:styles/style:default-style/style:text-properties';
70+
self::assertTrue($doc->elementExists($path, $file));
71+
$element = $doc->getElement($path, $file);
72+
73+
self::assertEquals('#' . $defaultFontColor, $element->getAttribute('fo:color'));
74+
}
75+
3776
/**
3877
* Test colors.
3978
*/

0 commit comments

Comments
 (0)