|
|
|
@ -90,7 +90,9 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
/// <returns>The split result.</returns>
|
|
|
|
public SplitTextCharactersResult Split(int length) |
|
|
|
{ |
|
|
|
var glyphCount = GlyphRun.FindGlyphIndex(GlyphRun.Characters.Start + length); |
|
|
|
var glyphCount = GlyphRun.IsLeftToRight ? |
|
|
|
GlyphRun.FindGlyphIndex(GlyphRun.Characters.Start + length) : |
|
|
|
GlyphRun.FindGlyphIndex(GlyphRun.Characters.End - length); |
|
|
|
|
|
|
|
if (GlyphRun.Characters.Length == length) |
|
|
|
{ |
|
|
|
@ -102,31 +104,64 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
return new SplitTextCharactersResult(this, null); |
|
|
|
} |
|
|
|
|
|
|
|
var firstGlyphRun = new GlyphRun( |
|
|
|
Properties.Typeface.GlyphTypeface, |
|
|
|
Properties.FontRenderingEmSize, |
|
|
|
GlyphRun.GlyphIndices.Take(glyphCount), |
|
|
|
GlyphRun.GlyphAdvances.Take(glyphCount), |
|
|
|
GlyphRun.GlyphOffsets.Take(glyphCount), |
|
|
|
GlyphRun.Characters.Take(length), |
|
|
|
GlyphRun.GlyphClusters.Take(glyphCount), |
|
|
|
GlyphRun.BiDiLevel); |
|
|
|
|
|
|
|
var firstTextRun = new ShapedTextCharacters(firstGlyphRun, Properties); |
|
|
|
|
|
|
|
var secondGlyphRun = new GlyphRun( |
|
|
|
Properties.Typeface.GlyphTypeface, |
|
|
|
Properties.FontRenderingEmSize, |
|
|
|
GlyphRun.GlyphIndices.Skip(glyphCount), |
|
|
|
GlyphRun.GlyphAdvances.Skip(glyphCount), |
|
|
|
GlyphRun.GlyphOffsets.Skip(glyphCount), |
|
|
|
GlyphRun.Characters.Skip(length), |
|
|
|
GlyphRun.GlyphClusters.Skip(glyphCount), |
|
|
|
GlyphRun.BiDiLevel); |
|
|
|
|
|
|
|
var secondTextRun = new ShapedTextCharacters(secondGlyphRun, Properties); |
|
|
|
|
|
|
|
return new SplitTextCharactersResult(firstTextRun, secondTextRun); |
|
|
|
if (GlyphRun.IsLeftToRight) |
|
|
|
{ |
|
|
|
var firstGlyphRun = new GlyphRun( |
|
|
|
Properties.Typeface.GlyphTypeface, |
|
|
|
Properties.FontRenderingEmSize, |
|
|
|
GlyphRun.GlyphIndices.Take(glyphCount), |
|
|
|
GlyphRun.GlyphAdvances.Take(glyphCount), |
|
|
|
GlyphRun.GlyphOffsets.Take(glyphCount), |
|
|
|
GlyphRun.Characters.Take(length), |
|
|
|
GlyphRun.GlyphClusters.Take(glyphCount), |
|
|
|
GlyphRun.BiDiLevel); |
|
|
|
|
|
|
|
var firstTextRun = new ShapedTextCharacters(firstGlyphRun, Properties); |
|
|
|
|
|
|
|
var secondGlyphRun = new GlyphRun( |
|
|
|
Properties.Typeface.GlyphTypeface, |
|
|
|
Properties.FontRenderingEmSize, |
|
|
|
GlyphRun.GlyphIndices.Skip(glyphCount), |
|
|
|
GlyphRun.GlyphAdvances.Skip(glyphCount), |
|
|
|
GlyphRun.GlyphOffsets.Skip(glyphCount), |
|
|
|
GlyphRun.Characters.Skip(length), |
|
|
|
GlyphRun.GlyphClusters.Skip(glyphCount), |
|
|
|
GlyphRun.BiDiLevel); |
|
|
|
|
|
|
|
var secondTextRun = new ShapedTextCharacters(secondGlyphRun, Properties); |
|
|
|
|
|
|
|
return new SplitTextCharactersResult(firstTextRun, secondTextRun); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var take = GlyphRun.GlyphIndices.Length - glyphCount; |
|
|
|
|
|
|
|
var firstGlyphRun = new GlyphRun( |
|
|
|
Properties.Typeface.GlyphTypeface, |
|
|
|
Properties.FontRenderingEmSize, |
|
|
|
GlyphRun.GlyphIndices.Take(take), |
|
|
|
GlyphRun.GlyphAdvances.Take(take), |
|
|
|
GlyphRun.GlyphOffsets.Take(take), |
|
|
|
GlyphRun.Characters.Skip(length), |
|
|
|
GlyphRun.GlyphClusters.Take(take), |
|
|
|
GlyphRun.BiDiLevel); |
|
|
|
|
|
|
|
var firstTextRun = new ShapedTextCharacters(firstGlyphRun, Properties); |
|
|
|
|
|
|
|
var secondGlyphRun = new GlyphRun( |
|
|
|
Properties.Typeface.GlyphTypeface, |
|
|
|
Properties.FontRenderingEmSize, |
|
|
|
GlyphRun.GlyphIndices.Skip(take), |
|
|
|
GlyphRun.GlyphAdvances.Skip(take), |
|
|
|
GlyphRun.GlyphOffsets.Skip(take), |
|
|
|
GlyphRun.Characters.Take(length), |
|
|
|
GlyphRun.GlyphClusters.Skip(take), |
|
|
|
GlyphRun.BiDiLevel); |
|
|
|
|
|
|
|
var secondTextRun = new ShapedTextCharacters(secondGlyphRun, Properties); |
|
|
|
|
|
|
|
return new SplitTextCharactersResult(secondTextRun,firstTextRun); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public readonly struct SplitTextCharactersResult |
|
|
|
|