mono / libgdiplus

C-based implementation of the GDI+ API
http://www.mono-project.com/
MIT License
329 stars 171 forks source link

Long font names are truncated, but cannot be used in truncated form #666

Open directhex opened 3 years ago

directhex commented 3 years ago

GdipGetFamilyName gets a font family name, capped at LF_FACESIZE. This truncates fonts with long names, so new FontFamily("Noto Sans Inscriptional Parthian").Name returns Noto Sans Inscriptional Parthia

However, the truncated font names cannot be used when using GdipCreateFontFamilyFromName, i.e. new FontFamily(parthian.Name).Name returns the default font (Verdana).

This issue is specific to libgdiplus - on Windows, the truncate formatting is different and truncated names can be used when getting font family.

Netcore bug: https://github.com/dotnet/runtime/issues/40937

Sample font with name > LF_FACESIZE (included out of the box on macOS 10.15+, packaged in fonts-noto-core on Debian/Ubuntu) : https://noto-website-2.storage.googleapis.com/pkgs/NotoSansInscriptionalParthian-unhinted.zip

Easy repro code to demonstrate the issue:

using System;
using System.Drawing;

namespace fontfont
{
    class Program
    {
        static void Main(string[] args)
        {
            FontFamily parthian = new FontFamily("Noto Sans Inscriptional Parthian");
            FontFamily parthianCopy = new FontFamily(parthian.Name);
            Console.WriteLine("new FontFamily(\"Noto Sans Inscriptional Parthian\").Name:\t{0}", parthian.Name);
            Console.WriteLine("new FontFamily(parthian.Name).Name:\t\t\t\t{0}", parthianCopy.Name);
        }
    }
}