Skip to content

feat(msword): parse native Word charts as classified pictures with data#3809

Open
DanielNg0729 wants to merge 1 commit into
docling-project:mainfrom
DanielNg0729:feat/word-chart-images
Open

feat(msword): parse native Word charts as classified pictures with data#3809
DanielNg0729 wants to merge 1 commit into
docling-project:mainfrom
DanielNg0729:feat/word-chart-images

Conversation

@DanielNg0729

Copy link
Copy Markdown
Contributor

Hi maintainers, This PR follow up with #3777 and #3794 which adds Word parity for the native-chart handling already shipped for Excel and PowerPoint. Charts embedded in .docx files (a w:drawing graphic frame referencing word/charts/chartN.xml) are now parsed into classified PictureItems that carry the chart's underlying data reconstructed as a table.

What changed

  • Native charts are detected during the document walk and emitted as a PictureItem whose meta carries:
    • a chart-type classification (bar_chart, line_chart, pie_chart, scatter_chart, other_chart) derived from the plot element under c:plotArea;
    • the chart's plotted numbers reconstructed as a TabularChartMetaField, read directly from the inline c:numCache/c:strCacheno LibreOffice required, fully deterministic.
  • New backend option MsWordBackendOptions.render_chart_images (default False). When enabled (and LibreOffice is available), a rendered image is attached to the chart picture via the existing DOCX→PDF→PNG path; charts keep their classification and data regardless.
  • Non-chart DrawingML (shapes, SmartArt) is unchanged and still rasterized via LibreOffice.

Behavior change

Previously a chart was rendered as a generic, unclassified image by default whenever LibreOffice was present (and produced nothing without it). It is now a classified picture with tabular data by default, and the rendered image is opt-in via render_chart_images=True. This matches the Excel/PPTX chart behavior. The rendered image is LibreOffice's rendering, not a pixel copy of Word's styling.

Tests & reference data

  • Reuses the existing drawingml.docx fixture (a line chart with 3 series).
  • Adds tests for: classification + data reconstruction without LibreOffice; the opt-in render path; and the opt-out (no image by default) — the last two gated on a LibreOffice install.
  • Regenerated drawingml.docx groundtruth: the chart picture now carries its classification + data table (and no default image); other pictures unchanged.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Detect charts embedded in .docx (a w:drawing graphic frame referencing word/charts/chartN.xml) and emit them as classified PictureItems whose meta carries the chart-type classification and the chart data reconstructed from the inline numCache/strCache — no LibreOffice required.

Add MsWordBackendOptions.render_chart_images (default False) to optionally attach a LibreOffice-rendered image; charts always keep their classification and tabular data regardless. Non-chart DrawingML (shapes, SmartArt) is unchanged.

Note: charts are no longer rendered as a generic image by default; the image is now opt-in, matching the Excel/PPTX chart behavior.
Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @DanielNg0729, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.78947% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/msword_backend.py 85.48% 27 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant