Browse Source

Simplify text formatting constructors (#20527)

* Remove the flowDirection parameter from TextCollapsingProperties.CreateCollapsedRuns

* Simplify text formatting constructors

* Update API suppressions
pull/18827/merge
Julien Lebosquain 1 week ago
committed by GitHub
parent
commit
3394815603
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 84
      api/Avalonia.nupkg.xml
  2. 7
      samples/TextTestApp/InteractiveLineControl.cs
  3. 37
      src/Avalonia.Base/Media/FormattedText.cs
  4. 21
      src/Avalonia.Base/Media/TextFormatting/GenericTextRunProperties.cs
  5. 4
      src/Avalonia.Base/Media/TextFormatting/TextCollapsingProperties.cs
  6. 4
      src/Avalonia.Base/Media/TextFormatting/TextEllipsisHelper.cs
  7. 4
      src/Avalonia.Base/Media/TextFormatting/TextFormatter.cs
  8. 10
      src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs
  9. 51
      src/Avalonia.Base/Media/TextFormatting/TextLayout.cs
  10. 11
      src/Avalonia.Base/Media/TextFormatting/TextRunProperties.cs
  11. 19
      src/Avalonia.Base/Media/TextFormatting/TextShaperOptions.cs
  12. 5
      src/Avalonia.Controls/Documents/Inline.cs
  13. 37
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  14. 15
      src/Avalonia.Controls/SelectableTextBlock.cs
  15. 4
      src/Avalonia.Controls/TextBlock.cs

84
api/Avalonia.nupkg.xml

@ -151,6 +151,48 @@
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left> <Left>baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right> <Right>current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression> </Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.GenericTextRunProperties.#ctor(Avalonia.Media.Typeface,Avalonia.Media.FontFeatureCollection,System.Double,Avalonia.Media.TextDecorationCollection,Avalonia.Media.IBrush,Avalonia.Media.IBrush,Avalonia.Media.BaselineAlignment,System.Globalization.CultureInfo)</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.GenericTextRunProperties.#ctor(Avalonia.Media.Typeface,System.Double,Avalonia.Media.TextDecorationCollection,Avalonia.Media.IBrush,Avalonia.Media.IBrush,Avalonia.Media.BaselineAlignment,System.Globalization.CultureInfo)</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextCollapsingProperties.CreateCollapsedRuns(Avalonia.Media.TextFormatting.TextLine,System.Int32,Avalonia.Media.FlowDirection,Avalonia.Media.TextFormatting.TextRun)</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextLayout.#ctor(System.String,Avalonia.Media.Typeface,Avalonia.Media.FontFeatureCollection,System.Double,Avalonia.Media.IBrush,Avalonia.Media.TextAlignment,Avalonia.Media.TextWrapping,Avalonia.Media.TextTrimming,Avalonia.Media.TextDecorationCollection,Avalonia.Media.FlowDirection,System.Double,System.Double,System.Double,System.Double,System.Int32,System.Collections.Generic.IReadOnlyList{Avalonia.Utilities.ValueSpan{Avalonia.Media.TextFormatting.TextRunProperties}})</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextLayout.#ctor(System.String,Avalonia.Media.Typeface,System.Double,Avalonia.Media.IBrush,Avalonia.Media.TextAlignment,Avalonia.Media.TextWrapping,Avalonia.Media.TextTrimming,Avalonia.Media.TextDecorationCollection,Avalonia.Media.FlowDirection,System.Double,System.Double,System.Double,System.Double,System.Int32,System.Collections.Generic.IReadOnlyList{Avalonia.Utilities.ValueSpan{Avalonia.Media.TextFormatting.TextRunProperties}})</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextShaperOptions.#ctor(Avalonia.Media.GlyphTypeface,System.Collections.Generic.IReadOnlyList{Avalonia.Media.FontFeature},System.Double,System.SByte,System.Globalization.CultureInfo,System.Double,System.Double)</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextShaperOptions.#ctor(Avalonia.Media.GlyphTypeface,System.Double,System.SByte,System.Globalization.CultureInfo,System.Double,System.Double)</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression> <Suppression>
<DiagnosticId>CP0002</DiagnosticId> <DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Platform.IDrawingContextImplWithEffects.PushEffect(Avalonia.Media.IEffect)</Target> <Target>M:Avalonia.Platform.IDrawingContextImplWithEffects.PushEffect(Avalonia.Media.IEffect)</Target>
@ -463,6 +505,48 @@
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left> <Left>baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right> <Right>current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression> </Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.GenericTextRunProperties.#ctor(Avalonia.Media.Typeface,Avalonia.Media.FontFeatureCollection,System.Double,Avalonia.Media.TextDecorationCollection,Avalonia.Media.IBrush,Avalonia.Media.IBrush,Avalonia.Media.BaselineAlignment,System.Globalization.CultureInfo)</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.GenericTextRunProperties.#ctor(Avalonia.Media.Typeface,System.Double,Avalonia.Media.TextDecorationCollection,Avalonia.Media.IBrush,Avalonia.Media.IBrush,Avalonia.Media.BaselineAlignment,System.Globalization.CultureInfo)</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextCollapsingProperties.CreateCollapsedRuns(Avalonia.Media.TextFormatting.TextLine,System.Int32,Avalonia.Media.FlowDirection,Avalonia.Media.TextFormatting.TextRun)</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextLayout.#ctor(System.String,Avalonia.Media.Typeface,Avalonia.Media.FontFeatureCollection,System.Double,Avalonia.Media.IBrush,Avalonia.Media.TextAlignment,Avalonia.Media.TextWrapping,Avalonia.Media.TextTrimming,Avalonia.Media.TextDecorationCollection,Avalonia.Media.FlowDirection,System.Double,System.Double,System.Double,System.Double,System.Int32,System.Collections.Generic.IReadOnlyList{Avalonia.Utilities.ValueSpan{Avalonia.Media.TextFormatting.TextRunProperties}})</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextLayout.#ctor(System.String,Avalonia.Media.Typeface,System.Double,Avalonia.Media.IBrush,Avalonia.Media.TextAlignment,Avalonia.Media.TextWrapping,Avalonia.Media.TextTrimming,Avalonia.Media.TextDecorationCollection,Avalonia.Media.FlowDirection,System.Double,System.Double,System.Double,System.Double,System.Int32,System.Collections.Generic.IReadOnlyList{Avalonia.Utilities.ValueSpan{Avalonia.Media.TextFormatting.TextRunProperties}})</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextShaperOptions.#ctor(Avalonia.Media.GlyphTypeface,System.Collections.Generic.IReadOnlyList{Avalonia.Media.FontFeature},System.Double,System.SByte,System.Globalization.CultureInfo,System.Double,System.Double)</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Media.TextFormatting.TextShaperOptions.#ctor(Avalonia.Media.GlyphTypeface,System.Double,System.SByte,System.Globalization.CultureInfo,System.Double,System.Double)</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression> <Suppression>
<DiagnosticId>CP0002</DiagnosticId> <DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Platform.IDrawingContextImplWithEffects.PushEffect(Avalonia.Media.IEffect)</Target> <Target>M:Avalonia.Platform.IDrawingContextImplWithEffects.PushEffect(Avalonia.Media.IEffect)</Target>

7
samples/TextTestApp/InteractiveLineControl.cs

@ -255,12 +255,15 @@ namespace TextTestApp
private GenericTextRunProperties CreateTextRunProperties() private GenericTextRunProperties CreateTextRunProperties()
{ {
Typeface typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); Typeface typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
return new GenericTextRunProperties(typeface, FontFeatures, FontSize, return new GenericTextRunProperties(
typeface,
FontSize,
textDecorations: null, textDecorations: null,
foregroundBrush: Brushes.Black, foregroundBrush: Brushes.Black,
backgroundBrush: null, backgroundBrush: null,
baselineAlignment: BaselineAlignment.Baseline, baselineAlignment: BaselineAlignment.Baseline,
cultureInfo: null); cultureInfo: null,
fontFeatures: FontFeatures);
} }
// TextParagraphProperties // TextParagraphProperties

