MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _get_font_alt_names

Function _get_font_alt_names

lib/matplotlib/font_manager.py:552–625  ·  view source on GitHub ↗

Return ``(name, weight)`` pairs for alternate family names of *font*. A font file can advertise its family name in several places. FreeType exposes ``font.family_name``, which is typically derived from the Macintosh-platform Name ID 1 entry. However, other entries may carry d

(font, primary_name)

Source from the content-addressed store, hash-verified

550
551
552def _get_font_alt_names(font, primary_name):
553 """
554 Return ``(name, weight)`` pairs for alternate family names of *font*.
555
556 A font file can advertise its family name in several places. FreeType
557 exposes ``font.family_name``, which is typically derived from the
558 Macintosh-platform Name ID 1 entry. However, other entries may carry
559 different (equally valid) names that users reasonably expect to work:
560
561 - **Name ID 1, other platform** — some fonts store a different family name
562 on the Microsoft platform than on the Macintosh platform.
563 - **Name ID 16** — "Typographic Family" (a.k.a. preferred family): groups
564 more than the traditional four styles under one name.
565 - **Name ID 21** — "WWS Family": an even narrower grouping used by some
566 fonts (weight/width/slope only).
567
568 Each name is paired with a weight derived from the corresponding subfamily
569 entry on the *same* platform. This ensures that the weight of the alternate entry
570 reflects the font's role *within that named family* rather than its absolute
571 typographic weight.
572
573 Parameters
574 ----------
575 font : `.FT2Font`
576 primary_name : str
577 The family name already extracted from the font (``font.family_name``).
578
579 Returns
580 -------
581 list of (str, int)
582 ``(alternate_family_name, weight)`` pairs, not including *primary_name*.
583 """
584 try:
585 sfnt = font.get_sfnt()
586 except ValueError:
587 return []
588
589 mac_key = (1, # platform: macintosh
590 0, # id: roman
591 0) # langid: english
592 ms_key = (3, # platform: microsoft
593 1, # id: unicode_cs
594 0x0409) # langid: english_united_states
595
596 seen = {primary_name}
597 result = []
598
599 def _weight_from_subfam(subfam):
600 subfam = subfam.replace(" ", "")
601 for regex, weight in _weight_regexes:
602 if re.search(regex, subfam, re.I):
603 return weight
604 return 400 # "Regular" or unrecognised
605
606 def _try_add(name, subfam):
607 name = name.strip()
608 if not name or name in seen:
609 return

Callers 3

addfontMethod · 0.85

Calls 2

_try_addFunction · 0.85
getMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…