FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: accept fractional w:pgMar twips values in ST_TwipsMeasure by SAY-5 · Pull Request #1552 · python-openxml/python-docx · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion src/docx/oxml/simpletypes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/test_section.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

Back | FazBrowse Home | New Git URL