Skip to content

Commit

Permalink
faster text rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
tfriedel6 committed Mar 16, 2020
1 parent 84d2b4f commit 421d388
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]
Expand Down

0 comments on commit 421d388

Please sign in to comment.