Fix PowerPoint math paragraph fonts (0.7.4)

This commit is contained in:
2026-10-15 18:17:40 +08:00
parent d671e412ae
commit 8943e7e5ae
5 changed files with 20 additions and 6 deletions
+9 -4
View File
@@ -242,8 +242,8 @@ def _property(parent, name, value):
return _sub(parent, M, name, **{"{" + M + "}val": str(value)})
def _run_properties(parent, spec):
properties = _sub(parent, A, "rPr", sz=str(round(spec["font_size_pt"] * 100)), b="0", dirty="0")
def _run_properties(parent, spec, *, tag="rPr"):
properties = _sub(parent, A, tag, sz=str(round(spec["font_size_pt"] * 100)), b="0", dirty="0")
_sub(_sub(properties, A, "solidFill"), A, "srgbClr", val=spec["color"][1:])
for script in ("latin", "ea", "cs"):
_sub(properties, A, script, typeface=spec["font_family"])
@@ -343,7 +343,10 @@ def _equation_shape(original, spec, px_to_emu):
_sub(body_props, A, "noAutofit")
_sub(body, A, "lstStyle")
paragraph = _sub(body, A, "p")
_sub(paragraph, A, "pPr", algn={"left": "l", "center": "ctr", "right": "r"}[spec["align"]])
paragraph_props = _sub(paragraph, A, "pPr", algn={"left": "l", "center": "ctr", "right": "r"}[spec["align"]])
# PowerPoint's math layout/export also reads the enclosing paragraph defaults.
# Run/control fonts alone leave radicals and tall delimiters incorrectly sized.
_run_properties(paragraph_props, spec, tag="defRPr")
math_node = _sub(paragraph, A14, "m")
if spec["display"] == "block":
container = _sub(math_node, M, "oMathPara")
@@ -351,6 +354,7 @@ def _equation_shape(original, spec, px_to_emu):
else:
container = math_node
_expression(_sub(container, M, "oMath"), spec["expression"], spec)
_run_properties(paragraph, spec, tag="endParaRPr")
return shape
@@ -386,7 +390,8 @@ def apply_math(path: Path, pages, canvas):
body = fallback.find("p:txBody", NS)
paragraph = body.find("a:p", NS)
paragraph.remove(paragraph.find("a14:m", NS))
run = _sub(paragraph, A, "r")
run = ET.Element("{" + A + "}r")
paragraph.insert(paragraph.index(paragraph.find("a:endParaRPr", NS)), run)
_run_properties(run, spec)
_sub(run, A, "t").text = linear_text(spec["expression"])
alternative = ET.Element("{" + MC + "}AlternateContent", nsmap={"mc": MC})