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

Function afmFontProperty

lib/matplotlib/font_manager.py:628–695  ·  view source on GitHub ↗

Extract information from an AFM font file. Parameters ---------- fontpath : str The filename corresponding to *font*. font : AFM The AFM font file from which information will be extracted. Returns ------- `FontEntry` The extracted font prope

(fontpath, font)

Source from the content-addressed store, hash-verified

626
627
628def afmFontProperty(fontpath, font):
629 """
630 Extract information from an AFM font file.
631
632 Parameters
633 ----------
634 fontpath : str
635 The filename corresponding to *font*.
636 font : AFM
637 The AFM font file from which information will be extracted.
638
639 Returns
640 -------
641 `FontEntry`
642 The extracted font properties.
643 """
644
645 name = font.get_familyname()
646 fontname = font.get_fontname().lower()
647
648 # Styles are: italic, oblique, and normal (default)
649
650 if font.get_angle() != 0 or 'italic' in name.lower():
651 style = 'italic'
652 elif 'oblique' in name.lower():
653 style = 'oblique'
654 else:
655 style = 'normal'
656
657 # Variants are: small-caps and normal (default)
658
659 # !!!! Untested
660 if name.lower() in ['capitals', 'small-caps']:
661 variant = 'small-caps'
662 else:
663 variant = 'normal'
664
665 weight = font.get_weight().lower()
666 if weight not in weight_dict:
667 weight = 'normal'
668
669 # Stretch can be absolute and relative
670 # Absolute stretches are: ultra-condensed, extra-condensed, condensed,
671 # semi-condensed, normal, semi-expanded, expanded, extra-expanded,
672 # and ultra-expanded.
673 # Relative stretches are: wider, narrower
674 # Child value is: inherit
675 if 'demi cond' in fontname:
676 stretch = 'semi-condensed'
677 elif any(word in fontname for word in ['narrow', 'cond']):
678 stretch = 'condensed'
679 elif any(word in fontname for word in ['wide', 'expanded', 'extended']):
680 stretch = 'expanded'
681 else:
682 stretch = 'normal'
683
684 # Sizes can be absolute and relative.
685 # Absolute sizes are: xx-small, x-small, small, medium, large, x-large,

Callers 1

addfontMethod · 0.85

Calls 5

FontEntryClass · 0.85
get_familynameMethod · 0.80
get_fontnameMethod · 0.45
get_angleMethod · 0.45
get_weightMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…