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
26.09k stars 2.26k forks source link

Some custom fonts in TextBox do not align with the center of the caret #15768

Open kurobirds opened 6 months ago

kurobirds commented 6 months ago

Describe the bug

I have added a custom font to the TextBox, but the caret position is lower than the text. Not every font has this issue, but I am currently experiencing it with Consolas and UniversNextPro. This could be a font issue, but Word and Notepad++ don't have this problem.

To Reproduce

<TextBox Text="Default TextBox: lyg" />
<TextBox FontFamily="Consolas" Text="Consolas TextBox: lyg" />
<TextBox FontFamily="{StaticResource UniversNextProFont}" Text="UniversNextPro TextBox: lyg" />
image

Expected behavior

A custom font can align the caret in the center like the default font, or it could display as it does in Word and Notepad++.

Word with Consolas font: image

Notepad++ with Consolas font:: image

Avalonia version

11.0.10, 11.1.0-beta2

OS

Windows

Additional context

No response

rabbitism commented 6 months ago

It should be fixed in https://github.com/AvaloniaUI/Avalonia/pull/15481 but seems not.

And btw your second textbox is not consolas. Consolas is monospace font right?

Also can you also include a letter like g or y so it demostrate the lower bound of glyphs?

kurobirds commented 6 months ago

It should be fixed in #15481 but seems not.

And btw your second textbox is not consolas. Consolas is monospace font right?

Also can you also include a letter like g or y so it demostrate the lower bound of glyphs?

The second TextBox uses the UniversNextPro font. The Consolas font will display like this: image

P.S.: I updated the demonstration for more clarity.

Gillibald commented 6 months ago

The caret and glyph positions are not aligned to the pixel grid

robloo commented 6 months ago

Duplicate of #10658 I believe

timunie commented 6 months ago

@robloo not entirely sure this is an 100 % duplicate, as is about caret position, not font position in general. But could coupled, yes.

robloo commented 6 months ago

@timunie Caret position should be calculated from the font dimensions. So I expect the underlying issue is the same.

timunie commented 6 months ago

@Gillibald should decide if we want to close this in favor of #10658