Skip to content

API: convert string fontsize to points immediately #7007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
MNT: ensure that defaults are cached init
This appears to already be the case for all of these properties, but
remove the rcparams lookup from the get_* methods just to be sure.
  • Loading branch information
tacaswell committed Dec 12, 2016
commit bb37ab6fd1e2cbb9049feb2e66225701c36ba68e
33 changes: 6 additions & 27 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,11 @@ def __init__(self,
_init = None # used only by copy()
):
self._family = None
Copy link
Member

Choose a reason for hiding this comment

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

Have you forgotten to change this?

self._slant = None
self._variant = None
self._weight = None
self._stretch = None
self._size = None
self._slant = rcParams['font.style']
self._variant = rcParams['font.variant']
self._weight = rcParams['font.weight']
self._stretch = rcParams['font.stretch']
self._size = rcParams['font.size']
self._file = None

# This is used only by copy()
Expand Down Expand Up @@ -740,11 +740,6 @@ def get_family(self):
"""
Return a list of font names that comprise the font family.
"""
if self._family is None:
family = rcParams['font.family']
if is_string_like(family):
return [family]
return family
return self._family

def get_name(self):
Expand All @@ -759,8 +754,6 @@ def get_style(self):
Return the font style. Values are: 'normal', 'italic' or
'oblique'.
"""
if self._slant is None:
return rcParams['font.style']
return self._slant
get_slant = get_style

Expand All @@ -769,8 +762,6 @@ def get_variant(self):
Return the font variant. Values are: 'normal' or
'small-caps'.
"""
if self._variant is None:
return rcParams['font.variant']
return self._variant

def get_weight(self):
Expand All @@ -780,8 +771,6 @@ def get_weight(self):
'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold',
'heavy', 'extra bold', 'black'
"""
if self._weight is None:
return rcParams['font.weight']
return self._weight

def get_stretch(self):
Expand All @@ -790,26 +779,16 @@ def get_stretch(self):
'extra-condensed', 'condensed', 'semi-condensed', 'normal',
'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'.
"""
if self._stretch is None:
return rcParams['font.stretch']
return self._stretch

def get_size(self):
"""
Return the font size.
"""
if self._size is None:
return rcParams['font.size']
return self._size

def get_size_in_points(self):
if self._size is not None:
try:
return float(self._size)
except ValueError:
pass
default_size = FontManager.get_default_size()
return default_size * font_scalings.get(self._size)
return self._size

def get_file(self):
"""
Expand Down
10 changes: 6 additions & 4 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def _get_layout(self, renderer):

baseline = 0
for i, line in enumerate(lines):
clean_line, ismath = self.is_math_text(line)
clean_line, ismath = self.is_math_text(line, self.get_usetex())
if clean_line:
w, h, d = renderer.get_text_width_height_descent(clean_line,
self._fontproperties,
Expand Down Expand Up @@ -782,7 +782,7 @@ def draw(self, renderer):
y = y + posy
if renderer.flipy():
y = canvash - y
clean_line, ismath = textobj.is_math_text(line)
clean_line, ismath = textobj.is_math_text(line, self.get_usetex())
Copy link
Member

Choose a reason for hiding this comment

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

matplotlib/text.py:785:80: E501 line too long (82 > 79 characters)


if textobj.get_path_effects():
from matplotlib.patheffects import PathEffectRenderer
Expand Down Expand Up @@ -1212,7 +1212,7 @@ def set_text(self, s):
self.stale = True

@staticmethod
def is_math_text(s):
def is_math_text(s, usetex=None):
"""
Returns a cleaned string and a boolean flag.
The flag indicates if the given string *s* contains any mathtext,
Expand All @@ -1222,7 +1222,9 @@ def is_math_text(s):
"""
# Did we find an even number of non-escaped dollar signs?
# If so, treat is as math text.
if self.get_usetex():
if usetex is None:
usetex = rcParams['text.usetex']
if usetex:
if s == ' ':
s = r'\ '
return s, 'TeX'
Expand Down