text/v2: performance optimization by caching glyph bounds

Updates #2454
This commit is contained in:
Hajime Hoshi 2023-11-17 13:07:04 +09:00
parent 2a1eac3b73
commit 4755da6a08
2 changed files with 4 additions and 1 deletions

View File

@ -332,7 +332,7 @@ func (g *GoTextFace) glyphImage(glyph glyph, origin fixed.Point26_6) (*ebiten.Im
origin.Y = adjustGranularity(origin.Y, g)
}
b := segmentsToBounds(glyph.scaledSegments)
b := glyph.bounds
subpixelOffset := fixed.Point26_6{
X: (origin.X + b.Min.X) & ((1 << 6) - 1),
Y: (origin.Y + b.Min.Y) & ((1 << 6) - 1),

View File

@ -24,6 +24,7 @@ import (
"github.com/go-text/typesetting/language"
"github.com/go-text/typesetting/opentype/api"
"github.com/go-text/typesetting/shaping"
"golang.org/x/image/math/fixed"
)
type goTextOutputCacheKey struct {
@ -41,6 +42,7 @@ type glyph struct {
startIndex int
endIndex int
scaledSegments []api.Segment
bounds fixed.Rectangle26_6
}
type goTextOutputCacheValue struct {
@ -193,6 +195,7 @@ func (g *GoTextFaceSource) shape(text string, face *GoTextFace) (shaping.Output,
startIndex: indices[gl.ClusterIndex],
endIndex: indices[gl.ClusterIndex+gl.RuneCount],
scaledSegments: scaledSegs,
bounds: segmentsToBounds(scaledSegs),
}
}
g.outputCache[key] = &goTextOutputCacheValue{