Skip to main content

Font descriptions

A FontDescription holds the strings in the font's name table: the family name, the full name, the style, the version, the copyright and others. You can read it without adding the font to a collection, which is fast. Use it to build a font picker, check licences, or index a folder of fonts.

Read the description of a font file​

using PinataLabs.Typography;

FontDescription description = FontDescription.LoadDescription("fonts/OpenSans-Regular.ttf");

Console.WriteLine(description.FontNameInvariantCulture); // Open Sans Regular
Console.WriteLine(description.FontFamilyInvariantCulture); // Open Sans
Console.WriteLine(description.FontSubFamilyNameInvariantCulture); // Regular
Console.WriteLine(description.Style); // Regular

LoadDescription also takes a Stream.

Read every font in a collection file​

For a .ttc file, LoadFontCollectionDescriptions returns one description for each font in it:

foreach (FontDescription d in FontDescription.LoadFontCollectionDescriptions("fonts/Helvetica.ttc"))
{
Console.WriteLine(d.FontNameInvariantCulture);
}

Read other names​

GetNameById reads any of the standard names. KnownNameIds lists them:

using System.Globalization;
using PinataLabs.Typography.WellKnownIds;

CultureInfo culture = CultureInfo.InvariantCulture;
string version = description.GetNameById(culture, KnownNameIds.Version); // Version 3.000
string copyright = description.GetNameById(culture, KnownNameIds.CopyrightNotice);
string license = description.GetNameById(culture, KnownNameIds.LicenseDescription);
KnownNameIds valueContains
CopyrightNoticeThe copyright notice.
FontFamilyNameThe family name, for example Open Sans.
FontSubfamilyNameThe style name, for example Bold Italic.
UniqueFontIDA unique identifier for the font.
FullFontNameThe family and style together, for example Open Sans Bold.
VersionThe version string.
PostscriptNameThe PostScript name, with no spaces.
TrademarkThe trademark notice.
ManufacturerThe name of the font vendor.
DesignerThe name of the designer.
DescriptionA description of the font.
VendorUrlThe website of the vendor.
DesignerUrlThe website of the designer.
LicenseDescriptionA description of the licence.
LicenseInfoUrlWhere to read the licence.
TypographicFamilyNameThe family name for fonts with more than the four basic styles.
TypographicSubfamilyNameThe style name that goes with TypographicFamilyName.
SampleTextSample text chosen by the designer.

If the font does not have the name, the result is an empty string.

Names in other languages​

FontName, FontFamily, FontSubFamilyName and GetNameById take a CultureInfo. They return the name in that language if the font has it. If it does not, they return the US English name, then the first Windows name, then the first name of any kind. The InvariantCulture properties use the same order, so they return the US English name when the font has one.

string name = description.FontFamily(CultureInfo.GetCultureInfo("zh-CN"));

Get the description of a loaded font​

A font that you already loaded has its description in its metrics:

FontDescription description = font.FontMetrics.Description;