OpenEPaperLink / Home_Assistant_Integration

Home assistant Integration for the OpenEPaperLink project
Apache License 2.0
132 stars 33 forks source link

multiline align doesnt work #128

Closed gertlind closed 3 months ago

gertlind commented 4 months ago

Describe the bug Using the the example from : https://github.com/jonasniesner/open_epaper_link_homeassistant/wiki/2.9%22-NAS-Dashboard service: open_epaper_link.drawcustom data: background: white rotate: 0 payload:

The texts does not align they start on the x value. In the example align is set to "center", documentation says "middle": None of these works.

Expected behavior Text to center on x value.

Screenshots open_epaper_link 00000283a2bb3b18

gertlind commented 3 months ago

added anchor to below section in imagegen.py. Seems to have solved the issue.

    if element["type"] == "multiline":
        d = ImageDraw.Draw(img)
        d.fontmode = "1"
        size = element.get('size', 20)
        font = element.get('font', "ppb.ttf")
        font_file = os.path.join(os.path.dirname(__file__), font)
        font = ImageFont.truetype(font_file, size)
        color = element.get('color', "black")
        anchor = element.get('anchor', "lm")
        _LOGGER.debug("Got Multiline string: %s with delimiter: %s" % (element['value'],element["delimiter"]))
        lst = element['value'].replace("\n","").split(element["delimiter"])
        pos = element.get('start_y', pos_y + element.get('y_padding', 10))
        for elem in lst:
            _LOGGER.debug("String: %s" % (elem))
            d.text((element['x'], pos ), str(elem), fill=getIndexColor(color), font=font, anchor=anchor)
            pos = pos + element['offset_y']
        pos_y = pos
gertlind commented 3 months ago

Fixed in v0.4.7.6