Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ per-file-ignores =
lib/matplotlib/backends/qt_editor/formlayout.py: F401, F403
lib/matplotlib/cbook/__init__.py: F401
lib/matplotlib/cbook/deprecation.py: F401
lib/matplotlib/font_manager.py: E221, E251, E501
lib/matplotlib/font_manager.py: E501
lib/matplotlib/image.py: F401, F403
lib/matplotlib/lines.py: F401
lib/matplotlib/mathtext.py: E221, E251
Expand Down
4 changes: 2 additions & 2 deletions doc/api/font_manager_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
:undoc-members:
:show-inheritance:



.. autoclass:: FontEntry
:no-undoc-members:
58 changes: 20 additions & 38 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# - setWeights function needs improvement
# - 'light' is an invalid weight value, remove it.

import dataclasses
from functools import lru_cache
import json
import logging
Expand Down Expand Up @@ -342,35 +343,22 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
return [fname for fname in fontfiles if os.path.exists(fname)]


class FontEntry:
"""
A class for storing Font properties. It is used when populating
the font lookup dictionary.
"""
def __init__(self,
fname ='',
name ='',
style ='normal',
variant='normal',
weight ='normal',
stretch='normal',
size ='medium',
):
self.fname = fname
self.name = name
self.style = style
self.variant = variant
self.weight = weight
self.stretch = stretch
try:
self.size = str(float(size))
except ValueError:
self.size = size
Comment on lines -365 to -368
Copy link
Member Author

@QuLogic QuLogic Apr 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is only called in two places, always with size='scalable', so there's no point to this conversion.

FontEntry = dataclasses.make_dataclass(
'FontEntry', [
('fname', str, dataclasses.field(default='')),
('name', str, dataclasses.field(default='')),
('style', str, dataclasses.field(default='normal')),
('variant', str, dataclasses.field(default='normal')),
('weight', str, dataclasses.field(default='normal')),
('stretch', str, dataclasses.field(default='normal')),
('size', str, dataclasses.field(default='medium')),
],
namespace={
'__doc__': """
A class for storing Font properties.

def __repr__(self):
return "<Font '%s' (%s) %s %s %s %s>" % (
self.name, os.path.basename(self.fname), self.style, self.variant,
self.weight, self.stretch)
It is used when populating the font lookup dictionary.
"""})


def ttfFontProperty(font):
Expand Down Expand Up @@ -630,16 +618,10 @@ class FontProperties:
fontconfig.
"""

def __init__(self,
family = None,
style = None,
variant= None,
weight = None,
stretch= None,
size = None,
fname = None, # if set, it's a hardcoded filename to use
math_fontfamily = None,
):
def __init__(self, family=None, style=None, variant=None, weight=None,
stretch=None, size=None,
fname=None, # if set, it's a hardcoded filename to use
math_fontfamily=None):
self._family = _normalize_font_family(rcParams['font.family'])
self._slant = rcParams['font.style']
self._variant = rcParams['font.variant']
Expand Down