|
|
@ -1,17 +1,20 @@ |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Buffers; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using Avalonia.Utilities; |
|
|
using Avalonia.Utilities; |
|
|
|
|
|
|
|
|
namespace Avalonia.Media.TextFormatting |
|
|
namespace Avalonia.Media.TextFormatting |
|
|
{ |
|
|
{ |
|
|
public sealed class ShapedBuffer : IList<GlyphInfo> |
|
|
public sealed class ShapedBuffer : IList<GlyphInfo>, IDisposable |
|
|
{ |
|
|
{ |
|
|
private static readonly IComparer<GlyphInfo> s_clusterComparer = new CompareClusters(); |
|
|
private static readonly IComparer<GlyphInfo> s_clusterComparer = new CompareClusters(); |
|
|
|
|
|
private bool _rented; |
|
|
|
|
|
|
|
|
public ShapedBuffer(CharacterBufferRange characterBufferRange, int bufferLength, IGlyphTypeface glyphTypeface, double fontRenderingEmSize, sbyte bidiLevel) : |
|
|
public ShapedBuffer(CharacterBufferRange characterBufferRange, int bufferLength, IGlyphTypeface glyphTypeface, double fontRenderingEmSize, sbyte bidiLevel) : |
|
|
this(characterBufferRange, new GlyphInfo[bufferLength], glyphTypeface, fontRenderingEmSize, bidiLevel) |
|
|
this(characterBufferRange, ArrayPool<GlyphInfo>.Shared.Rent(bufferLength), glyphTypeface, fontRenderingEmSize, bidiLevel) |
|
|
{ |
|
|
{ |
|
|
|
|
|
_rented = true; |
|
|
|
|
|
Length = bufferLength; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal ShapedBuffer(CharacterBufferRange characterBufferRange, ArraySlice<GlyphInfo> glyphInfos, IGlyphTypeface glyphTypeface, double fontRenderingEmSize, sbyte bidiLevel) |
|
|
internal ShapedBuffer(CharacterBufferRange characterBufferRange, ArraySlice<GlyphInfo> glyphInfos, IGlyphTypeface glyphTypeface, double fontRenderingEmSize, sbyte bidiLevel) |
|
|
@ -21,11 +24,12 @@ namespace Avalonia.Media.TextFormatting |
|
|
GlyphTypeface = glyphTypeface; |
|
|
GlyphTypeface = glyphTypeface; |
|
|
FontRenderingEmSize = fontRenderingEmSize; |
|
|
FontRenderingEmSize = fontRenderingEmSize; |
|
|
BidiLevel = bidiLevel; |
|
|
BidiLevel = bidiLevel; |
|
|
|
|
|
Length = GlyphInfos.Length; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal ArraySlice<GlyphInfo> GlyphInfos { get; } |
|
|
internal ArraySlice<GlyphInfo> GlyphInfos { get; } |
|
|
|
|
|
|
|
|
public int Length => GlyphInfos.Length; |
|
|
public int Length { get; } |
|
|
|
|
|
|
|
|
public IGlyphTypeface GlyphTypeface { get; } |
|
|
public IGlyphTypeface GlyphTypeface { get; } |
|
|
|
|
|
|
|
|
@ -260,6 +264,23 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
|
|
|
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); |
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
|
{ |
|
|
|
|
|
GC.SuppressFinalize(this); |
|
|
|
|
|
if (_rented) |
|
|
|
|
|
{ |
|
|
|
|
|
GlyphInfos.ReturnRent(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
~ShapedBuffer() |
|
|
|
|
|
{ |
|
|
|
|
|
if (_rented) |
|
|
|
|
|
{ |
|
|
|
|
|
GlyphInfos.ReturnRent(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public readonly record struct GlyphInfo |
|
|
public readonly record struct GlyphInfo |
|
|
|