Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextAlignment renders text in wrong location for External Fonts #17510

Closed
Niaxor opened this issue Nov 14, 2024 · 4 comments
Closed

TextAlignment renders text in wrong location for External Fonts #17510

Niaxor opened this issue Nov 14, 2024 · 4 comments
Labels

Comments

@Niaxor
Copy link

Niaxor commented Nov 14, 2024

Describe the bug

Avalonia does not render open type fonts loaded as a static resource in the correct location in certain circumstances. The circumstance seems to depend on the text length, text alignment, and previewer zoom %.

For example, this center aligned text is rendering as right-aligned:

image

If I left-align it it appears as centered:

image

If I removed a single 't' from the end of the string it then renders in the correct location....?

I have tested with two fonts, both open types as static resource, both behaved inconsistently.
Using a regular system font like Arial works as intended.

To Reproduce

Ive uploaded a repro project -
fonttest.zip

  1. Build and run, and the text will appear right-aligned, when it should be centre-aligned.
  2. By modifying the text length, the text placement will vary.
  3. You may also use the previewer, and modifying the zoom percentage also seems to trigger this issue, depending on the zoom percentage.

Expected behavior

Open type fonts as a static resource are rendered in their expected location (based on layout settings).

Avalonia version

11.2

OS

Windows

Additional context

Rider 2024.1.4

@Niaxor Niaxor added the bug label Nov 14, 2024
@Niaxor Niaxor closed this as completed Nov 14, 2024
@Niaxor Niaxor reopened this Nov 15, 2024
@Niaxor
Copy link
Author

Niaxor commented Nov 15, 2024

I have modified my description of this issue and uploaded a repro project. I previously believed this was an issue with the Rider previewer but am now aware it happens at runtime too, so this must be an issue with Avalonia itself.

I do not yet have a workaround, this is rather critical because the basic building blocks of the UI is simply not rendering inconsistently.

Here is an image showing the issue occurring at runtime.

image

@Niaxor Niaxor changed the title Previewer text rendering in wrong location TextAlignment renders text in wrong location for External Fonts Nov 15, 2024
@Niaxor
Copy link
Author

Niaxor commented Nov 15, 2024

After further testing, it seems that the issue is specifically triggered by using a non-default TextAlignment property at the same time as a non-default HorizontalAlignment property only with a custom font.

The issue will still occur if HorizontalAlignment is set on a parent control, i.e. below will still trigger this issue ->

    <Grid HorizontalAlignment="Center">
        <TextBlock TextAlignment="Center" VerticalAlignment="Center" FontSize="70" Foreground="#AFC0CB" Text="Test" ClipToBounds="False" />
    </Grid>

@Gillibald
Copy link
Contributor

Fixed by: #17402

@Niaxor
Copy link
Author

Niaxor commented Nov 15, 2024

It sure is! Thanks :)

@Niaxor Niaxor closed this as completed Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants