Simplify text formatting constructors (#20527)

* Remove the flowDirection parameter from TextCollapsingProperties.CreateCollapsedRuns

* Simplify text formatting constructors

* Update API suppressions
This commit is contained in:
Julien Lebosquain
2026-01-30 09:55:24 +00:00
committed by GitHub
parent 5361b98ce1
commit 3394815603
15 changed files with 184 additions and 133 deletions
+84
View File
@@ -151,6 +151,48 @@
<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,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>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Platform.IDrawingContextImplWithEffects.PushEffect(Avalonia.Media.IEffect)</Target>
@@ -463,6 +505,48 @@
<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,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>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Platform.IDrawingContextImplWithEffects.PushEffect(Avalonia.Media.IEffect)</Target>
@@ -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
+18 -19
View File
@@ -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
@@ -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
/// </summary>
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;
@@ -26,16 +26,14 @@
/// <param name="textLine">Text line to collapse.</param>
public abstract TextRun[]? Collapse(TextLine textLine);
// TODO12: Remove the flowDirection parameter
/// <summary>
/// Creates a list of runs for given collapsed length which includes specified symbol at the end.
/// </summary>
/// <param name="textLine">The text line.</param>
/// <param name="collapsedLength">The collapsed length.</param>
/// <param name="flowDirection">The flow direction.</param>
/// <param name="shapedSymbol">The symbol.</param>
/// <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)
{
@@ -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;
@@ -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);
@@ -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);
@@ -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
/// <summary>
/// Initializes a new instance of the <see cref="TextLayout" /> class.
/// </summary>
@@ -35,54 +34,13 @@ namespace Avalonia.Media.TextFormatting
/// <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>
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="textStyleOverrides">The text style overrides.</param>
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<ValueSpan<TextRunProperties>>? 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);
@@ -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);
}
}
}
@@ -8,27 +8,14 @@ namespace Avalonia.Media.TextFormatting
/// </summary>
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<FontFeature>? fontFeatures,
double fontRenderingEmSize = 12,
double fontRenderingEmSize = GenericTextRunProperties.DefaultFontRenderingEmSize,
sbyte bidiLevel = 0,
CultureInfo? culture = null,
double incrementalTabWidth = 0,
double letterSpacing = 0)
double letterSpacing = 0,
IReadOnlyList<FontFeature>? fontFeatures = null)
{
GlyphTypeface = typeface;
FontRenderingEmSize = fontRenderingEmSize;
+4 -3
View File
@@ -81,12 +81,13 @@ namespace Avalonia.Controls.Documents
return new GenericTextRunProperties(
typeface,
FontFeatures,
FontSize,
TextDecorations,
TextDecorations,
Foreground,
parentOrSelfBackground,
BaselineAlignment);
BaselineAlignment,
null,
FontFeatures);
}
/// <summary>
@@ -346,13 +346,26 @@ namespace Avalonia.Controls.Presenters
private TextLayout CreateTextLayoutInternal(Size constraint, string? text, Typeface typeface,
IReadOnlyList<ValueSpan<TextRunProperties>>? 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<TextRunProperties>(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<TextRunProperties>(start, length,
new GenericTextRunProperties(typeface, FontFeatures, FontSize,
foregroundBrush: SelectionForegroundBrush))
new GenericTextRunProperties(
typeface,
FontSize,
foregroundBrush: SelectionForegroundBrush,
fontFeatures: FontFeatures))
};
}
}
+9 -6
View File
@@ -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<TextRunProperties>(start, length,
new GenericTextRunProperties(typeface, FontFeatures, FontSize,
foregroundBrush: SelectionForegroundBrush))
new GenericTextRunProperties(
typeface,
FontSize,
foregroundBrush: SelectionForegroundBrush,
fontFeatures: FontFeatures))
];
}
}
+2 -2
View File
@@ -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)