mono / libgdiplus

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

Font.Name returns incorrect results on Linux #617

Open Yaroslav-Kuznetsov opened 4 years ago

Yaroslav-Kuznetsov commented 4 years ago

I'm using the System.Drawing.Common NuGet package and the latest version of libgdiplus (v6.0.x). The following two fonts are installed and are present in the /usr/share/fonts directory: DejaVuSansCondensed.ttf DejaVuSans.ttf

I'm instantiating font objects as follows:

var font = new Font("DejaVu Sans Condensed", 20.0F);  

Now, I'm trying to compare Font.Name with Font.OriginalName and the results I get are different based on the underlying operating system.

The correct and expected output (Windows): Font.Name: DejaVu Sans Condensed Font.OriginalFontName: DejaVu Sans Condensed FontFamily.Name: DejaVu Sans Condensed

The incorrect output (Linux); Font.Name: DejaVu Sans Font.OriginalFontName: DejaVu Sans Condensed FontFamily.Name: DejaVu Sans

Note: this is not the issue with the font resolution and subsequent fallback. I can draw with the given font on a Bitmap surface and the output is clearly different from the regular version of "DejaVu Sans". As I understand it from this method's implementation, libgdiplus returns the "Typographic Family" name (also known as "Preferred Name"). This behavior is not consistent with Windows GDI+ implementation, which obtains the "Font Family" name (due to the legacy "Style Linking" feature). See the name — Naming Table help topic for more information in this regard.

This issue appears to be crucial for our software needs as we serialize font information to XML. Any assistance on this issue would be greatly appreciated.