8000 Simplify handling of fontproperties=None. · matplotlib/matplotlib@4eda3f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4eda3f2

Browse files
committed
Simplify handling of fontproperties=None.
... by moving support for it (building a default FontProperties()) to the generic constructor `FontProperties._from_any`.
1 parent 5ab1352 commit 4eda3f2

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

lib/matplotlib/font_manager.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,20 @@ def __init__(self,
638638

639639
@classmethod
640640
def _from_any(cls, arg):
641+
"""
642+
Generic constructor which can build a `.FontProperties` from any of the
643+
following:
644+
645+
- a `.FontProperties`: it is passed through as is;
646+
- `None`: a `.FontProperties` using rc values is used;
647+
- an `os.PathLike`: it is used as path to the font file;
648+
- a `str`: it is parsed as a fontconfig pattern;
649+
- a `dict`: it is passed as ``**kwargs`` to `.FontProperties`.
650+
"""
641651
if isinstance(arg, cls):
642652
return arg
653+
elif arg is None:
654+
return cls()
643655
elif isinstance(arg, os.PathLike):
644656
return cls(fname=arg)
645657
elif isinstance(arg, str):

lib/matplotlib/text.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,9 @@ def __init__(self,
147147
"""
148148
Artist.__init__(self)
149149
self._x, self._y = x, y
150-
151-
if color is None:
152-
color = rcParams['text.color']
153-
if fontproperties is None:
154-
fontproperties = FontProperties()
155-
156150
self._text = ''
157151
self.set_text(text)
158-
self.set_color(color)
152+
self.set_color(color if color is not None else rcParams["text.color"])
159153
self.set_fontproperties(fontproperties)
160154
self.set_usetex(usetex)
161155
self.set_wrap(wrap)

lib/matplotlib/textpath.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,7 @@ def __init__(self, xy, s, size=None, prop=None,
385385
# Circular import.
386386
from matplotlib.text import Text
387387

388-
if prop is None:
389-
prop = FontProperties()
390-
else:
391-
prop = FontProperties._from_any(prop)
388+
prop = FontProperties._from_any(prop)
392389
if size is None:
393390
size = prop.get_size_in_points()
394391

0 commit comments

Comments
 (0)
0