Skip to content
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

Add anchor parameter to DisplayText #313

Merged
merged 2 commits into from
Sep 21, 2023

Conversation

hchargois
Copy link
Contributor

The anchor parameter is required to easily (and correctly) place text on the drawn image.

See https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html

@mathoudebine
Copy link
Owner

Hi @hchargois
Thanks for the PR! Can you rebase/update your branch with the latest commits on main? I have added a new Github CI check to quickly identify visual impacts on themes rendering.
Just want to check possible impacts of your changes on existing themes

@hchargois
Copy link
Contributor Author

Rebase is done :)

@mathoudebine
Copy link
Owner

The new CI actions have run and it seems your changes impact System Monitor existing themes, as some text fields have shifted.
Here is an example about a theme named "bash-dark-green":

Original rendering / new rendering with your changes:
screenshot-bash-dark-green screenshot-bash-dark-green

Diff between the two rendering:
diff-bash-dark-green

Because of all the existing themes on this repository but also from the community, I cannot merge your changes as-is to avoid breaking current themes support.

Is it possible to update your changes so that the text fields are still displayed in their original positions by default?

@hchargois
Copy link
Contributor Author

Is it possible to run these tests locally?

@hchargois
Copy link
Contributor Author

So, what was done manually before this PR, i.e. computing the empty "margins" around the drawn text via a call to textbbox at the (0,0) position, and subtracting them to the drawn text's location, is actually just the same as simply using the "lt" (left-top) anchor.

So I just added that anchor to the drawing functions for the themes. I was able to run the github action locally and confirm that all screencaps are now exactly the same as before.

IMO, I think the library's DisplayText should still default to "la" (left-ascender). When drawing text, you usually don't want it to jump up and down depending on whether you're displaying a _, a x or a X, which have different heights. You want the baseline to stay at the same position, so you use "la" or alternatively "ls" (left-baseline). The fact that Pillow's default is "la" gives even more weight to this.

However, this does mean that people who are using DisplayText directly in their own projects will have their text moved down a bit. We could also add the "lt" anchor as default of DisplayText to avoid breaking these users. I'll let you decide if you want a small breaking change now to get a better default, or no breaking change but keep lugging around an imperfect default.

@mathoudebine
Copy link
Owner

Thanks for the changes, I agree it is best to have the anchor default to la for DisplayText. Unfortunately it is too late to apply this change for the System Monitor themes, but I will add a disclaimer for people using the function in their own code that the behavior has changed.

@mathoudebine mathoudebine merged commit a681cc9 into mathoudebine:main Sep 21, 2023
@hchargois hchargois deleted the add-text-anchor branch December 9, 2024 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants