draw2d
draw2d copied to clipboard
[bug] GetStringBounds does not account for italics style
Hi, I'm drawing some text on an image and color its background with ClearRect()
I noticed that when italics is set, the background and the image are incorrectly offset

see the picture, the string has some space before the text starts, and a section of the 't' is drawn outside the background
for both italics and normal style, GetStringBounds reports l:3.703125, t:-29.546875, r:204.656250, b:0.468750
here is the relevant portions of my code
l, t, r, b := gc.GetStringBounds(str)
strWidth := int(math.Ceil(r)) - int(math.Ceil(l))
strHeight := int(math.Ceil(t)) - int(math.Ceil(b))
pointX := (input.Bounds().Dx() - strWidth) / 2
pointY := (input.Bounds().Dy() - strHeight) / 2
gc.SetFillColor(color.RGBA{255,255,255,255})
gc.ClearRect(pointX, pointY, pointX + strWidth, pointY + strHeight)
gc.SetFillColor(color.RGBA{0,0,0,255})
gc.FillStringAt(str, float64(pointX), float64(pointY))
We need to use the new freetype API to draw and compute string length. It may correct this issue.