Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69916e5

Browse files
committed
refactor: python layer cleanup
1 parent b319e4a commit 69916e5

2 files changed

Lines changed: 19 additions & 22 deletions

File tree

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, _check_savefig_extra_args, 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
@@ -300,7 +300,7 @@ def _get_agg_font(self, prop):
300300
"""
301301
Get the font for text instance t, caching for efficiency
302302
"""
303-
fname = find_fontsprop(prop)
303+
fname = find_fonts_by_props(prop)
304304
font = get_font(fname)
305305

306306
font.clear()

lib/matplotlib/font_manager.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,8 @@ def findfont(self, prop, fontext='ttf', directory=None,
13101310
prop, fontext, directory, fallback_to_default, rebuild_if_missing,
13111311
rc_params)
13121312

1313-
def find_fontsprop(self, prop, fontext='ttf', directory=None,
1314-
fallback_to_default=True, rebuild_if_missing=True):
1313+
def find_fonts_by_props(self, prop, fontext='ttf', directory=None,
1314+
fallback_to_default=True, rebuild_if_missing=True):
13151315
"""
13161316
Find font families that most closely matches the given properties.
13171317
@@ -1362,29 +1362,29 @@ def find_fontsprop(self, prop, fontext='ttf', directory=None,
13621362
"font.monospace"])
13631363

13641364
prop = FontProperties._from_any(prop)
1365-
ffamily = prop.get_family()
13661365

13671366
fpaths = OrderedDict()
1368-
for fidx in range(len(ffamily)):
1367+
for family in prop.get_family():
13691368
cprop = prop.copy()
13701369

13711370
# set current prop's family
1372-
cprop.set_family(ffamily[fidx])
1371+
cprop.set_family(family)
13731372

13741373
# do not fall back to default font
13751374
fpath = self._findfontsprop_cached(
1376-
ffamily[fidx], cprop, fontext, directory,
1375+
family, cprop, fontext, directory,
13771376
False, rebuild_if_missing, rc_params
13781377
)
13791378
if fpath:
1380-
fpaths[ffamily[fidx]] = fpath
1379+
fpaths[family] = fpath
13811380

13821381
# only add default family if no other font was found
13831382
# and fallback_to_default is enabled
13841383
if not fpaths:
13851384
if fallback_to_default:
13861385
dfamily = self.defaultFamily[fontext]
1387-
cprop = prop.copy().set_family(dfamily)
1386+
cprop = prop.copy()
1387+
cprop.set_family(dfamily)
13881388
fpath = self._findfontsprop_cached(
13891389
dfamily, cprop, fontext, directory,
13901390
True, rebuild_if_missing, rc_params
@@ -1514,20 +1514,17 @@ def is_opentype_cff_font(filename):
15141514

15151515
@lru_cache(64)
15161516
def _get_font(fpaths, hinting_factor, *, _kerning_factor, thread_id):
1517-
ftobjects = []
1518-
for fpath in fpaths[1:]:
1519-
ftobject = ft2font.FT2Font(
1520-
fpath, hinting_factor,
1521-
_kerning_factor=_kerning_factor
1522-
)
1523-
ftobjects.append(ftobject)
1524-
1525-
ft2font_object = ft2font.FT2Font(
1517+
return ft2font.FT2Font(
15261518
fpaths[0], hinting_factor,
1527-
_fallback_list=ftobjects,
1519+
_fallback_list=[
1520+
ft2font.FT2Font(
1521+
fpath, hinting_factor,
1522+
_kerning_factor=_kerning_factor
1523+
)
1524+
for fpath in fpaths[1:]
1525+
],
15281526
_kerning_factor=_kerning_factor
15291527
)
1530-
return ft2font_object
15311528

15321529

15331530
# FT2Font objects cannot be used across fork()s because they reference the same
@@ -1573,4 +1570,4 @@ def _load_fontmanager(*, try_read_cache=True):
15731570

15741571
fontManager = _load_fontmanager()
15751572
findfont = fontManager.findfont
1576-
find_fontsprop = fontManager.find_fontsprop
1573+
find_fonts_by_props = fontManager.find_fonts_by_props

0 commit comments

Comments
 (0)