diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs index 8bd52d41a38..afb91e07e95 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs @@ -15,6 +15,7 @@ using System.Collections; using System.ComponentModel; +using System.Runtime.CompilerServices; using System.Windows.Media.Converters; using System.Windows.Media.Composition; using System.Windows.Media.TextFormatting; @@ -1226,9 +1227,9 @@ public Rect ComputeInkBoundingBox() if ((_flags & GlyphRunFlags.CacheInkBounds) != 0) { - if (_inkBoundingBox != null) + if (_inkBoundingBox is not null) { - return (Rect)_inkBoundingBox; + return _inkBoundingBox.Value; } } @@ -1401,7 +1402,7 @@ public Rect ComputeInkBoundingBox() if ((_flags & GlyphRunFlags.CacheInkBounds) != 0) { - _inkBoundingBox = bounds; + _inkBoundingBox = new StrongBox(bounds); } return bounds; @@ -2463,7 +2464,7 @@ private enum GlyphRunFlags : byte private IList _caretStops; private XmlLanguage _language; private string _deviceFontName; - private object _inkBoundingBox; // Used when CacheInkBounds is on + private StrongBox _inkBoundingBox; // Used when CacheInkBounds is on private TextFormattingMode _textFormattingMode; private float _pixelsPerDip = MS.Internal.FontCache.Util.PixelsPerDip;