37
src/Avalonia.Base/Media/FormattedText.cs

@ -184,13 +184,13 @@ namespace Avalonia.Media
var newProps = new GenericTextRunProperties( var newProps = new GenericTextRunProperties(
runProps.Typeface, runProps.Typeface,
runProps.FontFeatures,
runProps.FontRenderingEmSize, runProps.FontRenderingEmSize,
runProps.TextDecorations, runProps.TextDecorations,
foregroundBrush, foregroundBrush,
runProps.BackgroundBrush, runProps.BackgroundBrush,
runProps.BaselineAlignment, runProps.BaselineAlignment,
runProps.CultureInfo runProps.CultureInfo,
runProps.FontFeatures
); );
#pragma warning restore 6506 #pragma warning restore 6506
@ -240,13 +240,13 @@ namespace Avalonia.Media
var newProps = new GenericTextRunProperties( var newProps = new GenericTextRunProperties(
runProps.Typeface, runProps.Typeface,
fontFeatures,
runProps.FontRenderingEmSize, runProps.FontRenderingEmSize,
runProps.TextDecorations, runProps.TextDecorations,
runProps.ForegroundBrush, runProps.ForegroundBrush,
runProps.BackgroundBrush, runProps.BackgroundBrush,
runProps.BaselineAlignment, runProps.BaselineAlignment,
runProps.CultureInfo runProps.CultureInfo,
fontFeatures
); );
#pragma warning restore 6506 #pragma warning restore 6506
@ -328,14 +328,13 @@ namespace Avalonia.Media
var newProps = new GenericTextRunProperties( var newProps = new GenericTextRunProperties(
new Typeface(fontFamily, oldTypeface.Style, oldTypeface.Weight), new Typeface(fontFamily, oldTypeface.Style, oldTypeface.Weight),
runProps.FontFeatures,
runProps.FontRenderingEmSize, runProps.FontRenderingEmSize,
runProps.TextDecorations, runProps.TextDecorations,
runProps.ForegroundBrush, runProps.ForegroundBrush,
runProps.BackgroundBrush, runProps.BackgroundBrush,
runProps.BaselineAlignment, runProps.BaselineAlignment,
runProps.CultureInfo runProps.CultureInfo,
); runProps.FontFeatures);
#pragma warning restore 6506 #pragma warning restore 6506
_latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition, _latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition,
@ -388,13 +387,13 @@ namespace Avalonia.Media
var newProps = new GenericTextRunProperties( var newProps = new GenericTextRunProperties(
runProps.Typeface, runProps.Typeface,
runProps.FontFeatures,
emSize, emSize,
runProps.TextDecorations, runProps.TextDecorations,
runProps.ForegroundBrush, runProps.ForegroundBrush,
runProps.BackgroundBrush, runProps.BackgroundBrush,
runProps.BaselineAlignment, runProps.BaselineAlignment,
runProps.CultureInfo runProps.CultureInfo,
runProps.FontFeatures
); );
_latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition, _latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition,
@ -451,13 +450,13 @@ namespace Avalonia.Media
var newProps = new GenericTextRunProperties( var newProps = new GenericTextRunProperties(
runProps.Typeface, runProps.Typeface,
runProps.FontFeatures,
runProps.FontRenderingEmSize, runProps.FontRenderingEmSize,
runProps.TextDecorations, runProps.TextDecorations,
runProps.ForegroundBrush, runProps.ForegroundBrush,
runProps.BackgroundBrush, runProps.BackgroundBrush,
runProps.BaselineAlignment, runProps.BaselineAlignment,
culture culture,
runProps.FontFeatures
); );
#pragma warning restore 6506 #pragma warning restore 6506
@ -511,13 +510,13 @@ namespace Avalonia.Media
var newProps = new GenericTextRunProperties( var newProps = new GenericTextRunProperties(
new Typeface(oldTypeface.FontFamily, oldTypeface.Style, weight), new Typeface(oldTypeface.FontFamily, oldTypeface.Style, weight),
runProps.FontFeatures,
runProps.FontRenderingEmSize, runProps.FontRenderingEmSize,
runProps.TextDecorations, runProps.TextDecorations,
runProps.ForegroundBrush, runProps.ForegroundBrush,
runProps.BackgroundBrush, runProps.BackgroundBrush,
runProps.BaselineAlignment, runProps.BaselineAlignment,
runProps.CultureInfo runProps.CultureInfo,
runProps.FontFeatures
); );
#pragma warning restore 6506 #pragma warning restore 6506
_latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition, newProps, formatRider.SpanPosition); _latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition, newProps, formatRider.SpanPosition);
@ -568,13 +567,13 @@ namespace Avalonia.Media
var newProps = new GenericTextRunProperties( var newProps = new GenericTextRunProperties(
new Typeface(oldTypeface.FontFamily, style, oldTypeface.Weight), new Typeface(oldTypeface.FontFamily, style, oldTypeface.Weight),
runProps.FontFeatures,
runProps.FontRenderingEmSize, runProps.FontRenderingEmSize,
runProps.TextDecorations, runProps.TextDecorations,
runProps.ForegroundBrush, runProps.ForegroundBrush,
runProps.BackgroundBrush, runProps.BackgroundBrush,
runProps.BaselineAlignment, runProps.BaselineAlignment,
runProps.CultureInfo runProps.CultureInfo,
runProps.FontFeatures
); );
#pragma warning restore 6506 #pragma warning restore 6506
@ -625,13 +624,13 @@ namespace Avalonia.Media
var newProps = new GenericTextRunProperties( var newProps = new GenericTextRunProperties(
typeface, typeface,
runProps.FontFeatures,
runProps.FontRenderingEmSize, runProps.FontRenderingEmSize,
runProps.TextDecorations, runProps.TextDecorations,
runProps.ForegroundBrush, runProps.ForegroundBrush,
runProps.BackgroundBrush, runProps.BackgroundBrush,
runProps.BaselineAlignment, runProps.BaselineAlignment,
runProps.CultureInfo runProps.CultureInfo,
runProps.FontFeatures
); );
#pragma warning restore 6506 #pragma warning restore 6506
@ -683,13 +682,13 @@ namespace Avalonia.Media
var newProps = new GenericTextRunProperties( var newProps = new GenericTextRunProperties(
runProps.Typeface, runProps.Typeface,
runProps.FontFeatures,
runProps.FontRenderingEmSize, runProps.FontRenderingEmSize,
textDecorations, textDecorations,
runProps.ForegroundBrush, runProps.ForegroundBrush,
runProps.BackgroundBrush, runProps.BackgroundBrush,
runProps.BaselineAlignment, runProps.BaselineAlignment,
runProps.CultureInfo runProps.CultureInfo,
runProps.FontFeatures
); );
#pragma warning restore 6506 #pragma warning restore 6506

