AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
24.63k stars 2.13k forks source link

TextBlock inline spacing & BaselineAlignment #14263

Open mrj001 opened 5 months ago

mrj001 commented 5 months ago

Describe the bug

There does not seem to be any way to control the spacing of Inline elements within a TextBlock. This may be due to lack of documentation, but I did not find any likely properties while reviewing the source of Run, Inline and TextElement.

Additionally, the subscript shares a common baseline with the rest of the text.

To Reproduce

I created a new project with "dotnet new avalonia.app". I updated the version of Avalonia to 11.0.7 as my templates created 11.0.6. This is my MainWindow.axaml:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="250"
        Width="400" Height="225"
        x:Class="RichText.MainWindow"
        Title="RichText">
  <StackPanel>
    <TextBlock>
      <TextBlock.Inlines>
        <Run Text="Welcome" />
        <Run Text="to" />
        <Run Text="Avalonia!" Foreground="Red" FontWeight="Bold" />
      </TextBlock.Inlines>
    </TextBlock>
    <TextBlock>
      <TextBlock.Inlines>
        <Run Text="H" />
        <Run Text="2" BaselineAlignment="Subscript" FontSize="8" />
        <Run Text="O" />
      </TextBlock.Inlines>
    </TextBlock>
  </StackPanel>
</Window>

Expected behavior

There ought to be some means of controlling the spacing between inline elements.

Screenshots

This is what is shown as the app window. The first line has spacing, which is good. However, the second line also has the same spacing, which is undesirable. I can find no means of controlling this. Window-Actual

This is what I expected for the second line (ignore any font differences). Note the baseline of the subscript is below the baseline of the rest of the text. H20-Expected

Environment

Additional context

Here is the version information for my dotnet:

.NET SDK: Version: 8.0.101 Commit: 6eceda187b Workload version: 8.0.100-manifests.69afb982

Runtime Environment: OS Name: debian OS Version: 12 OS Platform: Linux RID: linux-arm64 Base Path: /home/mj/dotnet/sdk/8.0.101/

.NET workloads installed: Workload version: 8.0.100-manifests.69afb982 There are no installed workloads to display.

Host: Version: 8.0.1 Architecture: arm64 Commit: bf5e279d92

.NET SDKs installed: 7.0.401 [/home/mj/dotnet/sdk] 8.0.101 [/home/mj/dotnet/sdk]

mrj001 commented 5 months ago

Additionally, the Superscript and TextTop values have no effect: Baselines-Actual

Gillibald commented 5 months ago

Y BaselineAlignment is currently not fully implemented

https://github.com/AvaloniaUI/Avalonia/blob/c3911177956897d7a5176f9d59932b308aebc0c9/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs#L113