From c1f693fc5e25290b6af088848a8456134c54cf83 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 18 Feb 2022 00:03:03 +0100 Subject: [PATCH] Some more maintenance for mathtext internal implementation. Inherit the render() docstring (without even bothering with a "docstring inherited" comment, as that would be as long as the actual docstring, the API is relatively transparent, and the module is private). Inline _determine_order, which, despite what it says, was never directly used by vpack/hpack, but only in _set_glue. Removing the indirection allows a more linear reading of _set_glue (which is also not *that* long). Delete unused SubSuperCluster. --- lib/matplotlib/_mathtext.py | 47 ++++++------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 360ee75e55da..d8fce11eb997 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -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 @@ -864,7 +864,7 @@ def shrink(self): self.size += 1 def render(self, x, y): - pass + """Render this node.""" class Box(Node): @@ -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() @@ -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) @@ -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] @@ -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: @@ -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.