Skip to content

feat(a11y): reading_order + accessibility_issues + is_hidden_from_accessibility (Phase B, closes #22)#38

Merged
MHoroszowski merged 1 commit into
masterfrom
feature/a11y-phase-b
May 8, 2026
Merged

feat(a11y): reading_order + accessibility_issues + is_hidden_from_accessibility (Phase B, closes #22)#38
MHoroszowski merged 1 commit into
masterfrom
feature/a11y-phase-b

Conversation

@MHoroszowski
Copy link
Copy Markdown
Owner

Accessibility Phase B — reading_order + accessibility_issues + is_hidden_from_accessibility

Closes #22. Phase B of the Accessibility epic. Phase A (alt_text, alt_title, is_decorative) shipped in #31. With this PR the items the issue called out are all covered, modulo Microsoft Accessibility Checker's deeper diagnostics (color contrast, font size, etc.) which are outside python-pptx's scope.

Phase A regression fix bundled in

PR #31's <adec:decorative> extension shipped with the wrong GUID for the <a:ext uri="..."> wrapper. PowerPoint's accessibility-rendering pipeline only recognizes the extension under one specific URI, and ours didn't match — so the XML round-tripped within python-pptx (unit tests passed) but PowerPoint silently ignored it and the "Mark as Decorative" checkbox in the Alt Text pane stayed unchecked on reopen.

URI
Before (PR #31, wrong) {FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}
After (matches PowerPoint exactly) {C183D7F6-B498-43B3-948B-1728B52AA6E4}

Confirmed empirically by diffing a maintainer-authored deck (where the checkbox was set in the UI, then saved) against a python-pptx-emitted deck — the only material difference was the GUID. Both is_decorative getter and setter, plus their unit tests, are updated to the correct GUID.

What this PR adds

# Convenience alias for is_decorative
shape.is_hidden_from_accessibility = True
shape.is_hidden_from_accessibility  # → True

# Reading order — z-order of shapes on the slide
slide.shapes.reading_order               # → tuple of shapes
slide.shapes.reading_order = (c, a, b)   # → reorders the spTree

# Lint helper — shapes lacking alt text and not marked decorative
slide.shapes.accessibility_issues()      # → list of BaseShape

Public API

  • Shape.is_hidden_from_accessibility (boolean, read/write). Convenience alias for is_decorative. Some accessibility documentation and third-party tools use the wording "hidden from accessibility" for the same flag; this property exists so the API reads naturally for either audience. Backed by the same <adec:decorative val="1"/> extension.

  • Slide.shapes.reading_order (read/write).

    • Getter returns a tuple of shapes in z-order — the order screen readers will narrate them on a slide that does not declare an explicit <p:tabLst>.
    • Setter accepts a permutation of the slide's existing shapes and reorders the underlying <p:spTree> to match. Raises ValueError on wrong length or unknown shapes.
  • Slide.shapes.accessibility_issues()list[BaseShape]. Lint helper. Returns shapes that lack alt text (neither alt_text nor alt_title is set) AND are not marked decorative. Returned in reading order. A fully-tagged slide reports []. Treat it as a fast first-pass — color-contrast / font-size / explicit-tab-order checks are not covered.

Out of scope (Phase C if it ever surfaces)

  • <p:tabLst> (the OOXML element for explicit reading order on a per-slide basis) is rare in practice — PowerPoint's UI doesn't expose it, and the OOXML spec calls out that the fallback for reading order is shape z-order. We deliberately model reading_order as z-order rather than emitting <p:tabLst>. This keeps the API simple and works correctly for the overwhelming majority of decks. If a real-world need for explicit <p:tabLst> emerges, that's a Phase C addition that would preserve the existing API as the no-tabLst fallback.

Test coverage

  • 20 new unit tests in tests/test_a11y_phase_b.py:
    • 5 tests on the is_hidden_from_accessibility alias including save/reopen round-trip
    • 9 tests on reading_order (getter, setter, round-trip, no-op, raise on wrong length, raise on unknown shape)
    • 6 tests on accessibility_issues() (flag-untagged, pass alt-text, pass alt-title, pass decorative, fully-tagged-slide empty, return-in-reading-order)
  • 4 new behave scenarios in features/a11y-phase-b.feature (alias, reading_order getter, reading_order setter, lint helper)
  • Existing tests/shapes/test_base.py is_decorative cases updated to the corrected GUID — semantic test surface unchanged.
  • UAT uat_a11y_phase_b.py (untracked per repo §6) builds a 2-slide deck. UAT signoff: ✓ — verified end-to-end that PowerPoint's "Mark as Decorative" checkbox now reads as checked on reopen, comparing against a maintainer-authored reference deck.

Verification

$ python3 -m pytest tests/ -q | tail -3
3242 passed in 4.42s

$ ruff check src tests | tail -3
All checks passed!

$ python3 -m behave features/ --no-color | tail -3
1003 scenarios passed, 0 failed, 0 skipped
3011 steps passed, 0 failed, 0 skipped

…essibility (Phase B)

Phase B of issue #22 (Accessibility epic). Phase A — `Shape.alt_text`,
`Shape.alt_title`, `Shape.is_decorative` — shipped in PR #31. Phase B
adds the remaining items the issue called out, finishing the epic
modulo Microsoft Accessibility Checker's deeper diagnostics (color
contrast, font size, etc.) which are outside python-pptx's scope.

Phase A regression fix (rolled into this PR)
--------------------------------------------
PR #31's `<adec:decorative>` extension used the wrong `<a:ext uri="...">`
GUID — it shipped with `{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}`, but
PowerPoint's accessibility-rendering pipeline only recognizes the
extension under `{C183D7F6-B498-43B3-948B-1728B52AA6E4}`. With the
wrong GUID, the XML round-tripped within python-pptx (so unit tests
passed) but PowerPoint silently ignored the extension and the
"Mark as Decorative" checkbox in the Alt Text pane stayed unchecked
on reopen. Confirmed empirically by diffing a maintainer-authored
PowerPoint deck (where the checkbox was set in the UI, then saved)
against a python-pptx-emitted deck — the only material difference was
the GUID. Both `is_decorative` getter and setter, plus their unit
tests, are updated to the correct GUID.

New public API (Phase B)
------------------------
- `Shape.is_hidden_from_accessibility` (boolean, read/write)
  Convenience alias for `is_decorative`. Mirrors the wording used in
  some accessibility documentation and third-party tools so the API
  reads naturally for either audience. Backed by the same
  `<adec:decorative val="1"/>` extension.

- `Slide.shapes.reading_order` (read/write)
  Getter returns a tuple of shapes in z-order — the order screen
  readers will narrate them on a slide that does not declare an
  explicit `<p:tabLst>`. Setter accepts a permutation of the slide's
  existing shapes and reorders the underlying `<p:spTree>` to match.
  Raises `ValueError` on wrong length or unknown shapes.

- `Slide.shapes.accessibility_issues()` (returns `list[BaseShape]`)
  Lint helper. Returns shapes that lack alt text (neither `alt_text`
  nor `alt_title` is set) AND are not marked decorative. Returned in
  reading order. A fully-tagged slide reports `[]`. Treat it as a
  fast first-pass — color-contrast / font-size / explicit-tab-order
  checks are not covered.

Phase B scope decisions
-----------------------
- `<p:tabLst>` (the OOXML element for explicit reading order on a
  per-slide basis) is rare in practice — PowerPoint's UI doesn't
  expose it, and the OOXML spec calls out that the fallback for
  reading order is shape z-order. We deliberately model
  `reading_order` as z-order rather than emitting `<p:tabLst>`.
  This keeps the API simple and works correctly for the
  overwhelming majority of decks. If a real-world need for explicit
  `<p:tabLst>` emerges, that's a Phase C addition that would
  preserve the existing API as the no-tabLst fallback.

Test coverage
-------------
- 20 new unit tests in `tests/test_a11y_phase_b.py`
- 4 new behave scenarios in `features/a11y-phase-b.feature`
- Existing `tests/shapes/test_base.py` `is_decorative` cases
  updated to the corrected GUID; semantic test surface unchanged.
- New `uat_a11y_phase_b.py` (untracked per repo §6) builds a 2-slide
  deck demonstrating the lint helper and reading_order setter.
  UAT signoff: ✓ on the corrected URI (verified end-to-end against
  a PowerPoint-authored reference deck).

Verification
------------
```
$ python3 -m pytest tests/ -q | tail -3
3242 passed in 4.42s

$ ruff check src tests | tail -3
All checks passed!

$ python3 -m behave features/ --no-color | tail -3
1003 scenarios passed, 0 failed, 0 skipped
3011 steps passed, 0 failed, 0 skipped
```

Closes #22
@MHoroszowski MHoroszowski merged commit 589002f into master May 8, 2026
12 checks passed
@MHoroszowski MHoroszowski deleted the feature/a11y-phase-b branch May 8, 2026 14:19
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.

[Epic] Accessibility (a11y) — alt text, decorative flag, reading order

1 participant