func (s Style) Rectangle(txt string) vg.Rectangle {
	e := s.Handler.Extents(s.Font)
	w, h := s.box(txt)
	desc := vg.Length(e.Height - e.Ascent)  
	xoff := vg.Length(s.XAlign) * w
	yoff := vg.Length(s.YAlign)*h - desc
	p1 := rotatePoint(s.Rotation, vg.Point{X: xoff, Y: yoff})
	p2 := rotatePoint(s.Rotation, vg.Point{X: xoff, Y: h + yoff})
	p3 := rotatePoint(s.Rotation, vg.Point{X: w + xoff, Y: yoff})
	p4 := rotatePoint(s.Rotation, vg.Point{X: w + xoff, Y: h + yoff})
	return vg.Rectangle{
		Max: vg.Point{
			X: max(p1.X, p2.X, p3.X, p4.X),
			Y: max(p1.Y, p2.Y, p3.Y, p4.Y),
		},
		Min: vg.Point{
			X: min(p1.X, p2.X, p3.X, p4.X),
			Y: min(p1.Y, p2.Y, p3.Y, p4.Y),
		},
	}
}
Rectangle returns a rectangle giving the bounds of
this text assuming that it is drawn at (0, 0).
package text
import (
	"image/color"
	"math"
	"gonum.org/v1/plot/font"
	"gonum.org/v1/plot/vg"
)
type Handler interface {
	Cache() *font.Cache
	Extents(fnt font.Font) font.Extents
	Lines(txt string) []string
	Box(txt string, fnt font.Font) (width, height, depth vg.Length)
	Draw(c vg.Canvas, txt string, sty Style, pt vg.Point)
}
type XAlignment float64
const (
	XLeft XAlignment = 0
	XCenter XAlignment = -0.5
	XRight XAlignment = -1
)
type YAlignment float64
const (
	YTop YAlignment = -1
	YCenter YAlignment = -0.5
	YBottom YAlignment = 0
)
const (
	PosLeft   = -1
	PosBottom = -1
	PosCenter = 0
	PosTop    = +1
	PosRight  = +1
)
type Style struct {
	Color color.Color
	Font font.Font
	Rotation float64
	XAlign XAlignment
	YAlign YAlignment
	Handler Handler
}
func (s Style) FontExtents() font.Extents {
	return s.Handler.Extents(s.Font)
}
func (s Style) Width(txt string) (max vg.Length) {
	w, _ := s.box(txt)
	return w
}
func (s Style) Height(txt string) vg.Length {
	_, h := s.box(txt)
	return h
}
func (s Style) box(txt string) (w, h vg.Length) {
	var (
		lines   = s.Handler.Lines(txt)
		e       = s.FontExtents()
		linegap = (e.Height - e.Ascent - e.Descent)
	)
	for i, line := range lines {
		ww, hh, dd := s.Handler.Box(line, s.Font)
		if ww > w {
			w = ww
		}
		h += hh + dd
		if i > 0 {
			h += linegap
		}
	}
	return w, h
}