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

Fix issue 4427 - System.InvalidOperationException: Default font family name can't be null or empty #12817

Merged
merged 6 commits into from
Sep 14, 2023
Merged

Conversation

mihnea-radulescu
Copy link
Contributor

Fix issue 4427 - System.InvalidOperationException: Default font family name can't be null or empty

Link to issue 4427

What does the pull request do?

Fixes the exception System.InvalidOperationException: Default font family name can't be null or empty occurring on some GNU / Linux operating systems, in particular Arch Linux and variants, through falling back to the first registered system font family, in the absence of a default font family name.

What is the current behavior?

On some GNU / Linux operating systems, in particular Arch Linux and variants, the FontManager constructor throws a System.InvalidOperationException when a defaultFontFamilyName is neither provided through the FontManagerOptions instance, nor can it be resolved using PlatformImpl.GetDefaultFontFamilyName().

What is the updated/expected behavior with this PR?

The PR fixes the issue by falling back to the first registered system font family, in the absence of a provided or resolved default font family name.

Checklist

  • Added new and updated existing unit tests

Fixed issues

Fixes #4427

@mihnea-radulescu
Copy link
Contributor Author

@dotnet-policy-service agree

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0039277-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@grokys
Copy link
Member

grokys commented Sep 13, 2023

Pinging @Gillibald

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0039434-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0039497-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@Gillibald
Copy link
Contributor

Can we avoid using Linq to select the first font and instead just use the indexer with a bounds check?

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0039540-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@mihnea-radulescu
Copy link
Contributor Author

Thank you for the feedback, @Gillibald!

The PR has been updated accordingly.

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0039544-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@grokys grokys added this pull request to the merge queue Sep 14, 2023
Merged via the queue into AvaloniaUI:master with commit 7b67fda Sep 14, 2023
6 checks passed
@nopara73
Copy link
Contributor

Congrats @mihnea-radulescu, you've earned the 0.03 BTC bounty I created some years ago for resolving #4427 🚀

Please send me a Bitcoin address to adam.ficsor73@gmail.com. If you don't yet have a Bitcoin wallet, then a natural choice would be Wasabi Wallet, which is also written with Avalonia.

@kekekeks
Copy link
Member

kekekeks commented Sep 15, 2023

Not sure why it got merged, but it's incorrect behavior. The first found font could be some symbol font or a font without any characters even for latin scripts.

e. g. on my machine the first font is /usr/share/fonts/truetype/noto/NotoSansTelugu-CondensedThin.ttf and it looks like this in FontForge:
image

We need to P/Invoke libfontconfig instead.

@mihnea-radulescu mihnea-radulescu deleted the fix/issue-4427 branch September 15, 2023 16:29
@maxkatz6 maxkatz6 added the backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch label Dec 7, 2023
@maxkatz6 maxkatz6 added backported-11.0.x and removed backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch labels Jan 17, 2024
maxkatz6 pushed a commit that referenced this pull request Jan 17, 2024
…y name can't be null or empty (#12817)

* Fix issue 4427 - System.InvalidOperationException: Default font family name can't be null or empty

* Updated FontManager

* Removed Linq usage from FontManager

---------

Co-authored-by: Mihnea Rădulescu <>
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
#Conflicts:
#	src/Avalonia.Base/Media/FontManager.cs
Jeric-X added a commit to Jeric-X/SyncClipboard that referenced this pull request Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.InvalidOperationException: Default font family name can't be null or empty
7 participants