具备的方法
源码
class Font(object):
"""
Character properties object, providing font size, font name, bold,
italic, etc. Corresponds to ``<a:rPr>`` child element of a run. Also
appears as ``<a:defRPr>`` and ``<a:endParaRPr>`` in paragraph and
``<a:defRPr>`` in list style elements.
"""
def __init__(self, rPr):
super(Font, self).__init__()
self._element = self._rPr = rPr
@property
def bold(self):
"""
Get or set boolean bold value of |Font|, e.g.
``paragraph.font.bold = True``. If set to |None|, the bold setting is
cleared and is inherited from an enclosing shape's setting, or a
setting in a style or master. Returns None if no bold attribute is
present, meaning the effective bold value is inherited from a master
or the theme.
"""
return self._rPr.b
@bold.setter
def bold(self, value):
self._rPr.b = value
@lazyproperty
def color(self):
"""
The |ColorFormat| instance that provides access to the color settings
for this font.
"""
if self.fill.type != MSO_FILL.SOLID:
self.fill.solid()
return self.fill.fore_color
@lazyproperty
def fill(self):
"""
|FillFormat| instance for this font, providing access to fill
properties such as fill color.
"""
return FillFormat.from_fill_parent(self._rPr)
@property
def italic(self):
"""
Get or set boolean italic value of |Font| instance, with the same
behaviors as bold with respect to None values.
"""
return self._rPr.i
@italic.setter
def italic(self, value):
self._rPr.i = value
@property
def language_id(self):
"""
Get or set the language id of this |Font| instance. The language id
is a member of the :ref:`MsoLanguageId` enumeration. Assigning |None|
removes any language setting, the same behavior as assigning
`MSO_LANGUAGE_ID.NONE`.
"""
lang = self._rPr.lang
if lang is None:
return MSO_LANGUAGE_ID.NONE
return self._rPr.lang
@language_id.setter
def language_id(self, value):
if value == MSO_LANGUAGE_ID.NONE:
value = None
self._rPr.lang = value
@property
def name(self):
"""
Get or set the typeface name for this |Font| instance, causing the
text it controls to appear in the named font, if a matching font is
found. Returns |None| if the typeface is currently inherited from the
theme. Setting it to |None| removes any override of the theme
typeface.
"""
latin = self._rPr.latin
if latin is None:
return None
return latin.typeface
@name.setter
def name(self, value):
if value is None:
self._rPr._remove_latin()
else:
latin = self._rPr.get_or_add_latin()
latin.typeface = value
@property
def size(self):
"""
Read/write |Length| value or |None|, indicating the font height in
English Metric Units (EMU). |None| indicates the font size should be
inherited from its style hierarchy, such as a placeholder or document
defaults (usually 18pt). |Length| is a subclass of |int| having
properties for convenient conversion into points or other length
units. Likewise, the :class:`pptx.util.Pt` class allows convenient
specification of point values::
>> font.size = Pt(24)
>> font.size
304800
>> font.size.pt
24.0
"""
sz = self._rPr.sz
if sz is None:
return None
return Centipoints(sz)
@size.setter
def size(self, emu):
if emu is None:
self._rPr.sz = None
else:
sz = Emu(emu).centipoints
self._rPr.sz = sz
@property
def underline(self):
"""
Read/write. |True|, |False|, |None|, or a member of the
:ref:`MsoTextUnderlineType` enumeration indicating the underline
setting for this font. |None| is the default and indicates the
underline setting should be inherited from the style hierarchy, such
as from a placeholder. |True| indicates single underline. |False|
indicates no underline. Other settings such as double and wavy
underlining are indicated with members of the
:ref:`MsoTextUnderlineType` enumeration.
"""
u = self._rPr.u
if u is MSO_UNDERLINE.NONE:
return False
if u is MSO_UNDERLINE.SINGLE_LINE:
return True
return u
@underline.setter
def underline(self, value):
if value is True:
value = MSO_UNDERLINE.SINGLE_LINE
elif value is False:
value = MSO_UNDERLINE.NONE
self._element.u = value