Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to draw string in one line with different colors #84

Open
RINNE-TAN opened this issue Jun 15, 2021 · 2 comments
Open

How to draw string in one line with different colors #84

RINNE-TAN opened this issue Jun 15, 2021 · 2 comments

Comments

@RINNE-TAN
Copy link

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?

@andresperezl
Copy link

andresperezl commented Jan 14, 2022

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:

out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@andresperezl @RINNE-TAN and others