Back to Devexpress

DXFontRepository.AddFont(Byte[]) Method

corelibraries-devexpress-dot-drawing-dot-dxfontrepository-dot-addfont-x28-system-dot-byte-x29.md

latest4.8 KB
Original Source

DXFontRepository.AddFont(Byte[]) Method

Loads a font from a byte array.

Namespace : DevExpress.Drawing

Assembly : DevExpress.Drawing.v25.2.dll

NuGet Package : DevExpress.Drawing

Declaration

csharp
public void AddFont(
    byte[] fontData
)
vb
Public Sub AddFont(
    fontData As Byte()
)

Parameters

NameTypeDescription
fontDataByte[]

A byte array that contains font data.

|

Remarks

The AddFont method supports the following font formats:

  • 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 required fonts to DXFontRepository before you load a document, report or dashboard that uses these fonts.

Loaded fonts are not saved to the document, report or dashboard. They are used to display, print, or export the document, report or dashboard to PDF.

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

csharp
using DevExpress.Drawing;
//...

DXFontRepository.Instance.AddFont(File.ReadAllBytes(@"Fonts\EmilysCandy-Regular.ttf"));
DXFontRepository.Instance.AddFont(File.ReadAllBytes(@"Fonts\FrederickatheGreat-Regular.ttf"));
//...

DXFontRepository.Instance.Dispose();
vb
Imports DevExpress.Drawing
'...

DXFontRepository.Instance.AddFont(File.ReadAllBytes("Fonts\EmilysCandy-Regular.ttf"))
DXFontRepository.Instance.AddFont(File.ReadAllBytes("Fonts\FrederickatheGreat-Regular.ttf"))
'...

DXFontRepository.Instance.Dispose()

The following code snippets (auto-collected from DevExpress Examples) contain references to the AddFont(Byte[]) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-wpf-use-private-custom-font-distributed-with-application/CS/PrivateFontDemo/MainWindow.xaml.cs#L17

csharp
byte[] fontData = System.IO.File.ReadAllBytes(fontFilePath);
    DXFontRepository.Instance.AddFont(fontData);
}

reporting-web-forms-use-custom-font-distributed-with-the-application/CS/E5198/Global.asax.cs#L17

csharp
byte[] fontData = System.IO.File.ReadAllBytes(fontFilePath);
DXFontRepository.Instance.AddFont(fontData);

reporting-wpf-use-private-custom-font-distributed-with-application/VB/PrivateFontDemo/MainWindow.xaml.vb#L19

vb
Dim fontData() As Byte = System.IO.File.ReadAllBytes(fontFilePath)
    DXFontRepository.Instance.AddFont(fontData)
End Sub

reporting-web-forms-use-custom-font-distributed-with-the-application/VB/E5198/Global.asax.vb#L18

vb
Dim fontData() As Byte = System.IO.File.ReadAllBytes(fontFilePath)
DXFontRepository.Instance.AddFont(fontData)

See Also

DXFontRepository Class

DXFontRepository Members

DevExpress.Drawing Namespace