DrawTextOnImage draws the specified text on the specified image at the specified coordinates.
(text string, x, y int, dst *image.RGBA)
| 216 | |
| 217 | // DrawTextOnImage draws the specified text on the specified image at the specified coordinates. |
| 218 | func (f *Font) DrawTextOnImage(text string, x, y int, dst *image.RGBA) { |
| 219 | |
| 220 | f.updateFace() |
| 221 | d := &font.Drawer{Dst: dst, Src: f.fg, Face: f.face} |
| 222 | |
| 223 | // Draw text |
| 224 | metrics := f.face.Metrics() |
| 225 | py := y + metrics.Ascent.Round() |
| 226 | lineHeight := (metrics.Ascent + metrics.Descent).Ceil() |
| 227 | lineGap := int((f.attrib.LineSpacing - float64(1)) * float64(lineHeight)) |
| 228 | lines := strings.Split(text, "\n") |
| 229 | for i, s := range lines { |
| 230 | d.Dot = fixed.P(x, py) |
| 231 | d.DrawString(s) |
| 232 | py += lineHeight |
| 233 | if i > 1 { |
| 234 | py += lineGap |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | // Canvas is an image to draw on. |
| 240 | type Canvas struct { |