Apply a kerning activation threshold to a run; kerning engages automatically for font sizes at or above the threshold.
Library verdicts: python-docx: — docxjs: —
| Feature id | docx/run-kerning |
|---|---|
| Format | docx |
| Category | text-formatting |
| Spec | ecma-376-5-part-1 § 17.3.2.17 w:kern |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
kern-element-presentword/document.xml | existThe run carrying the kerned text must have a <w:kern> child inside <w:rPr>. | //w:r[w:t[normalize-space()='Hello kerned world']]/w:rPr/w:kern | — | — |
kern-val-half-pointsword/document.xml | equal = 24The kerning threshold must serialise as the half-point value '24' (12 points). | //w:r[w:t[normalize-space()='Hello kerned world']]/w:rPr/w:kern/@w:val | — | — |
No render assertions declared.
scripts/gen_run_kerning.py
#!/usr/bin/env python3
"""Generate ``fixtures/docx/run-kerning.docx``.
A minimal document with one run whose font has a kerning threshold set
to 12 points (serialised as the half-point value ``24`` in XML).
Designed to satisfy the assertions in ``features/docx/run-kerning.json``.
"""
from __future__ import annotations
from pathlib import Path
from docx import Document
from docx.shared import Pt
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "docx" / "run-kerning.docx"
def main() -> int:
doc = Document()
paragraph = doc.add_paragraph()
run = paragraph.add_run("Hello kerned world")
run.font.kerning = Pt(12)
_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/run-kerning",
"title": "Run-level kerning threshold",
"format": "docx",
"category": "text-formatting",
"summary": "Apply a kerning activation threshold to a run; kerning engages automatically for font sizes at or above the threshold.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "17.3.2.17",
"element": "w:kern",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
"notes": "w:kern/@w:val is an ST_HpsMeasure (half-points). A value of 24 represents 12 points — Word engages automatic kerning for runs whose font size is at least the threshold. Setting run.font.kerning = Pt(12) via python-docx emits <w:kern w:val=\"24\"/> inside <w:rPr>."
},
"fixtures": {
"machine": "docx/run-kerning",
"office": "docx/run-kerning"
},
"generator": {
"python": "scripts/gen_run_kerning.py"
},
"assertions": [
{
"id": "kern-element-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:r[w:t[normalize-space()='Hello kerned world']]/w:rPr/w:kern",
"must": "exist",
"description": "The run carrying the kerned text must have a <w:kern> child inside <w:rPr>."
},
{
"id": "kern-val-half-points",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:r[w:t[normalize-space()='Hello kerned world']]/w:rPr/w:kern/@w:val",
"must": "equal",
"value": "24",
"description": "The kerning threshold must serialise as the half-point value '24' (12 points)."
}
]
}
