text: cache metrics

This commit is contained in:
Hajime Hoshi 2023-12-11 17:39:27 +09:00
parent 5a8cfb2561
commit 159c19a671

View File

@ -39,6 +39,7 @@ type kernCacheKey struct {
type faceWithCache struct { type faceWithCache struct {
f font.Face f font.Face
metrics font.Metrics
glyphBoundsCache map[rune]glyphBoundsCacheValue glyphBoundsCache map[rune]glyphBoundsCacheValue
glyphAdvanceCache map[rune]glyphAdvanceCacheValue glyphAdvanceCache map[rune]glyphAdvanceCacheValue
@ -126,5 +127,9 @@ func (f *faceWithCache) Kern(r0, r1 rune) fixed.Int26_6 {
} }
func (f *faceWithCache) Metrics() font.Metrics { func (f *faceWithCache) Metrics() font.Metrics {
return f.f.Metrics() if f.metrics != (font.Metrics{}) {
return f.metrics
}
f.metrics = f.f.Metrics()
return f.metrics
} }