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

Method AppendString

paint/span.go:169–214  ·  view source on GitHub ↗

AppendString adds string and associated formatting info, optimized with only first rune having non-nil face and color settings

(str string, face font.Face, clr image.Image, bg image.Image, deco styles.TextDecorations, sty *styles.FontRender, ctxt *units.Context)

Source from the content-addressed store, hash-verified

167// AppendString adds string and associated formatting info, optimized with
168// only first rune having non-nil face and color settings
169func (sr *Span) AppendString(str string, face font.Face, clr image.Image, bg image.Image, deco styles.TextDecorations, sty *styles.FontRender, ctxt *units.Context) {
170 if len(str) == 0 {
171 return
172 }
173 ucfont := &styles.FontRender{}
174 if runtime.GOOS == "darwin" {
175 ucfont.Family = "Arial Unicode"
176 } else {
177 ucfont.Family = "Arial"
178 }
179 ucfont.Size = sty.Size
180 ucfont.Font = OpenFont(ucfont, ctxt) // note: this is lightweight once loaded in library
181
182 TextFontRenderMu.Lock()
183 defer TextFontRenderMu.Unlock()
184
185 nwr := []rune(str)
186 sz := len(nwr)
187 sr.Text = append(sr.Text, nwr...)
188 rr := Rune{Face: face, Color: clr, Background: bg, Deco: deco}
189 r := nwr[0]
190 lastUc := false
191 if _, ok := face.GlyphAdvance(r); !ok {
192 rr.Face = ucfont.Face.Face
193 lastUc = true
194 }
195 sr.HasDecoUpdate(bg, deco)
196 sr.Render = append(sr.Render, rr)
197 for i := 1; i < sz; i++ { // optimize by setting rest to nil for same
198 rp := Rune{Deco: deco, Background: bg}
199 r := nwr[i]
200 if _, ok := face.GlyphAdvance(r); !ok {
201 if !lastUc {
202 rp.Face = ucfont.Face.Face
203 lastUc = true
204 }
205 } else {
206 if lastUc {
207 rp.Face = face
208 lastUc = false
209 }
210 }
211 // }
212 sr.Render = append(sr.Render, rp)
213 }
214}
215
216// SetRenders sets rendering parameters based on style
217func (sr *Span) SetRenders(sty *styles.FontRender, uc *units.Context, noBG bool, rot, scalex float32) {

Callers 2

SetHTMLNoPreMethod · 0.80
SetHTMLPreMethod · 0.80

Calls 4

HasDecoUpdateMethod · 0.95
OpenFontFunction · 0.85
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected