Incorrect font after loading from file in WPF

109 views Asked by At

Load a font to the program using

GetNonCachedFontFamilies(MainPath).FirstOrDefault();

GetNonCachedFontFamilies method

public static IEnumerable<FontFamily> GetNonCachedFontFamilies(string location)
{
    if (string.IsNullOrEmpty("location"))
        throw new ArgumentException("Must provide a location", "location");

    DirectoryInfo directoryInfo = new DirectoryInfo(location);
    if (directoryInfo.Exists)
    {
        FileInfo[] fileInfos = directoryInfo.GetFiles("*.?tf");
        foreach (FileInfo fileInfo in fileInfos)
            yield return CreateFontFamily(fileInfo.FullName);
    }
    else
    {
        FileInfo fileInfo = new FileInfo(location);
        if (fileInfo.Exists)
            yield return CreateFontFamily(location);
    }
}

CreateFontFamily method

private static FontFamily CreateFontFamily(string path)
{
    if (!Uri.TryCreate(path, UriKind.Absolute, out Uri uri))
        throw new ArgumentException("Must provide a valid location", "path");

    return new FontFamily(uri, string.Empty);
}

There is no problems with loading a font from file and creating a FontFamily class with it. But it must be a handwritten cyrillic font, and I can only see something like Microsoft Sans Serif. Photo and Font sample file
Please, give an answer without xaml. I need to load font programatically.
I use this font with TextBlocks

0

There are 0 answers