Skip to content

Add support for parsing w:sym tags in Word2007 reader #2805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 26, 2025

This PR adds support for parsing w:sym (symbol) tags in DOCX files, which was previously ignored by PHPWord's Word2007 reader.

Problem

When reading DOCX files containing symbol elements (like special characters from Wingdings or Symbol fonts), PHPWord would skip these w:sym tags entirely, resulting in missing content in the parsed document.

Solution

Added handling for w:sym nodes in the readRunChild() method of AbstractPart.php. The implementation:

  1. Extracts the w:font and w:char attributes from w:sym elements
  2. Formats them as readable text in the format [{font},{char}]
  3. Adds the formatted text to the document while preserving font and paragraph styling

Example

A DOCX file containing:

<w:r>
    <w:t>XXXX </w:t>
</w:r>
<w:r>
    <w:sym w:font="Wingdings 2" w:char="00A3"/>
</w:r>

Will now produce the text output:

XXXX [Wingdings 2,00A3]

Changes

  • Core functionality: Added 6 lines to handle w:sym nodes in AbstractPart.php
  • Test coverage: Added comprehensive test testReadSymbol() to verify the functionality works correctly with multiple symbols and edge cases
  • Edge cases: Handles missing or empty attributes gracefully

The implementation is minimal and surgical, adding only the necessary functionality without modifying existing code paths.

Fixes #2802.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/PHPOffice/Math/zipball/fc31c8f57a7a81f962cbf389fd89f4d9d06fc99a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/oLUyoc /usr/bin/composer install --no-dev (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] how to parse docx file "w:sym" tag? Add support for parsing w:sym tags in Word2007 reader Jul 26, 2025
@Copilot Copilot AI requested a review from Progi1984 July 26, 2025 17:17
Copilot finished work on behalf of Progi1984 July 26, 2025 17:17
@coveralls
Copy link

Coverage Status

coverage: 96.757%. remained the same
when pulling 1904d0e on copilot/fix-2802
into 0ab0b49 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

how to parse docx file "w:sym" tag?
3 participants