OpenEPaperLink / Home_Assistant_Integration

Home assistant Integration for the OpenEPaperLink project
https://openepaperlink.de
Apache License 2.0
159 stars 35 forks source link

Do not remove anchor when drawing multiline text #180

Closed jhbruhn closed 1 month ago

jhbruhn commented 1 month ago

I am not sure why this was done in the first place, maybe because support for it was only added in Pillow v8? This way, multiline text can properly be drawn if for example the text is fully centered.

jterrace commented 1 month ago

After this change, I'm getting:

"HomeAssistantError: anchor not supported for multiline text"

with a payload of:

type: "text",
value: "....",
font: "rbm.ttf",
x: 0,
y_padding: 5,
size: 20,
color: "black",
max_width: 296

which was previously working?

jterrace commented 1 month ago

Looks like it's because the default anchor is lt: https://github.com/OpenEPaperLink/Home_Assistant_Integration/blob/main/custom_components/open_epaper_link/imagegen.py#L220

and t is only supported for single line text: https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html#vertical-anchor-alignment

I fixed it by explicitly setting anchor to la instead of defaulting to la. I think the default anchor should probably be switched to la instead of lt, since a is the same as t for single line text but will also work for multiline text.

jterrace commented 1 month ago

Sent out https://github.com/OpenEPaperLink/Home_Assistant_Integration/pull/181

jhbruhn commented 1 month ago

Oops, nice catch :)