pptx/text-align--center

A paragraph inside a textbox text-frame has its alignment set via paragraph.alignment = PP_ALIGN.<NAME>; python-pptx emits <a:p>/<a:pPr algn="l|ctr|r|just"/>. This manifest is a parameterised family over the four mainstream alignments: one manifest file expands into 4 cases, each backed by a distinct fixture pptx/text-align--<id>.pptx generated from the same gen_text_align.py script parameterised by --align.

Library verdicts: python-pptx: — pptxjs: —

Metadata

Feature idpptx/text-align--center
Formatpptx
Categorytext-formatting
Familypptx/text-align
Axis valuesalign=center
Spececma-376-5-part-1 § 21.1.2.2.2 a:pPr

XPath assertions

ID / partPredicateXPathpython-pptxpptxjs
text-align-center
ppt/slides/slide1.xml
equal = ctr
The textbox paragraph must carry <a:pPr algn="ctr"/>.
//p:sp[p:nvSpPr/p:cNvSpPr[@txBox='1']]//a:p/a:pPr/@algn

Render assertions

No render assertions declared.

Generator source

scripts/gen_text_align.py

#!/usr/bin/env python3
"""Generate a single ``fixtures/pptx/text-align--<id>.pptx`` fixture.

Parameterised generator for the ``pptx/text-align`` manifest family.
The conformance runner invokes this script once per case with
``--align <PP_ALIGN_NAME> --out <path>``.

Each invocation produces a single-slide presentation containing one
textbox with a single paragraph whose alignment is set via
``paragraph.alignment = PP_ALIGN.<NAME>``. The underlying XML is
``<p:txBody>/<a:p>/<a:pPr algn="..."/>``; the manifest asserts the
``@algn`` attribute equals the axis ``algn`` field.
"""

from __future__ import annotations

import argparse
import datetime as _dt
from pathlib import Path

from pptx import Presentation
from pptx.enum.text import PP_ALIGN
from pptx.util import Inches

_REPO_ROOT = Path(__file__).resolve().parent.parent
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)


def _write(align_name: str, out: Path) -> None:
    align_enum = getattr(PP_ALIGN, align_name)
    prs = Presentation()
    # "Title Only" layout — an empty title placeholder plus our textbox.
    slide = prs.slides.add_slide(prs.slide_layouts[5])
    tb = slide.shapes.add_textbox(Inches(1), Inches(1), Inches(6), Inches(1))
    tf = tb.text_frame
    tf.text = "Aligned paragraph"
    tf.paragraphs[0].alignment = align_enum
    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(
        "--align",
        required=True,
        help="PP_ALIGN member name: LEFT, CENTER, RIGHT, or JUSTIFY.",
    )
    parser.add_argument(
        "--out",
        required=True,
        help="Output fixture path (absolute or repo-relative).",
    )
    args = parser.parse_args()

    out_path = Path(args.out)
    if not out_path.is_absolute():
        out_path = _REPO_ROOT / out_path
    _write(args.align, out_path)
    print(out_path)
    return 0


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

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "pptx/text-align--center",
  "kind": "literal",
  "title": "Paragraph text alignment",
  "format": "pptx",
  "category": "text-formatting",
  "summary": "A paragraph inside a textbox text-frame has its alignment set via paragraph.alignment = PP_ALIGN.<NAME>; python-pptx emits <a:p>/<a:pPr algn=\"l|ctr|r|just\"/>. This manifest is a parameterised family over the four mainstream alignments: one manifest file expands into 4 cases, each backed by a distinct fixture pptx/text-align--<id>.pptx generated from the same gen_text_align.py script parameterised by --align.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "21.1.2.2.2",
    "element": "a:pPr",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/DrawingML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/dml-text.xsd",
    "notes": "DrawingML <a:pPr> is a paragraph-properties element inside <a:p>. Its @algn attribute is a ST_TextAlignType token — l (left), ctr (center), r (right), just (justify), justLow (Kashida), dist (distribute), thaiDist. python-pptx's PP_ALIGN enum exposes LEFT/CENTER/RIGHT/JUSTIFY/DISTRIBUTE/THAI_DISTRIBUTE/JUSTIFY_LOW; this family covers the four mainstream values supported uniformly by readers. ``paragraph.alignment = PP_ALIGN.LEFT`` writes @algn=\"l\" etc."
  },
  "fixtures": {
    "machine": "pptx/text-align--center"
  },
  "generator": {
    "python": "scripts/gen_text_align.py",
    "arg_template": "--align {align.enum} --out fixtures/pptx/text-align--{align.id}.pptx"
  },
  "_expansion": {
    "parent_id": "pptx/text-align",
    "bindings": {
      "align": "center"
    }
  },
  "assertions": [
    {
      "id": "text-align-center",
      "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:nvSpPr/p:cNvSpPr[@txBox='1']]//a:p/a:pPr/@algn",
      "must": "equal",
      "value": "ctr",
      "description": "The textbox paragraph must carry <a:pPr algn=\"ctr\"/>."
    }
  ]
}

Fixture

Download text-align--center.pptx (27.5 KB)

Reference preview

Reference (machine, page 1 PNG)

pptx/text-align--center page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

DrawingML <a:pPr> is a paragraph-properties element inside <a:p>. Its @algn attribute is a ST_TextAlignType token — l (left), ctr (center), r (right), just (justify), justLow (Kashida), dist (distribute), thaiDist. python-pptx's PP_ALIGN enum exposes LEFT/CENTER/RIGHT/JUSTIFY/DISTRIBUTE/THAI_DISTRIBUTE/JUSTIFY_LOW; this family covers the four mainstream values supported uniformly by readers. ``paragraph.alignment = PP_ALIGN.LEFT`` writes @algn="l" etc.