File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ import (
55 "github.com/go-text/typesetting/harfbuzz"
66)
77
8+ // adjust the cache size of the zero value, used by default
9+ // in [HarfbuzzShaper]
10+ const defaultFontCacheSize = 32
11+
812// fontEntry holds a single key-value pair for an LRU cache.
913type fontEntry struct {
1014 next, prev *fontEntry
@@ -21,7 +25,9 @@ type fontLRU struct {
2125 // https://git.sr.ht/~eliasnaur/gio/tree/e768fe347a732056031100f2c66987d6db258ea4/item/text/lru.go
2226 m map[*font.Font]*fontEntry
2327 head, tail *fontEntry
24- maxSize int
28+
29+ // the actual cache size is [maxSizeOffset] + [defaultFontCacheSize]
30+ maxSizeOffset int
2531}
2632
2733// Get fetches the value associated with the given key, if any.
@@ -47,7 +53,7 @@ func (l *fontLRU) Put(k *font.Font, v *harfbuzz.Font) {
4753 val := &fontEntry{key: k, v: v}
4854 l.m[k] = val
4955 l.insert(val)
50- if len(l.m) > l.maxSize {
56+ if len(l.m) > (defaultFontCacheSize + l.maxSizeOffset) {
5157 oldest := l.tail.next
5258 l.remove(oldest)
5359 delete(l.m, oldest.key)
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ type HarfbuzzShaper struct {
2424// It is safe to adjust the size after using the shaper, though shrinking
2525// it may result in many evictions on the next shaping.
2626func (h *HarfbuzzShaper) SetFontCacheSize(size int) {
27- h.fonts.maxSize = size
27+ h.fonts.maxSizeOffset = size - defaultFontCacheSize
2828}
2929
3030var _ Shaper = (*HarfbuzzShaper)(nil)
You can’t perform that action at this time.
0 commit comments