pptx/text-align

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.

Cases (4)

Feature IDAxis bindingspython-pptxpptxjs
pptx/text-align--centeralign=center
pptx/text-align--justifyalign=justify
pptx/text-align--leftalign=left
pptx/text-align--rightalign=right

Aggregate

LibraryPassFailPending
python-pptx004
pptxjs004

Parameter axes

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.

Generator source

scripts/gen_text_align.py — runs with --arg_template --align {align.enum} --out fixtures/pptx/text-align--{align.id}.pptx

#!/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 (parent, unexpanded)

{
  "$schema": "../manifest.schema.json",
  "id": "pptx/text-align",
  "kind": "parameterised",
  "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"
  },
  "generator": {
    "python": "scripts/gen_text_align.py",
    "arg_template": "--align {align.enum} --out fixtures/pptx/text-align--{align.id}.pptx"
  },
  "parameters": {
    "align": [
      {
        "id": "left",
        "enum": "LEFT",
        "algn": "l"
      },
      {
        "id": "center",
        "enum": "CENTER",
        "algn": "ctr"
      },
      {
        "id": "right",
        "enum": "RIGHT",
        "algn": "r"
      },
      {
        "id": "justify",
        "enum": "JUSTIFY",
        "algn": "just"
      }
    ]
  },
  "assertions_template": [
    {
      "id": "text-align-{align.id}",
      "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": "{align.algn}",
      "description": "The textbox paragraph must carry <a:pPr algn=\"{align.algn}\"/>."
    }
  ]
}