From 6317a3ec181f107d6ce708ba288176e13d795403 Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Fri, 8 Apr 2022 10:08:26 +0200 Subject: [PATCH] Always produce a TextLine --- .../Media/TextFormatting/TextFormatter.cs | 2 +- .../Media/TextFormatting/TextFormatterImpl.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Avalonia.Visuals/Media/TextFormatting/TextFormatter.cs b/src/Avalonia.Visuals/Media/TextFormatting/TextFormatter.cs index ff8c1c4860..0b5d7649d7 100644 --- a/src/Avalonia.Visuals/Media/TextFormatting/TextFormatter.cs +++ b/src/Avalonia.Visuals/Media/TextFormatting/TextFormatter.cs @@ -38,7 +38,7 @@ /// A value that specifies the text formatter state, /// in terms of where the previous line in the paragraph was broken by the text formatting process. /// The formatted line. - 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); } } diff --git a/src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs b/src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs index 0ccff8ae3a..7241c62472 100644 --- a/src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs +++ b/src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs @@ -9,7 +9,7 @@ namespace Avalonia.Media.TextFormatting internal class TextFormatterImpl : TextFormatter { /// - 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 textRuns, ReadOnlySlice text, TextShaperOptions options) { var shapedRuns = new List(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;