From 159c19a671b603f58806f1e3c7688a9cf49e1ea6 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 11 Dec 2023 17:39:27 +0900 Subject: [PATCH] text: cache metrics --- text/cache.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/text/cache.go b/text/cache.go index fd2caa088..713562e23 100644 --- a/text/cache.go +++ b/text/cache.go @@ -38,7 +38,8 @@ type kernCacheKey struct { } type faceWithCache struct { - f font.Face + f font.Face + metrics font.Metrics glyphBoundsCache map[rune]glyphBoundsCacheValue glyphAdvanceCache map[rune]glyphAdvanceCacheValue @@ -126,5 +127,9 @@ func (f *faceWithCache) Kern(r0, r1 rune) fixed.Int26_6 { } 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 }