An OpenType font table having the tag 'name' and containing the name-related strings for the font.
| 274 | |
| 275 | |
| 276 | class _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): |
no outgoing calls
searching dependent graphs…