pptx/shape-rectangle

An auto-shape with rectangle preset geometry, added via shapes.add_shape(MSO_SHAPE.RECTANGLE, ...), carries <a:prstGeom prst="rect"/> and a text-frame run.

Library verdicts: python-pptx: — pptxjs: fail

Metadata

Feature idpptx/shape-rectangle
Formatpptx
Categoryshapes
Spececma-376-5-part-1 § 20.1.9.18 a:prstGeom

XPath assertions

ID / partPredicateXPathpython-pptxpptxjs
shape-rectangle-prst-geom-rect
ppt/slides/slide1.xml
equal = rect
The <p:sp> carrying the text 'Rectangle shape' must declare <a:prstGeom prst="rect"/> — the preset geometry MSO_SHAPE.RECTANGLE maps to.
//p:sp[.//a:t[normalize-space()='Rectangle shape']]/p:spPr/a:prstGeom/@prst
shape-rectangle-text-present
ppt/slides/slide1.xml
exist
A rectangle-preset shape must carry a text run whose value is 'Rectangle shape'.
//p:sp[p:spPr/a:prstGeom[@prst='rect']]//a:t[normalize-space()='Rectangle shape']

Render assertions

IDPredicateSelectorpython-pptxpptxjs
shape-rectangle-text-visiblecss_selector/ match-text = Rectangle shape
A DOM node annotated as a rectangle-preset shape (via data-shape-preset='rect', .pptx-shape-rect, or generic data-kind='sp') must carry the 'Rectangle shape' text. Falls back to any descendant under a generic slide section for renderers that don't expose shape metadata.
[data-shape-preset='rect'], .pptx-shape-rect, [data-kind='sp'], section[data-slide] *, section.slide *fail
slide-countcss_selector/ equal-count
Exactly one slide container must be rendered. Catches renderers that emit zero slides (hard failure) or duplicate the slide.
section.pptx-slide, .pptx-slide, section[data-slide], .slide, [data-slide]

Generator source

scripts/gen_shape_rectangle.py

#!/usr/bin/env python3
"""Generate ``fixtures/pptx/shape-rectangle.pptx``.

A one-slide presentation carrying a rectangle auto-shape added via
``shapes.add_shape(MSO_SHAPE.RECTANGLE, ...)``. Its preset geometry is
``prst="rect"``. Designed to satisfy the assertions in
``features/pptx/shape-rectangle.json``.
"""

from __future__ import annotations

from pathlib import Path

from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE
from pptx.util import Inches

import datetime as _dt
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)

_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "pptx" / "shape-rectangle.pptx"


def main() -> int:
    prs = Presentation()
    # slide_layouts[5] is the "title only" layout; it has a title placeholder
    # that we leave empty, plus whatever shapes we add.
    slide = prs.slides.add_slide(prs.slide_layouts[5])
    shape = slide.shapes.add_shape(
        MSO_SHAPE.RECTANGLE, Inches(1), Inches(1), Inches(3), Inches(2)
    )
    shape.text_frame.text = "Rectangle shape"

    _OUT.parent.mkdir(parents=True, exist_ok=True)
    prs.save(_OUT, zip_date_time=_REPRODUCIBLE_DT)
    print(_OUT)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "pptx/shape-rectangle",
  "title": "Rectangle auto-shape",
  "format": "pptx",
  "category": "shapes",
  "summary": "An auto-shape with rectangle preset geometry, added via shapes.add_shape(MSO_SHAPE.RECTANGLE, ...), carries <a:prstGeom prst=\"rect\"/> and a text-frame run.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "20.1.9.18",
    "element": "a:prstGeom",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/DrawingML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/dml-shape.xsd",
    "notes": "python-pptx emits shapes.add_shape(MSO_SHAPE.RECTANGLE, ...) as a <p:sp> whose <p:spPr>/<a:prstGeom> declares prst=\"rect\". Unlike a text box the shape also carries a <p:style> element (accent scheme references) and an <a:xfrm>. The text set via text_frame.text lives in the shape's <p:txBody>."
  },
  "fixtures": {
    "machine": "pptx/shape-rectangle",
    "office": "pptx/shape-rectangle"
  },
  "generator": {
    "python": "scripts/gen_shape_rectangle.py"
  },
  "assertions": [
    {
      "id": "shape-rectangle-prst-geom-rect",
      "part": "ppt/slides/slide1.xml",
      "namespaces": {
        "p": "http://schemas.openxmlformats.org/presentationml/2006/main",
        "a": "http://schemas.openxmlformats.org/drawingml/2006/main"
      },
      "xpath": "//p:sp[.//a:t[normalize-space()='Rectangle shape']]/p:spPr/a:prstGeom/@prst",
      "must": "equal",
      "value": "rect",
      "description": "The <p:sp> carrying the text 'Rectangle shape' must declare <a:prstGeom prst=\"rect\"/> — the preset geometry MSO_SHAPE.RECTANGLE maps to."
    },
    {
      "id": "shape-rectangle-text-present",
      "part": "ppt/slides/slide1.xml",
      "namespaces": {
        "p": "http://schemas.openxmlformats.org/presentationml/2006/main",
        "a": "http://schemas.openxmlformats.org/drawingml/2006/main"
      },
      "xpath": "//p:sp[p:spPr/a:prstGeom[@prst='rect']]//a:t[normalize-space()='Rectangle shape']",
      "must": "exist",
      "description": "A rectangle-preset shape must carry a text run whose value is 'Rectangle shape'."
    }
  ],
  "render_assertions": [
    {
      "id": "shape-rectangle-text-visible",
      "kind": "css_selector",
      "selector": "[data-shape-preset='rect'], .pptx-shape-rect, [data-kind='sp'], section[data-slide] *, section.slide *",
      "must": "match-text",
      "value": "Rectangle shape",
      "description": "A DOM node annotated as a rectangle-preset shape (via data-shape-preset='rect', .pptx-shape-rect, or generic data-kind='sp') must carry the 'Rectangle shape' text. Falls back to any descendant under a generic slide section for renderers that don't expose shape metadata."
    },
    {
      "id": "slide-count",
      "kind": "css_selector",
      "selector": "section.pptx-slide, .pptx-slide, section[data-slide], .slide, [data-slide]",
      "must": "equal-count",
      "count": 1,
      "description": "Exactly one slide container must be rendered. Catches renderers that emit zero slides (hard failure) or duplicate the slide."
    }
  ]
}

Fixture

Download shape-rectangle.pptx (27.6 KB)

Reference preview

Reference (machine, page 1 PNG)

pptx/shape-rectangle page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

python-pptx emits shapes.add_shape(MSO_SHAPE.RECTANGLE, ...) as a <p:sp> whose <p:spPr>/<a:prstGeom> declares prst="rect". Unlike a text box the shape also carries a <p:style> element (accent scheme references) and an <a:xfrm>. The text set via text_frame.text lives in the shape's <p:txBody>.