C# Load Font from File | Save CFF, TrueType, and Type1 Fonts

In digital typography, fonts define particular styles to be used for the characters’ appearance. Most often, the fonts are utilized in documents and web pages to stylize the text. Each font is described in a file that contains information about characters’ size, weight, styles, and encoding. Since fonts are an important part of the various file formats, Aspose offers a dedicated API for dealing with the manipulation and rendering of popular font types, including TrueType, CFF, OpenType, and Type1. In this article, you will learn how to load fonts from a file, save fonts, and extract font metrics from fonts in C#.

C# Font API to Load and Save Fonts from Files

Aspose.Font for .NET is an on-premise API that lets you implement the font management features using C# within your .NET applications. Along with loading, saving, and extracting information from the font, the API also allows you to render the glyph or text if required.

Please either download the API or install it within your .NET applications using NuGet.

PM> Install-Package Aspose.Font

Load or Save Font From File using C#

You can load a font from the file stored on your digital storage to retrieve the font’s information. Aspose.Font for .NET exposes separate classes to deal with the particular types of fonts, i.e., CFF, TrueType, etc. The following are the steps to load and save a font:

  • Load the font from the file (using the file’s path or byte array) using the FontDefinition class.
  • Access the font’s information using the CffFont, TtfFont, or Type1Font class.
  • Save the file (if required).

Load and Save the CFF Font

The following code sample shows how to load and save CFF fonts using C#.

Load and Save TrueType Font

The following code sample shows how to load and save TrueType fonts using C#.

Load and Save Type1 Font

The following code sample shows how to load and save Type1 fonts using C#.

Extract Font Metrics using C#

Aspose.Font for .NET also allows you to retrieve font metrics information such as Ascender, Descender, TypoAscender, TypoDescender, and UnitsPerEm. The following are the steps to do so:

  • Use the FontDefinition class to load TrueType or Type1 fonts from the file.
  • Open the font using the respective font type class i.e., Type1Font, TtfFont, etc.
  • Access the font’s metrics information.

The following code samples show how to extract font metrics from TrueType and Type1 fonts using C#.

Extract Font Metrics from TrueType Font

Get Font Metrics from Type1 Font

Detect Latin Symbols in Fonts using C#

You can also detect Latin text in the fonts by decoding the glyph codes using Aspose.Font for .NET. The following are the steps to perform this operation:

  • Load the font from the file using the FontDefinition class.
  • Decode the GlyphId using the DecodeToGid() method of the respective font class.

The following code samples show how to decode Latin symbols in TrueType and Type1 fonts using C#.

Detect Latin Symbols in TrueType Font

Detect Latin Symbols in Type1 Font

C# Font API - Learning Resources

You can learn more about loading, saving, converting, and manipulating fonts and explore various other features of Aspose.Font for .NET using the resources given below:

Conclusion

In this article, you have seen how to load and save CFF, TrueType and Type1 fonts programmatically using C#. Furthermore, you have learned how to extract font metrics information from TrueType and Type1 fonts within your .NET applications. By leveraging Aspose.Font for .NET, you can easily develop your own applications to manipulate fonts. In case of any ambiguity, please feel free to contact us on our [free support forum][18].

See Also