docx/small-caps-text

Render lowercase letters as reduced-size capital letters.

Library verdicts: python-docx: — docxjs: pass

Metadata

Feature iddocx/small-caps-text
Formatdocx
Categorytext-formatting
Spececma-376-5-part-1 § 17.3.2.33 w:smallCaps

XPath assertions

ID / partPredicateXPathpython-docxdocxjs
small-caps-element-present
word/document.xml
exist
The run carrying the small-caps text must have a <w:smallCaps> child inside <w:rPr>.
//w:r[w:t[normalize-space()='Small caps text']]/w:rPr/w:smallCaps
small-caps-val-not-false
word/document.xml
not-match = ^(0|false|off)$
If w:val is present it must not explicitly disable small caps.
//w:r[w:t[normalize-space()='Small caps text']]/w:rPr/w:smallCaps/@w:val

Render assertions

IDPredicateSelectorpython-docxdocxjs
small-caps-text-renderedcss_selector/ match-text = Small caps text
A DOM node marked small-caps (via font-variant or font-variant-caps) must contain the fixture text.
.docx-wrapper [style*='font-variant: small-caps'], .docx-wrapper [style*='font-variant:small-caps'], .docx-wrapper [style*='font-variant-caps: small-caps'], .docx-wrapper [style*='font-variant-caps:small-caps']pass
small-caps-text-visiblecomputed_style = small-caps style=font-variant-caps
The computed font-variant-caps on the small-caps run must be small-caps.
.docx-wrapper span:not(:has(*))pass

Generator source

scripts/gen_small_caps_text.py

#!/usr/bin/env python3
"""Generate ``fixtures/docx/small-caps-text.docx``.

A minimal document exercising the ``w:smallCaps`` element. One
paragraph containing one run presented in small capitals.
Satisfies the assertions in ``features/docx/small-caps-text.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" / "small-caps-text.docx"


def main() -> int:
    doc = Document()
    paragraph = doc.add_paragraph()
    run = paragraph.add_run("Small caps text")
    run.font.small_caps = True
    _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/small-caps-text",
  "title": "Small caps text",
  "format": "docx",
  "category": "text-formatting",
  "summary": "Render lowercase letters as reduced-size capital letters.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "17.3.2.33",
    "element": "w:smallCaps",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
    "notes": "Word emits <w:smallCaps/> to present the run's lowercase glyphs as small capitals. Empty element means true. w:val is optional; if present it must not be 0/false/off. Mutually exclusive with <w:caps> at render time — the spec allows both but Word uses the last one set."
  },
  "fixtures": {
    "machine": "docx/small-caps-text",
    "office": "docx/small-caps-text"
  },
  "generator": {
    "python": "scripts/gen_small_caps_text.py"
  },
  "assertions": [
    {
      "id": "small-caps-element-present",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:r[w:t[normalize-space()='Small caps text']]/w:rPr/w:smallCaps",
      "must": "exist",
      "description": "The run carrying the small-caps text must have a <w:smallCaps> child inside <w:rPr>."
    },
    {
      "id": "small-caps-val-not-false",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:r[w:t[normalize-space()='Small caps text']]/w:rPr/w:smallCaps/@w:val",
      "must": "not-match",
      "value": "^(0|false|off)$",
      "description": "If w:val is present it must not explicitly disable small caps."
    }
  ],
  "render_assertions": [
    {
      "id": "small-caps-text-rendered",
      "kind": "css_selector",
      "selector": ".docx-wrapper [style*='font-variant: small-caps'], .docx-wrapper [style*='font-variant:small-caps'], .docx-wrapper [style*='font-variant-caps: small-caps'], .docx-wrapper [style*='font-variant-caps:small-caps']",
      "must": "match-text",
      "value": "Small caps text",
      "description": "A DOM node marked small-caps (via font-variant or font-variant-caps) must contain the fixture text."
    },
    {
      "id": "small-caps-text-visible",
      "kind": "computed_style",
      "selector": ".docx-wrapper span:not(:has(*))",
      "style_property": "font-variant-caps",
      "value": "small-caps",
      "description": "The computed font-variant-caps on the small-caps run must be small-caps."
    }
  ]
}

Fixture

Download small-caps-text.docx (18.6 KB)

Reference preview

Reference (machine, page 1 PNG)

docx/small-caps-text page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Word emits <w:smallCaps/> to present the run's lowercase glyphs as small capitals. Empty element means true. w:val is optional; if present it must not be 0/false/off. Mutually exclusive with <w:caps> at render time — the spec allows both but Word uses the last one set.