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

[BUG] Linux font family error #153

Closed
RyanHir opened this issue Jan 6, 2021 · 9 comments
Closed

[BUG] Linux font family error #153

RyanHir opened this issue Jan 6, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@RyanHir
Copy link

RyanHir commented Jan 6, 2021

Program will only work if the base MS fonts are installed and will crash if not included on system.

  • Work Around:

    • Arch: install ttf-ms-fonts from the AUR.
    • Debian/Ubuntu: install ttf-mscorefonts-installer from the repos
  • Crash Log

Unhandled exception. System.InvalidOperationException: Default font family name can't be null or empty.
   at Avalonia.Media.FontManager..ctor(IFontManagerImpl platformImpl)
   at Avalonia.Media.FontManager.get_Current()
   at Avalonia.Media.TextFormatting.TextCharacters.TryGetRunProperties(ReadOnlySlice`1 text, Typeface typeface, Typeface defaultTypeface, Int32& count)
   at Avalonia.Media.TextFormatting.TextCharacters.CreateShapeableRun(ReadOnlySlice`1 text, TextRunProperties defaultProperties)
   at Avalonia.Media.TextFormatting.TextCharacters.GetShapeableCharacters()
   at Avalonia.Media.TextFormatting.TextFormatterImpl.FetchTextRuns(ITextSource textSource, Int32 firstTextSourceIndex, TextLineBreak previousLineBreak, TextLineBreak& nextLineBreak)
   at Avalonia.Media.TextFormatting.TextFormatterImpl.FormatLine(ITextSource textSource, Int32 firstTextSourceIndex, Double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak)
   at Avalonia.Media.TextFormatting.TextLayout.UpdateLayout()
   at Avalonia.Media.TextFormatting.TextLayout..ctor(String text, Typeface typeface, Double fontSize, IBrush foreground, TextAlignment textAlignment, TextWrapping textWrapping, TextTrimming textTrimming, TextDecorationCollection textDecorations, Double maxWidth, Double maxHeight, Double lineHeight, Int32 maxLines, IReadOnlyList`1 textStyleOverrides)
   at Avalonia.Controls.TextBlock.CreateTextLayout(Size constraint, String text)
   at Avalonia.Controls.TextBlock.get_TextLayout()
   at Avalonia.Controls.TextBlock.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.LayoutHelper.MeasureChild(ILayoutable control, Size availableSize, Thickness padding)
   at Avalonia.Layout.LayoutHelper.MeasureChild(ILayoutable control, Size availableSize, Thickness padding, Thickness borderThickness)
   at Avalonia.Controls.Presenters.ContentPresenter.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.LayoutManager.Measure(ILayoutable control)
   at Avalonia.Layout.LayoutManager.ExecuteMeasurePass()
   at Avalonia.Layout.LayoutManager.InnerLayoutPass()
   at Avalonia.Layout.LayoutManager.ExecuteLayoutPass()
   at Avalonia.Threading.JobRunner.Job.Avalonia.Threading.JobRunner.IJob.Run()
   at Avalonia.Threading.JobRunner.RunJobs(Nullable`1 priority)
   at Avalonia.Threading.Dispatcher.RunJobs(DispatcherPriority minimumPriority)
   at Avalonia.X11.X11Window.<OnEventSync>b__104_1()
   at Avalonia.Threading.JobRunner.Job.Avalonia.Threading.JobRunner.IJob.Run()
   at Avalonia.Threading.JobRunner.RunJobs(Nullable`1 priority)
   at Avalonia.X11.X11PlatformThreading.HandleX11(CancellationToken cancellationToken)
   at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken)
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode)
   at WPILibInstaller.Program.Main(String[] args)
Aborted (core dumped)
@AustinShalit AustinShalit added the bug Something isn't working label Jan 6, 2021
@ThadHouse
Copy link
Member

We never saw this during any testing, with multiple people testing both arch and debian installs, both stock and ones that had been used for a while. Its possible this is likely a configuration issue with your system, and installing those fonts just reconfigures some things. We can put a note in somewhere, but likely nothing we can do to fix it from our end.

@RyanHir
Copy link
Author

RyanHir commented Jan 6, 2021

I understand, I am using a minimal installation so I don't have much fonts installed. From what I read online Avalonia defaults to MS fonts and I presume Gnome/KDE installations put a MS font shim for compatibility which allows for it to work in the tests.

@RyanHir
Copy link
Author

RyanHir commented Jan 6, 2021

My understanding of Avalonia is limited but from what I have seen, it is possible to embed fonts into the package. This would allow for greater compatibility if a open licensed font is embedded into the installation.

@calcmogul
Copy link
Member

calcmogul commented Jan 6, 2021

I don't have msfonts installed and it works for me on Arch. SkiaSharp is picking up a different default font for me. After doing the following on Arch:

dotnet new console fonttest
cd fonttest
dotnet add package SkiaSharp
sudo pacman -S skia-sharp

Then edit fonttest/Program.cs with the following file adapted from AvaloniaUI/Avalonia#4427 (comment)

using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.Write("SkiaSharp.SKTypeface.Default.FamilyName=");
            System.Console.WriteLine(SkiaSharp.SKTypeface.Default.FamilyName);
            System.Console.Write("SkiaSharp.SKFontManager.Default.MatchFamily(null)=");
            System.Console.WriteLine(SkiaSharp.SKFontManager.Default.MatchFamily(null));
            System.Console.Write("SkiaSharp.SKFontManager.Default.MatchFamily(string.Empty)=");
            System.Console.WriteLine(SkiaSharp.SKFontManager.Default.MatchFamily(string.Empty));
            System.Console.Write("SkiaSharp.SKFontManager.Default.MatchFamily(\"sans\")=");
            System.Console.WriteLine(SkiaSharp.SKFontManager.Default.MatchFamily("sans"));
        }
    }
}

Then run with dotnet run, I get the following output:

SkiaSharp.SKTypeface.Default.FamilyName=DejaVu Sans
SkiaSharp.SKFontManager.Default.MatchFamily(null)=SkiaSharp.SKTypeface+SKTypefaceStatic
SkiaSharp.SKFontManager.Default.MatchFamily(string.Empty)=
SkiaSharp.SKFontManager.Default.MatchFamily("sans")=SkiaSharp.SKTypeface+SKTypefaceStatic

@ShannonZ
Copy link

ShannonZ commented Feb 4, 2021

I‘ve installed ttf-mscorefonts-installer and refresh the font cache. But I still get the same error.

@calcmogul
Copy link
Member

calcmogul commented Feb 4, 2021

Not surprising since that suggested fix for Ubuntu was never tested (the OP runs Arch). What fonts are installed on your system?

@RyanHir
Copy link
Author

RyanHir commented Feb 4, 2021

Correct, it was presumed not tested. If you want to attempt installation via CLI, try these instructions #11 (comment)

@RyanHir
Copy link
Author

RyanHir commented Dec 10, 2021

I'm closing this as the issue appears to have resolved itself and I am now using a combination of Windows & Ubuntu.

@RyanHir RyanHir closed this as completed Dec 10, 2021
@ErdajtSopjani
Copy link

This fixed the issue for me! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants