Back to Devexpress

DXFontRepository.AddFont(Stream) Method

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

latest3.7 KB
Original Source

DXFontRepository.AddFont(Stream) Method

Loads a font from a stream.

Namespace : DevExpress.Drawing

Assembly : DevExpress.Drawing.v25.2.dll

NuGet Package : DevExpress.Drawing

Declaration

csharp
public void AddFont(
    Stream fontStream
)
vb
Public Sub AddFont(
    fontStream As Stream
)

Parameters

NameTypeDescription
fontStreamStream

A stream from which to load the font.

|

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;
using System.IO;
//...

using (FileStream font1 = new FileStream(@"Fonts\advent-pro.regular.ttf", FileMode.Open))
    DXFontRepository.Instance.AddFont(font1);
using (FileStream font2 = new FileStream(@"Fonts\Roboto-Light.ttf", FileMode.Open))
    DXFontRepository.Instance.AddFont(font2);
//...

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

Using font1 As New FileStream("Fonts\advent-pro.regular.ttf", FileMode.Open)
    DXFontRepository.Instance.AddFont(font1)
End Using
Using font2 As New FileStream("Fonts\Roboto-Light.ttf", FileMode.Open)
    DXFontRepository.Instance.AddFont(font2)
End Using
'...

DXFontRepository.Instance.Dispose()

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddFont(Stream) 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.

maui-generate-data-bound-report/CS/MauiReportingApp/Platforms/iOS/AppDelegate.cs#L17

csharp
var fontStream = new MemoryStream(File.ReadAllBytes(fontPath));
DXFontRepository.Instance.AddFont(fontStream);

See Also

DXFontRepository Class

DXFontRepository Members

DevExpress.Drawing Namespace