Exemplo n.º 1
0
func drawText(font *truetype.Font, c *freetype.Context, color color.Color, rgba *image.RGBA, text string) (int, int) {
	fg := image.NewUniform(color)
	bg := image.Transparent
	draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src)
	c.SetFont(font)
	c.SetDst(rgba)
	c.SetSrc(fg)
	c.SetClip(rgba.Bounds())
	// height is the fraction of the font that is above the line, 1.0 would mean
	// that the font never falls below the line
	// TODO: wtf - this is all wrong!
	// fix fonts - we can't change the font size easily
	height := 1.3
	pt := freetype.Pt(0, int(float64(c.PointToFix32(*size)>>8)*height))
	adv, _ := c.DrawString(text, pt)
	pt.X += adv.X
	py := int(float64(pt.Y>>8)/height + 0.01)
	return int(pt.X >> 8), py
}
Exemplo n.º 2
0
func NextLine(c *freetype.Context, pt raster.Point) raster.Point {
	return raster.Point{inset, pt.Y - c.PointToFix32(size*1.5)}
}