From 33948156031334ac0c40c24dc8920a9e36ce4063 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Fri, 30 Jan 2026 09:55:24 +0000 Subject: [PATCH] Simplify text formatting constructors (#20527) * Remove the flowDirection parameter from TextCollapsingProperties.CreateCollapsedRuns * Simplify text formatting constructors * Update API suppressions --- api/Avalonia.nupkg.xml | 84 +++++++++++++++++++ samples/TextTestApp/InteractiveLineControl.cs | 7 +- src/Avalonia.Base/Media/FormattedText.cs | 37 ++++---- .../GenericTextRunProperties.cs | 23 ++--- .../TextCollapsingProperties.cs | 4 +- .../TextFormatting/TextEllipsisHelper.cs | 4 +- .../Media/TextFormatting/TextFormatter.cs | 4 +- .../Media/TextFormatting/TextFormatterImpl.cs | 10 ++- .../Media/TextFormatting/TextLayout.cs | 51 ++--------- .../Media/TextFormatting/TextRunProperties.cs | 11 ++- .../Media/TextFormatting/TextShaperOptions.cs | 19 +---- src/Avalonia.Controls/Documents/Inline.cs | 7 +- .../Presenters/TextPresenter.cs | 37 ++++++-- src/Avalonia.Controls/SelectableTextBlock.cs | 15 ++-- src/Avalonia.Controls/TextBlock.cs | 4 +- 15 files changed, 184 insertions(+), 133 deletions(-) diff --git a/api/Avalonia.nupkg.xml b/api/Avalonia.nupkg.xml index f8b5337574..4319e8343e 100644 --- a/api/Avalonia.nupkg.xml +++ b/api/Avalonia.nupkg.xml @@ -151,6 +151,48 @@ baseline/Avalonia/lib/net10.0/Avalonia.Base.dll current/Avalonia/lib/net10.0/Avalonia.Base.dll + + CP0002 + 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) + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + + + CP0002 + 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) + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + + + CP0002 + M:Avalonia.Media.TextFormatting.TextCollapsingProperties.CreateCollapsedRuns(Avalonia.Media.TextFormatting.TextLine,System.Int32,Avalonia.Media.FlowDirection,Avalonia.Media.TextFormatting.TextRun) + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + + + CP0002 + 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}}) + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + + + CP0002 + 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}}) + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + + + CP0002 + 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) + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + + + CP0002 + M:Avalonia.Media.TextFormatting.TextShaperOptions.#ctor(Avalonia.Media.GlyphTypeface,System.Double,System.SByte,System.Globalization.CultureInfo,System.Double,System.Double) + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + CP0002 M:Avalonia.Platform.IDrawingContextImplWithEffects.PushEffect(Avalonia.Media.IEffect) @@ -463,6 +505,48 @@ baseline/Avalonia/lib/net8.0/Avalonia.Base.dll current/Avalonia/lib/net8.0/Avalonia.Base.dll + + CP0002 + 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) + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + + + CP0002 + 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) + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + + + CP0002 + M:Avalonia.Media.TextFormatting.TextCollapsingProperties.CreateCollapsedRuns(Avalonia.Media.TextFormatting.TextLine,System.Int32,Avalonia.Media.FlowDirection,Avalonia.Media.TextFormatting.TextRun) + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + + + CP0002 + 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}}) + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + + + CP0002 + 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}}) + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + + + CP0002 + 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) + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + + + CP0002 + M:Avalonia.Media.TextFormatting.TextShaperOptions.#ctor(Avalonia.Media.GlyphTypeface,System.Double,System.SByte,System.Globalization.CultureInfo,System.Double,System.Double) + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + CP0002 M:Avalonia.Platform.IDrawingContextImplWithEffects.PushEffect(Avalonia.Media.IEffect) diff --git a/samples/TextTestApp/InteractiveLineControl.cs b/samples/TextTestApp/InteractiveLineControl.cs index 7af977f9a1..e1bc171952 100644 --- a/samples/TextTestApp/InteractiveLineControl.cs +++ b/samples/TextTestApp/InteractiveLineControl.cs @@ -255,12 +255,15 @@ namespace TextTestApp private GenericTextRunProperties CreateTextRunProperties() { Typeface typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); - return new GenericTextRunProperties(typeface, FontFeatures, FontSize, + return new GenericTextRunProperties( + typeface, + FontSize, textDecorations: null, foregroundBrush: Brushes.Black, backgroundBrush: null, baselineAlignment: BaselineAlignment.Baseline, - cultureInfo: null); + cultureInfo: null, + fontFeatures: FontFeatures); } // TextParagraphProperties diff --git a/src/Avalonia.Base/Media/FormattedText.cs b/src/Avalonia.Base/Media/FormattedText.cs index c285ce2f51..5000acb2c5 100644 --- a/src/Avalonia.Base/Media/FormattedText.cs +++ b/src/Avalonia.Base/Media/FormattedText.cs @@ -184,13 +184,13 @@ namespace Avalonia.Media var newProps = new GenericTextRunProperties( runProps.Typeface, - runProps.FontFeatures, runProps.FontRenderingEmSize, runProps.TextDecorations, foregroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, - runProps.CultureInfo + runProps.CultureInfo, + runProps.FontFeatures ); #pragma warning restore 6506 @@ -240,13 +240,13 @@ namespace Avalonia.Media var newProps = new GenericTextRunProperties( runProps.Typeface, - fontFeatures, runProps.FontRenderingEmSize, runProps.TextDecorations, runProps.ForegroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, - runProps.CultureInfo + runProps.CultureInfo, + fontFeatures ); #pragma warning restore 6506 @@ -328,14 +328,13 @@ namespace Avalonia.Media var newProps = new GenericTextRunProperties( new Typeface(fontFamily, oldTypeface.Style, oldTypeface.Weight), - runProps.FontFeatures, runProps.FontRenderingEmSize, runProps.TextDecorations, runProps.ForegroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, - runProps.CultureInfo - ); + runProps.CultureInfo, + runProps.FontFeatures); #pragma warning restore 6506 _latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition, @@ -388,13 +387,13 @@ namespace Avalonia.Media var newProps = new GenericTextRunProperties( runProps.Typeface, - runProps.FontFeatures, emSize, runProps.TextDecorations, runProps.ForegroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, - runProps.CultureInfo + runProps.CultureInfo, + runProps.FontFeatures ); _latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition, @@ -451,13 +450,13 @@ namespace Avalonia.Media var newProps = new GenericTextRunProperties( runProps.Typeface, - runProps.FontFeatures, runProps.FontRenderingEmSize, runProps.TextDecorations, runProps.ForegroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, - culture + culture, + runProps.FontFeatures ); #pragma warning restore 6506 @@ -511,13 +510,13 @@ namespace Avalonia.Media var newProps = new GenericTextRunProperties( new Typeface(oldTypeface.FontFamily, oldTypeface.Style, weight), - runProps.FontFeatures, runProps.FontRenderingEmSize, runProps.TextDecorations, runProps.ForegroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, - runProps.CultureInfo + runProps.CultureInfo, + runProps.FontFeatures ); #pragma warning restore 6506 _latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition, newProps, formatRider.SpanPosition); @@ -568,13 +567,13 @@ namespace Avalonia.Media var newProps = new GenericTextRunProperties( new Typeface(oldTypeface.FontFamily, style, oldTypeface.Weight), - runProps.FontFeatures, runProps.FontRenderingEmSize, runProps.TextDecorations, runProps.ForegroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, - runProps.CultureInfo + runProps.CultureInfo, + runProps.FontFeatures ); #pragma warning restore 6506 @@ -625,13 +624,13 @@ namespace Avalonia.Media var newProps = new GenericTextRunProperties( typeface, - runProps.FontFeatures, runProps.FontRenderingEmSize, runProps.TextDecorations, runProps.ForegroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, - runProps.CultureInfo + runProps.CultureInfo, + runProps.FontFeatures ); #pragma warning restore 6506 @@ -683,13 +682,13 @@ namespace Avalonia.Media var newProps = new GenericTextRunProperties( runProps.Typeface, - runProps.FontFeatures, runProps.FontRenderingEmSize, textDecorations, runProps.ForegroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, - runProps.CultureInfo + runProps.CultureInfo, + runProps.FontFeatures ); #pragma warning restore 6506 diff --git a/src/Avalonia.Base/Media/TextFormatting/GenericTextRunProperties.cs b/src/Avalonia.Base/Media/TextFormatting/GenericTextRunProperties.cs index 0a8ab72a25..a747854e3b 100644 --- a/src/Avalonia.Base/Media/TextFormatting/GenericTextRunProperties.cs +++ b/src/Avalonia.Base/Media/TextFormatting/GenericTextRunProperties.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Globalization; +using System.Globalization; namespace Avalonia.Media.TextFormatting { @@ -9,28 +7,17 @@ namespace Avalonia.Media.TextFormatting /// 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( - Typeface typeface, - FontFeatureCollection? fontFeatures, + Typeface typeface, double fontRenderingEmSize = DefaultFontRenderingEmSize, TextDecorationCollection? textDecorations = null, IBrush? foregroundBrush = null, IBrush? backgroundBrush = null, BaselineAlignment baselineAlignment = BaselineAlignment.Baseline, - CultureInfo? cultureInfo = null) + CultureInfo? cultureInfo = null, + FontFeatureCollection? fontFeatures = null) { Typeface = typeface; FontRenderingEmSize = fontRenderingEmSize; diff --git a/src/Avalonia.Base/Media/TextFormatting/TextCollapsingProperties.cs b/src/Avalonia.Base/Media/TextFormatting/TextCollapsingProperties.cs index dcee8cea46..b621dada54 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextCollapsingProperties.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextCollapsingProperties.cs @@ -26,16 +26,14 @@ /// Text line to collapse. public abstract TextRun[]? Collapse(TextLine textLine); - // TODO12: Remove the flowDirection parameter /// /// Creates a list of runs for given collapsed length which includes specified symbol at the end. /// /// The text line. /// The collapsed length. - /// The flow direction. /// The symbol. /// List of remaining runs. - 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) { diff --git a/src/Avalonia.Base/Media/TextFormatting/TextEllipsisHelper.cs b/src/Avalonia.Base/Media/TextFormatting/TextEllipsisHelper.cs index 426388f295..685bb08f27 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextEllipsisHelper.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextEllipsisHelper.cs @@ -71,7 +71,7 @@ namespace Avalonia.Media.TextFormatting collapsedLength += measuredLength; - return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, properties.FlowDirection, shapedSymbol); + return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, shapedSymbol); } availableWidth -= textRunWidth; @@ -84,7 +84,7 @@ namespace Avalonia.Media.TextFormatting //The whole run needs to fit into available space if (drawableRun.Size.Width > availableWidth) { - return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, properties.FlowDirection, shapedSymbol); + return TextCollapsingProperties.CreateCollapsedRuns(textLine, collapsedLength, shapedSymbol); } availableWidth -= drawableRun.Size.Width; diff --git a/src/Avalonia.Base/Media/TextFormatting/TextFormatter.cs b/src/Avalonia.Base/Media/TextFormatting/TextFormatter.cs index 1dbf55fb97..ed60dd44a0 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextFormatter.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextFormatter.cs @@ -59,8 +59,8 @@ var cultureInfo = textRun.Properties.CultureInfo; - var shaperOptions = new TextShaperOptions(glyphTypeface, textRun.Properties.FontFeatures, - fontRenderingEmSize, (sbyte)flowDirection, cultureInfo); + var shaperOptions = new TextShaperOptions(glyphTypeface, fontRenderingEmSize, + (sbyte)flowDirection, cultureInfo, 0, 0, textRun.Properties.FontFeatures); var shapedBuffer = textShaper.ShapeText(textRun.Text, shaperOptions); diff --git a/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs b/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs index 605804a82d..4428dff0f1 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs @@ -290,9 +290,13 @@ namespace Avalonia.Media.TextFormatting } var shaperOptions = new TextShaperOptions( - properties.CachedGlyphTypeface, properties.FontFeatures, - properties.FontRenderingEmSize, shapeableRun.BidiLevel, properties.CultureInfo, - paragraphProperties.DefaultIncrementalTab, paragraphProperties.LetterSpacing); + properties.CachedGlyphTypeface, + properties.FontRenderingEmSize, + shapeableRun.BidiLevel, + properties.CultureInfo, + paragraphProperties.DefaultIncrementalTab, + paragraphProperties.LetterSpacing, + properties.FontFeatures); ShapeTogether(groupedRuns, text, shaperOptions, textShaper, shapedRuns); diff --git a/src/Avalonia.Base/Media/TextFormatting/TextLayout.cs b/src/Avalonia.Base/Media/TextFormatting/TextLayout.cs index 3a578fb72d..24e9019084 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextLayout.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextLayout.cs @@ -17,7 +17,6 @@ namespace Avalonia.Media.TextFormatting private int _textSourceLength; - // TODO12: Remove in 12.0.0 and make fontFeatures parameter in main ctor optional /// /// Initializes a new instance of the class. /// @@ -35,54 +34,13 @@ namespace Avalonia.Media.TextFormatting /// The height of each line of text. /// The letter spacing that is applied to rendered glyphs. /// The maximum number of text lines. - /// The text style overrides. - 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>? 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 - /// - /// Initializes a new instance of the class. - /// - /// The text. - /// The typeface. - /// Size of the font. - /// The foreground. - /// The text alignment. - /// The text wrapping. - /// The text trimming. - /// The text decorations. - /// The text flow direction. - /// The maximum width. - /// The maximum height. - /// The height of each line of text. - /// The letter spacing that is applied to rendered glyphs. - /// The maximum number of text lines. - /// The text style overrides. /// Optional list of turned on/off features. + /// The text style overrides. public TextLayout( string? text, Typeface typeface, - FontFeatureCollection? fontFeatures, - double fontSize, - IBrush? foreground, + double fontSize = GenericTextRunProperties.DefaultFontRenderingEmSize, + IBrush? foreground = null, TextAlignment textAlignment = TextAlignment.Left, TextWrapping textWrapping = TextWrapping.NoWrap, TextTrimming? textTrimming = null, @@ -93,6 +51,7 @@ namespace Avalonia.Media.TextFormatting double lineHeight = double.NaN, double letterSpacing = 0, int maxLines = 0, + FontFeatureCollection? fontFeatures = null, IReadOnlyList>? textStyleOverrides = null) { _paragraphProperties = @@ -534,7 +493,7 @@ namespace Avalonia.Media.TextFormatting TextDecorationCollection? textDecorations, FlowDirection flowDirection, double lineHeight, 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, textRunStyle, textWrapping, lineHeight, 0, letterSpacing); diff --git a/src/Avalonia.Base/Media/TextFormatting/TextRunProperties.cs b/src/Avalonia.Base/Media/TextFormatting/TextRunProperties.cs index cf2f74ee4d..ac4cf4855d 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextRunProperties.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextRunProperties.cs @@ -107,8 +107,15 @@ namespace Avalonia.Media.TextFormatting if (this is GenericTextRunProperties other && other.Typeface == typeface) return this; - return new GenericTextRunProperties(typeface, FontFeatures, FontRenderingEmSize, - TextDecorations, ForegroundBrush, BackgroundBrush, BaselineAlignment); + return new GenericTextRunProperties( + typeface, + FontRenderingEmSize, + TextDecorations, + ForegroundBrush, + BackgroundBrush, + BaselineAlignment, + CultureInfo, + FontFeatures); } } } diff --git a/src/Avalonia.Base/Media/TextFormatting/TextShaperOptions.cs b/src/Avalonia.Base/Media/TextFormatting/TextShaperOptions.cs index 9ae20a3eaa..f19ce2ee5d 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextShaperOptions.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextShaperOptions.cs @@ -8,27 +8,14 @@ namespace Avalonia.Media.TextFormatting /// public readonly record struct TextShaperOptions { - // TODO12: Remove in 12.0.0 and make fontFeatures parameter in main ctor optional - public TextShaperOptions( - GlyphTypeface typeface, - double fontRenderingEmSize = 12, - sbyte bidiLevel = 0, - CultureInfo? culture = null, - double incrementalTabWidth = 0, - double letterSpacing = 0) - : this(typeface, null, fontRenderingEmSize, bidiLevel, culture, incrementalTabWidth, letterSpacing) - { - } - - // TODO12:Change signature in 12.0.0 public TextShaperOptions( GlyphTypeface typeface, - IReadOnlyList? fontFeatures, - double fontRenderingEmSize = 12, + double fontRenderingEmSize = GenericTextRunProperties.DefaultFontRenderingEmSize, sbyte bidiLevel = 0, CultureInfo? culture = null, double incrementalTabWidth = 0, - double letterSpacing = 0) + double letterSpacing = 0, + IReadOnlyList? fontFeatures = null) { GlyphTypeface = typeface; FontRenderingEmSize = fontRenderingEmSize; diff --git a/src/Avalonia.Controls/Documents/Inline.cs b/src/Avalonia.Controls/Documents/Inline.cs index fe526e9204..4338dc6d53 100644 --- a/src/Avalonia.Controls/Documents/Inline.cs +++ b/src/Avalonia.Controls/Documents/Inline.cs @@ -81,12 +81,13 @@ namespace Avalonia.Controls.Documents return new GenericTextRunProperties( typeface, - FontFeatures, FontSize, - TextDecorations, + TextDecorations, Foreground, parentOrSelfBackground, - BaselineAlignment); + BaselineAlignment, + null, + FontFeatures); } /// diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index 7078650da4..05c74b39e5 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -346,13 +346,26 @@ namespace Avalonia.Controls.Presenters private TextLayout CreateTextLayoutInternal(Size constraint, string? text, Typeface typeface, IReadOnlyList>? textStyleOverrides) { - var foreground = Foreground; var maxWidth = MathUtilities.IsZero(constraint.Width) ? double.PositiveInfinity : constraint.Width; var maxHeight = MathUtilities.IsZero(constraint.Height) ? double.PositiveInfinity : constraint.Height; - var textLayout = new TextLayout(text, typeface, FontFeatures, FontSize, foreground, TextAlignment, - TextWrapping, maxWidth: maxWidth, maxHeight: maxHeight, textStyleOverrides: textStyleOverrides, - flowDirection: FlowDirection, lineHeight: LineHeight, letterSpacing: LetterSpacing); + var textLayout = new TextLayout( + text, + typeface, + FontSize, + Foreground, + TextAlignment, + TextWrapping, + null, + null, + FlowDirection, + maxWidth, + maxHeight, + LineHeight, + LetterSpacing, + 0, + FontFeatures, + textStyleOverrides); return textLayout; } @@ -553,9 +566,12 @@ namespace Avalonia.Controls.Presenters if (!string.IsNullOrEmpty(preeditText)) { var preeditHighlight = new ValueSpan(caretIndex, preeditText.Length, - new GenericTextRunProperties(typeface, FontFeatures, FontSize, - foregroundBrush: foreground, - textDecorations: TextDecorations.Underline)); + new GenericTextRunProperties( + typeface, + FontSize, + TextDecorations.Underline, + foreground, + fontFeatures: FontFeatures)); textStyleOverrides = new[] { @@ -569,8 +585,11 @@ namespace Avalonia.Controls.Presenters textStyleOverrides = new[] { new ValueSpan(start, length, - new GenericTextRunProperties(typeface, FontFeatures, FontSize, - foregroundBrush: SelectionForegroundBrush)) + new GenericTextRunProperties( + typeface, + FontSize, + foregroundBrush: SelectionForegroundBrush, + fontFeatures: FontFeatures)) }; } } diff --git a/src/Avalonia.Controls/SelectableTextBlock.cs b/src/Avalonia.Controls/SelectableTextBlock.cs index 55321655cc..f3532763f6 100644 --- a/src/Avalonia.Controls/SelectableTextBlock.cs +++ b/src/Avalonia.Controls/SelectableTextBlock.cs @@ -186,10 +186,10 @@ namespace Avalonia.Controls var defaultProperties = new GenericTextRunProperties( typeface, - FontFeatures, FontSize, TextDecorations, - Foreground); + Foreground, + fontFeatures: FontFeatures); var paragraphProperties = new GenericTextParagraphProperties(FlowDirection, TextAlignment, true, false, defaultProperties, TextWrapping, LineHeight, 0, LetterSpacing) @@ -235,9 +235,9 @@ namespace Avalonia.Controls overlapLength, new GenericTextRunProperties( textRun.Properties?.Typeface ?? typeface, - textRun.Properties?.FontFeatures ?? FontFeatures, FontSize, - foregroundBrush: SelectionForegroundBrush))); + foregroundBrush: SelectionForegroundBrush, + fontFeatures: textRun.Properties?.FontFeatures ?? FontFeatures))); accumulatedLength += runLength; } @@ -247,8 +247,11 @@ namespace Avalonia.Controls textStyleOverrides = [ new ValueSpan(start, length, - new GenericTextRunProperties(typeface, FontFeatures, FontSize, - foregroundBrush: SelectionForegroundBrush)) + new GenericTextRunProperties( + typeface, + FontSize, + foregroundBrush: SelectionForegroundBrush, + fontFeatures: FontFeatures)) ]; } } diff --git a/src/Avalonia.Controls/TextBlock.cs b/src/Avalonia.Controls/TextBlock.cs index 55cbae773c..c70d06ae7f 100644 --- a/src/Avalonia.Controls/TextBlock.cs +++ b/src/Avalonia.Controls/TextBlock.cs @@ -657,10 +657,10 @@ namespace Avalonia.Controls var defaultProperties = new GenericTextRunProperties( typeface, - FontFeatures, FontSize, TextDecorations, - Foreground); + Foreground, + fontFeatures: FontFeatures); var paragraphProperties = new GenericTextParagraphProperties(FlowDirection, IsMeasureValid ? TextAlignment : TextAlignment.Left, true, false, defaultProperties, TextWrapping, LineHeight, 0, LetterSpacing)