mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
text/v2: performance optimization by caching glyph bounds
Updates #2454
This commit is contained in:
parent
2a1eac3b73
commit
4755da6a08
@ -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),
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user