Rectangle returns a rectangle giving the bounds of this text assuming that it is drawn at (0, 0).
(txt string)
| 136 | // Rectangle returns a rectangle giving the bounds of |
| 137 | // this text assuming that it is drawn at (0, 0). |
| 138 | func (s Style) Rectangle(txt string) vg.Rectangle { |
| 139 | e := s.Handler.Extents(s.Font) |
| 140 | w, h := s.box(txt) |
| 141 | desc := vg.Length(e.Height - e.Ascent) // descent + linegap |
| 142 | xoff := vg.Length(s.XAlign) * w |
| 143 | yoff := vg.Length(s.YAlign)*h - desc |
| 144 | |
| 145 | // lower left corner |
| 146 | p1 := rotatePoint(s.Rotation, vg.Point{X: xoff, Y: yoff}) |
| 147 | // upper left corner |
| 148 | p2 := rotatePoint(s.Rotation, vg.Point{X: xoff, Y: h + yoff}) |
| 149 | // lower right corner |
| 150 | p3 := rotatePoint(s.Rotation, vg.Point{X: w + xoff, Y: yoff}) |
| 151 | // upper right corner |
| 152 | p4 := rotatePoint(s.Rotation, vg.Point{X: w + xoff, Y: h + yoff}) |
| 153 | |
| 154 | return vg.Rectangle{ |
| 155 | Max: vg.Point{ |
| 156 | X: max(p1.X, p2.X, p3.X, p4.X), |
| 157 | Y: max(p1.Y, p2.Y, p3.Y, p4.Y), |
| 158 | }, |
| 159 | Min: vg.Point{ |
| 160 | X: min(p1.X, p2.X, p3.X, p4.X), |
| 161 | Y: min(p1.Y, p2.Y, p3.Y, p4.Y), |
| 162 | }, |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // rotatePoint applies rotation theta (in radians) about the origin to point p. |
| 167 | func rotatePoint(theta float64, p vg.Point) vg.Point { |
nothing calls this directly
no test coverage detected