faster text rendering
This commit is contained in:
parent
84d2b4f3cb
commit
421d388f91
1 changed files with 8 additions and 7 deletions
15
text.go
15
text.go
|
@ -234,6 +234,9 @@ func (cv *Canvas) StrokeText(str string, x, y float64) {
|
||||||
frc.setFontSize(float64(cv.state.fontSize))
|
frc.setFontSize(float64(cv.state.fontSize))
|
||||||
fnt := cv.state.font.font
|
fnt := cv.state.font.font
|
||||||
|
|
||||||
|
prevPath := cv.path
|
||||||
|
cv.BeginPath()
|
||||||
|
|
||||||
for _, rn := range str {
|
for _, rn := range str {
|
||||||
idx := fnt.Index(rn)
|
idx := fnt.Index(rn)
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
|
@ -244,21 +247,19 @@ func (cv *Canvas) StrokeText(str string, x, y float64) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
cv.strokeRune(rn, vec{x, y})
|
cv.runePath(rn, vec{x, y})
|
||||||
|
|
||||||
x += float64(advance) / 64
|
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 := &truetype.GlyphBuf{}
|
||||||
gb.Load(cv.state.font.font, fixed.Int26_6(cv.state.fontSize*64), cv.state.font.font.Index(rn), font.HintingNone)
|
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
|
from := 0
|
||||||
for _, to := range gb.Ends {
|
for _, to := range gb.Ends {
|
||||||
ps := gb.Points[from:to]
|
ps := gb.Points[from:to]
|
||||||
|
|
Loading…
Reference in a new issue