draw2d icon indicating copy to clipboard operation
draw2d copied to clipboard

Using a custom TextStyle

Open benoitmasson opened this issue 7 years ago • 3 comments

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?

benoitmasson avatar Jan 03 '18 11:01 benoitmasson

Hi @benoitmasson, it's not implemented yet.

llgcode avatar Jan 03 '18 12:01 llgcode

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)
}

benoitmasson avatar Jan 03 '18 17:01 benoitmasson

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.

llgcode avatar Jan 04 '18 13:01 llgcode