Skip to content

When I have multiple lines of text, how should the line height be calculated? #205

@jmu201621143028

Description

@jmu201621143028

Thank you for your great work.
i have a question. When I have multiple lines of text, how should the line height be calculated?

This is how I calculate it now. ref

line_height = extents.ascender - extents.descender + extents.line_gap
cursor_x, cursor_y = -300, 0
texts = 'i love you\n我爱你\n愛してます'

"""
some code
"""

for pos, c in zip(positions, texts):
    if c == "\n":
        cursor_x = -300
        cursor_y += line_height * scale
        continue
    outline = get_glyph_outline(font_path, c)
    draw_outline_with_turtle(outline, scale=scale,
                             offset=(cursor_x + pos.x_offset * scale, cursor_y + pos.y_offset * scale))
    cursor_x += pos.x_advance * scale
    cursor_y += pos.y_advance * scale

Is there any better way to calculate line_height

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions