Skip to main content
All docs
V24.1

Use DXFontRepository to Add Custom Fonts

  • 3 minutes to read

The DXFontRepository class allows you to use fonts that are not installed on the operating system. Add required fonts to the font repository to eliminate font substitution effects. The class is available for the following products:

  • Word Processing Document API
  • Spreadsheet Document API
  • PDF Document API (used in grahpics content only)
  • Reporting
  • Charts
  • Rich Text Editor and Spreadsheet controls (WinForms/WPF)

Use the FontRepository.Instance static property to access a DXFontRepository instance.

Loaded fonts are not saved to the document - they are used to display, print, or export Word and Spreadsheet documents. Custom fonts are applied to the report when it is exported to PDF or an image from code.

Add Fonts to the Repository

Use the DXFontRepository.AddFont method overloads to add fonts to the font repository. You can load a font from a file, stream, or byte array.

Supported font formats include:

  • TrueType fonts (.TTF)

  • OpenType fonts that use CFF (Compact Font Format) glyph outlines (.OTF)

  • OpenType Font Collections (.TTC, .OTC) that contain multiple fonts in a single file

To avoid excessive layout recalculations, add the fonts to DXFontRepository before you load a document, report, or chart that uses these fonts.

The code sample below adds custom fonts to DXFontRepository. This example uses the following Google fonts:

using DevExpress.Drawing;
//...
DXFontRepository.Instance.AddFont(@"Fonts\EmilysCandy-Regular.ttf");
DXFontRepository.Instance.AddFont(@"Fonts\FrederickatheGreat-Regular.ttf");
// you usage code here
//...

Obtain Information About Fonts in the Repository

Use the FontRepository.GetFonts method to return a list of all fonts in the font repository. Each item in this list is a DXFontData object that contains font information.

The following code sample retrieves the names of all fonts in the repository and displays this information in the console window:

using DevExpress.Drawing;
using System;
using System.Collections.Generic;
// ...

if (DXFontRepository.Instance.IsEmpty)
    Console.WriteLine("Font repository is empty.");
else
{
    Console.WriteLine("Font repository contains the following fonts:");
    IList<DXFontData> fonts = DXFontRepository.Instance.GetFonts();
    for (int i = 0; i < fonts.Count; i++)
    {
        Console.WriteLine($"  \u002A {fonts[i].Name}");
    }
}

The following image demonstrates a sample console output:

Console Output

Clear the Font Repository

Call the DXFontRepository.Clear method to remove all fonts from the font repository. Use the DXFontRepository.IsEmpty property to check whether the repository contains fonts.

using DevExpress.Drawing;
// ...

// Check whether the font repository is empty.
if (!DXFontRepository.Instance.IsEmpty)
    // If false, clear the font repository.
    DXFontRepository.Instance.Clear();