|
@@ -32,6 +32,7 @@ namespace Avalonia.Media.TextFormatting
|
|
|
/// <param name="textDecorations">The text decorations.</param>
|
|
|
/// <param name="maxWidth">The maximum width.</param>
|
|
|
/// <param name="maxHeight">The maximum height.</param>
|
|
|
+ /// <param name="maxLines">The maximum number of text lines.</param>
|
|
|
/// <param name="textStyleOverrides">The text style overrides.</param>
|
|
|
public TextLayout(
|
|
|
string text,
|
|
@@ -44,6 +45,7 @@ namespace Avalonia.Media.TextFormatting
|
|
|
TextDecorationCollection textDecorations = null,
|
|
|
double maxWidth = double.PositiveInfinity,
|
|
|
double maxHeight = double.PositiveInfinity,
|
|
|
+ int maxLines = 0,
|
|
|
IReadOnlyList<TextStyleRun> textStyleOverrides = null)
|
|
|
{
|
|
|
_text = string.IsNullOrEmpty(text) ?
|
|
@@ -59,6 +61,8 @@ namespace Avalonia.Media.TextFormatting
|
|
|
|
|
|
MaxHeight = maxHeight;
|
|
|
|
|
|
+ MaxLines = maxLines;
|
|
|
+
|
|
|
UpdateLayout();
|
|
|
}
|
|
|
|
|
@@ -73,6 +77,12 @@ namespace Avalonia.Media.TextFormatting
|
|
|
/// </summary>
|
|
|
public double MaxHeight { get; }
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the maximum number of text lines.
|
|
|
+ /// </summary>
|
|
|
+ public double MaxLines { get; }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Gets the text lines.
|
|
|
/// </summary>
|
|
@@ -192,7 +202,7 @@ namespace Avalonia.Media.TextFormatting
|
|
|
|
|
|
var currentPosition = 0;
|
|
|
|
|
|
- while (currentPosition < _text.Length)
|
|
|
+ while (currentPosition < _text.Length && (MaxLines == 0 || textLines.Count < MaxLines))
|
|
|
{
|
|
|
int length;
|
|
|
|
|
@@ -222,7 +232,7 @@ namespace Avalonia.Media.TextFormatting
|
|
|
|
|
|
var remainingLength = length;
|
|
|
|
|
|
- while (remainingLength > 0)
|
|
|
+ while (remainingLength > 0 && (MaxLines == 0 || textLines.Count < MaxLines))
|
|
|
{
|
|
|
var textSlice = _text.AsSlice(currentPosition, remainingLength);
|
|
|
|