[文档]classFont(ElementProxy):"""Proxy object for parent of a `<w:rPr>` element and providing access to character properties such as font name, font size, bold, and subscript."""def__init__(self,r:CT_R,parent:Any|None=None):super().__init__(r,parent)self._element=rself._r=r@propertydefall_caps(self)->bool|None:"""Read/write. Causes text in this font to appear in capital letters. """returnself._get_bool_prop("caps")@all_caps.setterdefall_caps(self,value:bool|None)->None:self._set_bool_prop("caps",value)@propertydefbold(self)->bool|None:"""Read/write. Causes text in this font to appear in bold. """returnself._get_bool_prop("b")@bold.setterdefbold(self,value:bool|None)->None:self._set_bool_prop("b",value)@propertydefcolor(self):"""A |ColorFormat| object providing a way to get and set the text color for this font."""returnColorFormat(self._element)@propertydefcomplex_script(self)->bool|None:"""Read/write tri-state value. When |True|, causes the characters in the run to be treated as complex script regardless of their Unicode values. """returnself._get_bool_prop("cs")@complex_script.setterdefcomplex_script(self,value:bool|None)->None:self._set_bool_prop("cs",value)@propertydefcs_bold(self)->bool|None:"""Read/write tri-state value. When |True|, causes the complex script characters in the run to be displayed in bold typeface. """returnself._get_bool_prop("bCs")@cs_bold.setterdefcs_bold(self,value:bool|None)->None:self._set_bool_prop("bCs",value)@propertydefcs_italic(self)->bool|None:"""Read/write tri-state value. When |True|, causes the complex script characters in the run to be displayed in italic typeface. """returnself._get_bool_prop("iCs")@cs_italic.setterdefcs_italic(self,value:bool|None)->None:self._set_bool_prop("iCs",value)@propertydefdouble_strike(self)->bool|None:"""Read/write tri-state value. When |True|, causes the text in the run to appear with double strikethrough. """returnself._get_bool_prop("dstrike")@double_strike.setterdefdouble_strike(self,value:bool|None)->None:self._set_bool_prop("dstrike",value)@propertydefemboss(self)->bool|None:"""Read/write tri-state value. When |True|, causes the text in the run to appear as if raised off the page in relief. """returnself._get_bool_prop("emboss")@emboss.setterdefemboss(self,value:bool|None)->None:self._set_bool_prop("emboss",value)@propertydefhidden(self)->bool|None:"""Read/write tri-state value. When |True|, causes the text in the run to be hidden from display, unless applications settings force hidden text to be shown. """returnself._get_bool_prop("vanish")@hidden.setterdefhidden(self,value:bool|None)->None:self._set_bool_prop("vanish",value)@propertydefhighlight_color(self)->WD_COLOR_INDEX|None:"""Color of highlighing applied or |None| if not highlighted."""rPr=self._element.rPrifrPrisNone:returnNonereturnrPr.highlight_val@highlight_color.setterdefhighlight_color(self,value:WD_COLOR_INDEX|None):rPr=self._element.get_or_add_rPr()rPr.highlight_val=value@propertydefitalic(self)->bool|None:"""Read/write tri-state value. When |True|, causes the text of the run to appear in italics. |None| indicates the effective value is inherited from the style hierarchy. """returnself._get_bool_prop("i")@italic.setterdefitalic(self,value:bool|None)->None:self._set_bool_prop("i",value)@propertydefimprint(self)->bool|None:"""Read/write tri-state value. When |True|, causes the text in the run to appear as if pressed into the page. """returnself._get_bool_prop("imprint")@imprint.setterdefimprint(self,value:bool|None)->None:self._set_bool_prop("imprint",value)@propertydefmath(self)->bool|None:"""Read/write tri-state value. When |True|, specifies this run contains WML that should be handled as though it was Office Open XML Math. """returnself._get_bool_prop("oMath")@math.setterdefmath(self,value:bool|None)->None:self._set_bool_prop("oMath",value)@propertydefname(self)->str|None:"""The 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.rPrifrPrisNone:returnNonereturnrPr.rFonts_ascii@name.setterdefname(self,value:str|None)->None:rPr=self._element.get_or_add_rPr()rPr.rFonts_ascii=valuerPr.rFonts_hAnsi=value@propertydefno_proof(self)->bool|None:"""Read/write tri-state value. When |True|, specifies that the contents of this run should not report any errors when the document is scanned for spelling and grammar. """returnself._get_bool_prop("noProof")@no_proof.setterdefno_proof(self,value:bool|None)->None:self._set_bool_prop("noProof",value)@propertydefoutline(self)->bool|None:"""Read/write tri-state value. When |True| causes the characters in the run to appear as if they have an outline, by drawing a one pixel wide border around the inside and outside borders of each character glyph. """returnself._get_bool_prop("outline")@outline.setterdefoutline(self,value:bool|None)->None:self._set_bool_prop("outline",value)@propertydefrtl(self)->bool|None:"""Read/write tri-state value. When |True| causes the text in the run to have right-to-left characteristics. """returnself._get_bool_prop("rtl")@rtl.setterdefrtl(self,value:bool|None)->None:self._set_bool_prop("rtl",value)@propertydefshadow(self)->bool|None:"""Read/write tri-state value. When |True| causes the text in the run to appear as if each character has a shadow. """returnself._get_bool_prop("shadow")@shadow.setterdefshadow(self,value:bool|None)->None:self._set_bool_prop("shadow",value)@propertydefsize(self)->Length|None:"""Font height in English Metric Units (EMU). |None| indicates the font size should be inherited from the style hierarchy. |Length| is a subclass of |int| having properties for convenient conversion into points or other length units. The :class:`docx.shared.Pt` class allows convenient specification of point values:: >>> font.size = Pt(24) >>> font.size 304800 >>> font.size.pt 24.0 """rPr=self._element.rPrifrPrisNone:returnNonereturnrPr.sz_val@size.setterdefsize(self,emu:int|Length|None)->None:rPr=self._element.get_or_add_rPr()rPr.sz_val=NoneifemuisNoneelseEmu(emu)@propertydefsmall_caps(self)->bool|None:"""Read/write tri-state value. When |True| causes the lowercase characters in the run to appear as capital letters two points smaller than the font size specified for the run. """returnself._get_bool_prop("smallCaps")@small_caps.setterdefsmall_caps(self,value:bool|None)->None:self._set_bool_prop("smallCaps",value)@propertydefsnap_to_grid(self)->bool|None:"""Read/write tri-state value. When |True| causes the run to use the document grid characters per line settings defined in the docGrid element when laying out the characters in this run. """returnself._get_bool_prop("snapToGrid")@snap_to_grid.setterdefsnap_to_grid(self,value:bool|None)->None:self._set_bool_prop("snapToGrid",value)@propertydefspec_vanish(self)->bool|None:"""Read/write tri-state value. When |True|, specifies that the given run shall always behave as if it is hidden, even when hidden text is being displayed in the current document. The property has a very narrow, specialized use related to the table of contents. Consult the spec (§17.3.2.36) for more details. """returnself._get_bool_prop("specVanish")@spec_vanish.setterdefspec_vanish(self,value:bool|None)->None:self._set_bool_prop("specVanish",value)@propertydefstrike(self)->bool|None:"""Read/write tri-state value. When |True| causes the text in the run to appear with a single horizontal line through the center of the line. """returnself._get_bool_prop("strike")@strike.setterdefstrike(self,value:bool|None)->None:self._set_bool_prop("strike",value)@propertydefsubscript(self)->bool|None:"""Boolean indicating whether the characters in this |Font| appear as subscript. |None| indicates the subscript/subscript value is inherited from the style hierarchy. """rPr=self._element.rPrifrPrisNone:returnNonereturnrPr.subscript@subscript.setterdefsubscript(self,value:bool|None)->None:rPr=self._element.get_or_add_rPr()rPr.subscript=value@propertydefsuperscript(self)->bool|None:"""Boolean indicating whether the characters in this |Font| appear as superscript. |None| indicates the subscript/superscript value is inherited from the style hierarchy. """rPr=self._element.rPrifrPrisNone:returnNonereturnrPr.superscript@superscript.setterdefsuperscript(self,value:bool|None)->None:rPr=self._element.get_or_add_rPr()rPr.superscript=value@propertydefunderline(self)->bool|WD_UNDERLINE|None:"""The underline style for this |Font|. The value is one of |None|, |True|, |False|, or a member of :ref:`WdUnderline`. |None| indicates the font inherits its underline value from the style hierarchy. |False| indicates no underline. |True| indicates single underline. The values from :ref:`WdUnderline` are used to specify other outline styles such as double, wavy, and dotted. """rPr=self._element.rPrifrPrisNone:returnNoneval=rPr.u_valreturn(Noneifval==WD_UNDERLINE.INHERITEDelseTrueifval==WD_UNDERLINE.SINGLEelseFalseifval==WD_UNDERLINE.NONEelseval)@underline.setterdefunderline(self,value:bool|WD_UNDERLINE|None)->None:rPr=self._element.get_or_add_rPr()# -- works fine without these two mappings, but only because True == 1 and# -- False == 0, which happen to match the mapping for WD_UNDERLINE.SINGLE# -- and .NONE respectively.val=(WD_UNDERLINE.SINGLEifvalueisTrueelseWD_UNDERLINE.NONEifvalueisFalseelsevalue)rPr.u_val=val@propertydefweb_hidden(self)->bool|None:"""Read/write tri-state value. When |True|, specifies that the contents of this run shall be hidden when the document is displayed in web page view. """returnself._get_bool_prop("webHidden")@web_hidden.setterdefweb_hidden(self,value:bool|None)->None:self._set_bool_prop("webHidden",value)def_get_bool_prop(self,name:str)->bool|None:"""Return the value of boolean child of `w:rPr` having `name`."""rPr=self._element.rPrifrPrisNone:returnNonereturnrPr._get_bool_val(name)# pyright: ignore[reportPrivateUsage]def_set_bool_prop(self,name:str,value:bool|None):"""Assign `value` to the boolean child `name` of `w:rPr`."""rPr=self._element.get_or_add_rPr()rPr._set_bool_val(name,value)# pyright: ignore[reportPrivateUsage]