box returns the bounding box of a possibly multi-line text.
(txt string)
| 114 | |
| 115 | // box returns the bounding box of a possibly multi-line text. |
| 116 | func (s Style) box(txt string) (w, h vg.Length) { |
| 117 | var ( |
| 118 | lines = s.Handler.Lines(txt) |
| 119 | e = s.FontExtents() |
| 120 | linegap = (e.Height - e.Ascent - e.Descent) |
| 121 | ) |
| 122 | for i, line := range lines { |
| 123 | ww, hh, dd := s.Handler.Box(line, s.Font) |
| 124 | if ww > w { |
| 125 | w = ww |
| 126 | } |
| 127 | h += hh + dd |
| 128 | if i > 0 { |
| 129 | h += linegap |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return w, h |
| 134 | } |
| 135 | |
| 136 | // Rectangle returns a rectangle giving the bounds of |
| 137 | // this text assuming that it is drawn at (0, 0). |