Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions tests/PhpWordTests/Reader/Word2007/PartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<w:p>
<w:r>
<w:t>Text before symbol </w:t>
</w:r>
<w:r>
<w:sym w:font="Wingdings 2" w:char="00A3"/>
</w:r>
<w:r>
<w:t> text after symbol</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>Another symbol: </w:t>
</w:r>
<w:r>
<w:sym w:font="Wingdings 2" w:char="0052"/>
</w:r>
</w:p>';

$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());
}
}