Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Fix positioning of mathtext glyphs#15339
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
anntzer wants to merge1 commit intomatplotlib:mainChoose a base branch fromanntzer:mathtext-glyphs
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
107 changes: 53 additions & 54 deletionslib/matplotlib/mathtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -101,70 +101,69 @@ class MathtextBackendAgg(MathtextBackend): | ||
Render glyphs and rectangles to an FTImage buffer, which is later | ||
transferred to the Agg image by the Agg backend. | ||
""" | ||
def __init__(self): | ||
MathtextBackend.__init__(self) | ||
self._xmin = self._ymin = np.inf | ||
self._xmax = self._ymax = -np.inf | ||
self._glyphs = [] | ||
self._rects = [] | ||
ox = cbook.deprecated("3.4")(property(lambda self: 0)) | ||
oy = cbook.deprecated("3.4")(property(lambda self: 0)) | ||
mode = cbook.deprecated("3.4")(property(lambda self: "bbox")) | ||
image = cbook.deprecated("3.4")(property(lambda self: None)) | ||
bbox = cbook.deprecated("3.4")(property( | ||
lambda self: [self._xmin, self._ymin, self._xmax, self._ymax])) | ||
def render_glyph(self, ox, oy, info): | ||
self._glyphs.append((ox, oy, info)) | ||
metrics = info.metrics | ||
self._xmin = min(self._xmin, ox + metrics.xmin) | ||
self._ymin = min(self._ymin, self.height - oy + metrics.ymin) | ||
self._xmax = max(self._xmax, ox + metrics.xmax) | ||
self._ymax = max(self._ymax, self.height - oy + metrics.ymax) | ||
def render_rect_filled(self, x1, y1, x2, y2): | ||
self._rects.append((x1, y1, x2, y2)) | ||
self._xmin = min(self._xmin, x1) | ||
self._xmax = max(self._xmax, x2) | ||
self._ymin = min(self._ymin, y1) | ||
self._ymax = max(self._ymax, y2) | ||
def get_results(self, box, used_characters): | ||
orig_height = box.height | ||
orig_depth = box.depth | ||
_mathtext.ship(0, 0, box) | ||
xmin = np.floor(self._xmin) | ||
xmax = np.ceil(self._xmax) | ||
ymin = np.floor(self._ymin) | ||
ymax = np.ceil(self._ymax) | ||
dxmin = self._xmin - xmin | ||
dymin = self._ymin - ymin | ||
image = FT2Image(np.ceil(xmax - xmin) + 1, np.ceil(ymax - ymin) + 1) | ||
for ox, oy, info in self._glyphs: | ||
info.font.draw_glyph_to_bitmap( | ||
image, ox + dxmin, oy - info.metrics.iceberg + dymin, | ||
info.glyph, antialiased=rcParams['text.antialiased']) | ||
for x1, y1, x2, y2 in self._rects: | ||
x1 += dxmin | ||
x2 += dymin | ||
y1 += dxmin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is this correct? | ||
y2 += dymin | ||
height = max(int(y2 - y1) - 1, 0) | ||
if height == 0: | ||
center = (y2 + y1) / 2 | ||
y = int(center - (height + 1) / 2) | ||
else: | ||
y = int(y1) | ||
image.draw_rect_filled(int(x1), y, np.ceil(x2), y + height) | ||
return (0, 0, | ||
np.ceil(xmax - xmin), np.ceil(ymax - ymin), -ymin, | ||
image, | ||
used_characters) | ||
def get_hinting_type(self): | ||
from matplotlib.backends import backend_agg | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.