21
src/Avalonia.Base/Media/TextFormatting/GenericTextRunProperties.cs

@ -1,6 +1,4 @@
using System; using System.Globalization;
using System.Collections.Generic;
using System.Globalization;
namespace Avalonia.Media.TextFormatting namespace Avalonia.Media.TextFormatting
{ {
@ -9,28 +7,17 @@ namespace Avalonia.Media.TextFormatting
/// </summary> /// </summary>
public class GenericTextRunProperties : TextRunProperties public class GenericTextRunProperties : TextRunProperties
{ {
private const double DefaultFontRenderingEmSize = 12; internal const double DefaultFontRenderingEmSize = 12;
// TODO12: Remove in 12.0.0 and make fontFeatures parameter in main ctor optional
public GenericTextRunProperties(Typeface typeface, double fontRenderingEmSize = DefaultFontRenderingEmSize,
TextDecorationCollection? textDecorations = null, IBrush? foregroundBrush = null,
IBrush? backgroundBrush = null, BaselineAlignment baselineAlignment = BaselineAlignment.Baseline,
CultureInfo? cultureInfo = null) :
this(typeface, null, fontRenderingEmSize, textDecorations, foregroundBrush,
backgroundBrush, baselineAlignment, cultureInfo)
{
}
// TODO12:Change signature in 12.0.0
public GenericTextRunProperties( public GenericTextRunProperties(
Typeface typeface, Typeface typeface,
FontFeatureCollection? fontFeatures,
double fontRenderingEmSize = DefaultFontRenderingEmSize, double fontRenderingEmSize = DefaultFontRenderingEmSize,
TextDecorationCollection? textDecorations = null, TextDecorationCollection? textDecorations = null,
IBrush? foregroundBrush = null, IBrush? foregroundBrush = null,
IBrush? backgroundBrush = null, IBrush? backgroundBrush = null,
BaselineAlignment baselineAlignment = BaselineAlignment.Baseline, BaselineAlignment baselineAlignment = BaselineAlignment.Baseline,
CultureInfo? cultureInfo = null) CultureInfo? cultureInfo = null,
FontFeatureCollection? fontFeatures = null)
{ {
Typeface = typeface; Typeface = typeface;
FontRenderingEmSize = fontRenderingEmSize; FontRenderingEmSize = fontRenderingEmSize;

4
src/Avalonia.Base/Media/TextFormatting/TextCollapsingProperties.cs

@ -26,16 +26,14 @@
/// <param name="textLine">Text line to collapse.</param> /// <param name="textLine">Text line to collapse.</param>
public abstract TextRun[]? Collapse(TextLine textLine); public abstract TextRun[]? Collapse(TextLine textLine);
// TODO12: Remove the flowDirection parameter
/// <summary> /// <summary>
/// Creates a list of runs for given collapsed length which includes specified symbol at the end. /// Creates a list of runs for given collapsed length which includes specified symbol at the end.
/// </summary> /// </summary>
/// <param name="textLine">The text line.</param> /// <param name="textLine">The text line.</param>
/// <param name="collapsedLength">The collapsed length.</param> /// <param name="collapsedLength">The collapsed length.</param>
/// <param name="flowDirection">The flow direction.</param>
/// <param name="shapedSymbol">The symbol.</param> /// <param name="shapedSymbol">The symbol.</param>
/// <returns>List of remaining runs.</returns> /// <returns>List of remaining runs.</returns>
public static TextRun[] CreateCollapsedRuns(TextLine textLine, int collapsedLength, FlowDirection flowDirection, TextRun shapedSymbol) public static TextRun[] CreateCollapsedRuns(TextLine textLine, int collapsedLength, TextRun shapedSymbol)
{ {
if (collapsedLength <= 0) if (collapsedLength <= 0)
{ {

4
src/Avalonia.Base/Media/TextFormatting/TextEllipsisHelper.cs

@ -71,7 +71,7 @@ namespace Avalonia.Media.TextFormatting
collapsedLength += measuredLength; collapsedLength += measuredLength;
return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, properties.FlowDirection, shapedSymbol); return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, shapedSymbol);
} }
availableWidth -= textRunWidth; availableWidth -= textRunWidth;
@ -84,7 +84,7 @@ namespace Avalonia.Media.TextFormatting
//The whole run needs to fit into available space //The whole run needs to fit into available space
if (drawableRun.Size.Width > availableWidth) if (drawableRun.Size.Width > availableWidth)
{ {
return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, properties.FlowDirection, shapedSymbol); return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, shapedSymbol);
} }
availableWidth -= drawableRun.Size.Width; availableWidth -= drawableRun.Size.Width;

4
src/Avalonia.Base/Media/TextFormatting/TextFormatter.cs

@ -59,8 +59,8 @@
var cultureInfo = textRun.Properties.CultureInfo; var cultureInfo = textRun.Properties.CultureInfo;
var shaperOptions = new TextShaperOptions(glyphTypeface, textRun.Properties.FontFeatures, var shaperOptions = new TextShaperOptions(glyphTypeface, fontRenderingEmSize,
fontRenderingEmSize, (sbyte)flowDirection, cultureInfo); (sbyte)flowDirection, cultureInfo, 0, 0, textRun.Properties.FontFeatures);
var shapedBuffer = textShaper.ShapeText(textRun.Text, shaperOptions); var shapedBuffer = textShaper.ShapeText(textRun.Text, shaperOptions);

10
src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs

@ -290,9 +290,13 @@ namespace Avalonia.Media.TextFormatting
} }
var shaperOptions = new TextShaperOptions( var shaperOptions = new TextShaperOptions(
properties.CachedGlyphTypeface, properties.FontFeatures, properties.CachedGlyphTypeface,
properties.FontRenderingEmSize, shapeableRun.BidiLevel, properties.CultureInfo, properties.FontRenderingEmSize,
paragraphProperties.DefaultIncrementalTab, paragraphProperties.LetterSpacing); shapeableRun.BidiLevel,
properties.CultureInfo,
paragraphProperties.DefaultIncrementalTab,
paragraphProperties.LetterSpacing,
properties.FontFeatures);
ShapeTogether(groupedRuns, text, shaperOptions, textShaper, shapedRuns); ShapeTogether(groupedRuns, text, shaperOptions, textShaper, shapedRuns);

51
src/Avalonia.Base/Media/TextFormatting/TextLayout.cs

@ -17,7 +17,6 @@ namespace Avalonia.Media.TextFormatting
private int _textSourceLength; private int _textSourceLength;
// TODO12: Remove in 12.0.0 and make fontFeatures parameter in main ctor optional
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="TextLayout" /> class. /// Initializes a new instance of the <see cref="TextLayout" /> class.
/// </summary> /// </summary>
@ -35,54 +34,13 @@ namespace Avalonia.Media.TextFormatting
/// <param name="lineHeight">The height of each line of text.</param> /// <param name="lineHeight">The height of each line of text.</param>
/// <param name="letterSpacing">The letter spacing that is applied to rendered glyphs.</param> /// <param name="letterSpacing">The letter spacing that is applied to rendered glyphs.</param>
/// <param name="maxLines">The maximum number of text lines.</param> /// <param name="maxLines">The maximum number of text lines.</param>
/// <param name="textStyleOverrides">The text style overrides.</param>
public TextLayout(
string? text,
Typeface typeface,
double fontSize,
IBrush? foreground,
TextAlignment textAlignment = TextAlignment.Left,
TextWrapping textWrapping = TextWrapping.NoWrap,
TextTrimming? textTrimming = null,
TextDecorationCollection? textDecorations = null,
FlowDirection flowDirection = FlowDirection.LeftToRight,
double maxWidth = double.PositiveInfinity,
double maxHeight = double.PositiveInfinity,
double lineHeight = double.NaN,
double letterSpacing = 0,
int maxLines = 0,
IReadOnlyList<ValueSpan<TextRunProperties>>? textStyleOverrides = null)
: this(text, typeface, null, fontSize, foreground, textAlignment, textWrapping, textTrimming, textDecorations,
flowDirection, maxWidth, maxHeight, lineHeight, letterSpacing, maxLines, textStyleOverrides)
{
}
// TODO12:Change signature in 12.0.0
/// <summary>
/// Initializes a new instance of the <see cref="TextLayout" /> class.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="typeface">The typeface.</param>
/// <param name="fontSize">Size of the font.</param>
/// <param name="foreground">The foreground.</param>
/// <param name="textAlignment">The text alignment.</param>
/// <param name="textWrapping">The text wrapping.</param>
/// <param name="textTrimming">The text trimming.</param>
/// <param name="textDecorations">The text decorations.</param>
/// <param name="flowDirection">The text flow direction.</param>
/// <param name="maxWidth">The maximum width.</param>
/// <param name="maxHeight">The maximum height.</param>
/// <param name="lineHeight">The height of each line of text.</param>
/// <param name="letterSpacing">The letter spacing that is applied to rendered glyphs.</param>
/// <param name="maxLines">The maximum number of text lines.</param>
/// <param name="textStyleOverrides">The text style overrides.</param>
/// <param name="fontFeatures">Optional list of turned on/off features.</param> /// <param name="fontFeatures">Optional list of turned on/off features.</param>
/// <param name="textStyleOverrides">The text style overrides.</param>
public TextLayout( public TextLayout(
string? text, string? text,
Typeface typeface, Typeface typeface,
FontFeatureCollection? fontFeatures, double fontSize = GenericTextRunProperties.DefaultFontRenderingEmSize,
double fontSize, IBrush? foreground = null,
IBrush? foreground,
TextAlignment textAlignment = TextAlignment.Left, TextAlignment textAlignment = TextAlignment.Left,
TextWrapping textWrapping = TextWrapping.NoWrap, TextWrapping textWrapping = TextWrapping.NoWrap,
TextTrimming? textTrimming = null, TextTrimming? textTrimming = null,
@ -93,6 +51,7 @@ namespace Avalonia.Media.TextFormatting
double lineHeight = double.NaN, double lineHeight = double.NaN,
double letterSpacing = 0, double letterSpacing = 0,
int maxLines = 0, int maxLines = 0,
FontFeatureCollection? fontFeatures = null,
IReadOnlyList<ValueSpan<TextRunProperties>>? textStyleOverrides = null) IReadOnlyList<ValueSpan<TextRunProperties>>? textStyleOverrides = null)
{ {
_paragraphProperties = _paragraphProperties =
@ -534,7 +493,7 @@ namespace Avalonia.Media.TextFormatting
TextDecorationCollection? textDecorations, FlowDirection flowDirection, double lineHeight, TextDecorationCollection? textDecorations, FlowDirection flowDirection, double lineHeight,
double letterSpacing, FontFeatureCollection? features) double letterSpacing, FontFeatureCollection? features)
{ {
var textRunStyle = new GenericTextRunProperties(typeface, features, fontSize, textDecorations, foreground); var textRunStyle = new GenericTextRunProperties(typeface, fontSize, textDecorations, foreground, fontFeatures: features);
return new GenericTextParagraphProperties(flowDirection, textAlignment, true, false, return new GenericTextParagraphProperties(flowDirection, textAlignment, true, false,
textRunStyle, textWrapping, lineHeight, 0, letterSpacing); textRunStyle, textWrapping, lineHeight, 0, letterSpacing);

11
src/Avalonia.Base/Media/TextFormatting/TextRunProperties.cs

@ -107,8 +107,15 @@ namespace Avalonia.Media.TextFormatting
if (this is GenericTextRunProperties other && other.Typeface == typeface) if (this is GenericTextRunProperties other && other.Typeface == typeface)
return this; return this;
return new GenericTextRunProperties(typeface, FontFeatures, FontRenderingEmSize, return new GenericTextRunProperties(
TextDecorations, ForegroundBrush, BackgroundBrush, BaselineAlignment); typeface,
FontRenderingEmSize,
TextDecorations,
ForegroundBrush,
BackgroundBrush,
BaselineAlignment,
CultureInfo,
FontFeatures);
} }
} }
} }

