From d5b253e532cfa348ee52e041a0eda7533b5f0849 Mon Sep 17 00:00:00 2001 From: Ratnabali Dutta Date: Fri, 28 Jul 2023 13:18:05 +0530 Subject: [PATCH 1/2] Update raster w, h, d calculation --- lib/matplotlib/_mathtext.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 25a825b7b0d9..3dcf44ff1b52 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -117,9 +117,8 @@ def to_raster(self, antialiased=None): *[x2 for x1, y1, x2, y2 in self.rects], 0]) + 1 ymax = max([*[oy - info.metrics.ymin for ox, oy, info in self.glyphs], *[y2 for x1, y1, x2, y2 in self.rects], 0]) + 1 - w = xmax - xmin - h = ymax - ymin - self.box.depth - d = ymax - ymin - self.box.height + w, h, d = map( + np.ceil, [self.box.width, self.box.height, self.box.depth]) image = FT2Image(np.ceil(w), np.ceil(h + max(d, 0))) # Ideally, we could just use self.glyphs and self.rects here, shifting From 3052cfa48143931120c11b0cd091b3b8f5af28df Mon Sep 17 00:00:00 2001 From: Ratnabali Dutta Date: Mon, 31 Jul 2023 12:46:49 +0530 Subject: [PATCH 2/2] Update the Vector Parse without rounding off --- lib/matplotlib/_mathtext.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 3dcf44ff1b52..56522d857d4a 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -98,8 +98,9 @@ def __init__(self, box): self.rects = [] # (x1, y1, x2, y2) def to_vector(self): - w, h, d = map( - np.ceil, [self.box.width, self.box.height, self.box.depth]) + w = self.box.width + h = self.box.height + d = self.box.depth gs = [(info.font, info.fontsize, info.num, ox, h - oy + info.offset) for ox, oy, info in self.glyphs] rs = [(x1, h - y2, x2 - x1, y2 - y1) @@ -116,10 +117,12 @@ def to_raster(self, antialiased=None): xmax = max([*[ox + info.metrics.xmax for ox, oy, info in self.glyphs], *[x2 for x1, y1, x2, y2 in self.rects], 0]) + 1 ymax = max([*[oy - info.metrics.ymin for ox, oy, info in self.glyphs], - *[y2 for x1, y1, x2, y2 in self.rects], 0]) + 1 - w, h, d = map( - np.ceil, [self.box.width, self.box.height, self.box.depth]) - image = FT2Image(np.ceil(w), np.ceil(h + max(d, 0))) + *[y2 for x1, y1, x2, y2 in self.rects], 0]) + 1.5 + + w = self.box.width + h = ymax - ymin - self.box.depth + d = ymax - ymin - self.box.height + image = FT2Image(w, h + max(d, 0)) # Ideally, we could just use self.glyphs and self.rects here, shifting # their coordinates by (-xmin, -ymin), but this yields slightly @@ -2448,7 +2451,6 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den): cnum.hpack(width, 'exactly') cden.hpack(width, 'exactly') vlist = Vlist([cnum, # numerator - Vbox(0, thickness * 2.0), # space Hrule(state, rule), # rule Vbox(0, thickness * 2.0), # space cden # denominator @@ -2461,7 +2463,7 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den): '=', state.fontsize, state.dpi) shift = (cden.height - ((metrics.ymax + metrics.ymin) / 2 - - thickness * 3.0)) + thickness * 1.5)) vlist.shift_amount = shift result = [Hlist([vlist, Hbox(thickness * 2.)])]