How to Get Font Metrics in C#

In this step by step guide, we’ll explain how to get font metrics in C#. This tutorial provides code to get Type1 font metrics in C#, but Aspose.Font for .NET, a C# font library helps you read font metrics in C# from other font types as well including TruType and OpenType font formats.

Steps to Get Font Metrics in C#

  1. Install Aspose.Font for .NET package from
  2. Include Aspose.Font, Aspose.Font.Sources, and Aspose.Font.Type1 namespaces
  3. Apply license to Aspose.Font for .NET to avoid evaluation watermark
  4. Load the input Type1 font into FileSystemStreamSource object
  5. Create a FontFileDefinition object from the stream source
  6. Create a FontDefinition object from the file definition
  7. Open font definition as Type1Font object
  8. Now, get all the metrics attributes of the Type1 font

A font contains metrics information that helps describe the glyphs inside a font. This metrics information of the fonts helps a computer learn how to draw characters and sentences on the screen. If we want to process this metrics information via code in our .NET applications, it’s not an easy task. However, Aspose.Font for .NET helps make the whole process very simple and easy using a few steps as mentioned above.

Code to Get Font Metrics in C#

In the above code, we’re loading a PFB file format, which contains our Type1 font we’re interested to process in C# code. Once we have loaded the font and converted it to a Type1Font object, we’re able to extract font metrics in C# from this file.

This code can help you create a C# font reader easily in your .NET applications including web, desktop, windows and Microsoft Store applications.