19
src/Avalonia.Base/Media/TextFormatting/TextShaperOptions.cs

@ -8,27 +8,14 @@ namespace Avalonia.Media.TextFormatting
/// </summary> /// </summary>
public readonly record struct TextShaperOptions public readonly record struct TextShaperOptions
{ {
// TODO12: Remove in 12.0.0 and make fontFeatures parameter in main ctor optional
public TextShaperOptions( public TextShaperOptions(
GlyphTypeface typeface, GlyphTypeface typeface,
double fontRenderingEmSize = 12, double fontRenderingEmSize = GenericTextRunProperties.DefaultFontRenderingEmSize,
sbyte bidiLevel = 0, sbyte bidiLevel = 0,
CultureInfo? culture = null, CultureInfo? culture = null,
double incrementalTabWidth = 0, double incrementalTabWidth = 0,
double letterSpacing = 0) double letterSpacing = 0,
: this(typeface, null, fontRenderingEmSize, bidiLevel, culture, incrementalTabWidth, letterSpacing) IReadOnlyList<FontFeature>? fontFeatures = null)
{
}
// TODO12:Change signature in 12.0.0
public TextShaperOptions(
GlyphTypeface typeface,
IReadOnlyList<FontFeature>? fontFeatures,
double fontRenderingEmSize = 12,
sbyte bidiLevel = 0,
CultureInfo? culture = null,
double incrementalTabWidth = 0,
double letterSpacing = 0)
{ {
GlyphTypeface = typeface; GlyphTypeface = typeface;
FontRenderingEmSize = fontRenderingEmSize; FontRenderingEmSize = fontRenderingEmSize;

5
src/Avalonia.Controls/Documents/Inline.cs

@ -81,12 +81,13 @@ namespace Avalonia.Controls.Documents
return new GenericTextRunProperties( return new GenericTextRunProperties(
typeface, typeface,
FontFeatures,
FontSize, FontSize,
TextDecorations, TextDecorations,
Foreground, Foreground,
parentOrSelfBackground, parentOrSelfBackground,
BaselineAlignment); BaselineAlignment,
null,
FontFeatures);
} }
/// <summary> /// <summary>

37
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -346,13 +346,26 @@ namespace Avalonia.Controls.Presenters
private TextLayout CreateTextLayoutInternal(Size constraint, string? text, Typeface typeface, private TextLayout CreateTextLayoutInternal(Size constraint, string? text, Typeface typeface,
IReadOnlyList<ValueSpan<TextRunProperties>>? textStyleOverrides) IReadOnlyList<ValueSpan<TextRunProperties>>? textStyleOverrides)
{ {
var foreground = Foreground;
var maxWidth = MathUtilities.IsZero(constraint.Width) ? double.PositiveInfinity : constraint.Width; var maxWidth = MathUtilities.IsZero(constraint.Width) ? double.PositiveInfinity : constraint.Width;
var maxHeight = MathUtilities.IsZero(constraint.Height) ? double.PositiveInfinity : constraint.Height; var maxHeight = MathUtilities.IsZero(constraint.Height) ? double.PositiveInfinity : constraint.Height;
var textLayout = new TextLayout(text, typeface, FontFeatures, FontSize, foreground, TextAlignment, var textLayout = new TextLayout(
TextWrapping, maxWidth: maxWidth, maxHeight: maxHeight, textStyleOverrides: textStyleOverrides, text,
flowDirection: FlowDirection, lineHeight: LineHeight, letterSpacing: LetterSpacing); typeface,
FontSize,
Foreground,
TextAlignment,
TextWrapping,
null,
null,
FlowDirection,
maxWidth,
maxHeight,
LineHeight,
LetterSpacing,
0,
FontFeatures,
textStyleOverrides);
return textLayout; return textLayout;
} }
@ -553,9 +566,12 @@ namespace Avalonia.Controls.Presenters
if (!string.IsNullOrEmpty(preeditText)) if (!string.IsNullOrEmpty(preeditText))
{ {
var preeditHighlight = new ValueSpan<TextRunProperties>(caretIndex, preeditText.Length, var preeditHighlight = new ValueSpan<TextRunProperties>(caretIndex, preeditText.Length,
new GenericTextRunProperties(typeface, FontFeatures, FontSize, new GenericTextRunProperties(
foregroundBrush: foreground, typeface,
textDecorations: TextDecorations.Underline)); FontSize,
TextDecorations.Underline,
foreground,
fontFeatures: FontFeatures));
textStyleOverrides = new[] textStyleOverrides = new[]
{ {
@ -569,8 +585,11 @@ namespace Avalonia.Controls.Presenters
textStyleOverrides = new[] textStyleOverrides = new[]
{ {
new ValueSpan<TextRunProperties>(start, length, new ValueSpan<TextRunProperties>(start, length,
new GenericTextRunProperties(typeface, FontFeatures, FontSize, new GenericTextRunProperties(
foregroundBrush: SelectionForegroundBrush)) typeface,
FontSize,
foregroundBrush: SelectionForegroundBrush,
fontFeatures: FontFeatures))
}; };
} }
} }

15
src/Avalonia.Controls/SelectableTextBlock.cs

@ -186,10 +186,10 @@ namespace Avalonia.Controls
var defaultProperties = new GenericTextRunProperties( var defaultProperties = new GenericTextRunProperties(
typeface, typeface,
FontFeatures,
FontSize, FontSize,
TextDecorations, TextDecorations,
Foreground); Foreground,
fontFeatures: FontFeatures);
var paragraphProperties = new GenericTextParagraphProperties(FlowDirection, TextAlignment, true, false, var paragraphProperties = new GenericTextParagraphProperties(FlowDirection, TextAlignment, true, false,
defaultProperties, TextWrapping, LineHeight, 0, LetterSpacing) defaultProperties, TextWrapping, LineHeight, 0, LetterSpacing)
@ -235,9 +235,9 @@ namespace Avalonia.Controls
overlapLength, overlapLength,
new GenericTextRunProperties( new GenericTextRunProperties(
textRun.Properties?.Typeface ?? typeface, textRun.Properties?.Typeface ?? typeface,
textRun.Properties?.FontFeatures ?? FontFeatures,
FontSize, FontSize,
foregroundBrush: SelectionForegroundBrush))); foregroundBrush: SelectionForegroundBrush,
fontFeatures: textRun.Properties?.FontFeatures ?? FontFeatures)));
accumulatedLength += runLength; accumulatedLength += runLength;
} }
@ -247,8 +247,11 @@ namespace Avalonia.Controls
textStyleOverrides = textStyleOverrides =
[ [
new ValueSpan<TextRunProperties>(start, length, new ValueSpan<TextRunProperties>(start, length,
new GenericTextRunProperties(typeface, FontFeatures, FontSize, new GenericTextRunProperties(
foregroundBrush: SelectionForegroundBrush)) typeface,
FontSize,
foregroundBrush: SelectionForegroundBrush,
fontFeatures: FontFeatures))
]; ];
} }
} }

4
src/Avalonia.Controls/TextBlock.cs

@ -657,10 +657,10 @@ namespace Avalonia.Controls
var defaultProperties = new GenericTextRunProperties( var defaultProperties = new GenericTextRunProperties(
typeface, typeface,
FontFeatures,
FontSize, FontSize,
TextDecorations, TextDecorations,
Foreground); Foreground,
fontFeatures: FontFeatures);
var paragraphProperties = new GenericTextParagraphProperties(FlowDirection, IsMeasureValid ? TextAlignment : TextAlignment.Left, true, false, var paragraphProperties = new GenericTextParagraphProperties(FlowDirection, IsMeasureValid ? TextAlignment : TextAlignment.Left, true, false,
defaultProperties, TextWrapping, LineHeight, 0, LetterSpacing) defaultProperties, TextWrapping, LineHeight, 0, LetterSpacing)

Loading…
Cancel
Save