8000 refactor: python layer cleanup · matplotlib/matplotlib@9e3809f · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e3809f

Browse files
aitikguptatacaswell
authored andcommitted
refactor: python layer cleanup
1 parent be3bc67 commit 9e3809f

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from matplotlib.backend_bases import (
3838
_Backend, FigureCanvasBase, FigureManagerBase,
3939
RendererBase)
40-
from matplotlib.font_manager import find_fontsprop, get_font
40+
from matplotlib.font_manager import find_fonts_by_props, get_font
4141
from matplotlib.ft2font import (LOAD_FORCE_AUTOHINT, LOAD_NO_HINTING,
4242
LOAD_DEFAULT, LOAD_NO_AUTOHINT)
4343
from matplotlib.mathtext import MathTextParser
@@ -293,7 +293,7 @@ def _prepare_font(self, font_prop):
293293
"""
294294
Get the `.FT2Font` for *font_prop*, clear its buffer, and set its size.
295295
"""
296-
fname = find_fontsprop(font_prop)
296+
fname = find_fonts_by_props(font_prop)
297297
font = get_font(fname)
298298

299299
font.clear()

lib/matplotlib/font_manager.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,8 +1335,8 @@ def get_font_names(self):
13351335
"""Return the list of available fonts."""
13361336
return list(set([font.name for font in self.ttflist]))
13371337

1338-
def find_fontsprop(self, prop, fontext='ttf', directory=None,
1339-
fallback_to_default=True, rebuild_if_missing=True):
1338+
def find_fonts_by_props(self, prop, fontext='ttf', directory=None,
1339+
fallback_to_default=True, rebuild_if_missing=True):
13401340
"""
13411341
Find font families that most closely matches the given properties.
13421342
@@ -1387,29 +1387,29 @@ def find_fontsprop(self, prop, fontext='ttf', directory=None,
13871387
"font.monospace"])
13881388

13891389
prop = FontProperties._from_any(prop)
1390-
ffamily = prop.get_family()
13911390

13921391
fpaths = OrderedDict()
1393-
for fidx in range(len 10000 (ffamily)):
1392+
for family in prop.get_family():
13941393
cprop = prop.copy()
13951394

13961395
# set current prop's family
1397-
cprop.set_family(ffamily[fidx])
1396+
cprop.set_family(family)
13981397

13991398
# do not fall back to default font
14001399
fpath = self._findfontsprop_cached(
1401-
ffamily[fidx], cprop, fontext, directory,
1400+
family, cprop, fontext, directory,
14021401
False, rebuild_if_missing, rc_params
14031402
)
14041403
if fpath:
1405-
fpaths[ffamily[fidx]] = fpath
1404+
fpaths[family] = fpath
14061405

14071406
# only add default family if no other font was found
14081407
# and fallback_to_default is enabled
14091408
if not fpaths:
14101409
if fallback_to_default:
14111410
dfamily = self.defaultFamily[fontext]
1412-
cprop = prop.copy().set_family(dfamily)
1411+
cprop = prop.copy()
1412+
cprop.set_family(dfamily)
14131413
fpath = self._findfontsprop_cached(
14141414
dfamily, cprop, fontext, directory,
14151415
True, rebuild_if_missing, rc_params
@@ -1539,20 +1539,17 @@ def is_opentype_cff_font(filename):
15391539

15401540
@lru_cache(64)
15411541
def _get_font(fpaths, hinting_factor, *, _kerning_factor, thread_id):
1542-
ftobjects = []
1543-
for fpath in fpaths[1:]:
1544-
ftobject = ft2font.FT2Font(
1545-
fpath, hinting_factor,
1546-
_kerning_factor=_kerning_factor
1547-
)
1548-
ftobjects.append(ftobject)
1549-
1550-
ft2font_object = ft2font.FT2Font(
1542+
return ft2font.FT2Font(
15511543
fpaths[0], hinting_factor,
1552-
_fallback_list=ftobjects,
1544+
_fallback_list=[
1545+
ft2font.FT2Font(
1546+
fpath, hinting_factor,
1547+
_kerning_factor=_kerning_factor
1548+
)
1549+
for fpath in fpaths[1:]
1550+
],
15531551
_kerning_factor=_kerning_factor
15541552
)
1555-
return ft2font_object
15561553

15571554

15581555
# FT2Font objects cannot be used across fork()s because they reference the same
@@ -1600,4 +1597,4 @@ def _load_fontmanager(*, try_read_cache=True):
16001597
fontManager = _load_fontmanager()
16011598
findfont = fontManager.findfont
16021599
get_font_names = fontManager.get_font_names
1603-
find_fontsprop = fontManager.find_fontsprop
1600+
find_fonts_by_props = fontManager.find_fonts_by_props

0 commit comments

Comments
 (0)
0