Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
I changed the offset code for draw_text for RendererAgg fixing issue #13044#20057
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -24,7 +24,7 @@ | ||
except ImportError: | ||
import dummy_threading as threading | ||
from contextlib import nullcontext | ||
from math import radians, cos, sin, sqrt | ||
import numpy as np | ||
from PIL import Image | ||
@@ -208,10 +208,13 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): | ||
xo, yo = font.get_bitmap_offset() | ||
xo /= 64.0 | ||
yo /= 64.0 | ||
h = sqrt(xo**2 + yo**2) | ||
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. Personally, I prefer using 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. I don't know if it will matter, but we could still change it. | ||
xd = d * sin(radians(angle)) | ||
yd = d * cos(radians(angle)) | ||
xo = h * cos(radians(angle)) | ||
yo = h * sin(radians(angle)) | ||
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. If we are going to calculate 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. Also, these four lines here would greatly benefit from a comment explaining the trigonometry. Usually, cos() goes with x, and y goes with sin(). Seeing it two different ways here for the offset and the descent is confusing. 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. I can explain the offset trigonometry, but I just left the code for the descent as it was before. The descent seems wrong - but I am unaware of the reason why it was like that before so I left it there. Basic trigonometry suggests that x components should be calculated by multiplying a number by the cosine of its angle and y components should be calculated by multiplying a number by the sine of its angle - so that is why I used that for the offset but I do think the descent should be in the same form too. | ||
x = round(x + xo + xd) | ||
y = round(y + yo- yd) | ||
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. much like the trig above, I think this will also need a quick proof in the comments. 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. I don't think I have a proof for this at the moment except that in the draw_mathtext function the y is calculated in a similar manner and by subtracting the y offset we get a satisfactory result. | ||
self._renderer.draw_text_image(font, x, y + 1, angle, gc) | ||
def get_text_width_height_descent(self, s, prop, ismath): | ||