diff --git a/docs/changes/1.x/1.4.0.md b/docs/changes/1.x/1.4.0.md
index 2afadebd5f..634d1d6f31 100644
--- a/docs/changes/1.x/1.4.0.md
+++ b/docs/changes/1.x/1.4.0.md
@@ -17,7 +17,8 @@
- 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)
- Reader HTML: Support font styles for h1/h6 by [@Progi1984](https://github.com/Progi1984) fixing [#2619](https://github.com/PHPOffice/PHPWord/issues/2619) in [#2737](https://github.com/PHPOffice/PHPWord/pull/2737)
- Writer EPub3: Basic support by [@Sambit003](https://github.com/Sambit003) fixing [#55](https://github.com/PHPOffice/PHPWord/issues/55) in [#2724](https://github.com/PHPOffice/PHPWord/pull/2724)
-
+- Writer2007: Added support for background and border color transparency in Text Box element [@chudy20007](https://github.com/Chudy20007) in [#2555](https://github.com/PHPOffice/PHPWord/pull/2555)
+
### Bug fixes
- Writer ODText: Support for images inside a textRun by [@Progi1984](https://github.com/Progi1984) fixing [#2240](https://github.com/PHPOffice/PHPWord/issues/2240) in [#2668](https://github.com/PHPOffice/PHPWord/pull/2668)
@@ -27,6 +28,7 @@
- Reader Word2007: Support Header elements within Title elements by [@SpraxDev](https://github.com/SpraxDev) fixing [#2616](https://github.com/PHPOffice/PHPWord/issues/2616), [#2426](https://github.com/PHPOffice/PHPWord/issues/2426) in [#2674](https://github.com/PHPOffice/PHPWord/pull/2674)
- Reader HTML: Support for inherit value for property line-height by [@Progi1984](https://github.com/Progi1984) fixing [#2683](https://github.com/PHPOffice/PHPWord/issues/2683) in [#2733](https://github.com/PHPOffice/PHPWord/pull/2733)
- Writer HTML: Fixed null string for Text Elements by [@armagedon007](https://github.com/armagedon007) and [@Progi1984](https://github.com/Progi1984) in [#2738](https://github.com/PHPOffice/PHPWord/pull/2738)
+- Template Processor: Fix 0 considered as empty string by [@cavasinf](https://github.com/cavasinf), [@SnipsMine](https://github.com/SnipsMine) and [@Progi1984](https://github.com/Progi1984) fixing [#2572](https://github.com/PHPOffice/PHPWord/issues/2572), [#2703](https://github.com/PHPOffice/PHPWord/issues/2703) in [#2748](https://github.com/PHPOffice/PHPWord/pull/2748)
### Miscellaneous
diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php
index 06026e19d3..c9bfcb1dc3 100644
--- a/src/PhpWord/TemplateProcessor.php
+++ b/src/PhpWord/TemplateProcessor.php
@@ -269,7 +269,7 @@ protected static function ensureMacroCompleted($macro)
*/
protected static function ensureUtf8Encoded($subject)
{
- return $subject ? Text::toUTF8($subject) : '';
+ return (null !== $subject) ? Text::toUTF8($subject) : '';
}
/**
diff --git a/src/PhpWord/Writer/Word2007/Element/TextBox.php b/src/PhpWord/Writer/Word2007/Element/TextBox.php
index e005480802..79011d8d6f 100644
--- a/src/PhpWord/Writer/Word2007/Element/TextBox.php
+++ b/src/PhpWord/Writer/Word2007/Element/TextBox.php
@@ -51,6 +51,13 @@ public function write(): void
if ($style->getBgColor()) {
$xmlWriter->writeAttribute('fillcolor', $style->getBgColor());
+ } else {
+ $xmlWriter->writeAttribute('filled', 'f');
+ }
+
+ if (!$style->getBorderColor()) {
+ $xmlWriter->writeAttribute('stroked', 'f');
+ $xmlWriter->writeAttribute('strokecolor', 'white');
}
$styleWriter->write();
diff --git a/tests/PhpWordTests/TemplateProcessorTest.php b/tests/PhpWordTests/TemplateProcessorTest.php
index 9ba6933e74..d031eb75c1 100644
--- a/tests/PhpWordTests/TemplateProcessorTest.php
+++ b/tests/PhpWordTests/TemplateProcessorTest.php
@@ -1641,4 +1641,101 @@ public function testShouldMakeFieldsUpdateOnOpenWithCustomMacro(): void
$templateProcessor->setUpdateFields(false);
self::assertStringContainsString('', $templateProcessor->getSettingsPart());
}
+
+ public function testEnsureUtf8Encoded(): void
+ {
+ $mainPart = '
+
+
+
+
+
+
+
+ ${stringZero}
+
+
+
+
+
+
+ ${intZero}
+
+
+
+
+
+
+ ${stringTest}
+
+
+
+
+
+
+ ${null}
+
+
+
+
+
+
+ ${floatZero}
+
+
+
+
+
+
+ ${intTen}
+
+
+
+
+
+
+ ${boolFalse}
+
+
+
+
+
+
+ ${boolTrue}
+
+
+
+
+ ';
+ $templateProcessor = new TestableTemplateProcesor($mainPart);
+
+ self::assertEquals(
+ ['stringZero', 'intZero', 'stringTest', 'null', 'floatZero', 'intTen', 'boolFalse', 'boolTrue'],
+ $templateProcessor->getVariables()
+ );
+
+ $templateProcessor->setValue('stringZero', '0');
+ self::assertStringContainsString('0', $templateProcessor->getMainPart());
+
+ $templateProcessor->setValue('intZero', 0);
+ self::assertStringContainsString('0', $templateProcessor->getMainPart());
+
+ $templateProcessor->setValue('stringTest', 'test');
+ self::assertStringContainsString('test', $templateProcessor->getMainPart());
+
+ $templateProcessor->setValue('null', null);
+ self::assertStringContainsString('', $templateProcessor->getMainPart());
+
+ $templateProcessor->setValue('floatZero', 0.00);
+ self::assertStringContainsString('0', $templateProcessor->getMainPart());
+
+ $templateProcessor->setValue('intTen', 10);
+ self::assertStringContainsString('10', $templateProcessor->getMainPart());
+
+ $templateProcessor->setValue('boolFalse', false);
+ self::assertStringContainsString('', $templateProcessor->getMainPart());
+
+ $templateProcessor->setValue('boolTrue', true);
+ self::assertStringContainsString('1', $templateProcessor->getMainPart());
+ }
}
diff --git a/tests/PhpWordTests/Writer/Word2007/Element/TextBoxTest.php b/tests/PhpWordTests/Writer/Word2007/Element/TextBoxTest.php
new file mode 100644
index 0000000000..6d4df65298
--- /dev/null
+++ b/tests/PhpWordTests/Writer/Word2007/Element/TextBoxTest.php
@@ -0,0 +1,84 @@
+setBgColor($bgColor);
+ }
+
+ if ($borderColor !== null) {
+ $style->setBorderColor($borderColor);
+ }
+
+ $textBoxElement = new TextBoxElement($style);
+ $textBox = new TextBox($xmlWriter, $textBoxElement);
+
+ // Act
+ $textBox->write();
+ $output = $xmlWriter->getData();
+
+ // Assert
+ self::assertStringContainsString($expectedFillColorAttribute, $output, 'Background color should be applied.');
+ self::assertStringContainsString($expectedBorderColorAttribute, $output, 'Border color should be applied correctly.');
+ }
+
+ /**
+ * Data provider for testing different combinations of background and border colors.
+ */
+ public static function textBoxColorProvider(): array
+ {
+ return [
+ // Case 1: Background color set, border color set
+ 'With both colors' => [
+ '#FF0000',
+ '#000000',
+ 'fillcolor="#FF0000"',
+ 'stroke color="#000000"',
+ ],
+ // Case 2: Background color set, no border color
+ 'With background only' => [
+ '#00FF00',
+ null,
+ 'fillcolor="#00FF00"',
+ 'stroked="f" strokecolor="white"',
+ ],
+ // Case 3: No background color, border color set
+ 'With border only' => [
+ null,
+ '#123456',
+ 'filled="f"',
+ 'stroke color="#123456"',
+ ],
+ // Case 4: Neither background nor border color set
+ 'Without any colors' => [
+ null,
+ null,
+ 'filled="f"',
+ 'stroked="f" strokecolor="white"',
+ ],
+ ];
+ }
+}