public sealed class ShapingCacheShaped paragraphs, kept until something has to go.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Shaping is the expensive part of drawing text and almost all of it is repeated: a label that has not changed is reshaped every frame unless something remembers. This is that, with least-recently-used eviction so a long session cannot grow without bound.
The size is not part of the key, and that is the point. The font is held at design-unit scale and HarfBuzz's OpenType path has no hinting, so a string shapes identically at 12pt and at 48pt — the caller scales the result. A cache keyed on size would hold one entry per string per DPI scale per animation frame of a growing label, and would miss on the frame that mattered. See FontFace.
⚠ Whole paragraphs, not runs, and the reason is a consequence of a decision made two files away. A run is shaped with the text around it as context, because an Arabic letter's form depends on whether its neighbour joins — so a run's glyphs are not a function of the run alone. Keying on runs would either be unsound or need the context in the key, at which point it is a paragraph cache with extra steps. Reuse across paragraphs that share a word is given up deliberately.
Not thread-safe, and neither is a FontFace: parallel layout gets a cache and a face per worker.
Fields and properties (3)
public int CountHow many paragraphs are held.
public long HitsHow many lookups were answered from the cache.
public long MissesHow many lookups had to shape.
Methods (3)
public ShapingCache(int capacity = 512)Creates a cache.
public ShapedText Shape(FontFace font, string text, ParagraphDirection direction = Auto, FontVariation? variation = null)Shapes a paragraph, or returns the one shaped earlier.
public void Clear()Forgets everything.
Used by (5)
- FontVariationTestsVixen.Ui.Text.Tests
- ShapingCacheTestsVixen.Ui.Text.Tests
- TextTestsVixen.Ui.Tests
- UiDocumentVixen.Ui
- UiElementVixen.Ui