---
title: "Font Fallback"
canonical: https://www.graphicsmill.com/samples/Text/FontRegistry/FontFallback_cs
product: "Graphics Mill"
source: "Text/FontRegistry/FontFallback.cs"
---

# Font Fallback

Draws multilanguage text with font fallback support.

## Instruction

This code demonstrates how to use a custom font registry and implement font fallback when rendering text that includes characters not available in the primary font.

## Usings

```csharp
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
using (var bitmap = new Bitmap(400, 200, PixelFormat.Format24bppRgb, RgbColor.White))
using (var graphics = bitmap.GetGraphics())
{
    var fontRegistry = new CustomFontRegistry();

    var lobsterPsName = fontRegistry.Add("Lobster.ttf")[0].PostscriptName;
    var arialUnicodePsName = fontRegistry.Add("ARIALUNI.TTF")[0].PostscriptName;

    fontRegistry.FallbackFonts.Add(arialUnicodePsName);

    graphics.FontRegistry = fontRegistry;

    var dummyText = "Lorem ipsum dolor sit amet, ex mel latine pertinax. 載自大制節規信兵著旋避漂。";

    var boundedText = new BoundedText(dummyText, graphics.CreateFont(lobsterPsName, 32f), new SolidBrush(RgbColor.Black))
    {
        Rectangle = new System.Drawing.RectangleF(20f, 20f, 360f, 360f),
    };

    graphics.DrawText(boundedText);

    bitmap.Save("FontFallback.png");
}
```

## Explanation

The code:

- Creates a `Bitmap` object with a white background (`RgbColor.White`) and dimensions of 400x200 pixels.
- Initializes a custom `FontRegistry` (`CustomFontRegistry`) and adds two fonts: `Lobster.ttf` and `ARIALUNI.TTF` (Arial Unicode).
- Configures the `FontRegistry` to include `ARIALUNI.TTF` as a fallback font in case certain characters (such as non-Latin characters) cannot be rendered with the primary font.
- Creates an `AdvancedGraphics` object to draw on the bitmap and sets the font registry.
- Defines a string (`dummyText`) containing both Latin and non-Latin characters (Chinese text).
- Creates a `BoundedText` object for the text using the `Lobster.ttf` font and specifies the rectangle where the text should be drawn.
- Draws the text inside the defined bounds using the graphics object (`graphics.DrawText`).
- Saves the resulting image as a PNG file (`FontFallback.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)
- [ARIALUNI.TTF](<https://www.graphicsmill.com/samples/Text/compiled/Debug/ARIALUNI_TTF>) (download)

## Output

- [FontFallback.png](<https://www.graphicsmill.com/samples/Text/compiled/Debug/FontFallback_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.BoundedText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_BoundedText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.BoundedText.Rectangle](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_BoundedText_Rectangle.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.FontAddResult.PostscriptName](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontAddResult_PostscriptName.htm.md>)
- [Aurigma.GraphicsMill.Drawing.FontRegistry.FallbackFonts](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_FontRegistry_FallbackFonts.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.DrawText(Text)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawText_1_f576d03f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FontRegistry](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_FontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
