Double (2.0x) line spacing on a paragraph.
Library verdicts: python-docx: — docxjs: fail
| Feature id | docx/line-spacing-double |
|---|---|
| Format | docx |
| Category | paragraph-layout |
| Spec | ecma-376-5-part-1 § 17.3.1.33 w:spacing |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
line-spacing-spacing-presentword/document.xml | existThe 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-480word/document.xml | equal = 480w: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-autoword/document.xml | equal = autow: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 | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
line-spacing-text-present | css_selector/ match-text = Double spaced paragraphThe rendered DOM must contain the fixture text. | .docx-wrapper p | — | pass |
line-spacing-double-computed | computed_style = ^(2|2\.0+|[3-9][0-9](\.[0-9]+)?px|[1-9][0-9]{2,}(\.[0-9]+)?px)$ style=line-heightThe computed line-height must be 2 (unitless) or a pixel value corresponding to ~2x the font size (>= ~30px at default 16px font). | .docx-wrapper p | — | fail |
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())
{
"$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)."
}
]
}
