ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.06k stars 236 forks source link

PdfSharpCore won't use icon font #262

Closed Steve-OH closed 2 years ago

Steve-OH commented 2 years ago

I'm trying to use an icon font in PdfSharpCore, and it refuses to let me. Using this sample code:

using PdfSharpCore.Drawing;
using System.Drawing;

IEnumerable<string> fontFamilies = new List<string>
{
    "Material Icons",
    "GLYPHICONS Basic Set",
    "la-solid-900",
    "Font Awesome 6 Free Solid",
};

foreach (var family in fontFamilies)
{
    var font = new Font(family, 8);
    Console.WriteLine($"{font.FontFamily.Name} : {font.Name}");
}

foreach (var family in fontFamilies)
{
    var font = new XFont(family, 8);
    Console.WriteLine($"{font.FontFamily.Name} : {font.Name}");
}

The output is:

Material Icons : Material Icons
GLYPHICONS Basic Set : GLYPHICONS Basic Set
la-solid-900 : la-solid-900
Font Awesome 6 Free Solid : Font Awesome 6 Free Solid
Agency FB : Agency FB
Agency FB : Agency FB
Agency FB : Agency FB
Agency FB : Agency FB

I believe it's picking Agency FB simply because it's the first font in alphabetical order that it can find. Needless to say, Agency FB doesn't contain any of the glyphs that I'd like to use.

The fonts I'm trying to use:

Material Icons: https://github.com/google/material-design-icons/blob/master/font/MaterialIcons-Regular.ttf Glyphicons: [commercial font; not available for download] Line Awesome: https://github.com/icons8/line-awesome/blob/master/dist/line-awesome/fonts/la-solid-900.ttf Font Awesome: https://use.fontawesome.com/releases/v6.1.1/fontawesome-free-6.1.1-desktop.zip

MichelMichels commented 2 years ago

Hi, I made some educated guesses as to why this is happening. I discovered that Windows does not install fonts in C:\Windows\Fonts anymore, but instead copies it to a folder inside your local AppData (of the currently logged-in Windows user).

I made a PR to also check this folder (see #267 ). This fixes this issue.

Steve-OH commented 2 years ago

Interesting. Thanks.

You can still install fonts in C:\Windows\Fonts by right-clicking on the font file and selecting Install for all users. This requires Administrator permissions, of course.