MCPcopy Create free account
hub / github.com/scanny/python-pptx / _Font

Class _Font

src/pptx/text/fonts.py:96–188  ·  view source on GitHub ↗

A wrapper around an OTF/TTF font file stream that knows how to parse it for its name and style characteristics, e.g. bold and italic.

Source from the content-addressed store, hash-verified

94
95
96class _Font(object):
97 """
98 A wrapper around an OTF/TTF font file stream that knows how to parse it
99 for its name and style characteristics, e.g. bold and italic.
100 """
101
102 def __init__(self, stream):
103 self._stream = stream
104
105 def __enter__(self):
106 return self
107
108 def __exit__(self, exception_type, exception_value, exception_tb):
109 self._stream.close()
110
111 @property
112 def is_bold(self):
113 """
114 |True| if this font is marked as a bold style of its font family.
115 """
116 try:
117 return self._tables["head"].is_bold
118 except KeyError:
119 # some files don't have a head table
120 return False
121
122 @property
123 def is_italic(self):
124 """
125 |True| if this font is marked as an italic style of its font family.
126 """
127 try:
128 return self._tables["head"].is_italic
129 except KeyError:
130 # some files don't have a head table
131 return False
132
133 @classmethod
134 def open(cls, font_file_path):
135 """
136 Return a |_Font| instance loaded from *font_file_path*.
137 """
138 return cls(_Stream.open(font_file_path))
139
140 @property
141 def family_name(self):
142 """
143 The name of the typeface family for this font, e.g. 'Arial'. The full
144 typeface name includes optional style names, such as 'Regular' or
145 'Bold Italic'. This attribute is only the common base name shared by
146 all fonts in the family.
147 """
148 return self._tables["name"].family_name
149
150 @lazyproperty
151 def _fields(self):
152 """5-tuple containing the fields read from the font file header.
153

Callers 7

bold_fixtureMethod · 0.90
family_fixtureMethod · 0.90
italic_fixtureMethod · 0.90
iter_fixtureMethod · 0.90
tables_fixtureMethod · 0.90
table_count_fixtureMethod · 0.90

Calls

no outgoing calls

Tested by 7

bold_fixtureMethod · 0.72
family_fixtureMethod · 0.72
italic_fixtureMethod · 0.72
iter_fixtureMethod · 0.72
tables_fixtureMethod · 0.72
table_count_fixtureMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…