Browse Source

Always produce a TextLine

pull/7946/head
Benedikt Stebner 5 years ago
parent
commit
6317a3ec18
  1. 2
      src/Avalonia.Visuals/Media/TextFormatting/TextFormatter.cs
  2. 14
      src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs

2
src/Avalonia.Visuals/Media/TextFormatting/TextFormatter.cs

@ -38,7 +38,7 @@
/// <param name="previousLineBreak">A <see cref="TextLineBreak"/> value that specifies the text formatter state,
/// in terms of where the previous line in the paragraph was broken by the text formatting process.</param>
/// <returns>The formatted line.</returns>
public abstract TextLine? FormatLine(ITextSource textSource, int firstTextSourceIndex, double paragraphWidth,
public abstract TextLine FormatLine(ITextSource textSource, int firstTextSourceIndex, double paragraphWidth,
TextParagraphProperties paragraphProperties, TextLineBreak? previousLineBreak = null);
}
}

14
src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs

@ -9,7 +9,7 @@ namespace Avalonia.Media.TextFormatting
internal class TextFormatterImpl : TextFormatter
{
/// <inheritdoc cref="TextFormatter.FormatLine"/>
public override TextLine? FormatLine(ITextSource textSource, int firstTextSourceIndex, double paragraphWidth,
public override TextLine FormatLine(ITextSource textSource, int firstTextSourceIndex, double paragraphWidth,
TextParagraphProperties paragraphProperties, TextLineBreak? previousLineBreak = null)
{
var textWrapping = paragraphProperties.TextWrapping;
@ -20,11 +20,6 @@ namespace Avalonia.Media.TextFormatting
var textRuns = FetchTextRuns(textSource, firstTextSourceIndex,
out var textEndOfLine, out var textSourceLength);
if(textRuns.Count == 0)
{
return null;
}
if (previousLineBreak?.RemainingRuns != null)
{
flowDirection = previousLineBreak.FlowDirection;
@ -272,7 +267,6 @@ namespace Avalonia.Media.TextFormatting
IReadOnlyList<ShapeableTextCharacters> textRuns, ReadOnlySlice<char> text, TextShaperOptions options)
{
var shapedRuns = new List<ShapedTextCharacters>(textRuns.Count);
var firstRun = textRuns[0];
var shapedBuffer = TextShaper.Current.ShapeText(text, options);
@ -544,6 +538,12 @@ namespace Avalonia.Media.TextFormatting
double paragraphWidth, TextParagraphProperties paragraphProperties, FlowDirection flowDirection,
TextLineBreak? currentLineBreak)
{
if(textRuns.Count == 0)
{
return new TextLineImpl(textRuns, firstTextSourceIndex, 0, paragraphWidth, paragraphProperties, flowDirection);
}
if (!TryMeasureLength(textRuns, paragraphWidth, out var measuredLength))
{
measuredLength = 1;

Loading…
Cancel
Save