freetype
freetype copied to clipboard
How to draw string in one line with different colors
I try to use the function DrawString draw it one by one and change the color , but it hard to know how much advanceWidth I should move,so I can't set the right pt . Can you give me some help?
I try to use the function DrawString draw it one by one and change the color , but it hard to know how much advanceWidth I should move,so I can't set the right pt . Can you give me some help?
hi, have you resolve this? I have the same request.
Everytime that you use DrawString
it returns a fixed.Point26_6
which has the coordinates where the next character should go, I recently did this:
for i, l := range lines {
for j, char := range l {
c.SetSrc(image.NewUniform(hsl.HSL{H: 360.0 * float64(j) / float64(len(l)), S: 1.0, L: 0.6}))
if j == 0 {
pt = freetype.Pt((j+1)*fontSizePx, (i+1)*fontSizePx)
}
pt, err = c.DrawString(string(char), pt)
if err != nil {
panic(err)
}
}
}
Which will produce something like this: