From c9fc2714304fceaf4e4b153663d437411b4d8359 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Tue, 12 May 2026 15:24:37 -0700 Subject: [PATCH] fix: accept fractional w:pgMar twips values in ST_TwipsMeasure --- src/docx/oxml/simpletypes.py | 2 +- tests/test_section.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/docx/oxml/simpletypes.py b/src/docx/oxml/simpletypes.py index a0fc87d3f..4d7341220 100644 --- a/src/docx/oxml/simpletypes.py +++ b/src/docx/oxml/simpletypes.py @@ -399,7 +399,7 @@ class ST_TwipsMeasure(XsdUnsignedLong): def convert_from_xml(cls, str_value: str) -> Length: if "i" in str_value or "m" in str_value or "p" in str_value: return ST_UniversalMeasure.convert_from_xml(str_value) - return Twips(int(str_value)) + return Twips(int(round(float(str_value)))) @classmethod def convert_to_xml(cls, value: int | Length) -> str: diff --git a/tests/test_section.py b/tests/test_section.py index 54d665768..d01ca275d 100644 --- a/tests/test_section.py +++ b/tests/test_section.py @@ -446,6 +446,7 @@ def it_can_change_its_orientation( ("sectPr_cxml", "margin_prop_name", "expected_value"), [ ("w:sectPr/w:pgMar{w:left=120}", "left_margin", 76200), + ("w:sectPr/w:pgMar{w:left=119.6}", "left_margin", 76200), ("w:sectPr/w:pgMar{w:right=240}", "right_margin", 152400), ("w:sectPr/w:pgMar{w:top=-360}", "top_margin", -228600), ("w:sectPr/w:pgMar{w:bottom=480}", "bottom_margin", 304800),