From 421d388f9178e4ca9d12f037ea1f9789cd9b3496 Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Mon, 16 Mar 2020 18:29:05 +0100 Subject: [PATCH] faster text rendering --- text.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/text.go b/text.go index cf6f69b..3782a76 100644 --- a/text.go +++ b/text.go @@ -234,6 +234,9 @@ func (cv *Canvas) StrokeText(str string, x, y float64) { frc.setFontSize(float64(cv.state.fontSize)) fnt := cv.state.font.font + prevPath := cv.path + cv.BeginPath() + for _, rn := range str { idx := fnt.Index(rn) if idx == 0 { @@ -244,21 +247,19 @@ func (cv *Canvas) StrokeText(str string, x, y float64) { continue } - cv.strokeRune(rn, vec{x, y}) + cv.runePath(rn, vec{x, y}) x += float64(advance) / 64 } + + cv.Stroke() + cv.path = prevPath } -func (cv *Canvas) strokeRune(rn rune, pos vec) { +func (cv *Canvas) runePath(rn rune, pos vec) { gb := &truetype.GlyphBuf{} gb.Load(cv.state.font.font, fixed.Int26_6(cv.state.fontSize*64), cv.state.font.font.Index(rn), font.HintingNone) - prevPath := cv.path - defer func() { - cv.path = prevPath - }() - from := 0 for _, to := range gb.Ends { ps := gb.Points[from:to]