From a52e12d77056a2ce94d459b18a1681b313da3779 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sat, 26 Jul 2025 17:02:23 +0000
Subject: [PATCH 1/2] Initial plan
From 1904d0ecb877b2bac6a3bf5a8fc224ee556c71eb Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sat, 26 Jul 2025 17:14:11 +0000
Subject: [PATCH 2/2] Implement w:sym tag support in Word2007 reader
Co-authored-by: Progi1984 <1533248+Progi1984@users.noreply.github.com>
---
src/PhpWord/Reader/Word2007/AbstractPart.php | 6 ++
.../PhpWordTests/Reader/Word2007/PartTest.php | 62 +++++++++++++++++++
2 files changed, 68 insertions(+)
diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php
index 9d49573d69..4770c039e6 100644
--- a/src/PhpWord/Reader/Word2007/AbstractPart.php
+++ b/src/PhpWord/Reader/Word2007/AbstractPart.php
@@ -551,6 +551,12 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract
$parent->addTextBreak();
} elseif ($node->nodeName == 'w:tab') {
$parent->addText("\t");
+ } elseif ($node->nodeName == 'w:sym') {
+ // Symbol
+ $font = $xmlReader->getAttribute('w:font', $node);
+ $char = $xmlReader->getAttribute('w:char', $node);
+ $textContent = "[{$font},{$char}]";
+ $parent->addText($textContent, $fontStyle, $paragraphStyle);
} elseif ($node->nodeName == 'mc:AlternateContent') {
if ($node->hasChildNodes()) {
// Get fallback instead of mc:Choice to make sure it is compatible
diff --git a/tests/PhpWordTests/Reader/Word2007/PartTest.php b/tests/PhpWordTests/Reader/Word2007/PartTest.php
index 4f19f8b91f..93d22c84b8 100644
--- a/tests/PhpWordTests/Reader/Word2007/PartTest.php
+++ b/tests/PhpWordTests/Reader/Word2007/PartTest.php
@@ -233,4 +233,66 @@ public function testReadHeadingWithOverriddenStyle(): void
self::assertInstanceOf('PhpOffice\PhpWord\Element\Text', $text);
self::assertEquals(' but with parts not in bold', $text->getText());
}
+
+ public function testReadSymbol(): void
+ {
+ $documentXml = '
+
+ Text before symbol
+
+
+
+
+
+ text after symbol
+
+
+
+
+ Another symbol:
+
+
+
+
+ ';
+
+ $phpWord = $this->getDocumentFromString(['document' => $documentXml]);
+
+ $elements = $phpWord->getSection(0)->getElements();
+
+ // Test first paragraph with symbol
+ self::assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $elements[0]);
+ /** @var \PhpOffice\PhpWord\Element\TextRun $textRun1 */
+ $textRun1 = $elements[0];
+
+ /** @var \PhpOffice\PhpWord\Element\Text $text1 */
+ $text1 = $textRun1->getElement(0);
+ self::assertInstanceOf('PhpOffice\PhpWord\Element\Text', $text1);
+ self::assertEquals('Text before symbol ', $text1->getText());
+
+ /** @var \PhpOffice\PhpWord\Element\Text $symbol1 */
+ $symbol1 = $textRun1->getElement(1);
+ self::assertInstanceOf('PhpOffice\PhpWord\Element\Text', $symbol1);
+ self::assertEquals('[Wingdings 2,00A3]', $symbol1->getText());
+
+ /** @var \PhpOffice\PhpWord\Element\Text $text2 */
+ $text2 = $textRun1->getElement(2);
+ self::assertInstanceOf('PhpOffice\PhpWord\Element\Text', $text2);
+ self::assertEquals(' text after symbol', $text2->getText());
+
+ // Test second paragraph with different symbol
+ self::assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $elements[1]);
+ /** @var \PhpOffice\PhpWord\Element\TextRun $textRun2 */
+ $textRun2 = $elements[1];
+
+ /** @var \PhpOffice\PhpWord\Element\Text $text3 */
+ $text3 = $textRun2->getElement(0);
+ self::assertInstanceOf('PhpOffice\PhpWord\Element\Text', $text3);
+ self::assertEquals('Another symbol: ', $text3->getText());
+
+ /** @var \PhpOffice\PhpWord\Element\Text $symbol2 */
+ $symbol2 = $textRun2->getElement(1);
+ self::assertInstanceOf('PhpOffice\PhpWord\Element\Text', $symbol2);
+ self::assertEquals('[Wingdings 2,0052]', $symbol2->getText());
+ }
}