MCPcopy Create free account
hub / github.com/cogentcore/core / Render

Method Render

paint/text.go:84–251  ·  view source on GitHub ↗

Render does text rendering into given image, within given bounds, at given absolute position offset (specifying position of text baseline) -- any applicable transforms (aside from the char-specific rotation in Render) must be applied in advance in computing the relative positions of the runes, and t

(pc *Context, pos math32.Vector2)

Source from the content-addressed store, hash-verified

82// stroking, only filling of text -- probably need to grab path from font and
83// use paint rendering for stroking.
84func (tr *Text) Render(pc *Context, pos math32.Vector2) {
85 // pr := profile.Start("RenderText")
86 // defer pr.End()
87
88 var ppaint styles.Paint
89 ppaint.CopyStyleFrom(pc.Paint)
90
91 pc.PushTransform(math32.Identity2()) // needed for SVG
92 defer pc.PopTransform()
93 pc.CurrentTransform = math32.Identity2()
94
95 TextFontRenderMu.Lock()
96 defer TextFontRenderMu.Unlock()
97
98 elipses := '…'
99 hadOverflow := false
100 rendOverflow := false
101 overBoxSet := false
102 var overStart math32.Vector2
103 var overBox math32.Box2
104 var overFace font.Face
105 var overColor image.Image
106
107 for _, sr := range tr.Spans {
108 if sr.IsValid() != nil {
109 continue
110 }
111
112 curFace := sr.Render[0].Face
113 curColor := sr.Render[0].Color
114 if g, ok := curColor.(gradient.Gradient); ok {
115 g.Update(pc.FontStyle.Opacity, math32.B2FromRect(pc.LastRenderBBox), pc.CurrentTransform)
116 } else {
117 curColor = gradient.ApplyOpacity(curColor, pc.FontStyle.Opacity)
118 }
119 tpos := pos.Add(sr.RelPos)
120
121 if !overBoxSet {
122 overWd, _ := curFace.GlyphAdvance(elipses)
123 overWd32 := math32.FromFixed(overWd)
124 overEnd := math32.Vector2FromPoint(pc.Bounds.Max)
125 overStart = overEnd.Sub(math32.Vec2(overWd32, 0.1*tr.FontHeight))
126 overBox = math32.Box2{Min: math32.Vec2(overStart.X, overEnd.Y-tr.FontHeight), Max: overEnd}
127 overFace = curFace
128 overColor = curColor
129 overBoxSet = true
130 }
131
132 d := &font.Drawer{
133 Dst: pc.Image,
134 Src: curColor,
135 Face: curFace,
136 }
137
138 // todo: cache flags if these are actually needed
139 if sr.HasDeco.HasFlag(styles.DecoBackgroundColor) {
140 // fmt.Println("rendering background color for span", rs)
141 sr.RenderBg(pc, tpos)

Callers 3

RenderTopPosMethod · 0.95
TestRenderFunction · 0.95
TestTextFunction · 0.95

Calls 15

CopyStyleFromMethod · 0.95
ContainsPointMethod · 0.95
ToFixedMethod · 0.95
Identity2Function · 0.92
B2FromRectFunction · 0.92
ApplyOpacityFunction · 0.92
FromFixedFunction · 0.92
Vector2FromPointFunction · 0.92
Vec2Function · 0.92
Scale2DFunction · 0.92
CeilFunction · 0.92
FloorFunction · 0.92

Tested by 2

TestRenderFunction · 0.76
TestTextFunction · 0.76