---
title: "Font Metrics"
canonical: https://www.graphicsmill.com/samples/Text/FontRegistry/FontMetrics_cs
product: "Graphics Mill"
source: "Text/FontRegistry/FontMetrics.cs"
---

# Font Metrics

Adds font to FontRegistry from file and shows its metrics.

## Instruction

This code demonstrates how to load a custom OpenType font, retrieve font metrics, and display font properties like size, ascender, descender, and more.

## Usings

```csharp
using System;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
using (var fontRegistry = new CustomFontRegistry())
{
    var fontSize = 30f;
    var dpi = 150f;

    // Load custom OpenType font
    var postscriptName = fontRegistry.Add("Amburegul.otf")[0].PostscriptName;

    var font = fontRegistry.CreateFont(postscriptName, fontSize, dpi, dpi);

    // Font metrics
    Console.WriteLine("Font: {0} {1}", font.Family, font.Style);
    Console.WriteLine("  DPI (X,Y):             {0},{0}", dpi);
    Console.WriteLine("  Size:                  {0}pt", fontSize);
    Console.WriteLine("  Ascender:              {0}px", font.Metrics.Ascender);
    Console.WriteLine("  Descender:             {0}px", font.Metrics.Descender);
    Console.WriteLine("  Height:                {0}px", font.Metrics.Height);
    Console.WriteLine("  Underline position:    {0}px", font.Metrics.UnderlinePosition);
    Console.WriteLine("  Underline thickness:   {0}px", font.Metrics.UnderlineThickness);
    Console.WriteLine();
}
```

## Explanation

The code:

- Creates a `CustomFontRegistry` to manage fonts.
- Loads a custom OpenType font (`Amburegul.otf`) using the font registry's `Add` method, and sets a font size of 30pt and DPI of 150 for rendering.
- Creates a font object using the `CreateFont` method from the registry, with the given size and DPI values.
- Prints various font metrics and properties to the console, such as:
- The font family and style
- DPI for both X and Y axis
- Font size in points
- Ascender and descender values (height from the baseline for the highest and lowest characters)
- Total height of the font
- Underline position and thickness
- The metrics are printed out in a human-readable format to help analyze the font characteristics.

## Tags

- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [Font](<https://www.graphicsmill.com/samples/tags/font_md>): Managing fonts and font metrics
- [Text](<https://www.graphicsmill.com/samples/tags/text_md>): Rendering and formatting text

## Input

- [Amburegul.otf](<https://www.graphicsmill.com/samples/Text/compiled/Debug/Amburegul_otf>) (download)

## Output

- [FontMetrics.txt](<https://www.graphicsmill.com/samples/Text/compiled/Debug/FontMetrics_txt>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Drawing.CustomFontRegistry](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_CustomFontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Drawing.CustomFontRegistry.Add(String)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_CustomFontRegistry_Add_1_bb3a7a4f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Font.Family](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Font_Family.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Font.Metrics](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Font_Metrics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Font.Style](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Font_Style.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontAddResult.PostscriptName](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontAddResult_PostscriptName.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontMetrics.Ascender](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontMetrics_Ascender.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontMetrics.Descender](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontMetrics_Descender.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontMetrics.UnderlinePosition](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontMetrics_UnderlinePosition.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontMetrics.UnderlineThickness](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontMetrics_UnderlineThickness.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontRegistry.CreateFont(String,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_FontRegistry_CreateFont_4_e130a0da.htm.md>)
