MCPcopy Index your code
hub / github.com/gonum/plot / Box

Method Box

text/latex.go:56–85  ·  view source on GitHub ↗

Box returns the bounding box of the given non-multiline text where: - width is the horizontal space from the origin. - height is the vertical space above the baseline. - depth is the vertical space below the baseline, a positive number.

(txt string, fnt font.Font)

Source from the content-addressed store, hash-verified

54// - height is the vertical space above the baseline.
55// - depth is the vertical space below the baseline, a positive number.
56func (hdlr Latex) Box(txt string, fnt font.Font) (width, height, depth vg.Length) {
57 cnv := drawtex.New()
58 face := hdlr.Fonts.Lookup(fnt, fnt.Size)
59 fnts := hdlr.fontsFor(fnt)
60 box, err := mtex.Parse(txt, face.Font.Size.Points(), latexDPI, ttf.NewFrom(cnv, fnts))
61 if err != nil {
62 panic(fmt.Errorf("could not parse math expression: %w", err))
63 }
64
65 var sh tex.Ship
66 sh.Call(0, 0, box.(tex.Tree))
67
68 width = vg.Length(box.Width())
69 height = vg.Length(box.Height())
70 depth = vg.Length(box.Depth())
71
72 // Add a bit of space, with a linegap as mtex.Box is returning
73 // a very tight bounding box.
74 // See gonum/plot#661.
75 if depth != 0 {
76 var (
77 e = face.Extents()
78 linegap = e.Height - (e.Ascent + e.Descent)
79 )
80 depth += linegap
81 }
82
83 dpi := vg.Length(hdlr.dpi() / latexDPI)
84 return width * dpi, height * dpi, depth * dpi
85}
86
87// Draw renders the given text with the provided style and position
88// on the canvas.

Callers

nothing calls this directly

Calls 8

fontsForMethod · 0.95
dpiMethod · 0.95
LookupMethod · 0.80
PointsMethod · 0.80
HeightMethod · 0.80
CallMethod · 0.65
ExtentsMethod · 0.65
WidthMethod · 0.45

Tested by

no test coverage detected