@@ -59,17 +59,11 @@ public sealed class DrawingCanvas<TPixel> : DrawingCanvas
5959 /// </summary>
6060 private readonly Stack < DrawingCanvasState > savedStates = new ( ) ;
6161
62- // Per-canvas glyph-outline cache: when enabled, hoists RichTextGlyphRenderer's per-glyph
63- // outline cache from per-DrawText-call scope up to the whole canvas, so a glyph outline
64- // built once is reused by every DrawText call on this canvas (across a frame's many text
65- // runs) instead of being rebuilt for every run on a text-heavy page. Lazily created and only
66- // used when sharing is opted in via Configuration.SetSharedGlyphCache; see shareGlyphCache.
67- private Dictionary < RichTextGlyphRenderer . CacheKey , List < RichTextGlyphRenderer . GlyphRenderData > > ? sharedGlyphCacheStore ;
68-
69- // Whether this canvas shares its glyph-outline cache across DrawText calls. Resolved once at
70- // construction from the configuration (Configuration.SetSharedGlyphCache); defaults to false,
71- // in which case each DrawText uses RichTextGlyphRenderer's private per-call cache.
72- private readonly bool shareGlyphCache ;
62+ // Per-canvas glyph-outline cache: hoists RichTextGlyphRenderer's per-glyph outline cache from
63+ // per-DrawText-call scope up to the whole canvas, so a glyph outline built once is reused by
64+ // every DrawText call on this canvas (across a frame's many text runs) instead of being
65+ // rebuilt for every run on a text-heavy page. Lazily created on first text draw.
66+ private Dictionary < RichTextGlyphRenderer . CacheKey , List < RichTextGlyphRenderer . GlyphRenderData > > ? glyphCache ;
7367
7468 /// <summary>
7569 /// Initializes a new instance of the <see cref="DrawingCanvas{TPixel}"/> class.
@@ -161,7 +155,6 @@ private DrawingCanvas(
161155 this . targetFrame = targetFrame ;
162156 this . batcher = batcher ;
163157 this . ownsBatcher = ownsBatcher ;
164- this . shareGlyphCache = configuration . GetSharedGlyphCache ( ) ;
165158
166159 // Canvas coordinates are local to the current frame; origin stays at (0,0).
167160 this . Bounds = new Rectangle ( 0 , 0 , targetFrame . Bounds . Width , targetFrame . Bounds . Height ) ;
@@ -450,10 +443,9 @@ public override void DrawText(
450443 this . DrawTextCore ( textOptions , text , path , brush , pen ) ;
451444 }
452445
453- // Returns the per-canvas shared glyph-outline cache (lazily created) when sharing is enabled,
454- // or null so the renderer falls back to its private per-call cache (the historical default).
455- private Dictionary < RichTextGlyphRenderer . CacheKey , List < RichTextGlyphRenderer . GlyphRenderData > > ? ResolveGlyphCache ( )
456- => this . shareGlyphCache ? this . sharedGlyphCacheStore ??= [ ] : null ;
446+ // Returns the per-canvas glyph-outline cache, lazily creating it on first use.
447+ private Dictionary < RichTextGlyphRenderer . CacheKey , List < RichTextGlyphRenderer . GlyphRenderData > > ResolveGlyphCache ( )
448+ => this . glyphCache ??= [ ] ;
457449
458450 private void DrawTextCore (
459451 RichTextOptions textOptions ,
@@ -1162,8 +1154,8 @@ public override void Dispose()
11621154 this . DisposePendingImageResources ( ) ;
11631155 }
11641156
1165- // Release the per-canvas shared glyph-outline cache.
1166- this . sharedGlyphCacheStore = null ;
1157+ // Release the per-canvas glyph-outline cache.
1158+ this . glyphCache = null ;
11671159
11681160 this . isDisposed = true ;
11691161 }
0 commit comments