A slide references a slide-layout part via a r:slideLayout relationship. PowerPoint's default template ships eleven standard layouts (Title, Title+Content, Section Header, Two Content, Comparison, Title Only, Blank, Content+Caption, Picture+Caption, Title+Vertical Text, Vertical Title+Text).
| Library | Pass | Fail | Pending |
|---|---|---|---|
python-pptx | 0 | 0 | 11 |
pptxjs | 0 | 0 | 11 |
layout (11 values): title, title-content, section-header, two-content, comparison, title-only, blank, content-caption, picture-caption, title-vert-text, vert-title-textscripts/gen_slide_layout.py — runs with --arg_template --layout-idx {layout.idx} --out fixtures/pptx/slide-layout--{layout.id}.pptx
#!/usr/bin/env python3
"""Generate a ``fixtures/pptx/slide-layout--<id>.pptx`` fixture.
Parameterised generator for the ``pptx/slide-layout`` manifest family.
python-pptx's default template ships eleven standard slide layouts
(idx 0-10); this generator adds a single slide based on the layout
at the requested index, sets the title placeholder text when one is
present, and writes the result to ``--out``.
The ``features/pptx/slide-layout.json`` manifest's
``generator.arg_template`` field drives these args at expansion time.
"""
from __future__ import annotations
import argparse
import datetime as _dt
from pathlib import Path
from pptx import Presentation
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)
_REPO_ROOT = Path(__file__).resolve().parent.parent
def _write(layout_idx: int, out: Path) -> None:
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[layout_idx])
# Not every layout has a title placeholder (e.g. Blank). Set it
# where present so visual renders have at least one text anchor.
if slide.shapes.title is not None:
slide.shapes.title.text = f"Layout idx {layout_idx}"
out.parent.mkdir(parents=True, exist_ok=True)
prs.save(out, zip_date_time=_REPRODUCIBLE_DT)
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
"--layout-idx",
type=int,
default=0,
help="Slide layout index in the default template (0-10).",
)
parser.add_argument(
"--out",
default=str(_REPO_ROOT / "fixtures" / "pptx" / "slide-layout.pptx"),
)
args = parser.parse_args()
out_path = Path(args.out)
if not out_path.is_absolute():
out_path = _REPO_ROOT / out_path
_write(args.layout_idx, out_path)
print(out_path)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"$schema": "../manifest.schema.json",
"id": "pptx/slide-layout",
"kind": "parameterised",
"title": "Slide layout",
"format": "pptx",
"category": "slide-layout",
"summary": "A slide references a slide-layout part via a r:slideLayout relationship. PowerPoint's default template ships eleven standard layouts (Title, Title+Content, Section Header, Two Content, Comparison, Title Only, Blank, Content+Caption, Picture+Caption, Title+Vertical Text, Vertical Title+Text).",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "19.3.1.15",
"element": "sldLayout",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/PresentationML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/pml.xsd",
"notes": "Each slide part carries exactly one slideLayout relationship pointing at its parent layout. The default presentation template in python-pptx ships 11 standard layouts at indices 0-10 that map to slideLayout1.xml ... slideLayout11.xml; however the target filename depends on the layout ordering inside the theme and should not be asserted on. This manifest is a parameterised family: one manifest expands into eleven concrete cases, one per standard layout. Each expanded case targets a distinct fixture pptx/slide-layout--<id>.pptx generated from gen_slide_layout.py parameterised by --layout-idx."
},
"fixtures": {
"machine": "pptx/slide-layout"
},
"generator": {
"python": "scripts/gen_slide_layout.py",
"arg_template": "--layout-idx {layout.idx} --out fixtures/pptx/slide-layout--{layout.id}.pptx"
},
"parameters": {
"layout": [
{
"id": "title",
"idx": 0,
"name": "Title Slide"
},
{
"id": "title-content",
"idx": 1,
"name": "Title and Content"
},
{
"id": "section-header",
"idx": 2,
"name": "Section Header"
},
{
"id": "two-content",
"idx": 3,
"name": "Two Content"
},
{
"id": "comparison",
"idx": 4,
"name": "Comparison"
},
{
"id": "title-only",
"idx": 5,
"name": "Title Only"
},
{
"id": "blank",
"idx": 6,
"name": "Blank"
},
{
"id": "content-caption",
"idx": 7,
"name": "Content with Caption"
},
{
"id": "picture-caption",
"idx": 8,
"name": "Picture with Caption"
},
{
"id": "title-vert-text",
"idx": 9,
"name": "Title and Vertical Text"
},
{
"id": "vert-title-text",
"idx": 10,
"name": "Vertical Title and Text"
}
]
},
"assertions_template": [
{
"id": "slide-has-layout-rel-{layout.id}",
"part": "ppt/slides/_rels/slide1.xml.rels",
"namespaces": {
"r": "http://schemas.openxmlformats.org/package/2006/relationships"
},
"xpath": "count(//*[local-name()='Relationship'][@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout'])",
"must": "match",
"value": "^1(\\.0)?$",
"description": "slide1 must carry exactly one slideLayout relationship."
},
{
"id": "layout-ref-from-slide-{layout.id}",
"part": "ppt/slides/_rels/slide1.xml.rels",
"namespaces": {
"r": "http://schemas.openxmlformats.org/package/2006/relationships"
},
"xpath": "//*[local-name()='Relationship'][@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout']/@Target",
"must": "match",
"value": "slideLayout\\d+\\.xml$",
"description": "The slideLayout relationship target must point at a slideLayoutN.xml part; the exact N depends on theme ordering, not on the axis idx."
}
]
}