Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

[11.0.0] TextWrapping behavior of TextBlock and TextBox in different languages

Open yumikou opened this issue 1 year ago • 3 comments

Describe the bug In Avalonia, string of text after the space appears to be treated as a single word, When there is not enough space after a space to display a word, it will start a new line. But in Chinese, It does not require line breaks. I don't know the grammar of other languages and may also need to pay attention to it. It displays correctly in the wpf.

TextTest

To Reproduce Testing xaml code:

<Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto"></ColumnDefinition>
      <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <Label Content="English-TextBlock: "></Label>
    <TextBlock Grid.Column="1" TextWrapping="Wrap" Text="aaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc" HorizontalAlignment="Left" ></TextBlock>
    <Label Grid.Row="1" Content="English-TextBox: "></Label>
    <TextBox Grid.Row="1" Grid.Column="1" TextWrapping="Wrap" Text="aaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc" HorizontalAlignment="Left" ></TextBox>
    <Label Grid.Row="2" Content="Chinese-TextBlock: "></Label>
    <TextBlock Grid.Row="2" Grid.Column="1" TextWrapping="Wrap" Text="啊啊啊啊啊啊啊啊啊啊啊啊啊啊 喔喔喔喔喔喔喔喔喔喔喔喔喔喔喔 额额额额额额额额额额额额额" HorizontalAlignment="Left" ></TextBlock>
    <Label Grid.Row="3" Content="Chinese-TextBox: "></Label>
    <TextBox Grid.Row="3" Grid.Column="1" TextWrapping="Wrap" Text="啊啊啊啊啊啊啊啊啊啊啊啊啊啊 喔喔喔喔喔喔喔喔喔喔喔喔喔喔喔 额额额额额额额额额额额额额" HorizontalAlignment="Left" ></TextBox>
  </Grid>

Expected behavior Consistent with wpf.

Desktop:

  • OS: Windows 10
  • Version: 11.0.0

yumikou avatar Jul 09 '23 12:07 yumikou

So just to clarify, in Chinese the linebreak is allowed after any char?

timunie avatar Jul 09 '23 12:07 timunie

So just to clarify, in Chinese the linebreak is allowed after any char?

This is a complicated topic and I believe it's not something UI framework could handle. Cjk text composing is very complicated, usually its easy because theoretically words can be broken by line breaks, but there are so many exceptions, especially when line breaks interacting with punctuations, or the text is a mixture of cjk characters, latin characters and numbers. Adobe indesign even has a bunch of settings to adjust the composing rules.

rabbitism avatar Jul 09 '23 12:07 rabbitism

We are using the unicode text segmentation algorithm for text wrapping. Text wrapping can happen at any possible break position.

Gillibald avatar Jul 09 '23 12:07 Gillibald