|
|
@ -1,5 +1,4 @@ |
|
|
using System; |
|
|
using Avalonia.Media.TextFormatting.Unicode; |
|
|
using Avalonia.Media.TextFormatting.Unicode; |
|
|
|
|
|
|
|
|
|
|
|
namespace Avalonia.Media.TextFormatting |
|
|
namespace Avalonia.Media.TextFormatting |
|
|
{ |
|
|
{ |
|
|
@ -17,12 +16,12 @@ namespace Avalonia.Media.TextFormatting |
|
|
var runIndex = 0; |
|
|
var runIndex = 0; |
|
|
var currentWidth = 0.0; |
|
|
var currentWidth = 0.0; |
|
|
var collapsedLength = 0; |
|
|
var collapsedLength = 0; |
|
|
var shapedSymbol = TextFormatterImpl.CreateSymbol(properties.Symbol, FlowDirection.LeftToRight); |
|
|
var shapedSymbol = TextFormatter.CreateSymbol(properties.Symbol, FlowDirection.LeftToRight); |
|
|
|
|
|
|
|
|
if (properties.Width < shapedSymbol.GlyphRun.Bounds.Width) |
|
|
if (properties.Width < shapedSymbol.GlyphRun.Bounds.Width) |
|
|
{ |
|
|
{ |
|
|
//Not enough space to fit in the symbol
|
|
|
//Not enough space to fit in the symbol
|
|
|
return Array.Empty<TextRun>(); |
|
|
return []; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var availableWidth = properties.Width - shapedSymbol.Size.Width; |
|
|
var availableWidth = properties.Width - shapedSymbol.Size.Width; |
|
|
@ -72,7 +71,7 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
|
|
|
|
|
collapsedLength += measuredLength; |
|
|
collapsedLength += measuredLength; |
|
|
|
|
|
|
|
|
return CreateCollapsedRuns(textLine, collapsedLength, FlowDirection.LeftToRight, shapedSymbol); |
|
|
return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, FlowDirection.LeftToRight, shapedSymbol); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
availableWidth -= shapedRun.Size.Width; |
|
|
availableWidth -= shapedRun.Size.Width; |
|
|
@ -85,7 +84,7 @@ namespace Avalonia.Media.TextFormatting |
|
|
//The whole run needs to fit into available space
|
|
|
//The whole run needs to fit into available space
|
|
|
if (currentWidth + drawableRun.Size.Width > availableWidth) |
|
|
if (currentWidth + drawableRun.Size.Width > availableWidth) |
|
|
{ |
|
|
{ |
|
|
return CreateCollapsedRuns(textLine, collapsedLength, FlowDirection.LeftToRight, shapedSymbol); |
|
|
return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, FlowDirection.LeftToRight, shapedSymbol); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
availableWidth -= drawableRun.Size.Width; |
|
|
availableWidth -= drawableRun.Size.Width; |
|
|
@ -146,7 +145,7 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
|
|
|
|
|
collapsedLength += measuredLength; |
|
|
collapsedLength += measuredLength; |
|
|
|
|
|
|
|
|
return CreateCollapsedRuns(textLine, collapsedLength, FlowDirection.RightToLeft, shapedSymbol); |
|
|
return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, FlowDirection.RightToLeft, shapedSymbol); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
availableWidth -= shapedRun.Size.Width; |
|
|
availableWidth -= shapedRun.Size.Width; |
|
|
@ -159,7 +158,7 @@ namespace Avalonia.Media.TextFormatting |
|
|
//The whole run needs to fit into available space
|
|
|
//The whole run needs to fit into available space
|
|
|
if (currentWidth + drawableRun.Size.Width > availableWidth) |
|
|
if (currentWidth + drawableRun.Size.Width > availableWidth) |
|
|
{ |
|
|
{ |
|
|
return CreateCollapsedRuns(textLine, collapsedLength, FlowDirection.RightToLeft, shapedSymbol); |
|
|
return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, FlowDirection.RightToLeft, shapedSymbol); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
availableWidth -= drawableRun.Size.Width; |
|
|
availableWidth -= drawableRun.Size.Width; |
|
|
@ -176,48 +175,5 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
|
|
|
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static TextRun[] CreateCollapsedRuns(TextLine textLine, int collapsedLength, |
|
|
|
|
|
FlowDirection flowDirection, TextRun shapedSymbol) |
|
|
|
|
|
{ |
|
|
|
|
|
var textRuns = textLine.TextRuns; |
|
|
|
|
|
|
|
|
|
|
|
if (collapsedLength <= 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return new[] { shapedSymbol }; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(flowDirection == FlowDirection.RightToLeft) |
|
|
|
|
|
{ |
|
|
|
|
|
collapsedLength = textLine.Length - collapsedLength; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var objectPool = FormattingObjectPool.Instance; |
|
|
|
|
|
|
|
|
|
|
|
var (preSplitRuns, postSplitRuns) = TextFormatterImpl.SplitTextRuns(textRuns, collapsedLength, objectPool); |
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
if (flowDirection == FlowDirection.RightToLeft) |
|
|
|
|
|
{ |
|
|
|
|
|
var collapsedRuns = new TextRun[postSplitRuns!.Count + 1]; |
|
|
|
|
|
postSplitRuns.CopyTo(collapsedRuns, 1); |
|
|
|
|
|
collapsedRuns[0] = shapedSymbol; |
|
|
|
|
|
return collapsedRuns; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
var collapsedRuns = new TextRun[preSplitRuns!.Count + 1]; |
|
|
|
|
|
preSplitRuns.CopyTo(collapsedRuns); |
|
|
|
|
|
collapsedRuns[collapsedRuns.Length - 1] = shapedSymbol; |
|
|
|
|
|
return collapsedRuns; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
objectPool.TextRunLists.Return(ref preSplitRuns); |
|
|
|
|
|
objectPool.TextRunLists.Return(ref postSplitRuns); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|