MCPcopy
hub / github.com/tdewolff/canvas / Bounds

Method Bounds

text.go:1098–1115  ·  view source on GitHub ↗

Bounds returns the bounding rectangle that defines the text box.

()

Source from the content-addressed store, hash-verified

1096
1097// Bounds returns the bounding rectangle that defines the text box.
1098func (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).
1118func (t *Text) OutlineBounds() Rect {

Callers 2

WritePathMethod · 0.45
WriteImageMethod · 0.45

Calls 3

EmptyMethod · 0.95
AddMethod · 0.95
MetricsMethod · 0.80

Tested by

no test coverage detected