uno icon indicating copy to clipboard operation
uno copied to clipboard

Text selection color is sometimes incorrect

Open MartinZikmund opened this issue 1 year ago • 1 comments

Current behavior

I have the following in my TextBox in samples app Playground:

<Grid>
 <ComboBox  xmlns:my="using:Uno.UI.RuntimeTests.Tests.ComboBoxTests" Margin="0 20 0 0">
    <ComboBox.Items>
      <ComboBoxItem Content="a" />
      <ComboBoxItem Content="b" />
      <ComboBoxItem Content="c" />
      <ComboBoxItem Content="d" />
      <ComboBoxItem Content="e" />
      <ComboBoxItem Content="f" />
      <ComboBoxItem Content="g" />
      <ComboBoxItem Content="h" />
      <ComboBoxItem Content="i" />
      <ComboBoxItem Content="j" />
      <ComboBoxItem Content="k" />
      <ComboBoxItem Content="l" />
    </ComboBox.Items>
  </ComboBox>
  </Grid>

With various selections, colors happen incorrectly:

image

image

Here I started the selection from cursor position just after the \ to the left, which made the > disappear

image

Expected behavior

No response

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

No response

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

MartinZikmund avatar Feb 19 '24 11:02 MartinZikmund

This is a ligature problem. Cascadia Code (which is the font used in the playground sample) contains ligatures, so the text rendering engine is treating /> as one character, which / being the one in control, i.e. if / is selected, then /> color is wholly changed to white, hence the disappearing > effect. If only > is selected, it's as if neither is selected, so > remains black. There doesn't seem to be anything we can do here. SkiaSharp and HarfBuffSharp doesn't seem to support configuring ligatures,

ramezgerges avatar Feb 19 '24 17:02 ramezgerges

I just saw SixLabors.Fonts - could this benefit us in any way (as alternative to Harfbuzz maybe?)

MartinZikmund avatar Feb 25 '24 12:02 MartinZikmund

I don't think so. Skia internally uses HarfBuzz. So the problem is mostly within skia, not with our harfbuzz logic.

Edit: unless you mean not rendering text with skia altogher and using this other package for rendering fonts and then drawing them on the skia canvas as simple bitmaps. That option would be interesting, but probably too big of a change just to support ligatures.

ramezgerges avatar Feb 25 '24 13:02 ramezgerges

I was wrong about this. We can disable ligatures with HarfBuzz and that will provide us with non-ligatured glyphs that can then be used with SKTextBlobs. Obviouslly, it would be better to have full ligature support, but we can settle for at least not breaking on fonts with ligatures.

ramezgerges avatar May 26 '24 21:05 ramezgerges