docx/line-spacing-double

Double (2.0x) line spacing on a paragraph.

Library verdicts: python-docx: — docxjs: fail

Metadata

Feature iddocx/line-spacing-double
Formatdocx
Categoryparagraph-layout
Spececma-376-5-part-1 § 17.3.1.33 w:spacing

XPath assertions

ID / partPredicateXPathpython-docxdocxjs
line-spacing-spacing-present
word/document.xml
exist
The paragraph must have a <w:spacing> child inside <w:pPr>.
//w:p[w:r/w:t[normalize-space()='Double spaced paragraph']]/w:pPr/w:spacing
line-spacing-line-480
word/document.xml
equal = 480
w:spacing@w:line must be 480 (2 * 240 twentieths of a point) for double spacing.
//w:p[w:r/w:t[normalize-space()='Double spaced paragraph']]/w:pPr/w:spacing/@w:line
line-spacing-lineRule-auto
word/document.xml
equal = auto
w:spacing@w:lineRule must be 'auto' — required for multiple-based line heights.
//w:p[w:r/w:t[normalize-space()='Double spaced paragraph']]/w:pPr/w:spacing/@w:lineRule

Render assertions

IDPredicateSelectorpython-docxdocxjs
line-spacing-text-presentcss_selector/ match-text = Double spaced paragraph
The rendered DOM must contain the fixture text.
.docx-wrapper ppass
line-spacing-double-computedcomputed_style = ^(2|2\.0+|[3-9][0-9](\.[0-9]+)?px|[1-9][0-9]{2,}(\.[0-9]+)?px)$ style=line-height
The computed line-height must be 2 (unitless) or a pixel value corresponding to ~2x the font size (>= ~30px at default 16px font).
.docx-wrapper pfail

Generator source

scripts/gen_line_spacing_double.py

#!/usr/bin/env python3
"""Generate ``fixtures/docx/line-spacing-double.docx``.

A minimal document exercising ``w:spacing`` with double (2.0x) line
spacing. One paragraph whose paragraph_format.line_spacing is 2.0,
which python-docx encodes as w:line=480, w:lineRule=auto. Designed to
satisfy the assertions in ``features/docx/line-spacing-double.json``.
"""

from __future__ import annotations

from pathlib import Path

from docx import Document

_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "docx" / "line-spacing-double.docx"


def main() -> int:
    doc = Document()
    paragraph = doc.add_paragraph("Double spaced paragraph")
    paragraph.paragraph_format.line_spacing = 2.0
    _OUT.parent.mkdir(parents=True, exist_ok=True)
    doc.save(_OUT, reproducible=True)
    print(_OUT)
    return 0


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

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "docx/line-spacing-double",
  "title": "Line spacing — double",
  "format": "docx",
  "category": "paragraph-layout",
  "summary": "Double (2.0x) line spacing on a paragraph.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "17.3.1.33",
    "element": "w:spacing",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
    "notes": "Line spacing is carried by <w:spacing w:line=\"...\" w:lineRule=\"...\"/> inside <w:pPr>. With lineRule='auto' the w:line attribute is a multiple of 240 twentieths of a point (240 = single, 360 = 1.5x, 480 = double). See also 17.3.1.1 for pPr."
  },
  "fixtures": {
    "machine": "docx/line-spacing-double",
    "office": "docx/line-spacing-double"
  },
  "generator": {
    "python": "scripts/gen_line_spacing_double.py"
  },
  "assertions": [
    {
      "id": "line-spacing-spacing-present",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:p[w:r/w:t[normalize-space()='Double spaced paragraph']]/w:pPr/w:spacing",
      "must": "exist",
      "description": "The paragraph must have a <w:spacing> child inside <w:pPr>."
    },
    {
      "id": "line-spacing-line-480",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:p[w:r/w:t[normalize-space()='Double spaced paragraph']]/w:pPr/w:spacing/@w:line",
      "must": "equal",
      "value": "480",
      "description": "w:spacing@w:line must be 480 (2 * 240 twentieths of a point) for double spacing."
    },
    {
      "id": "line-spacing-lineRule-auto",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:p[w:r/w:t[normalize-space()='Double spaced paragraph']]/w:pPr/w:spacing/@w:lineRule",
      "must": "equal",
      "value": "auto",
      "description": "w:spacing@w:lineRule must be 'auto' — required for multiple-based line heights."
    }
  ],
  "render_assertions": [
    {
      "id": "line-spacing-text-present",
      "kind": "css_selector",
      "selector": ".docx-wrapper p",
      "must": "match-text",
      "value": "Double spaced paragraph",
      "description": "The rendered DOM must contain the fixture text."
    },
    {
      "id": "line-spacing-double-computed",
      "kind": "computed_style",
      "selector": ".docx-wrapper p",
      "style_property": "line-height",
      "value": "^(2|2\\.0+|[3-9][0-9](\\.[0-9]+)?px|[1-9][0-9]{2,}(\\.[0-9]+)?px)$",
      "description": "The computed line-height must be 2 (unitless) or a pixel value corresponding to ~2x the font size (>= ~30px at default 16px font)."
    }
  ]
}

Fixture

Download line-spacing-double.docx (18.6 KB)

Reference preview

Reference (machine, page 1 PNG)

docx/line-spacing-double page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Line spacing is carried by <w:spacing w:line="..." w:lineRule="..."/> inside <w:pPr>. With lineRule='auto' the w:line attribute is a multiple of 240 twentieths of a point (240 = single, 360 = 1.5x, 480 = double). See also 17.3.1.1 for pPr.