MCPcopy Index your code
hub / github.com/g3n/engine / DrawTextOnImage

Method DrawTextOnImage

text/font.go:218–237  ·  view source on GitHub ↗

DrawTextOnImage draws the specified text on the specified image at the specified coordinates.

(text string, x, y int, dst *image.RGBA)

Source from the content-addressed store, hash-verified

216
217// DrawTextOnImage draws the specified text on the specified image at the specified coordinates.
218func (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.
240type Canvas struct {

Callers 2

DrawTextMethod · 0.95
DrawTextMethod · 0.80

Calls 5

updateFaceMethod · 0.95
MetricsMethod · 0.80
SplitMethod · 0.80
RoundMethod · 0.45
CeilMethod · 0.45

Tested by

no test coverage detected