From d801af121fa008e3c5279fdc6baf9ab7d9b73eb7 Mon Sep 17 00:00:00 2001 From: floatid Date: Sat, 2 Mar 2024 21:11:48 +0530 Subject: [PATCH 1/2] Add capability to get/set complex script fontname --- src/docx/oxml/text/font.py | 19 ++++++++++++++++++- src/docx/text/font.py | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/docx/oxml/text/font.py b/src/docx/oxml/text/font.py index 0e183cf65..58d026dae 100644 --- a/src/docx/oxml/text/font.py +++ b/src/docx/oxml/text/font.py @@ -45,7 +45,9 @@ class CT_Fonts(BaseOxmlElement): hAnsi: str | None = OptionalAttribute( # pyright: ignore[reportGeneralTypeIssues] "w:hAnsi", ST_String ) - + cs: str | None = OptionalAttribute( # pyright: ignore[reportGeneralTypeIssues] + "w:cs", ST_String + ) class CT_Highlight(BaseOxmlElement): """`w:highlight` element, specifying font highlighting/background color.""" @@ -226,6 +228,21 @@ def rFonts_hAnsi(self, value: str | None): rFonts = self.get_or_add_rFonts() rFonts.hAnsi = value + @property + def rFonts_cs(self) -> str | None: + """The value of `w:rFonts/@w:cs` or |None| if not present.""" + rFonts = self.rFonts + if rFonts is None: + return None + return rFonts.cs + + @rFonts_cs.setter + def rFonts_cs(self, value: str | None): + if value is None and self.rFonts is None: + return + rFonts = self.get_or_add_rFonts() + rFonts.cs = value + @property def style(self) -> str | None: """String in `./w:rStyle/@val`, or None if `w:rStyle` is not present.""" diff --git a/src/docx/text/font.py b/src/docx/text/font.py index acd60795b..8fe8c8b6e 100644 --- a/src/docx/text/font.py +++ b/src/docx/text/font.py @@ -199,6 +199,23 @@ def name(self, value: str | None) -> None: rPr.rFonts_ascii = value rPr.rFonts_hAnsi = value + @property + def name_cs(self) -> str | None: + """The cs typeface name for this |Font|. + + Causes the text it controls to appear in the named font, if a matching font is + found. |None| indicates the typeface is inherited from the style hierarchy. + """ + rPr = self._element.rPr + if rPr is None: + return None + return rPr.rFonts_cs + + @name.setter + def name_cs(self, value: str | None) -> None: + rPr = self._element.get_or_add_rPr() + rPr.rFonts_cs = value + @property def no_proof(self) -> bool | None: """Read/write tri-state value. From 86bcb67c5d9d2d7fe85edf2bf77b515ee4b60d7e Mon Sep 17 00:00:00 2001 From: floatid Date: Sat, 2 Mar 2024 22:43:19 +0530 Subject: [PATCH 2/2] Update font.py --- src/docx/text/font.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docx/text/font.py b/src/docx/text/font.py index 8fe8c8b6e..fda728985 100644 --- a/src/docx/text/font.py +++ b/src/docx/text/font.py @@ -215,7 +215,7 @@ def name_cs(self) -> str | None: def name_cs(self, value: str | None) -> None: rPr = self._element.get_or_add_rPr() rPr.rFonts_cs = value - + @property def no_proof(self) -> bool | None: """Read/write tri-state value.