Skip to content

Some more maintenance for mathtext internal implementation. #22488

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
Feb 18, 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
47 changes: 7 additions & 40 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ def __init__(self):
self.size = 0

def __repr__(self):
return self.__class__.__name__
return type(self).__name__

def get_kerning(self, next):
return 0.0
Expand All @@ -864,7 +864,7 @@ def shrink(self):
self.size += 1

def render(self, x, y):
pass
"""Render this node."""


class Box(Node):
Expand Down Expand Up @@ -961,12 +961,8 @@ def get_kerning(self, next):
return advance + kern

def render(self, x, y):
"""
Render the character to the canvas
"""
self.font_output.render_glyph(
x, y,
self.font, self.font_class, self.c, self.fontsize, self.dpi)
x, y, self.font, self.font_class, self.c, self.fontsize, self.dpi)

def shrink(self):
super().shrink()
Expand Down Expand Up @@ -995,9 +991,6 @@ def shrink(self):
self._update_metrics()

def render(self, x, y):
"""
Render the character to the canvas.
"""
self.font_output.render_glyph(
x - self._metrics.xmin, y + self._metrics.ymin,
self.font, self.font_class, self.c, self.fontsize, self.dpi)
Expand All @@ -1022,21 +1015,10 @@ def __repr__(self):
self.depth, self.shift_amount,
', '.join([repr(x) for x in self.children]))

@staticmethod
def _determine_order(totals):
"""
Determine the highest order of glue used by the members of this list.

Helper function used by vpack and hpack.
"""
for i in range(len(totals))[::-1]:
if totals[i] != 0:
return i
return 0

def _set_glue(self, x, sign, totals, error_type):
o = self._determine_order(totals)
self.glue_order = o
self.glue_order = o = next(
# Highest order of glue used by the members of this list.
(i for i in range(len(totals))[::-1] if totals[i] != 0), 0)
self.glue_sign = sign
if totals[o] != 0.:
self.glue_set = x / totals[o]
Expand All @@ -1046,7 +1028,7 @@ def _set_glue(self, x, sign, totals, error_type):
if o == 0:
if len(self.children):
_log.warning("%s %s: %r",
error_type, self.__class__.__name__, self)
error_type, type(self).__name__, self)

def shrink(self):
for child in self.children:
Expand Down Expand Up @@ -1372,21 +1354,6 @@ def shrink(self):
self.width *= SHRINK_FACTOR


class SubSuperCluster(Hlist):
"""
A hack to get around that fact that this code does a two-pass parse like
TeX. This lets us store enough information in the hlist itself, namely the
nucleus, sub- and super-script, such that if another script follows that
needs to be attached, it can be reconfigured on the fly.
"""

def __init__(self):
self.nucleus = None
self.sub = None
self.super = None
super().__init__([])


class AutoHeightChar(Hlist):
"""
A character as close to the given height and depth as possible.
Expand Down