MCPcopy Create free account
hub / github.com/FloatTech/ZeroBot-Plugin-Playground / truncate

Function truncate

plugin/draw/draw.go:415–429  ·  view source on GitHub ↗

截断文字

(one *gg.Context, text string, maxW float64)

Source from the content-addressed store, hash-verified

413
414// 截断文字
415func truncate(one *gg.Context, text string, maxW float64) (string, float64) {
416 var tmp strings.Builder
417 tmp.Grow(len(text))
418 res, w := make([]rune, 0, len(text)), 0.0
419 for _, r := range text {
420 tmp.WriteRune(r)
421 width, _ := one.MeasureString(tmp.String()) // 获取文字宽度
422 if width > maxW { // 如果宽度大于文字边距
423 break // 跳出
424 }
425 w = width
426 res = append(res, r) // 写入
427 }
428 return string(res), w
429}
430
431// 编码看板娘图片和加载字体
432func (mp *mpic) loadpic() error {

Callers 1

createPic2Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected