[]
        
(Showing Draft Content)

GrapeCity.ActiveReports.Design.Designer.FontResolver

FontResolver Property

FontResolver

Gets or sets a value representing the font resolver used by the designer to resolve fonts in reports.

Declaration
public IFontResolver FontResolver { get; set; }
Property Value
Type Description
IFontResolver

An IFontResolver that handles font resolution. The default is null, which indicates that the default font resolver is used.

Remarks

The font resolver is responsible for determining the specific font instance to use when rendering text in reports. This can be particularly useful in scenarios where custom fonts are used or when there is a need to map generic font names to specific font files. Implementing a custom IFontResolver allows for precise control over font selection and rendering in the designer environment.

Note: Setting this property to a custom font resolver overrides the default font resolution mechanism. Ensure that the custom resolver properly handles all font requests to avoid rendering issues.

Examples

This property allows you to specify custom fonts for use in both the preview and design of reports. To utilize this feature, you must first define a custom font resolver:

//Custom font resolver
public sealed class DirectoryFontResolver : GrapeCity.ActiveReports.IFontResolver
{
	Documents.Text.FontCollection _fonts;
	public DirectoryFontResolver(string fontsDirectory)
	{
		_fonts = new Documents.Text.FontCollection();
		// load standard Windows fonts
		_fonts.RegisterDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Fonts));
		// load fonts from custom directory
		_fonts.RegisterDirectory(fontsDirectory);
		_fonts.DefaultFont = _fonts.FindFamilyName("Arial");
	}
	Documents.Text.FontCollection IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic)
	{
		var fonts = new Documents.Text.FontCollection();
		fonts.Add(_fonts.FindFamilyName(familyName, isBold, isItalic) ?? _fonts.DefaultFont);
		return fonts;
	}
}

After defining a custom font resolver, you can then associate it with the designer instance.

class MyDesignerForm : Form
{
	public MyDesignerForm()
	{
		InitializeComponent();
		//note the designer must be added to the form and its name have to be '_designer'.
		_designer.FontResolver = new DirectoryFontResolver("c:\\Fonts");
	}
}