draw2d
draw2d copied to clipboard
Using a custom TextStyle
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?
Hi @benoitmasson, it's not implemented yet.
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)
}
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.