MCPcopy
hub / github.com/matplotlib/matplotlib / _from_any

Method _from_any

lib/matplotlib/font_manager.py:839–859  ·  view source on GitHub ↗

Generic constructor which can build a `.FontProperties` from any of the following: - a `.FontProperties`: it is passed through as is; - `None`: a `.FontProperties` using rc values is used; - an `os.PathLike`: it is used as path to the font file; - a

(cls, arg)

Source from the content-addressed store, hash-verified

837
838 @classmethod
839 def _from_any(cls, arg):
840 """
841 Generic constructor which can build a `.FontProperties` from any of the
842 following:
843
844 - a `.FontProperties`: it is passed through as is;
845 - `None`: a `.FontProperties` using rc values is used;
846 - an `os.PathLike`: it is used as path to the font file;
847 - a `str`: it is parsed as a fontconfig pattern;
848 - a `dict`: it is passed as ``**kwargs`` to `.FontProperties`.
849 """
850 if arg is None:
851 return cls()
852 elif isinstance(arg, cls):
853 return arg
854 elif isinstance(arg, os.PathLike):
855 return cls(fname=arg)
856 elif isinstance(arg, str):
857 return cls(arg)
858 else:
859 return cls(**arg)
860
861 def __hash__(self):
862 return hash(tuple(self.__dict__.values()))

Callers 6

set_fontpropertiesMethod · 0.80
_find_fonts_by_propsMethod · 0.80
_findfont_cachedMethod · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected