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