Skip to content

Question about text series api (TextLine、NewTextBox..) #19

@luankefei

Description

@luankefei

hi, I want to draw a text content at the top-left of the screen, and without spacing. like this.

image

so I do a simply transform

// c.H is canvas height
c := Canvas{canvas.New(1000, 1000)}
canvas.NewContext(c).SetView(canvas.Identity.Translate(0, 1000))

and call c.DrawText, set y * -1

c.DrawText(x, y*-1, text)

but, I have trouble in the "TextBox".

I tried to do some tests, you can see the text.Bounds() has little offsets. and here is my code

for i := 5; i > 0; i-- {
    face := fontFamily[fontKey].Face(t.Size+float64(i*30)*ptPerMm, color, t.FontStyle, canvas.FontNormal)
    text := canvas.NewTextBox(face, content, 0, 0, canvas.Left, canvas.Top, indent, lineStretch)

    rect := text.Bounds()
    if i%2 == 0 {
        c.SetFillColor(canvas.Red)
    } else {
        c.SetFillColor(canvas.Blue)
    }
    c.DrawPath(t.X, t.Y, rect.ToPath())

    c.SetFillColor(color)
    c.DrawText(t.X, t.Y, text)
}

image

sorry for bad english

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