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

Class _NameTable

src/pptx/text/fonts.py:276–390  ·  view source on GitHub ↗

An OpenType font table having the tag 'name' and containing the name-related strings for the font.

Source from the content-addressed store, hash-verified

274
275
276class _NameTable(_BaseTable):
277 """
278 An OpenType font table having the tag 'name' and containing the
279 name-related strings for the font.
280 """
281
282 def __init__(self, tag, stream, offset, length):
283 super(_NameTable, self).__init__(tag, stream, offset, length)
284
285 @property
286 def family_name(self):
287 """
288 The name of the typeface family for this font, e.g. 'Arial'.
289 """
290
291 def find_first(dict_, keys, default=None):
292 for key in keys:
293 value = dict_.get(key)
294 if value is not None:
295 return value
296 return default
297
298 # keys for Unicode, Mac, and Windows family name, respectively
299 return find_first(self._names, ((0, 1), (1, 1), (3, 1)))
300
301 @staticmethod
302 def _decode_name(raw_name, platform_id, encoding_id):
303 """
304 Return the unicode name decoded from *raw_name* using the encoding
305 implied by the combination of *platform_id* and *encoding_id*.
306 """
307 if platform_id == 1:
308 # reject non-Roman Mac font names
309 if encoding_id != 0:
310 return None
311 return raw_name.decode("mac-roman")
312 elif platform_id in (0, 3):
313 return raw_name.decode("utf-16-be")
314 else:
315 return None
316
317 def _iter_names(self):
318 """Generate a key/value pair for each name in this table.
319
320 The key is a (platform_id, name_id) 2-tuple and the value is the unicode text
321 corresponding to that key.
322 """
323 table_format, count, strings_offset = self._table_header
324 table_bytes = self._table_bytes
325
326 for idx in range(count):
327 platform_id, name_id, name = self._read_name(table_bytes, idx, strings_offset)
328 if name is None:
329 continue
330 yield ((platform_id, name_id), name)
331
332 @staticmethod
333 def _name_header(bufr, idx):

Callers 10

bytes_fixtureMethod · 0.90
decode_fixtureMethod · 0.90
family_fixtureMethod · 0.90
header_fixtureMethod · 0.90
name_hdr_fixtureMethod · 0.90
name_text_fixtureMethod · 0.90
raw_fixtureMethod · 0.90

Calls

no outgoing calls

Tested by 10

bytes_fixtureMethod · 0.72
decode_fixtureMethod · 0.72
family_fixtureMethod · 0.72
header_fixtureMethod · 0.72
name_hdr_fixtureMethod · 0.72
name_text_fixtureMethod · 0.72
raw_fixtureMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…