---
title: "Show Custom Font Metrics"
canonical: https://www.graphicsmill.com/samples/Text/FontRegistry/ShowCustomFontMetrics_cs
product: "Graphics Mill"
source: "Text/FontRegistry/ShowCustomFontMetrics.cs"
---

# Show Custom Font Metrics

Adds font to FontRegistry from file and shows its metrics.

## Instruction

Write a C# program that loads custom TrueType font "Lobster.ttf" into CustomFontRegistry via Add method to get PostScript name, creates 600x250 RGB bitmap with white background, uses AdvancedGraphics with font registry to render PlainText and RoundText samples at 60pt size, calculates and displays black box metrics with DPI-aware positioning, draws visual markup showing position points, bounding boxes, ascender/descender/baseline lines, and saves both console metrics output and annotated PNG visualization "ShowCustomFontMetrics.png".

## Usings

```csharp
using System;
using Aurigma.GraphicsMill.Drawing;
using Aurigma.GraphicsMill.Drawing.Art;
```

## Code Snippet

```csharp
public static void Run()
{
    using (var bitmap = new Bitmap(600, 250, PixelFormat.Format24bppRgb, new RgbColor(255, 255, 255, 255)))
    using (var graphics = bitmap.GetGraphics())
    using (var fontRegistry = new CustomFontRegistry())
    {
        var fontSize = 60f;

        // Load custom TrueType font
        var psName = fontRegistry.Add("Lobster.ttf")[0].PostscriptName;

        graphics.FontRegistry = fontRegistry;

        var font = graphics.CreateFont(psName, fontSize);

        // Plain text metrics
        var plainText = new PlainText("plain text", font);
        plainText.Position = new System.Drawing.PointF(5, plainText.GetBlackBox(fontRegistry, bitmap.DpiX, bitmap.DpiY).Height + 10);

        ShowTextPosition(plainText.String, plainText.Position, plainText.GetBlackBox(fontRegistry, bitmap.DpiX, bitmap.DpiY));

        DrawPlainTextWithMarkup(plainText, graphics);

        // Round text metrics
        var roundText = new RoundText("Art round text", font, new System.Drawing.PointF(50, 50))
        {
            Bend = 0.9f,
        };

        roundText.Center = new System.Drawing.PointF(
            graphics.Width - (roundText.GetBlackBox(fontRegistry, bitmap.DpiX, bitmap.DpiY).Width / 2) - 15,
            graphics.Height - (roundText.GetBlackBox(fontRegistry, bitmap.DpiX, bitmap.DpiY).Height / 2) - 10);

        ShowTextPosition(roundText.String, roundText.Center, roundText.GetBlackBox(fontRegistry, bitmap.DpiX, bitmap.DpiY));

        DrawArtTextWithMarkup(roundText, graphics);

        bitmap.Save("ShowCustomFontMetrics.png");
    }
}

private static void ShowTextPosition(string str, System.Drawing.PointF pos, System.Drawing.RectangleF blackBox)
{
    Console.WriteLine("Text metrics (\"{0}\")", str);
    Console.WriteLine("  Position");
    Console.WriteLine("    X:       {0}", pos.X);
    Console.WriteLine("    Y:       {0}", pos.Y);
    Console.WriteLine("  Black box");
    Console.WriteLine("    X:       {0}", blackBox.X);
    Console.WriteLine("    Y:       {0}", blackBox.Y);
    Console.WriteLine("    Width:   {0}", blackBox.Width);
    Console.WriteLine("    Height:  {0}", blackBox.Height);
    Console.WriteLine();
}

/// <summary>
/// Draws art text with center point and black box
/// </summary>
private static void DrawArtTextWithMarkup(ArtText text, Graphics graphics)
{
    // Draw round text, its black box and center point
    graphics.DrawText(text);

    graphics.DrawRectangle(new Pen(RgbColor.Gray, 1f), text.GetBlackBox(graphics.FontRegistry, graphics.DpiX, graphics.DpiY));

    graphics.FillEllipse(new SolidBrush(RgbColor.Red), text.Center.X - 3, text.Center.Y - 3, 6, 6);
}

/// <summary>
/// Draws PlainText with ascender and descender lines
/// </summary>
private static void DrawPlainTextWithMarkup(PlainText text, Graphics graphics)
{
    // Draw plain text, its black box, ascender, descender and position point
    graphics.DrawText(text);

    var bbox = text.GetBlackBox(graphics.FontRegistry, graphics.DpiX, graphics.DpiY);

    graphics.DrawRectangle(new Pen(RgbColor.Gray, 1f), bbox);

    var font = graphics.CreateFont(text.CharStyle.PostScriptName, text.CharStyle.Size);

    var stringMeasure = font.MeasureString("plain text");

    graphics.DrawLine(
        new Pen(RgbColor.Blue, 1f),
        bbox.X,
        text.Position.Y - stringMeasure.Ascender,
        bbox.X + bbox.Width,
        text.Position.Y - stringMeasure.Ascender);

    graphics.DrawLine(
        new Pen(RgbColor.Green, 1f),
        bbox.X,
        text.Position.Y - stringMeasure.Descender,
        bbox.X + bbox.Width,
        text.Position.Y - stringMeasure.Descender);

    graphics.DrawLine(
        new Pen(RgbColor.IndianRed, 1f),
        bbox.X,
        text.Position.Y,
        bbox.X + bbox.Width,
        text.Position.Y);

    graphics.FillEllipse(new SolidBrush(RgbColor.Red), text.Position.X - 3, text.Position.Y - 3, 6, 6);
}
```

