Skip to content

Having some trouble with vertical alignment #17

@EnricoMonese

Description

@EnricoMonese

I'm trying to have some text with two lines, aligned to the bottom of some bounds, and with a small line-height so that the two lines are closer together. However the text is not going where I would expect. It looks like it's going too downwards. When aligned to bottom it even goes outside the bounds. If I leave the line-height to default it also doesn't look right.
Am I missing something?

Here's an example and it's output:

import pixie

image = pixie.Image(800, 800)
image.fill(pixie.Color(1, 1, 1, 1))

paint = pixie.Paint(pixie.PK_SOLID)
paint.color = pixie.Color(1, 0, 0, 1)
ctx = image.new_context()
ctx.line_width = 1
ctx.stroke_style = paint
ctx.stroke_rect(0, 266, 800, 318)

text = "AbCd\naBcD"

font = pixie.read_font("./Inter-Bold.otf")
font.size = 182
font.line_height = 140

font.paint.color = pixie.Color(1, 0, 0, 1)
image.fill_text(
    font,
    text,
    bounds = pixie.Vector2(800, 318),
    h_align = pixie.HA_CENTER,
    v_align = pixie.VA_TOP,
    transform = pixie.translate(0, 266)
)

font.paint.color = pixie.Color(0, 1, 0, 1)
image.fill_text(
    font,
    text,
    bounds = pixie.Vector2(800, 318),
    h_align = pixie.HA_CENTER,
    v_align = pixie.VA_MIDDLE,
    transform = pixie.translate(0, 266)
)

font.paint.color = pixie.Color(0, 0, 1, 1)
image.fill_text(
    font,
    text,
    bounds = pixie.Vector2(800, 318),
    h_align = pixie.HA_CENTER,
    v_align = pixie.VA_BOTTOM,
    transform = pixie.translate(0, 266)
)

image.write_file("out.png")

result

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions