Browse Source

Introduce TextBlock.LineSpacing (#13243)

* Introduce TextBlock.LineSpacing

* Introduce TextBlock.LineSpacing
pull/13295/head
Benedikt Stebner 3 years ago
committed by GitHub
parent
commit
a5b12fbc7d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs
  2. 5
      src/Avalonia.Base/Media/TextFormatting/TextParagraphProperties.cs
  3. 26
      src/Avalonia.Controls/TextBlock.cs

3
src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

@ -1233,6 +1233,7 @@ namespace Avalonia.Media.TextFormatting
var height = descent - ascent + lineGap;
var lineHeight = _paragraphProperties.LineHeight;
var lineSpacing = _paragraphProperties.LineSpacing;
var bounds = new Rect();
@ -1339,7 +1340,7 @@ namespace Avalonia.Media.TextFormatting
return new TextLineMetrics
{
HasOverflowed = hasOverflowed,
Height = height,
Height = height + lineSpacing,
Extent = bounds.Height,
NewlineLength = newLineLength,
Start = start,

5
src/Avalonia.Base/Media/TextFormatting/TextParagraphProperties.cs

@ -21,6 +21,11 @@
/// </summary>
public abstract double LineHeight { get; }
/// <summary>
/// Paragraph's line spacing
/// </summary>
internal double LineSpacing { get; set; }
/// <summary>
/// Indicates the first line of the paragraph.
/// </summary>

26
src/Avalonia.Controls/TextBlock.cs

@ -83,6 +83,16 @@ namespace Avalonia.Controls
validate: IsValidLineHeight,
inherits: true);
/// <summary>
/// Defines the <see cref="LineSpacing"/> property.
/// </summary>
public static readonly AttachedProperty<double> LineSpacingProperty =
AvaloniaProperty.RegisterAttached<TextBlock, Control, double>(
nameof(LineSpacing),
0,
validate: IsValidLineSpacing,
inherits: true);
/// <summary>
/// Defines the <see cref="LetterSpacing"/> property.
/// </summary>
@ -265,6 +275,15 @@ namespace Avalonia.Controls
set => SetValue(LineHeightProperty, value);
}
/// <summary>
/// Gets or sets the extra distance of each line to the next line.
/// </summary>
public double LineSpacing
{
get => GetValue(LineSpacingProperty);
set => SetValue(LineSpacingProperty, value);
}
/// <summary>
/// Gets or sets the letter spacing.
/// </summary>
@ -620,7 +639,10 @@ namespace Avalonia.Controls
Foreground);
var paragraphProperties = new GenericTextParagraphProperties(FlowDirection, TextAlignment, true, false,
defaultProperties, TextWrapping, LineHeight, 0, LetterSpacing);
defaultProperties, TextWrapping, LineHeight, 0, LetterSpacing)
{
LineSpacing = LineSpacing
};
ITextSource textSource;
@ -800,6 +822,8 @@ namespace Avalonia.Controls
private static bool IsValidLineHeight(double lineHeight) => double.IsNaN(lineHeight) || lineHeight > 0;
private static bool IsValidLineSpacing(double lineSpacing) => !double.IsNaN(lineSpacing) && !double.IsInfinity(lineSpacing);
private void OnInlinesChanged(InlineCollection? oldValue, InlineCollection? newValue)
{
if (oldValue is not null)

Loading…
Cancel
Save