Bounds returns the bounding rectangle that defines the text box.
()
| 1096 | |
| 1097 | // Bounds returns the bounding rectangle that defines the text box. |
| 1098 | func (t *Text) Bounds() Rect { |
| 1099 | if t.Empty() { |
| 1100 | return Rect{} |
| 1101 | } |
| 1102 | rect := Rect{math.Inf(1), math.Inf(1), math.Inf(-1), math.Inf(-1)} |
| 1103 | for _, line := range t.lines { |
| 1104 | for _, span := range line.spans { |
| 1105 | // TODO: vertical text |
| 1106 | x, y := span.X, -line.y-span.Face.Metrics().Descent |
| 1107 | rect = rect.Add(Rect{x, y, x + span.Width, y + span.Face.Metrics().Ascent + span.Face.Metrics().Descent}) |
| 1108 | } |
| 1109 | } |
| 1110 | if math.IsNaN(rect.X0) || math.IsNaN(rect.Y0) || math.IsNaN(rect.X1) || math.IsNaN(rect.Y1) { |
| 1111 | return Rect{} |
| 1112 | } |
| 1113 | |
| 1114 | return rect |
| 1115 | } |
| 1116 | |
| 1117 | // OutlineBounds returns the rectangle that contains the entire text box, i.e. the glyph outlines (slow). |
| 1118 | func (t *Text) OutlineBounds() Rect { |
no test coverage detected