## Explanation

Below is a C# code sample that demonstrates custom font loading and advanced text metrics visualization:

The code showcases complete custom font integration workflow: loading TTF via CustomFontRegistry.Add for PostScript name resolution, DPI-aware font creation, PlainText baseline positioning with ascender/descender visualization using MeasureString metrics, and RoundText with Bend=0.9f circular layout centered via black box calculations. Visual markup includes gray bounding rectangles, colored baseline/ascender/descender lines, red position/center markers, enabling precise typographic analysis. Console output provides quantitative metrics while PNG visualization shows spatial relationships, essential for custom font validation, UI layout precision, and advanced text rendering in graphics applications.

## 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

- [Lobster.ttf](<https://www.graphicsmill.com/samples/Text/compiled/Debug/Lobster_ttf>) (download)

## Output

- [ShowCustomFontMetrics.txt](<https://www.graphicsmill.com/samples/Text/compiled/Debug/ShowCustomFontMetrics_txt>) (preview)
- [ShowCustomFontMetrics.png](<https://www.graphicsmill.com/samples/Text/compiled/Debug/ShowCustomFontMetrics_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Art.ArtText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Art_ArtText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Art.ArtText.Center](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Art_ArtText_Center.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Art.RoundText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Art_RoundText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Art.RoundText.Bend](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Art_RoundText_Bend.htm.md>)
- [Aurigma.GraphicsMill.Drawing.CharStyle.PostScriptName](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_CharStyle_PostScriptName.htm.md>)
- [Aurigma.GraphicsMill.Drawing.CharStyle.Size](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_CharStyle_Size.htm.md>)
- [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.MeasureString(String)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Font_MeasureString_1_bb3a7a4f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontAddResult.PostscriptName](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontAddResult_PostscriptName.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Graphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.CreateFont(String,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_CreateFont_2_1dbfa9fa.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawLine(Pen,Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawLine_5_b3708ac1.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawRectangle(Pen,RectangleF)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawRectangle_2_169e24a7.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawText(Text)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawText_1_f576d03f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FillEllipse(Brush,Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_FillEllipse_5_2d30ad96.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FontRegistry](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_FontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Pen.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_PlainText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText.Position](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_PlainText_Position.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.StringMeasure.Ascender](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_StringMeasure_Ascender.htm.md>)
- [Aurigma.GraphicsMill.Drawing.StringMeasure.Descender](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_StringMeasure_Descender.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.CharStyle](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Text_CharStyle.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.GetBlackBox(FontRegistry,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Text_GetBlackBox_3_185e8a92.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.String](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Text_String.htm.md>)
