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

Skip to content

Factor out underline-thickness lookups in mathtext. #22203

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 1 commit into from
Jan 12, 2022
Merged
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
35 changes: 14 additions & 21 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,8 +1500,7 @@ class Hrule(Rule):

def __init__(self, state, thickness=None):
if thickness is None:
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
thickness = state.get_current_underline_thickness()
height = depth = thickness * 0.5
super().__init__(np.inf, height, depth, state)

Expand All @@ -1510,8 +1509,7 @@ class Vrule(Rule):
"""Convenience class to create a vertical rule."""

def __init__(self, state):
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
thickness = state.get_current_underline_thickness()
super().__init__(thickness, np.inf, np.inf, state)


Expand Down Expand Up @@ -2255,6 +2253,11 @@ def font(self, name):
self.font_class = name
self._font = name

def get_current_underline_thickness(self):
"""Return the underline thickness for this state."""
return self.font_output.get_underline_thickness(
self.font, self.fontsize, self.dpi)

def get_state(self):
"""Get the current `State` of the parser."""
return self._state_stack[-1]
Expand Down Expand Up @@ -2401,8 +2404,7 @@ def unknown_symbol(self, s, loc, toks):

def accent(self, s, loc, toks):
state = self.get_state()
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
thickness = state.get_current_underline_thickness()
(accent, sym), = toks
if accent in self._wide_accents:
accent_box = AutoWidthChar(
Expand Down Expand Up @@ -2687,8 +2689,7 @@ def subsuper(self, s, loc, toks):

def _genfrac(self, ldelim, rdelim, rule, style, num, den):
state = self.get_state()
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
thickness = state.get_current_underline_thickness()

rule = float(rule)

Expand Down Expand Up @@ -2731,17 +2732,13 @@ def genfrac(self, s, loc, toks):
return self._genfrac(*args)

def frac(self, s, loc, toks):
state = self.get_state()
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
thickness = self.get_state().get_current_underline_thickness()
(num, den), = toks
return self._genfrac('', '', thickness, self._MathStyle.TEXTSTYLE,
num, den)

def dfrac(self, s, loc, toks):
state = self.get_state()
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
thickness = self.get_state().get_current_underline_thickness()
(num, den), = toks
return self._genfrac('', '', thickness, self._MathStyle.DISPLAYSTYLE,
num, den)
Expand All @@ -2753,9 +2750,7 @@ def binom(self, s, loc, toks):

def _genset(self, s, loc, toks):
(annotation, body), = toks
state = self.get_state()
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
thickness = self.get_state().get_current_underline_thickness()

annotation.shrink()
cannotation = HCentered([annotation])
Expand Down Expand Up @@ -2787,8 +2782,7 @@ def _genset(self, s, loc, toks):
def sqrt(self, s, loc, toks):
(root, body), = toks
state = self.get_state()
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
thickness = state.get_current_underline_thickness()

# Determine the height of the body, and add a little extra to
# the height so it doesn't seem cramped
Expand Down Expand Up @@ -2828,8 +2822,7 @@ def overline(self, s, loc, toks):
(body,), = toks

state = self.get_state()
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
thickness = state.get_current_underline_thickness()

height = body.height - body.shift_amount + thickness * 3.0
depth = body.depth + body.shift_amount
Expand Down