---
title: "Font API"
canonical: https://www.graphicsmill.com/samples/Text/FontRegistry/FontAPI_cs
product: "Graphics Mill"
source: "Text/FontRegistry/FontAPI.cs"
---

# Font API

Draws text without text objects, only with getting char info + simple metrics.

## Instruction

This code demonstrates how to render each character of a text string using a custom font and apply individual character outlines.

## Usings

```csharp
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
using (var bitmap = new Bitmap(200, 200, PixelFormat.Format24bppRgb, RgbColor.White))
using (var gr = bitmap.GetGraphics())
using (var fr = new CustomFontRegistry())
{
    var psName = fr.Add("Lobster.ttf")[0].PostscriptName;

    gr.FontRegistry = fr;

    var font = gr.CreateFont(psName, 40);

    string[] lines = new string[] { "SOME", "TEXT", "TO ADD" };

    float x = 10f;
    float y = 50f;

    float offsetY = 0f;

    foreach (string line in lines)
    {
        float offsetX = 0f;

        for (int i = 0; i < line.Length; i++)
        {
            using (var charInfo = font.GetCharacterInfo(line[i]))
            {
                charInfo.Outline.Translate(x + offsetX, y + offsetY);

                gr.FillPath(new SolidBrush(RgbColor.Black), charInfo.Outline);

                offsetX += charInfo.AdvanceX;
            }
        }

        offsetY += font.Metrics.Height;
    }

    bitmap.Save("FontAPI.png");
}
```

## Explanation

The code:

- Creates a `Bitmap` object with a white background (`RgbColor.White`) and dimensions of 200x200 pixels.
- Initializes an `AdvancedGraphics` object for drawing on the bitmap and uses a custom font registry (`CustomFontRegistry`) to add a font (`Lobster.ttf`).
- Sets the font registry for the graphics object and creates a font using the custom font (`Lobster.ttf`) at 40 points size.
- Defines an array of strings (`lines`) containing the text to render: "SOME", "TEXT", "TO ADD".
- Iterates through each line and each character of the line to obtain character information using `font.GetCharacterInfo`.
- Translates and draws the character outlines on the bitmap using `gr.FillPath` with black color (`RgbColor.Black`).
- Adjusts the X and Y positions for each character and each line to properly space them.
- Saves the resulting image with outlined characters as a PNG file (`FontAPI.png`).

## 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

- [FontAPI.png](<https://www.graphicsmill.com/samples/Text/compiled/Debug/FontAPI_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.CharInfo.AdvanceX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_CharInfo_AdvanceX.htm.md>)
- [Aurigma.GraphicsMill.Drawing.CharInfo.Outline](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_CharInfo_Outline.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.GetCharacterInfo(Char)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Font_GetCharacterInfo_1_391855ca.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Font.Metrics](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Font_Metrics.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.CreateFont(String,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_CreateFont_2_1dbfa9fa.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FillPath(Brush,Path)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_FillPath_2_3cee1596.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FontRegistry](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_FontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.Translate(Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_Translate_2_427c5821.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
