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

Using a custom TextStyle #138

Open
benoitmasson opened this issue Jan 3, 2018 · 3 comments
Open

Using a custom TextStyle #138

benoitmasson opened this issue Jan 3, 2018 · 3 comments

Comments

@benoitmasson
Copy link

benoitmasson commented Jan 3, 2018

Hi, I can't find a way to customize the TextStyle in my calls to gc.FillString().

This type (and all its field, in particular Halign which I'm interested in) do not seem to be used in any of the packages.

Am I missing something, or is there another way to have gc.FillString() draw centered text?

@llgcode
Copy link
Owner

llgcode commented Jan 3, 2018

Hi @benoitmasson, it's not implemented yet.

@benoitmasson
Copy link
Author

OK, thanks for the quick response.

Meanwhile I wrote a small workaround for my specific needs, in anybody has the same issue:

func fillStringHCenteredAt(gc draw2d.GraphicContext, text string, x, y float64) float64 {
	// draw text outside of image, to compute width without printing
	w := gc.FillStringAt(text, 0, -1000)
	// draw centered text
	return gc.FillStringAt(text, x-w/2, y)
}

@llgcode
Copy link
Owner

llgcode commented Jan 4, 2018

Hi @benoitmasson
thanks for the function.
There's a method here that can help you compute the size of the string. This method is only available in draw2dimg package.
We need functions that computes metrics in draw2d base package.

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

No branches or pull requests

2 participants